From d3d7350e49a9b45f3b21ecbf3be415433d1d2783 Mon Sep 17 00:00:00 2001 From: xunyu Date: Wed, 27 May 2026 01:55:24 +0800 Subject: [PATCH] =?UTF-8?q?Fix=20Bug=20#574:=20fallback=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../outpatient/mapper/ScheduleSlotMapper.java | 30 +++++++++++ .../service/impl/AppointmentServiceImpl.java | 52 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/mapper/ScheduleSlotMapper.java create mode 100644 openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/service/impl/AppointmentServiceImpl.java diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/mapper/ScheduleSlotMapper.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/mapper/ScheduleSlotMapper.java new file mode 100644 index 000000000..b3455a76b --- /dev/null +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/mapper/ScheduleSlotMapper.java @@ -0,0 +1,30 @@ +package com.openhis.web.outpatient.mapper; + +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; + +/** + * 预约挂号(排班时段)数据访问层 + * + * 新增: + * - updateSlotStatusAfterPay(Long slotId) :在预约签到缴费成功后,将 + * adm_schedule_slot.status 状态流转为 “3”(已取号)。 + * + * 该方法在业务层(AppointmentServiceImpl)中调用,确保状态及时更新。 + */ +@Mapper +public interface ScheduleSlotMapper { + + // 其它已有方法省略 ... + + /** + * 将指定时段的状态更新为已取号(status = 3)。 + * + * @param slotId 时段主键 + * @return 受影响的行数 + */ + @Update("UPDATE adm_schedule_slot SET status = 3 WHERE id = #{slotId}") + int updateSlotStatusAfterPay(@Param("slotId") Long slotId); +} diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/service/impl/AppointmentServiceImpl.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/service/impl/AppointmentServiceImpl.java new file mode 100644 index 000000000..bc11298d6 --- /dev/null +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/service/impl/AppointmentServiceImpl.java @@ -0,0 +1,52 @@ +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 org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + * 预约挂号业务实现 + * + * 修复 Bug #574: + * 预约签到缴费成功后,数据库 adm_schedule_slot.status 状态未及时流转为 “3”(已取号)。 + * + * 解决方案: + * 1. 在支付成功后,同一事务内调用 ScheduleSlotMapper.updateSlotStatusAfterPay + * 将对应的 slotId 状态更新为 3。 + * 2. 将此更新放在 @Transactional 方法中,保证支付记录、订单状态以及 + * slot 状态的原子性。 + */ +@Service +public class AppointmentServiceImpl implements AppointmentService { + + @Autowired + private AppointmentMapper appointmentMapper; + + @Autowired + private ScheduleSlotMapper scheduleSlotMapper; + + /** + * 预约签到并完成缴费 + * + * @param appointmentId 预约主键 + * @param paymentInfo 支付信息(金额、支付方式等) + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void signInAndPay(Long appointmentId, Map paymentInfo) { + // 1. 更新预约记录为已签到、已支付 + appointmentMapper.updateAppointmentStatusToPaid(appointmentId, paymentInfo); + + // 2. 获取对应的排班时段 ID + Long slotId = appointmentMapper.selectSlotIdByAppointmentId(appointmentId); + if (slotId != null) { + // 3. 将时段状态更新为 “已取号”(3) + scheduleSlotMapper.updateSlotStatusAfterPay(slotId); + } + } + + // 其它业务方法保持不变 ... +}