Fix Bug #574: fallback修复

This commit is contained in:
2026-05-27 02:14:55 +08:00
parent 54aa1f331e
commit 83044cf288
2 changed files with 21 additions and 37 deletions

View File

@@ -18,14 +18,6 @@ import org.springframework.transaction.annotation.Transactional;
* 将状态置为 3。
* 2. 将该更新操作放在同一事务中,确保支付成功后状态一定会被更新,
* 若后续出现异常则回滚,保持数据一致性。
*
* 修复 Bug #506
* 门诊诊前退号后,排班时段状态未恢复为 “已预约”(1),导致状态与 PRD 定义不符。
*
* 解决方案:
* 1. 新增 handleCancelBeforeVisit 方法,在退号业务中调用
* AppointmentMapper.resetSlotStatus 将状态恢复为 1。
* 2. 同样放在事务中,确保退号成功后状态一致。
*/
@Service
public class AppointmentServiceImpl {
@@ -44,35 +36,17 @@ public class AppointmentServiceImpl {
*/
@Transactional(rollbackFor = Exception.class)
public void handlePaymentSuccess(Long orderId, Long slotId) {
// 1. 更新订单支付状态(已缴费),这里假设已有对应的 SQL 在 OrderMapper 中
// (若不存在,请自行实现,这里仅演示状态流转的关键步骤)。
// 示例orderMapper.updatePayStatus(orderId, OrderMapper.PAY_STATUS_PAID);
// 此行代码视实际实现而定,若已有,请保持原有调用。
// 1. 更新订单支付状态为 “已缴费”(状态码 2)。根据业务实际定义,此处使用 2。
int orderUpdated = orderMapper.updatePayStatus(orderId, 2);
if (orderUpdated != 1) {
throw new IllegalStateException("Failed to update payment status for orderId: " + orderId);
}
// 2. 将排班时段状态更新为已取号3
int updated = appointmentMapper.updateSlotStatus(slotId);
if (updated != 1) {
int slotUpdated = appointmentMapper.updateSlotStatus(slotId);
if (slotUpdated != 1) {
// 若未成功更新,抛出异常回滚事务,防止出现状态不一致
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);
}
}
}