From 3a1f1ee4e166ad7ff89d4e88d3433243a74e27d8 Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期五, 23 一月 2026 11:17:21 +0800
Subject: [PATCH] 【丽水】数据同步增加院区id

---
 smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java |  182 ++++++++++++++++++++++++++++-----------------
 1 files changed, 114 insertions(+), 68 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 f98f258..068d985 100644
--- a/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
@@ -2229,55 +2229,59 @@
     @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<>();
-        List<ServiceSubtask> rawData = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq);
-
-        // 鏍规嵁鏉′欢杩涜鍒嗙粍
-        Map<String, List<ServiceSubtask>> collect = new HashMap<>();
-
-        if (serviceSubtaskCountReq.getLeavehospitaldistrictcodes() != null && serviceSubtaskCountReq.getLeavehospitaldistrictcodes().size() > 0) {
+        String groupKey = "drcode";
+        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")));
+                groupKey = "drcode";
             } else {
-                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getLeavehospitaldistrictname()).orElse("Unknown")));
+                groupKey = "leavehospitaldistrictcode";
             }
-        } 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")));
+                groupKey = "drcode";
             } else {
-                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDeptname()).orElse("Unknown")));
+                groupKey = "deptcode";
             }
         }
-
-
-        for (List<ServiceSubtask> serviceSubtaskList : collect.values()) {
+        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()) {
+            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());
+            if(ObjectUtils.isNotEmpty(jsRates)){
+                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());
                 }
+                Double jsRateDouble = (jsRate.setScale(4, RoundingMode.HALF_UP)).doubleValue();
+                statistic.setRate(jsRateDouble);
             }
-
-            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);
 
             if (ObjectUtils.isNotEmpty(statistic)) {
                 serviceSubtaskStatistics.add(statistic);
@@ -2286,6 +2290,40 @@
         return serviceSubtaskStatistics;
     }
 
+    /**
+     * 闅忚缁熻-鍙婃椂鐜囩粺璁�
+     * @param serviceSubtaskCountReq
+     * @param collect
+     * @return
+     */
+    public  Map<String, Map<String, Object>> getSsRateForSfStatistics(ServiceSubtaskCountReq serviceSubtaskCountReq, Map<String, List<ServiceSubtask>> collect){
+        if(ObjectUtils.isEmpty(serviceSubtaskCountReq)){
+            return null;
+        }
+        String groupKey = serviceSubtaskCountReq.getGroupKey();
+        if(StringUtils.isEmpty(groupKey)){
+            return null;
+        }
+        List<String> groupKeyList = new ArrayList<>(collect.keySet());
+        if(ObjectUtils.isEmpty(groupKeyList)){
+            return null;
+        }
+        //鍙婃椂鐜囩粺璁�
+        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());
+        }
+        ssRate.setGroupKey(groupKey);
+        ssRate.setGroupKeyList(groupKeyList);
+        Map<String, Map<String, Object>> jsRates = new HashMap<>();
+        if(!collect.isEmpty()){
+            jsRates = serviceSubtaskMapper.selectTimelyRateBatch(ssRate);
+        }
+        return jsRates;
+    }
     @Override
     public List<ServiceSubtaskStatistic> getSfStatisticsExport(ServiceSubtaskCountReq serviceSubtaskCountReq) {
         List<ServiceSubtaskStatistic> sfStatistics = getSfStatistics(serviceSubtaskCountReq);
@@ -3084,59 +3122,67 @@
     @Override
     @Cacheable(value = "getSfStatisticsScript", key = "T(org.springframework.util.DigestUtils).md5DigestAsHex(#serviceSubtaskCountReq.toString().getBytes())", unless = "#result == null or #result.isEmpty()")
     public List<ServiceSubtaskStatistic> getSfStatisticsScript(ServiceSubtaskCountReq serviceSubtaskCountReq) {
-        log.error("getSfStatisticsScript鐨勫叆鍙備负锛歿}", serviceSubtaskCountReq);
+        log.info("getSfStatisticsScript鐨勫叆鍙備负锛歿}", serviceSubtaskCountReq);
         List<ServiceSubtaskStatistic> serviceSubtaskStatistics = new ArrayList<>();
 
         // 鏍规嵁鏉′欢杩涜鍒嗙粍
         Map<String, List<ServiceSubtask>> collect = new HashMap<>();
-        String orgid = null;
-
-        if (serviceSubtaskCountReq.getLeavehospitaldistrictcodes() != null && serviceSubtaskCountReq.getLeavehospitaldistrictcodes().size() > 0) {
+        String groupKey = "drcode";
+        if (serviceSubtaskCountReq.getLeavehospitaldistrictcodes() != null && !serviceSubtaskCountReq.getLeavehospitaldistrictcodes().isEmpty()) {
             if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) {
-                collect = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq).stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrname()).orElse("Unknown")));
-
+                groupKey = "drcode";
             } else {
-                collect = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq).stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getLeavehospitaldistrictname()).orElse("Unknown")));
+                groupKey = "leavehospitaldistrictcode";
             }
-        } 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 = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq).stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDrname()).orElse("Unknown")));
+                groupKey = "drcode";
             } else {
-                collect = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq).stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDeptname()).orElse("Unknown")));
+                groupKey = "deptcode";
             }
         }
-        for (List<ServiceSubtask> serviceSubtaskList : collect.values()) {
+        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()) {
+            List<ServiceSubtask> serviceSubtaskList = collect.get(collectKey);
             if (CollectionUtils.isEmpty(serviceSubtaskList)) {
                 continue;
             }
             ServiceSubtaskStatistic statistic = getStatisticCategory(serviceSubtaskList, serviceSubtaskCountReq);
-            //鍙婃椂鐜�
-            ServiceSubtask ss = new ServiceSubtask();
-            orgid = serviceSubtaskList.get(0).getOrgid();
-            ss.setOrgid(orgid);
-
-            // 濡傛灉鏈夊尰鐢熺紪鐮侊紝璁剧疆鍖荤敓缂栫爜鐢ㄤ簬鍙婃椂鐜囨煡璇�
-            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());
+            if(ObjectUtils.isNotEmpty(jsRates)){
+                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());
                 }
+                Double jsRateDouble = (jsRate.setScale(4, RoundingMode.HALF_UP)).doubleValue();
+                statistic.setRate(jsRateDouble);
             }
-
-            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);
             if (ObjectUtils.isNotEmpty(statistic)) {
                 serviceSubtaskStatistics.add(statistic);
             }
         }
+
+        //缁熻闅忚棰樼洰鍒嗙被
         if (CollectionUtils.isNotEmpty(serviceSubtaskStatistics)) {
             for (ServiceSubtaskStatistic serviceSubtaskStatistic : serviceSubtaskStatistics) {
                 //鑾峰彇婊℃剰搴﹂鐩�婚噺

--
Gitblit v1.9.3