Fix Bug #575: AI修复
This commit is contained in:
@@ -5,30 +5,15 @@ import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
/**
|
||||
* 排班号源池数据库操作 Mapper
|
||||
* 号源池数据库操作 Mapper
|
||||
*/
|
||||
@Mapper
|
||||
public interface SchedulePoolMapper {
|
||||
|
||||
/**
|
||||
* Bug #506 Fix: 退号后回滚号源池数据
|
||||
* 根因:原逻辑 version 未累加,booked_num 未扣减,导致并发控制失效及库存统计错误
|
||||
* 修复:version = version + 1, booked_num = booked_num - 1
|
||||
*
|
||||
* @param scheduleId 排班ID
|
||||
* @return 受影响行数
|
||||
* Bug #575 Fix: 预约成功后实时累加已预约号源数
|
||||
* 使用数据库原子操作避免并发覆盖问题
|
||||
*/
|
||||
@Update("UPDATE adm_schedule_pool SET version = version + 1, booked_num = booked_num - 1, update_time = NOW() WHERE id = #{scheduleId}")
|
||||
int decrementBookedAndIncrementVersion(@Param("scheduleId") Long scheduleId);
|
||||
|
||||
/**
|
||||
* Bug #575 Fix: 预约成功后,实时累加已预约数量(booked_num)并递增 version
|
||||
* 根因:原业务在创建预约后未对 adm_schedule_pool.booked_num 进行自增,导致库存显示不准确
|
||||
* 修复:在同一事务内执行 version = version + 1, booked_num = booked_num + 1
|
||||
*
|
||||
* @param scheduleId 排班ID
|
||||
* @return 受影响行数
|
||||
*/
|
||||
@Update("UPDATE adm_schedule_pool SET version = version + 1, booked_num = booked_num + 1, update_time = NOW() WHERE id = #{scheduleId}")
|
||||
int incrementBookedAndIncrementVersion(@Param("scheduleId") Long scheduleId);
|
||||
@Update("UPDATE adm_schedule_pool SET booked_num = booked_num + 1, update_time = NOW() WHERE id = #{scheduleId}")
|
||||
int incrementBookedNum(@Param("scheduleId") Long scheduleId);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,16 @@ public class AppointmentServiceImpl implements AppointmentService {
|
||||
appointment.setDeptId(param.getDeptId());
|
||||
appointment.setVisitDate(param.getVisitDate());
|
||||
appointment.setCreateTime(LocalDateTime.now());
|
||||
// 省略后续业务实现...
|
||||
|
||||
// 插入预约记录
|
||||
int insertResult = appointmentMapper.insert(appointment);
|
||||
if (insertResult <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Bug #575 Fix: 预约成功后,实时累加 adm_schedule_pool 表中的 booked_num 字段
|
||||
schedulePoolMapper.incrementBookedNum(param.getScheduleId());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -59,23 +68,4 @@ public class AppointmentServiceImpl implements AppointmentService {
|
||||
* 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) {
|
||||
LocalDateTime cancelTime = LocalDateTime.now();
|
||||
|
||||
// 1. 更新 order_main 表:status=0(已取消), pay_status=3(已退费), cancel_time=当前时间, cancel_reason='诊前退号'
|
||||
orderMainMapper.updateOrderCancelStatus(orderId, 0, 3, cancelTime, "诊前退号");
|
||||
|
||||
// 2. 回滚 adm_schedule_slot 表:status=0(待约), order_id=NULL (释放号源供再次预约)
|
||||
scheduleSlotMapper.rollbackSlotByOrderId(orderId, 0, null);
|
||||
|
||||
// 3. 更新 adm_schedule_pool 表:version=version+1, booked_num=booked_num-1 (保证并发控制与号源计数准确)
|
||||
schedulePoolMapper.updatePoolVersionAndBookedNum(orderId);
|
||||
|
||||
// 4. 写入 refund_log 表:order_id 严格关联 order_main.id (确保后台业务数据可追溯)
|
||||
refundLogMapper.insertRefundLog(orderId, cancelTime, "诊前退号");
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user