From 357100150bd0ba266d78d8d0f3b02c37b22435d8 Mon Sep 17 00:00:00 2001
From: 陈昶聿 <chychen@nbjetron.com>
Date: 星期一, 02 十一月 2026 10:17:19 +0800
Subject: [PATCH] 【丽水】1、指标查询与随访统计条件不同问题 2、微信发送重复问题
---
smartor/src/main/java/com/smartor/service/impl/PatMedInhospServiceImpl.java | 210 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 210 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 d30b56e..8cf5d67 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,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Isolation;
+import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import java.io.IOException;
@@ -708,6 +712,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,濡傛灉涔嬪墠鐨勫皬浜庣幇鍦ㄧ殑锛屽垯鐩存帴灏嗕箣鍓嶇殑鍋滄帀锛堝師鍥犲啀鍏ラ櫌锛�
@@ -1955,5 +1982,188 @@
return generatedCount;
}
+ @Override
+ public void dealIcd10Subtask(PatMedInhosp pmks, String config) {
+ pmks.setDiagcheckFlag("0");
+ pmks.setInhospstate("1");
+ pmks.setFuflag("1");
+ List<PatMedInhosp> patMedInhosps = patMedInhospMapper.selectPatMedInhospList(pmks);
+ log.info("dealIcd10Subtask 寰呭鐞嗗嚭闄㈢柧鐥呮偅鑰呮暟锛歿}", CollectionUtils.isEmpty(patMedInhosps) ? 0 : patMedInhosps.size());
+ if (CollectionUtils.isNotEmpty(patMedInhosps)) {
+ int matchedTaskCount = 0;
+ for (PatMedInhosp patMedInhosp : patMedInhosps) {
+ // 鑾峰彇鎮h�呭熀鏈俊鎭紝妗f涓嶅瓨鍦ㄦ椂鐩存帴鏍囪澶辫触锛岄伩鍏嶅悗缁┖鎸囬拡
+ PatArchive patArchive = patArchiveMapper.selectPatArchiveByPatid(patMedInhosp.getPatid());
+ if (Objects.isNull(patArchive)) {
+ PatMedInhosp updateObj = new PatMedInhosp();
+ updateObj.setInhospid(patMedInhosp.getInhospid());
+ updateObj.setDiagcheckFlag("2");
+ updateObj.setLongTaskReason("鎮h�呭熀鏈俊鎭负绌�");
+ patMedInhospMapper.updatePatMedInhosp(updateObj);
+ continue;
+ }
+ matchedTaskCount += addIcd10SubTaskForPatient(patMedInhosp, patArchive, config);
+ }
+ log.info("dealIcd10Subtask 澶勭悊瀹屾垚锛屽緟澶勭悊锛歿}锛屽尮閰嶇柧鐥呴暱鏈熶换鍔℃鏁帮細{}", patMedInhosps.size(), matchedTaskCount);
+ }
+ }
+
+ /**
+ * 浜哄伐闅忚锛氬垹闄ゆ偅鑰呭嚭闄㈣褰曞搴旂殑鏈畬鎴愰殢璁夸换鍔★紝骞舵寜鎸囧畾浠诲姟閲嶆柊鐢熸垚銆�
+ * 鍒犻櫎鏃т换鍔″彛寰勶細sendstate in (1,2,3,7)锛�
+ * 閲嶅浠诲姟鏍¢獙鍙e緞锛歴endstate in (1,2,3,5,7)锛屽凡鏈夌浉鍚� taskid 鏈畬鎴愪换鍔$殑鎮h�呰烦杩囥��
+ */
+ @Override
+ @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
+ 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());
+ }
+
+ // 鍗囧簭澶勭悊锛岄厤鍚堟偅鑰呮。妗堣閿侊紝閬垮厤鎵归噺璇锋眰浜ゅ弶鍔犻攣浜х敓姝婚攣
+ List<Long> patids = manualVisitDTO.getPatids().stream()
+ .filter(Objects::nonNull)
+ .distinct()
+ .sorted()
+ .collect(Collectors.toList());
+ if (patids.isEmpty()) {
+ throw new BaseException("鎮h�卲atid闆嗗悎涓嶈兘涓虹┖");
+ }
+
+ String config = iSysConfigService.selectConfigByKey("visit.early.day");
+ List<Long> unfinishedSendstates = Arrays.asList(1L, 2L, 3L, 7L);
+ // 涓庡墠绔緟闅忚鍙e緞淇濇寔涓�鑷达紝鍙戦�佸け璐�(5)涔熻涓哄凡鏈夋湭瀹屾垚浠诲姟
+ List<Long> activeSendstates = Arrays.asList(1L, 2L, 3L, 5L, 7L);
+ int deletedCount = 0;
+ int generatedCount = 0;
+ List<Long> noDischargeRecordPatids = new ArrayList<>();
+ List<Long> noArchivePatids = new ArrayList<>();
+ List<Long> generateFailedPatids = new ArrayList<>();
+ List<Long> duplicatePatids = new ArrayList<>();
+ List<String> duplicatePatientNames = 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;
+ }
+
+ // 閿佸畾鎮h�呮。妗堣锛屼覆琛屽寲鍚屼竴鎮h�呯殑骞跺彂鍒涘缓璇锋眰
+ Long lockedPatid = patArchiveMapper.lockPatArchiveByPatid(patid);
+ if (Objects.isNull(lockedPatid)) {
+ noArchivePatids.add(patid);
+ continue;
+ }
+
+ // 鍚屼竴鎮h�呭湪鍚屼竴 taskid 涓嬪凡鏈夋湭瀹屾垚闅忚浠诲姟鏃讹紝璺宠繃璇ユ偅鑰咃紝閬垮厤閲嶅鍒涘缓
+ int existingSubtaskCount = serviceSubtaskMapper.countUnfinishedServiceSubtaskByPatidAndTaskid(
+ patid, serviceTask.getTaskid(), activeSendstates);
+ if (existingSubtaskCount > 0) {
+ duplicatePatids.add(patid);
+ String patientName = StringUtils.isNotEmpty(patArchive.getName())
+ ? patArchive.getName() : String.valueOf(patid);
+ duplicatePatientNames.add(patientName + "(" + patid + ")");
+ log.info("addManualVisit 鎮h�呭凡鏈夌浉鍚屾湇鍔★紝璺宠繃鐢熸垚锛宲atid锛歿}锛宼askid锛歿}锛屽凡鏈変换鍔℃暟锛歿}",
+ patid, serviceTask.getTaskid(), existingSubtaskCount);
+ 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());
+ }
+
+ String tipMessage = null;
+ if (CollectionUtils.isNotEmpty(duplicatePatids)) {
+ String taskName = StringUtils.isNotEmpty(serviceTask.getTaskName())
+ ? serviceTask.getTaskName() : String.valueOf(serviceTask.getTaskid());
+ tipMessage = "鎮h��" + String.join("銆�", duplicatePatientNames)
+ + "宸叉湁鐩稿悓鏈嶅姟銆�" + taskName + "銆戯紝宸茶烦杩�";
+ if (generatedCount > 0) {
+ tipMessage += "锛涘叾浣欐偅鑰呭凡澶勭悊";
+ }
+ }
+
+ 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);
+ result.put("duplicatePatids", duplicatePatids);
+ result.put("duplicatePatientNames", duplicatePatientNames);
+ result.put("hasDuplicate", CollectionUtils.isNotEmpty(duplicatePatids));
+ result.put("tipMessage", tipMessage);
+ log.info("addManualVisit 澶勭悊瀹屾垚锛宲atid鏁帮細{}锛宼askid锛歿}锛屽垹闄ゆ湭瀹屾垚浠诲姟鏁帮細{}锛岀敓鎴愪换鍔℃暟锛歿}锛岄噸澶嶈烦杩囨暟锛歿}",
+ patids.size(), serviceTask.getTaskid(), deletedCount, generatedCount, duplicatePatids.size());
+ return result;
+ }
}
--
Gitblit v1.9.3