package cn.cecep.talroad.vo.query.analysis;

import cn.cecep.talroad.common.core.domain.query.PageQuery;
import cn.cecep.talroad.domain.analysis.SRaAbNalysisLowCar;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;


/**
 * 管控期车辆异常分析对象 s_ra_ab_nalysis_low_car
 *
 * @author szhpt
 * @date 2023-03-24*/
@ApiModel(value = "管控期车辆异常分析")
@EqualsAndHashCode(callSuper = false)
@Data
public class SRaAbNalysisLowCarQuery extends PageQuery
{

    @ApiModelProperty(value = "数据主键")
    private String dataId;
    @ApiModelProperty(value = "企业主键")
    private String factoryId;
    @ApiModelProperty(value = "企业名称")
    private String factoryName;
    @ApiModelProperty(value = "行业类别名称(多个使用'、'拼接)")
    private String industryCategoryName;
    @ApiModelProperty(value = "行业类别编码(多个使用'、'拼接)")
    private String industryCategoryCode;
    @ApiModelProperty(value = "所在区县名称")
    private String districtName;
    @ApiModelProperty(value = "所在区县编码")
    private String districtCode;
    @ApiModelProperty(value = "所在区县编码")
    private List<String> regionCodes;
    @ApiModelProperty(value = "绩效级别")
    private String performanceLevel;
    @ApiModelProperty(value = "$column.columnComment")
    private String workingProcedure;
    @ApiModelProperty(value = "国四及以下车辆进出厂次数")
    private Long inOutNumber;
    @ApiModelProperty(value = "更新时间")
    private String updateTime;
    @ApiModelProperty(value = "创建时间(默认当前时间)")
    private String createTime;
    @ApiModelProperty(value = "分析时间(原型中日期)")
    private String analyseTime;

    @ApiModelProperty(value = "分析开始时间(原型中日期)")
    @TableField(exist = false)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date startAnalyseTime;
    @ApiModelProperty(value = "分析结束时间(原型中日期)")
    @TableField(exist = false)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date endAnalyseTime;

    @ApiModelProperty(value = "排放阶段")
    private String dischargeStage;
    /**
     *
     * @Title: getQueryWrapper
     * @Description: 查询参数组装
     * @param: @return
     * @return: QueryWrapper<BasIndustry>
     * @throws
     */
    public static QueryWrapper<SRaAbNalysisLowCar> createLambdaQueryWrapper(SRaAbNalysisLowCarQuery query) {
        Calendar calendar = new GregorianCalendar();
        if(ObjectUtil.isNotEmpty(query.getEndAnalyseTime())){
            calendar.setTime(query.getEndAnalyseTime());
            // 把日期往后增加一天,整数  往后推,负数往前移动
            calendar.add(Calendar.DATE, 1);
            calendar.add(Calendar.HOUR_OF_DAY, -1);
        }
        QueryWrapper<SRaAbNalysisLowCar> wrapper = new QueryWrapper<>();
        wrapper.eq(ObjectUtil.isNotNull(query.getDataId()), "data_id", query.getDataId());
        wrapper.eq(ObjectUtil.isNotNull(query.getFactoryId()), "factory_id", query.getFactoryId());
        wrapper.like(ObjectUtil.isNotEmpty(query.getFactoryName()), "factory_name", query.getFactoryName());
        wrapper.eq(ObjectUtil.isNotEmpty(query.getIndustryCategoryName()), "industry_category_name", query.getIndustryCategoryName());
        wrapper.likeRight(ObjectUtil.isNotEmpty(query.getIndustryCategoryCode()), "industry_category_code", query.getIndustryCategoryCode());
        wrapper.eq(ObjectUtil.isNotEmpty(query.getDistrictName()), "district_name", query.getDistrictName());
        wrapper.likeRight(ObjectUtil.isNotEmpty(query.getDistrictCode()), "district_code", query.getDistrictCode());
        wrapper.eq(ObjectUtil.isNotEmpty(query.getPerformanceLevel()), "performance_level", query.getPerformanceLevel());
        wrapper.eq(ObjectUtil.isNotEmpty(query.getWorkingProcedure()), "working_procedure", query.getWorkingProcedure());
        wrapper.eq(ObjectUtil.isNotNull(query.getInOutNumber()), "in_out_number", query.getInOutNumber());
        wrapper.eq(ObjectUtil.isNotNull(query.getUpdateTime()), "update_time", query.getUpdateTime());
        wrapper.eq(ObjectUtil.isNotEmpty(query.getCreateTime()), "create_time", query.getCreateTime());
        wrapper.eq(ObjectUtil.isNotNull(query.getDischargeStage()), "discharge_stage", query.getDischargeStage());
        wrapper.ge(ObjectUtil.isNotEmpty(query.getStartAnalyseTime()), "analyse_time", query.getStartAnalyseTime());
        wrapper.lt(ObjectUtil.isNotEmpty(query.getEndAnalyseTime()), "analyse_time", calendar.getTime());
        wrapper.in(ObjectUtil.isNotEmpty(query.getRegionCodes()), "district_code", query.getRegionCodes());
        wrapper.select("*","TO_CHAR(analyse_time, 'YYYY-MM-DD HH') AS analyseTimeStr");
        return wrapper;
        }
}
