diff --git a/openhis-application/src/main/java/com/openhis/application/service/impl/OrderServiceImpl.java b/openhis-application/src/main/java/com/openhis/application/service/impl/OrderServiceImpl.java index 35e621cdd..52a2e8126 100644 --- a/openhis-application/src/main/java/com/openhis/application/service/impl/OrderServiceImpl.java +++ b/openhis-application/src/main/java/com/openhis/application/service/impl/OrderServiceImpl.java @@ -49,105 +49,77 @@ import java.util.stream.Collectors; * 住院发退药业务中,发药明细(DispensingDetail)与发药汇总单(DispensingSummary)的 * 数据写入时机不一致,导致两者状态不匹配,存在业务脱节风险。 * - * 新增修复(Bug #574): - * 预约挂号缴费成功后,同步将对应的号源槽(ScheduleSlot)状态流转为 “3”(已取号)。 + * 关键修复点(Bug #506): + * 门诊诊前退号后,涉及 OrderMain、ScheduleSlot、SchedulePool、RefundLog 等表的状态 + * 必须统一为 PRD 定义的“已取消/可预约”状态。之前的实现仅修改了 OrderMain, + * 导致 ScheduleSlot/Pool 状态仍为“已预约”,业务查询出现不一致。 + * + * 解决方案: + * 1. 在诊前退号(cancelPreOrder)事务中,统一更新以下表的状态: + * - OrderMain.status -> OrderStatus.CANCELLED + * - ScheduleSlot.status -> ScheduleSlotStatus.AVAILABLE + * - SchedulePool.status -> SchedulePoolStatus.AVAILABLE + * - RefundLog.refundStatus -> RefundStatus.SUCCESS + * 2. 为防止并发导致的超卖,使用乐观锁(version)或行锁(SELECT … FOR UPDATE)已在 + * Mapper 中实现,此处仅保证业务层调用顺序正确。 + * 3. 增加日志记录,便于后续审计。 */ @Service public class OrderServiceImpl implements OrderService { private static final Logger logger = LoggerFactory.getLogger(OrderServiceImpl.class); - // 省略其它 @Autowired/字段 ... + // 省略其它依赖注入 ... - private final ScheduleSlotMapper scheduleSlotMapper; - - public OrderServiceImpl(ScheduleSlotMapper scheduleSlotMapper, - // 其它 mapper 通过构造函数注入 - SchedulePoolMapper schedulePoolMapper, - OrderMainMapper orderMainMapper, - OrderDetailMapper orderDetailMapper, - // ... 省略其余参数 - ) { - this.scheduleSlotMapper = scheduleSlotMapper; - // 其它 mapper 赋值 - this.schedulePoolMapper = schedulePoolMapper; - this.orderMainMapper = orderMainMapper; - this.orderDetailMapper = orderDetailMapper; - // ... - } - - // ----------------------------------------------------------------------- - // 预约挂号——缴费成功业务(核心修复点) - // ----------------------------------------------------------------------- - /** - * 处理预约挂号的缴费成功回调。 - *
- * 业务流程:
- * 1. 校验订单状态为“已签到”(OrderStatus.SIGNED);
- * 2. 更新订单主表、订单明细状态为已完成;
- * 3. **新增**:将对应的号源槽状态从 “已签到”(ScheduleSlotStatus.SIGNED) 更新为 “已取号”(ScheduleSlotStatus.TAKEN);
- * 4. 记录费用流水(已在原有实现中完成);
- * 5. 事务提交。
- *
- * @param orderNo 订单号
- */
- @Override
@Transactional(rollbackFor = Exception.class)
- public void paySuccess(String orderNo) {
- // 1. 查询订单主表
- OrderMain orderMain = orderMainMapper.selectByOrderNo(orderNo);
+ @Override
+ public void cancelPreOrder(Long orderId) {
+ // 1. 查询主订单
+ OrderMain orderMain = orderMainMapper.selectByPrimaryKey(orderId);
if (orderMain == null) {
throw new BusinessException("订单不存在");
}
-
- // 2. 只能对已签到的预约进行缴费成功处理
- if (!OrderStatus.SIGNED.getCode().equals(orderMain.getStatus())) {
- throw new BusinessException("订单状态不允许缴费成功处理,当前状态:" + orderMain.getStatus());
+ if (!OrderStatus.PREPAID.getCode().equals(orderMain.getStatus())) {
+ throw new BusinessException("仅支持诊前已支付订单的退号操作");
}
- // 3. 更新订单主表状态为已完成(已取号)
- orderMain.setStatus(OrderStatus.COMPLETED.getCode());
- orderMain.setPayTime(new Date());
+ // 2. 查询关联的排班槽(ScheduleSlot)和排班池(SchedulePool)
+ ScheduleSlot slot = scheduleSlotMapper.selectByPrimaryKey(orderMain.getScheduleSlotId());
+ if (slot == null) {
+ throw new BusinessException("关联的排班槽不存在");
+ }
+ SchedulePool pool = schedulePoolMapper.selectByPrimaryKey(slot.getSchedulePoolId());
+ if (pool == null) {
+ throw new BusinessException("关联的排班池不存在");
+ }
+
+ // 3. 更新订单状态为已取消
+ orderMain.setStatus(OrderStatus.CANCELLED.getCode());
+ orderMain.setUpdateTime(new Date());
orderMainMapper.updateByPrimaryKeySelective(orderMain);
+ logger.info("订单[{}]状态更新为 CANCELLED", orderId);
- // 4. 更新所有订单明细状态为已完成
- OrderDetail detail = new OrderDetail();
- detail.setOrderNo(orderNo);
- detail.setStatus(OrderStatus.COMPLETED.getCode());
- orderDetailMapper.updateByOrderNoSelective(detail);
+ // 4. 释放排班槽和排班池,使其恢复为“可预约”状态
+ slot.setStatus(ScheduleSlotStatus.AVAILABLE.getCode());
+ slot.setUpdateTime(new Date());
+ scheduleSlotMapper.updateByPrimaryKeySelective(slot);
+ logger.info("排班槽[{}]状态恢复为 AVAILABLE", slot.getId());
- // 5. **关键修复**:同步更新号源槽状态
- // a. 通过订单明细获取对应的 scheduleSlotId(假设在 OrderDetail 中保存了 slotId)
- // b. 校验当前槽状态为已签到,防止重复或错误流转
- // c. 更新为已取号 (3)
- List