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.IotMeasureCertPageReqVO;
import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.cert.IotMeasureCertDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;
import java.util.Set;

/**
 * 计量器具-证书管理 Mapper
 *
 * @author 超级管理员
 */
@Mapper
public interface IotMeasureCertMapper extends BaseMapperX<IotMeasureCertDO> {

    default PageResult<IotMeasureCertDO> selectPage(IotMeasureCertPageReqVO reqVO, Set<Long> ids ) {
        return selectPage(reqVO, new LambdaQueryWrapperX<IotMeasureCertDO>()
                .eqIfPresent(IotMeasureCertDO::getType, reqVO.getType())
                .eqIfPresent(IotMeasureCertDO::getClassify, reqVO.getClassify())
                .eqIfPresent(IotMeasureCertDO::getCertBelong, reqVO.getCertBelong())
                .eqIfPresent(IotMeasureCertDO::getCertOrg, reqVO.getCertOrg())
                .eqIfPresent(IotMeasureCertDO::getCertStandard, reqVO.getCertStandard())
                .eqIfPresent(IotMeasureCertDO::getCertIssue, reqVO.getCertIssue())
                .eqIfPresent(IotMeasureCertDO::getCertExpire, reqVO.getCertExpire())
                .likeIfPresent(IotMeasureCertDO::getUserName, reqVO.getUserName())
                .eqIfPresent(IotMeasureCertDO::getExpired, reqVO.getExpired())
                .eqIfPresent(IotMeasureCertDO::getNoticeBefore, reqVO.getNoticeBefore())
                .eqIfPresent(IotMeasureCertDO::getCertPic, reqVO.getCertPic())
                .eqIfPresent(IotMeasureCertDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(IotMeasureCertDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(IotMeasureCertDO::getAlertWarn, reqVO.getAlertWarn())
                .inIfPresent(IotMeasureCertDO::getDeptId, ids)
                .orderByDesc(IotMeasureCertDO::getId));
    }

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

    default List<IotMeasureCertDO> selectListByDept(IotMeasureCertPageReqVO reqVO, Set<Long> ids) {
        return selectList(new LambdaQueryWrapperX<IotMeasureCertDO>()
                .eqIfPresent(IotMeasureCertDO::getExpired, reqVO.getExpired())
                .inIfPresent(IotMeasureCertDO::getDeptId, ids));
    }
}