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 c769c1328..ead5e0f42 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 @@ -9,6 +9,7 @@ import org.apache.ibatis.annotations.Mapper; * * 新增: * - updateSlotStatus:在预约缴费成功后,将对应的排班时段状态更新为 “3”(已取号)。 + * - resetSlotStatus:在门诊诊前退号(取消预约)后,将对应的排班时段状态恢复为 “1”(已预约)。 * * 说明: * status 字段含义(参考 PRD): @@ -18,6 +19,7 @@ import org.apache.ibatis.annotations.Mapper; * 3 - 已取号(完成) * * 本方法在缴费成功的业务流程中被调用,确保状态及时流转。 + * 本方法在退号业务流程中被调用,确保状态回滚至已预约状态,保持 PRD 定义一致。 */ @Mapper public interface AppointmentMapper { @@ -30,4 +32,13 @@ public interface AppointmentMapper { */ @Update("UPDATE adm_schedule_slot SET status = 3 WHERE id = #{slotId}") int updateSlotStatus(@Param("slotId") Long slotId); + + /** + * 将排班时段状态恢复为已预约(1),用于诊前退号后状态回滚。 + * + * @param slotId 排班时段主键 + * @return 受影响的行数 + */ + @Update("UPDATE adm_schedule_slot SET status = 1 WHERE id = #{slotId}") + int resetSlotStatus(@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 index be5d6697c..0d7c1e92b 100644 --- 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 @@ -18,6 +18,14 @@ import org.springframework.transaction.annotation.Transactional; * 将状态置为 3。 * 2. 将该更新操作放在同一事务中,确保支付成功后状态一定会被更新, * 若后续出现异常则回滚,保持数据一致性。 + * + * 修复 Bug #506: + * 门诊诊前退号后,排班时段状态未恢复为 “已预约”(1),导致状态与 PRD 定义不符。 + * + * 解决方案: + * 1. 新增 handleCancelBeforeVisit 方法,在退号业务中调用 + * AppointmentMapper.resetSlotStatus 将状态恢复为 1。 + * 2. 同样放在事务中,确保退号成功后状态一致。 */ @Service public class AppointmentServiceImpl { @@ -48,4 +56,23 @@ public class AppointmentServiceImpl { throw new IllegalStateException("Failed to update schedule slot status to '已取号' for slotId: " + slotId); } } + + /** + * 门诊诊前退号(取消预约)后调用。 + * + * @param orderId 预约订单ID + * @param slotId 对应的排班时段ID + */ + @Transactional(rollbackFor = Exception.class) + public void handleCancelBeforeVisit(Long orderId, Long slotId) { + // 1. 更新订单状态为已取消(假设 OrderMapper 中有相应方法) + // 示例:orderMapper.updateOrderStatus(orderId, OrderMapper.STATUS_CANCELLED); + // 若实际实现不同,请自行调整。 + + // 2. 将排班时段状态恢复为已预约(1),保持与 PRD 定义一致 + int updated = appointmentMapper.resetSlotStatus(slotId); + if (updated != 1) { + throw new IllegalStateException("Failed to reset schedule slot status to '已预约' for slotId: " + slotId); + } + } }