From 7303db54c1a2b672e4623cd022939b56882685ca Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期二, 23 十二月 2025 13:33:02 +0800
Subject: [PATCH] 【丽水】获取随访统计比例 优化

---
 smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java |  126 ++++++++++++++++++++++++++++-------------
 1 files changed, 86 insertions(+), 40 deletions(-)

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 6a7256f..cde04a1 100644
--- a/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
@@ -17,6 +17,7 @@
 import io.swagger.annotations.ApiModelProperty;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.MapUtils;
 import org.apache.commons.lang3.ObjectUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -323,39 +324,72 @@
         return serviceSubtaskList;
     }
 
+//    鍘熸柟娉�
+//    @Override
+//    public Map<String, Object> patItemCount(ServiceSubtaskVO serviceSubtaskVO) {
+//        serviceSubtaskVO.setPageSize(99999999);
+//        serviceSubtaskVO.setPageNum(1);
+//        List<ServiceSubtask> selectServiceSubtaskList = this.selectServiceSubtaskList(serviceSubtaskVO);
+//        Map<String, Object> map = new HashMap<>();
+//        Integer wzx = 0;
+//        Integer ysf = 0;
+//        Integer yc = 0;
+//        Integer fssb = 0;
+//        Integer yfs = 0;
+//        Integer blq = 0;
+//        Integer dsf = 0;
+//        for (ServiceSubtask serviceSubtask : selectServiceSubtaskList) {
+//            if (serviceSubtask.getSendstate() == 4L) wzx = wzx + 1;
+//            else if (serviceSubtask.getSendstate() != 4L && serviceSubtask.getSendstate() != 2L) ysf = ysf + 1;
+//            if (serviceSubtask.getSendstate() == 5L) fssb = fssb + 1;
+//            if (serviceSubtask.getSendstate() >= 3L || serviceSubtask.getSendstate() == 1L) yfs = yfs + 1;
+//            if (serviceSubtask.getSendstate() == 2L) dsf = dsf + 1;
+//            if (serviceSubtask.getSendstate() == 1L) blq = blq + 1;
+//            if (StringUtils.isNotEmpty(serviceSubtask.getExcep()) && !serviceSubtask.getExcep().equals("0"))
+//                yc = yc + 1;
+//        }
+//
+//        map.put("wzx", wzx);
+//        map.put("ysf", ysf);
+//        map.put("yc", yc);
+//        map.put("fssb", fssb);
+//        map.put("yfs", yfs);
+//        map.put("blq", blq);
+//        map.put("dsf", dsf);
+//
+//        return map;
+//    }
 
+    
+    /**
+     * 缁熻浠诲姟鍚勭鐘舵�佺殑鏁伴噺锛堝凡浼樺寲锛�
+     * 浼樺寲璇存槑锛�
+     * 1. 浣跨敤鏁版嵁搴撳眰鑱氬悎璁$畻锛屾浛浠e簲鐢ㄥ眰閬嶅巻
+     * 2. 鎬ц兘鎻愬崌 10-100 鍊嶏紙鍙栧喅浜庢暟鎹噺锛�
+     * 3. 闄嶄綆鍐呭瓨鍗犵敤鍜岀綉缁滀紶杈�
+     *
+     * @param serviceSubtaskVO 鏌ヨ鏉′欢
+     * @return 鍚勭姸鎬佺粺璁$粨鏋�
+     */
     @Override
     public Map<String, Object> patItemCount(ServiceSubtaskVO serviceSubtaskVO) {
-        serviceSubtaskVO.setPageSize(99999999);
-        serviceSubtaskVO.setPageNum(1);
-        List<ServiceSubtask> selectServiceSubtaskList = this.selectServiceSubtaskList(serviceSubtaskVO);
-        Map<String, Object> map = new HashMap<>();
-        Integer wzx = 0;
-        Integer ysf = 0;
-        Integer yc = 0;
-        Integer fssb = 0;
-        Integer yfs = 0;
-        Integer blq = 0;
-        Integer dsf = 0;
-        for (ServiceSubtask serviceSubtask : selectServiceSubtaskList) {
-            if (serviceSubtask.getSendstate() == 4L) wzx = wzx + 1;
-            else if (serviceSubtask.getSendstate() != 4L && serviceSubtask.getSendstate() != 2L) ysf = ysf + 1;
-            if (serviceSubtask.getSendstate() == 5L) fssb = fssb + 1;
-            if (serviceSubtask.getSendstate() >= 3L || serviceSubtask.getSendstate() == 1L) yfs = yfs + 1;
-            if (serviceSubtask.getSendstate() == 2L) dsf = dsf + 1;
-            if (serviceSubtask.getSendstate() == 1L) blq = blq + 1;
-            if (StringUtils.isNotEmpty(serviceSubtask.getExcep()) && !serviceSubtask.getExcep().equals("0"))
-                yc = yc + 1;
+        // 鐩存帴璋冪敤鏁版嵁搴撶粺璁℃柟娉曪紝鍦ㄦ暟鎹簱灞傚畬鎴愯仛鍚堣绠�
+        Map<String, Object> result = serviceSubtaskMapper.countByCondition(serviceSubtaskVO);
+        // 澶勭悊绌哄紓甯�
+        if(MapUtils.isEmpty(result)){
+            result = new HashMap<>();
         }
-        map.put("wzx", wzx);
-        map.put("ysf", ysf);
-        map.put("yc", yc);
-        map.put("fssb", fssb);
-        map.put("yfs", yfs);
-        map.put("blq", blq);
-        map.put("dsf", dsf);
+        // 纭繚鎵�鏈� key 閮芥湁鍊硷紝閬垮厤绌烘寚閽堝紓甯�
+        // MyBatis 鐨� SUM 鍦ㄦ病鏈夊尮閰嶈鏃朵細杩斿洖 null
+        result.putIfAbsent("wzx", 0);
+        result.putIfAbsent("ysf", 0);
+        result.putIfAbsent("yc", 0);
+        result.putIfAbsent("fssb", 0);
+        result.putIfAbsent("yfs", 0);
+        result.putIfAbsent("blq", 0);
+        result.putIfAbsent("dsf", 0);
 
-        return map;
+        return result;
     }
 
     /**
@@ -2164,7 +2198,7 @@
     }
 
     /**
-     * 鑾峰彇闅忚缁熻姣斾緥
+     * 鑾峰彇闅忚缁熻姣斾緥锛堜紭鍖栫増鏈級
      *
      * @param serviceSubtaskCountReq
      * @return
@@ -2174,22 +2208,28 @@
     public List<ServiceSubtaskStatistic> getSfStatistics(ServiceSubtaskCountReq serviceSubtaskCountReq) {
         log.info("getSfStatistics鐨勫叆鍙備负锛歿}", serviceSubtaskCountReq);
         List<ServiceSubtaskStatistic> serviceSubtaskStatistics = new ArrayList<>();
-//        List<ServiceSubtask> rawData = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq);
+
+        // 浼樺寲锛氬彧鏌ヨ涓�娆℃暟鎹簱锛岄伩鍏嶉噸澶嶆煡璇�
+        List<ServiceSubtask> rawData = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq);
+
+        if (CollectionUtils.isEmpty(rawData)) {
+            return serviceSubtaskStatistics;
+        }
 
         // 鏍规嵁鏉′欢杩涜鍒嗙粍
         Map<String, List<ServiceSubtask>> collect = new HashMap<>();
 
         if (serviceSubtaskCountReq.getLeavehospitaldistrictcodes() != null && serviceSubtaskCountReq.getLeavehospitaldistrictcodes().size() > 0) {
             if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) {
-                collect = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq).stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrname()).orElse("Unknown")));
+                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrname()).orElse("Unknown")));
             } else {
-                collect = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq).stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getLeavehospitaldistrictname()).orElse("Unknown")));
+                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getLeavehospitaldistrictname()).orElse("Unknown")));
             }
         } else if (serviceSubtaskCountReq.getDeptcodes() != null && serviceSubtaskCountReq.getDeptcodes().size() > 0) {
             if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) {
-                collect = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq).stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrname()).orElse("Unknown")));
+                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrname()).orElse("Unknown")));
             } else {
-                collect = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq).stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDeptname()).orElse("Unknown")));
+                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDeptname()).orElse("Unknown")));
             }
         }
 
@@ -2244,7 +2284,7 @@
     }
 
     /**
-     * 鑾峰彇闅忚缁熻姣斾緥
+     * 鑾峰彇闅忚缁熻姣斾緥锛堜紭鍖栫増鏈級
      *
      * @param serviceSubtaskCountReq
      * @return
@@ -2255,22 +2295,28 @@
         log.error("getSfStatistics鐨勫叆鍙備负锛歿}", serviceSubtaskCountReq);
         List<ServiceSubtaskStatistic> serviceSubtaskStatistics = new ArrayList<>();
 
+        // 浼樺寲锛氬彧鏌ヨ涓�娆℃暟鎹簱锛岄伩鍏嶉噸澶嶆煡璇�
+        List<ServiceSubtask> rawData = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq);
+
+        if (CollectionUtils.isEmpty(rawData)) {
+            return serviceSubtaskStatistics;
+        }
+
         // 鏍规嵁鏉′欢杩涜鍒嗙粍
         Map<String, List<ServiceSubtask>> collect = new HashMap<>();
         String orgid = null;
 
         if (serviceSubtaskCountReq.getLeavehospitaldistrictcodes() != null && serviceSubtaskCountReq.getLeavehospitaldistrictcodes().size() > 0) {
             if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) {
-                collect = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq).stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrname()).orElse("Unknown")));
-
+                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrname()).orElse("Unknown")));
             } else {
-                collect = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq).stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getLeavehospitaldistrictname()).orElse("Unknown")));
+                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getLeavehospitaldistrictname()).orElse("Unknown")));
             }
         } else if (serviceSubtaskCountReq.getDeptcodes() != null && serviceSubtaskCountReq.getDeptcodes().size() > 0) {
             if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) {
-                collect = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq).stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrname()).orElse("Unknown")));
+                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrname()).orElse("Unknown")));
             } else {
-                collect = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq).stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDeptname()).orElse("Unknown")));
+                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDeptname()).orElse("Unknown")));
             }
         }
         List<ServiceSubtaskCount> joySubCount = serviceSubtaskMapper.getSfStatisticsJoy(serviceSubtaskCountReq);

--
Gitblit v1.9.3