陈昶聿
2 天以前 b79d14af673a7adc8614b5cb1e49773b5a992f83
smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskDetailTraceServiceImpl.java
@@ -71,47 +71,39 @@
    }
    @Override
    public List<DetailTraceDealDTO> tracedeallist(DetailTraceDealVO detailTraceDealVO) {
        // 获取所有需要处理的记录
    public Map<String, Object> tracedeallist(DetailTraceDealVO detailTraceDealVO) {
        // 分页查询
        List<ServiceSubtaskDetailTrace> tracedeallist = serviceSubtaskDetailTraceMapper.tracedeallist(detailTraceDealVO);
        // 按 questiontext 分组
        Map<String, List<ServiceSubtaskDetailTrace>> groupByQuestion = tracedeallist.stream()
                .filter(t -> t.getQuestiontext() != null)
                .collect(Collectors.groupingBy(ServiceSubtaskDetailTrace::getQuestiontext));
        Map<String, List<ServiceSubtaskDetailTrace>> groupByQuestion = tracedeallist.stream().filter(t -> t.getQuestiontext() != null).collect(Collectors.groupingBy(ServiceSubtaskDetailTrace::getQuestiontext));
        List<DetailTraceDealDTO> detailTraceDealDTOList = new ArrayList<>();
        long totalException = 0L;
        long noDealException = 0L;
        long yesDealException = 0L;
        for (Map.Entry<String, List<ServiceSubtaskDetailTrace>> entry : groupByQuestion.entrySet()) {
            List<ServiceSubtaskDetailTrace> group = entry.getValue();
            DetailTraceDealDTO dto = new DetailTraceDealDTO();
            // 问题内容
            dto.setQuestiontext(entry.getKey());
            if (CollectionUtils.isNotEmpty(group)) {
                dto.setScriptid(group.get(0).getScriptid());
                dto.setTemplateType(group.get(0).getTemplateType());
            }
            // 负责科室(去重)
            List<Map<String, Object>> responsibleDept = group.stream()
                    .filter(t -> t.getTodeptcode() != null)
                    .collect(Collectors.collectingAndThen(
                            Collectors.toMap(
                                    ServiceSubtaskDetailTrace::getTodeptcode,
                                    t -> {
                                        Map<String, Object> deptMap = new HashMap<>();
                                        deptMap.put("deptName", t.getTodeptname());
                                        deptMap.put("deptCode", t.getTodeptcode());
                                        return deptMap;
                                    },
                                    (existing, replacement) -> existing
                            ),
                            map -> new ArrayList<>(map.values())
                    ));
            List<Map<String, Object>> responsibleDept = group.stream().filter(t -> t.getTodeptcode() != null).collect(Collectors.collectingAndThen(Collectors.toMap(ServiceSubtaskDetailTrace::getTodeptcode, t -> {
                Map<String, Object> deptMap = new HashMap<>();
                deptMap.put("deptName", t.getTodeptname());
                deptMap.put("deptCode", t.getTodeptcode());
                return deptMap;
            }, (existing, replacement) -> existing), map -> new ArrayList<>(map.values())));
            dto.setResponsibleDept(responsibleDept);
            // 有效填写数:通过组内的 scriptid 去 service_subtask_detail 表查询
            List<Long> scriptIds = group.stream()
                    .map(ServiceSubtaskDetailTrace::getScriptid)
                    .filter(Objects::nonNull)
                    .distinct()
                    .collect(Collectors.toList());
            List<Long> scriptIds = group.stream().map(ServiceSubtaskDetailTrace::getScriptid).filter(Objects::nonNull).distinct().collect(Collectors.toList());
            long effectiveFillNum = 0L;
            if (CollectionUtils.isNotEmpty(scriptIds)) {
                ServiceSubtaskDetail query = new ServiceSubtaskDetail();
@@ -140,19 +132,26 @@
            exceptionQuesNum.put("all", exceptionFillNum);
            dto.setExceptionQuesNum(exceptionQuesNum);
            // 汇总统计累加
            totalException += exceptionFillNum;
            noDealException += noDeal;
            yesDealException += yesDeal;
            // 最新处理人和处理时间(取 handleTime 最新的一条)
            group.stream()
                    .filter(t -> t.getHandleTime() != null)
                    .max(Comparator.comparing(ServiceSubtaskDetailTrace::getHandleTime))
                    .ifPresent(latest -> {
                        dto.setHandleBy(latest.getHandleBy());
                        dto.setHandleTime(latest.getHandleTime());
                    });
            group.stream().filter(t -> t.getHandleTime() != null).max(Comparator.comparing(ServiceSubtaskDetailTrace::getHandleTime)).ifPresent(latest -> {
                dto.setHandleBy(latest.getHandleBy());
                dto.setHandleTime(latest.getHandleTime());
            });
            detailTraceDealDTOList.add(dto);
        }
        return detailTraceDealDTOList;
        Map<String, Object> result = new HashMap<>();
        result.put("detailTraceDealDTOList", detailTraceDealDTOList);
        result.put("totalException", totalException);
        result.put("noDealException", noDealException);
        result.put("yesDealException", yesDealException);
        return result;
    }
    /**