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

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.producereport.vo.ProduceReportPageReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.producereport.ProduceReportDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 生产报工单 Mapper
 *
 * @author 内蒙必硕
 */
@Mapper
public interface ProduceReportMapper extends BaseMapperX<ProduceReportDO> {

    default PageResult<ProduceReportDO> selectPage(ProduceReportPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ProduceReportDO>()
                .eqIfPresent(ProduceReportDO::getProcessInstanceId, reqVO.getProcessInstanceId())
                .eqIfPresent(ProduceReportDO::getReportCode, reqVO.getReportCode())
                .eqIfPresent(ProduceReportDO::getUserId, reqVO.getUserId())
                .eqIfPresent(ProduceReportDO::getOrgId, reqVO.getOrgId())
                .eqIfPresent(ProduceReportDO::getOrgType, reqVO.getOrgType())
                .eqIfPresent(ProduceReportDO::getReportStatus, reqVO.getReportStatus())
                .eqIfPresent(ProduceReportDO::getRemark, reqVO.getRemark())
                .gtIfPresent(ProduceReportDO::getTotalTime, reqVO.getTotalTime())
                .betweenIfPresent(ProduceReportDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(ProduceReportDO::getGroupType, reqVO.getGroupType())
                .eqIfPresent(ProduceReportDO::getReportType, reqVO.getReportType())
                .betweenIfPresent(ProduceReportDO::getReportDate, reqVO.getReportDate())
                .inIfPresent(ProduceReportDO::getUserId, reqVO.getUserIds())
                .orderByDesc(ProduceReportDO::getId));
    }
    default List<ProduceReportDO> selectBy(ProduceReportPageReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<ProduceReportDO>()
                .eqIfPresent(ProduceReportDO::getGroupType, reqVO.getGroupType())
                .eqIfPresent(ProduceReportDO::getReportType, reqVO.getReportType())
                .eqIfPresent(ProduceReportDO::getUserId, reqVO.getUserId())
                .betweenIfPresent(ProduceReportDO::getReportDate, reqVO.getReportDate())
                .eqIfPresent(ProduceReportDO::getOrgType, reqVO.getOrgType())
                .orderByDesc(ProduceReportDO::getReportDate));
    }
}