package cn.iocoder.yudao.module.mes.dal.mysql.itemrequisition;

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.mes.controller.admin.itemrequisition.vo.ItemRequisitionPageReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.itemrequisition.ItemRequisitionDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 生产领料 Mapper
 *
 * @author 内蒙必硕
 */
@Mapper
public interface ItemRequisitionMapper extends BaseMapperX<ItemRequisitionDO> {

    default PageResult<ItemRequisitionDO> selectPage(ItemRequisitionPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ItemRequisitionDO>()
                .eqIfPresent(ItemRequisitionDO::getCode, reqVO.getCode())
                .betweenIfPresent(ItemRequisitionDO::getRequisitionDate, reqVO.getRequisitionDate())
                .betweenIfPresent(ItemRequisitionDO::getDeliveryDate, reqVO.getDeliveryDate())
                .eqIfPresent(ItemRequisitionDO::getStatus, reqVO.getStatus())
                .eqIfPresent(ItemRequisitionDO::getProcessInstanceId, reqVO.getProcessInstanceId())
                .eqIfPresent(ItemRequisitionDO::getPlanId, reqVO.getPlanId())
                .eqIfPresent(ItemRequisitionDO::getWorkerId, reqVO.getWorkerId())
                .eqIfPresent(ItemRequisitionDO::getRemark, reqVO.getRemark())
                .eqIfPresent(ItemRequisitionDO::getIsEnable, reqVO.getIsEnable())
                .betweenIfPresent(ItemRequisitionDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ItemRequisitionDO::getId));
    }

    default ItemRequisitionDO selectByNo(String no) {
        return selectOne(ItemRequisitionDO::getCode, no);
    }

    default ItemRequisitionDO selectByPlanId(Long planId) {
        return selectOne(ItemRequisitionDO::getPlanId, planId);
    }
}