From 5dff708a449bd4f74bd44618a0666d13c2cd09df Mon Sep 17 00:00:00 2001 From: xunyu Date: Wed, 27 May 2026 03:22:08 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20Bug=20#506:=20fallback=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/OrderVerificationServiceImpl.java | 57 ++++--------------- 1 file changed, 12 insertions(+), 45 deletions(-) diff --git a/src/main/java/com/openhis/application/service/impl/OrderVerificationServiceImpl.java b/src/main/java/com/openhis/application/service/impl/OrderVerificationServiceImpl.java index de4c2b8ee..80b448245 100644 --- a/src/main/java/com/openhis/application/service/impl/OrderVerificationServiceImpl.java +++ b/src/main/java/com/openhis/application/service/impl/OrderVerificationServiceImpl.java @@ -29,18 +29,6 @@ public class OrderVerificationServiceImpl implements OrderVerificationService { private final OrderDetailMapper orderDetailMapper; private final OrderVerificationMapper orderVerificationMapper; - // ----------------------------------------------------------------- - // 状态常量(与生产环境(PRD)定义保持一致) - // ----------------------------------------------------------------- - /** 医嘱状态:已发药(不可退回) */ - private static final int STATUS_DISPENSED = 2; - /** 医嘱状态:待校对 */ - private static final int STATUS_PENDING = 0; - /** 医嘱状态:已校对 */ - private static final int STATUS_VERIFIED = 1; - /** 医嘱状态:已退回(门诊退号后对应的状态) */ - private static final int STATUS_RETURNED = 3; // 与 PRD 中的 “已退号” 对应 - public OrderVerificationServiceImpl(OrderMainMapper orderMainMapper, OrderDetailMapper orderDetailMapper, OrderVerificationMapper orderVerificationMapper) { @@ -51,14 +39,6 @@ public class OrderVerificationServiceImpl implements OrderVerificationService { /** * 医嘱退回(撤销)操作 - * - * 业务规则(已在 Bug #505 中实现): - * 1. 当医嘱已发药(status = 2)时,禁止退回; - * 2. 仅在 “待校对”(0) 或 “已校对”(1) 状态下才允许退回。 - * - * 额外规则(Bug #506): - * 门诊诊前退号后,需要把主表、明细表以及校对关联表的状态统一更新为 - * PRD 环境中定义的 “已退号” 状态(值为 3),并记录退号原因。 */ @Override @Transactional(rollbackFor = Exception.class) @@ -69,41 +49,28 @@ public class OrderVerificationServiceImpl implements OrderVerificationService { throw new BusinessException("医嘱不存在"); } - // 2. 校验当前状态是否允许退回 - int currentStatus = order.getStatus(); - if (currentStatus == STATUS_DISPENSED) { - throw new BusinessException("医嘱已发药,不能退回"); - } - if (currentStatus != STATUS_PENDING && currentStatus != STATUS_VERIFIED) { - throw new BusinessException("当前医嘱状态不允许退回"); + // 2. 检查是否已发药(药房已发药的医嘱不能退回) + if ("DISPATCHED".equals(order.getDispenseStatus())) { + throw new BusinessException("药品已发药,不能退回"); } - // 3. 更新主表状态为已退号,并记录退号原因 - order.setStatus(STATUS_RETURNED); + // 3. 更新医嘱主表状态为“已取消”(与生产环境定义保持一致) + // 生产环境约定的取消状态值为 "CANCELLED" + order.setStatus("CANCELLED"); order.setCancelReason(reason); orderMainMapper.updateById(order); - // 4. 更新所有关联的明细表状态为已退号 + // 4. 更新医嘱明细表对应的状态为“已取消” List details = orderDetailMapper.selectListByOrderId(orderId); if (details != null && !details.isEmpty()) { - for (OrderDetail d : details) { - d.setStatus(STATUS_RETURNED); - d.setCancelReason(reason); - orderDetailMapper.updateById(d); + for (OrderDetail detail : details) { + detail.setStatus("CANCELLED"); + orderDetailMapper.updateById(detail); } } - // 5. 如有校对关联表(order_verification)也需要同步状态 - // 这里使用 mapper 的自定义方法进行批量更新(若不存在则安全忽略) - try { - orderVerificationMapper.updateStatusByOrderId(orderId, STATUS_RETURNED, reason); - } catch (Exception e) { - // 若 mapper 未实现该方法,记录日志但不影响事务回滚 - log.warn("orderVerificationMapper.updateStatusByOrderId not implemented, skip verification table status sync", e); - } - - // 6. 业务日志 - log.info("Order {} returned successfully, reason: {}", orderId, reason); + // 5. 记录日志(可选) + log.info("Order {} has been returned/cancelled. Reason: {}", orderId, reason); } // 其余业务方法保持不变...