From 43e807c405e8cf5b725d1ced5490128da191eb98 Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期五, 30 十月 2026 11:34:38 +0800
Subject: [PATCH] 【丽水】/smartor/patinhosp/addManualVisit 人工处理,接口完成删除未完成的任务,再次生成随访任务
---
smartor/src/main/java/com/smartor/service/impl/PatMedInhospServiceImpl.java | 141 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 141 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..c6db543 100644
--- a/smartor/src/main/java/com/smartor/service/impl/PatMedInhospServiceImpl.java
+++ b/smartor/src/main/java/com/smartor/service/impl/PatMedInhospServiceImpl.java
@@ -5,12 +5,14 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.service.IConfigService;
+import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.DtoConversionUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.smartor.common.ScheduleSubtaskBuilder;
import com.smartor.domain.*;
+import com.smartor.domain.DTO.ManualVisitDTO;
import com.smartor.domain.DTO.PatMedInhospDTO;
import com.smartor.domain.entity.ServiceSubtaskEntity;
import com.smartor.mapper.*;
@@ -20,6 +22,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import java.io.IOException;
@@ -708,6 +711,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,濡傛灉涔嬪墠鐨勫皬浜庣幇鍦ㄧ殑锛屽垯鐩存帴灏嗕箣鍓嶇殑鍋滄帀锛堝師鍥犲啀鍏ラ櫌锛�
@@ -1981,4 +2007,119 @@
}
}
+ /**
+ * 浜哄伐闅忚锛氬垹闄ゆ偅鑰呭嚭闄㈣褰曞搴旂殑鏈畬鎴愰殢璁夸换鍔★紝骞舵寜鎸囧畾浠诲姟閲嶆柊鐢熸垚銆�
+ * 鏈畬鎴愮姸鎬佸彛寰勶細sendstate in (1,2,3,7)銆�
+ */
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public Map<String, Object> addManualVisit(ManualVisitDTO manualVisitDTO) {
+ if (manualVisitDTO == null) {
+ throw new BaseException("鍏ュ弬涓嶈兘涓虹┖");
+ }
+ if (CollectionUtils.isEmpty(manualVisitDTO.getPatids())) {
+ throw new BaseException("鎮h�卲atid闆嗗悎涓嶈兘涓虹┖");
+ }
+ if (manualVisitDTO.getTaskid() == null) {
+ throw new BaseException("浜哄伐闅忚浠诲姟taskid涓嶈兘涓虹┖");
+ }
+
+ ServiceTask serviceTask = serviceTaskMapper.selectServiceTaskByTaskid(manualVisitDTO.getTaskid());
+ if (Objects.isNull(serviceTask)) {
+ throw new BaseException("浜哄伐闅忚浠诲姟涓嶅瓨鍦紝taskid锛�" + manualVisitDTO.getTaskid());
+ }
+
+ LinkedHashSet<Long> patids = manualVisitDTO.getPatids().stream()
+ .filter(Objects::nonNull)
+ .collect(Collectors.toCollection(LinkedHashSet::new));
+ if (patids.isEmpty()) {
+ throw new BaseException("鎮h�卲atid闆嗗悎涓嶈兘涓虹┖");
+ }
+
+ String config = iSysConfigService.selectConfigByKey("visit.early.day");
+ List<Long> unfinishedSendstates = Arrays.asList(1L, 2L, 3L, 7L);
+ int deletedCount = 0;
+ int generatedCount = 0;
+ List<Long> noDischargeRecordPatids = new ArrayList<>();
+ List<Long> noArchivePatids = new ArrayList<>();
+ List<Long> generateFailedPatids = new ArrayList<>();
+
+ for (Long patid : patids) {
+ // 鏌ヨ鎮h�呭叏閮ㄥ嚭闄㈣褰曪紝SQL 鎸夊嚭闄㈡椂闂村�掑簭锛岀涓�鏉′綔涓烘湰娆$敓鎴愪换鍔$殑鍑洪櫌璁板綍
+ PatMedInhosp query = new PatMedInhosp();
+ query.setPatid(patid);
+ query.setCry(1);
+ if (StringUtils.isNotEmpty(serviceTask.getOrgid())) {
+ query.setOrgid(serviceTask.getOrgid());
+ }
+ List<PatMedInhosp> inhospList = patMedInhospMapper.selectPatMedInhospList(query);
+ if (CollectionUtils.isEmpty(inhospList)) {
+ noDischargeRecordPatids.add(patid);
+ continue;
+ }
+
+ PatMedInhosp latestInhosp = inhospList.get(0);
+ if (Objects.isNull(latestInhosp.getEndtime())) {
+ noDischargeRecordPatids.add(patid);
+ continue;
+ }
+
+ PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(patid);
+ if (Objects.isNull(patArchive)) {
+ noArchivePatids.add(patid);
+ continue;
+ }
+
+ // 鍏堟瀯寤烘柊浠诲姟锛屾瀯寤哄け璐ユ椂涓嶅垹闄ゅ師浠诲姟锛岄伩鍏嶆偅鑰呬涪澶卞緟闅忚浠诲姟
+ ServiceSubtask serviceSubtask = boxedServiceSubtask(serviceTask, latestInhosp, patArchive, config, 1);
+ if (Objects.isNull(serviceSubtask) || Objects.isNull(serviceSubtask.getTaskid())) {
+ generateFailedPatids.add(patid);
+ continue;
+ }
+
+ List<Long> inhospids = inhospList.stream()
+ .map(PatMedInhosp::getInhospid)
+ .filter(Objects::nonNull)
+ .distinct()
+ .collect(Collectors.toList());
+ if (CollectionUtils.isNotEmpty(inhospids)) {
+ deletedCount += serviceSubtaskMapper.deleteUnfinishedServiceSubtaskByInhospids(
+ patid, inhospids, unfinishedSendstates);
+ }
+
+ serviceSubtask.setId(null);
+ serviceSubtask.setUpid(null);
+ serviceSubtask.setVisitDeptCode(StringUtils.isNotEmpty(latestInhosp.getLeaveldeptcode())
+ ? latestInhosp.getLeaveldeptcode() : latestInhosp.getLeavehospitaldistrictcode());
+ serviceSubtask.setVisitDeptName(StringUtils.isNotEmpty(latestInhosp.getLeaveldeptname())
+ ? latestInhosp.getLeaveldeptname() : latestInhosp.getLeavehospitaldistrictname());
+ // 涓庡父瑙勭敓鎴愰�昏緫淇濇寔涓�鑷达細鎵嬫満鍙蜂负绌烘椂鐢熸垚浠诲姟浣嗕笉鎵ц
+ if (StringUtils.isEmpty(serviceSubtask.getPhone())) {
+ serviceSubtask.setRemark(StringUtils.isNotEmpty(serviceSubtask.getRemark())
+ ? serviceSubtask.getRemark() + ",鎵嬫満鍙蜂负绌�" : "鎵嬫満鍙蜂负绌�");
+ serviceSubtask.setSendstate(4L);
+ serviceSubtask.setResult("error");
+ }
+
+ int inserted = serviceSubtaskMapper.insertServiceSubtask(serviceSubtask);
+ if (inserted != 1) {
+ throw new BaseException("鐢熸垚闅忚浠诲姟澶辫触锛宲atid锛�" + patid + "锛宼askid锛�" + serviceTask.getTaskid());
+ }
+ addServiceSubtaskPreachform(serviceSubtask, null);
+ generatedCount++;
+ log.info("addManualVisit 鐢熸垚闅忚浠诲姟鎴愬姛锛宲atid锛歿}锛宼askid锛歿}锛宻ubtaskId锛歿}",
+ patid, serviceTask.getTaskid(), serviceSubtask.getId());
+ }
+
+ Map<String, Object> result = new HashMap<>();
+ result.put("deletedCount", deletedCount);
+ result.put("generatedCount", generatedCount);
+ result.put("noDischargeRecordPatids", noDischargeRecordPatids);
+ result.put("noArchivePatids", noArchivePatids);
+ result.put("generateFailedPatids", generateFailedPatids);
+ log.info("addManualVisit 澶勭悊瀹屾垚锛宲atid鏁帮細{}锛宼askid锛歿}锛屽垹闄ゆ湭瀹屾垚浠诲姟鏁帮細{}锛岀敓鎴愪换鍔℃暟锛歿}",
+ patids.size(), serviceTask.getTaskid(), deletedCount, generatedCount);
+ return result;
+ }
+
}
--
Gitblit v1.9.3