From 990ddfd92bfe81eb3396d741a3ce9106ea5e132f Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期五, 31 七月 2026 14:11:24 +0800
Subject: [PATCH] 【市一】报错调整

---
 smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java |  124 +++++++++++++++++++++++++++++++++--------
 1 files changed, 100 insertions(+), 24 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 67be372..6c932e0 100644
--- a/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
@@ -6,7 +6,6 @@
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.google.gson.Gson;
-import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.domain.entity.SysDept;
 import com.ruoyi.common.core.redis.RedisCache;
 import com.ruoyi.common.dx.MessageSend;
@@ -18,9 +17,9 @@
 import com.ruoyi.system.domain.SysConfig;
 import com.ruoyi.system.mapper.SysConfigMapper;
 import com.ruoyi.system.service.ISysConfigService;
-import com.smartor.common.DeepSeekApi;
 import com.smartor.common.FtpService;
 import com.smartor.common.MtSubmitSmUtil;
+import com.smartor.common.ScheduleSubtaskBuilder;
 import com.smartor.config.PhoneUtils;
 import com.smartor.domain.DTO.ServiceSubtaskDetailDTO;
 import com.smartor.domain.*;
@@ -33,7 +32,6 @@
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.MapUtils;
 import org.apache.commons.lang3.ObjectUtils;
-import org.apache.ibatis.annotations.Param;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -121,6 +119,12 @@
 
     @Autowired
     private IServiceSubtaskDetailTraceService traceService;
+
+    @Autowired
+    private IServiceTaskScheduleService serviceTaskScheduleService;
+
+    @Autowired
+    private ScheduleSubtaskBuilder scheduleSubtaskBuilder;
 
     @Autowired
     private FtpService ftpService;
@@ -834,6 +838,29 @@
                             serviceTaskoperService.insertServiceTaskoper(serviceTaskoper);
                         }
                     }
+
+                } else if (serviceTaskVO.getAppltype().equals("5")) {
+                    // 浠诲姟缁勶細蹇呴』涓洪暱鏈熶换鍔★紙鍚﹀垯 findMatchingTaskIds 鎵笉鍒帮紝鏃犳硶鑷姩绾冲叆鏂板嚭闄㈡偅鑰咃級
+                    if (serviceTaskVO.getLongTask() == null || serviceTaskVO.getLongTask() != 1) {
+                        throw new BaseException("appltype=5 浠诲姟缁勫繀椤讳负闀挎湡浠诲姟锛坙ongTask=1锛�");
+                    }
+                    // 淇濆瓨璁″垝 + 鏄庣粏
+                    ServiceTaskScheduleVO scheduleVO = serviceTaskVO.getServiceTaskScheduleVO();
+                    if (scheduleVO == null) {
+                        throw new BaseException("appltype=5 浠诲姟缁勶細serviceTaskScheduleVO 涓嶈兘涓虹┖");
+                    }
+                    scheduleVO.setTaskid(serviceTask.getTaskid());
+                    scheduleVO.setOrgid(serviceTask.getOrgid());
+                    scheduleVO.setCampusid(serviceTask.getCampusid());
+                    scheduleVO.setCreateBy(serviceTask.getCreateBy());
+
+                    scheduleVO.setDeptCodes(serviceTaskVO.getDeptcode());
+                    scheduleVO.setWardCodes(serviceTaskVO.getLeavehospitaldistrictcode());
+                    scheduleVO.setIcd10Codes(serviceTaskVO.getIcd10code());
+                    scheduleVO.setOplevelCodes(serviceTaskVO.getOplevelcode());
+
+                    log.info("----serviceTaskSchedule鐨勫�间负锛歿}", scheduleVO);
+                    serviceTaskScheduleService.saveScheduleWithDetail(scheduleVO);
                 } else {
                     ServiceTaskdept serviceTaskdept = new ServiceTaskdept();
                     serviceTaskdept.setTaskId(serviceTask.getTaskid());
@@ -919,6 +946,20 @@
                         serviceSubtask.setLongSendTime(patTaskRelevance.getLongSendTime());
                         serviceSubtask.setVisitTime(patTaskRelevance.getVisittime());
                     }
+
+                    // ===== appltype=5 浠诲姟缁勶細鎸� schedule 鐨� detailList 娲剧敓澶氭潯 subtask =====
+                    if ("5".equals(serviceTaskVO.getAppltype())) {
+                        ServiceTaskSchedule schedule = serviceTaskScheduleService.selectByTaskid(serviceTask.getTaskid());
+                        if (schedule == null) {
+                            throw new BaseException("appltype=5 浠诲姟缁勶細鏈壘鍒� taskid=" + serviceTask.getTaskid() + " 鐨勮鍒�");
+                        }
+                        List<ServiceTaskScheduleDetail> detailList =
+                                serviceTaskScheduleService.selectDetailByScheduleid(schedule.getId());
+                        scheduleSubtaskBuilder.buildSubtasksForPatient(
+                                serviceTask, serviceTaskVO.getPreachformList(), schedule, detailList, patTaskRelevance, serviceSubtask);
+                        continue;
+                    }
+
                     serviceSubtaskMapper.insertServiceSubtask(serviceSubtask);
                     serviceSubtask.getId().intValue();
 
@@ -1133,6 +1174,24 @@
                             }
                         }
                     }
+                } else if (serviceTaskVO.getAppltype().equals("5")) {
+                    // 浠诲姟缁勪慨鏀癸細鍒犳棫 schedule + 鏄庣粏锛岄噸寤恒�俿ubtask 涓婇潰宸叉壒閲忔竻鐞嗐��
+                    if (serviceTaskVO.getLongTask() == null || serviceTaskVO.getLongTask() != 1) {
+                        throw new BaseException("appltype=5 浠诲姟缁勫繀椤讳负闀挎湡浠诲姟锛坙ongTask=1锛�");
+                    }
+                    ServiceTaskScheduleVO scheduleVO = serviceTaskVO.getServiceTaskScheduleVO();
+                    if (scheduleVO == null) {
+                        throw new BaseException("appltype=5 浠诲姟缁勶細serviceTaskScheduleVO 涓嶈兘涓虹┖");
+                    }
+                    scheduleVO.setTaskid(serviceTask.getTaskid());
+                    scheduleVO.setOrgid(serviceTask.getOrgid());
+                    scheduleVO.setCampusid(serviceTask.getCampusid());
+                    scheduleVO.setDeptCodes(serviceTaskVO.getDeptcode());
+                    scheduleVO.setWardCodes(serviceTaskVO.getLeavehospitaldistrictcode());
+                    scheduleVO.setIcd10Codes(serviceTaskVO.getIcd10code());
+                    scheduleVO.setOplevelCodes(serviceTaskVO.getOplevelcode());
+                    scheduleVO.setCreateBy(serviceTask.getUpdateBy());
+                    serviceTaskScheduleService.saveScheduleWithDetail(scheduleVO);
                 }
             }
             if (ObjectUtils.isNotEmpty(serviceTaskVO.getIvrTaskTemplateVO())) {
@@ -1186,6 +1245,20 @@
                     serviceSubtask.setVisitTime(patTaskRelevance.getVisittime());
                     serviceSubtask.setTextParam(new Gson().toJson(serviceTaskVO.getTextParam()));
                     if (patTaskRelevance.getIsoperation() != null) {
+                        // appltype=5 浠诲姟缁勶細杩藉姞鎮h�咃紙isoperation=1锛夎蛋璁″垝娲剧敓锛涗慨鏀癸紙2锛�/鍒犻櫎锛�3锛変粛璧板師閫昏緫
+                        if ("5".equals(serviceTaskVO.getAppltype()) && patTaskRelevance.getIsoperation() == 1) {
+                            ServiceTaskSchedule schedule = serviceTaskScheduleService.selectByTaskid(serviceTask.getTaskid());
+                            if (schedule == null) {
+                                throw new BaseException("appltype=5 浠诲姟缁勶細鏈壘鍒� taskid=" + serviceTask.getTaskid() + " 鐨勮鍒�");
+                            }
+                            List<ServiceTaskScheduleDetail> detailList =
+                                    serviceTaskScheduleService.selectDetailByScheduleid(schedule.getId());
+                            serviceSubtask.setUpdateBy(serviceTask.getUpdateBy());
+                            serviceSubtask.setCreateBy(serviceTask.getUpdateBy());
+                            scheduleSubtaskBuilder.buildSubtasksForPatient(
+                                    serviceTask, serviceTaskVO.getPreachformList(), schedule, detailList, patTaskRelevance, serviceSubtask);
+                            continue;
+                        }
                         if (patTaskRelevance.getIsoperation() == 2) {
                             serviceSubtask.setUpdateBy(serviceTask.getUpdateBy());
                             serviceSubtaskMapper.updateServiceSubtaskByCondition(serviceSubtask);
@@ -1238,7 +1311,6 @@
         map.put("taskId", serviceTask.getTaskid().intValue());
         return map;
     }
-
 
     @Override
     public void phoneCallBack(PhoneCallBackVO phoneCallBackVO) {
@@ -1740,14 +1812,10 @@
                 //鐢ㄦ潵鏍囪锛屾槸鍚︽湁鍖归厤涓婄殑
                 Integer flag = 0;
                 //1-AI璇嗗埆
-                SysConfig configVoiceMatchAi = new SysConfig();
-                configVoiceMatchAi.setOrgid(phoneCallReqYQVO.getOrgid());
-                configVoiceMatchAi.setConfigKey("sys.voice.match.ai");
-                SysConfig matchAi = sysConfigMapper.selectConfig(configVoiceMatchAi);
+                String url = configService.selectConfigByKey("sys.voice.match.ai.url",phoneCallReqYQVO.getOrgid());
 
-            if (ObjectUtils.isNotEmpty(matchAi) && StringUtils.isNotEmpty(matchAi.getConfigValue())
-                    && matchAi.getConfigValue().equals("1")) {
-                PhoneCallBackYQVO aiMatchResult = AiMatch(phoneCallReqYQVO, phoneCallBackYQVO,
+            if (ObjectUtils.isNotEmpty(url)) {
+                PhoneCallBackYQVO aiMatchResult = AiMatch(url, phoneCallReqYQVO, phoneCallBackYQVO,
                         ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate,
                         ivrTaskTemplateScripts, scriptId, flag, phoneCallReqYQVO.getUuid());
                 if(aiMatchResult != null){
@@ -2617,16 +2685,21 @@
     @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);
-        String groupKey = "drcode";
+        String drcode = "drcode";
+        //缂欎簯浜烘皯 鏍规嵁缁忕鍖荤敓鍒嗙粍
+        if(serviceSubtaskCountReq.getOrgid().equals("47246116333112211A1001")){
+            drcode = "management_doctor_code";
+        }
+        String groupKey = drcode;
         if (serviceSubtaskCountReq.getStatisticaltype() != null && serviceSubtaskCountReq.getStatisticaltype() == 1) {
             if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) {
-                groupKey = "drcode";
+                groupKey = drcode;
             } else {
                 groupKey = "leavehospitaldistrictcode";
             }
         } else if (serviceSubtaskCountReq.getStatisticaltype() != null && serviceSubtaskCountReq.getStatisticaltype() == 2) {
             if (serviceSubtaskCountReq.getDrcode() != null && !serviceSubtaskCountReq.getDrcode().isEmpty()) {
-                groupKey = "drcode";
+                groupKey = drcode;
             } else {
                 groupKey = "deptcode";
             }
@@ -2639,11 +2712,14 @@
         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 "management_doctor_code":
+                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getManagementDoctorCode()).orElse("Unknown")));
+                break;
+            case "deptcode":
+                collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getDeptcode()).orElse("Unknown")));
                 break;
             case "leavehospitaldistrictcode":
                 collect = rawData.stream().collect(Collectors.groupingBy(subtask -> Optional.ofNullable(subtask.getLeavehospitaldistrictcode()).orElse("Unknown")));
@@ -4981,7 +5057,7 @@
      * @param options
      * @return
      */
-    public Integer matchOptionIndex(String questionText, String voiceText, List<IvrTaskTemplateTargetoption> options, String uuid){
+    public Integer matchOptionIndex(String url, String questionText, String voiceText, List<IvrTaskTemplateTargetoption> options, String uuid){
         JSONObject jsonObject = new JSONObject();
         jsonObject.put("userQuestion",questionText);
         jsonObject.put("userAnswer",voiceText);
@@ -4990,8 +5066,7 @@
         String jsonString = jsonObject.toJSONString();
         String result = null;
 
-        String url = "http://localhost:8099/matchOptionIndex";
-//        String url = configService.selectConfigByKey("sys.voice.match.ai.url");
+//        String url = "http://localhost:8099/matchOptionIndex";
         if(StringUtils.isNotEmpty(url)){
             try {
                 Map<String, String> headers = new HashMap<>();
@@ -5009,7 +5084,7 @@
         }
     }
 
-    public PhoneCallBackYQVO AiMatch(PhoneCallReqYQVO phoneCallReqYQVO, PhoneCallBackYQVO phoneCallBackYQVO,
+    public PhoneCallBackYQVO AiMatch(String url, PhoneCallReqYQVO phoneCallReqYQVO, PhoneCallBackYQVO phoneCallBackYQVO,
                         IvrTaskTemplateScriptVO ivrTaskTemplateScriptVO, ServiceSubtask serviceSubtask, IvrTaskTemplate ivrTaskTemplate,
                         List<IvrTaskTemplateScript> ivrTaskTemplateScripts, String scriptId, Integer flag, String uuid){
         PhoneCallBackYQVO back = null;
@@ -5017,7 +5092,7 @@
         String voiceText = phoneCallReqYQVO.getAsrtext();
         String questionText = StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrtext()) ? ivrTaskTemplateScriptVO.getIvrtext() : ivrTaskTemplateScriptVO.getScriptContent();
         Integer matched = -1;
-        matched = matchOptionIndex(questionText, voiceText, options, uuid);
+        matched = matchOptionIndex(url, questionText, voiceText, options, uuid);
         //璇存槑鍖归厤姝g‘浜�
         if(matched != null && matched >= 0){
             IvrTaskTemplateTargetoption chosenOption = options.get(matched);
@@ -5253,8 +5328,9 @@
         IvrTaskTemplateTargetoption ivrTaskTemplateTargetoption3 = new IvrTaskTemplateTargetoption();
         ivrTaskTemplateTargetoption3.setTargetvalue("鍏朵粬");
         options.add(ivrTaskTemplateTargetoption3);
-
-        Integer matched = matchOptionIndex(questionText,voiceText,options,"1");
+        //1-AI璇嗗埆
+        String url = configService.selectConfigByKey("sys.voice.match.ai.url");
+        Integer matched = matchOptionIndex(url, questionText,voiceText,options,"1");
         if(ObjectUtils.isNotEmpty(matched)){
             if(matched >= 0){
                 matchedText = options.get(matched).getTargetvalue();

--
Gitblit v1.9.3