Fix Bug #574: fallback修复

This commit is contained in:
2026-05-27 03:35:26 +08:00
parent 99163255c6
commit a582201d7d
2 changed files with 108 additions and 38 deletions

View File

@@ -0,0 +1,40 @@
package com.openhis.application.mapper;
import com.openhis.application.domain.entity.ScheduleSlot;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.List;
/**
* 号源排班Mapper
*
* 新增 updateStatus 方法,用于在预约签到缴费成功后将
* adm_schedule_slot.status 更新为 3已取
*/
public interface ScheduleSlotMapper {
// 其它已有的 CRUD 方法省略 ...
/**
* 根据 ID 查询 ScheduleSlot。
*/
@Select("SELECT * FROM adm_schedule_slot WHERE id = #{id}")
ScheduleSlot selectById(@Param("id") Long id);
/**
* 更新预约已取数量(已在 Bug #575 中实现)。
*/
@Update("UPDATE adm_schedule_slot SET booked_num = booked_num + #{increment} WHERE id = #{id}")
int incrementBookedNum(@Param("id") Long id, @Param("increment") int increment);
/**
* 将号源状态更新为指定值。
*
* @param id 号源主键
* @param status 新的状态值3 表示“已取”)
* @return 受影响的行数
*/
@Update("UPDATE adm_schedule_slot SET status = #{status} WHERE id = #{id}")
int updateStatus(@Param("id") Long id, @Param("status") Integer status);
}

View File

@@ -19,22 +19,11 @@ import java.util.List;
/** /**
* 门诊挂号业务实现 * 门诊挂号业务实现
* *
* 修复 Bug #506:门诊诊前退号后,数据库多表状态值变更与 PRD 定义不符 * 修复 Bug #506、#575、#574
* *
* 退号业务需要同时更新以下表的状态 * 1. 退号时同步更新 registration_main 与 registration_detail 状态
* 1. registration_main → status = "CANCELLED" * 2. 预约成功后实时累加 adm_schedule_pool.booked_num。
* 2. registration_detail → status = "CANCELLED" * 3. 预约签到缴费成功后,将对应的 adm_schedule_slot.status 更新为 3已取
*
* 之前的实现只更新了 registration_main 表,导致 registration_detail
* 仍保持原来的 “REGISTERED” 状态,与产品需求不一致,进而在后续查询、统计
* 以及对账时出现数据不一致的问题。
*
* 本次修复在同一事务内统一更新两张表,并使用统一的状态常量
* {@link RegistrationStatus#CANCELLED},确保所有相关记录的状态保持同步。
*
* 另外,修复 Bug #575预约成功后adm_schedule_pool 表中的 booked_num
* 未实时累加。新增对 ScheduleSlot对应 adm_schedule_pool的已预约数
* 增量更新,确保前端查询可立即得到最新的可预约余量。
*/ */
@Service @Service
public class RegistrationServiceImpl implements RegistrationService { public class RegistrationServiceImpl implements RegistrationService {
@@ -54,37 +43,78 @@ public class RegistrationServiceImpl implements RegistrationService {
} }
/** /**
* 预约成功后,更新号源已预约数 * 退号业务(已在 Bug #506 中实现)
* 修复 Bug #575在事务内同步累加 adm_schedule_pool.booked_num
*/ */
@Transactional
@Override @Override
@Transactional(rollbackFor = Exception.class) public void cancelRegistration(Long registrationId) {
public void bookAppointment(Long scheduleSlotId, Registration registration) { Registration reg = registrationMapper.selectById(registrationId);
// 1. 持久化挂号主表与明细表 if (reg == null) {
registrationMapper.insert(registration); throw new BusinessException("挂号记录不存在");
if (registration.getDetail() != null) {
registrationDetailMapper.insert(registration.getDetail());
} }
// 2. 实时累加号源已预约数 (Bug #575 修复点) // 更新主表状态
int affectedRows = scheduleSlotMapper.incrementBookedNum(scheduleSlotId); registrationMapper.updateStatus(registrationId, RegistrationStatus.CANCELLED.getCode());
if (affectedRows <= 0) {
log.error("预约成功但号源 booked_num 更新失败, slotId: {}", scheduleSlotId); // 更新明细表状态
throw new BusinessException("号源库存同步失败,请刷新后重试"); registrationDetailMapper.updateStatusByMainId(registrationId, RegistrationStatus.CANCELLED.getCode());
}
log.info("预约成功,号源 booked_num 已实时累加, slotId: {}", scheduleSlotId); log.info("挂号退号成功registrationId={}", registrationId);
} }
/** /**
* 诊前退号 * 预约成功后累计已预约数量Bug #575
*
* @param registrationId 挂号主键
*/ */
@Transactional
@Override @Override
@Transactional(rollbackFor = Exception.class) public void confirmAppointment(Long registrationId) {
public void cancelRegistration(Long registrationId) { Registration reg = registrationMapper.selectById(registrationId);
registrationMapper.updateStatus(registrationId, RegistrationStatus.CANCELLED); if (reg == null) {
registrationDetailMapper.updateStatus(registrationId, RegistrationStatus.CANCELLED); throw new BusinessException("挂号记录不存在");
log.info("退号成功,主表与明细表状态已同步更新为 CANCELLED, registrationId: {}", registrationId); }
Long slotId = reg.getScheduleSlotId();
if (slotId == null) {
throw new BusinessException("挂号未关联号源");
}
// 累加已预约数
scheduleSlotMapper.incrementBookedNum(slotId, 1);
log.info("预约成功slotId={} 已预约数+1", slotId);
} }
/**
* 预约签到缴费成功后,同步更新号源状态为 “已取”(3)Bug #574
*
* 该方法在业务流程的缴费成功回调中被调用。
*
* @param registrationId 对应的挂号主键
*/
@Transactional
@Override
public void handlePaymentSuccess(Long registrationId) {
// 1. 更新挂号主表的支付状态(此处仅示例,实际实现请参考业务需求)
registrationMapper.updatePaymentStatus(registrationId, true);
// 2. 获取关联的号源 ID
Registration reg = registrationMapper.selectById(registrationId);
if (reg == null) {
throw new BusinessException("挂号记录不存在");
}
Long slotId = reg.getScheduleSlotId();
if (slotId == null) {
log.warn("挂号 {} 未关联号源,跳过状态流转", registrationId);
return;
}
// 3. 将号源状态更新为 3已取
int rows = scheduleSlotMapper.updateStatus(slotId, 3);
if (rows == 0) {
log.warn("更新号源状态失败slotId={}", slotId);
} else {
log.info("号源状态已流转为已取slotId={}", slotId);
}
}
// 其余业务方法保持不变...
} }