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

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.specialtyrolesplitperson.SpecialtyRoleSplitPersonDO;
import org.apache.ibatis.annotations.Mapper;

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

/**
 * 页面 5 角色人员分配明细 Mapper
 *
 * @author Codex
 */
@Mapper
public interface SpecialtyRoleSplitPersonMapper extends BaseMapperX<SpecialtyRoleSplitPersonDO> {

    default List<SpecialtyRoleSplitPersonDO> selectListByRoleSplitId(Long roleSplitId) {
        return selectList(new LambdaQueryWrapperX<SpecialtyRoleSplitPersonDO>()
                .eq(SpecialtyRoleSplitPersonDO::getRoleSplitId, roleSplitId)
                .orderByAsc(SpecialtyRoleSplitPersonDO::getSortNo)
                .orderByAsc(SpecialtyRoleSplitPersonDO::getId));
    }

    default List<SpecialtyRoleSplitPersonDO> selectListByRoleSplitIds(Collection<Long> roleSplitIds) {
        if (roleSplitIds == null || roleSplitIds.isEmpty()) {
            return Collections.emptyList();
        }
        return selectList(new LambdaQueryWrapperX<SpecialtyRoleSplitPersonDO>()
                .in(SpecialtyRoleSplitPersonDO::getRoleSplitId, roleSplitIds)
                .orderByAsc(SpecialtyRoleSplitPersonDO::getRoleSplitId)
                .orderByAsc(SpecialtyRoleSplitPersonDO::getSortNo)
                .orderByAsc(SpecialtyRoleSplitPersonDO::getId));
    }

    default List<SpecialtyRoleSplitPersonDO> selectListByOutputSplitIds(Collection<Long> outputSplitIds) {
        if (outputSplitIds == null || outputSplitIds.isEmpty()) {
            return Collections.emptyList();
        }
        return selectList(new LambdaQueryWrapperX<SpecialtyRoleSplitPersonDO>()
                .in(SpecialtyRoleSplitPersonDO::getOutputSplitId, outputSplitIds)
                .orderByAsc(SpecialtyRoleSplitPersonDO::getOutputSplitId)
                .orderByAsc(SpecialtyRoleSplitPersonDO::getRoleSplitId)
                .orderByAsc(SpecialtyRoleSplitPersonDO::getSortNo)
                .orderByAsc(SpecialtyRoleSplitPersonDO::getId));
    }

    default List<SpecialtyRoleSplitPersonDO> selectListByEmployeeIds(Collection<Long> employeeIds) {
        if (employeeIds == null || employeeIds.isEmpty()) {
            return Collections.emptyList();
        }
        return selectList(new LambdaQueryWrapperX<SpecialtyRoleSplitPersonDO>()
                .in(SpecialtyRoleSplitPersonDO::getEmployeeId, employeeIds)
                .orderByAsc(SpecialtyRoleSplitPersonDO::getPlanningId)
                .orderByAsc(SpecialtyRoleSplitPersonDO::getRoleSplitId)
                .orderByAsc(SpecialtyRoleSplitPersonDO::getSortNo)
                .orderByAsc(SpecialtyRoleSplitPersonDO::getId));
    }

    default List<SpecialtyRoleSplitPersonDO> selectListByPlanningIdsAndEmployeeIds(Collection<Long> planningIds,
                                                                                   Collection<Long> employeeIds) {
        if (planningIds == null || planningIds.isEmpty() || employeeIds == null || employeeIds.isEmpty()) {
            return Collections.emptyList();
        }
        return selectList(new LambdaQueryWrapperX<SpecialtyRoleSplitPersonDO>()
                .in(SpecialtyRoleSplitPersonDO::getPlanningId, planningIds)
                .in(SpecialtyRoleSplitPersonDO::getEmployeeId, employeeIds)
                .orderByAsc(SpecialtyRoleSplitPersonDO::getPlanningId)
                .orderByAsc(SpecialtyRoleSplitPersonDO::getRoleSplitId)
                .orderByAsc(SpecialtyRoleSplitPersonDO::getSortNo)
                .orderByAsc(SpecialtyRoleSplitPersonDO::getId));
    }

    default void deleteByRoleSplitId(Long roleSplitId) {
        delete(SpecialtyRoleSplitPersonDO::getRoleSplitId, roleSplitId);
    }

    default void deleteByRoleSplitIds(Collection<Long> roleSplitIds) {
        if (roleSplitIds == null || roleSplitIds.isEmpty()) {
            return;
        }
        delete(new LambdaQueryWrapperX<SpecialtyRoleSplitPersonDO>()
                .in(SpecialtyRoleSplitPersonDO::getRoleSplitId, roleSplitIds));
    }

    default void deleteByOutputSplitId(Long outputSplitId) {
        delete(SpecialtyRoleSplitPersonDO::getOutputSplitId, outputSplitId);
    }

    default void deleteByOutputSplitIds(Collection<Long> outputSplitIds) {
        if (outputSplitIds == null || outputSplitIds.isEmpty()) {
            return;
        }
        delete(new LambdaQueryWrapperX<SpecialtyRoleSplitPersonDO>()
                .in(SpecialtyRoleSplitPersonDO::getOutputSplitId, outputSplitIds));
    }

    default Long selectCountByEmployeeId(Long employeeId) {
        return selectCount(new LambdaQueryWrapperX<SpecialtyRoleSplitPersonDO>()
                .eq(SpecialtyRoleSplitPersonDO::getEmployeeId, employeeId));
    }

}
