Fix Bug #505: fallback修复

This commit is contained in:
2026-05-27 03:08:43 +08:00
parent 60b8713236
commit d8742b0a61

View File

@@ -0,0 +1,64 @@
package com.openhis.application.service.impl;
import com.openhis.application.mapper.OrderMainMapper;
import com.openhis.application.domain.entity.OrderMain;
import com.openhis.application.exception.BusinessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* 医嘱校对业务实现
*
* 修复 Bug #505药品医嘱已由药房发药护士仍能在“医嘱校对”模块执行“退回”操作。
*
* 业务规则:
* 1. 医嘱状态为“已发药”(status = 2) 时,禁止退回。
* 2. 只有在“待校对”(status = 0) 或 “已校对”(status = 1) 状态下才允许退回。
*
* 该实现通过在退回前校验医嘱状态并抛出业务异常阻止后续处理,确保业务流程符合药房发药后的不可逆性要求。
*/
@Service
public class OrderVerificationServiceImpl implements OrderVerificationService {
private final OrderMainMapper orderMainMapper;
public OrderVerificationServiceImpl(OrderMainMapper orderMainMapper) {
this.orderMainMapper = orderMainMapper;
}
/**
* 医嘱退回(撤销)操作
*
* @param orderId 医嘱主表ID
* @param reason 退回原因
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void returnOrder(Long orderId, String reason) {
// 1. 查询医嘱
OrderMain order = orderMainMapper.selectById(orderId);
if (order == null) {
throw new BusinessException("医嘱不存在");
}
// 2. 检查医嘱状态,已发药的医嘱禁止退回
// 假设 status: 0=待校对, 1=已校对, 2=已发药, 3=已退药等
if (order.getStatus() != null && order.getStatus() == 2) {
// 已发药,直接阻止退回
throw new BusinessException("药品已由药房发药,不能退回");
}
// 3. 只有待校对或已校对状态可以退回
if (order.getStatus() == null || (order.getStatus() != 0 && order.getStatus() != 1)) {
throw new BusinessException("当前医嘱状态不允许退回");
}
// 4. 更新医嘱状态为退回(假设 3 表示已退回)
OrderMain update = new OrderMain();
update.setId(orderId);
update.setStatus(3);
update.setReturnReason(reason);
update.setReturnTime(new java.util.Date());
orderMainMapper.updateById(update);
}
}