diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/chargemanage/appservice/impl/OutpatientRegistrationAppServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/chargemanage/appservice/impl/OutpatientRegistrationAppServiceImpl.java index 8be9cc0c..0852a29b 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/chargemanage/appservice/impl/OutpatientRegistrationAppServiceImpl.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/chargemanage/appservice/impl/OutpatientRegistrationAppServiceImpl.java @@ -108,6 +108,9 @@ public class OutpatientRegistrationAppServiceImpl implements IOutpatientRegistra @Resource IOrderService orderService; + @Resource + com.openhis.triageandqueuemanage.service.TriageQueueItemService triageQueueItemService; + @Resource ScheduleSlotMapper scheduleSlotMapper; @@ -324,6 +327,9 @@ public class OutpatientRegistrationAppServiceImpl implements IOutpatientRegistra // 如果本次门诊挂号来自预约签到,同步把预约订单与号源槽位状态改为已退号 if (result != null && result.getCode() == 200) { syncAppointmentReturnStatus(byId, cancelRegPaymentDto.getReason()); + + // 同步移除分诊队列中的记录 + removeTriageQueueItem(byId.getId()); } // 记录退号日志 @@ -779,4 +785,48 @@ public class OutpatientRegistrationAppServiceImpl implements IOutpatientRegistra } } + /** + * 移除分诊队列中的记录 + * 退号时同步移除患者队列记录,避免已退号患者仍在排队 + * + * @param encounterId 就诊ID + */ + private void removeTriageQueueItem(Long encounterId) { + if (encounterId == null) { + return; + } + // 1. 移除分诊队列中的记录(必须成功,否则回滚事务) + com.openhis.triageandqueuemanage.domain.TriageQueueItem queueItem = triageQueueItemService.getOne( + new LambdaQueryWrapper() + .eq(com.openhis.triageandqueuemanage.domain.TriageQueueItem::getEncounterId, encounterId) + .eq(com.openhis.triageandqueuemanage.domain.TriageQueueItem::getDeleteFlag, "0") + ); + + if (queueItem != null) { + // 逻辑删除队列项 + queueItem.setDeleteFlag("1"); + queueItem.setUpdateTime(LocalDateTime.now()); + triageQueueItemService.updateById(queueItem); + log.info("退号成功,已移除分诊队列记录,encounterId={}, queueItemId={}", encounterId, queueItem.getId()); + } + + // 2. 移除候选池排除记录(非必须,即使失败也不影响主流程) + try { + TriageCandidateExclusion exclusion = triageCandidateExclusionService.getOne( + new LambdaQueryWrapper() + .eq(TriageCandidateExclusion::getEncounterId, encounterId) + .eq(TriageCandidateExclusion::getDeleteFlag, "0") + ); + if (exclusion != null) { + exclusion.setDeleteFlag("1"); + exclusion.setUpdateTime(LocalDateTime.now()); + triageCandidateExclusionService.updateById(exclusion); + log.info("已移除候选池排除记录,encounterId={}", encounterId); + } + } catch (Exception e) { + // 候选池排除记录移除失败不影响主流程,仅记录日志 + log.warn("移除候选池排除记录失败,encounterId={}", encounterId, e); + } + } + } diff --git a/openhis-server-new/openhis-application/src/main/resources/mapper/chargemanage/OutpatientRegistrationAppMapper.xml b/openhis-server-new/openhis-application/src/main/resources/mapper/chargemanage/OutpatientRegistrationAppMapper.xml index be71ec4d..2f5fa0e8 100644 --- a/openhis-server-new/openhis-application/src/main/resources/mapper/chargemanage/OutpatientRegistrationAppMapper.xml +++ b/openhis-server-new/openhis-application/src/main/resources/mapper/chargemanage/OutpatientRegistrationAppMapper.xml @@ -84,7 +84,7 @@ T8.gender_enum AS gender_enum, T8.id_card AS id_card, T1.status_enum AS status_enum, - T1.create_time AS "registerTime", + T1.create_time AS register_time, T10.total_price, T11."name" AS account_name, T12."name" AS enterer_name, @@ -178,7 +178,7 @@ AND T10.context_enum = #{register} ) AS T9 ${ew.customSqlSegment} - ORDER BY T9.registerTime DESC + ORDER BY T9.register_time DESC