From d047a35e640a59e02a422d9a9a62c752c88b69b5 Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期三, 28 十月 2026 15:51:52 +0800
Subject: [PATCH] 【丽水】 同一 inhospid + taskid 已存在未删除的首次随访(upid 为空)时,不再插入,避免出现两条首次随访

---
 smartor/src/main/java/com/smartor/service/impl/PatMedInhospServiceImpl.java   |   23 +++++++++++++++++++++++
 smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java |    2 ++
 smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml            |    1 +
 3 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/smartor/src/main/java/com/smartor/service/impl/PatMedInhospServiceImpl.java b/smartor/src/main/java/com/smartor/service/impl/PatMedInhospServiceImpl.java
index 9160c37..e1ba487 100644
--- a/smartor/src/main/java/com/smartor/service/impl/PatMedInhospServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/PatMedInhospServiceImpl.java
@@ -708,6 +708,29 @@
         //璁板綍insertServiceSubtask璇彞杩斿洖鐘舵��
         Integer i = 0;
         try {
+            // 鍏滃簳锛氫换鍔℃ā鏉夸慨鏀逛細閲嶇疆 pat_med_inhosp 鐨勫鐞嗘爣璁帮紝浣嗗凡瀹屾垚鐨勯璁夸笉浼氬垹闄ゃ��
+            // 鍚屼竴 inhospid + taskid 宸插瓨鍦ㄦ湭鍒犻櫎鐨勯娆¢殢璁匡紙upid 涓虹┖锛夋椂锛屼笉鍐嶆彃鍏ワ紝閬垮厤鍑虹幇涓ゆ潯棣栨闅忚銆�
+            if (check
+                    && ("2".equals(serviceTask.getServiceType()) || "13".equals(serviceTask.getServiceType()))
+                    && (type == 1 || type == 2 || type == 3)) {
+                ServiceSubtaskEntity firstQuery = new ServiceSubtaskEntity();
+                firstQuery.setInhospid(patMedInhosp1.getInhospid());
+                firstQuery.setTaskid(taskid);
+                List<ServiceSubtask> firstList = serviceSubtaskMapper.selectServiceSubtaskList(firstQuery);
+                boolean firstExists = CollectionUtils.isNotEmpty(firstList)
+                        && firstList.stream().anyMatch(item -> item.getUpid() == null);
+                if (firstExists) {
+                    log.info("鎮h�厈}宸插瓨鍦ㄩ娆¢殢璁夸换鍔★紝璺宠繃閲嶅鐢熸垚, taskid={}, type={}",
+                            patMedInhosp1.getInhospid(), taskid, type);
+                    PatMedInhosp flagUpdate = new PatMedInhosp();
+                    flagUpdate.setInhospid(patMedInhosp1.getInhospid());
+                    if (type == 1) flagUpdate.setDeptcheckFlag("1");
+                    if (type == 2) flagUpdate.setWardcheckFlag("1");
+                    if (type == 3) flagUpdate.setDiagcheckFlag("1");
+                    patMedInhospMapper.updatePatMedInhosp(flagUpdate);
+                    return;
+                }
+            }
             //鍏堝垽鏂竴涓嬶紝鏄惁闇�瑕佹牎楠�
             if (check && (Objects.isNull(serviceSubtask.getTaskSituation()) || serviceSubtask.getTaskSituation() != 6)) {
                 //鍦ㄦ柊澧炰箣鍓嶏紝鍏堥�氳繃鎮h�匢D锛宻endstate=2鏌ヨ涓�涓嬶紝鍦ㄦ墍鏈夐暱鏈熶换鍔′腑锛屾槸涓嶆槸杩樻湁璇ユ偅鑰呭緟鎵ц鐨勪换鍔★紝鏈夌殑璇�,姣旇緝涔嬪墠鐨別ndtime鏄惁灏忎簬褰撳墠鐨別ndtaime,濡傛灉涔嬪墠鐨勫皬浜庣幇鍦ㄧ殑锛屽垯鐩存帴灏嗕箣鍓嶇殑鍋滄帀锛堝師鍥犲啀鍏ラ櫌锛�
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 954734b..b0f5b1f 100644
--- a/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/ServiceSubtaskServiceImpl.java
@@ -1630,6 +1630,8 @@
             ServiceTask serviceTask1 = serviceTaskService.selectServiceTaskByTaskid(serviceTask.getTaskid());
             ServiceSubtaskEntity serviceSubtaskVO = new ServiceSubtaskEntity();
             serviceSubtaskVO.setTaskid(serviceTask1.getTaskid());
+            //鍙垹闄ら娆¢殢璁挎湭瀹屾垚鐨�
+            serviceSubtaskVO.setVisitCount(1);
             serviceSubtaskVO.setSendstate(2L);
             List<ServiceSubtask> serviceSubtaskList = serviceSubtaskMapper.selectServiceSubtaskList(serviceSubtaskVO);
             serviceSubtaskVO.setSendstate(1L);
diff --git a/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml b/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
index e1f7071..2de4dec 100644
--- a/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
+++ b/smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
@@ -405,6 +405,7 @@
         <if test="managementDoctorCode != null ">and management_doctor_code = #{managementDoctorCode}</if>
         <if test="submit != null ">and submit = #{submit}</if>
         <if test="upid != null ">and upid = #{upid}</if>
+        <if test="visitCount != null ">and visit_count = #{visitCount}</if>
         <if test="patfrom != null ">and patfrom = #{patfrom}</if>
         <if test="serviceType != null ">and service_type = #{serviceType}</if>
         <if test="patid != null ">and patid = #{patid}</if>

--
Gitblit v1.9.3