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

import cn.cecep.talroad.common.core.domain.query.PageQuery;
import cn.cecep.talroad.common.core.utils.StringUtils;
import cn.cecep.talroad.domain.analysis.SRaRealTimeAnalysisKwh;
import cn.hutool.core.collection.CollectionUtil;
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.math.BigDecimal;
import java.util.List;


/**
 * 企业用电水平分析对象 s_ra_real_time_analysis_kwh
 *
 * @author szhpt
 * @date 2023-03-24*/
@ApiModel(value = "企业用电水平分析")
@EqualsAndHashCode(callSuper = false)
@Data
public class SRaRealTimeAnalysisKwhQuery 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 String paramName;
    @ApiModelProperty(value = "区域排名")
    private Long areaRank;
    @ApiModelProperty(value = "行业排名")
    private Long industryRank;
    @ApiModelProperty(value = "是否用电大户(0-否,1-是)")
    private String largeHouse;
    @ApiModelProperty(value = "用电规模")
    private String scale;
    @ApiModelProperty(value = "单位产品用电强度")
    private String vol;
    @ApiModelProperty(value = "更新时间")
    private String updateTime;
    @ApiModelProperty(value = "创建时间(默认当前时间)")
    private String createTime;
    @ApiModelProperty(value = "年份(yyyy)")
    private String year;
    @ApiModelProperty(value = "参数编码(污染物简写)")
    private String paramCode;
    @ApiModelProperty(value = "参数单位(污染物单位)")
    private String paramUnit;
    private List<String> regionCodes;
    /**
     *
     * @Title: getQueryWrapper
     * @Description: 查询参数组装
     * @param: @return
     * @return: QueryWrapper<BasIndustry>
     * @throws
     */
    public static QueryWrapper<SRaRealTimeAnalysisKwh> createLambdaQueryWrapper(SRaRealTimeAnalysisKwhQuery query) {
        QueryWrapper<SRaRealTimeAnalysisKwh> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotEmpty(query.getDataId()), "data_id", query.getDataId());
        wrapper.eq(StringUtils.isNotEmpty(query.getFactoryId()), "factory_id", query.getFactoryId());
        wrapper.eq(StringUtils.isNotEmpty(query.getFactoryName()), "factory_name", query.getFactoryName());
        wrapper.eq(StringUtils.isNotEmpty(query.getIndustryCategoryName()), "industry_category_name", query.getIndustryCategoryName());
        wrapper.eq(StringUtils.isNotEmpty(query.getIndustryCategoryCode()), "industry_category_code", query.getIndustryCategoryCode());
        wrapper.eq(StringUtils.isNotEmpty(query.getDistrictName()), "district_name", query.getDistrictName());
        wrapper.eq(StringUtils.isNotEmpty(query.getDistrictCode()), "district_code", query.getDistrictCode());
        wrapper.in(CollectionUtil.isNotEmpty(query.getRegionCodes()), "district_code", query.getRegionCodes());
        wrapper.eq(StringUtils.isNotEmpty(query.getParamName()), "param_name", query.getParamName());
        wrapper.eq(ObjectUtil.isNotNull(query.getAreaRank()), "area_rank", query.getAreaRank());
        wrapper.eq(ObjectUtil.isNotNull(query.getIndustryRank()), "industry_rank", query.getIndustryRank());
        wrapper.eq(StringUtils.isNotEmpty(query.getLargeHouse()), "large_house", query.getLargeHouse());
        wrapper.eq(StringUtils.isNotEmpty(query.getVol()), "vol", query.getVol());
        wrapper.eq(StringUtils.isNotEmpty(query.getUpdateTime()), "update_time", query.getUpdateTime());
        wrapper.eq(StringUtils.isNotEmpty(query.getCreateTime()), "create_time", query.getCreateTime());
        wrapper.eq(StringUtils.isNotEmpty(query.getYear()), "year", query.getYear());
        wrapper.eq(StringUtils.isNotEmpty(query.getParamCode()), "param_code", query.getParamCode());
        wrapper.eq(StringUtils.isNotEmpty(query.getParamUnit()), "param_unit", query.getParamUnit());
        if(StringUtils.isNotEmpty(query.getScale())){
            wrapper.apply(cn.cecep.talroad.common.core.utils.StringUtils.isNotEmpty(query.getScale()), "CAST(scale AS NUMERIC) >= {0}", new BigDecimal(query.getScale().split("-")[0]));
            wrapper.apply(cn.cecep.talroad.common.core.utils.StringUtils.isNotEmpty(query.getScale()), "CAST(scale AS NUMERIC) <= {0}", new BigDecimal(query.getScale().split("-")[1]));
        }
        return wrapper;
        }
}
