From a2dd5b42824eff9626d1f48e1561be85f17f6107 Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期五, 23 十月 2026 16:36:19 +0800
Subject: [PATCH] 【丽水】指标统计查看详情里面问题重复了,本来应该只有3条,里面18条

---
 smartor/src/main/java/com/smartor/service/impl/SvyLibTemplateScriptServiceImpl.java      |   40 +++++++------
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/ServiceSubtaskController.java |   14 ++++
 smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java            |   70 ++++++++++++++++-------
 smartor/src/main/java/com/smartor/service/IServiceSubtaskService.java                    |    2 
 smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml                       |   30 +++++++---
 5 files changed, 104 insertions(+), 52 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/ServiceSubtaskController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/ServiceSubtaskController.java
index f4434ea..f857470 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/ServiceSubtaskController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/smartor/ServiceSubtaskController.java
@@ -811,8 +811,18 @@
         LoginUser loginUser = getLoginUser();
         String orgid = loginUser.getUser().getOrgid();
         serviceSubtaskCountReq.setOrgid(orgid);
-        PageUtils.startPageByPost(serviceSubtaskCountReq.getPageNum(), serviceSubtaskCountReq.getPageSize());
-        return success(serviceSubtaskService.getSfStatisticsScriptDetails(serviceSubtaskCountReq));
+        //娉ㄦ剰锛氳繖閲屼笉鑳藉啀璋冪敤 PageUtils.startPageByPost銆�
+        //杩斿洖缁撴瀯鏄� Map锛屼笖涓嶄紶 type 鏃朵細鎵ц涓ゆ潯 SQL锛孭ageHelper 鍙綔鐢ㄤ簬绗竴鏉� SQL锛�
+        //鍒嗛〉宸叉斁鍒� Service 閲屾寜棰樼洰锛坰criptid锛夊畬鎴愶紝淇濊瘉 total 鏄鐩�绘暟銆�
+        Map<String, Object> details = serviceSubtaskService.getSfStatisticsScriptDetails(serviceSubtaskCountReq);
+        AjaxResult ajax = success(details.get("data"));
+        //鍏煎鏃у墠绔細data 浠嶇劧鏄� {scriptid: 棰樼洰} 鐨� Map锛�
+        //鍚屾椂鎸� RuoYi 涔犳儻琛ヤ笂 rows/total/pageNum/pageSize 鏂逛究鍓嶇鍒嗛〉
+        ajax.put("rows", details.get("rows"));
+        ajax.put("total", details.get("total"));
+        ajax.put("pageNum", details.get("pageNum"));
+        ajax.put("pageSize", details.get("pageSize"));
+        return ajax;
     }
 
     /**
diff --git a/smartor/src/main/java/com/smartor/service/IServiceSubtaskService.java b/smartor/src/main/java/com/smartor/service/IServiceSubtaskService.java
index 2ec5625..8b56ef5 100644
--- a/smartor/src/main/java/com/smartor/service/IServiceSubtaskService.java
+++ b/smartor/src/main/java/com/smartor/service/IServiceSubtaskService.java
@@ -200,7 +200,7 @@
 
     public List<ServiceSubtaskStatistic> getSfStatisticsScript(ServiceSubtaskCountReq serviceSubtaskCountReq);
 
-    public Map<String, ServiceSubtaskScriptCount> getSfStatisticsScriptDetails(ServiceSubtaskCountReq serviceSubtaskCountReq);
+    public Map<String, Object> getSfStatisticsScriptDetails(ServiceSubtaskCountReq serviceSubtaskCountReq);
 
     public List<PatArchiveSrmVO> sendMsgTemplate(List<PatArchiveSrmVO> patArchiveSrmVOS);
 
diff --git a/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
index b86de2f..a170ee4 100644
--- a/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
@@ -5004,8 +5004,7 @@
     }
 
     @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();
@@ -5029,7 +5028,23 @@
             allItemCounts = serviceSubtaskMapper.getSfStatisticsScriptItemDetails(serviceSubtaskCountReq);
         }
 
-        for (ServiceSubtaskScriptCount count : allCounts) {
+        //杩斿洖缁撴瀯鏄� Map锛屼笖涓嶄紶 type 鏃朵細鎵ц涓ゆ潯 SQL锛孭ageHelper 娌℃硶瀵规暣浣撳垎椤碉紝
+        //鎵�浠ュ湪棰樼洰鍚堝苟瀹屾垚涔嬪悗鎸夐鐩紙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")) {
@@ -5060,31 +5075,42 @@
                 }
             }
             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 鏄鐩�绘暟锛堝凡鎸夐鐩悎骞讹級锛宺ows/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;
     }
 
diff --git a/smartor/src/main/java/com/smartor/service/impl/SvyLibTemplateScriptServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/SvyLibTemplateScriptServiceImpl.java
index 0f9761f..d2a72ef 100644
--- a/smartor/src/main/java/com/smartor/service/impl/SvyLibTemplateScriptServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/SvyLibTemplateScriptServiceImpl.java
@@ -16,6 +16,7 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 
 import static net.sf.jsqlparser.parser.feature.Feature.values;
 
@@ -157,25 +158,28 @@
                     }
                 }
                 itemCounts.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);
+                    //鏄庣粏琛屽凡鎸夆�滈鐩唴瀹�+浠诲姟绫诲瀷鈥濊仛鍚堬紝涓嶈兘鐢� 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> details = new ArrayList<>(itemCountMap.values());
diff --git a/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml b/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
index 0f34f88..d9513ec 100644
--- a/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
+++ b/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
@@ -2281,14 +2281,14 @@
     <select id="getSfStatisticsScriptDetails" parameterType="com.smartor.domain.ServiceSubtaskCountReq"
             resultMap="ServiceSubtaskScriptCountResult">
         SELECT
-        a.id as scriptid,
-        a.templateid as templateid,
-        a.script_type,
+        MIN(a.id) as scriptid,
+        MIN(a.templateid) as templateid,
+        MIN(a.script_type) as script_type,
         a.script_content,
         b.subtask_type,
-        b.completed_quantity,
-        b.all_quantity,
-        ROUND(b.completed_quantity/b.all_quantity,2) as completed_percentage
+        SUM(b.completed_quantity) as completed_quantity,
+        SUM(b.all_quantity) as all_quantity,
+        ROUND(SUM(b.completed_quantity)/SUM(b.all_quantity),2) as completed_percentage
         FROM
         <if test="type == 1">
             ivr_task_template_script a
@@ -2351,25 +2351,37 @@
         group by ssd.scriptid) b
         ON a.id = b.scriptid
         <!-- 閫傜敤鍗曟潯鏌ヨ -->
-        <if test="scriptids != null">
+        <if test="scriptids != null and scriptids != ''">
             AND a.scriptid in
             (SELECT lib_script.scriptid FROM
             svy_lib_template_script lib_script
             WHERE lib_script.scriptid in (${scriptids}))
         </if>
+        <!-- 鍚屼竴閬撻浼氳澶嶅埗鍒板涓换鍔℃ā鏉匡紝鎸夐鐩唴瀹瑰悎骞讹紝淇濊瘉涓�閬撻鍙繑鍥炰竴鏉� -->
+        GROUP BY a.script_content, b.subtask_type
+        ORDER BY MIN(a.id)
     </select>
 
     <select id="getSfStatisticsScriptItemDetails" parameterType="com.smartor.domain.ServiceSubtaskCountReq"
             resultMap="ServiceSubtaskScriptCountResult">
         SELECT
-        ssd.scriptid,
+        a.script_content,
+        ss.type as subtask_type,
         IFNULL(ssd.matchedtext,ssd.asrtext) AS option_text,
         COUNT(*) AS chosen_quantity
         FROM
         service_subtask_detail ssd
         INNER JOIN service_subtask ss ON ssd.sub_id = ss.id
+        INNER JOIN
+        <if test="type == 1">
+            ivr_task_template_script a ON a.id = ssd.scriptid
+        </if>
+        <if test="type == 2">
+            svy_task_template_script a ON a.id = ssd.scriptid
+        </if>
         where 1=1
         and ss.del_flag=0
+        and ssd.del_flag=0
         <if test="orgid != null and orgid != ''">
             and ss.orgid = #{orgid}
         </if>
@@ -2408,7 +2420,7 @@
         <if test="configValue != null and configValue != ''">
             AND ssd.categoryid IN (${configValue})
         </if>
-        group by ssd.scriptid, IFNULL(ssd.matchedtext,ssd.asrtext)
+        group by a.script_content, ss.type, IFNULL(ssd.matchedtext,ssd.asrtext)
     </select>
 
     <select id="getDataByTime" resultMap="ServiceSubtaskResult">

--
Gitblit v1.9.3