diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/mapper/AppointmentMapper.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/mapper/AppointmentMapper.java index ead5e0f42..07e81784e 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/mapper/AppointmentMapper.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/mapper/AppointmentMapper.java @@ -10,6 +10,7 @@ import org.apache.ibatis.annotations.Mapper; * 新增: * - updateSlotStatus:在预约缴费成功后,将对应的排班时段状态更新为 “3”(已取号)。 * - resetSlotStatus:在门诊诊前退号(取消预约)后,将对应的排班时段状态恢复为 “1”(已预约)。 + * - incrementBookedNum:在预约成功后,实时累加排班池(adm_schedule_pool)中的 booked_num。 * * 说明: * status 字段含义(参考 PRD): @@ -41,4 +42,18 @@ public interface AppointmentMapper { */ @Update("UPDATE adm_schedule_slot SET status = 1 WHERE id = #{slotId}") int resetSlotStatus(@Param("slotId") Long slotId); + + /** + * 预约成功后,实时累加对应排班池的已预约人数(booked_num)。 + * 通过 slotId 关联到 adm_schedule_pool 表的 id(pool_id)。 + * + * @param slotId 排班时段主键 + * @return 受影响的行数 + */ + @Update({ + "UPDATE adm_schedule_pool", + "SET booked_num = booked_num + 1", + "WHERE id = (SELECT pool_id FROM adm_schedule_slot WHERE id = #{slotId})" + }) + int incrementBookedNum(@Param("slotId") Long slotId); } diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/service/impl/AppointmentServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/service/impl/AppointmentServiceImpl.java index dadacbb5a..cb787f532 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/service/impl/AppointmentServiceImpl.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/service/impl/AppointmentServiceImpl.java @@ -18,6 +18,11 @@ import org.springframework.transaction.annotation.Transactional; * 将状态置为 3。 * 2. 将该更新操作放在同一事务中,确保支付成功后状态一定会被更新, * 若后续出现异常则回滚,保持数据一致性。 + * + * 新增修复 Bug #575: + * 预约成功后,adm_schedule_pool 表的 booked_num 未实时累加,导致排班容量统计不准确。 + * 在支付成功的同一事务中,调用 AppointmentMapper.incrementBookedNum + * 对对应的排班池进行原子递增。 */ @Service public class AppointmentServiceImpl { @@ -48,5 +53,12 @@ public class AppointmentServiceImpl { // 若未成功更新,抛出异常回滚事务,防止出现状态不一致 throw new IllegalStateException("Failed to update schedule slot status to '已取号' for slotId: " + slotId); } + + // 3. 实时累加排班池已预约人数(booked_num) + int poolUpdated = appointmentMapper.incrementBookedNum(slotId); + if (poolUpdated != 1) { + // 若未成功更新,抛出异常回滚事务,确保预约人数统计准确 + throw new IllegalStateException("Failed to increment booked_num for schedule pool related to slotId: " + slotId); + } } }