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

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

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

/**
 * QHSE_PTW作业许可 Mapper
 *
 * @author 超级管理员
 */
@Mapper
public interface QhsePtwMapper extends BaseMapperX<QhsePtwDO> {

    default PageResult<QhsePtwDO> selectPage(QhsePtwPageReqVO reqVO, Set<Long> ids) {
        return selectPage(reqVO, new LambdaQueryWrapperX<QhsePtwDO>()
                .eqIfPresent(QhsePtwDO::getPtwNo, reqVO.getPtwNo())
                .betweenIfPresent(QhsePtwDO::getPtwTime, reqVO.getPtwTime())
                .eqIfPresent(QhsePtwDO::getPtwXh, reqVO.getPtwXh())
                .eqIfPresent(QhsePtwDO::getPtwType, reqVO.getPtwType())
                .eqIfPresent(QhsePtwDO::getPtwGrade, reqVO.getPtwGrade())
                .eqIfPresent(QhsePtwDO::getWorkLocation, reqVO.getWorkLocation())
                .eqIfPresent(QhsePtwDO::getWorkContent, reqVO.getWorkContent())
                .eqIfPresent(QhsePtwDO::getWorkPerson, reqVO.getWorkPerson())
                .eqIfPresent(QhsePtwDO::getGuardian, reqVO.getGuardian())
                .eqIfPresent(QhsePtwDO::getWorkDuty, reqVO.getWorkDuty())
                .eqIfPresent(QhsePtwDO::getJsaId, reqVO.getJsaId())
                .inIfPresent(QhsePtwDO::getDeptId, ids)
                .likeIfPresent(QhsePtwDO::getDeptName, reqVO.getDeptName())
                .eqIfPresent(QhsePtwDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(QhsePtwDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(QhsePtwDO::getFile, reqVO.getFile())
                .orderByDesc(QhsePtwDO::getId));
    }

    default List<QhsePtwDO> selectListByDept(QhsePtwPageReqVO reqVO, Set<Long> ids) {
        return selectList(new LambdaQueryWrapperX<QhsePtwDO>()
                .eq(QhsePtwDO::getDeleted, false)
                .betweenIfPresent(QhsePtwDO::getCreateTime, reqVO.getCreateTime())
                .inIfPresent(QhsePtwDO::getDeptId, ids));
    }

    default Long selectCountByDeptAndTime(QhsePtwPageReqVO reqVO, Set<Long> ids) {
        return selectCount(new LambdaQueryWrapperX<QhsePtwDO>()
                .inIfPresent(QhsePtwDO::getDeptId, ids)
                .betweenIfPresent(QhsePtwDO::getPtwTime, reqVO.getPtwTime()));
    }
}