From 9198cc1d419a239096d8d083b8cec5be72def7c2 Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期四, 22 一月 2026 14:24:46 +0800
Subject: [PATCH] 【丽水】getSfStatistics 优化

---
 smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java |   85 +++++++++++++++++----------
 smartor/src/main/java/com/smartor/mapper/ServiceSubtaskMapper.java            |    4 
 smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml            |   36 ++++++++++--
 smartor/src/main/java/com/smartor/domain/ServiceSubtaskVO.java                |   13 ++++
 4 files changed, 98 insertions(+), 40 deletions(-)

diff --git a/smartor/src/main/java/com/smartor/domain/ServiceSubtaskVO.java b/smartor/src/main/java/com/smartor/domain/ServiceSubtaskVO.java
index 7dca9b1..123d78e 100644
--- a/smartor/src/main/java/com/smartor/domain/ServiceSubtaskVO.java
+++ b/smartor/src/main/java/com/smartor/domain/ServiceSubtaskVO.java
@@ -738,6 +738,19 @@
     @ApiModelProperty(value = "闅忚閮ㄩ棬缂栫爜闆嗗悎")
     private List<String> visitDeptCodes;
 
+    /**
+     * 鍖荤敓缂栫爜
+     */
+    @Excel(name = "鍒嗙粍key")
+    @ApiModelProperty(value = "鍒嗙粍key")
+    private String groupKey;
+    /**
+     * 鍖荤敓缂栫爜
+     */
+    @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 870ef3c..2f64842 100644
--- a/smartor/src/main/java/com/smartor/mapper/ServiceSubtaskMapper.java
+++ b/smartor/src/main/java/com/smartor/mapper/ServiceSubtaskMapper.java
@@ -70,11 +70,11 @@
     /**
      * 闅忚鍙婃椂鐜囷細搴旈殢璁挎椂闂�<瀹為檯闅忚鏃堕棿
      *
-     * @param ServiceSubtask
+     * @param ServiceSubtaskvo
      * @return
      */
     @MapKey("groupKey")
-    public Map<String, Double> selectTimelyRateBatch(ServiceSubtask ServiceSubtask);
+    public Map<String, Map<String,Object>> selectTimelyRateBatch(ServiceSubtaskVO ServiceSubtaskvo);
     /**
      * 闅忚鍙婃椂鐜囪鎯�
      *
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 f98f258..0041822 100644
--- a/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
@@ -2226,7 +2226,7 @@
      * @return
      */
     @Override
-    @Cacheable(value = "sfStatistics", key = "T(org.springframework.util.DigestUtils).md5DigestAsHex(#serviceSubtaskCountReq.toString().getBytes())", unless = "#result == null or #result.isEmpty()")
+//    @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) {
         log.info("getSfStatistics鐨勫叆鍙備负锛歿}", serviceSubtaskCountReq);
         List<ServiceSubtaskStatistic> serviceSubtaskStatistics = new ArrayList<>();
@@ -2235,50 +2235,71 @@
         // 鏍规嵁鏉′欢杩涜鍒嗙粍
         Map<String, List<ServiceSubtask>> collect = new HashMap<>();
 
-        if (serviceSubtaskCountReq.getLeavehospitaldistrictcodes() != null && serviceSubtaskCountReq.getLeavehospitaldistrictcodes().size() > 0) {
+        String groupKeyType = "";
+
+        if (serviceSubtaskCountReq.getLeavehospitaldistrictcodes() != null && !serviceSubtaskCountReq.getLeavehospitaldistrictcodes().isEmpty()) {
             if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) {
-                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrname()).orElse("Unknown")));
+                groupKeyType = "drCode";
+                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrcode()).orElse("Unknown")));
             } else {
-                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getLeavehospitaldistrictname()).orElse("Unknown")));
+                groupKeyType = "leaveHospitalDistrictCode";
+                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getLeavehospitaldistrictcode()).orElse("Unknown")));
             }
-        } else if (serviceSubtaskCountReq.getDeptcodes() != null && serviceSubtaskCountReq.getDeptcodes().size() > 0) {
+        } else if (serviceSubtaskCountReq.getDeptcodes() != null && !serviceSubtaskCountReq.getDeptcodes().isEmpty()) {
             if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) {
-                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrname()).orElse("Unknown")));
+                groupKeyType = "drCode";
+                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrcode()).orElse("Unknown")));
             } else {
-                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDeptname()).orElse("Unknown")));
+                groupKeyType = "deptCode";
+                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDeptcode()).orElse("Unknown")));
             }
         }
+        List<String> groupKeyList = new ArrayList<>(collect.keySet());
+        //鍙婃椂鐜�
+        ServiceSubtaskVO ssRate = new ServiceSubtaskVO();
+        ssRate.setOrgid(serviceSubtaskCountReq.getOrgid());
+        ssRate.setStarttime(serviceSubtaskCountReq.getStartTime());
+        ssRate.setEndtime(serviceSubtaskCountReq.getEndTime());
+        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;
+        }
+        Map<String, Map<String, Object>> jsRates = new HashMap<>();
+        if(!collect.isEmpty()){
+            jsRates = serviceSubtaskMapper.selectTimelyRateBatch(ssRate);
+        }
 
-
-        for (List<ServiceSubtask> serviceSubtaskList : collect.values()) {
+        for (String collectKey : collect.keySet()) {
+            List<ServiceSubtask> serviceSubtaskList = collect.get(collectKey);
             if (CollectionUtils.isEmpty(serviceSubtaskList)) {
                 continue;
             }
             ServiceSubtaskStatistic statistic = getStatistic(serviceSubtaskList);
-
-            //鍙婃椂鐜�
-            ServiceSubtask ss = new ServiceSubtask();
-            ss.setOrgid(serviceSubtaskList.get(0).getOrgid());
-
-            // 濡傛灉鏈夊尰鐢熺紪鐮侊紝璁剧疆鍖荤敓缂栫爜鐢ㄤ簬鍙婃椂鐜囨煡璇�
-            if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) {
-                ss.setDrcode(serviceSubtaskList.get(0).getDrcode());
-            } else {
-                if (CollectionUtils.isNotEmpty(serviceSubtaskCountReq.getLeavehospitaldistrictcodes())) {
-                    ss.setLeavehospitaldistrictcode(serviceSubtaskList.get(0).getLeavehospitaldistrictcode());
-                } else if (CollectionUtils.isNotEmpty(serviceSubtaskCountReq.getDeptcodes())) {
-                    ss.setDeptcode(serviceSubtaskList.get(0).getDeptcode());
-                }
+            Map<String, Object> jsRateMap = jsRates.get(collectKey);
+            BigDecimal jsRate = new BigDecimal("0");
+            if(ObjectUtils.isNotEmpty(jsRateMap) && ObjectUtils.isNotEmpty(jsRateMap.get("rate"))){
+                jsRate = new BigDecimal(jsRateMap.get("rate").toString());
             }
-
-            ss.setStarttime(serviceSubtaskCountReq.getStartTime());
-            ss.setEndtime(serviceSubtaskCountReq.getEndTime());
-            if (serviceSubtaskCountReq.getEndTime() != null && new Date().before(serviceSubtaskCountReq.getEndTime())) {
-                ss.setEndtime(new Date());
-            }
-            Double jsRate = serviceSubtaskMapper.selectTimelyRate(ss);
-            statistic.setRate(jsRate);
-
+            Double jsRateDouble = (jsRate.setScale(4, RoundingMode.HALF_UP)).doubleValue();
+            statistic.setRate(jsRateDouble);
             if (ObjectUtils.isNotEmpty(statistic)) {
                 serviceSubtaskStatistics.add(statistic);
             }
diff --git a/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml b/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
index 312e13a..30e4c15 100644
--- a/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
+++ b/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
@@ -563,16 +563,40 @@
 
     <select id="selectTimelyRateBatch" parameterType="com.smartor.domain.ServiceSubtask" resultType="map">
         SELECT
-        <if test="deptcode != null">deptcode as groupKey,</if>
-        <if test="leavehospitaldistrictcode != null">leavehospitaldistrictcode as groupKey,</if>
-        <if test="drcode != null">drcode as groupKey,</if>
+        <if test="groupKey != null and groupKey != ''">
+            ${groupKey} as groupKey,
+        </if>
         SUM(CASE WHEN DATE(visit_time) &lt; DATE(IFNULL(finishtime, NOW())) THEN 1 ELSE 0 END) / COUNT(*) as rate
         FROM service_subtask
         WHERE del_flag = 0
-        AND visit_time >= #{starttime}
-        AND visit_time &lt; DATE_ADD(#{endtime}, INTERVAL 1 DAY)
         <if test="orgid != null">AND orgid = #{orgid}</if>
-        GROUP BY groupKey
+        <if test="starttime == null and endtime==null">
+            AND visit_time &lt; NOW()
+        </if>
+        <if test="starttime != null and endtime!=null">
+            AND visit_time >= #{starttime}
+            AND visit_time &lt; DATE_ADD(#{endtime}, INTERVAL 1 DAY)
+        </if>
+        <if test="orgid != null  and orgid != ''">and orgid = #{orgid}</if>
+        <if test="deptcode != null  and deptcode != ''">and deptcode = #{deptcode}</if>
+        <if test="deptname != null  and deptname != ''">and deptname = #{deptname}</if>
+        <if test="isabnormal != null">and isabnormal = #{isabnormal}</if>
+        <if test="leavehospitaldistrictcode != null  and leavehospitaldistrictcode != ''">and
+            leavehospitaldistrictcode = #{leavehospitaldistrictcode}
+        </if>
+        <if test="leavehospitaldistrictname != null  and leavehospitaldistrictname != ''">and
+            leavehospitaldistrictname = #{leavehospitaldistrictname}
+        </if>
+        <if test="managementDoctorCode != null">and management_doctor_code = #{managementDoctorCode}</if>
+        <if test="managementDoctor != null">and management_doctor like concat('%',#{managementDoctor}, '%')</if>
+        <if test="groupKey != null and groupKey != ''">
+            AND ${groupKey} IN
+            <foreach collection="groupKeyList" item="key" open="(" separator=","
+                     close=")">
+                #{key}
+            </foreach>
+            GROUP BY ${groupKey}
+        </if>
     </select>
 
 

--
Gitblit v1.9.3