| | |
| | | return new FebsResponse().success().data(vos); |
| | | } |
| | | |
| | | // 按 productPointId 分组并计算每个分组的总学习时间 |
| | | Map<String, Integer> productPointTimeMap = aiMemberPoints.stream() |
| | | .collect(Collectors.groupingBy( |
| | | AiMemberPoint::getProductPointId, |
| | | Collectors.summingInt(AiMemberPoint::getTotalTime) |
| | | )); |
| | | |
| | | // stream流操作aiMemberPoints,返回一个productPointId的set集合 |
| | | Set<String> productPointIdSet = aiMemberPoints.stream() |
| | | .map(AiMemberPoint::getProductPointId) |
| | |
| | | .select(AiProductPoint::getId, AiProductPoint::getTitle) |
| | | .in(AiProductPoint::getId, productPointIdSet) |
| | | ); |
| | | //stream操作aiProductPoints,返回一个根据Map<id,AiProductPoint> |
| | | Map<String, AiProductPoint> productPointMap = aiProductPoints.stream().collect(Collectors.toMap(AiProductPoint::getId, aiProductPoint -> aiProductPoint)); |
| | | |
| | | if (CollUtil.isEmpty(aiProductPoints)){ |
| | | return new FebsResponse().success().data(vos); |
| | | } |
| | | |
| | | for (AiProductPoint aiProductPoint : aiProductPoints){ |
| | | ApiMemberTeamStudyVo vo = new ApiMemberTeamStudyVo(); |
| | | vo.setTitle(aiProductPoint.getTitle()); |
| | | Integer totalTime = productPointTimeMap.get(aiProductPoint.getId()); |
| | | // 添加 null 值保护,避免 NPE |
| | | vo.setTotalTime(DateUtil.secondToTime(totalTime != null ? totalTime : 0)); |
| | | vos.add(vo); |
| | | for (AiMemberPoint aiMemberPoint : aiMemberPoints) { |
| | | String productPointId = aiMemberPoint.getProductPointId(); |
| | | AiProductPoint productPoint = productPointMap.get(productPointId); |
| | | |
| | | // 检查 productPoint 是否存在 |
| | | if (productPoint != null) { |
| | | ApiMemberTeamStudyVo vo = new ApiMemberTeamStudyVo(); |
| | | vo.setTitle(productPoint.getTitle()); |
| | | |
| | | // 检查 totalTime 是否为 null |
| | | Integer totalTime = aiMemberPoint.getTotalTime(); |
| | | vo.setTotalTime(DateUtil.secondToTime(totalTime != null ? totalTime : 0)); |
| | | |
| | | vos.add(vo); |
| | | } |
| | | } |
| | | |
| | | return new FebsResponse().success().data(vos); |