| | |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, ServiceSubtaskScriptCount> getSfStatisticsScriptDetails(ServiceSubtaskCountReq serviceSubtaskCountReq) { |
| | | Map<String, ServiceSubtaskScriptCount> result = new HashMap<>(); |
| | | public Map<String, Object> getSfStatisticsScriptDetails(ServiceSubtaskCountReq serviceSubtaskCountReq) { |
| | | List<ServiceSubtaskScriptCount> allCounts = new ArrayList<>(); |
| | | List<ServiceSubtaskScriptCount> allItemCounts = new ArrayList<>(); |
| | | String type = serviceSubtaskCountReq.getType(); |
| | |
| | | allItemCounts = serviceSubtaskMapper.getSfStatisticsScriptItemDetails(serviceSubtaskCountReq); |
| | | } |
| | | |
| | | for (ServiceSubtaskScriptCount count : allCounts) { |
| | | //返回结构是 Map,且不传 type 时会执行两条 SQL,PageHelper 没法对整体分页, |
| | | //所以在题目合并完成之后按题目(scriptid)在这里分页,保证 total 和每页数据都是题目维度的。 |
| | | allCounts.sort(Comparator |
| | | .comparing(ServiceSubtaskScriptCount::getSubtaskType, Comparator.nullsLast(String::compareTo)) |
| | | .thenComparing(ServiceSubtaskScriptCount::getScriptid, Comparator.nullsLast(Long::compareTo))); |
| | | |
| | | int pageNum = ObjectUtils.isNotEmpty(serviceSubtaskCountReq.getPageNum()) && serviceSubtaskCountReq.getPageNum() > 0 |
| | | ? serviceSubtaskCountReq.getPageNum() : 1; |
| | | int pageSize = ObjectUtils.isNotEmpty(serviceSubtaskCountReq.getPageSize()) && serviceSubtaskCountReq.getPageSize() > 0 |
| | | ? serviceSubtaskCountReq.getPageSize() : 10; |
| | | int total = allCounts.size(); |
| | | int fromIndex = (int) Math.min((long) (pageNum - 1) * pageSize, total); |
| | | int toIndex = Math.min(fromIndex + pageSize, total); |
| | | List<ServiceSubtaskScriptCount> pageCounts = allCounts.subList(fromIndex, toIndex); |
| | | |
| | | Map<String, ServiceSubtaskScriptCount> pageData = new LinkedHashMap<>(); |
| | | for (ServiceSubtaskScriptCount count : pageCounts) { |
| | | Map<String, ServiceSubtaskScriptCount> itemCountMap = new HashMap<>(); |
| | | //问卷加上空白选项 |
| | | if (ObjectUtils.isNotEmpty(count.getTemplateid()) && ObjectUtils.isNotEmpty(count.getSubtaskType()) && count.getSubtaskType().equals("2")) { |
| | |
| | | } |
| | | } |
| | | allItemCounts.forEach(itemCount -> { |
| | | if (ObjectUtils.isNotEmpty(count.getScriptid()) && ObjectUtils.isNotEmpty(itemCount.getScriptid())) { |
| | | if (count.getScriptid().equals(itemCount.getScriptid())) { |
| | | //放入统计信息 |
| | | itemCount.setScriptContent(count.getScriptContent()); |
| | | itemCount.setScriptType(count.getScriptType()); |
| | | itemCount.setSubtaskType(count.getSubtaskType()); |
| | | itemCount.setCompletedQuantity(count.getCompletedQuantity()); |
| | | itemCount.setAllQuantity(count.getAllQuantity()); |
| | | itemCount.setCompletedPercentage(count.getCompletedPercentage()); |
| | | itemCount.setTemplateid(count.getTemplateid()); |
| | | //计算选择比例 |
| | | int chosenQuantity = ObjectUtils.isNotEmpty(itemCount.getChosenQuantity()) ? itemCount.getChosenQuantity() : 0; |
| | | int completedQuantity = itemCount.getCompletedQuantity(); |
| | | if (ObjectUtils.isNotEmpty(completedQuantity) && completedQuantity != 0) { |
| | | BigDecimal chosenPercentage = (new BigDecimal(chosenQuantity)).divide(new BigDecimal(completedQuantity), 2, RoundingMode.HALF_UP); |
| | | itemCount.setChosenPercentage(chosenPercentage.toString()); |
| | | } |
| | | itemCountMap.put(itemCount.getOptionText(), itemCount); |
| | | //明细行已按“题目内容+任务类型”聚合并带出 script_content,不能用 scriptid 匹配: |
| | | //同一道题会被复制到多个任务模板,每个模板的 scriptid 都不同 |
| | | boolean sameQuestion = ObjectUtils.isNotEmpty(count.getScriptContent()) |
| | | && ObjectUtils.isNotEmpty(itemCount.getScriptContent()) |
| | | && count.getScriptContent().equals(itemCount.getScriptContent()) |
| | | && Objects.equals(count.getSubtaskType(), itemCount.getSubtaskType()); |
| | | if (sameQuestion) { |
| | | //放入统计信息 |
| | | itemCount.setScriptContent(count.getScriptContent()); |
| | | itemCount.setScriptType(count.getScriptType()); |
| | | itemCount.setSubtaskType(count.getSubtaskType()); |
| | | itemCount.setCompletedQuantity(count.getCompletedQuantity()); |
| | | itemCount.setAllQuantity(count.getAllQuantity()); |
| | | itemCount.setCompletedPercentage(count.getCompletedPercentage()); |
| | | itemCount.setTemplateid(count.getTemplateid()); |
| | | //计算选择比例 |
| | | int chosenQuantity = ObjectUtils.isNotEmpty(itemCount.getChosenQuantity()) ? itemCount.getChosenQuantity() : 0; |
| | | int completedQuantity = itemCount.getCompletedQuantity(); |
| | | if (ObjectUtils.isNotEmpty(completedQuantity) && completedQuantity != 0) { |
| | | BigDecimal chosenPercentage = (new BigDecimal(chosenQuantity)).divide(new BigDecimal(completedQuantity), 2, RoundingMode.HALF_UP); |
| | | itemCount.setChosenPercentage(chosenPercentage.toString()); |
| | | } |
| | | itemCountMap.put(itemCount.getOptionText(), itemCount); |
| | | } |
| | | }); |
| | | List<ServiceSubtaskScriptCount> itemCounts = new ArrayList<>(itemCountMap.values()); |
| | | count.setDetails(itemCounts); |
| | | result.put(count.getScriptid().toString(), count); |
| | | pageData.put(count.getScriptid().toString(), count); |
| | | } |
| | | Map<String, Object> result = new HashMap<>(); |
| | | // total 是题目总数(已按题目合并),rows/data 是当前页数据 |
| | | result.put("total", total); |
| | | result.put("pageNum", pageNum); |
| | | result.put("pageSize", pageSize); |
| | | result.put("rows", new ArrayList<>(pageCounts)); |
| | | result.put("data", pageData); |
| | | return result; |
| | | } |
| | | |