From efaa2a7a5b7d9d1a36f4d6a7e275d2b76f6cd9d3 Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期四, 06 八月 2026 18:06:09 +0800
Subject: [PATCH] 【景宁】查询随访任务组科室关联列表、查询随访任务组疾病关联列表

---
 smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java |  309 ++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 265 insertions(+), 44 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..36c346d 100644
--- a/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
@@ -6,19 +6,20 @@
 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;
 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.smartor.common.DeepSeekApi;
+import com.ruoyi.system.service.ISysConfigService;
 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.*;
@@ -31,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;
@@ -86,6 +86,8 @@
 
     @Autowired
     private IServiceTaskdeptService serviceTaskdeptService;
+    @Autowired
+    private IServiceTaskmedicalService serviceTaskmedicalService;
 
     @Autowired
     private IServiceTaskdiagService serviceTaskdiagService;
@@ -121,6 +123,15 @@
     private IServiceSubtaskDetailTraceService traceService;
 
     @Autowired
+    private IServiceTaskScheduleService serviceTaskScheduleService;
+
+    @Autowired
+    private IPatArchiveService patArchiveService;
+
+    @Autowired
+    private ScheduleSubtaskBuilder scheduleSubtaskBuilder;
+
+    @Autowired
     private FtpService ftpService;
 
     @Autowired
@@ -146,6 +157,9 @@
 
     @Value("${ASRCallBackPath}")
     private String ASRCallBackPath;
+
+    @Autowired
+    private ISysConfigService configService;
 
     @Autowired
     private MtSubmitSmUtil mtSubmitSmUtil;
@@ -384,6 +398,17 @@
             }
         }
         serviceTaskVO.setPatTaskRelevances(patTaskRelevances);
+        if(StringUtils.isNotEmpty(serviceTaskVO.getAppltype()) && serviceTaskVO.getAppltype().equals("5")){
+            //浠诲姟缁勪俊鎭�
+            ServiceTaskSchedule schedule = serviceTaskScheduleService.selectByTaskid(serviceTaskVO.getTaskid());
+            if (ObjectUtils.isNotEmpty(schedule)) {
+                ServiceTaskScheduleVO serviceTaskScheduleVO = DtoConversionUtils.sourceToTarget(schedule, ServiceTaskScheduleVO.class);
+                List<ServiceTaskScheduleDetail> scheduleDetailList =
+                        serviceTaskScheduleService.selectDetailByScheduleid(schedule.getId());
+                serviceTaskScheduleVO.setDetailList(scheduleDetailList);
+                serviceTaskVO.setServiceTaskScheduleVO(serviceTaskScheduleVO);
+            }
+        }
         return serviceTaskVO;
     }
 
@@ -398,7 +423,16 @@
             if (serviceSubtaskEntity.getSendstateView() == 3)
                 serviceSubtaskEntity.setSendstates(new ArrayList<>(Arrays.asList(4L)));
         }
-
+        //鎮h�呰幏鍙栭殢璁夸换鍔�-闇�瑕佹煡璇㈠悓涓偅鑰咃紙韬唤璇侊級鎵�鏈夌殑浠诲姟 鏅畞
+        if (StringUtils.isNotEmpty(serviceSubtaskEntity.getOrgid()) && serviceSubtaskEntity.getOrgid().equals("47255004333112711A1001")) {
+            if(ObjectUtils.isNotEmpty(serviceSubtaskEntity.getPatid())){
+                PatArchive patArchive = patArchiveService.selectPatArchiveByPatid(serviceSubtaskEntity.getPatid());
+                if(ObjectUtils.isNotEmpty(patArchive) && StringUtils.isNotEmpty(patArchive.getIdcardno())){
+                    serviceSubtaskEntity.setPatid(null);
+                    serviceSubtaskEntity.setSfzh(patArchive.getIdcardno());
+                }
+            }
+        }
         List<ServiceSubtask> selectServiceSubtaskList = this.selectServiceSubtaskList(serviceSubtaskEntity);
 
         List<ServiceSubtaskRes> serviceSubtaskResList = new ArrayList<>();
@@ -579,9 +613,30 @@
      * @return 缁撴灉
      */
     @Override
-    public int insertServiceSubtask(ServiceSubtask serviceSubtask) {
+    public Map<String, Object> insertServiceSubtask(ServiceSubtask serviceSubtask) {
         serviceSubtask.setCreateTime(DateUtils.getNowDate());
-        return serviceSubtaskMapper.insertServiceSubtask(serviceSubtask);
+        serviceSubtaskMapper.insertServiceSubtask(serviceSubtask);
+        RSAPublicKeyExample rsaPublicKeyExample = new RSAPublicKeyExample();
+        String taskId = rsaPublicKeyExample.encryptedData(serviceSubtask.getTaskid().toString(), pub_key);
+        String patid = rsaPublicKeyExample.encryptedData(serviceSubtask.getPatid().toString(), pub_key);
+        String subId = rsaPublicKeyExample.encryptedData(serviceSubtask.getId().toString(), pub_key);
+        ServiceOutPath serviceOutPath = new ServiceOutPath();
+        serviceOutPath.setParam1(taskId);
+        serviceOutPath.setParam2(patid);
+        serviceOutPath.setCreateTime(new Date());
+        serviceOutPath.setParam6(subId);
+        serviceOutPath.setOrgid(serviceSubtask.getOrgid());
+        iServiceOutPathService.insertServiceOutPath(serviceOutPath);
+        //杞垚16杩涘埗
+        String format = String.format("%03X", serviceOutPath.getId());
+        serviceOutPath.setRadix(format);
+        serviceOutPath.setUpdateTime(new Date());
+        iServiceOutPathService.updateServiceOutPath(serviceOutPath);
+
+        Map<String, Object> result = new HashMap<>();
+        result.put("url", localIP + ":" + req_path + "/wt?p=" + format);
+        result.put("subId",serviceSubtask.getId());
+        return result;
     }
 
     /**
@@ -829,6 +884,59 @@
                             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 if (serviceTaskVO.getAppltype().equals("6")) {
+                    ServiceTaskmedical serviceTaskmedical = new ServiceTaskmedical();
+                    serviceTaskmedical.setTaskId(serviceTask.getTaskid());
+                    serviceTaskmedical.setTaskName(serviceTask.getTaskName());
+                    serviceTaskmedical.setServiceType(serviceTaskVO.getServiceType());
+                    serviceTaskmedical.setLongtask(Long.valueOf(serviceTask.getLongTask()));
+                    if (serviceTaskVO.getLongTask() == 1) serviceTaskmedical.setLongtask(1L);
+                    serviceTaskmedical.setMedicalCode(serviceTaskVO.getIcd10code());
+                    serviceTaskmedical.setMedicalName(serviceTaskVO.getIcd10name());
+                    serviceTaskmedical.setGuid(serviceTask.getGuid());
+                    serviceTaskmedical.setOrgid(serviceTask.getOrgid());
+                    serviceTaskmedical.setCreateTime(new Date());
+                    serviceTaskmedical.setDeptCode(serviceTaskVO.getDeptcode());
+                    serviceTaskmedical.setDeptName(serviceTaskVO.getDeptname());
+                    serviceTaskmedical.setWardCode(serviceTaskVO.getLeavehospitaldistrictcode());
+                    serviceTaskmedical.setWardName(serviceTaskVO.getLeavehospitaldistrictname());
+                    //鍗楀崕闄勪竴鐨刬cd10code鏄湁閲嶅鐨勶紝鎵�浠ヤ笉鑳界敤鍗楀崕闄勪竴鐨刬cd10code鍘绘煡璇�
+                    log.info("----serviceTaskmedical鐨勫�间负锛歿}", serviceTaskmedical);
+                    if (!StringUtils.isEmpty(serviceTaskVO.getMedicalName())) {
+                        String[] medicalNames = serviceTaskVO.getMedicalName().split(",");
+                        String[] medicalcodes = serviceTaskVO.getMedicalCode().split(",");
+                        String[] medicalCompanys = serviceTaskVO.getMedicalCompany().split(",");
+                        for (int i = 0; i < medicalNames.length; i++) {
+                            serviceTaskmedical.setMedicalCode(medicalNames[i]);
+                            serviceTaskmedical.setMedicalName(medicalcodes[i]);
+                            if (ObjectUtils.isNotEmpty(medicalCompanys))
+                                serviceTaskmedical.setMedicalCompany(medicalcodes[i]);
+                            serviceTaskmedicalService.insertServiceTaskmedical(serviceTaskmedical);
+                        }
+                    }
                 } else {
                     ServiceTaskdept serviceTaskdept = new ServiceTaskdept();
                     serviceTaskdept.setTaskId(serviceTask.getTaskid());
@@ -914,6 +1022,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();
 
@@ -1088,6 +1210,51 @@
                         }
                     }
 
+                } else if (serviceTaskVO.getAppltype().equals("6")) {
+                    ServiceTaskmedical serviceTaskmedical = new ServiceTaskmedical();
+                    serviceTaskmedical.setTaskId(serviceTask.getTaskid());
+                    serviceTaskmedical.setTaskName(serviceTask.getTaskName());
+                    if (StringUtils.isEmpty(serviceTaskVO.getIcd10code())) {
+                        throw new BaseException("鑽搧缂栫爜涓虹┖");
+                    }
+                    serviceTaskmedical.setLongtask(Long.valueOf(serviceTask.getLongTask()));
+                    serviceTaskmedical.setMedicalName(serviceTaskVO.getMedicalName());
+                    serviceTaskmedical.setGuid(serviceTask1.getGuid());
+                    serviceTaskmedical.setServiceType(serviceTask1.getServiceType());
+                    serviceTaskmedical.setOrgid(serviceTask1.getOrgid());
+                    serviceTaskmedical.setDeptCode(serviceTask1.getDeptcode());
+                    serviceTaskmedical.setDeptName(serviceTask1.getDeptname());
+                    serviceTaskmedical.setWardCode(serviceTask1.getLeavehospitaldistrictcode());
+                    serviceTaskmedical.setWardName(serviceTask1.getLeavehospitaldistrictname());
+                    serviceTaskmedical.setUpdateTime(new Date());
+                    if (StringUtils.isNotEmpty(serviceTaskVO.getMedicalCode())) {
+                        String[] medicalCodes = serviceTaskVO.getMedicalCode().split(",");
+                        String[] medicalNames = serviceTaskVO.getMedicalName().split(",");
+                        String[] medicalCompany = serviceTaskVO.getMedicalCompany().split(",");
+                        if (!active.equals("nhfy") && !active.equals("druid")) {
+                            if (medicalCodes.length != medicalNames.length) {
+                                throw new BaseException("鑽搧缂栫爜鍜岃嵂鍝佸悕绉版暟閲忎笉涓�鑷�");
+                            }
+                        }
+                        for (int i = 0; i < medicalCodes.length; i++) {
+                            //鍏堟煡璇竴涓嬫槸鍚﹀瓨鍦�
+                            ServiceTaskmedical serviceTaskmedical1 = new ServiceTaskmedical();
+                            serviceTaskmedical1.setTaskId(serviceTaskVO.getTaskid());
+                            serviceTaskmedical1.setMedicalCode(medicalCodes[i]);
+                            serviceTaskmedical1.setMedicalName(medicalNames[i]);
+                            List<ServiceTaskmedical> serviceTaskmedicals = serviceTaskmedicalService.selectServiceTaskmedicalList(serviceTaskmedical1);
+                            serviceTaskmedical.setMedicalCode(medicalCodes[i]);
+                            serviceTaskmedical.setMedicalName(medicalNames[i]);
+                            log.info("----serviceTaskmedical鏇存柊鐨勫�间负锛歿}", serviceTaskmedical);
+                            if (CollectionUtils.isNotEmpty(serviceTaskmedicals)) {
+                                serviceTaskmedical.setId(serviceTaskmedicals.get(0).getId());
+                                serviceTaskmedicalService.updateServiceTaskmedical(serviceTaskmedical);
+                            } else {
+                                serviceTaskmedicalService.insertServiceTaskmedical(serviceTaskmedical);
+                            }
+                        }
+                    }
+
                 } else if (serviceTaskVO.getAppltype().equals("4")) {
                     ServiceTaskoper serviceTaskoper = new ServiceTaskoper();
 //                    if (StringUtils.isEmpty(serviceTaskVO.getOpcode())) {
@@ -1128,6 +1295,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 +1366,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 +1432,6 @@
         map.put("taskId", serviceTask.getTaskid().intValue());
         return map;
     }
-
 
     @Override
     public void phoneCallBack(PhoneCallBackVO phoneCallBackVO) {
@@ -1734,21 +1932,17 @@
             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")) {
-//                PhoneCallBackYQVO aiMatchResult = AiMatch(phoneCallReqYQVO, phoneCallBackYQVO,
-//                        ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate,
-//                        ivrTaskTemplateScripts, scriptId, flag);
-//                if(aiMatchResult != null){
-//                    return aiMatchResult;
-//                }
-//            } else {
+                //1-AI璇嗗埆
+                String url = configService.selectConfigByKey("sys.voice.match.ai.url",phoneCallReqYQVO.getOrgid());
+
+            if (ObjectUtils.isNotEmpty(url)) {
+                PhoneCallBackYQVO aiMatchResult = AiMatch(url, phoneCallReqYQVO, phoneCallBackYQVO,
+                        ivrTaskTemplateScriptVO, serviceSubtask, ivrTaskTemplate,
+                        ivrTaskTemplateScripts, scriptId, flag, phoneCallReqYQVO.getUuid());
+                if(aiMatchResult != null){
+                    return aiMatchResult;
+                }
+            } else {
                 //鏄�夋嫨棰�
                 for (int j = 0; j < ivrTaskTemplateScriptVO.getIvrTaskScriptTargetoptionList().size(); j++) {
                     log.error("phoneCallReqYQVO.getAsrtext()鐨勫�间负锛歿}", phoneCallReqYQVO.getAsrtext());
@@ -1990,7 +2184,7 @@
                         continue;
                     }
                 }
-//            }
+            }
                 //閮芥病鏈夊尮閰嶅埌
                 if (StringUtils.isEmpty(phoneCallBackYQVO.getValue())) {
                     log.info("閮芥病鏈夊尮閰嶅埌-------------------------");
@@ -2612,16 +2806,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";
             }
@@ -2634,11 +2833,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")));
@@ -4976,34 +5178,45 @@
      * @param options
      * @return
      */
-    public String matchOptionIndex(String questionText, String voiceText, List<IvrTaskTemplateTargetoption> options) {
+    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);
         jsonObject.put("options", options);
+        jsonObject.put("uuid", uuid);
         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";
+        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,
+    public PhoneCallBackYQVO AiMatch(String url, PhoneCallReqYQVO phoneCallReqYQVO, PhoneCallBackYQVO phoneCallBackYQVO,
                         IvrTaskTemplateScriptVO ivrTaskTemplateScriptVO, ServiceSubtask serviceSubtask, IvrTaskTemplate ivrTaskTemplate,
-                        List<IvrTaskTemplateScript> ivrTaskTemplateScripts, String scriptId, Integer flag){
+                        List<IvrTaskTemplateScript> ivrTaskTemplateScripts, String scriptId, Integer flag, String uuid){
         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(url, questionText, voiceText, options, uuid);
         //璇存槑鍖归厤姝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 +5438,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 +5449,14 @@
         IvrTaskTemplateTargetoption ivrTaskTemplateTargetoption3 = new IvrTaskTemplateTargetoption();
         ivrTaskTemplateTargetoption3.setTargetvalue("鍏朵粬");
         options.add(ivrTaskTemplateTargetoption3);
-        matchOptionIndex(questionText,voiceText,options);
+        //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();
+            }
+        }
+        log.info("ai鍖归厤鎴愬姛锛屽尮閰嶇粨鏋滄槸:" + matchedText);
     }
 }

--
Gitblit v1.9.3