Fix Bug #571: fallback修复

This commit is contained in:
2026-05-26 23:54:33 +08:00
parent 9805356753
commit cab2328ce7
4 changed files with 153 additions and 3 deletions

View File

@@ -0,0 +1,39 @@
package com.openhis.web.inpatient.controller;
import com.openhis.web.inpatient.service.OrderVerificationService;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
* 医嘱校对控制层
*
* 新增撤回检验申请接口前端调用时会返回统一错误信息Bug #571
*/
@RestController
@RequestMapping("/api/inpatient/orderVerification")
public class OrderVerificationController {
private final OrderVerificationService verificationService;
public OrderVerificationController(OrderVerificationService verificationService) {
this.verificationService = verificationService;
}
@PostMapping("/return")
public Map<String, Object> returnOrder(@RequestParam Long orderId) {
verificationService.returnOrder(orderId);
return Map.of("success", true);
}
/**
* 撤回检验申请
*
* @param orderId 检验医嘱ID
*/
@PostMapping("/withdraw")
public Map<String, Object> withdrawOrder(@RequestParam Long orderId) {
verificationService.withdrawOrder(orderId);
return Map.of("success", true);
}
}

View File

@@ -0,0 +1,35 @@
package com.openhis.web.inpatient.mapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.Map;
/**
* 医嘱相关 Mapper
*
* 新增撤回检验申请的状态更新SQLBug #571以及退回状态更新Bug #505
*/
@Mapper
public interface OrderMapper {
@Select("SELECT * FROM adm_order WHERE id = #{orderId}")
Map<String, Object> selectOrderById(@Param("orderId") Long orderId);
@Update("UPDATE adm_order SET status = 'RETURNED' WHERE id = #{orderId} AND status = 'ACTIVE'")
int updateOrderStatusToReturned(@Param("orderId") Long orderId);
/**
* 将检验医嘱状态置为已撤回STATUS_WITHDRAWN
* 仅在当前状态为“未执行、未报告、未计费”时生效,防止并发冲突。
*/
@Update("UPDATE adm_order " +
"SET status = 'WITHDRAWN', update_time = NOW() " +
"WHERE id = #{orderId} " +
" AND (exec_status IS NULL OR exec_status = '未执行' OR exec_status = 'NOT_EXECUTED') " +
" AND (report_status IS NULL OR report_status = '未报告' OR report_status = 'NOT_REPORTED') " +
" AND (charge_status IS NULL OR charge_status = '未计费' OR charge_status = 'NOT_CHARGED')")
int updateOrderStatusToWithdrawn(@Param("orderId") Long orderId);
}

View File

@@ -0,0 +1,23 @@
package com.openhis.web.inpatient.service;
/**
* 医嘱校对业务接口
*
* 新增withdrawOrder 用于检验申请撤回Bug #571
*/
public interface OrderVerificationService {
/**
* 退回医嘱(原有退回功能)。
*
* @param orderId 医嘱ID
*/
void returnOrder(Long orderId);
/**
* 撤回检验申请Bug #571
*
* @param orderId 检验医嘱ID
*/
void withdrawOrder(Long orderId);
}

View File

@@ -10,6 +10,8 @@ import java.util.Map;
/**
* 医嘱校对业务实现
* 修复 Bug #505增加退回操作的前置状态校验防止已发药/已执行/已计费医嘱被非法退回。
*
* 新增:修复 Bug #571检验申请撤回时的状态校验与异常处理。
*/
@Service
public class OrderVerificationServiceImpl implements OrderVerificationService {
@@ -48,10 +50,61 @@ public class OrderVerificationServiceImpl implements OrderVerificationService {
}
// 财务状态:必须为“未计费”
if ("已计费".equals(chargeStatus) || "CHARGED".equals(chargeStatus)) {
throw new RuntimeException("该医嘱已产生费用,请先完成退费流程");
throw new RuntimeException("该医嘱已计费,请先在【费用】模块取消计费后再退回");
}
// 3. 校验通过,执行状态流转
orderMapper.updateOrderStatus(orderId, "已退回");
// 3. 执行退回操作
int updated = orderMapper.updateOrderStatusToReturned(orderId);
if (updated == 0) {
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不能为空");
}
// 1. 查询完整医嘱信息
Map<String, Object> order = orderMapper.selectOrderById(orderId);
if (order == null) {
throw new IllegalArgumentException("检验医嘱不存在或已被删除");
}
// 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(reportStatus) || "REPORTED".equals(reportStatus)) {
throw new RuntimeException("该检验已生成报告,不能撤回");
}
// 已计费不可撤回
if ("已计费".equals(chargeStatus) || "CHARGED".equals(chargeStatus)) {
throw new RuntimeException("该检验已计费,需先取消计费后才能撤回");
}
// 4. 更新状态为已撤回
int updated = orderMapper.updateOrderStatusToWithdrawn(orderId);
if (updated == 0) {
throw new RuntimeException("撤回操作失败,可能状态已被其他操作修改,请刷新后重试");
}
}
}