Fix Bug #575: AI修复
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
package com.openhis.application.service.impl;
|
||||
|
||||
import com.openhis.application.domain.entity.Registration;
|
||||
import com.openhis.application.domain.entity.RegistrationDetail;
|
||||
import com.openhis.application.mapper.RegistrationMapper;
|
||||
import com.openhis.application.mapper.RegistrationDetailMapper;
|
||||
import com.openhis.application.mapper.ScheduleSlotMapper; // ← 新增导入
|
||||
import com.openhis.application.exception.BusinessException;
|
||||
import com.openhis.application.service.RegistrationService;
|
||||
import com.openhis.application.constants.RegistrationStatus;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 门诊挂号业务实现
|
||||
*
|
||||
* 修复 Bug #506:门诊诊前退号后,数据库多表状态值变更与 PRD 定义不符。
|
||||
*
|
||||
* 退号业务需要同时更新以下表的状态:
|
||||
* 1. registration_main → status = "CANCELLED"
|
||||
* 2. registration_detail → status = "CANCELLED"
|
||||
*
|
||||
* 之前的实现只更新了 registration_main 表,导致 registration_detail
|
||||
* 仍保持原来的 “REGISTERED” 状态,与产品需求不一致,进而在后续查询、统计
|
||||
* 以及对账时出现数据不一致的问题。
|
||||
*
|
||||
* 本次修复在同一事务内统一更新两张表,并使用统一的状态常量
|
||||
* {@link RegistrationStatus#CANCELLED},确保所有相关记录的状态保持同步。
|
||||
*
|
||||
* 另外,修复 Bug #575:预约成功后,adm_schedule_pool 表中的 booked_num
|
||||
* 未实时累加。新增对 ScheduleSlot(对应 adm_schedule_pool)的已预约数
|
||||
* 增量更新,确保前端查询可立即得到最新的可预约余量。
|
||||
*/
|
||||
@Service
|
||||
public class RegistrationServiceImpl implements RegistrationService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(RegistrationServiceImpl.class);
|
||||
|
||||
private final RegistrationMapper registrationMapper;
|
||||
private final RegistrationDetailMapper registrationDetailMapper;
|
||||
private final ScheduleSlotMapper scheduleSlotMapper; // ← 新增成员变量
|
||||
|
||||
public RegistrationServiceImpl(RegistrationMapper registrationMapper,
|
||||
RegistrationDetailMapper registrationDetailMapper,
|
||||
ScheduleSlotMapper scheduleSlotMapper) { // ← 构造函数注入
|
||||
this.registrationMapper = registrationMapper;
|
||||
this.registrationDetailMapper = registrationDetailMapper;
|
||||
this.scheduleSlotMapper = scheduleSlotMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 诊前退号
|
||||
*
|
||||
* @param registrationId 挂号主键
|
||||
*/
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user