package com.ningdatech.carapi.industry.model.req;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ningdatech.basic.model.PagePo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.constraints.NotNull;
import java.time.LocalDate;

/**
 * <p>
 * LabWorkerCertificateListReq
 * </p>
 *
 * @author WendyYang
 * @since 14:50 2022/11/4
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class LabWorkerCertificateListReq extends PagePo {

    @ApiModelProperty("区域ID")
    private Long regionId;

    @ApiModelProperty("企业名称")
    private String companyName;

    @ApiModelProperty("发证日期")
    private LocalDate startDate;

    @ApiModelProperty("发证日期")
    private LocalDate endDate;

    @ApiModelProperty("审核状态：0 待审核、1 已审核")
    private Integer auditStatus;

    @ApiModelProperty("证书类型：1 从业资格证、2 继续教育合格证")
    @NotNull(message = "证书类型不能为空")
    private Integer certificateType;

    public <T> QueryWrapper<T> listQuery() {
        QueryWrapper<T> query = Wrappers.query();
        if (StrUtil.isNotBlank(this.companyName)) {
            query.like("company_name", this.companyName);
        }
        if (this.startDate != null) {
            query.ge("confer_date", this.startDate);
        }
        if (this.endDate != null) {
            query.le("confer_date", this.endDate);
        }
        query.orderByDesc("update_on");
        return query;
    }

    public <T> QueryWrapper<T> changeListQuery() {
        QueryWrapper<T> query = listQuery();
        query.eq(this.auditStatus != null, "audit_status", this.auditStatus);
        return query;
    }

}
