From 26d1f59f0266672398975ba0337bb3d8267c2d95 Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期一, 12 十月 2026 15:36:52 +0800
Subject: [PATCH] 满意度扫码BUG修改

---
 smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskDetailTraceServiceImpl.java |  278 +++++++++++++++++++++++++++----------------------------
 1 files changed, 138 insertions(+), 140 deletions(-)

diff --git a/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskDetailTraceServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskDetailTraceServiceImpl.java
index d49690e..f8dadef 100644
--- a/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskDetailTraceServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskDetailTraceServiceImpl.java
@@ -3,13 +3,14 @@
 import java.util.*;
 import java.util.stream.Collectors;
 
+import com.alibaba.fastjson2.JSON;
 import com.github.pagehelper.util.StringUtil;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.StringUtils;
 import com.smartor.domain.*;
 import com.smartor.domain.DTO.DetailTraceDealDTO;
 import com.smartor.domain.VO.DetailTraceDealVO;
-import com.smartor.domain.VO.SatisfactionExceptConfigQuestionReqVO;
+import com.smartor.domain.VO.ServiceSubtaskDetailTraceVO;
 import com.smartor.mapper.ServiceSubtaskDetailMapper;
 import com.smartor.mapper.ServiceSubtaskDetailTraceMapper;
 import com.smartor.mapper.SvyLibScriptCategoryMapper;
@@ -62,88 +63,131 @@
     /**
      * 鏌ヨ闅忚浠诲姟寮傚父璁板綍璺熻釜鍒楄〃
      *
-     * @param serviceSubtaskDetailTrace 闅忚浠诲姟寮傚父璁板綍璺熻釜
+     * @param serviceSubtaskDetailTraceVO 闅忚浠诲姟寮傚父璁板綍璺熻釜
      * @return 闅忚浠诲姟寮傚父璁板綍璺熻釜
      */
     @Override
-    public List<ServiceSubtaskDetailTrace> selectServiceSubtaskDetailTtraceList(ServiceSubtaskDetailTrace serviceSubtaskDetailTrace) {
-        return serviceSubtaskDetailTraceMapper.selectServiceSubtaskDetailTtraceList(serviceSubtaskDetailTrace);
+    public List<ServiceSubtaskDetailTrace> selectServiceSubtaskDetailTtraceList(ServiceSubtaskDetailTraceVO serviceSubtaskDetailTraceVO) {
+        List<ServiceSubtaskDetailTrace> serviceSubtaskDetailTraces = serviceSubtaskDetailTraceMapper.selectServiceSubtaskDetailTtraceList(serviceSubtaskDetailTraceVO);
+        for (ServiceSubtaskDetailTrace serviceSubtaskDetailTrace : serviceSubtaskDetailTraces) {
+            if (StringUtils.isNotEmpty(serviceSubtaskDetailTrace.getPatdesc())) {
+                serviceSubtaskDetailTrace.setPatdescJson(JSON.parseObject(serviceSubtaskDetailTrace.getPatdesc()));
+            }
+        }
+        return serviceSubtaskDetailTraces;
     }
 
     @Override
     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));
+        // 浼樺寲鍓嶏細鈶� 杩欐潯 SQL 娌℃湁 limit锛屾瘡娆¢兘鎶婃暣琛� trace锛堝惈 patdesc/recordurl 澶у瓧娈碉級鎷夊洖 Java 鍐嶅垎缁勶紱
+        //        鈶� 姣忎釜闂閮芥嬁 scriptid 鍘� service_subtask_detail 鏌ヤ竴娆″叏琛ㄥ彧涓哄彇 size锛圢+1锛夛紱
+        //        鈶� controller 鎶婅繖涓柟娉曡皟浜嗕袱閬嶏紙绗簩閬嶄负浜嗘�绘暟锛夛紝绛変簬涓婇潰涓ゆ鍚勮窇涓ゆ銆�
+        // 浼樺寲鍚庯細鍥哄畾鐨� 5 鏉¤仛鍚� SQL锛孌B 鍙鐞嗗綋鍓嶉〉鐨勯鐩��
+        //  1) 褰撳墠椤电殑闂鍒嗙粍鑱氬悎锛堝垎椤典笅鎺ㄥ埌 SQL锛�
+        List<Map<String, Object>> groupRows = serviceSubtaskDetailTraceMapper.selectTraceDealGroups(detailTraceDealVO);
+        //  2) 闂鎬绘暟锛堝垎椤� total锛屽叏閲忓彛寰勶級
+        long questionTotal = serviceSubtaskDetailTraceMapper.countTraceDealQuestions(detailTraceDealVO);
+        //  3) 姹囨�荤粺璁★紙鍏ㄩ噺鍙e緞锛屼笉鍙楀垎椤靛奖鍝嶏級
+        Map<String, Object> sumRow = serviceSubtaskDetailTraceMapper.sumTraceDeal(detailTraceDealVO);
+        long totalException = toLong(sumRow == null ? null : sumRow.get("totalException"), 0L);
+        long yesDealException = toLong(sumRow == null ? null : sumRow.get("yesDeal"), 0L);
+        long noDealException = totalException - yesDealException;
 
         List<DetailTraceDealDTO> detailTraceDealDTOList = new ArrayList<>();
-        long totalException = 0L;
-        long noDealException = 0L;
-        long yesDealException = 0L;
+        if (CollectionUtils.isNotEmpty(groupRows)) {
+            // 鏈〉娑夊強鐨勯棶棰樻枃鏈紝鍚庨潰 3 鏉℃煡璇㈤兘鎸夊畠杩囨护
+            List<String> questiontexts = groupRows.stream()
+                    .map(row -> row.get("questiontext"))
+                    .filter(Objects::nonNull)
+                    .map(String::valueOf)
+                    .distinct()
+                    .collect(Collectors.toList());
 
-        for (Map.Entry<String, List<ServiceSubtaskDetailTrace>> entry : groupByQuestion.entrySet()) {
-            List<ServiceSubtaskDetailTrace> group = entry.getValue();
-            DetailTraceDealDTO dto = new DetailTraceDealDTO();
+            //  4) 鏈〉闂鐨勮礋璐g瀹わ紙鎸夌瀹ょ紪鍙峰幓閲嶏級
+            Map<String, List<Map<String, Object>>> deptMap = new HashMap<>();
+            //  5) 鏈〉闂鐨勬渶鏂板鐞嗕汉/澶勭悊鏃堕棿
+            Map<String, Map<String, Object>> latestHandleMap = new HashMap<>();
+            if (CollectionUtils.isNotEmpty(questiontexts)) {
+                for (Map<String, Object> row : serviceSubtaskDetailTraceMapper.selectTraceDealDepts(detailTraceDealVO, questiontexts)) {
+                    String questiontext = row.get("questiontext") == null ? null : String.valueOf(row.get("questiontext"));
+                    if (questiontext == null) continue;
+                    Map<String, Object> deptMapItem = new HashMap<>();
+                    deptMapItem.put("deptName", row.get("deptName"));
+                    deptMapItem.put("deptCode", row.get("deptCode"));
+                    deptMap.computeIfAbsent(questiontext, key -> new ArrayList<>()).add(deptMapItem);
+                }
 
-            // 闂鍐呭
-            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())));
-            dto.setResponsibleDept(responsibleDept);
-
-            // 鏈夋晥濉啓鏁帮細閫氳繃缁勫唴鐨� scriptid 鍘� service_subtask_detail 琛ㄦ煡璇�
-            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();
-                query.setDelFlag("0");
-                for (Long scriptId : scriptIds) {
-                    query.setScriptid(scriptId);
-                    List<ServiceSubtaskDetail> details = serviceSubtaskDetailMapper.selectServiceSubtaskDetailList(query);
-                    effectiveFillNum += CollectionUtils.isEmpty(details) ? 0 : details.size();
+                for (Map<String, Object> row : serviceSubtaskDetailTraceMapper.selectTraceDealLatestHandle(detailTraceDealVO, questiontexts)) {
+                    String questiontext = row.get("questiontext") == null ? null : String.valueOf(row.get("questiontext"));
+                    if (questiontext == null) continue;
+                    // 鍚屼竴涓渶澶у鐞嗘椂闂村彲鑳芥湁澶氭潯锛屼繚鐣欑涓�鏉″嵆鍙紙鍘熷疄鐜板彇缁勫唴 handle_time 鏈�澶х殑閭f潯锛�
+                    latestHandleMap.putIfAbsent(questiontext, row);
                 }
             }
 
-            // 寮傚父濉啓鏁� = 褰撳墠鍒嗙粍鐨� List 鏁伴噺
-            long exceptionFillNum = group.size();
+            //  6) 鏈〉闂鐨勬湁鏁堝~鍐欐暟锛氫竴娆� group by 鏌ュ洖锛屾浛浠i�愪釜 scriptid 鏌ヨ
+            // 涓�涓棶棰樺彲鑳藉搴斿涓� scriptid锛屾墍浠ュ厛鎶� questiontext -> scriptid 鍒楄〃瑙e紑锛�
+            // 鍐嶆妸璇ラ棶棰樻墍鏈� scriptid 鐨勫~鍐欐暟鐩稿姞锛堜笌鍘熷疄鐜� for 寰幆绱姞鐨勫彛寰勪竴鑷达級
+            Map<String, List<Long>> questionScriptIds = new LinkedHashMap<>();
+            Set<Long> scriptIdSet = new LinkedHashSet<>();
+            for (Map<String, Object> row : groupRows) {
+                String questiontext = row.get("questiontext") == null ? null : String.valueOf(row.get("questiontext"));
+                if (questiontext == null) continue;
+                List<Long> ids = parseScriptIds(row.get("scriptids"));
+                questionScriptIds.put(questiontext, ids);
+                scriptIdSet.addAll(ids);
+            }
+            Map<Long, Long> effectiveFillMap = new HashMap<>();
+            if (CollectionUtils.isNotEmpty(scriptIdSet)) {
+                for (Map<String, Object> row : serviceSubtaskDetailMapper.countDetailByScriptIds(new ArrayList<>(scriptIdSet))) {
+                    Long scriptId = toLongObj(row.get("scriptid"));
+                    if (scriptId == null) continue;
+                    effectiveFillMap.put(scriptId, toLong(row.get("cnt"), 0L));
+                }
+            }
 
-            Map<String, Object> fillSituation = new HashMap<>();
-            fillSituation.put("effectiveFillNum", effectiveFillNum);
-            fillSituation.put("exceptionFillNum", exceptionFillNum);
-            dto.setFillSituation(fillSituation);
+            //  7) 缁勮杩斿洖缁撴瀯锛堥『搴� = SQL 鐨� order by questiontext锛屼繚璇佸垎椤电ǔ瀹氾級
+            for (Map<String, Object> row : groupRows) {
+                String questiontext = row.get("questiontext") == null ? null : String.valueOf(row.get("questiontext"));
+                if (questiontext == null) continue;
 
-            // 寮傚父闂澶勭悊鏁伴噺锛氫粠 handleFlag 缁熻
-            long yesDeal = group.stream().filter(t -> "1".equals(t.getHandleFlag())).count();
-            long noDeal = group.stream().filter(t -> !"1".equals(t.getHandleFlag())).count();
-            Map<String, Object> exceptionQuesNum = new HashMap<>();
-            exceptionQuesNum.put("yesDeal", yesDeal);
-            exceptionQuesNum.put("noDeal", noDeal);
-            exceptionQuesNum.put("all", exceptionFillNum);
-            dto.setExceptionQuesNum(exceptionQuesNum);
+                DetailTraceDealDTO dto = new DetailTraceDealDTO();
+                dto.setQuestiontext(questiontext);
+                Long scriptId = toLongObj(row.get("scriptid"));
+                dto.setScriptid(scriptId);
+                dto.setScriptids(parseScriptIds(row.get("scriptids")));
+                Object templateType = row.get("templateType");
+                dto.setTemplateType(templateType == null ? null : Integer.valueOf(String.valueOf(templateType)));
+                dto.setResponsibleDept(deptMap.getOrDefault(questiontext, new ArrayList<>()));
 
-            // 姹囨�荤粺璁$疮鍔�
-            totalException += exceptionFillNum;
-            noDealException += noDeal;
-            yesDealException += yesDeal;
+                long exceptionFillNum = toLong(row.get("exceptionFillNum"), 0L);
+                // 璇ラ棶棰樹笅鎵�鏈� scriptid 鐨勬湁鏁堝~鍐欐暟涔嬪拰锛堜竴涓� questiontext 鍙兘瀵瑰簲澶氫釜 scriptid锛�
+                long effectiveFillNum = 0L;
+                for (Long sid : questionScriptIds.getOrDefault(questiontext, new ArrayList<>())) {
+                    effectiveFillNum += effectiveFillMap.getOrDefault(sid, 0L);
+                }
+                Map<String, Object> fillSituation = new HashMap<>();
+                fillSituation.put("effectiveFillNum", effectiveFillNum);
+                fillSituation.put("exceptionFillNum", exceptionFillNum);
+                dto.setFillSituation(fillSituation);
 
-            // 鏈�鏂板鐞嗕汉鍜屽鐞嗘椂闂达紙鍙� handleTime 鏈�鏂扮殑涓�鏉★級
-            group.stream().filter(t -> t.getHandleTime() != null).max(Comparator.comparing(ServiceSubtaskDetailTrace::getHandleTime)).ifPresent(latest -> {
-                dto.setHandleBy(latest.getHandleBy());
-                dto.setHandleTime(latest.getHandleTime());
-            });
+                long yesDeal = toLong(row.get("yesDeal"), 0L);
+                long noDeal = toLong(row.get("noDeal"), 0L);
+                Map<String, Object> exceptionQuesNum = new HashMap<>();
+                exceptionQuesNum.put("yesDeal", yesDeal);
+                exceptionQuesNum.put("noDeal", noDeal);
+                exceptionQuesNum.put("all", exceptionFillNum);
+                dto.setExceptionQuesNum(exceptionQuesNum);
 
-            detailTraceDealDTOList.add(dto);
+                Map<String, Object> latestHandle = latestHandleMap.get(questiontext);
+                if (latestHandle != null) {
+                    dto.setHandleBy(latestHandle.get("handleBy") == null ? null : String.valueOf(latestHandle.get("handleBy")));
+                    Object handleTime = latestHandle.get("handleTime");
+                    dto.setHandleTime(handleTime instanceof Date ? (Date) handleTime : null);
+                }
+
+                detailTraceDealDTOList.add(dto);
+            }
         }
 
         Map<String, Object> result = new HashMap<>();
@@ -151,7 +195,36 @@
         result.put("totalException", totalException);
         result.put("noDealException", noDealException);
         result.put("yesDealException", yesDealException);
+        // 鍒嗛〉鎬绘暟锛堟寜闂缁村害锛夛紝controller 鐩存帴鐢ㄥ畠锛屼笉鐢ㄥ啀鍏ㄩ噺鏌ヤ竴閬�
+        result.put("questionTotal", questionTotal);
         return result;
+    }
+
+    private static Long toLongObj(Object value) {
+        if (value == null) return null;
+        if (value instanceof Number) return ((Number) value).longValue();
+        String text = String.valueOf(value).trim();
+        return text.isEmpty() ? null : Long.valueOf(text);
+    }
+
+    private static long toLong(Object value, long defaultValue) {
+        Long result = toLongObj(value);
+        return result == null ? defaultValue : result;
+    }
+
+    /**
+     * 瑙f瀽 group_concat(distinct scriptid) 鐨勭粨鏋滐紙濡� "101,102"锛変负 scriptid 鍒楄〃
+     */
+    private static List<Long> parseScriptIds(Object value) {
+        List<Long> scriptIds = new ArrayList<>();
+        if (value == null) return scriptIds;
+        for (String item : String.valueOf(value).split(",")) {
+            Long scriptId = toLongObj(item);
+            if (scriptId != null && !scriptIds.contains(scriptId)) {
+                scriptIds.add(scriptId);
+            }
+        }
+        return scriptIds;
     }
 
     /**
@@ -199,79 +272,4 @@
     public int deleteServiceSubtaskDetailTtraceById(Long id) {
         return serviceSubtaskDetailTraceMapper.deleteServiceSubtaskDetailTtraceById(id);
     }
-
-    @Override
-    public Map<String, Object> getSatisfactionExceptConfigQuestion(SatisfactionExceptConfigQuestionReqVO questionReqVO) {
-        // 鍒濆鍖栫粨鏋滈泦
-        Map<String, Object> result = new HashMap<>();
-
-        if (StringUtils.isEmpty(questionReqVO.getScriptType()) || questionReqVO.getScriptType().equals("1")) {
-            List<Map<String, Object>> voicetDataList = new ArrayList<>();
-            //鑾峰彇婊℃剰搴︾殑鍒嗙被
-            IvrLibaScriptAssort ivrLibaScriptAssort = new IvrLibaScriptAssort();
-            ivrLibaScriptAssort.setType("myd");
-            if (!StringUtils.isEmpty(questionReqVO.getType())) ivrLibaScriptAssort.setType(questionReqVO.getType());
-            List<IvrLibaScriptAssortVO> ivrLibaScriptAssortVOS = iIvrLibaScriptAssortService.selectIvrLibaScriptAssortList(ivrLibaScriptAssort);
-            List<Long> assortIdList = Optional.ofNullable(ivrLibaScriptAssortVOS).filter(list -> !list.isEmpty()).map(list -> list.stream().map(IvrLibaScriptAssortVO::getId).collect(Collectors.toList())).orElse(Collections.emptyList());
-
-            //鐢ㄦ潵璁板綍婊℃剰搴︾殑鎵�鏈夐棶棰�
-            List<IvrLibaTemplateScript> ivrLibaTemplateScriptList = new ArrayList<>();
-            if (CollectionUtils.isNotEmpty(assortIdList)) {
-                for (Long assortId : assortIdList) {
-                    IvrLibaTemplateScript ivrLibaTemplateScript = new IvrLibaTemplateScript();
-                    ivrLibaTemplateScript.setScriptAssortid(assortId);
-                    List<IvrLibaTemplateScript> ivrLibaTemplateScripts = iIvrLibaTemplateScriptService.selectIvrLibaTemplateScriptList(ivrLibaTemplateScript);
-                    ivrLibaTemplateScriptList.addAll(ivrLibaTemplateScripts);
-                }
-                for (IvrLibaTemplateScript ivrLibaTemplateScript : ivrLibaTemplateScriptList) {
-                    Map<String, Object> voicetData = new HashMap<>();
-                    voicetData.put("questionId", ivrLibaTemplateScript.getId());
-                    voicetData.put("libtemplateid", ivrLibaTemplateScript.getTemplateid());
-                    voicetData.put("questionContent", ivrLibaTemplateScript.getScriptContent());
-                    voicetData.put("questionTopic", ivrLibaTemplateScript.getScriptTopic());
-                    voicetData.put("questionType", ivrLibaTemplateScript.getScriptType());
-                    voicetData.put("categoryName", ivrLibaTemplateScript.getScriptAssortname());
-                    voicetData.put("categoryId", ivrLibaTemplateScript.getScriptAssortid());
-                    voicetDataList.add(voicetData);
-                }
-            }
-            //璇煶鏁版嵁杩斿洖闆嗗悎
-            result.put("voiceDataList", voicetDataList);
-        }
-
-        if (StringUtils.isEmpty(questionReqVO.getScriptType()) || questionReqVO.getScriptType().equals("2")) {
-            List<Map<String, Object>> questionnaireDataList = new ArrayList<>();
-            //鑾峰彇婊℃剰搴︾殑鍒嗙被
-            SvyLibScriptCategory svyLibScriptCategory = new SvyLibScriptCategory();
-            svyLibScriptCategory.setType("myd");
-            if (!StringUtils.isEmpty(questionReqVO.getType())) svyLibScriptCategory.setType(questionReqVO.getType());
-            List<SvyLibScriptCategory> svyLibScriptCategoryVOS = svyLibScriptCategoryMapper.selectSvyLibScriptCategoryList(svyLibScriptCategory);
-            List<Long> assortIdList = Optional.ofNullable(svyLibScriptCategoryVOS).filter(list -> !list.isEmpty()).map(list -> list.stream().map(SvyLibScriptCategory::getId).collect(Collectors.toList())).orElse(Collections.emptyList());
-
-            //鐢ㄦ潵璁板綍婊℃剰搴︾殑鎵�鏈夐棶棰�
-            List<SvyLibTemplateScript> svyLibTemplateScriptList = new ArrayList<>();
-            if (CollectionUtils.isNotEmpty(assortIdList)) {
-                for (Long categoryid : assortIdList) {
-                    SvyLibTemplateScript svyLibTemplateScript = new SvyLibTemplateScript();
-                    svyLibTemplateScript.setCategoryid(categoryid);
-                    List<SvyLibTemplateScript> svyLibTemplateScripts = isvyLibTemplateScriptService.selectSvyLibTemplateScriptList(svyLibTemplateScript);
-                    svyLibTemplateScriptList.addAll(svyLibTemplateScripts);
-                }
-                for (SvyLibTemplateScript svyLibTemplateScript : svyLibTemplateScriptList) {
-                    Map<String, Object> voicetData = new HashMap<>();
-                    voicetData.put("questionId", svyLibTemplateScript.getId());
-                    voicetData.put("libtemplateid", svyLibTemplateScript.getSvyid());
-                    voicetData.put("questionContent", svyLibTemplateScript.getScriptContent());
-                    voicetData.put("questionTopic", svyLibTemplateScript.getScriptTopic());
-                    voicetData.put("questionType", svyLibTemplateScript.getScriptType());
-                    voicetData.put("categoryName", svyLibTemplateScript.getCategoryName());
-                    voicetData.put("categoryId", svyLibTemplateScript.getCategoryid());
-                    questionnaireDataList.add(voicetData);
-                }
-            }
-            //闂嵎鏁版嵁杩斿洖闆嗗悎
-            result.put("questionnaireDataList", questionnaireDataList);
-        }
-        return result;
-    }
-}
+}
\ No newline at end of file

--
Gitblit v1.9.3