package cn.cecep.talroad.vo.query;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import cn.cecep.talroad.domain.EarlyWarning;
import cn.cecep.talroad.common.core.domain.query.PageQuery;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;
import java.util.List;


/**
 * 管控浓度超标预警对象 early_warning
 *
 * @author szhpt
 * @date 2023-04-24*/
@ApiModel(value = "管控浓度超标预警")
@EqualsAndHashCode(callSuper = false)
@Data
public class EarlyWarningQuery extends PageQuery
{

    @ApiModelProperty(value = "主键")
    private String ewId;
    @ApiModelProperty(value = "企业id")
    private String factoryId;
    @ApiModelProperty(value = "行业编码")
    private String industryCode;
    @ApiModelProperty(value = "在线监测点位id")
    private String stationId;
    @ApiModelProperty(value = "预警时间")
    private Date warningTime;
    @ApiModelProperty(value = "预警内容")
    private String warningContent;
    @ApiModelProperty(value = "入库时间")
    private String createTime;
    @ApiModelProperty(value = "企业名称")
    private String factoryName;
    @ApiModelProperty(value = "在线监测点位名称")
    private String stationName;
    @ApiModelProperty(value = "区县编码")
    private String countryCode;
    @ApiModelProperty(value = "区县名称")
    private String countryName;
    @ApiModelProperty(value = "预警开始时间")
    private String startWarningTime;
    @ApiModelProperty(value = "预警结束时间")
    private String endWarningTime;
    private List<String> regionCodes;
    /**
     *
     * @Title: getQueryWrapper
     * @Description: 查询参数组装
     * @param: @return
     * @return: QueryWrapper<BasIndustry>
     * @throws
     */
    public static QueryWrapper<EarlyWarning> createLambdaQueryWrapper(EarlyWarningQuery query) {
        QueryWrapper<EarlyWarning> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(query.getEwId()), "ew_id", query.getEwId());
        wrapper.eq(StringUtils.isNotBlank(query.getFactoryId()), "factory_id", query.getFactoryId());
        wrapper.eq(StringUtils.isNotBlank(query.getIndustryCode()), "industry_code", query.getIndustryCode());
        wrapper.eq(StringUtils.isNotBlank(query.getStationId()), "station_id", query.getStationId());
        wrapper.between(StringUtils.isNotBlank(query.getStartWarningTime())&&StringUtils.isNotBlank(query.getEndWarningTime()),"warning_time", DateUtil.parse(query.getStartWarningTime(),"yyyy-MM-dd HH:mm:ss"),DateUtil.parse(query.getEndWarningTime(),"yyyy-MM-dd HH:mm:ss"));
        wrapper.eq(StringUtils.isNotBlank(query.getWarningContent()), "warning_content", query.getWarningContent());
        wrapper.eq(StringUtils.isNotBlank(query.getCreateTime()), "create_time", query.getCreateTime());
        wrapper.like(StringUtils.isNotBlank(query.getFactoryName()), "factory_name", query.getFactoryName());
        wrapper.like(StringUtils.isNotBlank(query.getStationName()), "station_name", query.getStationName());
        wrapper.eq(StringUtils.isNotBlank(query.getCountryCode()), "country_code", query.getCountryCode());
        wrapper.in(CollectionUtil.isNotEmpty(query.getRegionCodes()), "country_code", query.getRegionCodes());
        wrapper.eq(StringUtils.isNotBlank(query.getCountryName()), "country_name", query.getCountryName());
        return wrapper;
        }
}
