package cn.cecep.talroad.vo.query;

import cn.cecep.talroad.common.core.domain.query.PageQuery;
import cn.cecep.talroad.common.core.utils.StringUtils;
import cn.cecep.talroad.domain.SEnvGasReal;
import cn.cecep.talroad.vo.AmProblemFiVo;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;


/**
 * 无组织监控数据对象 s_env_gas_real
 *
 * @author szhpt
 * @date 2023-01-10*/
@ApiModel(value = "无组织监控数据")
@EqualsAndHashCode(callSuper = false)
@Data
public class SEnvGasRealQuery extends PageQuery
{

    @ApiModelProperty(value = "主键id")
    private String id;
    @ApiModelProperty(value = "排口id")
    private String outletId;
    @ApiModelProperty(value = "监测点位名称")
    private String stationName;
    @ApiModelProperty(value = "对应许可证无组织监测点位名称")
    private String licenceStationName;
    @ApiModelProperty(value = "开始日期")
    private String monitoringStartTime;
    @ApiModelProperty(value = "结束日期")
    private String monitoringEndTime;
    @ApiModelProperty(value = "PM10")
    private String pm10;
    @ApiModelProperty(value = "PM2.5")
    private String pm25;
    @ApiModelProperty(value = "TSP")
    private String tsp;
    @ApiModelProperty(value = "NMHC")
    private String nmhc;
    @ApiModelProperty(value = "甲烷")
    private String ch4;
    @ApiModelProperty(value = "总烃")
    private String hydrocarbon;
    @ApiModelProperty(value = "苯")
    private String benzene;
    @ApiModelProperty(value = "甲苯")
    private String methylbenzene;
    @ApiModelProperty(value = "温度")
    private String temperature;
    @ApiModelProperty(value = "湿度")
    private String humidity;
    @ApiModelProperty(value = "风向")
    private String windDirection;
    @ApiModelProperty(value = "风速")
    private String windSpeed;
    @ApiModelProperty(value = "大气压")
    private String barometricPressure;

    @ApiModelProperty(value = "时间类型")
    private String dataType;
    @ApiModelProperty(value = "企业id")
    private String factoryId;

    @ApiModelProperty(value = "asc/desc")
    private String ascOrDesc = "desc";

    @ApiModelProperty(value = "曲线图返回指定的污染物")
    private List<AmProblemFiVo.PollutantVo> pollutantVos;

    /**
     *
     * @Title: getQueryWrapper
     * @Description: 查询参数组装
     * @param: @return
     * @return: QueryWrapper<BasIndustry>
     * @throws
     */
    public static QueryWrapper<SEnvGasReal> createLambdaQueryWrapper(SEnvGasRealQuery query) {

        String format;
        switch (query.getDataType()) {
            default:
                format = "yyyy-MM-dd HH:mm:ss";
                break;
            case "D":
                // 天
                format = "yyyy-MM-dd";
                break;
            case "H":
                // 小时
                format = "yyyy-MM-dd HH";
                break;
            case "M":
                // 分钟
                format = "yyyy-MM-dd HH:mm";
                break;
        }

        QueryWrapper<SEnvGasReal> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotEmpty(query.getOutletId()), "outlet_id", query.getOutletId());
        wrapper.eq(StringUtils.isNotEmpty(query.getStationName()), "station_name", query.getStationName());
        wrapper.eq(StringUtils.isNotEmpty(query.getLicenceStationName()), "licence_station_name", query.getLicenceStationName());

        if (StringUtils.isNotEmpty(query.getMonitoringStartTime()) && StringUtils.isNotEmpty(query.getMonitoringEndTime())) {
            DateTime monitoringStartTime = DateUtil.parse(query.getMonitoringStartTime(), format);
            DateTime monitoringEndTime = DateUtil.parse(query.getMonitoringEndTime(), format);

            wrapper.between("monitoring_time", monitoringStartTime.toString(), monitoringEndTime.toString());
        }

        wrapper.eq(ObjectUtil.isNotNull(query.getPm10()), "pm10", query.getPm10());
        wrapper.eq(ObjectUtil.isNotNull(query.getPm25()), "pm25", query.getPm25());
        wrapper.eq(ObjectUtil.isNotNull(query.getTsp()), "tsp", query.getTsp());
        wrapper.eq(ObjectUtil.isNotNull(query.getNmhc()), "nmhc", query.getNmhc());
        wrapper.eq(ObjectUtil.isNotNull(query.getCh4()), "ch4", query.getCh4());
        wrapper.eq(ObjectUtil.isNotNull(query.getHydrocarbon()), "hydrocarbon", query.getHydrocarbon());
        wrapper.eq(ObjectUtil.isNotNull(query.getBenzene()), "benzene", query.getBenzene());
        wrapper.eq(ObjectUtil.isNotNull(query.getMethylbenzene()), "methylbenzene", query.getMethylbenzene());
        wrapper.eq(ObjectUtil.isNotNull(query.getTemperature()), "temperature", query.getTemperature());
        wrapper.eq(ObjectUtil.isNotNull(query.getHumidity()), "humidity", query.getHumidity());
        wrapper.eq(ObjectUtil.isNotNull(query.getWindDirection()), "wind_direction", query.getWindDirection());
        wrapper.eq(ObjectUtil.isNotNull(query.getWindSpeed()), "wind_speed", query.getWindSpeed());
        wrapper.eq(ObjectUtil.isNotNull(query.getBarometricPressure()), "barometric_pressure", query.getBarometricPressure());
        wrapper.eq(ObjectUtil.isNotNull(query.getDataType()), "data_type", query.getDataType());
        wrapper.eq(ObjectUtil.isNotEmpty(query.getFactoryId()), "factory_id", query.getFactoryId());
        if(!StringUtils.isEmpty(query.getAscOrDesc())){
            if(query.getAscOrDesc().equalsIgnoreCase("asc")){
                wrapper.orderByAsc("monitoring_time");
            } else if (query.getAscOrDesc().equalsIgnoreCase("desc")){
                wrapper.orderByDesc("monitoring_time");
            }
        }
        return wrapper;
    }
}
