package cn.iocoder.yudao.module.pms.dal.mysql.iotmaterialrequisition;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
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.iotmaterialrequisition.vo.IotMaterialRequisitionPageReqVO;
import cn.iocoder.yudao.module.pms.dal.dataobject.iotmaterialrequisition.IotMaterialRequisitionDO;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 物料领用 Mapper
 *
 * @author ruiqi
 */
@Mapper
public interface IotMaterialRequisitionMapper extends BaseMapperX<IotMaterialRequisitionDO> {

    default PageResult<IotMaterialRequisitionDO> selectPage(IotMaterialRequisitionPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<IotMaterialRequisitionDO>()
                .eqIfPresent(IotMaterialRequisitionDO::getDeptId, reqVO.getDeptId())
                .eqIfPresent(IotMaterialRequisitionDO::getRequisitionNumber, reqVO.getRequisitionNumber())
                .likeIfPresent(IotMaterialRequisitionDO::getName, reqVO.getName())
                .eqIfPresent(IotMaterialRequisitionDO::getType, reqVO.getType())
                .eqIfPresent(IotMaterialRequisitionDO::getResponsiblePerson, reqVO.getResponsiblePerson())
                .eqIfPresent(IotMaterialRequisitionDO::getCost, reqVO.getCost())
                .eqIfPresent(IotMaterialRequisitionDO::getResult, reqVO.getResult())
                .eqIfPresent(IotMaterialRequisitionDO::getOtherCost, reqVO.getOtherCost())
                .eqIfPresent(IotMaterialRequisitionDO::getLaborCost, reqVO.getLaborCost())
                .betweenIfPresent(IotMaterialRequisitionDO::getRequisitionTime, reqVO.getRequisitionTime())
                .eqIfPresent(IotMaterialRequisitionDO::getReason, reqVO.getReason())
                .eqIfPresent(IotMaterialRequisitionDO::getRemark, reqVO.getRemark())
                .eqIfPresent(IotMaterialRequisitionDO::getStatus, reqVO.getStatus())
                .eqIfPresent(IotMaterialRequisitionDO::getProcessInstanceId, reqVO.getProcessInstanceId())
                .eqIfPresent(IotMaterialRequisitionDO::getAuditStatus, reqVO.getAuditStatus())
                .betweenIfPresent(IotMaterialRequisitionDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(IotMaterialRequisitionDO::getId));
    }

    /**
     * 查询指定角色 指定部门的人员 （需要过滤掉数据权限）
     *
     * @param roleCode
     * @param deptId
     * @return
     */
    @DataPermission(enable = false)
    List<AdminUserRespDTO> msgReceiveUsers(@Param("roleCode") String roleCode, @Param("deptId") Long deptId);

}