package cn.iocoder.lyzsys.module.tjt.dal.mysql.planningquarter;

import cn.iocoder.lyzsys.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.lyzsys.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.lyzsys.module.tjt.dal.dataobject.planningquarter.ProjectPlanningQuarterDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * 合约规划季度分配 Mapper
 *
 * @author Codex
 */
@Mapper
public interface ProjectPlanningQuarterMapper extends BaseMapperX<ProjectPlanningQuarterDO> {

    default ProjectPlanningQuarterDO selectByPlanningIdAndDistributionYearAndQuarter(Long planningId,
                                                                                      Integer distributionYear,
                                                                                      Integer quarterNo) {
        return selectOne(ProjectPlanningQuarterDO::getPlanningId, planningId,
                ProjectPlanningQuarterDO::getDistributionYear, distributionYear,
                ProjectPlanningQuarterDO::getQuarterNo, quarterNo);
    }

    default List<ProjectPlanningQuarterDO> selectListByPlanningId(Long planningId) {
        return selectList(new LambdaQueryWrapperX<ProjectPlanningQuarterDO>()
                .eq(ProjectPlanningQuarterDO::getPlanningId, planningId)
                .orderByAsc(ProjectPlanningQuarterDO::getDistributionYear)
                .orderByAsc(ProjectPlanningQuarterDO::getQuarterNo)
                .orderByAsc(ProjectPlanningQuarterDO::getId));
    }

    default List<ProjectPlanningQuarterDO> selectListByPlanningIds(Collection<Long> planningIds) {
        if (planningIds == null || planningIds.isEmpty()) {
            return Collections.emptyList();
        }
        return selectList(new LambdaQueryWrapperX<ProjectPlanningQuarterDO>()
                .in(ProjectPlanningQuarterDO::getPlanningId, planningIds)
                .orderByAsc(ProjectPlanningQuarterDO::getDistributionYear)
                .orderByAsc(ProjectPlanningQuarterDO::getQuarterNo)
                .orderByAsc(ProjectPlanningQuarterDO::getId));
    }

}
