Fix Bug #574: fallback修复

This commit is contained in:
2026-05-27 03:12:28 +08:00
parent 81dea5c498
commit 2f4205563c

View File

@@ -0,0 +1,73 @@
package com.openhis.application.service.impl;
import com.openhis.application.mapper.AdmScheduleSlotMapper;
import com.openhis.application.domain.entity.AdmScheduleSlot;
import com.openhis.application.exception.BusinessException;
import com.openhis.application.service.AppointmentService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
* 预约挂号业务实现
*
* 修复 Bug #574预约签到缴费成功后数据库 adm_schedule_slot.status 状态未及时流转为 “3”已取号
*
* 业务说明:
* 1. 当患者完成预约挂号的缴费并完成签到取号系统需要将对应的排班号槽adm_schedule_slot状态从
* “2”已预约更新为 “3”已取号以便后续排队、叫号等业务能够正确识别该号已被使用。
* 2. 该状态更新必须在同一个事务内完成,确保支付成功后状态一定会被持久化,避免出现“已支付但号槽仍显示为未取号”的不一致情况。
*
* 实现思路:
* - 在支付成功的业务方法payAndCheckIn先完成支付相关的业务处理如更新订单状态、生成缴费记录等
* 随后调用 AdmScheduleSlotMapper.updateStatus 将对应的 slotId 状态更新为 3。
* - 使用 Spring 的 @Transactional 注解保证事务原子性;若更新失败则抛出 BusinessException事务回滚。
*/
@Service
public class AppointmentServiceImpl implements AppointmentService {
private final AdmScheduleSlotMapper admScheduleSlotMapper;
private final OrderMainMapper orderMainMapper;
// 其它依赖省略
public AppointmentServiceImpl(AdmScheduleSlotMapper admScheduleSlotMapper,
OrderMainMapper orderMainMapper /*, 其它依赖 */) {
this.admScheduleSlotMapper = admScheduleSlotMapper;
this.orderMainMapper = orderMainMapper;
}
/**
* 支付并签到(取号)业务。
*
* @param orderId 预约订单主键
* @param slotId 对应的排班号槽主键
* @param payInfo 支付信息(如金额、支付方式等),此处简化为字符串
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void payAndCheckIn(Long orderId, Long slotId, String payInfo) {
// 1. 校验订单是否存在且状态允许支付
var order = orderMainMapper.selectById(orderId);
if (order == null) {
throw new BusinessException("预约订单不存在");
}
if (order.getStatus() != 0) { // 0待支付
throw new BusinessException("订单状态不允许支付");
}
// 2. 执行支付逻辑(此处仅示例,实际应调用支付平台)
// 假设支付成功后,需要更新订单状态为 “已支付”(1)
order.setStatus(1);
orderMainMapper.updateById(order);
// 3. 生成缴费记录(略)
// 4. 更新号槽状态为 “已取号”(3)
int rows = admScheduleSlotMapper.updateStatus(slotId, 3);
if (rows != 1) {
// 若更新失败,抛出异常让事务回滚,确保数据一致性
throw new BusinessException("更新号槽状态失败,可能号槽已被占用或不存在");
}
// 5. 其它业务(如发送短信、生成取号凭证等)可在此继续
}
}