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.BMainHazardousWasteOutput;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
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;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * 危废产生与处理对象 b_main_hazardous_waste_output
 *
 * @author szhpt
 * @date 2023-01-10
 */
@ApiModel(value = "危废产生与处理")
@EqualsAndHashCode(callSuper = false)
@Data
public class BMainHazardousWasteOutputQuery extends PageQuery {

    @ApiModelProperty(value = "主键id")
    private String id;
    @ApiModelProperty(value = "企业id")
    private String factoryId;
    @ApiModelProperty(value = "年份")
    private String particularYear;
    @ApiModelProperty(value = "月份")
    private String particularMonth;

    @ApiModelProperty(value = "开始年月")
    private String startDate;
    @ApiModelProperty(value = "结束年月")
    private String endDate;

    @ApiModelProperty(value = "废物类别")
    private String materialsType;
    @ApiModelProperty(value = "废物代码")
    private String materialsCode;
    @ApiModelProperty(value = "废物名称")
    private String materialsName;
    @ApiModelProperty(value = "上月贮存量")
    private String materialsLastMonth;
    @ApiModelProperty(value = "产生量")
    private String materialsOutput;
    @ApiModelProperty(value = "修正量")
    private String materialsAllowance;
    @ApiModelProperty(value = "转移量")
    private String materialsAsFollows;
    @ApiModelProperty(value = "利用处置量")
    private String materialsUse;
    @ApiModelProperty(value = "期末库存")
    private String materialsRepertory;
    @ApiModelProperty(value = "期末超一年库存")
    private String materialsRepertoryYear;

    /**
     * @throws
     * @Title: getQueryWrapper
     * @Description: 查询参数组装
     * @param: @return
     * @return: QueryWrapper<BasIndustry>
     */
    public static QueryWrapper<BMainHazardousWasteOutput> createLambdaQueryWrapper(BMainHazardousWasteOutputQuery query) {
        QueryWrapper<BMainHazardousWasteOutput> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotEmpty(query.getId()), "id", query.getId());
        wrapper.eq(StringUtils.isNotEmpty(query.getFactoryId()), "factory_id", query.getFactoryId());
        wrapper.eq(StringUtils.isNotEmpty(query.getParticularYear()), "particular_year", query.getParticularYear());
        wrapper.eq(StringUtils.isNotEmpty(query.getParticularMonth()), "particular_month", query.getParticularMonth());
        if (StringUtils.isNotEmpty(query.getStartDate()) && StringUtils.isNotEmpty(query.getEndDate())) {
            wrapper.between("particular_year || '-'||particular_month",query.getStartDate(), query.getEndDate());
        }
        if(StringUtils.isNotEmpty(query.getMaterialsType())){
            String[] split = query.getMaterialsType().split(",");
            wrapper.in(StringUtils.isNotEmpty(query.getMaterialsType()), "materials_type",split);
        }
        wrapper.eq(StringUtils.isNotEmpty(query.getMaterialsCode()), "materials_code", query.getMaterialsCode());
        wrapper.like(StringUtils.isNotEmpty(query.getMaterialsName()), "materials_name", query.getMaterialsName());
        wrapper.eq(StringUtils.isNotEmpty(query.getMaterialsLastMonth()), "materials_last_month", query.getMaterialsLastMonth());
        wrapper.eq(StringUtils.isNotEmpty(query.getMaterialsOutput()), "materials_output", query.getMaterialsOutput());
        wrapper.eq(StringUtils.isNotEmpty(query.getMaterialsAllowance()), "materials_allowance", query.getMaterialsAllowance());
        wrapper.eq(StringUtils.isNotEmpty(query.getMaterialsAsFollows()), "materials_as_follows", query.getMaterialsAsFollows());
        wrapper.eq(StringUtils.isNotEmpty(query.getMaterialsUse()), "materials_use", query.getMaterialsUse());
        wrapper.eq(StringUtils.isNotEmpty(query.getMaterialsRepertory()), "materials_repertory", query.getMaterialsRepertory());
        wrapper.eq(StringUtils.isNotEmpty(query.getMaterialsRepertoryYear()), "materials_repertory_year", query.getMaterialsRepertoryYear());
        wrapper.orderByDesc("particular_year", "particular_month::varchar");
        return wrapper;
    }
}
