From 9b96619ab91dce35b606faa3f4e0468ec702fd69 Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期四, 22 一月 2026 15:25:11 +0800
Subject: [PATCH] 【丽水】getSfStatisticsScript 优化
---
smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java | 129 ++++++++++++++++++++++++------------------
1 files changed, 74 insertions(+), 55 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 0041822..c1605f2 100644
--- a/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
@@ -2226,8 +2226,9 @@
* @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) {
+ //todo
log.info("getSfStatistics鐨勫叆鍙備负锛歿}", serviceSubtaskCountReq);
List<ServiceSubtaskStatistic> serviceSubtaskStatistics = new ArrayList<>();
List<ServiceSubtask> rawData = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq);
@@ -2236,7 +2237,6 @@
Map<String, List<ServiceSubtask>> collect = new HashMap<>();
String groupKeyType = "";
-
if (serviceSubtaskCountReq.getLeavehospitaldistrictcodes() != null && !serviceSubtaskCountReq.getLeavehospitaldistrictcodes().isEmpty()) {
if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) {
groupKeyType = "drCode";
@@ -2254,8 +2254,51 @@
collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDeptcode()).orElse("Unknown")));
}
}
+ serviceSubtaskCountReq.setGroupKeyType(groupKeyType);
+ //鑾峰彇鍙婃椂鐜囩粺璁″悎闆�
+ 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);
+ 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);
+ }
+
+ if (ObjectUtils.isNotEmpty(statistic)) {
+ serviceSubtaskStatistics.add(statistic);
+ }
+ }
+ 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 groupKeyType = serviceSubtaskCountReq.getGroupKeyType();
+ if(StringUtils.isEmpty(groupKeyType)){
+ 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());
@@ -2286,27 +2329,8 @@
if(!collect.isEmpty()){
jsRates = serviceSubtaskMapper.selectTimelyRateBatch(ssRate);
}
-
- for (String collectKey : collect.keySet()) {
- List<ServiceSubtask> serviceSubtaskList = collect.get(collectKey);
- if (CollectionUtils.isEmpty(serviceSubtaskList)) {
- continue;
- }
- ServiceSubtaskStatistic statistic = getStatistic(serviceSubtaskList);
- 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);
- if (ObjectUtils.isNotEmpty(statistic)) {
- serviceSubtaskStatistics.add(statistic);
- }
- }
- return serviceSubtaskStatistics;
+ return jsRates;
}
-
@Override
public List<ServiceSubtaskStatistic> getSfStatisticsExport(ServiceSubtaskCountReq serviceSubtaskCountReq) {
List<ServiceSubtaskStatistic> sfStatistics = getSfStatistics(serviceSubtaskCountReq);
@@ -3105,59 +3129,54 @@
@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<>();
+ List<ServiceSubtask> rawData = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq);
// 鏍规嵁鏉′欢杩涜鍒嗙粍
Map<String, List<ServiceSubtask>> collect = new HashMap<>();
- String orgid = null;
-
- 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 = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq).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 = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq).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 = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq).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 = serviceSubtaskMapper.getSfStatistics(serviceSubtaskCountReq).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")));
}
}
- for (List<ServiceSubtask> serviceSubtaskList : collect.values()) {
+ serviceSubtaskCountReq.setGroupKeyType(groupKeyType);
+ //鑾峰彇鍙婃椂鐜囩粺璁″悎闆�
+ 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