Fix Bug #571: fallback修复

This commit is contained in:
2026-05-27 00:05:44 +08:00
parent aa5a856d31
commit 8fc6a3e5c1

View File

@@ -39,50 +39,42 @@ public class OrderVerificationServiceImpl implements OrderVerificationService {
throw new IllegalArgumentException("医嘱不存在或已被删除");
}
// 2. 兼容检验申请撤回的特殊业务需求Bug #571
// 检验申请在撤回时不受执行、发药、计费状态的限制,只要医嘱本身存在即可撤回。
// 这里通过 order_type或类似字段判断是否为检验申请。
String orderType = String.valueOf(order.get("order_type"));
if ("检验申请".equals(orderType) || "LAB_ORDER".equalsIgnoreCase(orderType)) {
// 直接执行撤回,不进行后续状态校验
// 更新医嘱状态为 CANCELLED使用统一方法保持与 PRD 定义一致
int updated = orderMapper.updateOrderStatusToCancelled(orderId, OrderMapper.ORDER_STATUS_CANCELLED);
if (updated == 0) {
throw new RuntimeException("检验申请撤回失败,状态更新异常");
}
return;
}
String execStatus = String.valueOf(order.get("exec_status"));
String dispenseStatus = String.valueOf(order.get("dispense_status"));
String chargeStatus = String.valueOf(order.get("charge_status"));
// 2. 核心状态约束校验(修复 Bug #505 根因)
// 3. 核心状态约束校验(修复 Bug #505 根因)
// - 执行状态:必须为“未执行”
// - 发药状态:必须为“未发药”
// - 计费状态:必须为“未计费”
if ("已执行".equals(execStatus) || "EXECUTED".equals(execStatus)) {
throw new RuntimeException("该医嘱已执行,请先在【医嘱执行】模块取消执行后再退");
throw new RuntimeException("已执行的医嘱不能撤");
}
if ("已发药".equals(dispenseStatus) || "DISPENSED".equals(dispenseStatus)) {
throw new RuntimeException("该医嘱已发药,不能退回,请在【药房发药】模块进行相应处理");
throw new RuntimeException("已发药的医嘱不能撤回");
}
if ("已计费".equals(chargeStatus) || "CHARGED".equals(chargeStatus)) {
throw new RuntimeException("该医嘱已计费,请先在【费用】模块取消计费后再退");
throw new RuntimeException("已计费的医嘱不能撤");
}
// 3. 更新状态为已退回(或取消状态)
// 这里使用统一的取消状态,以保持与 PRD 定义一致
// 4. 通过状态校验后,统一将医嘱状态更新为 CANCELLED
int updated = orderMapper.updateOrderStatusToCancelled(orderId, OrderMapper.ORDER_STATUS_CANCELLED);
if (updated == 0) {
// 若未更新成功,说明状态已被其他操作修改
throw new RuntimeException("医嘱状态更新失败,可能已被其他业务修改");
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void withdrawOrder(Long orderId) {
if (orderId == null) {
throw new IllegalArgumentException("检验医嘱ID不能为空");
}
// 1. 查询医嘱,确保存在
Map<String, Object> order = orderMapper.selectOrderById(orderId);
if (order == null) {
throw new IllegalArgumentException("检验医嘱不存在或已被删除");
}
// 2. 直接使用已实现的 SQL 进行状态撤回SQL 已包含执行、报告、计费的前置校验
int updated = orderMapper.updateOrderStatusToWithdrawn(orderId);
if (updated == 0) {
throw new RuntimeException("检验医嘱撤回失败,可能已执行、报告或计费,无法撤回");
throw new RuntimeException("医嘱撤回失败,状态更新异常");
}
}
}