From db2a00f5df9990e55ebbdf16cf8c68c3d64fe09d Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期二, 28 七月 2026 16:26:43 +0800
Subject: [PATCH] Merge branch 'master' into master-任务组

---
 smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java |  142 ++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 120 insertions(+), 22 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 1201841..57f6c79 100644
--- a/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
@@ -13,12 +13,15 @@
 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;
 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.*;
@@ -121,6 +124,12 @@
     private IServiceSubtaskDetailTraceService traceService;
 
     @Autowired
+    private IServiceTaskScheduleService serviceTaskScheduleService;
+
+    @Autowired
+    private ScheduleSubtaskBuilder scheduleSubtaskBuilder;
+
+    @Autowired
     private FtpService ftpService;
 
     @Autowired
@@ -146,6 +155,9 @@
 
     @Value("${ASRCallBackPath}")
     private String ASRCallBackPath;
+
+    @Autowired
+    private ISysConfigService configService;
 
     @Autowired
     private MtSubmitSmUtil mtSubmitSmUtil;
@@ -829,6 +841,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());
@@ -914,6 +949,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();
 
@@ -1128,6 +1177,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())) {
@@ -1181,6 +1248,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);
@@ -1233,7 +1314,6 @@
         map.put("taskId", serviceTask.getTaskid().intValue());
         return map;
     }
-
 
     @Override
     public void phoneCallBack(PhoneCallBackVO phoneCallBackVO) {
@@ -1734,14 +1814,14 @@
             if (ivrTaskTemplateScriptVO.getScriptType().equals("1")) {
                 //鐢ㄦ潵鏍囪锛屾槸鍚︽湁鍖归厤涓婄殑
                 Integer flag = 0;
-//                //2-AI璇嗗埆
-//                SysConfig configVoiceMatchType = new SysConfig();
-//                configVoiceMatchType.setOrgid(phoneCallReqYQVO.getOrgid());
-//                configVoiceMatchType.setConfigKey("sys.voice.match.type");
-//                SysConfig matchType = sysConfigMapper.selectConfig(configVoiceMatchType);
-//
-//            if (ObjectUtils.isNotEmpty(matchType) && StringUtils.isNotEmpty(matchType.getConfigValue())
-//                    && matchType.getConfigValue().equals("2")) {
+                //1-AI璇嗗埆
+                SysConfig configVoiceMatchAi = new SysConfig();
+                configVoiceMatchAi.setOrgid(phoneCallReqYQVO.getOrgid());
+                configVoiceMatchAi.setConfigKey("sys.voice.match.ai");
+                SysConfig matchAi = sysConfigMapper.selectConfig(configVoiceMatchAi);
+
+//            if (ObjectUtils.isNotEmpty(matchAi) && StringUtils.isNotEmpty(matchAi.getConfigValue())
+//                    && matchAi.getConfigValue().equals("1")) {
 //                PhoneCallBackYQVO aiMatchResult = AiMatch(phoneCallReqYQVO, phoneCallBackYQVO,
 //                        ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate,
 //                        ivrTaskTemplateScripts, scriptId, flag);
@@ -4976,34 +5056,45 @@
      * @param options
      * @return
      */
-    public String matchOptionIndex(String questionText, String voiceText, List<IvrTaskTemplateTargetoption> options) {
+    public Integer matchOptionIndex(String questionText, String voiceText, List<IvrTaskTemplateTargetoption> options){
         JSONObject jsonObject = new JSONObject();
         jsonObject.put("userQuestion",questionText);
         jsonObject.put("userAnswer",voiceText);
         jsonObject.put("options", options);
         String jsonString = jsonObject.toJSONString();
         String result = null;
-        try {
-            result = OkHttpExample.post("http://localhost:8099/matchOptionIndex", jsonString);
-        } catch (IOException e) {
-            throw new RuntimeException(e);
+
+        String url = "http://localhost:8099/matchOptionIndex";
+//        String url = configService.selectConfigByKey("sys.voice.match.ai.url");
+        if(StringUtils.isNotEmpty(url)){
+            try {
+                Map<String, String> headers = new HashMap<>();
+                headers.put("Content-Type", "application/json");
+
+                result = HttpUtils.sendPostByHeader(url, jsonString, headers);
+            } catch (Exception e) {
+                log.error("AI璇嗗埆澶辫触", e);
+            }
         }
-        return result;
+        if(StringUtils.isNotEmpty(result) && result.matches("^-?\\d+$")){
+            return Integer.parseInt(result);
+        }else {
+            return -1;
+        }
     }
 
     public PhoneCallBackYQVO AiMatch(PhoneCallReqYQVO phoneCallReqYQVO, PhoneCallBackYQVO phoneCallBackYQVO,
                         IvrTaskTemplateScriptVO ivrTaskTemplateScriptVO, ServiceSubtask serviceSubtask, IvrTaskTemplate ivrTaskTemplate,
                         List<IvrTaskTemplateScript> ivrTaskTemplateScripts, String scriptId, Integer flag){
         PhoneCallBackYQVO back = null;
-        String result = "0";
         List<IvrTaskTemplateTargetoption> options = ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList();
         String voiceText = phoneCallReqYQVO.getAsrtext();
         String questionText = StringUtils.isNotEmpty(ivrTaskTemplateScriptVO.getIvrtext()) ? ivrTaskTemplateScriptVO.getIvrtext() : ivrTaskTemplateScriptVO.getScriptContent();
-        result = matchOptionIndex(questionText, voiceText, options);
-        Integer matched = Integer.valueOf(result);
-        IvrTaskTemplateTargetoption chosenOption = options.get(matched);
+        Integer matched = -1;
+        matched = matchOptionIndex(questionText, voiceText, options);
         //璇存槑鍖归厤姝g‘浜�
-        if(matched != null && matched != 0){
+        if(matched != null && matched >= 0){
+            IvrTaskTemplateTargetoption chosenOption = options.get(matched);
             //杩欓噷搴旇鍏堝垽鏂被鍨嬶紝鍘诲啀淇敼锛岃缃甀sUserOperation鏄崟閫夐鐨勬敼娉�
             log.info("鍖归厤姝g‘浜嗗悧--------------");
             chosenOption.setIsUserOperation(1);
@@ -5225,7 +5316,7 @@
     public void TestMatch(){
         String questionText = "鎮ㄥソ,璇烽棶鎮ㄦ槸鎮h�呮湰浜鸿繕鏄灞烇紵\n";
         String voiceText = "鎴戣嚜宸�";
-        Long scriptid = 31231L;
+        String matchedText = "";
         List<IvrTaskTemplateTargetoption> options = new ArrayList<>();
         IvrTaskTemplateTargetoption ivrTaskTemplateTargetoption1 = new IvrTaskTemplateTargetoption();
         ivrTaskTemplateTargetoption1.setTargetvalue("鏈汉");
@@ -5236,6 +5327,13 @@
         IvrTaskTemplateTargetoption ivrTaskTemplateTargetoption3 = new IvrTaskTemplateTargetoption();
         ivrTaskTemplateTargetoption3.setTargetvalue("鍏朵粬");
         options.add(ivrTaskTemplateTargetoption3);
-        matchOptionIndex(questionText,voiceText,options);
+
+        Integer matched = matchOptionIndex(questionText,voiceText,options);
+        if(ObjectUtils.isNotEmpty(matched)){
+            if(matched >= 0){
+                matchedText = options.get(matched).getTargetvalue();
+            }
+        }
+        log.info("ai鍖归厤鎴愬姛锛屽尮閰嶇粨鏋滄槸:" + matchedText);
     }
 }

--
Gitblit v1.9.3