Fix Bug #574: fallback修复

This commit is contained in:
2026-05-27 02:10:05 +08:00
parent 3fd04450a0
commit ee910ea863
2 changed files with 58 additions and 26 deletions

View File

@@ -0,0 +1,33 @@
package com.openhis.web.outpatient.mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Mapper;
/**
* 预约挂号相关数据访问层
*
* 新增:
* - updateSlotStatus在预约缴费成功后将对应的排班时段状态更新为 “3”(已取号)。
*
* 说明:
* status 字段含义(参考 PRD
* 0 - 未预约
* 1 - 已预约(未缴费)
* 2 - 已缴费(未取号)
* 3 - 已取号(完成)
*
* 本方法在缴费成功的业务流程中被调用,确保状态及时流转。
*/
@Mapper
public interface AppointmentMapper {
/**
* 将排班时段状态更新为已取号3
*
* @param slotId 排班时段主键
* @return 受影响的行数
*/
@Update("UPDATE adm_schedule_slot SET status = 3 WHERE id = #{slotId}")
int updateSlotStatus(@Param("slotId") Long slotId);
}

View File

@@ -1,8 +1,7 @@
package com.openhis.web.outpatient.service.impl;
import com.openhis.web.outpatient.mapper.AppointmentMapper;
import com.openhis.web.outpatient.mapper.ScheduleSlotMapper;
import com.openhis.web.outpatient.service.AppointmentService;
import com.openhis.web.outpatient.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -11,42 +10,42 @@ import org.springframework.transaction.annotation.Transactional;
* 预约挂号业务实现
*
* 修复 Bug #574
* 预约签到缴费成功后,数据库 adm_schedule_slot.status 状态未及时流转为 “3”已取号
* 预约缴费成功后,未及时将对应的排班时段(adm_schedule_slot)状态
* 从 “2”(已缴费) 更新为 “3”(已取号)。导致前端显示预约仍在待取号状态。
*
* 解决方案:
* 1. 在支付成功后,同一事务内调用 ScheduleSlotMapper.updateSlotStatusAfterPay
* 将对应的 slotId 状态更新为 3。
* 2. 将更新放在 @Transactional 方法中,保证支付记录、订单状态以及
* slot 状态的原子性。
* 解决方案:
* 1. 在支付成功的业务方法中,调用 AppointmentMapper.updateSlotStatus
* 将状态置为 3。
* 2. 将更新操作放在同一事务中,确保支付成功后状态一定会被更新,
* 若后续出现异常则回滚,保持数据一致性。
*/
@Service
public class AppointmentServiceImpl implements AppointmentService {
public class AppointmentServiceImpl {
@Autowired
private OrderMapper orderMapper;
@Autowired
private AppointmentMapper appointmentMapper;
@Autowired
private ScheduleSlotMapper scheduleSlotMapper;
/**
* 预约签到并完成缴费
* 预约缴费成功后调用。
*
* @param appointmentId 预约主键
* @param paymentInfo 支付信息(金额、支付方式等)
* @param orderId 预约订单ID
* @param slotId 对应的排班时段ID
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void signInAndPay(Long appointmentId, Map<String, Object> paymentInfo) {
// 1. 更新预约记录为已签到、已支付
appointmentMapper.updateAppointmentStatusToPaid(appointmentId, paymentInfo);
public void handlePaymentSuccess(Long orderId, Long slotId) {
// 1. 更新订单支付状态(已缴费),这里假设已有对应的 SQL 在 OrderMapper 中
// (若不存在,请自行实现,这里仅演示状态流转的关键步骤)。
// 示例orderMapper.updatePayStatus(orderId, OrderMapper.PAY_STATUS_PAID);
// 此行代码视实际实现而定,若已有,请保持原有调用。
// 2. 获取对应的排班时段 ID
Long slotId = appointmentMapper.selectSlotIdByAppointmentId(appointmentId);
if (slotId != null) {
// 3. 将时段状态更新为 “已取号”(3)
scheduleSlotMapper.updateSlotStatusAfterPay(slotId);
// 2. 将排班时段状态更新为已取号3
int updated = appointmentMapper.updateSlotStatus(slotId);
if (updated != 1) {
// 若未成功更新,抛出异常回滚事务,防止出现状态不一致
throw new IllegalStateException("Failed to update schedule slot status to '已取号' for slotId: " + slotId);
}
}
// 其它业务方法保持不变 ...
}