From fe0ff7ffdcff748c2e9bd37548c187c039176ca4 Mon Sep 17 00:00:00 2001 From: xunyu Date: Wed, 27 May 2026 02:40:53 +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/AppointmentMapper.java | 45 +++++++------- .../outpatient/mapper/ScheduleSlotMapper.java | 20 +++--- .../service/AppointmentService.java | 61 +++++++++++++++---- 3 files changed, 79 insertions(+), 47 deletions(-) diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/mapper/AppointmentMapper.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/mapper/AppointmentMapper.java index 1ed77e260..fb6f67cc7 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/mapper/AppointmentMapper.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/mapper/AppointmentMapper.java @@ -1,40 +1,43 @@ package com.openhis.web.outpatient.mapper; -import org.apache.ibatis.annotations.*; -import java.util.List; -import java.util.Map; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; +import org.apache.ibatis.annotations.Update; /** - * 预约挂号数据访问层 + * 预约(his_appointment)数据访问层 * - * 新增方法用于门诊诊前退号(取消预约)后,恢复排班时段状态并同步更新排班池已预约人数。 - * 与 PRD 定义保持一致: - * - 订单状态更新为 “已取消”(状态码 4) - * - 对应的 adm_schedule_slot.status 设为 “1”(可预约) - * - 对应的 adm_schedule_pool.booked_num -1 + * 新增查询对应排班槽ID的方法,配合 Bug #574 的状态同步。 */ @Mapper public interface AppointmentMapper { - // 现有方法省略 ... + /** + * 检查预约是否可以缴费(状态为未缴费且未取消) + * + * @param appointmentId 预约ID + * @return 可缴费记录数 + */ + @Select("SELECT COUNT(1) FROM his_appointment WHERE id = #{appointmentId} AND pay_status = 0 AND cancel_flag = 0") + Integer checkCanPay(@Param("appointmentId") Long appointmentId); /** - * 更新排班时段状态 + * 更新预约的缴费信息 * - * @param slotId 时段ID - * @param status 新状态值 (1: 可预约, 2: 已缴费, 3: 已取号) + * @param appointmentId 预约ID + * @param payAmount 实际缴费金额 * @return 受影响行数 */ - @Update("UPDATE adm_schedule_slot SET status = #{status} WHERE id = #{slotId}") - int updateSlotStatus(@Param("slotId") Long slotId, @Param("status") Integer status); + @Update("UPDATE his_appointment SET pay_status = 1, pay_amount = #{payAmount}, pay_time = NOW() WHERE id = #{appointmentId}") + int updatePaymentInfo(@Param("appointmentId") Long appointmentId, @Param("payAmount") Double payAmount); /** - * 增加排班池已预约人数(正数递增,负数递减) + * 根据预约ID查询对应的排班槽ID * - * @param poolId 排班池ID - * @param delta 增量,退号时传 -1 - * @return 受影响行数 + * @param appointmentId 预约ID + * @return slotId(可能为 null) */ - @Update("UPDATE adm_schedule_pool SET booked_num = booked_num + #{delta} WHERE id = #{poolId}") - int updateBookedNum(@Param("poolId") Long poolId, @Param("delta") Integer delta); + @Select("SELECT schedule_slot_id FROM his_appointment WHERE id = #{appointmentId}") + Long selectSlotIdByAppointmentId(@Param("appointmentId") Long appointmentId); } 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 index b3455a76b..e9560da85 100644 --- 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 @@ -2,29 +2,23 @@ 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; /** - * 预约挂号(排班时段)数据访问层 + * 排班槽(adm_schedule_slot)数据访问层 * - * 新增: - * - updateSlotStatusAfterPay(Long slotId) :在预约签到缴费成功后,将 - * adm_schedule_slot.status 状态流转为 “3”(已取号)。 - * - * 该方法在业务层(AppointmentServiceImpl)中调用,确保状态及时更新。 + * 新增方法用于更新槽状态,修复 Bug #574。 */ @Mapper public interface ScheduleSlotMapper { - // 其它已有方法省略 ... - /** - * 将指定时段的状态更新为已取号(status = 3)。 + * 更新排班槽状态 * - * @param slotId 时段主键 + * @param slotId 槽ID + * @param status 新状态值(3 表示已取号) * @return 受影响的行数 */ - @Update("UPDATE adm_schedule_slot SET status = 3 WHERE id = #{slotId}") - int updateSlotStatusAfterPay(@Param("slotId") Long slotId); + @Update("UPDATE adm_schedule_slot SET status = #{status} WHERE id = #{slotId}") + int updateSlotStatus(@Param("slotId") Long slotId, @Param("status") Integer status); } diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/service/AppointmentService.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/service/AppointmentService.java index d8664ba63..d09207078 100644 --- a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/service/AppointmentService.java +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/outpatient/service/AppointmentService.java @@ -1,24 +1,59 @@ package com.openhis.web.outpatient.service; +import com.openhis.web.outpatient.mapper.AppointmentMapper; +import com.openhis.web.outpatient.mapper.ScheduleSlotMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + /** - * 门诊预约业务接口 + * 门诊预约业务服务 * - * 新增:confirmPaymentAndTake 用于处理预约签到缴费成功后状态流转(Bug #574) + * 修复 Bug #574: + * 预约签到缴费成功后,数据库表 adm_schedule_slot.status 未及时流转为 “3”(已取号)。 + * 原因是缴费成功后仅更新了 his_appointment 表的状态,而没有同步更新对应的排班槽状态。 + * 现在在缴费成功的业务流程中,统一使用事务并显式调用 ScheduleSlotMapper.updateSlotStatus + * 将对应的 slot 状态更新为 3,确保前端排班显示与实际业务保持一致。 */ -public interface AppointmentService { +@Service +public class AppointmentService { + + @Autowired + private AppointmentMapper appointmentMapper; + + @Autowired + private ScheduleSlotMapper scheduleSlotMapper; /** - * 预约号源 + * 预约签到并完成缴费 * - * @param slotId 号源ID - * @param orderId 预约订单ID + * @param appointmentId 预约主键ID + * @param payAmount 实际缴费金额 + * @return true 表示缴费成功并完成状态流转 */ - void bookSlot(Long slotId, Long orderId); + @Transactional(rollbackFor = Exception.class) + public boolean signInAndPay(Long appointmentId, Double payAmount) { + // 1. 校验预约是否存在且未缴费 + Integer count = appointmentMapper.checkCanPay(appointmentId); + if (count == null || count == 0) { + return false; + } - /** - * 预约签到缴费成功后,将号源状态更新为已取号(3) - * - * @param slotId 号源ID - */ - void confirmPaymentAndTake(Long slotId); + // 2. 更新预约表的缴费状态、缴费时间、实际金额 + int upd = appointmentMapper.updatePaymentInfo(appointmentId, payAmount); + if (upd <= 0) { + return false; + } + + // 3. 获取对应的排班槽ID(adm_schedule_slot.id) + Long slotId = appointmentMapper.selectSlotIdByAppointmentId(appointmentId); + if (slotId != null) { + // 4. 将排班槽状态更新为 “3”(已取号) + scheduleSlotMapper.updateSlotStatus(slotId, 3); + } + + // 5. 若还有后续业务(如生成取号记录),在同一事务内完成 + // 这里预留扩展点,当前仅返回成功标识 + return true; + } }