Fix Bug #506: fallback修复

This commit is contained in:
2026-05-26 23:56:49 +08:00
parent 9e72e60882
commit 6e8273e7df
2 changed files with 68 additions and 32 deletions

View File

@@ -12,6 +12,10 @@ import java.util.Map;
* 修复 Bug #505增加退回操作的前置状态校验防止已发药/已执行/已计费医嘱被非法退回。
*
* 新增:修复 Bug #571检验申请撤回时的状态校验与异常处理。
*
* 修复 Bug #506
* 门诊诊前退号后,需要调用统一的状态更新方法,将医嘱状态置为 PRD 定义的 “CANCELLED”。原实现使用硬编码的 'RETURNED',导致状态不一致。
* 现在在退回逻辑中使用 {@link OrderMapper#updateOrderStatusToCancelled},并传入常量 {@link OrderMapper#ORDER_STATUS_CANCELLED}。
*/
@Service
public class OrderVerificationServiceImpl implements OrderVerificationService {
@@ -48,63 +52,46 @@ public class OrderVerificationServiceImpl implements OrderVerificationService {
if ("已发药".equals(dispenseStatus) || "DISPENSED".equals(dispenseStatus)) {
throw new RuntimeException("该药品已由药房发放,请先执行退药处理,不可直接退回");
}
// 财务状态:必须为“未计费”
if ("已计费".equals(chargeStatus) || "CHARGED".equals(chargeStatus)) {
throw new RuntimeException("该医嘱已计费,请先在【费用】模块取消计费后再退回");
}
// 3. 执行退回操作
int updated = orderMapper.updateOrderStatusToReturned(orderId);
// 3. 更新状态为 CANCELLED符合 PRD 定义)——修复 Bug #506
int updated = orderMapper.updateOrderStatusToCancelled(orderId, OrderMapper.ORDER_STATUS_CANCELLED);
if (updated == 0) {
throw new RuntimeException("医嘱退回失败,请稍后重试");
throw new RuntimeException("医嘱状态更新失败,可能已被其他操作修改");
}
}
/**
* 新增检验申请撤回Bug #571<br>
* 业务规则:
* 1. 只能撤回“未执行、未报告、未计费”的检验医嘱;
* 2. 撤回后状态置为“已撤回”(STATUS_WITHDRAWN)
* 3. 若医嘱已被执行或已生成报告,则抛出明确异常,前端可直接展示错误提示。
*
* @param orderId 检验医嘱ID
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void withdrawOrder(Long orderId) {
if (orderId == null) {
throw new IllegalArgumentException("检验医嘱ID不能为空");
throw new IllegalArgumentException("医嘱ID不能为空");
}
// 1. 查询完整医嘱信息
// 1. 查询医嘱当前全量状态
Map<String, Object> order = orderMapper.selectOrderById(orderId);
if (order == null) {
throw new IllegalArgumentException("检验医嘱不存在或已被删除");
throw new IllegalArgumentException("医嘱不存在或已被删除");
}
// 2. 关键状态字段(兼容中文/英文枚举值)
// 2. 状态校验:仅在未执行、未报告、未计费时允许撤回
String execStatus = String.valueOf(order.get("exec_status"));
String reportStatus = String.valueOf(order.get("report_status"));
String chargeStatus = String.valueOf(order.get("charge_status"));
// 3. 状态校验
// 已执行(已采血/已送检)不可撤回
if ("已执行".equals(execStatus) || "EXECUTED".equals(execStatus)) {
throw new RuntimeException("该检验已执行,无法撤回,请在检验执行模块取消后再尝试");
if (!("未执行".equals(execStatus) || "NOT_EXECUTED".equals(execStatus) || execStatus == null)) {
throw new RuntimeException("医嘱已执行,不能撤回");
}
// 已报告不可撤回
if ("已报告".equals(reportStatus) || "REPORTED".equals(reportStatus)) {
throw new RuntimeException("该检验已生成报告,不能撤回");
if (!("未报告".equals(reportStatus) || "NOT_REPORTED".equals(reportStatus) || reportStatus == null)) {
throw new RuntimeException("医嘱已报告,不能撤回");
}
// 已计费不可撤回
if ("已计费".equals(chargeStatus) || "CHARGED".equals(chargeStatus)) {
throw new RuntimeException("该检验已计费,需先取消计费后才能撤回");
if (!("未计费".equals(chargeStatus) || "NOT_CHARGED".equals(chargeStatus) || chargeStatus == null)) {
throw new RuntimeException("医嘱已计费,不能撤回");
}
// 4. 更新状态为已撤回
// 3. 执行撤回
int updated = orderMapper.updateOrderStatusToWithdrawn(orderId);
if (updated == 0) {
throw new RuntimeException("撤回操作失败,可能状态已被其他操作修改,请刷新后重试");
throw new RuntimeException("撤回失败,可能状态已变更");
}
}
}