package com.ruoyi.task.api.contract; import com.ruoyi.common.core.service.VisitTaskCreateApi; import com.ruoyi.common.core.service.dto.VisitLongTaskDto; import com.ruoyi.common.core.service.dto.VisitPendingSubtaskDto; import com.ruoyi.common.core.service.dto.VisitSubtaskDraft; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.Collections; import java.util.List; import com.ruoyi.task.domain.entity.ServiceSubtaskEntity; import com.ruoyi.task.domain.ServiceSubtask; import com.ruoyi.task.domain.ServiceTask; import com.ruoyi.task.mapper.ServiceSubtaskMapper; import com.ruoyi.task.mapper.ServiceTaskMapper; /** * 【过渡实现·临时】{@link VisitTaskCreateApi} 在 smartor 侧的桥接。 * *
* 将来动作:新模块建好后,把它的实现注册进容器, * 本类整体删除即可,{@code ruoyi-inhospvisit} 一行都不用改。 * *
| 本类方法 | 原实现位置 |
|---|---|
| {@link #findPublishedLongTask(Long)} | L686-728(查 ServiceTask,sendState=2) |
| {@link #insertSubtask(VisitSubtaskDraft)} | L823 / L838 / L854 / L862 / L873 |
| {@link #findPendingSubtasks(Long, Long)} | L760-764、L1325-1328 |
| {@link #updatePendingSubtask(VisitPendingSubtaskDto)} | L782 / L791 / L812 / L836 / L1349 |
* 原实现({@code PatMedInhospServiceImpl} L686-690): *
* ServiceTask st = new ServiceTask();
* st.setTaskid(taskid);
* st.setSendState(2L);
* List<ServiceTask> serviceTasks = serviceTaskMapper.selectServiceTaskList(st);
* ServiceTask serviceTask = null;
* if (CollectionUtils.isEmpty(serviceTasks)) { ...按 type 写不同 flag 后 return... }
* else { serviceTask = serviceTasks.get(0); }
*
* 这里只负责"查 + 取第一条";"查不到时按 type 写哪个 flag"属于随访域,
* 留在 {@code writeInSubTask} 里。
*/
@Override
public VisitLongTaskDto findPublishedLongTask(Long taskid) {
ServiceTask query = new ServiceTask();
query.setTaskid(taskid);
query.setSendState(2L);
List* 原实现({@code PatMedInhospServiceImpl#addServiceSubtaskPreachform} L1063)用的是 * {@code serviceTaskMapper.selectServiceTaskByTaskid(taskid)} —— * 不带 sendState 条件,且查不到时返回 null。 * 这里逐字照搬,不复用 {@link #findPublishedLongTask}(那个带 {@code sendState=2})。 */ @Override public String findPreachformDesc(Long taskid) { if (taskid == null) { return null; } ServiceTask task = serviceTaskMapper.selectServiceTaskByTaskid(taskid); return task == null ? null : task.getPreachformDesc(); } /** * 是否存在「指定状态 + 指定服务类型」的子任务。 *
* 原实现(门诊 {@code selectPatMedOuthospList} L108-117):调 * {@code serviceSubtaskMapper.selectServiceSubtaskBySendstate(v)}, * 参数是 {@code ServiceSubtaskEntity},设了 {@code patid} / {@code sendstates} / {@code serviceType}。 * 这里逐字照搬,只把"非空"折叠成 {@code boolean}(调用方原本只用它做 if 判断)。 * *
⚠️ 不属于 {@link #findPendingSubtasks(Long, Long)}:那个固定 {@code sendstate=2}
* 且按 taskid 过滤、查 {@code selectServiceSubtaskList},口径不同、不可互替。
*/
@Override
public boolean existsSubtaskWithStates(Long patid, java.util.List
* 直接用现成的 {@code selectServiceSubtaskList}(本身就带
* {@code del_flag = 0} + {@code patid} + {@code inhospid} + {@code taskid} 三个条件),
* 不新增 XML —— 避免为了一个"有没有"再写一条等价 SQL。
*
* ⚠️ 不按 {@code sendstate} 过滤:已停用(sendstate=4)的历史行也算"生成过"。
* 否则"停旧一条 + 再生成一条"会无限累积 —— 这正是 2026-10 同一患者几十条子任务的成因。
*/
@Override
public boolean existsSubtask(Long patid, Long inhospid, Long taskid) {
if (patid == null || taskid == null) {
return false;
}
ServiceSubtaskEntity q = new ServiceSubtaskEntity();
q.setPatid(patid);
q.setInhospid(inhospid);
q.setTaskid(taskid);
return !CollectionUtils.isEmpty(serviceSubtaskMapper.selectServiceSubtaskList(q));
}
// ==========================================================================
// 字段搬运(逐字段对照,勿"顺手精简")
// ==========================================================================
private VisitLongTaskDto toLongTaskDto(ServiceTask t) {
VisitLongTaskDto dto = new VisitLongTaskDto();
dto.setTaskid(t.getTaskid());
dto.setTaskName(t.getTaskName());
dto.setTaskDesc(t.getTaskDesc());
dto.setType(t.getType());
dto.setServiceType(t.getServiceType());
dto.setTemplateid(t.getTemplateid());
dto.setTemplatename(t.getTemplatename());
dto.setLibtemplateid(t.getLibtemplateid());
dto.setLibtemplatename(t.getLibtemplatename());
dto.setSendDay(t.getSendDay());
dto.setPreachform(t.getPreachform());
dto.setPreachformDesc(t.getPreachformDesc());
dto.setOrgid(t.getOrgid());
dto.setCampusid(t.getCampusid());
dto.setHosType(t.getHospType());
// 原 boxedServiceSubtask 第一行的 DtoConversionUtils.sourceToTarget 会把这 6 个
// 拷进子任务并随 insertServiceSubtask 落库;不搬就是静默丢列(见 VisitLongTaskDto 注释)
dto.setGuid(t.getGuid());
dto.setPid(t.getPid());
dto.setSendType(t.getSendType());
dto.setIsupload(t.getIsupload());
dto.setTextParam(t.getTextParam());
dto.setUploadTime(t.getUploadTime());
dto.setUpdateBy(t.getUpdateBy());
dto.setCreateBy(t.getCreateBy());
return dto;
}
/**
* 草稿 → 实体。
*
* 逐个 setter 对照迁移前的 {@code boxedServiceSubtask} 与 {@code writeInSubTask},
* 少一个字段就会让对应列静默不更新(XML 里是 {@code