fix(#574): 请修复 Bug #574:[一般] [预约挂号] 预约签到缴费成功后,数据库 adm_schedule_slot.status 状态未及时流转为“3”(已取
根因: - 项目中有 **3 个 `AppointmentServiceImpl` 文件**,其中 2 个存在编译错误,导致正确实现无法被 Spring 加载: - | 文件 | 状态 | 问题 | - |---|---|---| - | `com.openhis.web.outpatient.service.AppointmentServiceImpl` | ✅ **保留(正确)** | 正确实现 `AppointmentService`,`confirmPaymentAndTake()` 调用 `AppointmentSlotMapper.updateSlotToTaken()` 将 `adm_schedule_slot.status` 更新为 3 | - | `com.openhis.web.appointment.service.AppointmentServiceImpl` | ❌ **已删除** | `@Override` 注解的方法名 (`createAppointment`, `checkInAndPay`) 与 `AppointmentService` 接口 (`bookSlot`, `confirmPaymentAndTake`) 不匹配,编译失败 | - | `com.openhis.web.outpatient.service.impl.AppointmentServiceImpl` | ❌ **已删除** | 调用了 `AppointmentMapper` 中不存在的方法 (`updateSlotStatus`, `updateBookedNum`),且未被任何代码引用 | - ### 状态流转链路 - 预约 (book) → AppointmentSlotMapper: status = 2 (已预约) - 签到缴费成功 → AppointmentController (/confirm) - AppointmentService.confirmPaymentAndTake(slotId) - AppointmentSlotMapper.updateSlotToTaken(slotId) - SQL: UPDATE adm_schedule_slot SET status = 3 WHERE id = ? AND status = 2 - status = 3 (已取号/签到,待就诊) ✅ - ### 改动文件 - 删除**: `openhis-application/src/main/java/com/openhis/web/appointment/service/AppointmentServiceImpl.java`(编译失败) - 删除**: `openhis-application/src/main/java/com/openhis/web/outpatient/service/impl/AppointmentServiceImpl.java`(编译失败,引用不存在的方法) 修复: - 修改相关代码文件
This commit is contained in:
@@ -1,87 +0,0 @@
|
|||||||
package com.openhis.web.appointment.service;
|
|
||||||
|
|
||||||
import com.openhis.web.appointment.entity.Appointment;
|
|
||||||
import com.openhis.web.appointment.mapper.AppointmentMapper;
|
|
||||||
import com.openhis.web.appointment.mapper.ScheduleSlotMapper;
|
|
||||||
import com.openhis.web.appointment.mapper.OrderMainMapper;
|
|
||||||
import com.openhis.web.appointment.mapper.SchedulePoolMapper;
|
|
||||||
import com.openhis.web.appointment.mapper.RefundLogMapper;
|
|
||||||
import com.openhis.web.appointment.dto.AppointmentParam;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 门诊预约挂号服务实现
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
public class AppointmentServiceImpl implements AppointmentService {
|
|
||||||
|
|
||||||
private final AppointmentMapper appointmentMapper;
|
|
||||||
private final ScheduleSlotMapper scheduleSlotMapper;
|
|
||||||
private final OrderMainMapper orderMainMapper;
|
|
||||||
private final SchedulePoolMapper schedulePoolMapper;
|
|
||||||
private final RefundLogMapper refundLogMapper;
|
|
||||||
|
|
||||||
public AppointmentServiceImpl(AppointmentMapper appointmentMapper,
|
|
||||||
ScheduleSlotMapper scheduleSlotMapper,
|
|
||||||
OrderMainMapper orderMainMapper,
|
|
||||||
SchedulePoolMapper schedulePoolMapper,
|
|
||||||
RefundLogMapper refundLogMapper) {
|
|
||||||
this.appointmentMapper = appointmentMapper;
|
|
||||||
this.scheduleSlotMapper = scheduleSlotMapper;
|
|
||||||
this.orderMainMapper = orderMainMapper;
|
|
||||||
this.schedulePoolMapper = schedulePoolMapper;
|
|
||||||
this.refundLogMapper = refundLogMapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public boolean createAppointment(AppointmentParam param) {
|
|
||||||
Appointment appointment = new Appointment();
|
|
||||||
appointment.setPatientId(param.getPatientId());
|
|
||||||
appointment.setScheduleId(param.getScheduleId());
|
|
||||||
appointment.setDoctorId(param.getDoctorId());
|
|
||||||
appointment.setDeptId(param.getDeptId());
|
|
||||||
appointment.setVisitDate(param.getVisitDate());
|
|
||||||
appointment.setCreateTime(LocalDateTime.now());
|
|
||||||
|
|
||||||
// 1. 保存预约记录
|
|
||||||
appointmentMapper.insert(appointment);
|
|
||||||
|
|
||||||
// 2. 累加号源池已预约数(已实现的原子操作)
|
|
||||||
schedulePoolMapper.incrementBookedNum(param.getScheduleId());
|
|
||||||
|
|
||||||
// 3. 创建订单并完成支付(简化示例,实际业务已在后续代码中实现)
|
|
||||||
Long orderId = orderMainMapper.insertOrder(appointment.getId(),
|
|
||||||
param.getAmount(), LocalDateTime.now());
|
|
||||||
return orderId != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Bug #574 Fix: 预约签到缴费成功后,更新号源时段状态为“已取号”(status=3)
|
|
||||||
* 修复原流程中遗漏调用 scheduleSlotMapper.updateStatusToTaken 导致状态滞留为 1 的问题
|
|
||||||
*
|
|
||||||
* @param orderId 订单ID
|
|
||||||
* @param slotId 号源时段ID
|
|
||||||
* @return 是否更新成功
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public boolean checkInAndPay(Long orderId, Long slotId) {
|
|
||||||
if (orderId == null || slotId == null) {
|
|
||||||
throw new IllegalArgumentException("订单ID或号源时段ID不能为空");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 核心修复:显式调用 Mapper 将 adm_schedule_slot.status 更新为 3(已取号/签到)
|
|
||||||
int rows = scheduleSlotMapper.updateStatusToTaken(slotId);
|
|
||||||
if (rows <= 0) {
|
|
||||||
throw new RuntimeException("更新号源时段状态失败,未找到对应记录或状态已变更");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 此处可补充订单状态流转逻辑(如 orderMainMapper.updateOrderStatus(orderId, 2))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
package com.openhis.web.outpatient.service.impl;
|
|
||||||
|
|
||||||
import com.openhis.web.outpatient.mapper.AppointmentMapper;
|
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 预约挂号业务实现
|
|
||||||
*
|
|
||||||
* 修复 Bug #506:
|
|
||||||
* 门诊诊前退号后,涉及的多表状态未按 PRD 定义同步更新,导致前端显示异常。
|
|
||||||
* 现在在取消预约的业务路径中统一处理:
|
|
||||||
* 1. 将订单状态置为 “已取消”(4)。
|
|
||||||
* 2. 将对应的 adm_schedule_slot.status 设回 “1”(可预约)。
|
|
||||||
* 3. 将对应的 adm_schedule_pool.booked_num 递减 1。
|
|
||||||
*
|
|
||||||
* 同时保持原有支付成功后的状态同步逻辑不变。
|
|
||||||
*/
|
|
||||||
@Service
|
|
||||||
public class AppointmentServiceImpl {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private OrderMapper orderMapper;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private AppointmentMapper appointmentMapper;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 预约缴费成功后调用。
|
|
||||||
*
|
|
||||||
* @param orderId 预约订单ID
|
|
||||||
* @param slotId 对应的排班时段ID
|
|
||||||
*/
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public void handlePaymentSuccess(Long orderId, Long slotId) {
|
|
||||||
// 1. 更新订单支付状态为 “已缴费”(2)
|
|
||||||
int orderUpdated = orderMapper.updatePayStatus(orderId, 2);
|
|
||||||
if (orderUpdated != 1) {
|
|
||||||
throw new IllegalStateException("Failed to update payment status for orderId: " + orderId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 将排班时段状态更新为已取号(3)
|
|
||||||
int slotUpdated = appointmentMapper.updateSlotStatus(slotId, 3);
|
|
||||||
if (slotUpdated != 1) {
|
|
||||||
throw new IllegalStateException("Failed to update slot status for slotId: " + slotId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. 累加排班池已预约人数(已在支付成功时递增)
|
|
||||||
// 此处假设 slot 与 pool 已经关联,业务层可自行获取 poolId 并调用
|
|
||||||
// appointmentMapper.updateBookedNum(poolId, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 门诊诊前退号(取消预约)处理。
|
|
||||||
*
|
|
||||||
* @param orderId 预约订单ID
|
|
||||||
* @param slotId 对应的排班时段ID
|
|
||||||
* @param poolId 对应的排班池ID(用于 booked_num 调整)
|
|
||||||
*/
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public void cancelPreRegistration(Long orderId, Long slotId, Long poolId) {
|
|
||||||
// 1. 将订单状态更新为 “已取消”(4)
|
|
||||||
int orderUpdated = orderMapper.updateOrderStatus(orderId, 4);
|
|
||||||
if (orderUpdated != 1) {
|
|
||||||
throw new IllegalStateException("Failed to cancel orderId: " + orderId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 将排班时段状态恢复为 “可预约”(1)
|
|
||||||
int slotUpdated = appointmentMapper.updateSlotStatus(slotId, 1);
|
|
||||||
if (slotUpdated != 1) {
|
|
||||||
throw new IllegalStateException("Failed to reset slot status for slotId: " + slotId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. 已预约人数递减 1,防止 booked_num 超出实际可用数
|
|
||||||
int poolUpdated = appointmentMapper.updateBookedNum(poolId, -1);
|
|
||||||
if (poolUpdated != 1) {
|
|
||||||
throw new IllegalStateException("Failed to decrement booked_num for poolId: " + poolId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user