From c24d16a37523a49080392610357872ce580cbc38 Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期一, 26 十月 2026 14:03:33 +0800
Subject: [PATCH] 代码提交

---
 smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskAnswerServiceImpl.java |  106 ++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 89 insertions(+), 17 deletions(-)

diff --git a/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskAnswerServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskAnswerServiceImpl.java
index ec3e1c4..19130e6 100644
--- a/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskAnswerServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskAnswerServiceImpl.java
@@ -11,9 +11,7 @@
 import com.ruoyi.common.utils.RSAPublicKeyExample;
 import com.ruoyi.common.utils.StringUtils;
 import com.smartor.domain.*;
-import com.smartor.domain.DTO.ServiceSubtaskDetailDTO;
-import com.smartor.domain.VO.ServiceSubtaskDetailTraceVO;
-import com.smartor.domain.entity.ServiceSubtaskEntity;
+import com.ruoyi.task.domain.VO.ServiceSubtaskDetailTraceVO;
 import com.smartor.mapper.*;
 import com.smartor.service.*;
 import lombok.extern.slf4j.Slf4j;
@@ -29,6 +27,42 @@
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
+import com.ruoyi.template.domain.HeLibrary;
+import com.ruoyi.template.domain.IvrLibaScriptAssort;
+import com.ruoyi.inhospvisit.domain.PatMedInhosp;
+import com.ruoyi.outpatientvisit.domain.PatMedOuthosp;
+import com.ruoyi.outpatientvisit.domain.PatMedOuthospQueryReq;
+import com.ruoyi.inhospvisit.api.InhospVisitFacade;
+import com.ruoyi.outpatientvisit.api.OuthospDataFacade;
+import com.ruoyi.template.domain.IvrTaskTemplate;
+import com.ruoyi.template.domain.IvrTaskTemplateScriptVO;
+import com.ruoyi.template.domain.IvrTaskTemplateTargetoption;
+import com.ruoyi.template.service.IIvrTaskTemplateService;
+import com.ruoyi.template.domain.IvrLibaTemplateScript;
+import com.ruoyi.template.mapper.IvrLibaScriptAssortMapper;
+import com.ruoyi.template.service.IIvrLibaTemplateScriptService;
+import com.ruoyi.template.domain.SvyLibScriptCategory;
+import com.ruoyi.template.domain.SvyLibTemplateScript;
+import com.ruoyi.template.domain.SvyTaskTemplate;
+import com.ruoyi.template.domain.SvyTaskTemplateScriptVO;
+import com.ruoyi.template.domain.SvyTaskTemplateTargetoption;
+import com.ruoyi.template.mapper.SvyLibScriptCategoryMapper;
+import com.ruoyi.template.service.ISvyTaskTemplateService;
+import com.ruoyi.common.core.domain.entity.PatArchive;
+import com.ruoyi.task.domain.DTO.ServiceSubtaskDetailDTO;
+import com.ruoyi.task.domain.entity.ServiceSubtaskEntity;
+import com.ruoyi.task.domain.ServiceSubtask;
+import com.ruoyi.task.domain.ServiceSubtaskDetail;
+import com.ruoyi.task.domain.ServiceSubtaskDetailVO;
+import com.ruoyi.task.domain.ServiceTask;
+import com.ruoyi.task.domain.TaskSendTimeVO;
+import com.ruoyi.task.mapper.ServiceSubtaskDetailMapper;
+import com.ruoyi.task.mapper.ServiceSubtaskMapper;
+import com.ruoyi.task.domain.ServiceSubtaskDetailTrace;
+import com.ruoyi.task.domain.VO.ServiceSubtaskDetailTraceVO;
+import com.ruoyi.task.service.IServiceSubtaskDetailTraceService;
+import com.ruoyi.task.domain.ServiceSubtaskPreachform;
+import com.ruoyi.task.service.IServiceTaskService;
 /**
  * 浠诲姟闂嵎闂閫夐」Service涓氬姟灞傚鐞�
  *
@@ -40,6 +74,18 @@
 public class ServiceSubtaskAnswerServiceImpl implements IServiceSubtaskAnswerService {
     @Autowired
     private ServiceSubtaskAnswerMapper serviceSubtaskAnswerMapper;
+
+    /**
+     * 璺ㄦā鍧楄闂竴寰嬬粡妯″潡闂ㄩ潰锛堢姝㈢洿杩炲凡鎼蛋鐨� Mapper锛夈��
+     */
+    @Autowired
+    private OuthospDataFacade outhospDataFacade;
+
+    /**
+     * 璺ㄦā鍧楄闂竴寰嬬粡妯″潡闂ㄩ潰锛堢姝㈢洿杩炲凡鎼蛋鐨� Mapper锛夈��
+     */
+    @Autowired
+    private InhospVisitFacade inhospVisitFacade;
 
     @Autowired
     private ServiceSubtaskMapper serviceSubtaskMapper;
@@ -66,11 +112,7 @@
     private PatArchiveMapper patArchiveMapper;
 
 
-    @Autowired
-    private PatMedInhospMapper patMedInhospMapper;
 
-    @Autowired
-    private PatMedOuthospMapper patMedOuthospMapper;
 
     @Autowired
     private IServiceSubtaskDetailTraceService traceService;
@@ -81,8 +123,6 @@
     @Autowired
     private ISvyLibTemplateScriptService svyLibTemplateScriptService;
 
-    @Autowired
-    private ISvyTaskTemplateTargetoptionService svyTaskTemplateTargetoptionService;
 
     @Autowired
     private IIvrTaskTemplateService ivrTaskTemplateService;
@@ -236,6 +276,8 @@
     public Integer saveQuestionAnswer(ServiceSubTaskAnswerReq serviceSubTaskAnswerReq, Long flag) {
         String threadName = Thread.currentThread().getName();
         log.info("[{}] 寮�濮嬪紓姝ュ鐞嗕繚瀛橀棶鍗风瓟妗�", threadName);
+        // 骞傜瓑鍗犱綅閿細澶辫触鏃惰閲婃斁锛屽厑璁告偅鑰呴噸璇�
+        String idemKey = null;
         try {
             //鍙傛暟瑙e瘑
             Long tid = null;
@@ -259,6 +301,17 @@
             //鏍规嵁 PID銆乀ID銆丼UBID 鏋勫缓闇�瑕佸鐞嗙殑 cache key
             String scriptCacheKeyPrefix = pid + "-" + tid + "-" + subid;
             Set<String> targetKeys = new HashSet<>();
+
+            // ---------------- 骞傜瓑锛氬悓涓�浠介棶鍗� 60 绉掑唴鍙鐞嗕竴娆� ----------------
+            // 鏈柟娉曟槸 @Async 寮傛鎵ц锛屾偅鑰呯閲嶅鐐瑰嚮/缃戠粶閲嶈瘯浼氳瀹冨苟鍙戣窇澶氭锛�
+            // 姣忔閮戒細 upsert 涓�閬嶆槑缁嗭紱骞跺彂鏃跺郊姝ょ湅涓嶅埌瀵规柟杩樻病鎻愪氦鐨勮 -> 鎻掑叆閲嶅鍓湰
+            // 锛坣hfy 2026-09-08 灏辨槸杩欐牱鍫嗗嚭 2~6 浠斤紝骞朵笖鎶� del_flag 涓�璧峰啓鍧忥級銆�
+            idemKey = "subtaskAnswer:submit:" + scriptCacheKeyPrefix + ":"
+                    + (serviceSubTaskAnswerReq == null || serviceSubTaskAnswerReq.getType() == null ? "all" : serviceSubTaskAnswerReq.getType());
+            if (!redisCache.setCacheObjectIfAbsent(idemKey, "1", 60, TimeUnit.SECONDS)) {
+                log.warn("[{}] 妫�娴嬪埌閲嶅鎻愪氦锛屾湰娆″拷鐣ワ細{}", threadName, idemKey);
+                return 0;
+            }
 
             if (serviceSubTaskAnswerReq != null && serviceSubTaskAnswerReq.getType() != null) {
                 if (serviceSubTaskAnswerReq.getType() == 2) {
@@ -451,6 +504,14 @@
             return 1;
         } catch (Exception e) {
             log.error("[{}] 寮傛澶勭悊淇濆瓨闂嵎绛旀鍙戠敓寮傚父 : {},璇锋眰鐨勫璞′负锛歿}", Thread.currentThread().getName(), e.getMessage(), e, serviceSubTaskAnswerReq);
+            // 澶勭悊澶辫触鏃堕噴鏀惧箓绛夐敭锛屽厑璁告偅鑰呴噸鏂版彁浜�
+            if (idemKey != null) {
+                try {
+                    redisCache.deleteObject(idemKey);
+                } catch (Exception ignore) {
+                    log.warn("[{}] 閲婃斁骞傜瓑閿け璐ワ細{}", Thread.currentThread().getName(), idemKey);
+                }
+            }
             throw new RuntimeException("淇濆瓨闂嵎绛旀澶辫触", e);
         }
     }
@@ -613,13 +674,13 @@
             //浣忛櫌
             PatMedInhosp patMedInhosp = new PatMedInhosp();
             patMedInhosp.setSerialnum(serviceSubTaskMYDAnswerReq.getSerialnum());
-            patMedInhospList = patMedInhospMapper.selectPatMedInhospList(patMedInhosp);
+            patMedInhospList = inhospVisitFacade.selectPatMedInhospList(patMedInhosp);
             if (CollectionUtils.isNotEmpty(patMedInhospList)) patid = patMedInhospList.get(0).getPatid();
         } else if (serviceSubTaskMYDAnswerReq.getMzzy().equals("2")) {
             //闂ㄨ瘖
             PatMedOuthospQueryReq patMedOuthosp = new PatMedOuthospQueryReq();
             patMedOuthosp.setSerialnum(serviceSubTaskMYDAnswerReq.getSerialnum());
-            patMedOuthosps = patMedOuthospMapper.callSpQueryOuthosp(patMedOuthosp);
+            patMedOuthosps = outhospDataFacade.callSpQueryOuthosp(patMedOuthosp);
             if (CollectionUtils.isNotEmpty(patMedOuthosps)) patid = patMedOuthosps.get(0).getPatid();
         } else if (serviceSubTaskMYDAnswerReq.getMzzy().equals("3")) {
             //鎸囧畾涓�涓儴闂紝鐢ㄦ潵澶勭悊鎶曡瘔寤鸿
@@ -688,8 +749,8 @@
                 serviceSubtask.setLibtemplateid(Long.valueOf(serviceTask.getLibtemplateid()));
                 if (CollectionUtils.isNotEmpty(patMedInhospList)) {
                     serviceSubtask.setHospType("2");
-                    serviceSubtask.setDeptname(patMedInhospList.get(0).getDeptname());
-                    serviceSubtask.setDeptcode(patMedInhospList.get(0).getDeptcode());
+                    serviceSubtask.setLeaveldeptname(patMedInhospList.get(0).getDeptname());
+                    serviceSubtask.setLeaveldeptcode(patMedInhospList.get(0).getDeptcode());
                     serviceSubtask.setLeavehospitaldistrictcode(patMedInhospList.get(0).getLeavehospitaldistrictcode());
                     serviceSubtask.setLeavehospitaldistrictname(patMedInhospList.get(0).getLeavehospitaldistrictname());
                     serviceSubtask.setDrname(patMedInhospList.get(0).getDrname());
@@ -703,8 +764,8 @@
                     serviceSubtask.setHospType("1");
                     serviceSubtask.setAdmindate(patMedOuthosps.get(0).getAdmitdate());
                     serviceSubtask.setHospno(patMedOuthosps.get(0).getOuthospno());
-                    serviceSubtask.setDeptname(patMedOuthosps.get(0).getDeptname());
-                    serviceSubtask.setDeptcode(patMedOuthosps.get(0).getDeptcode());
+                    serviceSubtask.setLeaveldeptname(patMedOuthosps.get(0).getDeptname());
+                    serviceSubtask.setLeaveldeptcode(patMedOuthosps.get(0).getDeptcode());
                     serviceSubtask.setDrname(patMedOuthosps.get(0).getDrname());
                     serviceSubtask.setDrcode(patMedOuthosps.get(0).getDrcode());
                     serviceSubtask.setCampusid(patMedOuthosps.get(0).getCampusid());
@@ -726,7 +787,7 @@
                 }
                 if (StringUtils.isNotEmpty(dealDept)) {
                     //鎶曡瘔寤鸿鐨勫鐞嗛儴闂�
-                    serviceSubtask.setDeptcode(dealDept);
+                    serviceSubtask.setLeaveldeptcode(dealDept);
                     serviceSubtask.setServiceType("15");
                 }
                 serviceSubtask.setSubmit(1L);
@@ -985,6 +1046,11 @@
 
     /**
      * 鎵归噺鏌ヨ宸插瓨鍦ㄧ殑鏄庣粏璁板綍ID锛屾寜scriptid鍒嗙粍锛堥伩鍏嶅惊鐜腑閫愭潯鏌ヨ锛�
+     * <p>
+     * 鈿狅笍 2026-10-21锛�<b>涓嶅啀杩囨护 del_flag</b>锛屽悓涓� scriptid 鍙� id 鏈�澶э紙鏈�鏂帮級鐨勯偅涓�琛屻��
+     * 鍘熸潵鍙 del_flag=0锛屾槑缁嗚閫昏緫鍒犻櫎鍚庡氨鏌ヤ笉鍒� 鈫� 涓嬩竴娆′繚瀛樺繀鐒� INSERT 鏂板壇鏈紝
+     * 鍚屼竴鎮h�呭悓涓�棰樹細鍫嗗嚭 2~6 鏉¢噸澶嶆槑缁嗭紙nhfy 2026-09-08锛夈��
+     * 鍛戒腑琚垹鍓湰鏃剁敱璋冪敤鏂瑰啀璋� {@code reviveServiceSubtaskDetail} 缃洖 '0'銆�
      */
     private Map<Long, Long> getExistingDetailIdMap(Long subid) {
         if (subid == null) return Collections.emptyMap();
@@ -994,7 +1060,9 @@
         if (CollectionUtils.isEmpty(details)) return Collections.emptyMap();
         Map<Long, Long> map = new HashMap<>();
         for (ServiceSubtaskDetail d : details) {
-            if ((d.getDelFlag() == null || "0".equals(d.getDelFlag())) && d.getScriptid() != null && !map.containsKey(d.getScriptid())) {
+            if (d.getScriptid() == null || d.getId() == null) continue;
+            Long existId = map.get(d.getScriptid());
+            if (existId == null || d.getId() > existId) {
                 map.put(d.getScriptid(), d.getId());
             }
         }
@@ -1091,6 +1159,8 @@
             serviceSubtaskDetail.setId(existDetailId);
             serviceSubtaskDetail.setUpdateTime(new Date());
             serviceSubtaskDetailMapper.updateServiceSubtaskDetail(serviceSubtaskDetail);
+            //鍛戒腑鍘嗗彶琚�昏緫鍒犻櫎鐨勫壇鏈椂缃洖 del_flag='0'锛堝惁鍒欑瓟妗堝啓杩涘幓浜嗗嵈鏌ヤ笉鍒帮紝涓斾笅娆″張浼氭柊澧炲壇鏈級
+            serviceSubtaskDetailMapper.reviveServiceSubtaskDetail(existDetailId);
         } else {
             serviceSubtaskDetailMapper.insertServiceSubtaskDetail(serviceSubtaskDetail);
         }
@@ -1390,6 +1460,8 @@
             serviceSubtaskDetail.setId(existServiceSubtaskDetail.getId());
             serviceSubtaskDetail.setUpdateTime(new Date());
             serviceSubtaskDetailMapper.updateServiceSubtaskDetail(serviceSubtaskDetail);
+            //鍛戒腑鍘嗗彶琚�昏緫鍒犻櫎鐨勫壇鏈椂缃洖 del_flag='0'锛岄伩鍏嶉噸澶嶅壇鏈�
+            serviceSubtaskDetailMapper.reviveServiceSubtaskDetail(existServiceSubtaskDetail.getId());
         } else {
             serviceSubtaskDetailMapper.insertServiceSubtaskDetail(serviceSubtaskDetail);
         }

--
Gitblit v1.9.3