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

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.devicecert.vo.QhseDeviceCertPageReqVO;
import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.devicecert.QhseDeviceCertDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Set;

/**
 * QHSE应检设备证书 Mapper
 *
 * @author 超级管理员
 */
@Mapper
public interface QhseDeviceCertMapper extends BaseMapperX<QhseDeviceCertDO> {

    default PageResult<QhseDeviceCertDO> selectPage(QhseDeviceCertPageReqVO reqVO, Set<Long> ids) {
        return selectPage(reqVO, new LambdaQueryWrapperX<QhseDeviceCertDO>()
                .eqIfPresent(QhseDeviceCertDO::getDeviceId, reqVO.getDeviceId())
                .inIfPresent(QhseDeviceCertDO::getDeptId, ids)
                .likeIfPresent(QhseDeviceCertDO::getDeviceName, reqVO.getDeviceName())
                .eqIfPresent(QhseDeviceCertDO::getCertNo, reqVO.getCertNo())
                .eqIfPresent(QhseDeviceCertDO::getCertOrg, reqVO.getCertOrg())
                .betweenIfPresent(QhseDeviceCertDO::getCertTime, reqVO.getCertTime())
                .betweenIfPresent(QhseDeviceCertDO::getCertExpire, reqVO.getCertExpire())
                .eqIfPresent(QhseDeviceCertDO::getFile, reqVO.getFile())
                .eqIfPresent(QhseDeviceCertDO::getCertType, reqVO.getCertType())
                .eqIfPresent(QhseDeviceCertDO::getAlertWarn, reqVO.getAlertWarn())
                .eqIfPresent(QhseDeviceCertDO::getExpired, reqVO.getExpired())
                .eqIfPresent(QhseDeviceCertDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(QhseDeviceCertDO::getCreateTime, reqVO.getCreateTime())
                .likeIfPresent(QhseDeviceCertDO::getDeptName, reqVO.getDeptName())
                .orderByDesc(QhseDeviceCertDO::getId));
    }

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