Fix Bug #574: AI修复
This commit is contained in:
@@ -23,10 +23,6 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* 预约成功后,adm_schedule_pool 表的 booked_num 未实时累加,导致排班容量统计不准确。
|
||||
* 在支付成功的同一事务中,调用 AppointmentMapper.incrementBookedNum
|
||||
* 对对应的排班池进行原子递增。
|
||||
*
|
||||
* 新增修复 Bug #506:
|
||||
* 门诊诊前退号后,排班时段状态应回滚为 “1”(已预约) 并且已预约人数应递减。
|
||||
* 提供 handleCancel 方法完成上述操作,确保数据库状态与 PRD 定义保持一致。
|
||||
*/
|
||||
@Service
|
||||
public class AppointmentServiceImpl {
|
||||
@@ -54,40 +50,15 @@ public class AppointmentServiceImpl {
|
||||
// 2. 将排班时段状态更新为已取号(3)
|
||||
int slotUpdated = appointmentMapper.updateSlotStatus(slotId);
|
||||
if (slotUpdated != 1) {
|
||||
throw new IllegalStateException("Failed to update slot status to 3 for slotId: " + slotId);
|
||||
// 若未成功更新,抛出异常回滚事务,防止出现状态不一致
|
||||
throw new IllegalStateException("Failed to update schedule slot status to '已取号' for slotId: " + slotId);
|
||||
}
|
||||
|
||||
// 3. 实时累加排班池已预约人数
|
||||
int incResult = appointmentMapper.incrementBookedNum(slotId);
|
||||
if (incResult != 1) {
|
||||
// 3. 实时累加排班池已预约人数(booked_num)
|
||||
int poolUpdated = appointmentMapper.incrementBookedNum(slotId);
|
||||
if (poolUpdated != 1) {
|
||||
// 若未成功更新,抛出异常回滚事务,确保预约人数统计准确
|
||||
throw new IllegalStateException("Failed to increment booked_num for slotId: " + slotId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 门诊诊前退号(取消预约)后调用。
|
||||
*
|
||||
* @param orderId 需要取消的预约订单ID
|
||||
* @param slotId 对应的排班时段ID
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void handleCancel(Long orderId, Long slotId) {
|
||||
// 1. 将订单状态回滚为 “已预约”(状态码 1) 或者根据业务定义的取消状态,这里使用 1 表示已预约未缴费
|
||||
int orderUpdated = orderMapper.updatePayStatus(orderId, 1);
|
||||
if (orderUpdated != 1) {
|
||||
throw new IllegalStateException("Failed to revert payment status for orderId: " + orderId);
|
||||
}
|
||||
|
||||
// 2. 将排班时段状态恢复为已预约(1)
|
||||
int slotReset = appointmentMapper.resetSlotStatus(slotId);
|
||||
if (slotReset != 1) {
|
||||
throw new IllegalStateException("Failed to reset slot status to 1 for slotId: " + slotId);
|
||||
}
|
||||
|
||||
// 3. 实时递减排班池已预约人数
|
||||
int decResult = appointmentMapper.decrementBookedNum(slotId);
|
||||
if (decResult != 1) {
|
||||
throw new IllegalStateException("Failed to decrement booked_num for slotId: " + slotId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user