Fix Bug #506: fallback修复

This commit is contained in:
2026-05-27 03:22:08 +08:00
parent aadfd94c0e
commit 5dff708a44

View File

@@ -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<OrderDetail> 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);
}
// 其余业务方法保持不变...