diff --git a/ruoyi-oa/src/main/java/com/ruoyi/oa/domain/OaProjectScheduleStep.java b/ruoyi-oa/src/main/java/com/ruoyi/oa/domain/OaProjectScheduleStep.java index b53afa0..8d71cbf 100644 --- a/ruoyi-oa/src/main/java/com/ruoyi/oa/domain/OaProjectScheduleStep.java +++ b/ruoyi-oa/src/main/java/com/ruoyi/oa/domain/OaProjectScheduleStep.java @@ -139,4 +139,6 @@ public class OaProjectScheduleStep extends BaseEntity { //排序字段 private Integer sortNum; + private Long projectId; + } diff --git a/ruoyi-oa/src/main/java/com/ruoyi/oa/service/impl/OaProjectScheduleStepServiceImpl.java b/ruoyi-oa/src/main/java/com/ruoyi/oa/service/impl/OaProjectScheduleStepServiceImpl.java index 4a53d87..1aaf661 100644 --- a/ruoyi-oa/src/main/java/com/ruoyi/oa/service/impl/OaProjectScheduleStepServiceImpl.java +++ b/ruoyi-oa/src/main/java/com/ruoyi/oa/service/impl/OaProjectScheduleStepServiceImpl.java @@ -369,21 +369,30 @@ public class OaProjectScheduleStepServiceImpl implements IOaProjectScheduleStepS .eq(SysOaProject::getFunctionary, nickName) ); - // 4. 查询用户负责的进度步骤(核心数据) + // 4. 查询用户负责的进度步骤(核心数据),并关联项目ID List userSteps = new ArrayList<>(); + // 存储 scheduleId 与 projectId 的映射关系(关键:通过进度主表关联项目ID) + Map scheduleProjectMap = new HashMap<>(); + if (CollUtil.isNotEmpty(projectIds)) { - // 查询关联项目的进度主表 + // 查询关联项目的进度主表,并构建 scheduleId -> projectId 映射 List schedules = projectScheduleMapper.selectList( Wrappers.lambdaQuery() .in(OaProjectSchedule::getProjectId, projectIds) .eq(OaProjectSchedule::getDelFlag, "0") ); if (CollUtil.isNotEmpty(schedules)) { - List scheduleIds = schedules.stream() + // 构建映射:进度ID -> 项目ID + scheduleProjectMap = schedules.stream() .filter(Objects::nonNull) - .map(OaProjectSchedule::getScheduleId) - .filter(Objects::nonNull) - .collect(Collectors.toList()); + .filter(s -> s.getScheduleId() != null && s.getProjectId() != null) + .collect(Collectors.toMap( + OaProjectSchedule::getScheduleId, + OaProjectSchedule::getProjectId, + (existing, replacement) -> existing // 若有重复ID,保留第一个 + )); + + List scheduleIds = new ArrayList<>(scheduleProjectMap.keySet()); // 查询用户负责的进度步骤 userSteps = projectScheduleStepMapper.selectList( @@ -393,10 +402,19 @@ public class OaProjectScheduleStepServiceImpl implements IOaProjectScheduleStepS .eq(OaProjectScheduleStep::getDelFlag, "0") .eq(OaProjectScheduleStep::getUseFlag, 1) ); + + // 为每个步骤设置对应的项目ID + for (OaProjectScheduleStep step : userSteps) { + if (step != null && step.getScheduleId() != null) { + // 从映射中获取当前步骤所属的项目ID + Long projectId = scheduleProjectMap.get(step.getScheduleId()); + step.setProjectId(projectId); + } + } } } - // 5. 统计进度数据 + // 5. 统计进度数据(逻辑不变) PersonalReportDTO.ProgressStats progressStats = new PersonalReportDTO.ProgressStats(); progressStats.setTotal((long) userSteps.size()); progressStats.setCompleted(userSteps.stream() @@ -415,7 +433,7 @@ public class OaProjectScheduleStepServiceImpl implements IOaProjectScheduleStepS result.setUserInfo(user); result.setResponsibleProjects(responsibleProjects); result.setProgressStats(progressStats); - result.setUserSteps(userSteps); + result.setUserSteps(userSteps); // 此时userSteps已包含每个步骤对应的projectId return result; }