From 4a8af0dce1f6e2d82b9e3da1dde9aa4a6059b6ad Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期二, 22 九月 2026 09:39:25 +0800
Subject: [PATCH] 【市一】市一打电话调整
---
smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java | 671 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 609 insertions(+), 62 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 90236af..7e5e14a 100644
--- a/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
@@ -12,7 +12,6 @@
import com.ruoyi.common.dx.MessageSend;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.*;
-import com.ruoyi.common.core.service.IConfigService;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.system.domain.SysConfig;
@@ -22,8 +21,9 @@
import com.smartor.common.MtSubmitSmUtil;
import com.smartor.common.ScheduleSubtaskBuilder;
import com.smartor.config.PhoneUtils;
+import com.smartor.domain.DTO.MydTrendReqDTO;
+import com.smartor.domain.DTO.MzMydScoreRankDTO;
import com.smartor.domain.DTO.QuestionCountKsOrBqDTO;
-import com.smartor.domain.DTO.QuestionResultDTO;
import com.smartor.domain.DTO.ServiceSubtaskDetailDTO;
import com.smartor.domain.*;
import com.smartor.domain.VO.*;
@@ -34,9 +34,7 @@
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.ObjectUtils;
-import org.checkerframework.checker.nullness.qual.NonNull;
import org.junit.Test;
-import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.Cacheable;
@@ -44,10 +42,8 @@
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
-import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
-import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
@@ -207,12 +203,13 @@
@Value("${spring.profiles.active}")
private String active;
- @Autowired
- private PatMedOperationMapper patMedOperationMapper;
- @Autowired
- private PatMedOperationItemMapper patMedOperationItemMapper;
+
@Autowired
private ServiceOutPathMapper serviceOutPathMapper;
+
+ private static final String KEY_SEP = "\u0001";
+ @Autowired
+ private PatMedOperationItemMapper patMedOperationItemMapper;
/**
* 鏌ヨ鍗曚竴浠诲姟锛堥殢璁匡級
@@ -790,6 +787,7 @@
serviceSubtask.setUpdateTime(DateUtils.getNowDate());
if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate() == 6)
serviceSubtask.setFinishtime(new Date());
+
return serviceSubtaskMapper.updateServiceSubtask(serviceSubtask);
}
@@ -1058,8 +1056,8 @@
//灏嗕换鍔′俊鎭斁鍒版湇鍔¤〃涓�
ServiceSubtask serviceSubtask = DtoConversionUtils.sourceToTarget(serviceTaskVO, ServiceSubtask.class);
serviceSubtask.setTaskid(serviceTask.getTaskid().longValue());
- serviceSubtask.setTemplatename(tempName);
- serviceSubtask.setTemplateid(tempid);
+ serviceSubtask.setTemplatename(ObjectUtils.isNotEmpty(tempid) ? tempName : serviceTask.getTemplatename());
+ serviceSubtask.setTemplateid(ObjectUtils.isNotEmpty(tempid) ? tempid : serviceTask.getTemplateid());
serviceSubtask.setLibtemplateid(ObjectUtils.isEmpty(serviceTask.getLibtemplateid()) ? null : Long.valueOf(serviceTask.getLibtemplateid()));
serviceSubtask.setLibtemplatename(serviceTask.getLibtemplatename());
//鏂板
@@ -1170,7 +1168,7 @@
redisCache.removeElementFromList("cache-3", serviceSubtask.getId().toString());
redisCache.removeElementFromList("cache-4", serviceSubtask.getId().toString());
//灏嗗嚭鍏ラ櫌琛ㄧ殑鏁版嵁锛岃繕鍘熸垚杩樻湭澶勭悊鐨勭姸鎬�
- if (serviceSubtask.getServiceType().equals("2")) {
+ if (serviceSubtask.getServiceType().equals("2") || serviceSubtask.getServiceType().equals("13")) {
ServiceTask st = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid());
//濡傛灉浠诲姟鏄暱鏈熶换鍔★紝闇�瑕佸皢璇ユ偅鑰呯殑鍑哄叆闄㈡暟鎹繕鍘熸垚杩樻湭澶勭悊鐨勭姸鎬�
if (st != null && st.getLongTask() == 1) {
@@ -1191,6 +1189,16 @@
patMedOuthosp.setServerState("0");
patMedOuthospService.updatePatMedOuthosp(patMedOuthosp);
}
+ }
+ } else if (serviceSubtask.getServiceType().equals("19")) {
+ ServiceTask st = serviceTaskService.selectServiceTaskByTaskid(serviceSubtask.getTaskid());
+ //濡傛灉浠诲姟鏄暱鏈熶换鍔★紝闇�瑕佸皢璇ユ偅鑰呯殑鍑洪櫌璇︽儏鐘舵�佽繕鍘熸垚杩樻湭澶勭悊鐨勭姸鎬�
+ if (st != null && st.getLongTask() == 1
+ && ObjectUtils.isNotEmpty(serviceSubtask.getOperationItemId())) {
+ PatMedOperationItem patMedOperationItem = new PatMedOperationItem();
+ patMedOperationItem.setOpercheckFlag("0");
+ patMedOperationItem.setId(serviceSubtask.getOperationItemId());
+ patMedOperationItemMapper.updatePatMedOperationItem(patMedOperationItem);
}
}
}
@@ -1424,6 +1432,8 @@
ServiceSubtask serviceSubtask = DtoConversionUtils.sourceToTarget(serviceTaskVO, ServiceSubtask.class);
serviceSubtask.setLibtemplateid(ObjectUtils.isEmpty(serviceTaskVO.getLibtemplateid()) ? null : Long.valueOf(serviceTaskVO.getLibtemplateid()));
serviceSubtask.setLibtemplatename(serviceTaskVO.getLibtemplatename());
+ serviceSubtask.setTemplateid(serviceTask.getTemplateid());
+ serviceSubtask.setTemplatename(serviceTask.getTemplatename());
serviceSubtask.setSendname(patTaskRelevance.getName());
serviceSubtask.setAge(patTaskRelevance.getAge());
serviceSubtask.setSfzh(patTaskRelevance.getSfzh());
@@ -3345,6 +3355,24 @@
serviceSubtaskStatistic.setWeChat(serviceSubtaskStatistic.getWeChat() + 1L);
}
}
+
+ //棣栨闅忚浜哄伐鎴愬姛
+ if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("1")) {
+ serviceSubtaskStatistic.setManualSuccess(serviceSubtaskStatistic.getManualSuccess() + 1L);
+ }
+ //棣栨闅忚璇煶鎴愬姛
+ if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("3")) {
+ serviceSubtaskStatistic.setVoiceSuccess(serviceSubtaskStatistic.getVoiceSuccess() + 1L);
+ }
+ //棣栨闅忚鐭俊鎴愬姛
+ if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("4")) {
+ serviceSubtaskStatistic.setSmsSuccess(serviceSubtaskStatistic.getSmsSuccess() + 1L);
+ }
+ //棣栨闅忚寰俊鎴愬姛
+ if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("5")) {
+ serviceSubtaskStatistic.setWeChatSuccess(serviceSubtaskStatistic.getWeChatSuccess() + 1L);
+ }
+
if (serviceSubtaskStatistic.getNeedFollowUp() > 0) {
double rate = (double) (serviceSubtaskStatistic.getFollowUpSuccess() + serviceSubtaskStatistic.getFollowUpFail()) / serviceSubtaskStatistic.getNeedFollowUp();
serviceSubtaskStatistic.setFollowUpRate(percentFormat.format(rate));
@@ -3440,6 +3468,24 @@
serviceSubtaskStatistic.setWeChatAgain(serviceSubtaskStatistic.getWeChatAgain() + 1L);
}
}
+
+ //鍐嶆闅忚浜哄伐鎴愬姛
+ if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("1")) {
+ serviceSubtaskStatistic.setManualAgainSuccess(serviceSubtaskStatistic.getManualAgainSuccess() + 1L);
+ }
+ //鍐嶆闅忚璇煶鎴愬姛
+ if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("3")) {
+ serviceSubtaskStatistic.setVoiceAgainSuccess(serviceSubtaskStatistic.getVoiceAgainSuccess() + 1L);
+ }
+ //鍐嶆闅忚鐭俊鎴愬姛
+ if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("4")) {
+ serviceSubtaskStatistic.setSmsAgainSuccess(serviceSubtaskStatistic.getSmsAgainSuccess() + 1L);
+ }
+ //鍐嶆闅忚寰俊鎴愬姛
+ if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("5")) {
+ serviceSubtaskStatistic.setWeChatAgainSuccess(serviceSubtaskStatistic.getWeChatAgainSuccess() + 1L);
+ }
+
if (serviceSubtaskStatistic.getNeedFollowUp() > 0) {
double rate = (double) (serviceSubtaskStatistic.getFollowUpSuccessAgain() + serviceSubtaskStatistic.getFollowUpFailAgain()) / serviceSubtaskStatistic.getNeedFollowUpAgain();
serviceSubtaskStatistic.setFollowUpRateAgain(percentFormat.format(rate));
@@ -3594,6 +3640,24 @@
serviceSubtaskStatistic.setWeChat(serviceSubtaskStatistic.getWeChat() + 1L);
}
}
+
+ //棣栨闅忚浜哄伐鎴愬姛
+ if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("1")) {
+ serviceSubtaskStatistic.setManualSuccess(serviceSubtaskStatistic.getManualSuccess() + 1L);
+ }
+ //棣栨闅忚璇煶鎴愬姛
+ if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("3")) {
+ serviceSubtaskStatistic.setVoiceSuccess(serviceSubtaskStatistic.getVoiceSuccess() + 1L);
+ }
+ //棣栨闅忚鐭俊鎴愬姛
+ if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("4")) {
+ serviceSubtaskStatistic.setSmsSuccess(serviceSubtaskStatistic.getSmsSuccess() + 1L);
+ }
+ //棣栨闅忚寰俊鎴愬姛
+ if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("5")) {
+ serviceSubtaskStatistic.setWeChatSuccess(serviceSubtaskStatistic.getWeChatSuccess() + 1L);
+ }
+
if (serviceSubtaskStatistic.getNeedFollowUp() > 0) {
double rate = (double) (serviceSubtaskStatistic.getFollowUpSuccess() + serviceSubtaskStatistic.getFollowUpFail()) / serviceSubtaskStatistic.getNeedFollowUp();
serviceSubtaskStatistic.setFollowUpRate(percentFormat.format(rate));
@@ -3745,6 +3809,24 @@
serviceSubtaskStatistic.setWeChatAgain(serviceSubtaskStatistic.getWeChatAgain() + 1L);
}
}
+
+ //鍐嶆闅忚浜哄伐鎴愬姛
+ if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("1")) {
+ serviceSubtaskStatistic.setManualAgainSuccess(serviceSubtaskStatistic.getManualAgainSuccess() + 1L);
+ }
+ //鍐嶆闅忚璇煶鎴愬姛
+ if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("3")) {
+ serviceSubtaskStatistic.setVoiceAgainSuccess(serviceSubtaskStatistic.getVoiceAgainSuccess() + 1L);
+ }
+ //鍐嶆闅忚鐭俊鎴愬姛
+ if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("4")) {
+ serviceSubtaskStatistic.setSmsAgainSuccess(serviceSubtaskStatistic.getSmsAgainSuccess() + 1L);
+ }
+ //鍐嶆闅忚寰俊鎴愬姛
+ if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate().equals(6L) && ObjectUtils.isNotEmpty(serviceSubtask.getCurrentPreachform()) && serviceSubtask.getCurrentPreachform().equals("5")) {
+ serviceSubtaskStatistic.setWeChatAgainSuccess(serviceSubtaskStatistic.getWeChatAgainSuccess() + 1L);
+ }
+
if (serviceSubtaskStatistic.getNeedFollowUp() > 0) {
double rate = (double) (serviceSubtaskStatistic.getFollowUpSuccessAgain() + serviceSubtaskStatistic.getFollowUpFailAgain()) / serviceSubtaskStatistic.getNeedFollowUpAgain();
serviceSubtaskStatistic.setFollowUpRateAgain(percentFormat.format(rate));
@@ -4175,6 +4257,10 @@
* voiceInfo - visitCount = 1 && currentPreachForm = "3"
* smsInfo - visitCount = 1 && currentPreachForm = "4"
* wechatInfo - visitCount = 1 && currentPreachForm = "5"
+ * manualSuccessInfo - visitCount = 1 && currentPreachForm = "1" && sendstate = 6
+ * voiceSuccessInfo - visitCount = 1 && currentPreachForm = "3" && sendstate = 6
+ * smsSuccessInfo - visitCount = 1 && currentPreachForm = "4" && sendstate = 6
+ * wechatSuccessInfo - visitCount = 1 && currentPreachForm = "5" && sendstate = 6
* abnormalInfo - visitCount = 1 && excep = "1"
* needFollowUpAgainInfo - visitCount > 1 && sendstate != 4
* pendingFollowUpAgainInfo - visitCount > 1 && sendstate = 2
@@ -4184,6 +4270,10 @@
* voiceAgainInfo - visitCount > 1 && currentPreachForm = "3"
* smsAgainInfo - visitCount > 1 && currentPreachForm = "4"
* wechatAgainInfo - visitCount > 1 && currentPreachForm = "5"
+ * manualAgainSuccessInfo - visitCount > 1 && currentPreachForm = "1" && sendstate = 6
+ * voiceAgainSuccessInfo - visitCount > 1 && currentPreachForm = "3" && sendstate = 6
+ * smsAgainSuccessInfo - visitCount > 1 && currentPreachForm = "4" && sendstate = 6
+ * wechatAgainSuccessInfo - visitCount > 1&& currentPreachForm = "5" && sendstate = 6
* abnormalAgainInfo- visitCount = 1 && excep = "1"
* taskSituation1Info - taskSituation = 1
* taskSituation2Info - taskSituation = 2
@@ -4267,6 +4357,26 @@
serviceSubtaskCountReq.setVisitCount(1);
serviceSubtaskCountReq.setCurrentPreachform("5");
break;
+ case "manualSuccessInfo":
+ serviceSubtaskCountReq.setVisitCount(1);
+ serviceSubtaskCountReq.setSendstates(new ArrayList<>(Collections.singletonList(6L)));
+ serviceSubtaskCountReq.setCurrentPreachform("1");
+ break;
+ case "voiceSuccessInfo":
+ serviceSubtaskCountReq.setVisitCount(1);
+ serviceSubtaskCountReq.setSendstates(new ArrayList<>(Collections.singletonList(6L)));
+ serviceSubtaskCountReq.setCurrentPreachform("3");
+ break;
+ case "smsSuccessInfo":
+ serviceSubtaskCountReq.setVisitCount(1);
+ serviceSubtaskCountReq.setSendstates(new ArrayList<>(Collections.singletonList(6L)));
+ serviceSubtaskCountReq.setCurrentPreachform("4");
+ break;
+ case "wechatSuccessInfo":
+ serviceSubtaskCountReq.setVisitCount(1);
+ serviceSubtaskCountReq.setSendstates(new ArrayList<>(Collections.singletonList(6L)));
+ serviceSubtaskCountReq.setCurrentPreachform("5");
+ break;
case "abnormalInfo":
serviceSubtaskCountReq.setVisitCount(1);
serviceSubtaskCountReq.setExcep("1");
@@ -4301,6 +4411,26 @@
break;
case "wechatAgainInfo":
serviceSubtaskCountReq.setVisitCount(2);
+ serviceSubtaskCountReq.setCurrentPreachform("5");
+ break;
+ case "manualAgainSuccessInfo":
+ serviceSubtaskCountReq.setVisitCount(1);
+ serviceSubtaskCountReq.setSendstates(new ArrayList<>(Collections.singletonList(6L)));
+ serviceSubtaskCountReq.setCurrentPreachform("1");
+ break;
+ case "voiceAgainSuccessInfo":
+ serviceSubtaskCountReq.setVisitCount(2);
+ serviceSubtaskCountReq.setSendstates(new ArrayList<>(Collections.singletonList(6L)));
+ serviceSubtaskCountReq.setCurrentPreachform("3");
+ break;
+ case "smsAgainSuccessInfo":
+ serviceSubtaskCountReq.setVisitCount(2);
+ serviceSubtaskCountReq.setSendstates(new ArrayList<>(Collections.singletonList(6L)));
+ serviceSubtaskCountReq.setCurrentPreachform("4");
+ break;
+ case "wechatAgainSuccessInfo":
+ serviceSubtaskCountReq.setVisitCount(2);
+ serviceSubtaskCountReq.setSendstates(new ArrayList<>(Collections.singletonList(6L)));
serviceSubtaskCountReq.setCurrentPreachform("5");
break;
case "abnormalAgainInfo":
@@ -5011,13 +5141,13 @@
}
@Override
- public List<ServiceSubtaskDetailRatioExport> statQuestionOption(List<Long> taskIds, Date startOutHospTime, Date endOutHospTime, String scriptContent, Double scoreStart, Double scoreEnd, String valueType) {
+ public List<ServiceSubtaskDetailRatioExport> statQuestionOption(List<Long> taskIds, Date startFinishTime, Date endFinishTime, Date startOutHospTime, Date endOutHospTime, String scriptContent, Double scoreStart, Double scoreEnd, String valueType) {
//鍏堟竻鐞嗕竴涓嬮噸澶嶆暟鎹�
List<Long> repeatIds = serviceSubtaskDetailMapper.selectRepeatDetailIds();
if (!CollectionUtils.isEmpty(repeatIds)) {
serviceSubtaskDetailMapper.deleteRepeatDetailByIds(repeatIds);
}
- List<ServiceSubtaskDetailRatioExport> serviceSubtaskDetailRatioExports = serviceSubtaskMapper.statQuestionOption(taskIds, startOutHospTime, endOutHospTime, scoreStart, scoreEnd, scriptContent, valueType);
+ List<ServiceSubtaskDetailRatioExport> serviceSubtaskDetailRatioExports = serviceSubtaskMapper.statQuestionOption(taskIds, startOutHospTime, endOutHospTime, startFinishTime, endFinishTime, scoreStart, scoreEnd, scriptContent, valueType);
// 澶勭悊 targetvalue锛氭寜 & 鍒嗗壊鎴愬鏉¤褰�
List<ServiceSubtaskDetailRatioExport> result = new ArrayList<>();
@@ -5062,58 +5192,135 @@
* 鏍规嵁绉戝鎴栫梾鍖虹粺璁¢棶鍗烽�夐」(绉戝銆侀鐩煡璇㈢殑绉戝璇勫垎琛�)
*/
@Override
- public List<QuestionCountKsOrBqDTO> statQuestionOptionByKsOrBq(QuestionCountKsOrBqVO questionCountKsOrBqVO) {
- List<QuestionCountKsOrBqDTO> questionCountKsOrBqDTOS = serviceSubtaskMapper.statQuestionOptionByKsOrBq(questionCountKsOrBqVO);
+ public Map<String, Map<String, List<QuestionCountKsOrBqDTO>>> statQuestionOptionByKsOrBq(QuestionCountKsOrBqVO vo) {
- // 澶勭悊 targetvalue锛氭寜 & 鍒嗗壊鎴愬鏉¤褰�
- List<QuestionCountKsOrBqDTO> result = new ArrayList<>();
- for (QuestionCountKsOrBqDTO questionCountKsOrBqDTO : questionCountKsOrBqDTOS) {
- if (StringUtils.isNotEmpty(questionCountKsOrBqDTO.getTargetvalue()) && questionCountKsOrBqDTO.getTargetvalue().contains("&")) {
- String[] values = questionCountKsOrBqDTO.getTargetvalue().split("&");
- // 濡傛灉鏈夊鏉$洰鏍囧�硷紝鎷嗗垎鎴愬琛�
- for (String value : values) {
- //鍏堝幓 result 涓煡涓�涓嬶紝鏈夋病鏈夎繖涓� questiontext 鍜屽搴旂殑 targetvalue
- QuestionCountKsOrBqDTO existingExport = result.stream().filter(e -> e.getQeustionText().equals(questionCountKsOrBqDTO.getQeustionText()) && value.trim().equals(e.getTargetvalue())).findFirst().orElse(null);
- if (existingExport != null && existingExport.getAnswerCount().equals("0") && existingExport.getSingleScore().equals("0")) {
- //濡傛灉瀛樺湪锛屽垯灏� result 閲岀殑杩欎釜闂鎵�瀵瑰簲鐨� Targetvalue=value 杩欐潯鏁版嵁鏇存柊鎴愬綋鍓嶈繖鏉℃暟鎹�
- if (value.equals(questionCountKsOrBqDTO.getAsrtext())) {
- existingExport.setAsrtext(questionCountKsOrBqDTO.getAsrtext());
- existingExport.setAnswerCount(questionCountKsOrBqDTO.getAnswerCount());
- existingExport.setSingleScore(questionCountKsOrBqDTO.getSingleScore());
- existingExport.setAvgScore(questionCountKsOrBqDTO.getAvgScore());
- }
- } else if (existingExport != null && !existingExport.getAnswerCount().equals("0")) {
- continue;
- } else {
- QuestionCountKsOrBqDTO qcDto = DtoConversionUtils.sourceToTarget(questionCountKsOrBqDTO, QuestionCountKsOrBqDTO.class);
- qcDto.setTargetvalue(value.trim()); // targetvalue 鏄剧ず鍗曚釜閫夐」
- if (!value.equals(qcDto.getAsrtext())) {
- existingExport.setAsrtext(null);
- existingExport.setAnswerCount("0");
- existingExport.setSingleScore("0");
- existingExport.setAvgScore("0");
- }
- result.add(qcDto);
- }
- }
- } else {
- // targetvalue 涓嶅寘鍚� &锛岀洿鎺ユ坊鍔犲埌缁撴灉
- result.add(questionCountKsOrBqDTO);
+ // 1. 鏌ユ槑缁�
+ List<QuestionCountKsOrBqDTO> sourceList = serviceSubtaskMapper.statQuestionOptionByKsOrBq(vo);
+ if (CollectionUtils.isEmpty(sourceList)) {
+ return Collections.emptyMap();
+ }
+
+ // 2. 鍒ゆ柇鎸夌瀹よ繕鏄寜鐥呭尯
+ boolean byDept = vo.getLeaveldeptcodes() != null;
+ boolean byDistrict = !byDept && vo.getLeavehospitaldistrictcodes() != null;
+ if (!byDept && !byDistrict) {
+ return Collections.emptyMap();
+ }
+
+ // 3. key = 绉戝/鐥呭尯 + 棰樼洰 + 閫夐」
+ Map<String, QuestionCountKsOrBqDTO> map = new LinkedHashMap<>();
+
+ for (QuestionCountKsOrBqDTO dto : sourceList) {
+
+ if (StringUtils.isEmpty(dto.getTargetvalue())) {
+ continue;
}
+
+ // 鍒嗙粍鍚嶏細绉戝 鎴� 鐥呭尯
+ String groupName = byDept ? dto.getDeptname() : dto.getLeavehospitaldistrictname();
+ if (StringUtils.isEmpty(groupName)) {
+ continue;
+ }
+
+ String asrtext = trimAll(dto.getAsrtext()); // 鐢ㄦ埛瀹為檯閫変腑鐨勯�夐」
+ String questionText = trimAll(dto.getQuestionText()); // 棰樼洰
+ if (StringUtils.isEmpty(questionText)) {
+ continue;
+ }
+
+ // 鎷嗗垎 targetvalue锛屾瘡涓�夐」閮借鏈変竴鏉¤褰�
+ for (String raw : dto.getTargetvalue().split("&")) {
+
+ String option = trimAll(raw);
+ if (option.isEmpty()) {
+ continue;
+ }
+
+ // key = 绉戝/鐥呭尯 + 棰樼洰 + 閫夐」
+ String key = buildKey(groupName, questionText, option);
+
+ QuestionCountKsOrBqDTO item = map.get(key);
+ if (item == null) {
+ item = DtoConversionUtils.sourceToTarget(dto, QuestionCountKsOrBqDTO.class);
+ item.setTargetvalue(option);
+ item.setAsrtext(option);
+ item.setQuestionText(dto.getQuestionText());
+ item.setAnswerCount("0");
+ item.setSingleScore("0");
+ map.put(key, item);
+ }
+
+ // 鍙湁褰撳墠閫夐」 == 鐢ㄦ埛瀹為檯閫変腑鐨勯�夐」锛屾墠绱姞
+ if (option.equals(asrtext)) {
+ int count = parseCount(item.getAnswerCount()) + 1;
+ item.setAnswerCount(String.valueOf(count));
+
+ BigDecimal totalScore = new BigDecimal(item.getSingleScore())
+ .add(new BigDecimal(dto.getSingleScore() == null ? "0" : dto.getSingleScore()));
+ item.setSingleScore(totalScore.toPlainString());
+ }
+ }
+ }
+
+ // 4. 璁$畻骞冲潎鍒�
+ for (QuestionCountKsOrBqDTO dto : map.values()) {
+ String answerCount = dto.getAnswerCount();
+ String singleScore = dto.getSingleScore();
+
+ BigDecimal avg;
+ if (StringUtils.isEmpty(answerCount)
+ || BigDecimal.ZERO.compareTo(new BigDecimal(answerCount.trim())) == 0) {
+ avg = BigDecimal.ZERO;
+ } else {
+ avg = new BigDecimal(singleScore == null ? "0" : singleScore)
+ .divide(new BigDecimal(answerCount.trim()), 2, RoundingMode.HALF_UP);
+ }
+ dto.setAvgScore(avg.toPlainString());
+ }
+
+ // 5. 杞垚 Map<String, Map<String, List<QuestionCountKsOrBqDTO>>>
+ // 绗竴灞� key锛氱瀹�/鐥呭尯
+ // 绗簩灞� key锛氶鐩�
+ // 绗簩灞� value锛氳棰樼洰涓嬬殑鎵�鏈夐�夐」鍒楄〃
+ Map<String, Map<String, List<QuestionCountKsOrBqDTO>>> result = new LinkedHashMap<>();
+
+ for (QuestionCountKsOrBqDTO dto : map.values()) {
+
+ // 鍒嗙粍鍚�
+ String groupName = byDept ? dto.getDeptname() : dto.getLeavehospitaldistrictname();
+ if (StringUtils.isEmpty(groupName)) {
+ continue;
+ }
+
+ // 棰樼洰鍚�
+ String questionText = dto.getQuestionText();
+ if (StringUtils.isEmpty(questionText)) {
+ continue;
+ }
+
+ // 绗竴灞傦細绉戝/鐥呭尯
+ Map<String, List<QuestionCountKsOrBqDTO>> questionMap =
+ result.computeIfAbsent(groupName, k -> new LinkedHashMap<>());
+
+ // 绗簩灞傦細棰樼洰
+ List<QuestionCountKsOrBqDTO> optionList =
+ questionMap.computeIfAbsent(questionText, k -> new ArrayList<>());
+
+ optionList.add(dto);
}
return result;
}
@Override
- public List<ServiceSubtaskDetailRatioExport> statQuestionOptionBySubtaskIds(List<Long> subtaskIds, Date startOutHospTime, Date endOutHospTime, String scriptContent, Double scoreStart, Double scoreEnd, String valueType) {
+ public List<ServiceSubtaskDetailRatioExport> statQuestionOptionBySubtaskIds(List<Long> subtaskIds, Date startOutHospTime, Date endOutHospTime, Date startFinishTime, Date endFinishTime, String scriptContent, Double scoreStart, Double scoreEnd, String valueType) {
//鍏堟竻鐞嗕竴涓嬮噸澶嶆暟鎹�
List<Long> repeatIds = serviceSubtaskDetailMapper.selectRepeatDetailIds();
if (!CollectionUtils.isEmpty(repeatIds)) {
serviceSubtaskDetailMapper.deleteRepeatDetailByIds(repeatIds);
}
- List<ServiceSubtaskDetailRatioExport> serviceSubtaskDetailRatioExports = serviceSubtaskMapper.statQuestionOptionBySubtaskIds(subtaskIds, startOutHospTime, endOutHospTime, scoreStart, scoreEnd, scriptContent, valueType);
+ List<ServiceSubtaskDetailRatioExport> serviceSubtaskDetailRatioExports = serviceSubtaskMapper.statQuestionOptionBySubtaskIds(subtaskIds, startOutHospTime, endOutHospTime, startFinishTime, endFinishTime, scoreStart, scoreEnd, scriptContent, valueType);
// 澶勭悊 targetvalue锛氭寜 & 鍒嗗壊鎴愬鏉¤褰�
List<ServiceSubtaskDetailRatioExport> result = new ArrayList<>();
for (ServiceSubtaskDetailRatioExport export : serviceSubtaskDetailRatioExports) {
@@ -5122,8 +5329,17 @@
// 濡傛灉鏈夊鏉$洰鏍囧�硷紝鎷嗗垎鎴愬琛�
for (String value : values) {
//鍏堝幓 result 涓煡涓�涓嬶紝鏈夋病鏈夎繖涓� questiontext 鍜屽搴旂殑 targetvalue
- ServiceSubtaskDetailRatioExport existingExport = result.stream().filter(e -> e.getQuestiontext().equals(export.getQuestiontext()) && value.trim().equals(e.getTargetvalue())).findFirst().orElse(null);
- if (existingExport != null && existingExport.getRatio().equals("0") && existingExport.getCount().equals("0")) {
+ ServiceSubtaskDetailRatioExport existingExport = result.stream().filter(e -> {
+ if (e == null || export == null) {
+ return false;
+ }
+ String q1 = e.getQuestiontext() != null ? e.getQuestiontext() : "";
+ String q2 = export.getQuestiontext() != null ? export.getQuestiontext() : "";
+ String t1 = value.trim();
+ String t2 = e.getTargetvalue() != null ? e.getTargetvalue() : "";
+ return q1.equals(q2) && t1.equals(t2);
+ }).findFirst().orElse(null);
+ if (existingExport != null && "0".equals(existingExport.getRatio()) && "0".equals(existingExport.getCount())) {
//濡傛灉瀛樺湪锛屽垯灏� result 閲岀殑杩欎釜闂鎵�瀵瑰簲鐨� Targetvalue=value 杩欐潯鏁版嵁鏇存柊鎴愬綋鍓嶈繖鏉℃暟鎹�
if (value.equals(export.getOptionresult())) {
existingExport.setRatio(export.getRatio());
@@ -5131,7 +5347,7 @@
existingExport.setCount(export.getCount());
existingExport.setOptionresult(export.getOptionresult());
}
- } else if (existingExport != null && !existingExport.getRatio().equals("0")) {
+ } else if (existingExport != null && !"0".equals(existingExport.getRatio())) {
continue;
} else {
ServiceSubtaskDetailRatioExport newExport = DtoConversionUtils.sourceToTarget(export, ServiceSubtaskDetailRatioExport.class);
@@ -5373,6 +5589,34 @@
}
return content;
}
+
+ /**
+ * 婊℃剰搴﹁秼鍔挎煡璇�
+ *
+ * @param mydTrendReqVO
+ * @return
+ */
+ @Override
+ public List<MydTrendReqDTO> mydTrend(MydTrendReqVO mydTrendReqVO) {
+ List<MydTrendReqDTO> list = serviceSubtaskMapper.mydTrend(mydTrendReqVO.getStartFinishTime(), mydTrendReqVO.getEndFinishTime(), mydTrendReqVO.getType());
+ if (mydTrendReqVO.getType().equals("week")) list = getWeekDate(mydTrendReqVO, list);
+ if (mydTrendReqVO.getType().equals("year")) list = getYearDate(mydTrendReqVO, list);
+ if (mydTrendReqVO.getType().equals("month")) list = getMonthDate(mydTrendReqVO, list);
+ if (mydTrendReqVO.getType().equals("day")) list = getDayDate(mydTrendReqVO, list);
+ return list;
+ }
+
+ @Override
+ public List<MydTrendReqDTO> sltdMydTotalByDimension(MydTrendReqVO mydTrendReqVO) {
+ List<MydTrendReqDTO> list = null;
+ if (mydTrendReqVO.getDimensionType().equals("1"))
+ list = serviceSubtaskMapper.sltdMydTotalByDimension(mydTrendReqVO.getStartFinishTime(), mydTrendReqVO.getEndFinishTime(), mydTrendReqVO.getType());
+ else if (mydTrendReqVO.getDimensionType().equals("2"))
+ list = serviceSubtaskMapper.sltdMydTotalByYQ(mydTrendReqVO.getStartFinishTime(), mydTrendReqVO.getEndFinishTime(), mydTrendReqVO.getType());
+
+ return list;
+ }
+
public ServiceSubtask boxedServiceSubtask(ServiceTask serviceTask, ServiceTaskdept serviceTaskdept, PatArchive patArchive) {
ServiceSubtask serviceSubtask = DtoConversionUtils.sourceToTarget(serviceTask, ServiceSubtask.class);
@@ -5842,20 +6086,23 @@
/**
* 闂缁撴灉鍗犳瘮
*
- * @param serviceSubtaskEntity
+ * @param sltdMydTotalVO
* @param serviceSubtaskRes
* @return
*/
- public List<ServiceSubtaskDetailRatioExport> getDetailRatio(QuestionResultVO questionResultVO, List<ServiceSubtaskRes> serviceSubtaskRes) {
+ public List<ServiceSubtaskDetailRatioExport> getDetailRatio(SltdMydTotalVO sltdMydTotalVO, List<ServiceSubtaskRes> serviceSubtaskRes) {
List<ServiceSubtaskDetailRatioExport> serviceSubtaskDetailRatioExports = null;
- if (StringUtils.isNotEmpty(questionResultVO.getServiceType()) && questionResultVO.getServiceType().equals("2")) {
+ if (CollectionUtils.isNotEmpty(sltdMydTotalVO.getServiceTypeList()) && sltdMydTotalVO.getServiceTypeList().contains("2") && (sltdMydTotalVO.getServiceTypeList().contains("6") || sltdMydTotalVO.getServiceTypeList().contains("14"))) {
+ //serviceType锛屽嵆鏈夐殢璁垮張鏈夋弧鎰忓害锛屾殏鏃舵病娉曠粺璁�
+ return serviceSubtaskDetailRatioExports;
+ } else if (CollectionUtils.isNotEmpty(sltdMydTotalVO.getServiceTypeList()) && sltdMydTotalVO.getServiceTypeList().contains("2")) {
//鑾峰彇serviceSubtaskList涓殑鎵�鏈塼askid
List<Long> taskIds = serviceSubtaskRes.stream().map(ServiceSubtaskRes::getTaskid).filter(ObjectUtils::isNotEmpty).distinct().collect(Collectors.toList());
- serviceSubtaskDetailRatioExports = statQuestionOption(taskIds, questionResultVO.getStartOutHospTime(), questionResultVO.getEndOutHospTime(), questionResultVO.getQuestionContent(), questionResultVO.getStartScore(), questionResultVO.getEndScore(), questionResultVO.getValueType());
- } else if (StringUtils.isNotEmpty(questionResultVO.getServiceType()) && questionResultVO.getServiceType().equals("6")) {
+ serviceSubtaskDetailRatioExports = statQuestionOption(taskIds, sltdMydTotalVO.getStartFinishTime(), sltdMydTotalVO.getEndFinishTime(), sltdMydTotalVO.getStartOutHospTime(), sltdMydTotalVO.getEndOutHospTime(), sltdMydTotalVO.getQuestionContent(), sltdMydTotalVO.getStartScore(), sltdMydTotalVO.getEndScore(), sltdMydTotalVO.getValueType());
+ } else if (CollectionUtils.isNotEmpty(sltdMydTotalVO.getServiceTypeList()) && sltdMydTotalVO.getServiceTypeList().contains("6") || sltdMydTotalVO.getServiceTypeList().contains("14")) {
//婊℃剰搴︾粺璁� 锛堥�氳繃 subtask 鐨� id 鍘荤粺璁★級
List<Long> subtaskIds = serviceSubtaskRes.stream().map(ServiceSubtaskRes::getId).collect(Collectors.toList());
- serviceSubtaskDetailRatioExports = statQuestionOptionBySubtaskIds(subtaskIds, questionResultVO.getStartOutHospTime(), questionResultVO.getEndOutHospTime(), questionResultVO.getQuestionContent(), questionResultVO.getStartScore(), questionResultVO.getEndScore(), questionResultVO.getValueType());
+ serviceSubtaskDetailRatioExports = statQuestionOptionBySubtaskIds(subtaskIds, sltdMydTotalVO.getStartOutHospTime(), sltdMydTotalVO.getEndOutHospTime(), sltdMydTotalVO.getStartFinishTime(), sltdMydTotalVO.getEndFinishTime(), sltdMydTotalVO.getQuestionContent(), sltdMydTotalVO.getStartScore(), sltdMydTotalVO.getEndScore(), sltdMydTotalVO.getValueType());
}
return serviceSubtaskDetailRatioExports;
}
@@ -5899,4 +6146,304 @@
}
log.info("ai鍖归厤鎴愬姛锛屽尮閰嶇粨鏋滄槸:" + matchedText);
}
+
+ private static String trimAll(String s) {
+ if (s == null) {
+ return "";
+ }
+ int start = 0;
+ int end = s.length();
+ while (start < end && isBlankChar(s.charAt(start))) {
+ start++;
+ }
+ while (end > start && isBlankChar(s.charAt(end - 1))) {
+ end--;
+ }
+ return s.substring(start, end);
+ }
+
+ private static Boolean isBlankChar(char c) {
+ return c == '\u3000' // 鍏ㄨ绌烘牸
+ || c == ' ' // 鍗婅绌烘牸
+ || c == '\t' || c == '\n' || c == '\r' || c == '\f' || Character.isWhitespace(c);
+ }
+
+
+ private String buildKey(String groupName, String questionText, String option) {
+ return groupName + "\u0001" + questionText + "\u0001" + option;
+ }
+
+ private static int parseCount(String s) {
+ if (StringUtils.isEmpty(s)) {
+ return 0;
+ }
+ try {
+ return Integer.parseInt(s.trim());
+ } catch (NumberFormatException e) {
+ return 0;
+ }
+ }
+
+ private List<MydTrendReqDTO> getWeekDate(MydTrendReqVO mydTrendReqVO, List<MydTrendReqDTO> list) {
+ // 1. 璁$畻鎬诲懆鏁帮紙鍜� SQL 閲岀殑鍏紡淇濇寔涓�鑷达級
+ long days = (mydTrendReqVO.getEndFinishTime().getTime() - mydTrendReqVO.getStartFinishTime().getTime()) / (1000L * 60 * 60 * 24);
+ int totalWeeks = (int) (days / 7) + 1;
+
+ // 2. 宸叉湁鏁版嵁锛歱eriod -> totalScore
+ Map<Integer, String> exist = new HashMap<>();
+ for (MydTrendReqDTO row : list) {
+ // period 鏄暟瀛楋紝鍙兘鏄� Integer / Long / BigDecimal锛岀粺涓�杞� int
+ int p = Integer.parseInt(StringUtils.isNotEmpty(row.getPeriod()) ? row.getPeriod() : "0");
+ exist.put(p, row.getTotalScore() != null ? row.getTotalScore() : "0");
+ // 涓嬮潰杩欒鎸変綘鐨勫師閫昏緫淇濈暀锛堣櫧鐒剁湅璧锋潵鏈夌偣澶氫綑锛�
+ exist.put(p, String.valueOf(row.getTotalScore() != null ? row.getTotalScore() : 0));
+ }
+
+ // 3. 琛ュ叏 1..totalWeeks
+ List<MydTrendReqDTO> result = new ArrayList<>(totalWeeks);
+
+ // 鑾峰彇鏁翠綋鐨勫紑濮嬫椂闂�
+ long startTimeMillis = mydTrendReqVO.getStartFinishTime().getTime();
+ long endTimeMillis = mydTrendReqVO.getEndFinishTime().getTime();
+ long oneWeekMillis = 7L * 24 * 60 * 60 * 1000; // 涓�鍛ㄧ殑姣鏁�
+
+ for (int i = 1; i <= totalWeeks; i++) {
+ MydTrendReqDTO row = new MydTrendReqDTO();
+ row.setPeriod(String.valueOf(i));
+ row.setTotalScore(exist.getOrDefault(i, "0"));
+
+ // -------- 鏂板锛氳缃瘡鍛ㄧ殑 startDate 鍜� endDate --------
+ // 褰撳墠鍛ㄥ紑濮嬫椂闂� = 鏁翠綋寮�濮嬫椂闂� + (i - 1) * 7澶�
+ long currentStartMillis = startTimeMillis + (long) (i - 1) * oneWeekMillis;
+
+ // 褰撳墠鍛ㄧ粨鏉熸椂闂� = 褰撳墠鍛ㄥ紑濮嬫椂闂� + 7澶� - 1姣锛堜繚璇佹槸杩欎竴鍛ㄧ殑鏈�鍚庝竴鍒伙級
+ long currentEndMillis = currentStartMillis + oneWeekMillis - 1;
+
+ // 濡傛灉鏄渶鍚庝竴鍛紝缁撴潫鏃堕棿涓嶈兘瓒呰繃鏁翠綋鐨� endTime
+ if (i == totalWeeks) {
+ currentEndMillis = endTimeMillis;
+ }
+
+ row.setStartDate(new Date(currentStartMillis));
+ row.setEndDate(new Date(currentEndMillis));
+ // ----------------------------------------------------
+
+ result.add(row);
+ }
+
+ return result;
+ }
+
+ private List<MydTrendReqDTO> getYearDate(MydTrendReqVO mydTrendReqVO, List<MydTrendReqDTO> list) {
+ // 鑾峰彇鏁翠綋寮�濮嬪拰缁撴潫鏃堕棿
+ Date startTime = mydTrendReqVO.getStartFinishTime();
+ Date endTime = mydTrendReqVO.getEndFinishTime();
+
+ // 1. 璁$畻骞翠唤鑼冨洿
+ // 浣跨敤 Calendar 鑾峰彇璧峰骞翠唤鍜岀粨鏉熷勾浠�
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(startTime);
+ int startYear = cal.get(Calendar.YEAR);
+
+ cal.setTime(endTime);
+ int endYear = cal.get(Calendar.YEAR);
+
+ // 鎬诲勾鏁� (鍖呭惈棣栧熬)
+ int totalYears = endYear - startYear + 1;
+
+ // 2. 宸叉湁鏁版嵁锛歱eriod -> totalScore (鍋囪 period 瀛樼殑鏄勾浠藉瓧绗︿覆锛屽 "2024")
+ Map<String, String> exist = new HashMap<>();
+ for (MydTrendReqDTO row : list) {
+ String period = row.getPeriod() != null ? row.getPeriod() : "";
+ exist.put(period, row.getTotalScore() != null ? row.getTotalScore() : "0");
+ }
+
+ // 3. 琛ュ叏鎵�鏈夊勾浠�
+ List<MydTrendReqDTO> result = new ArrayList<>(totalYears);
+
+ for (int i = 0; i < totalYears; i++) {
+ int currentYear = startYear + i;
+ String periodKey = String.valueOf(currentYear);
+
+ MydTrendReqDTO row = new MydTrendReqDTO();
+ row.setPeriod(periodKey);
+ // 濡傛灉娌℃湁璇ュ勾浠界殑鏁版嵁锛岄粯璁ょ粰 "0"
+ row.setTotalScore(exist.getOrDefault(periodKey, "0"));
+
+ // -------- 璁剧疆璇ュ勾浠界殑 startDate 鍜� endDate --------
+ Calendar yearCal = Calendar.getInstance();
+ // 璁剧疆涓鸿骞寸殑 1鏈�1鏃� 00:00:00
+ yearCal.set(currentYear, Calendar.JANUARY, 1, 0, 0, 0);
+ yearCal.set(Calendar.MILLISECOND, 0);
+ row.setStartDate(yearCal.getTime());
+
+ // 璁剧疆涓鸿骞寸殑 12鏈�31鏃� 23:59:59
+ yearCal.set(currentYear, Calendar.DECEMBER, 31, 23, 59, 59);
+ yearCal.set(Calendar.MILLISECOND, 999);
+ row.setEndDate(yearCal.getTime());
+ // ----------------------------------------------------
+
+ result.add(row);
+ }
+
+ return result;
+ }
+
+ private List<MydTrendReqDTO> getMonthDate(MydTrendReqVO mydTrendReqVO, List<MydTrendReqDTO> list) {
+ // 鑾峰彇鏁翠綋寮�濮嬪拰缁撴潫鏃堕棿
+ Date startTime = mydTrendReqVO.getStartFinishTime();
+ Date endTime = mydTrendReqVO.getEndFinishTime();
+
+ // 1. 璁$畻鏈堜唤鑼冨洿
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(startTime);
+ int startYear = cal.get(Calendar.YEAR);
+ int startMonth = cal.get(Calendar.MONTH); // 娉ㄦ剰锛欳alendar.MONTH 浠� 0 寮�濮�
+
+ cal.setTime(endTime);
+ int endYear = cal.get(Calendar.YEAR);
+ int endMonth = cal.get(Calendar.MONTH);
+
+ // 鎬绘湀鏁� = (缁撴潫骞� - 寮�濮嬪勾) * 12 + (缁撴潫鏈� - 寮�濮嬫湀) + 1
+ int totalMonths = (endYear - startYear) * 12 + (endMonth - startMonth) + 1;
+
+ // 2. 宸叉湁鏁版嵁锛歱eriod -> totalScore (period 瀛樼殑鏄湀浠藉瓧绗︿覆锛屽 "2024-06")
+ Map<String, String> exist = new HashMap<>();
+ for (MydTrendReqDTO row : list) {
+ String period = row.getPeriod() != null ? row.getPeriod() : "";
+ exist.put(period, row.getTotalScore() != null ? row.getTotalScore() : "0");
+ }
+
+ // 3. 琛ュ叏鎵�鏈夋湀浠�
+ List<MydTrendReqDTO> result = new ArrayList<>(totalMonths);
+
+ Calendar monthCal = Calendar.getInstance();
+ monthCal.set(startYear, startMonth, 1, 0, 0, 0);
+ monthCal.set(Calendar.MILLISECOND, 0);
+
+ for (int i = 0; i < totalMonths; i++) {
+ int currentYear = monthCal.get(Calendar.YEAR);
+ int currentMonth = monthCal.get(Calendar.MONTH) + 1; // 杞垚 1-12 鏈�
+
+ // 鎷兼帴 period锛屾牸寮忥細yyyy-MM锛屾瘮濡� "2024-06"
+ // 濡傛灉浣犲笇鏈涙槸 "2024-6"锛屽彲浠ユ妸 String.format 鏀规垚 currentMonth
+ String periodKey = String.format("%04d-%02d", currentYear, currentMonth);
+
+ MydTrendReqDTO row = new MydTrendReqDTO();
+ row.setPeriod(periodKey);
+ row.setTotalScore(exist.getOrDefault(periodKey, "0"));
+
+ // -------- 璁剧疆璇ユ湀鐨� startDate 鍜� endDate --------
+ // 褰撴湀寮�濮嬫椂闂达細1鍙� 00:00:00.000
+ Calendar startCal = (Calendar) monthCal.clone();
+ row.setStartDate(startCal.getTime());
+
+ // 褰撴湀缁撴潫鏃堕棿锛氫笅涓湀1鍙� 00:00:00.000 鍑� 1 姣
+ Calendar endCal = (Calendar) monthCal.clone();
+ endCal.add(Calendar.MONTH, 1);
+ endCal.add(Calendar.MILLISECOND, -1);
+ row.setEndDate(endCal.getTime());
+ // ----------------------------------------------------
+
+ result.add(row);
+
+ // 杩涘叆涓嬩竴涓湀
+ monthCal.add(Calendar.MONTH, 1);
+ }
+
+ return result;
+ }
+
+ private List<MydTrendReqDTO> getDayDate(MydTrendReqVO mydTrendReqVO, List<MydTrendReqDTO> list) {
+ // 鑾峰彇鏁翠綋寮�濮嬪拰缁撴潫鏃堕棿
+ Date startTime = mydTrendReqVO.getStartFinishTime();
+ Date endTime = mydTrendReqVO.getEndFinishTime();
+
+ // 1. 璁$畻鎬诲ぉ鏁�
+ long oneDayMillis = 24L * 60 * 60 * 1000;
+ // 娉ㄦ剰锛氳繖閲屽彧绠楁棩鏈熷樊锛屼笉鑰冭檻鏃跺垎绉掞紝鍚﹀垯鍙兘宸竴澶�
+ Calendar startCal = Calendar.getInstance();
+ startCal.setTime(startTime);
+ startCal.set(Calendar.HOUR_OF_DAY, 0);
+ startCal.set(Calendar.MINUTE, 0);
+ startCal.set(Calendar.SECOND, 0);
+ startCal.set(Calendar.MILLISECOND, 0);
+
+ Calendar endCal = Calendar.getInstance();
+ endCal.setTime(endTime);
+ endCal.set(Calendar.HOUR_OF_DAY, 0);
+ endCal.set(Calendar.MINUTE, 0);
+ endCal.set(Calendar.SECOND, 0);
+ endCal.set(Calendar.MILLISECOND, 0);
+
+ long days = (endCal.getTimeInMillis() - startCal.getTimeInMillis()) / oneDayMillis;
+ int totalDays = (int) days + 1;
+
+ // 2. 宸叉湁鏁版嵁锛歱eriod -> totalScore (period 瀛樼殑鏄棩鏈熷瓧绗︿覆锛屽 "2024-06-01")
+ Map<String, String> exist = new HashMap<>();
+ for (MydTrendReqDTO row : list) {
+ String period = row.getPeriod() != null ? row.getPeriod() : "";
+ exist.put(period, row.getTotalScore() != null ? row.getTotalScore() : "0");
+ }
+
+ // 3. 琛ュ叏鎵�鏈夋棩鏈�
+ List<MydTrendReqDTO> result = new ArrayList<>(totalDays);
+
+ Calendar dayCal = (Calendar) startCal.clone();
+ for (int i = 0; i < totalDays; i++) {
+ // 鎷兼帴 period锛屾牸寮忥細yyyy-MM-dd
+ String periodKey = String.format("%04d-%02d-%02d", dayCal.get(Calendar.YEAR), dayCal.get(Calendar.MONTH) + 1, dayCal.get(Calendar.DAY_OF_MONTH));
+
+ MydTrendReqDTO row = new MydTrendReqDTO();
+ row.setPeriod(periodKey);
+ row.setTotalScore(exist.getOrDefault(periodKey, "0"));
+
+ // -------- 璁剧疆璇ュぉ鐨� startDate 鍜� endDate --------
+ Calendar startOfDay = (Calendar) dayCal.clone();
+ row.setStartDate(startOfDay.getTime());
+
+ Calendar endOfDay = (Calendar) dayCal.clone();
+ endOfDay.set(Calendar.HOUR_OF_DAY, 23);
+ endOfDay.set(Calendar.MINUTE, 59);
+ endOfDay.set(Calendar.SECOND, 59);
+ endOfDay.set(Calendar.MILLISECOND, 999);
+ row.setEndDate(endOfDay.getTime());
+ // ----------------------------------------------------
+
+ result.add(row);
+
+ // 杩涘叆涓嬩竴澶�
+ dayCal.add(Calendar.DAY_OF_MONTH, 1);
+ }
+
+ return result;
+ }
+
+ /**
+ * 闂ㄨ瘖婊℃剰搴︾患鍚堝緱鍒嗘帓鍚嶏紙鎸夌瀹ゆ垨鐥呭尯锛�
+ * <p>
+ * 缁煎悎婊℃剰搴� = 危(璇勫垎鏄庣粏鏉冮噸) / 璇勫垎鏄庣粏鏉℃暟 脳 100%锛�
+ * 鏉冮噸鍙彇 1銆�0.8銆�0.6銆�0.4銆�0.2 浜旀。锛堝緢婊℃剰銆佹弧鎰忋�佷竴鑸�佷笉婊℃剰銆佸緢涓嶆弧鎰忥級銆�
+ *
+ * @param mzMydScoreRankVO 鏌ヨ鏉′欢
+ * @return 鎺掑悕缁撴灉锛屽悕娆′粠 1 寮�濮嬮『搴忕紪鍙�
+ */
+ @Override
+ public List<MzMydScoreRankDTO> mzMydScoreRank(MzMydScoreRankVO mzMydScoreRankVO) {
+ if (StringUtils.isEmpty(mzMydScoreRankVO.getDimensionType())) {
+ mzMydScoreRankVO.setDimensionType("1");
+ }
+ if (StringUtils.isEmpty(mzMydScoreRankVO.getServiceType())) {
+ mzMydScoreRankVO.setServiceType("14");
+ }
+ List<MzMydScoreRankDTO> list = serviceSubtaskMapper.selectMzMydScoreRank(mzMydScoreRankVO);
+ if (CollectionUtils.isEmpty(list)) {
+ return new ArrayList<>();
+ }
+ // 鍚嶆锛歋QL 宸叉寜缁煎悎寰楀垎闄嶅簭杩斿洖锛岃繖閲岄『搴忕紪鍙�
+ for (int i = 0; i < list.size(); i++) {
+ list.get(i).setRank(i + 1);
+ }
+ return list;
+ }
}
--
Gitblit v1.9.3