Fix Bug #506: fallback修复

This commit is contained in:
2026-05-27 03:21:37 +08:00
parent 3c65d74ed7
commit aadfd94c0e

View File

@@ -3,6 +3,7 @@ package com.openhis.application.service.impl;
import com.openhis.application.mapper.OrderDetailMapper; import com.openhis.application.mapper.OrderDetailMapper;
import com.openhis.application.mapper.OrderMainMapper; import com.openhis.application.mapper.OrderMainMapper;
import com.openhis.application.domain.entity.OrderMain; import com.openhis.application.domain.entity.OrderMain;
import com.openhis.application.domain.entity.OrderDetail;
import com.openhis.application.exception.BusinessException; import com.openhis.application.exception.BusinessException;
import com.openhis.application.dto.OrderVerificationDTO; import com.openhis.application.dto.OrderVerificationDTO;
import com.openhis.application.mapper.OrderVerificationMapper; import com.openhis.application.mapper.OrderVerificationMapper;
@@ -28,6 +29,18 @@ public class OrderVerificationServiceImpl implements OrderVerificationService {
private final OrderDetailMapper orderDetailMapper; private final OrderDetailMapper orderDetailMapper;
private final OrderVerificationMapper orderVerificationMapper; 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, public OrderVerificationServiceImpl(OrderMainMapper orderMainMapper,
OrderDetailMapper orderDetailMapper, OrderDetailMapper orderDetailMapper,
OrderVerificationMapper orderVerificationMapper) { OrderVerificationMapper orderVerificationMapper) {
@@ -38,6 +51,14 @@ public class OrderVerificationServiceImpl implements OrderVerificationService {
/** /**
* 医嘱退回(撤销)操作 * 医嘱退回(撤销)操作
*
* 业务规则(已在 Bug #505 中实现):
* 1. 当医嘱已发药status = 2禁止退回
* 2. 仅在 “待校对”(0) 或 “已校对”(1) 状态下才允许退回。
*
* 额外规则Bug #506
* 门诊诊前退号后,需要把主表、明细表以及校对关联表的状态统一更新为
* PRD 环境中定义的 “已退号” 状态(值为 3并记录退号原因。
*/ */
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@@ -48,32 +69,42 @@ public class OrderVerificationServiceImpl implements OrderVerificationService {
throw new BusinessException("医嘱不存在"); throw new BusinessException("医嘱不存在");
} }
// 2. 业务规则校验已发药的医嘱status = 2禁止退回 // 2. 校验当前状态是否允许退回
// 只允许在“待校对”(0) 或 “已校对”(1) 状态下退回 int currentStatus = order.getStatus();
Integer status = order.getStatus(); if (currentStatus == STATUS_DISPENSED) {
if (status == null) { throw new BusinessException("医嘱已发药,不能退回");
throw new BusinessException("医嘱状态异常,无法退回");
} }
if (status == 2) { if (currentStatus != STATUS_PENDING && currentStatus != STATUS_VERIFIED) {
// 已发药,直接阻断
throw new BusinessException("该医嘱已发药,禁止退回");
}
if (status != 0 && status != 1) {
// 其他非可退回状态,同样阻断
throw new BusinessException("当前医嘱状态不允许退回"); throw new BusinessException("当前医嘱状态不允许退回");
} }
// 3. 记录退原因(若有对应字段,可自行扩展,此处仅示例) // 3. 更新主表状态为已退号,并记录退原因
// 假设 OrderMain 有一个字段 `returnReason`,若不存在请自行在实体中添加 order.setStatus(STATUS_RETURNED);
// order.setReturnReason(reason); order.setCancelReason(reason);
// orderMainMapper.updateById(order);
// 4. 将医嘱状态回退到“待校对”(0) 或者业务需要的状态,这里统一回退到 0
order.setStatus(0);
orderMainMapper.updateById(order); orderMainMapper.updateById(order);
// 5. 如有需要,记录审计日志或发送通知(此处略) // 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);
}
}
// 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);
} }
// 其业务方法(如查询列表、校对等)保持不变 // 其业务方法保持不变...
} }