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

import cn.cecep.talroad.common.core.annotation.Excel;
import cn.cecep.talroad.common.core.domain.query.PageQuery;
import cn.cecep.talroad.common.core.utils.StringUtils;
import cn.cecep.talroad.domain.analysis.SRaEmissionsStandard;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
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.math.BigDecimal;
import java.util.List;


/**
 * 企业排放水平分析对象 s_ra_emissions_standard
 *
 * @author szhpt
 * @date 2023-03-24*/
@ApiModel(value = "企业排放水平分析")
@EqualsAndHashCode(callSuper = false)
@Data
public class SRaEmissionsStandardQuery extends PageQuery
{



    @ApiModelProperty(value = "主键")
    /** 主键 */
    @TableId(value = "id",type = IdType.UUID)
    private String id;


    @ApiModelProperty(value = "企业id")
    /** 企业id */
    private String factoryId;


    @ApiModelProperty(value = "企业名称")
    /** 企业名称 */
    @Excel(name = "企业名称")
    private String factoryName;


    @ApiModelProperty(value = "行业类别名称(多个使用''、''拼接)")
    /** 行业类别名称(多个使用''、''拼接) */
    @Excel(name = "行业名称")
    private String industryCategoryName;


    @ApiModelProperty(value = "行业类别编码(多个使用''、''拼接)")
    /** 行业类别编码(多个使用''、''拼接) */
    private String industryCategoryCode;


    @ApiModelProperty(value = "区域名称")
    /** 区域名称 */
    @Excel(name = "区县名称")
    private String districtName;


    @ApiModelProperty(value = "区域编码")
    /** 区域编码 */
    private String districtCode;


    @ApiModelProperty(value = "分析年份")
    /** 分析年份 */
    @Excel(name = "分析年份")
    private String analyseYear;


    @ApiModelProperty(value = "参数名称")
    /** 参数名称 */
    @Excel(name = "参数名称")
    private String pollutantName;


    @ApiModelProperty(value = "区域排名")
    /** 区域排名 */
    @Excel(name = "区域排名")
    private String regionRanking;


    @ApiModelProperty(value = "行业排名")
    /** 行业排名 */
    @Excel(name = "行业排名")
    private String industryRanking;


    @ApiModelProperty(value = "是否排放大户(0-否, 1-是)")
    /** 是否排放大户 */
    @Excel(name = "是否排放大户", readConverterExp = "0=否,1=是")
    private String isEmissionsBigUser;


    @ApiModelProperty(value = "排放规模")
    /** 排放规模 */
    @Excel(name = "排放规模")
    private String emissionsScale;


    @ApiModelProperty(value = "单位产品排放量强度")
    /** 单位产品排放量强度 */
    @Excel(name = "单位产品排放量强度")
    private String unitEmissions;

    private List<String> regionCodes;
    /**
     *
     * @Title: getQueryWrapper
     * @Description: 查询参数组装
     * @param: @return
     * @return: QueryWrapper<BasIndustry>
     * @throws
     */
    public static QueryWrapper<SRaEmissionsStandard> createLambdaQueryWrapper(SRaEmissionsStandardQuery query) {
        QueryWrapper<SRaEmissionsStandard> wrapper = new QueryWrapper<>();
        wrapper.eq(ObjectUtil.isNotNull(query.getId()), "id", query.getId());
        wrapper.eq(ObjectUtil.isNotNull(query.getFactoryId()), "factory_id", query.getFactoryId());
        wrapper.eq(StringUtils.isNotEmpty(query.getAnalyseYear()), "analyse_year", query.getAnalyseYear());
        wrapper.eq(StringUtils.isNotEmpty(query.getPollutantName()), "pollutant_name", query.getPollutantName());
        wrapper.eq(StringUtils.isNotEmpty(query.getRegionRanking()), "region_ranking", query.getRegionRanking());
        wrapper.eq(StringUtils.isNotEmpty(query.getIndustryRanking()), "industry_ranking", query.getIndustryRanking());
        wrapper.eq(StringUtils.isNotEmpty(query.getIsEmissionsBigUser()), "is_emissions_big_user", query.getIsEmissionsBigUser());
        if(StringUtils.isNotEmpty(query.getEmissionsScale())){
            wrapper.apply(StringUtils.isNotEmpty(query.getEmissionsScale()), "CAST(emissions_scale AS NUMERIC) >= {0}", new BigDecimal(query.getEmissionsScale().split("-")[0]));
            wrapper.apply(StringUtils.isNotEmpty(query.getEmissionsScale()), "CAST(emissions_scale AS NUMERIC) <= {0}", new BigDecimal(query.getEmissionsScale().split("-")[1]));
        }
        wrapper.eq(StringUtils.isNotEmpty(query.getUnitEmissions()), "unit_emissions", query.getUnitEmissions());
        wrapper.like(StringUtils.isNotEmpty(query.getFactoryName()), "factory_name", query.getFactoryName());
        wrapper.like(StringUtils.isNotEmpty(query.getIndustryCategoryName()), "industry_category_name", query.getIndustryCategoryName());
        wrapper.like(StringUtils.isNotEmpty(query.getDistrictName()), "district_name", query.getDistrictName());
        wrapper.like(StringUtils.isNotEmpty(query.getDistrictCode()), "district_code", query.getDistrictCode());
        wrapper.in(CollectionUtil.isNotEmpty(query.getRegionCodes()), "district_code", query.getRegionCodes());
        return wrapper;
        }
}
