From 61e000e674e377b68bc9d6f36a007899a66b364b Mon Sep 17 00:00:00 2001 From: guanyu Date: Wed, 27 May 2026 03:10:38 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20Bug=20#505:=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 | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 openhis-application/src/main/java/com/openhis/application/service/impl/OrderVerificationServiceImpl.java diff --git a/openhis-application/src/main/java/com/openhis/application/service/impl/OrderVerificationServiceImpl.java b/openhis-application/src/main/java/com/openhis/application/service/impl/OrderVerificationServiceImpl.java new file mode 100644 index 000000000..161b63f4b --- /dev/null +++ b/openhis-application/src/main/java/com/openhis/application/service/impl/OrderVerificationServiceImpl.java @@ -0,0 +1,61 @@ +package com.openhis.application.service.impl; + +import com.openhis.application.mapper.OrderMainMapper; +import com.openhis.application.domain.entity.OrderMain; +import com.openhis.application.exception.BusinessException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + * 医嘱校对业务实现 + * + * 修复 Bug #505:药品医嘱已由药房发药,护士仍能在“医嘱校对”模块执行“退回”操作。 + * + * 业务规则: + * 1. 医嘱状态为“已发药”(status = 2) 时,禁止退回。 + * 2. 只有在“待校对”(status = 0) 或 “已校对”(status = 1) 状态下才允许退回。 + * + * 该实现通过在退回前校验医嘱状态并抛出业务异常阻止后续处理,确保业务流程符合药房发药后的不可逆性要求。 + */ +@Service +public class OrderVerificationServiceImpl implements OrderVerificationService { + + private final OrderMainMapper orderMainMapper; + + public OrderVerificationServiceImpl(OrderMainMapper orderMainMapper) { + this.orderMainMapper = orderMainMapper; + } + + /** + * 医嘱退回(撤销)操作 + * + * @param orderId 医嘱主表ID + * @param reason 退回原因 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void returnOrder(Long orderId, String reason) { + // 1. 查询医嘱 + OrderMain order = orderMainMapper.selectById(orderId); + if (order == null) { + throw new BusinessException("医嘱不存在"); + } + + // 2. 检查医嘱状态,仅在待校对(0)或已校对(1)时允许退回 + // 已发药(2)及其它状态均不允许退回 + Integer status = order.getStatus(); + if (status == null || (status != 0 && status != 1)) { + // 已发药或已退药等不可退回状态 + throw new BusinessException("药品已由药房发药,不能退回"); + } + + // 3. 业务处理:这里仅示例更新状态为“已退药”(3) 并记录退回原因 + OrderMain update = new OrderMain(); + update.setId(orderId); + update.setStatus(3); // 已退药 + update.setCancelReason(reason); // 记录退回原因 + update.setCancelTime(new java.util.Date()); + + orderMainMapper.updateById(update); + } +}