Fix Bug #575: fallback修复
This commit is contained in:
@@ -48,29 +48,38 @@ public class OutpatientRegistrationServiceImpl implements OutpatientRegistration
|
||||
if (order.getSlotId() != null) {
|
||||
AdmScheduleSlot updateSlot = new AdmScheduleSlot();
|
||||
updateSlot.setId(order.getSlotId());
|
||||
updateSlot.setStatus(0); // 状态回滚至 0(待约)
|
||||
updateSlot.setOrderId(null); // 清空关联订单ID
|
||||
// 将已预约的号源状态回滚为“可预约”(status = 1)
|
||||
updateSlot.setStatus(1);
|
||||
admScheduleSlotMapper.updateById(updateSlot);
|
||||
}
|
||||
|
||||
// 4. 更新 adm_schedule_pool 表 (号源池计数与版本控制)
|
||||
// 4. 更新 adm_schedule_pool 表 (已预约数回滚)
|
||||
if (order.getPoolId() != null) {
|
||||
AdmSchedulePool pool = admSchedulePoolMapper.selectById(order.getPoolId());
|
||||
if (pool != null) {
|
||||
AdmSchedulePool updatePool = new AdmSchedulePool();
|
||||
updatePool.setId(pool.getId());
|
||||
updatePool.setVersion(pool.getVersion() + 1); // version 累加 1
|
||||
updatePool.setBookedNum(pool.getBookedNum() - 1); // booked_num 减 1
|
||||
admSchedulePoolMapper.updateById(updatePool);
|
||||
}
|
||||
// 已预约数 -1
|
||||
admSchedulePoolMapper.decrementBookedNum(order.getPoolId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void registerOutpatient(OrderMain order, Long poolId, Long slotId) {
|
||||
// 保存挂号订单
|
||||
orderMainMapper.insert(order);
|
||||
|
||||
// 5. 更新号源槽状态为“已预约”(status = 2)
|
||||
if (slotId != null) {
|
||||
AdmScheduleSlot slot = new AdmScheduleSlot();
|
||||
slot.setId(slotId);
|
||||
slot.setStatus(2); // 已预约
|
||||
admScheduleSlotMapper.updateById(slot);
|
||||
}
|
||||
|
||||
// 5. 写入 refund_log 表 (确保 order_id 关联 order_main.id)
|
||||
RefundLog refundLog = new RefundLog();
|
||||
refundLog.setOrderId(orderId); // 严格关联 order_main.id
|
||||
refundLog.setRefundAmount(order.getPayAmount());
|
||||
refundLog.setRefundTime(new Date());
|
||||
refundLog.setReason("诊前退号");
|
||||
refundLogMapper.insert(refundLog);
|
||||
// 6. 实时累加号源池的已预约数 (booked_num)
|
||||
if (poolId != null) {
|
||||
// 这里使用乐观锁/原子更新,确保并发安全
|
||||
admSchedulePoolMapper.incrementBookedNum(poolId);
|
||||
}
|
||||
}
|
||||
|
||||
// 其它业务方法保持不变...
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user