|
|
@@ -581,10 +581,6 @@ public class OkrService {
|
|
|
.orderByDesc(KrProgressLog::getCreatedAt))
|
|
|
.stream().collect(Collectors.groupingBy(KrProgressLog::getKrId));
|
|
|
}
|
|
|
- Map<Long, String> userNames = userMapper.selectList(null).stream()
|
|
|
- .collect(Collectors.toMap(SysUser::getId, SysUser::getRealName, (a, b) -> a));
|
|
|
- Map<Long, String> deptNames = departmentMapper.selectList(null).stream()
|
|
|
- .collect(Collectors.toMap(SysDepartment::getId, SysDepartment::getName, (a, b) -> a));
|
|
|
|
|
|
// Collect all aligned objective IDs
|
|
|
Set<Long> allAlignedIds = new LinkedHashSet<>();
|
|
|
@@ -595,9 +591,55 @@ public class OkrService {
|
|
|
.map(Long::parseLong).forEach(allAlignedIds::add);
|
|
|
}
|
|
|
}
|
|
|
- Map<Long, OkrDetailDto> alignedObjMap = new LinkedHashMap<>();
|
|
|
+ List<OkrObjective> alignedObjs = List.of();
|
|
|
if (!allAlignedIds.isEmpty()) {
|
|
|
- List<OkrObjective> alignedObjs = objectiveMapper.selectBatchIds(allAlignedIds);
|
|
|
+ alignedObjs = objectiveMapper.selectBatchIds(allAlignedIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<Long> sourceKrIds = krMap.values().stream()
|
|
|
+ .flatMap(List::stream)
|
|
|
+ .map(KrKeyResult::getSourceKrId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toCollection(LinkedHashSet::new));
|
|
|
+ Map<Long, KrKeyResult> sourceKrMap = new LinkedHashMap<>();
|
|
|
+ if (!sourceKrIds.isEmpty()) {
|
|
|
+ sourceKrMap = krMapper.selectBatchIds(sourceKrIds).stream()
|
|
|
+ .collect(Collectors.toMap(KrKeyResult::getId, kr -> kr, (a, b) -> a, LinkedHashMap::new));
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<Long> sourceObjectiveIds = sourceKrMap.values().stream()
|
|
|
+ .map(KrKeyResult::getObjectiveId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toCollection(LinkedHashSet::new));
|
|
|
+ Map<Long, OkrObjective> sourceObjectiveMap = new LinkedHashMap<>();
|
|
|
+ if (!sourceObjectiveIds.isEmpty()) {
|
|
|
+ sourceObjectiveMap = objectiveMapper.selectBatchIds(sourceObjectiveIds).stream()
|
|
|
+ .collect(Collectors.toMap(OkrObjective::getId, obj -> obj, (a, b) -> a, LinkedHashMap::new));
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<Long> userIds = new LinkedHashSet<>();
|
|
|
+ Set<Long> deptIds = new LinkedHashSet<>();
|
|
|
+ objectives.forEach(obj -> {
|
|
|
+ addIfPresent(userIds, obj.getUserId());
|
|
|
+ addIfPresent(userIds, obj.getReviewedBy());
|
|
|
+ addIfPresent(deptIds, obj.getDeptId());
|
|
|
+ });
|
|
|
+ alignedObjs.forEach(obj -> addIfPresent(userIds, obj.getUserId()));
|
|
|
+ krMap.values().stream().flatMap(List::stream)
|
|
|
+ .forEach(kr -> addIfPresent(userIds, kr.getAssignedTo()));
|
|
|
+ sourceObjectiveMap.values().forEach(obj -> addIfPresent(userIds, obj.getUserId()));
|
|
|
+
|
|
|
+ Map<Long, String> userNames = userIds.isEmpty()
|
|
|
+ ? Collections.emptyMap()
|
|
|
+ : userMapper.selectBatchIds(userIds).stream()
|
|
|
+ .collect(Collectors.toMap(SysUser::getId, SysUser::getRealName, (a, b) -> a));
|
|
|
+ Map<Long, String> deptNames = deptIds.isEmpty()
|
|
|
+ ? Collections.emptyMap()
|
|
|
+ : departmentMapper.selectBatchIds(deptIds).stream()
|
|
|
+ .collect(Collectors.toMap(SysDepartment::getId, SysDepartment::getName, (a, b) -> a));
|
|
|
+
|
|
|
+ Map<Long, OkrDetailDto> alignedObjMap = new LinkedHashMap<>();
|
|
|
+ if (!alignedObjs.isEmpty()) {
|
|
|
for (OkrObjective ao : alignedObjs) {
|
|
|
List<KrKeyResult> akrs = krMap.getOrDefault(ao.getId(),
|
|
|
krMapper.selectList(new LambdaQueryWrapper<KrKeyResult>().eq(KrKeyResult::getObjectiveId, ao.getId())));
|
|
|
@@ -641,10 +683,10 @@ public class OkrService {
|
|
|
k.setAssignedToName(userNames.get(kr.getAssignedTo()));
|
|
|
}
|
|
|
if (kr.getSourceKrId() != null) {
|
|
|
- KrKeyResult src = krMapper.selectById(kr.getSourceKrId());
|
|
|
+ KrKeyResult src = sourceKrMap.get(kr.getSourceKrId());
|
|
|
if (src != null) {
|
|
|
k.setSourceKrTitle(src.getTitle());
|
|
|
- OkrObjective srcObj = objectiveMapper.selectById(src.getObjectiveId());
|
|
|
+ OkrObjective srcObj = sourceObjectiveMap.get(src.getObjectiveId());
|
|
|
if (srcObj != null && srcObj.getUserId() != null) {
|
|
|
k.setSourceKrUserName(userNames.get(srcObj.getUserId()));
|
|
|
}
|
|
|
@@ -669,4 +711,10 @@ public class OkrService {
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+ private void addIfPresent(Set<Long> target, Long value) {
|
|
|
+ if (value != null) {
|
|
|
+ target.add(value);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|