|
|
@@ -1070,7 +1070,7 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
/**
|
|
|
* 取消律师咨询订单
|
|
|
* <p>
|
|
|
- * 取消订单前会进行以下校验和处理:
|
|
|
+ * 取消订单的业务逻辑:
|
|
|
* 1. 参数校验:订单ID不能为空
|
|
|
* 2. 订单存在性校验:订单必须存在
|
|
|
* 3. 订单状态校验:已取消或已完成的订单不允许再次取消
|
|
|
@@ -1104,43 +1104,47 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
// 3. 订单状态校验
|
|
|
Integer orderStatus = order.getOrderStatus();
|
|
|
String orderNumber = order.getOrderNumber();
|
|
|
+
|
|
|
+ // 提取订单状态常量,避免魔法值
|
|
|
Integer cancelStatus = LawyerStatusEnum.CANCEL.getStatus();
|
|
|
Integer completedStatus = LawyerStatusEnum.COMPLETE.getStatus();
|
|
|
Integer waitAcceptStatus = LawyerStatusEnum.WAIT_ACCEPT.getStatus();
|
|
|
Integer waitPayStatus = LawyerStatusEnum.WAIT_PAY.getStatus();
|
|
|
Integer refundedStatus = LawyerStatusEnum.REFUNDED.getStatus();
|
|
|
|
|
|
- // 3.1 检查订单是否已取消
|
|
|
- if (cancelStatus.equals(orderStatus)) {
|
|
|
+ // 3.1 检查订单是否已取消(使用 Objects.equals 避免空指针异常)
|
|
|
+ if (Objects.equals(cancelStatus, orderStatus)) {
|
|
|
log.warn("取消订单失败:订单已取消,订单ID={}, 订单编号={}", id, orderNumber);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 3.2 检查订单是否已完成
|
|
|
- if (completedStatus.equals(orderStatus)) {
|
|
|
+ if (Objects.equals(completedStatus, orderStatus)) {
|
|
|
log.warn("取消订单失败:订单已完成,不允许取消,订单ID={}, 订单编号={}", id, orderNumber);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 4. 如果订单是待支付状态,取消Redis中的订单支付超时计时器
|
|
|
- if (waitPayStatus.equals(orderStatus) && StringUtils.hasText(orderNumber)) {
|
|
|
+ if (Objects.equals(waitPayStatus, orderStatus) && StringUtils.hasText(orderNumber)) {
|
|
|
try {
|
|
|
orderExpirationService.cancelOrderPaymentTimeout(orderNumber);
|
|
|
log.info("已取消订单支付超时计时器,订单编号={}", orderNumber);
|
|
|
} catch (Exception e) {
|
|
|
- log.error("取消订单支付超时计时器失败,订单编号={}", orderNumber, e);
|
|
|
+ log.error("取消订单支付超时计时器失败,订单编号={},异常信息:{}", orderNumber, e.getMessage(), e);
|
|
|
// 继续执行取消订单操作,不因取消计时器失败而中断
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 5. 根据订单状态更新为相应状态
|
|
|
- Integer targetStatus = null;
|
|
|
- if (waitAcceptStatus.equals(orderStatus)) {
|
|
|
+ Integer targetStatus;
|
|
|
+ if (Objects.equals(waitAcceptStatus, orderStatus)) {
|
|
|
// 待接单状态:更新为已退款状态
|
|
|
targetStatus = refundedStatus;
|
|
|
- } else if (waitPayStatus.equals(orderStatus)) {
|
|
|
+ log.debug("待接单订单取消,将更新为已退款状态,订单ID={}", id);
|
|
|
+ } else if (Objects.equals(waitPayStatus, orderStatus)) {
|
|
|
// 待支付状态:更新为已取消状态
|
|
|
targetStatus = cancelStatus;
|
|
|
+ log.debug("待支付订单取消,将更新为已取消状态,订单ID={}", id);
|
|
|
} else {
|
|
|
log.warn("取消订单失败:订单状态不允许取消,订单ID={}, 订单编号={}, 订单状态={}",
|
|
|
id, orderNumber, orderStatus);
|
|
|
@@ -1161,8 +1165,8 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
log.info("取消订单成功,订单ID={}, 订单编号={}, 原状态={}, 新状态={}",
|
|
|
id, orderNumber, orderStatus, targetStatus);
|
|
|
} else {
|
|
|
- log.error("取消订单失败:更新数据库失败,订单ID={}, 订单编号={}, 原状态={}",
|
|
|
- id, orderNumber, orderStatus);
|
|
|
+ log.error("取消订单失败:更新数据库失败,订单ID={}, 订单编号={}, 原状态={}, 目标状态={}",
|
|
|
+ id, orderNumber, orderStatus, targetStatus);
|
|
|
}
|
|
|
|
|
|
return success;
|