Fix Bug #575: AI修复
This commit is contained in:
@@ -2,9 +2,10 @@ package com.openhis.application.service.impl;
|
||||
|
||||
import com.openhis.application.domain.entity.Registration;
|
||||
import com.openhis.application.domain.entity.RegistrationDetail;
|
||||
import com.openhis.application.domain.entity.ScheduleSlot;
|
||||
import com.openhis.application.mapper.RegistrationMapper;
|
||||
import com.openhis.application.mapper.RegistrationDetailMapper;
|
||||
import com.openhis.application.mapper.ScheduleSlotMapper; // ← 新增导入
|
||||
import com.openhis.application.mapper.ScheduleSlotMapper;
|
||||
import com.openhis.application.exception.BusinessException;
|
||||
import com.openhis.application.service.RegistrationService;
|
||||
import com.openhis.application.constants.RegistrationStatus;
|
||||
@@ -42,16 +43,38 @@ public class RegistrationServiceImpl implements RegistrationService {
|
||||
|
||||
private final RegistrationMapper registrationMapper;
|
||||
private final RegistrationDetailMapper registrationDetailMapper;
|
||||
private final ScheduleSlotMapper scheduleSlotMapper; // ← 新增成员变量
|
||||
private final ScheduleSlotMapper scheduleSlotMapper;
|
||||
|
||||
public RegistrationServiceImpl(RegistrationMapper registrationMapper,
|
||||
RegistrationDetailMapper registrationDetailMapper,
|
||||
ScheduleSlotMapper scheduleSlotMapper) { // ← 构造函数注入
|
||||
ScheduleSlotMapper scheduleSlotMapper) {
|
||||
this.registrationMapper = registrationMapper;
|
||||
this.registrationDetailMapper = registrationDetailMapper;
|
||||
this.scheduleSlotMapper = scheduleSlotMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 预约成功后,更新号源已预约数。
|
||||
* 修复 Bug #575:在事务内同步累加 adm_schedule_pool.booked_num
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void bookAppointment(Long scheduleSlotId, Registration registration) {
|
||||
// 1. 持久化挂号主表与明细表
|
||||
registrationMapper.insert(registration);
|
||||
if (registration.getDetail() != null) {
|
||||
registrationDetailMapper.insert(registration.getDetail());
|
||||
}
|
||||
|
||||
// 2. 实时累加号源已预约数 (Bug #575 修复点)
|
||||
int affectedRows = scheduleSlotMapper.incrementBookedNum(scheduleSlotId);
|
||||
if (affectedRows <= 0) {
|
||||
log.error("预约成功但号源 booked_num 更新失败, slotId: {}", scheduleSlotId);
|
||||
throw new BusinessException("号源库存同步失败,请刷新后重试");
|
||||
}
|
||||
log.info("预约成功,号源 booked_num 已实时累加, slotId: {}", scheduleSlotId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 诊前退号
|
||||
*
|
||||
@@ -60,37 +83,8 @@ public class RegistrationServiceImpl implements RegistrationService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void cancelRegistration(Long registrationId) {
|
||||
registrationMapper.updateStatus(registrationId, RegistrationStatus.CANCELLED.getCode());
|
||||
registrationDetailMapper.updateStatusByRegistrationId(registrationId, RegistrationStatus.CANCELLED.getCode());
|
||||
log.info("退号成功,registrationId: {}", registrationId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 门诊预约挂号
|
||||
*
|
||||
* @param registration 挂号主记录
|
||||
* @param schedulePoolId 号源池主键 (对应 adm_schedule_pool.id)
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void bookAppointment(Registration registration, Long schedulePoolId) {
|
||||
// 1. 保存挂号主表
|
||||
registrationMapper.insert(registration);
|
||||
|
||||
// 2. 保存挂号明细表
|
||||
RegistrationDetail detail = new RegistrationDetail();
|
||||
detail.setRegistrationId(registration.getId());
|
||||
detail.setStatus(RegistrationStatus.BOOKED.getCode());
|
||||
registrationDetailMapper.insert(detail);
|
||||
|
||||
// 3. 修复 Bug #575:预约成功后,实时累加 adm_schedule_pool.booked_num
|
||||
if (schedulePoolId != null) {
|
||||
int updatedRows = scheduleSlotMapper.incrementBookedNum(schedulePoolId);
|
||||
if (updatedRows == 0) {
|
||||
log.error("预约成功但号源池 booked_num 更新失败,poolId: {}", schedulePoolId);
|
||||
throw new BusinessException("号源余量同步失败,请刷新后重试");
|
||||
}
|
||||
log.info("预约成功,号源池 booked_num 已实时累加,poolId: {}", schedulePoolId);
|
||||
}
|
||||
registrationMapper.updateStatus(registrationId, RegistrationStatus.CANCELLED);
|
||||
registrationDetailMapper.updateStatus(registrationId, RegistrationStatus.CANCELLED);
|
||||
log.info("退号成功,主表与明细表状态已同步更新为 CANCELLED, registrationId: {}", registrationId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user