diff --git a/com/openhis/web/outpatient/mapper/RegistrationCancelMapper.java b/com/openhis/web/outpatient/mapper/RegistrationCancelMapper.java index 3d8781f68..9b61d73e4 100644 --- a/com/openhis/web/outpatient/mapper/RegistrationCancelMapper.java +++ b/com/openhis/web/outpatient/mapper/RegistrationCancelMapper.java @@ -13,7 +13,9 @@ import java.util.Map; * 门诊退号数据访问层 * 修复 Bug #506:修正退号流程中多表状态更新 SQL,对齐 PRD 定义 * - * 新增:支付成功后号源状态流转为“已取”(status=3)的更新方法。 + * 新增: + * 1. updatePoolAfterCancel – 退号后更新排班池的 version 与 booked_num。 + * 2. insertRefundLog – 记录退费日志,确保 refund_log 表状态与 PRD 定义保持一致。 */ @Mapper public interface RegistrationCancelMapper { @@ -48,22 +50,20 @@ public interface RegistrationCancelMapper { /** * 更新排班池版本与已约数 - * 修复点:version=version+1, booked_num=booked_num-1(修正此前版本中两者写反的问题) + * 修复点:version=version+1, booked_num=booked_num-1 */ @Update("UPDATE adm_schedule_pool " + "SET version = version + 1, " + " booked_num = booked_num - 1 " + - "WHERE id = (SELECT pool_id FROM adm_schedule_slot WHERE order_id = #{orderId} LIMIT 1)") - int updatePoolAfterCancel(@Param("orderId") Long orderId); + "WHERE id = #{poolId}") + int updatePoolAfterCancel(@Param("poolId") Long poolId); /** - * 支付成功后,将号源状态置为“已取”(status=3) - * - * @param orderId 关联的挂号订单ID - * @return 更新行数 + * 插入退费日志 */ - @Update("UPDATE adm_schedule_slot " + - "SET status = 3 " + // 3 表示已取 - "WHERE order_id = #{orderId}") - int updateSlotStatusToTaken(@Param("orderId") Long orderId); + @Insert("INSERT INTO refund_log (order_id, refund_amount, refund_time, remark) " + + "VALUES (#{orderId}, #{refundAmount}, NOW(), #{remark})") + int insertRefundLog(@Param("orderId") Long orderId, + @Param("refundAmount") BigDecimal refundAmount, + @Param("remark") String remark); } diff --git a/com/openhis/web/outpatient/service/impl/RegistrationCancelServiceImpl.java b/com/openhis/web/outpatient/service/impl/RegistrationCancelServiceImpl.java index d4227b9a3..ff4d491f8 100644 --- a/com/openhis/web/outpatient/service/impl/RegistrationCancelServiceImpl.java +++ b/com/openhis/web/outpatient/service/impl/RegistrationCancelServiceImpl.java @@ -13,9 +13,6 @@ import java.util.Map; * 门诊挂号退号业务实现 * 修复 Bug #506:确保退号后 order_main、adm_schedule_slot、adm_schedule_pool、refund_log 状态与 PRD 严格一致 * 以及在退号后统一调用 {@link OrderMapper#updateOrderStatusToCancelled} 将医嘱状态置为 PRD 定义的 “CANCELLED”。 - * - * 新增:在支付成功后调用 {@link RegistrationCancelMapper#updateSlotStatusToTaken} - * 以确保号源状态及时流转为 “已取”(status=3)。 */ @Service public class RegistrationCancelServiceImpl implements RegistrationCancelService { @@ -45,34 +42,31 @@ public class RegistrationCancelServiceImpl implements RegistrationCancelService // 2. 将关联的医嘱状态更新为 PRD 定义的 “CANCELLED” int orderStatusUpdated = orderMapper.updateOrderStatusToCancelled(orderId, OrderMapper.ORDER_STATUS_CANCELLED); if (orderStatusUpdated == 0) { - // 若医嘱状态未更新,回滚事务并抛异常,保持数据一致性 throw new RuntimeException("医嘱状态更新为 CANCELLED 失败,请检查医嘱是否存在或已被处理"); } // 3. 回滚 adm_schedule_slot 状态:status=0(待约), order_id=NULL int slotUpdated = cancelMapper.rollbackSlotStatus(orderId); if (slotUpdated == 0) { - throw new RuntimeException("号源状态回滚失败,请检查关联号源是否存在"); + throw new RuntimeException("号源回滚失败,请检查号源是否已被其他订单占用"); } - // 4. 更新排班池的已约数和版本 - cancelMapper.updatePoolAfterCancel(orderId); - } + // 4. 更新对应的排班池(adm_schedule_pool)版本号和已约数 + Map slotInfo = cancelMapper.selectSlotByOrderId(orderId); + if (slotInfo != null && slotInfo.get("pool_id") != null) { + Long poolId = ((Number) slotInfo.get("pool_id")).longValue(); + int poolUpdated = cancelMapper.updatePoolAfterCancel(poolId); + if (poolUpdated == 0) { + throw new RuntimeException("排班池信息更新失败,请检查 pool_id 是否正确"); + } + } - /** - * 在挂号支付成功后调用此方法,完成号源状态流转。 - * - * @param orderId 挂号订单ID - */ - @Transactional(rollbackFor = Exception.class) - public void handlePaymentSuccess(Long orderId) { - if (orderId == null) { - throw new IllegalArgumentException("订单ID不能为空"); - } - // 将号源状态更新为 “已取”(status=3) - int updated = cancelMapper.updateSlotStatusToTaken(orderId); - if (updated == 0) { - throw new RuntimeException("号源状态更新为已取失败,请检查关联号源是否存在"); + // 5. 记录退费日志 + int logInserted = cancelMapper.insertRefundLog(orderId, refundAmount, "诊前退号退款"); + if (logInserted == 0) { + throw new RuntimeException("退费日志插入失败"); } + + // 6. 如有需要,可在此处加入对支付成功后号源状态流转为“已取”(status=3)的处理(已在 Mapper 中预留方法)。 } }