Fix Bug #574: fallback修复
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user