package cn.cecep.talroad.vo.query;

import cn.cecep.talroad.common.core.domain.query.PageQuery;
import cn.cecep.talroad.common.core.utils.DateUtils;
import cn.cecep.talroad.common.core.utils.StringUtils;
import cn.cecep.talroad.domain.BEnterpriseIrBusinessAlerts;
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 javax.validation.constraints.NotBlank;
import java.text.ParseException;
import java.util.Date;


/**
 * 通知提醒-业务提醒对象 b_enterprise_ir_business_alerts
 *
 * @author szhpt
 * @date 2023-03-14*/
@ApiModel(value = "通知提醒-业务提醒")
@EqualsAndHashCode(callSuper = false)
@Data
public class BEnterpriseIrBusinessAlertsQuery extends PageQuery
{

    @ApiModelProperty(value = "通知提醒主键")
    private Long businessId;
    @ApiModelProperty(value = "企业id")
    @NotBlank(message = "请指定查询企业主键")
    private String factoryId;
    @ApiModelProperty(value = "业务类型")
    private String businessType;
    @ApiModelProperty(value = "提醒内容")
    private String businessDetails;
    @ApiModelProperty(value = "提醒日期")
    private Date businessTime;
    @ApiModelProperty(value = "状态")
    private String status;

    @ApiModelProperty(value = "检索开始时间(yyyy-MM-dd)")
    private String searchBeginTime;

    @ApiModelProperty(value = "检索截至时间(yyyy-MM-dd)")
    private String searchEndTime;
    /**
     *
     * @Title: getQueryWrapper
     * @Description: 查询参数组装
     * @param: @return
     * @return: QueryWrapper<BasIndustry>
     * @throws
     */
    public static QueryWrapper<BEnterpriseIrBusinessAlerts> createLambdaQueryWrapper(BEnterpriseIrBusinessAlertsQuery query) throws ParseException {
        QueryWrapper<BEnterpriseIrBusinessAlerts> wrapper = new QueryWrapper<>();
        wrapper.eq(ObjectUtil.isNotNull(query.getBusinessId()), "business_id", query.getBusinessId());
        wrapper.eq(StringUtils.isNotEmpty(query.getFactoryId()), "factory_id", query.getFactoryId());
        wrapper.eq(StringUtils.isNotEmpty(query.getBusinessType()), "business_type", query.getBusinessType());
        wrapper.like(StringUtils.isNotEmpty(query.getBusinessDetails()), "business_details", query.getBusinessDetails());
        wrapper.eq(ObjectUtil.isNotNull(query.getBusinessTime()), "business_time", query.getBusinessTime());
        wrapper.eq(StringUtils.isNotEmpty(query.getStatus()), "status", query.getStatus());
        wrapper.eq("del_flag", "0");
        wrapper.between(ObjectUtil.isNotEmpty(query.getSearchBeginTime()) && ObjectUtil.isNotEmpty(query.getSearchEndTime()), "business_time", ObjectUtil.isNotEmpty(query.getSearchBeginTime()) ? DateUtils.parseDate(query.getSearchBeginTime(), DateUtils.YYYY_MM_DD) : query.getSearchBeginTime(), ObjectUtil.isNotEmpty(query.getSearchEndTime()) ? DateUtils.parseDate(query.getSearchEndTime()+" 23:59:59", DateUtils.YYYY_MM_DD_HH_MM_SS) : query.getSearchEndTime());
        wrapper.orderByDesc("business_time");
        return wrapper;
        }
}
