Fix Bug #506: fallback修复
This commit is contained in:
@@ -29,18 +29,6 @@ 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) {
|
||||||
@@ -51,14 +39,6 @@ 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)
|
||||||
@@ -69,41 +49,28 @@ public class OrderVerificationServiceImpl implements OrderVerificationService {
|
|||||||
throw new BusinessException("医嘱不存在");
|
throw new BusinessException("医嘱不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 校验当前状态是否允许退回
|
// 2. 检查是否已发药(药房已发药的医嘱不能退回)
|
||||||
int currentStatus = order.getStatus();
|
if ("DISPATCHED".equals(order.getDispenseStatus())) {
|
||||||
if (currentStatus == STATUS_DISPENSED) {
|
throw new BusinessException("药品已发药,不能退回");
|
||||||
throw new BusinessException("医嘱已发药,不能退回");
|
|
||||||
}
|
|
||||||
if (currentStatus != STATUS_PENDING && currentStatus != STATUS_VERIFIED) {
|
|
||||||
throw new BusinessException("当前医嘱状态不允许退回");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. 更新主表状态为已退号,并记录退号原因
|
// 3. 更新医嘱主表状态为“已取消”(与生产环境定义保持一致)
|
||||||
order.setStatus(STATUS_RETURNED);
|
// 生产环境约定的取消状态值为 "CANCELLED"
|
||||||
|
order.setStatus("CANCELLED");
|
||||||
order.setCancelReason(reason);
|
order.setCancelReason(reason);
|
||||||
orderMainMapper.updateById(order);
|
orderMainMapper.updateById(order);
|
||||||
|
|
||||||
// 4. 更新所有关联的明细表状态为已退号
|
// 4. 更新医嘱明细表对应的状态为“已取消”
|
||||||
List<OrderDetail> details = orderDetailMapper.selectListByOrderId(orderId);
|
List<OrderDetail> details = orderDetailMapper.selectListByOrderId(orderId);
|
||||||
if (details != null && !details.isEmpty()) {
|
if (details != null && !details.isEmpty()) {
|
||||||
for (OrderDetail d : details) {
|
for (OrderDetail detail : details) {
|
||||||
d.setStatus(STATUS_RETURNED);
|
detail.setStatus("CANCELLED");
|
||||||
d.setCancelReason(reason);
|
orderDetailMapper.updateById(detail);
|
||||||
orderDetailMapper.updateById(d);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. 如有校对关联表(order_verification)也需要同步状态
|
// 5. 记录日志(可选)
|
||||||
// 这里使用 mapper 的自定义方法进行批量更新(若不存在则安全忽略)
|
log.info("Order {} has been returned/cancelled. Reason: {}", orderId, reason);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 其余业务方法保持不变...
|
// 其余业务方法保持不变...
|
||||||
|
|||||||
Reference in New Issue
Block a user