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

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.task.vo.TaskPageReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.task.vo.TaskStatusEnum;
import cn.iocoder.yudao.module.mes.dal.dataobject.task.TaskDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 生产任务单 Mapper
 *
 * @author 内蒙必硕
 */
@Mapper
public interface TaskMapper extends BaseMapperX<TaskDO> {

    default PageResult<TaskDO> selectPage(TaskPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<TaskDO>()
                .eqIfPresent(TaskDO::getCode, reqVO.getCode())
                .betweenIfPresent(TaskDO::getOrderDate, reqVO.getOrderDate())
                .betweenIfPresent(TaskDO::getDeliveryDate, reqVO.getDeliveryDate())
                .eqIfPresent(TaskDO::getStatus, reqVO.getStatus())
                .eqIfPresent(TaskDO::getProcessInstanceId, reqVO.getProcessInstanceId())
                .eqIfPresent(TaskDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(TaskDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(TaskDO::getId));
    }

    default PageResult<TaskDO> selectPage2(TaskPageReqVO reqVO) {

        return selectPage(reqVO, new LambdaQueryWrapperX<TaskDO>()
                .eqIfPresent(TaskDO::getCode, reqVO.getCode())
                .betweenIfPresent(TaskDO::getOrderDate, reqVO.getOrderDate())
                .betweenIfPresent(TaskDO::getDeliveryDate, reqVO.getDeliveryDate())
                .inIfPresent(TaskDO::getStatus, TaskStatusEnum.getEnablePlanStatus())
                .eqIfPresent(TaskDO::getStatus, reqVO.getStatus())
                .eqIfPresent(TaskDO::getProcessInstanceId, reqVO.getProcessInstanceId())
                .eqIfPresent(TaskDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(TaskDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(TaskDO::getId));
    }

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

    default List<TaskDO> selectList(List<Integer> status) {
        return selectList(TaskDO::getStatus, status);
    }
}