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.BMainSolidWasteOutput;
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;


/**
 * 固废产生与处理对象 b_main_solid_waste_output
 *
 * @author szhpt
 * @date 2023-01-10*/
@ApiModel(value = "固废产生与处理")
@EqualsAndHashCode(callSuper = false)
@Data
public class BMainSolidWasteOutputQuery 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 materialsOutput;
    @ApiModelProperty(value = "期初贮存量")
    private String materialsPreliminaryStage;
    @ApiModelProperty(value = "累计贮存量")
    private String materialsAccumulated;
    @ApiModelProperty(value = "自行利用数量")
    private String materialsUse;
    @ApiModelProperty(value = "自行处置数量")
    private String materialsDispose;
    @ApiModelProperty(value = "委托利用数量")
    private String materialsEntrustUse;
    @ApiModelProperty(value = "委托处置数量")
    private String materialsEntrustDispose;
    /**
     *
     * @Title: getQueryWrapper
     * @Description: 查询参数组装
     * @param: @return
     * @return: QueryWrapper<BasIndustry>
     * @throws
     */
    public static QueryWrapper<BMainSolidWasteOutput> createLambdaQueryWrapper(BMainSolidWasteOutputQuery query) {
        QueryWrapper<BMainSolidWasteOutput> wrapper = new QueryWrapper<>();
        wrapper.eq(ObjectUtil.isNotNull(query.getId()), "id", query.getId());
        wrapper.eq(ObjectUtil.isNotNull(query.getFactoryId()), "factory_id", query.getFactoryId());
        wrapper.eq(ObjectUtil.isNotNull(query.getParticularYear()), "particular_year", query.getParticularYear());
        wrapper.eq(ObjectUtil.isNotNull(query.getParticularMonth()), "particular_month", query.getParticularMonth());


        if (StringUtils.isNotEmpty(query.getStartDate()) && StringUtils.isNotEmpty(query.getEndDate())) {
            DateTime startDate = DateUtil.parseDate(query.getStartDate());
            DateTime endDate = DateUtil.parseDate(query.getEndDate());
            wrapper.between("particular_year", String.valueOf(startDate.year()), String.valueOf(endDate.year()));
            wrapper.between("particular_month", String.valueOf(startDate.monthStartFromOne()), String.valueOf(endDate.monthStartFromOne()));
        }


        wrapper.eq(ObjectUtil.isNotNull(query.getMaterialsType()), "materials_type", query.getMaterialsType());
        wrapper.eq(ObjectUtil.isNotNull(query.getMaterialsCode()), "materials_code", query.getMaterialsCode());
        wrapper.eq(ObjectUtil.isNotNull(query.getMaterialsName()), "materials_name", query.getMaterialsName());
        wrapper.eq(ObjectUtil.isNotNull(query.getMaterialsOutput()), "materials_output", query.getMaterialsOutput());
        wrapper.eq(ObjectUtil.isNotNull(query.getMaterialsPreliminaryStage()), "materials_preliminary_stage", query.getMaterialsPreliminaryStage());
        wrapper.eq(ObjectUtil.isNotNull(query.getMaterialsAccumulated()), "materials_accumulated", query.getMaterialsAccumulated());
        wrapper.eq(ObjectUtil.isNotNull(query.getMaterialsUse()), "materials_use", query.getMaterialsUse());
        wrapper.eq(ObjectUtil.isNotNull(query.getMaterialsDispose()), "materials_dispose", query.getMaterialsDispose());
        wrapper.eq(ObjectUtil.isNotNull(query.getMaterialsEntrustUse()), "materials_entrust_use", query.getMaterialsEntrustUse());
        wrapper.eq(ObjectUtil.isNotNull(query.getMaterialsEntrustDispose()), "materials_entrust_dispose", query.getMaterialsEntrustDispose());

        wrapper.orderByDesc("particular_year", "particular_month");
        return wrapper;
        }
}
