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

import cn.iocoder.yudao.framework.common.pojo.PageParam;
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.producereportplan.vo.ReportPlanSummaryRespVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.workreportplan.ReportPlanSummaryDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 报工分配计划 Mapper
 *
 * @author 内蒙必硕
 */
@Mapper
public interface ReportPlanSummaryMapper extends BaseMapperX<ReportPlanSummaryDO> {

    default PageResult<ReportPlanSummaryDO> selectPage(PageParam param, ReportPlanSummaryDO reqVO) {
        LambdaQueryWrapper<ReportPlanSummaryDO> wrapper = new LambdaQueryWrapperX<ReportPlanSummaryDO>()
                .eqIfPresent(ReportPlanSummaryDO::getPlanId, reqVO.getPlanId())
                .eqIfPresent(ReportPlanSummaryDO::getProductId, reqVO.getProductId())
                .eqIfPresent(ReportPlanSummaryDO::getOrgType, reqVO.getOrgType())
                .orderByDesc(ReportPlanSummaryDO::getOrgType);
        return selectPage(param,wrapper );
    }

    default List<ReportPlanSummaryDO> selectList(ReportPlanSummaryRespVO respVO) {
        LambdaQueryWrapper<ReportPlanSummaryDO> wrapper = new LambdaQueryWrapperX<ReportPlanSummaryDO>()
                .eqIfPresent(ReportPlanSummaryDO::getPlanId, respVO.getPlanId())
                .eqIfPresent(ReportPlanSummaryDO::getProductId, respVO.getProductId())
                .eqIfPresent(ReportPlanSummaryDO::getOrgType, respVO.getOrgType())
                .inIfPresent(ReportPlanSummaryDO::getPlanId, respVO.getPlanIds())
                .orderByDesc(ReportPlanSummaryDO::getOrgType);
        List<ReportPlanSummaryDO> list = selectList(wrapper);
        return list;
    }
    default ReportPlanSummaryDO selectOne(ReportPlanSummaryDO reqVO) {
        LambdaQueryWrapper<ReportPlanSummaryDO> wrapper = new LambdaQueryWrapperX<ReportPlanSummaryDO>()
                .eqIfPresent(ReportPlanSummaryDO::getPlanId, reqVO.getPlanId())
                .eqIfPresent(ReportPlanSummaryDO::getProductId, reqVO.getProductId())
                .eqIfPresent(ReportPlanSummaryDO::getOrgType, reqVO.getOrgType())
                .orderByDesc(ReportPlanSummaryDO::getOrgType);
        List<ReportPlanSummaryDO> list = selectList(wrapper);
        if (list!=null && list.size()>0)return list.get(0);
        return null;
    }
}