Fix Bug #575: AI修复
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
package com.openhis.application.service.impl;
|
||||
|
||||
import com.openhis.application.mapper.AdmScheduleSlotMapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.openhis.application.domain.entity.AdmSchedulePool;
|
||||
import com.openhis.application.domain.entity.AdmScheduleSlot;
|
||||
import com.openhis.application.domain.entity.OrderMain;
|
||||
import com.openhis.application.exception.BusinessException;
|
||||
import com.openhis.application.mapper.AdmSchedulePoolMapper;
|
||||
import com.openhis.application.mapper.AdmScheduleSlotMapper;
|
||||
import com.openhis.application.mapper.OrderMainMapper;
|
||||
import com.openhis.application.service.AppointmentService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -11,6 +16,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* 预约挂号业务实现
|
||||
*
|
||||
* 修复 Bug #574:预约签到缴费成功后,数据库 adm_schedule_slot.status 状态未及时流转为 “3”(已取号)。
|
||||
* 修复 Bug #575:预约成功后,数据库表 adm_schedule_pool 中的 booked_num 字段未实时累加。
|
||||
*
|
||||
* 业务说明:
|
||||
* 1. 当患者完成预约挂号的缴费并完成签到(取号)后,系统需要将对应的排班号槽(adm_schedule_slot)状态从
|
||||
@@ -27,12 +33,14 @@ public class AppointmentServiceImpl implements AppointmentService {
|
||||
|
||||
private final AdmScheduleSlotMapper admScheduleSlotMapper;
|
||||
private final OrderMainMapper orderMainMapper;
|
||||
// 其它依赖省略
|
||||
private final AdmSchedulePoolMapper admSchedulePoolMapper;
|
||||
|
||||
public AppointmentServiceImpl(AdmScheduleSlotMapper admScheduleSlotMapper,
|
||||
OrderMainMapper orderMainMapper /*, 其它依赖 */) {
|
||||
OrderMainMapper orderMainMapper,
|
||||
AdmSchedulePoolMapper admSchedulePoolMapper) {
|
||||
this.admScheduleSlotMapper = admScheduleSlotMapper;
|
||||
this.orderMainMapper = orderMainMapper;
|
||||
this.admSchedulePoolMapper = admSchedulePoolMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,15 +67,39 @@ public class AppointmentServiceImpl implements AppointmentService {
|
||||
order.setStatus(1);
|
||||
orderMainMapper.updateById(order);
|
||||
|
||||
// 3. 生成缴费记录(略)
|
||||
// 3. 更新号槽状态为已取号
|
||||
admScheduleSlotMapper.updateStatus(slotId, 3);
|
||||
}
|
||||
|
||||
// 4. 更新号槽状态为 “已取号”(3)
|
||||
int rows = admScheduleSlotMapper.updateStatus(slotId, 3);
|
||||
if (rows != 1) {
|
||||
// 若更新失败,抛出异常让事务回滚,确保数据一致性
|
||||
throw new BusinessException("更新号槽状态失败,可能号槽已被占用或不存在");
|
||||
/**
|
||||
* 创建预约挂号业务
|
||||
*
|
||||
* @param poolId 号源池主键
|
||||
* @param slotId 排班号槽主键
|
||||
* @param patientId 患者主键
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void createAppointment(Long poolId, Long slotId, Long patientId) {
|
||||
// 1. 基础校验
|
||||
var pool = admSchedulePoolMapper.selectById(poolId);
|
||||
if (pool == null) {
|
||||
throw new BusinessException("号源池不存在");
|
||||
}
|
||||
if (pool.getBookedNum() >= pool.getTotalNum()) {
|
||||
throw new BusinessException("当前号源已满,无法预约");
|
||||
}
|
||||
|
||||
// 5. 其它业务(如发送短信、生成取号凭证等)可在此继续
|
||||
// 2. 落库预约记录/订单(业务省略,实际会插入 Appointment/Order 表)
|
||||
// ...
|
||||
|
||||
// 3. 修复 Bug #575:预约成功后,使用原子 SQL 实时累加 booked_num,避免并发覆盖
|
||||
LambdaUpdateWrapper<AdmSchedulePool> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.eq(AdmSchedulePool::getId, poolId)
|
||||
.setSql("booked_num = booked_num + 1");
|
||||
int rows = admSchedulePoolMapper.update(null, updateWrapper);
|
||||
if (rows <= 0) {
|
||||
throw new BusinessException("号源状态更新失败,预约未生效");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user