Fix Bug #505: AI修复

This commit is contained in:
2026-05-27 04:22:10 +08:00
parent 4193be1160
commit 69928fd8f0
3 changed files with 158 additions and 194 deletions

View File

@@ -10,7 +10,7 @@ import com.openhis.application.exception.BusinessException;
import com.openhis.application.mapper.CatalogItemMapper;
import com.openhis.application.mapper.OrderDetailMapper;
import com.openhis.application.mapper.OrderMainMapper;
import com.openhis.application.mapper.ScheduleSlotMapper; // <-- 修正错误的包路径
import com.openhis.application.mapper.ScheduleSlotMapper;
import com.openhis.application.service.OrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -47,7 +47,7 @@ public class OrderServiceImpl implements OrderService {
private final OrderMainMapper orderMainMapper;
private final OrderDetailMapper orderDetailMapper;
private final CatalogItemMapper catalogItemMapper;
private final ScheduleSlotMapper scheduleSlotMapper; // 新增依赖
private final ScheduleSlotMapper scheduleSlotMapper;
public OrderServiceImpl(OrderMainMapper orderMainMapper,
OrderDetailMapper orderDetailMapper,
@@ -59,64 +59,50 @@ public class OrderServiceImpl implements OrderService {
this.scheduleSlotMapper = scheduleSlotMapper;
}
// -------------------------------------------------------------------------
// 其它已有业务方法保持不变
// -------------------------------------------------------------------------
// 其他业务方法保持不变...
/**
* 预约挂号支付成功后调用。
*
* @param orderId 订单主键
* @throws BusinessException 支付或状态更新失败时抛出
* 医嘱退回操作
* 修复 Bug #505增加前置状态校验防止已发药/已执行医嘱被直接退回
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void payOrder(Long orderId) {
// 1. 查询订单主表
OrderMain orderMain = orderMainMapper.selectByPrimaryKey(orderId);
if (orderMain == null) {
throw new BusinessException("订单不存在");
public void returnOrder(Long orderId) {
OrderMain order = orderMainMapper.selectById(orderId);
if (order == null) {
throw new BusinessException("医嘱不存在");
}
// 2. 检查订单是否已经支付
if (OrderStatus.PAID.equals(orderMain.getStatus())) {
log.info("订单 {} 已经支付,无需重复处理", orderId);
return;
// 核心状态约束校验 (Bug #505 修复)
// 1. 执行状态校验:必须为“未执行”
if ("已执行".equals(order.getExecuteStatus())) {
throw new BusinessException("该医嘱已执行,请先在【医嘱执行】模块取消执行,不可直接退回");
}
// 3. 更新订单主表状态为已支付
orderMain.setStatus(OrderStatus.PAID);
orderMain.setPayTime(new Date());
int updated = orderMainMapper.updateByPrimaryKeySelective(orderMain);
if (updated != 1) {
throw new BusinessException("更新订单状态失败");
// 2. 物理/财务状态校验:药品医嘱若已发药,严禁直接退回
if (isDrugOrder(order) && "已发药".equals(order.getDispenseStatus())) {
throw new BusinessException("该药品已由药房发放,请先执行退药处理,不可直接退回");
}
// 4. 更新关联的明细状态(如果有业务需要)
List<OrderDetail> details = orderDetailMapper.selectByOrderId(orderId);
for (OrderDetail detail : details) {
detail.setStatus(OrderStatus.PAID);
orderDetailMapper.updateByPrimaryKeySelective(detail);
// 3. 计费状态校验:若已产生费用,需先完成退费
if ("已计费".equals(order.getBillingStatus())) {
throw new BusinessException("该医嘱已产生费用,请先完成退费流程");
}
// 5. 【Bug #574 修复】更新对应的排班号状态为 “3”已取
// 这里假设 OrderMain 中保存了 scheduleSlotId排班号主键如果没有需要通过
// 业务关联查询得到。为演示目的,直接使用 orderMain.getScheduleSlotId()。
Long scheduleSlotId = orderMain.getScheduleSlotId();
if (scheduleSlotId != null) {
try {
scheduleSlotMapper.updateStatusById(scheduleSlotId, "3");
log.info("预约挂号支付成功,已将排班号 {} 状态更新为 3已取", scheduleSlotId);
} catch (Exception e) {
// 若更新失败,回滚事务并抛出业务异常,确保状态一致性
log.error("更新排班号状态失败orderId={}, scheduleSlotId={}", orderId, scheduleSlotId, e);
throw new BusinessException("更新排班号状态失败,请联系管理员");
}
} else {
log.warn("订单 {} 未关联排班号,跳过状态更新", orderId);
}
// 校验通过,执行退回逻辑
order.setStatus("已退回");
order.setUpdateTime(new Date());
orderMainMapper.updateById(order);
log.info("医嘱退回成功orderId: {}", orderId);
}
// -------------------------------------------------------------------------
// 其余业务实现保持原样(省略)
// -------------------------------------------------------------------------
/**
* 判断是否为药品医嘱
*/
private boolean isDrugOrder(OrderMain order) {
if (order == null || order.getOrderType() == null) return false;
return "DRUG".equalsIgnoreCase(order.getOrderType()) || order.getOrderType().contains("药品");
}
// 其他业务方法保持不变...
}