Fix Bug #506: fallback修复
This commit is contained in:
@@ -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<String, Object> 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 中预留方法)。
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user