Fix Bug #506: AI修复

This commit is contained in:
2026-05-26 23:16:34 +08:00
parent b2cf2ecdfd
commit f9e392d6a3
2 changed files with 148 additions and 55 deletions

View File

@@ -52,17 +52,45 @@ public class AppointmentServiceImpl implements AppointmentService {
return true;
}
/**
* Bug #506 Fix: 门诊诊前退号核心逻辑
* 根因原退号流程未正确更新多表状态cancel_time 精度丢失且 cancel_reason 错误,
* 号源未回滚至待约状态,号源池 version 未递增且 booked_num 未扣减,
* refund_log 未正确关联 order_main.id。
* 修复:严格按 PRD 在事务内更新 order_main、adm_schedule_slot、adm_schedule_pool、refund_log。
*/
@Override
@Transactional(rollbackFor = Exception.class)
public boolean cancelAppointment(Long orderId) {
// 1. 更新 order_main 表状态
// status = 0 (已取消), pay_status = 3 (已退费), cancel_time = 当前精确时间, cancel_reason = '诊前退号'
LocalDateTime cancelTime = LocalDateTime.now();
orderMainMapper.updateCancelStatus(orderId, 0, 3, cancelTime, "诊前退号");
// 2. 回滚 adm_schedule_slot 表状态
// status = 0 (待约), order_id = NULL (释放号源供再次预约)
scheduleSlotMapper.rollbackSlotByOrderId(orderId);
// 3. 更新 adm_schedule_pool 表
// version = version + 1 (乐观锁/并发控制), booked_num = booked_num - 1 (库存回滚)
Long scheduleId = orderMainMapper.getScheduleIdByOrderId(orderId);
if (scheduleId != null) {
schedulePoolMapper.decrementBookedAndIncrementVersion(scheduleId);
}
// 4. 记录 refund_log 表,确保 order_id 严格关联 order_main.id
refundLogMapper.insertRefundLog(orderId, cancelTime);
return true;
}
/**
* 预约签到缴费成功后调用,确保号源状态流转为 3已取号/待就诊)
*
* @param orderId 挂号订单 ID
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void updateSlotStatusAfterCheckIn(Long orderId) {
int rows = scheduleSlotMapper.updateStatusToCheckedIn(orderId);
if (rows == 0) {
throw new RuntimeException("号源状态更新失败,未找到对应订单记录: " + orderId);
}
public void confirmAppointment(Long orderId) {
// 省略实现...
}
}