package cn.iocoder.yudao.module.pms.dal.mysql.qhse.cert;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.pms.controller.admin.qhse.cert.vo.QhseOrgCertPageReqVO;
import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.cert.QhseOrgCertDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Set;

/**
 * QHSE组织证书管理 Mapper
 *
 * @author 超级管理员
 */
@Mapper
public interface QhseOrgCertMapper extends BaseMapperX<QhseOrgCertDO> {

    default PageResult<QhseOrgCertDO> selectPage(QhseOrgCertPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<QhseOrgCertDO>()
                .eqIfPresent(QhseOrgCertDO::getClassify, reqVO.getClassify())
                .eqIfPresent(QhseOrgCertDO::getCertBelong, reqVO.getCertBelong())
                .eqIfPresent(QhseOrgCertDO::getCertOrg, reqVO.getCertOrg())
                .eqIfPresent(QhseOrgCertDO::getCertStandard, reqVO.getCertStandard())
                .eqIfPresent(QhseOrgCertDO::getCertIssue, reqVO.getCertIssue())
                .eqIfPresent(QhseOrgCertDO::getCertExpire, reqVO.getCertExpire())
                .eqIfPresent(QhseOrgCertDO::getNoticeBefore, reqVO.getNoticeBefore())
                .eqIfPresent(QhseOrgCertDO::getCertPic, reqVO.getCertPic())
                .eqIfPresent(QhseOrgCertDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(QhseOrgCertDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(QhseOrgCertDO::getDeptId, reqVO.getDeptId())
                .eqIfPresent(QhseOrgCertDO::getUserId, reqVO.getUserId())
                .eqIfPresent(QhseOrgCertDO::getExpired, reqVO.getExpired())
                .likeIfPresent(QhseOrgCertDO::getCertName, reqVO.getCertName())
                .eqIfPresent(QhseOrgCertDO::getAlertWarn, reqVO.getAlertWarn())
                .orderByDesc(QhseOrgCertDO::getId));
    }

    default Long selectCountByDeptAndExpireAndWarn(QhseOrgCertPageReqVO reqVO, Set<Long> ids) {
        return selectCount(new LambdaQueryWrapperX<QhseOrgCertDO>()
                .eqIfPresent(QhseOrgCertDO::getExpired, reqVO.getExpired())
                .eqIfPresent(QhseOrgCertDO::getAlertWarn, reqVO.getAlertWarn())
                .inIfPresent(QhseOrgCertDO::getDeptId, ids)
                .betweenIfPresent(QhseOrgCertDO::getCreateTime, reqVO.getCreateTime()));
    }
}