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

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

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

@Mapper
public interface ProjectRolePersonMapper extends BaseMapperX<ProjectRolePersonDO> {

    default List<ProjectRolePersonDO> selectListByProjectId(Long projectId) {
        return selectList(new LambdaQueryWrapperX<ProjectRolePersonDO>()
                .eq(ProjectRolePersonDO::getProjectId, projectId)
                .eq(ProjectRolePersonDO::getEnabledFlag, Boolean.TRUE)
                .orderByAsc(ProjectRolePersonDO::getRoleCode)
                .orderByAsc(ProjectRolePersonDO::getSortNo)
                .orderByAsc(ProjectRolePersonDO::getId));
    }

    default List<ProjectRolePersonDO> selectListByProjectIds(Collection<Long> projectIds) {
        if (projectIds == null || projectIds.isEmpty()) {
            return Collections.emptyList();
        }
        return selectList(new LambdaQueryWrapperX<ProjectRolePersonDO>()
                .in(ProjectRolePersonDO::getProjectId, projectIds)
                .eq(ProjectRolePersonDO::getEnabledFlag, Boolean.TRUE)
                .orderByAsc(ProjectRolePersonDO::getProjectId)
                .orderByAsc(ProjectRolePersonDO::getRoleCode)
                .orderByAsc(ProjectRolePersonDO::getSortNo)
                .orderByAsc(ProjectRolePersonDO::getId));
    }

    default List<ProjectRolePersonDO> selectListByEmployeeIds(Collection<Long> employeeIds) {
        if (employeeIds == null || employeeIds.isEmpty()) {
            return Collections.emptyList();
        }
        return selectList(new LambdaQueryWrapperX<ProjectRolePersonDO>()
                .in(ProjectRolePersonDO::getEmployeeId, employeeIds)
                .eq(ProjectRolePersonDO::getEnabledFlag, Boolean.TRUE)
                .orderByAsc(ProjectRolePersonDO::getProjectId)
                .orderByAsc(ProjectRolePersonDO::getRoleCode)
                .orderByAsc(ProjectRolePersonDO::getSortNo)
                .orderByAsc(ProjectRolePersonDO::getId));
    }

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

}
