| | |
| | | // 创建分页对象,传入当前页和每页大小 |
| | | Page<ApiCompanyStudyVo> page = new Page<>(dto.getPageNow(), dto.getPageSize()); |
| | | IPage<ApiCompanyStudyVo> result = aiMemberAnswerService.selectListPage(dto, page); |
| | | // List<ApiCompanyStudyVo> records = result.getRecords(); |
| | | // if (CollUtil.isNotEmpty(records)){ |
| | | // //stream流获取re cords集合中的元素productId的set集合 |
| | | // Set<String> collect = records.stream().map(ApiCompanyStudyVo::getProductId).collect(Collectors.toSet()); |
| | | // List<AiMemberAnswer> list = aiMemberAnswerService.getIdListByCompanyIdAndProductId(companyId, collect); |
| | | // if (CollUtil.isNotEmpty(list)){ |
| | | // //利用stream流,操作集合list,返回一个map对象,key为productId,value为按照productId分组的集合的大小,默认值为0 |
| | | // Map<String, Long> memberAnswerItemCountMap = |
| | | // list.stream().collect(Collectors.groupingBy( |
| | | // AiMemberAnswer::getProductId, |
| | | // Collectors.counting() |
| | | // )); |
| | | // for ( ApiCompanyStudyVo record : records){ |
| | | // record.setPracticeCnt(memberAnswerItemCountMap.getOrDefault(record.getProductId(), 0L).intValue()); |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | List<ApiCompanyStudyVo> records = result.getRecords(); |
| | | if (CollUtil.isNotEmpty(records)){ |
| | | //stream流获取re cords集合中的元素productId的set集合 |
| | | Set<String> collect = records.stream().map(ApiCompanyStudyVo::getProductId).collect(Collectors.toSet()); |
| | | // 安全地获取 productId 集合,过滤掉 null 值 |
| | | Set<String> collect = records.stream() |
| | | .filter(Objects::nonNull) |
| | | .map(ApiCompanyStudyVo::getProductId) |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.toSet()); |
| | | |
| | | if (CollUtil.isNotEmpty(collect)) { // 确保 collect 不为空 |
| | | List<AiMemberAnswer> list = aiMemberAnswerService.getIdListByCompanyIdAndProductId(companyId, collect); |
| | | if (CollUtil.isNotEmpty(list)){ |
| | | //利用stream流,操作集合list,返回一个map对象,key为productId,value为按照productId分组的集合的大小,默认值为0 |
| | | Map<String, Long> memberAnswerItemCountMap = |
| | | list.stream().collect(Collectors.groupingBy( |
| | | Map<String, Long> memberAnswerItemCountMap = list.stream() |
| | | .collect(Collectors.groupingBy( |
| | | AiMemberAnswer::getProductId, |
| | | Collectors.counting() |
| | | )); |
| | | |
| | | for ( ApiCompanyStudyVo record : records){ |
| | | if (record != null && record.getProductId() != null) { |
| | | record.setPracticeCnt(memberAnswerItemCountMap.getOrDefault(record.getProductId(), 0L).intValue()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | return new FebsResponse().success().data(result); |
| | | } |
| | | |