From c3395d01203fd57d191b36f3410f8ae6e6aafd09 Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期四, 22 一月 2026 16:41:00 +0800
Subject: [PATCH] 【丽水】getSfStatistics、getSfStatisticsScript 优化

---
 smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java |  104 ++++++++++++++++++----------------
 smartor/src/main/java/com/smartor/domain/ServiceSubtaskCountReq.java          |   11 +++
 smartor/src/main/java/com/smartor/mapper/ServiceSubtaskMapper.java            |    2 
 smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml            |   55 ++++++++++++++++++
 smartor/src/main/java/com/smartor/domain/ServiceSubtaskVO.java                |    6 -
 5 files changed, 125 insertions(+), 53 deletions(-)

diff --git a/smartor/src/main/java/com/smartor/domain/ServiceSubtaskCountReq.java b/smartor/src/main/java/com/smartor/domain/ServiceSubtaskCountReq.java
index f8030b3..79c133a 100644
--- a/smartor/src/main/java/com/smartor/domain/ServiceSubtaskCountReq.java
+++ b/smartor/src/main/java/com/smartor/domain/ServiceSubtaskCountReq.java
@@ -99,6 +99,17 @@
     private String groupKeyType;
 
     /**
+     * 鍒嗙粍key
+     */
+    @ApiModelProperty(value = "鍒嗙粍key")
+    private String groupKey;
+    /**
+     * 鍒嗙粍code闆嗗悎
+     */
+    @ApiModelProperty(value = "鍒嗙粍code闆嗗悎")
+    private List<String> groupKeyList;
+
+    /**
      * pageNum
      */
     @ApiModelProperty("pageNum")
diff --git a/smartor/src/main/java/com/smartor/domain/ServiceSubtaskVO.java b/smartor/src/main/java/com/smartor/domain/ServiceSubtaskVO.java
index 123d78e..912f1ac 100644
--- a/smartor/src/main/java/com/smartor/domain/ServiceSubtaskVO.java
+++ b/smartor/src/main/java/com/smartor/domain/ServiceSubtaskVO.java
@@ -739,15 +739,13 @@
     private List<String> visitDeptCodes;
 
     /**
-     * 鍖荤敓缂栫爜
+     * 鍒嗙粍key
      */
-    @Excel(name = "鍒嗙粍key")
     @ApiModelProperty(value = "鍒嗙粍key")
     private String groupKey;
     /**
-     * 鍖荤敓缂栫爜
+     * 鍒嗙粍code闆嗗悎
      */
-    @Excel(name = "鍒嗙粍code闆嗗悎")
     @ApiModelProperty(value = "鍒嗙粍code闆嗗悎")
     private List<String> groupKeyList;
 
diff --git a/smartor/src/main/java/com/smartor/mapper/ServiceSubtaskMapper.java b/smartor/src/main/java/com/smartor/mapper/ServiceSubtaskMapper.java
index 2f64842..6d3b69c 100644
--- a/smartor/src/main/java/com/smartor/mapper/ServiceSubtaskMapper.java
+++ b/smartor/src/main/java/com/smartor/mapper/ServiceSubtaskMapper.java
@@ -117,6 +117,8 @@
 
     public List<ServiceSubtask> getSfStatistics(ServiceSubtaskCountReq serviceSubtaskCountReq);
 
+    public List<String> getSfStatisticsGroupKey(ServiceSubtaskCountReq serviceSubtaskCountReq);
+
     public List<ServiceSubtaskCount> getSfStatisticsJoy(ServiceSubtaskCountReq serviceSubtaskCountReq);
 
     public List<ServiceSubtaskCount> getSfStatisticsJoydetails(ServiceSubtaskCountReq serviceSubtaskCountReq);
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 c1605f2..068d985 100644
--- a/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
@@ -2228,33 +2228,43 @@
     @Override
     @Cacheable(value = "sfStatistics", key = "T(org.springframework.util.DigestUtils).md5DigestAsHex(#serviceSubtaskCountReq.toString().getBytes())", unless = "#result == null or #result.isEmpty()")
     public List<ServiceSubtaskStatistic> getSfStatistics(ServiceSubtaskCountReq serviceSubtaskCountReq) {
-        //todo
         log.info("getSfStatistics鐨勫叆鍙備负锛歿}", serviceSubtaskCountReq);
-        List<ServiceSubtaskStatistic> serviceSubtaskStatistics = new ArrayList<>();
-        List<ServiceSubtask> rawData = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq);
-
-        // 鏍规嵁鏉′欢杩涜鍒嗙粍
-        Map<String, List<ServiceSubtask>> collect = new HashMap<>();
-
-        String groupKeyType = "";
+        String groupKey = "drcode";
         if (serviceSubtaskCountReq.getLeavehospitaldistrictcodes() != null && !serviceSubtaskCountReq.getLeavehospitaldistrictcodes().isEmpty()) {
             if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) {
-                groupKeyType = "drCode";
-                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrcode()).orElse("Unknown")));
+                groupKey = "drcode";
             } else {
-                groupKeyType = "leaveHospitalDistrictCode";
-                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getLeavehospitaldistrictcode()).orElse("Unknown")));
+                groupKey = "leavehospitaldistrictcode";
             }
         } else if (serviceSubtaskCountReq.getDeptcodes() != null && !serviceSubtaskCountReq.getDeptcodes().isEmpty()) {
             if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) {
-                groupKeyType = "drCode";
-                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrcode()).orElse("Unknown")));
+                groupKey = "drcode";
             } else {
-                groupKeyType = "deptCode";
-                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDeptcode()).orElse("Unknown")));
+                groupKey = "deptcode";
             }
         }
-        serviceSubtaskCountReq.setGroupKeyType(groupKeyType);
+        List<ServiceSubtaskStatistic> serviceSubtaskStatistics = new ArrayList<>();
+        // 鏍规嵁鏉′欢杩涜鍒嗙粍
+        Map<String, List<ServiceSubtask>> collect = new HashMap<>();
+        serviceSubtaskCountReq.setGroupKey(groupKey);
+        List<String> groupKeyList = serviceSubtaskMapper.getSfStatisticsGroupKey(serviceSubtaskCountReq);
+        serviceSubtaskCountReq.setGroupKeyList(groupKeyList);
+        List<ServiceSubtask> rawData = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq);
+        switch (groupKey)
+        {
+            case "deptcode":
+                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDeptcode()).orElse("Unknown")));
+                break;
+            case "drcode":
+                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrcode()).orElse("Unknown")));
+                break;
+            case "leavehospitaldistrictcode":
+                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getLeavehospitaldistrictcode()).orElse("Unknown")));
+                break;
+            default:
+                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrcode()).orElse("Unknown")));
+                break;
+        }
         //鑾峰彇鍙婃椂鐜囩粺璁″悎闆�
         Map<String, Map<String, Object>> jsRates = getSsRateForSfStatistics(serviceSubtaskCountReq, collect);
         for (String collectKey : collect.keySet()) {
@@ -2290,8 +2300,8 @@
         if(ObjectUtils.isEmpty(serviceSubtaskCountReq)){
             return null;
         }
-        String groupKeyType = serviceSubtaskCountReq.getGroupKeyType();
-        if(StringUtils.isEmpty(groupKeyType)){
+        String groupKey = serviceSubtaskCountReq.getGroupKey();
+        if(StringUtils.isEmpty(groupKey)){
             return null;
         }
         List<String> groupKeyList = new ArrayList<>(collect.keySet());
@@ -2306,25 +2316,8 @@
         if (serviceSubtaskCountReq.getEndTime() != null && new Date().before(serviceSubtaskCountReq.getEndTime())) {
             ssRate.setEndtime(new Date());
         }
-        switch (groupKeyType)
-        {
-            case "deptCode":
-                ssRate.setGroupKey("deptcode");
-                ssRate.setGroupKeyList(groupKeyList);
-                break;
-            case "drCode":
-                ssRate.setGroupKey("drcode");
-                ssRate.setGroupKeyList(groupKeyList);
-                break;
-            case "leaveHospitalDistrictCode":
-                ssRate.setGroupKey("leavehospitaldistrictcode");
-                ssRate.setGroupKeyList(groupKeyList);
-                break;
-            default:
-                ssRate.setGroupKey("drcode");
-                ssRate.setGroupKeyList(groupKeyList);
-                break;
-        }
+        ssRate.setGroupKey(groupKey);
+        ssRate.setGroupKeyList(groupKeyList);
         Map<String, Map<String, Object>> jsRates = new HashMap<>();
         if(!collect.isEmpty()){
             jsRates = serviceSubtaskMapper.selectTimelyRateBatch(ssRate);
@@ -3131,29 +3124,42 @@
     public List<ServiceSubtaskStatistic> getSfStatisticsScript(ServiceSubtaskCountReq serviceSubtaskCountReq) {
         log.info("getSfStatisticsScript鐨勫叆鍙備负锛歿}", serviceSubtaskCountReq);
         List<ServiceSubtaskStatistic> serviceSubtaskStatistics = new ArrayList<>();
-        List<ServiceSubtask> rawData = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq);
 
         // 鏍规嵁鏉′欢杩涜鍒嗙粍
         Map<String, List<ServiceSubtask>> collect = new HashMap<>();
-        String groupKeyType = "";
+        String groupKey = "drcode";
         if (serviceSubtaskCountReq.getLeavehospitaldistrictcodes() != null && !serviceSubtaskCountReq.getLeavehospitaldistrictcodes().isEmpty()) {
             if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) {
-                groupKeyType = "drCode";
-                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrcode()).orElse("Unknown")));
+                groupKey = "drcode";
             } else {
-                groupKeyType = "leaveHospitalDistrictCode";
-                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getLeavehospitaldistrictcode()).orElse("Unknown")));
+                groupKey = "leavehospitaldistrictcode";
             }
         } else if (serviceSubtaskCountReq.getDeptcodes() != null && !serviceSubtaskCountReq.getDeptcodes().isEmpty()) {
             if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) {
-                groupKeyType = "drCode";
-                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrcode()).orElse("Unknown")));
+                groupKey = "drcode";
             } else {
-                groupKeyType = "deptCode";
-                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDeptcode()).orElse("Unknown")));
+                groupKey = "deptcode";
             }
         }
-        serviceSubtaskCountReq.setGroupKeyType(groupKeyType);
+        serviceSubtaskCountReq.setGroupKey(groupKey);
+        List<String> groupKeyList = serviceSubtaskMapper.getSfStatisticsGroupKey(serviceSubtaskCountReq);
+        serviceSubtaskCountReq.setGroupKeyList(groupKeyList);
+        List<ServiceSubtask> rawData = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq);
+        switch (groupKey)
+        {
+            case "deptcode":
+                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDeptcode()).orElse("Unknown")));
+                break;
+            case "drcode":
+                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrcode()).orElse("Unknown")));
+                break;
+            case "leavehospitaldistrictcode":
+                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getLeavehospitaldistrictcode()).orElse("Unknown")));
+                break;
+            default:
+                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrcode()).orElse("Unknown")));
+                break;
+        }
         //鑾峰彇鍙婃椂鐜囩粺璁″悎闆�
         Map<String, Map<String, Object>> jsRates = getSsRateForSfStatistics(serviceSubtaskCountReq, collect);
         for (String collectKey : collect.keySet()) {
diff --git a/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml b/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
index 30e4c15..b5588c7 100644
--- a/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
+++ b/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
@@ -1255,6 +1255,61 @@
             <!-- 鐩墠鍙粺璁¤闊冲拰闂嵎 -->
             <if test="type != null">
                 and type = #{type}
+        </if>
+        <if test="groupKey != null and groupKey != '' and groupKeyList != null and groupKeyList.size>0">
+            AND ${groupKey} IN
+            <foreach collection="groupKeyList" item="key" open="(" separator=","
+                     close=")">
+                #{key}
+            </foreach>
+        </if>
+    </select>
+    <select id="getSfStatisticsGroupKey" parameterType="com.smartor.domain.ServiceSubtaskCountReq"
+            resultType="String">
+            select
+            <if test="groupKey != null and groupKey != ''">
+                ${groupKey} as groupKey
+            </if>
+            from service_subtask
+            where 1=1
+            and del_flag = 0
+            <if test="orgid != null and orgid != ''">
+            and orgid = #{orgid}
+            </if>
+            <if test="leavehospitaldistrictcodes != null and leavehospitaldistrictcodes.size() > 0">
+            AND leavehospitaldistrictcode IN
+            <foreach collection="leavehospitaldistrictcodes" item="leavehospitaldistrictcode" open="(" separator=","
+                     close=")">
+                #{leavehospitaldistrictcode}
+            </foreach>
+            </if>
+            <if test="deptcodes != null and deptcodes.size() > 0">
+            AND deptcode IN
+            <foreach collection="deptcodes" item="deptcode" open="(" separator=","
+                     close=")">
+                #{deptcode}
+            </foreach>
+            </if>
+            <if test="serviceType != null and serviceType.size() > 0">
+            AND service_type IN
+            <foreach collection="serviceType" item="serviceType" open="(" separator=","
+                     close=")">
+                #{serviceType}
+            </foreach>
+            </if>
+            <if test="startTime != null and endTime!=null">
+            AND visit_time >= DATE(#{startTime})
+            AND visit_time &lt; DATE_ADD(DATE(#{endTime}), INTERVAL 1 DAY)
+            </if>
+            <if test="visitDeptCode != null">and visit_dept_code = #{visitDeptCode}</if>
+            <if test="visitDeptName != null">and visit_dept_name = #{visitDeptName}</if>
+            <if test="isabnormal != null">and isabnormal = #{isabnormal}</if>
+            <!-- 鐩墠鍙粺璁¤闊冲拰闂嵎 -->
+            <if test="type != null">
+            and type = #{type}
+            </if>
+            <if test="groupKey != null and groupKey != ''">
+                group by ${groupKey}
             </if>
             <if test="pageSize != null  and pageNum != null">
                 limit ${pageSize} OFFSET ${pageNum}

--
Gitblit v1.9.3