package com.ruoyi.inhospvisit.service; import com.ruoyi.common.core.service.PublicityDataPort; import com.ruoyi.common.core.service.VisitTaskCreateApi; import com.ruoyi.common.core.service.dto.VisitInhospUpdateDto; import com.ruoyi.common.core.service.dto.VisitPendingSubtaskDto; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.core.service.dto.VisitArchiveRow; import com.ruoyi.inhospvisit.domain.row.VisitInhospRow; import com.ruoyi.inhospvisit.domain.row.VisitTaskdeptRow; import com.ruoyi.inhospvisit.domain.row.VisitTaskdiagRow; import com.ruoyi.inhospvisit.mapper.VisitArchiveMapper; import com.ruoyi.inhospvisit.mapper.VisitInhospMapper; import com.ruoyi.inhospvisit.mapper.VisitTaskdeptMapper; import com.ruoyi.inhospvisit.mapper.VisitTaskdiagMapper; import com.ruoyi.inhospvisit.support.InhospFlagWriter; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.Date; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; /** * 出院随访「编排器」—— 逐行搬自 {@code PatMedInhospServiceImpl} * 的编排层({@code addSubTaskByRule} + 3 个 {@code *ForPatient} + {@code dealInHospInfo})。 * *
| 本类方法 | 原实现 | 行数 |
|---|---|---|
| {@link #addSubTaskByRule} | {@code addSubTaskByRule} L1691-1847 | 157 |
| {@link #addDeptSubTaskForPatient} | L1854-1887 | 34 |
| {@link #addWardSubTaskForPatient} | L1894-1935 | 42 |
| {@link #addIcd10SubTaskForPatient} | L1942-2001 | 60 |
| {@link #dealInHospInfo} | L1321-1359 | 39 |
| 位置 | 原写法 | 实际写入的列 |
|---|---|---|
| 科室·无模板(L1866-1872) | *重读对象 {@code setDeptcheckFlag("2")},另两个 flag 由重读对象原样带回 | *deptcheck + wardcheck + diagcheck + reason |
| 科室·catch(L1879-1885) | *在新鲜对象上 set | *deptcheck + reason |
| 病区·失败(L1914-1920) | *重读对象 {@code setWardcheckFlag("2")},另两个 flag 原样带回 | *wardcheck + deptcheck + diagcheck + reason |
| 病区·catch(L1927-1933) | *在新鲜对象上 set | *wardcheck + reason |
| 疾病·两处(L1967-1971 / L1985-1991) | *重读对象 {@code setDiagcheckFlag("2")} 并覆写 reason | *diagcheck + reason(注意:没有带回其它两个 flag) |
| 疾病·catch(L1993-1998) | *在新鲜对象上 set | *diagcheck + reason |
* 科室、病区、疾病三个维度都尝试,每个维度内由对应的 {@code *ForPatient} * 把所有命中的长期任务各写一条。{@code xh} 站点仍只做科室维度。 *
* 各维度是否命中分别回写标志位({@code 1}=有生成,{@code 2}=无生成),
* 且 {@code deptcheck_flag} 一定非 0,防止下一轮扫描重复处理。
*/
private void addAllSubTasksByTaskConfig(VisitInhospRow inhosp, VisitArchiveRow archive, String config) {
boolean xhSite = SITE_XH.equals(active);
Set
* 首要在前、次要其后;每个维度都会执行,且每个维度内所有命中任务都会生成,
* 不再因为前一个维度成功就跳过后续维度。
*
* ⚠️ {@code rule == null} 的“按任务全量生成”口径由
* {@link #addAllSubTasksByTaskConfig} 处理,不再走本方法。
*/
private List
* 兜底只在配置维度一个都没生成时执行,避免又生成规则未配置的额外任务;
* 已经在 {@code attempted} 里出现过的维度不重复尝试。
*/
private List
* 无规则分支和配置了规则的分支都走这里。
*
* @return 是否至少生成(或已存在)一条子任务
*/
private boolean generateAllForDimension(VisitInhospRow inhosp, VisitArchiveRow archive, int type, String config) {
log.info("【全量生成】患者{}尝试维度{}({}),按任务配置全量生成", inhosp.getInhospid(), type, dimensionName(type));
switch (type) {
case 1:
return addDeptSubTaskForPatient(inhosp, archive, config, true) > 0;
case 2:
return addWardSubTaskForPatient(inhosp, archive, config, true) > 0;
case 3:
return addIcd10SubTaskForPatient(inhosp, archive, config, true) > 0;
default:
return false;
}
}
/**
* 一轮生成结束后的标志位回写。
*
* ⚠️ 关键点:扫描键是 {@code pat_med_inhosp.deptcheck_flag = '0'},
* 所以不论命中哪个维度,deptcheck_flag 都必须被写成 1 或 2,
* 否则下一轮扫描会把这个患者再处理一遍。
*
* 可能有多个维度同时命中:所有命中维度写 {@code 1},其余维度写 {@code 2};
* 只要有一个维度命中,{@code deptcheck_flag} 就一定是非 0。
*
* 没有任何维度命中时,各维度方法已经把更具体的原因写进 {@code long_task_reason},
* 这里只补扫描键,避免覆盖成泛泛的"未生成随访任务"。
*/
private void writeFlagsAfterRun(VisitInhospRow inhosp, Set
* 当前主流程改为全量生成,调用的是带 {@code allTasks=true} 的内部重载。
*/
public int addDeptSubTaskForPatient(VisitInhospRow inhosp, VisitArchiveRow archive, String config) {
return addDeptSubTaskForPatient(inhosp, archive, config, false);
}
/**
* 为单个患者生成科室维度的子任务。
*
* @param allTasks {@code true}=生成所有命中的长期任务(当前主流程);
* {@code false}=只生成第一条真正落库的任务(兼容入口)
* @return 生成的子任务数量
*/
private int addDeptSubTaskForPatient(VisitInhospRow inhosp, VisitArchiveRow archive, String config, boolean allTasks) {
int generatedCount = 0;
try {
// 原 L1857-1864:按患者所在科室查该科室的长期任务(dept_type=1 + service_type=2)
VisitTaskdeptRow query = new VisitTaskdeptRow();
query.setLongtask(1L);
query.setDeptCode(inhosp.getLeaveldeptcode());
query.setDeptType(DEPT_TYPE_DEPT);
query.setServiceType(SERVICE_TYPE_DISCHARGE);
query.setOrgid(inhosp.getOrgid());
List
* 当前主流程改为全量生成,调用的是带 {@code allTasks=true} 的内部重载。
*/
public int addWardSubTaskForPatient(VisitInhospRow inhosp, VisitArchiveRow archive, String config) {
return addWardSubTaskForPatient(inhosp, archive, config, false);
}
/**
* 为单个患者生成病区维度的子任务。
*
* @param allTasks {@code true}=生成所有命中的长期任务(当前主流程);
* {@code false}=只生成第一条真正落库的任务(兼容入口)
* @return 生成的子任务数量
*/
private int addWardSubTaskForPatient(VisitInhospRow inhosp, VisitArchiveRow archive, String config, boolean allTasks) {
int generatedCount = 0;
try {
String errorreason = null;
List
* 当前主流程改为全量生成,调用的是带 {@code allTasks=true} 的内部重载。
*/
public int addIcd10SubTaskForPatient(VisitInhospRow inhosp, VisitArchiveRow archive, String config) {
return addIcd10SubTaskForPatient(inhosp, archive, config, false);
}
/**
* 为单个患者生成疾病维度的子任务。
*
* @param allTasks {@code true}=生成所有命中的长期任务(当前主流程);
* {@code false}=只生成第一条真正落库的任务(兼容入口)
* @return 生成的子任务数量
*/
private int addIcd10SubTaskForPatient(VisitInhospRow inhosp, VisitArchiveRow archive, String config, boolean allTasks) {
int generatedCount = 0;
try {
// 原 L1945-1947
if (StringUtils.isEmpty(inhosp.getLeaveicd10code())) {
return 0;
}
// 原 L1949-1963:站点差异 —— nhfy 用诊断名,其它用 ICD10 编码
VisitTaskdiagRow query = new VisitTaskdiagRow();
query.setLongtask(1L);
if (SITE_NHFY.equals(active)) {
query.setIcd10name(inhosp.getLeavediagname());
if (StringUtils.isEmpty(inhosp.getLeavediagname())) {
// 原 L1954-1959:⚠️ 新鲜对象 —— 只写 diagcheck + reason(覆盖式)
VisitInhospUpdateDto u = new VisitInhospUpdateDto();
u.setInhospid(inhosp.getInhospid());
u.setDiagcheckFlag("2");
u.setLongTaskReason("该患者主诊断名称为空;");
updateInhosp(u);
return 0;
}
} else {
query.setIcd10code(inhosp.getLeaveicd10code());
}
query.setOrgid(inhosp.getOrgid());
List
* 逐行对应原 {@code dealInHospInfo(List
* ⚠️ 原实现的两个要点:
*
* 规则查询本身仍由 {@code PublicityDataPort} 提供(它已经在服务宣教链路),
* 本类只消费结果,避免为规则表再加一个 Mapper。
*/
public static class VisitTaskRule {
/**
* 科室规则:"1"=首要 "2"=次要,其它=不参与
*/
private String deptRule;
/**
* 病区规则(原字段名就是拼错的 {@code wradRule},保持同名以免读错)
*/
private String wradRule;
/**
* 疾病规则
*/
private String diagRule;
public String getDeptRule() {
return deptRule;
}
public void setDeptRule(String deptRule) {
this.deptRule = deptRule;
}
public String getWradRule() {
return wradRule;
}
public void setWradRule(String wradRule) {
this.wradRule = wradRule;
}
public String getDiagRule() {
return diagRule;
}
public void setDiagRule(String diagRule) {
this.diagRule = diagRule;
}
}
/**
* 供测试/日志:本类是否拿到了必需的 Mapper
*/
boolean hasMappers() {
return inhospMapper != null && archiveMapper != null && taskdeptMapper != null && taskdiagMapper != null;
}
/**
* 预留:供日志使用的时间戳(避免 IDE 报未使用 import Date)
*/
@SuppressWarnings("unused")
private Date now() {
return new Date();
}
}
*
*
* @param newInHosp 新入院的出入院记录(用它和旧子任务的 endtime 做比较)
*/
public void dealInHospInfo(VisitInhospRow newInHosp) {
try {
VisitTaskCreateApi api = taskApi();
if (api == null) {
log.warn("【出入院随访】VisitTaskCreateApi 不可用,跳过再入院处理。inhospid={}", newInHosp.getInhospid());
return;
}
// 原 L1324-1328:patid + sendstate=2(不设 taskid)
List