|
|
@@ -1,5 +1,6 @@
|
|
|
package shop.alien.lawyer.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.alibaba.nacos.common.utils.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
@@ -19,10 +20,14 @@ import shop.alien.entity.store.LawFirm;
|
|
|
import shop.alien.entity.store.LawyerConsultationOrder;
|
|
|
import shop.alien.entity.store.LawyerServiceArea;
|
|
|
import shop.alien.entity.store.LawyerUser;
|
|
|
+import shop.alien.entity.store.LifeNotice;
|
|
|
+import shop.alien.entity.store.LifeUser;
|
|
|
import shop.alien.entity.store.dto.LawyerConsultationOrderDto;
|
|
|
import shop.alien.entity.store.dto.PayStatusRequest;
|
|
|
import shop.alien.entity.store.vo.LawyerConsultationOrderVO;
|
|
|
import shop.alien.entity.store.vo.OrderRevenueVO;
|
|
|
+import shop.alien.entity.store.vo.WebSocketVo;
|
|
|
+import shop.alien.lawyer.config.WebSocketProcess;
|
|
|
import shop.alien.lawyer.service.LawyerConsultationOrderService;
|
|
|
import shop.alien.lawyer.service.LawyerUserService;
|
|
|
import shop.alien.lawyer.service.OrderExpirationService;
|
|
|
@@ -58,6 +63,14 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
private final OrderExpirationService orderExpirationService;
|
|
|
// private final AliApi aliApi;
|
|
|
private final LawFirmMapper lawFirmMapper;
|
|
|
+ private final LifeNoticeMapper lifeNoticeMapper;
|
|
|
+ private final LifeUserMapper lifeUserMapper;
|
|
|
+ private final WebSocketProcess webSocketProcess;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 系统发送者ID
|
|
|
+ */
|
|
|
+ private static final String SYSTEM_SENDER_ID = "system";
|
|
|
|
|
|
|
|
|
@Override
|
|
|
@@ -397,7 +410,7 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
|
|
|
@Override
|
|
|
public R<LawyerConsultationOrderDto> consultNow(LawyerConsultationOrder lawyerConsultationOrder) {
|
|
|
- log.info("LawyerConsultationOrderServiceImpl.consultNow?lawyerConsultationOrder={}", lawyerConsultationOrder);
|
|
|
+ log.info("LawyerConsultationOrderServiceImpl.consultNow?lawyerConsultationOrder={}", lawyerConsultationOrder);
|
|
|
|
|
|
// 参数校验
|
|
|
if (lawyerConsultationOrder == null) {
|
|
|
@@ -910,61 +923,100 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
|
|
|
/**
|
|
|
* 取消律师咨询订单
|
|
|
+ * <p>
|
|
|
+ * 取消订单前会进行以下校验和处理:
|
|
|
+ * 1. 参数校验:订单ID不能为空
|
|
|
+ * 2. 订单存在性校验:订单必须存在
|
|
|
+ * 3. 订单状态校验:已取消或已完成的订单不允许再次取消
|
|
|
+ * 4. 如果订单是待支付状态,会取消Redis中的订单支付超时计时器
|
|
|
+ * 5. 根据订单状态更新为相应状态:
|
|
|
+ * - 待接单状态:更新为已退款状态
|
|
|
+ * - 待支付状态:更新为已取消状态
|
|
|
+ * </p>
|
|
|
*
|
|
|
* @param id 订单ID
|
|
|
- * @return 是否取消成功
|
|
|
+ * @return 是否取消成功,true表示成功,false表示失败
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public boolean cancelOrder(String id) {
|
|
|
- // 参数校验
|
|
|
+ log.info("开始取消订单,订单ID={}", id);
|
|
|
+
|
|
|
+ // 1. 参数校验
|
|
|
if (!StringUtils.hasText(id)) {
|
|
|
log.warn("取消订单失败:订单ID为空");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- // 查询订单信息
|
|
|
+ // 2. 查询订单信息
|
|
|
LawyerConsultationOrder order = consultationOrderMapper.selectById(id);
|
|
|
if (order == null) {
|
|
|
log.warn("取消订单失败:订单不存在,订单ID={}", id);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- // 检查订单状态:已完成或已取消的订单不允许再次取消
|
|
|
+ // 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)) {
|
|
|
- log.warn("取消订单失败:订单已取消,订单ID={}, 订单编号={}", id, order.getOrderNumber());
|
|
|
+ log.warn("取消订单失败:订单已取消,订单ID={}, 订单编号={}", id, orderNumber);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- // 如果订单已完成,不允许取消
|
|
|
- Integer completedStatus = LawyerStatusEnum.COMPLETE.getStatus(); // 3:已完成
|
|
|
+ // 3.2 检查订单是否已完成
|
|
|
if (completedStatus.equals(orderStatus)) {
|
|
|
- log.warn("取消订单失败:订单已完成,不允许取消,订单ID={}, 订单编号={}", id, order.getOrderNumber());
|
|
|
+ log.warn("取消订单失败:订单已完成,不允许取消,订单ID={}, 订单编号={}", id, orderNumber);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- // 如果订单是待支付状态,取消Redis中的订单支付超时计时
|
|
|
- Integer waitPayStatus = LawyerStatusEnum.WAIT_PAY.getStatus(); // 0:待支付
|
|
|
- if (waitPayStatus.equals(orderStatus) && order.getOrderNumber() != null) {
|
|
|
- orderExpirationService.cancelOrderPaymentTimeout(order.getOrderNumber());
|
|
|
- log.info("已取消订单支付超时计时,订单编号={}", order.getOrderNumber());
|
|
|
+ // 4. 如果订单是待支付状态,取消Redis中的订单支付超时计时器
|
|
|
+ if (waitPayStatus.equals(orderStatus) && StringUtils.hasText(orderNumber)) {
|
|
|
+ try {
|
|
|
+ orderExpirationService.cancelOrderPaymentTimeout(orderNumber);
|
|
|
+ log.info("已取消订单支付超时计时器,订单编号={}", orderNumber);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("取消订单支付超时计时器失败,订单编号={}", orderNumber, e);
|
|
|
+ // 继续执行取消订单操作,不因取消计时器失败而中断
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5. 根据订单状态更新为相应状态
|
|
|
+ Integer targetStatus = null;
|
|
|
+ if (waitAcceptStatus.equals(orderStatus)) {
|
|
|
+ // 待接单状态:更新为已退款状态
|
|
|
+ targetStatus = refundedStatus;
|
|
|
+ } else if (waitPayStatus.equals(orderStatus)) {
|
|
|
+ // 待支付状态:更新为已取消状态
|
|
|
+ targetStatus = cancelStatus;
|
|
|
+ } else {
|
|
|
+ log.warn("取消订单失败:订单状态不允许取消,订单ID={}, 订单编号={}, 订单状态={}",
|
|
|
+ id, orderNumber, orderStatus);
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
- // 更新订单状态为已取消
|
|
|
+ // 6. 更新订单状态
|
|
|
LambdaUpdateWrapper<LawyerConsultationOrder> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
updateWrapper.eq(LawyerConsultationOrder::getId, id)
|
|
|
- .set(LawyerConsultationOrder::getOrderStatus, cancelStatus)
|
|
|
+ .set(LawyerConsultationOrder::getOrderStatus, targetStatus)
|
|
|
.set(LawyerConsultationOrder::getUpdatedTime, new Date());
|
|
|
|
|
|
int updateCount = consultationOrderMapper.update(null, updateWrapper);
|
|
|
boolean success = updateCount > 0;
|
|
|
|
|
|
+ // 7. 记录操作结果
|
|
|
if (success) {
|
|
|
- log.info("取消订单成功,订单ID={}, 订单编号={}, 原状态={}", id, order.getOrderNumber(), orderStatus);
|
|
|
+ log.info("取消订单成功,订单ID={}, 订单编号={}, 原状态={}, 新状态={}",
|
|
|
+ id, orderNumber, orderStatus, targetStatus);
|
|
|
} else {
|
|
|
- log.error("取消订单失败:更新数据库失败,订单ID={}, 订单编号={}", id, order.getOrderNumber());
|
|
|
+ log.error("取消订单失败:更新数据库失败,订单ID={}, 订单编号={}, 原状态={}",
|
|
|
+ id, orderNumber, orderStatus);
|
|
|
}
|
|
|
|
|
|
return success;
|
|
|
@@ -1297,6 +1349,176 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 用户申请退款
|
|
|
+ * <p>
|
|
|
+ * 申请退款前会进行以下校验和处理:
|
|
|
+ * 1. 参数校验:用户ID和订单ID不能为空
|
|
|
+ * 2. 订单存在性校验:订单必须存在
|
|
|
+ * 3. 订单归属校验:订单必须属于该用户
|
|
|
+ * 4. 订单状态校验:只有进行中(2)和已完成(3)状态的订单可以申请退款
|
|
|
+ * 5. 退款状态校验:已申请退款的订单不允许重复申请
|
|
|
+ * 6. 更新订单的申请退款状态为已申请(1),并更新退款申请时间
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @param clientUserId 客户端用户ID
|
|
|
+ * @param orderId 订单ID
|
|
|
+ * @return 申请退款结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R<Boolean> applyRefund(Integer clientUserId, Integer orderId, String applyRefundReason) {
|
|
|
+ log.info("开始申请退款,用户ID={}, 订单ID={}", clientUserId, orderId);
|
|
|
+
|
|
|
+ // 1. 参数校验
|
|
|
+ if (clientUserId == null || clientUserId <= 0) {
|
|
|
+ log.warn("申请退款失败:用户ID为空或无效,clientUserId={}", clientUserId);
|
|
|
+ return R.fail("用户ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (orderId == null || orderId <= 0) {
|
|
|
+ log.warn("申请退款失败:订单ID为空或无效,orderId={}", orderId);
|
|
|
+ return R.fail("订单ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 查询订单信息
|
|
|
+ LawyerConsultationOrder order = consultationOrderMapper.selectById(orderId);
|
|
|
+ if (order == null) {
|
|
|
+ log.warn("申请退款失败:订单不存在,订单ID={}", orderId);
|
|
|
+ return R.fail("订单不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 订单归属校验:订单必须属于该用户
|
|
|
+ if (!clientUserId.equals(order.getClientUserId())) {
|
|
|
+ log.warn("申请退款失败:订单不属于该用户,订单ID={}, 订单用户ID={}, 请求用户ID={}",
|
|
|
+ orderId, order.getClientUserId(), clientUserId);
|
|
|
+ return R.fail("订单不属于该用户,无法申请退款");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 订单状态校验:只有进行中(2)和已完成(3)状态的订单可以申请退款
|
|
|
+ Integer orderStatus = order.getOrderStatus();
|
|
|
+ Integer inProgressStatus = LawyerStatusEnum.INPROGRESS.getStatus(); // 2:进行中
|
|
|
+ Integer completeStatus = LawyerStatusEnum.COMPLETE.getStatus(); // 3:已完成
|
|
|
+
|
|
|
+ if (!inProgressStatus.equals(orderStatus) && !completeStatus.equals(orderStatus)) {
|
|
|
+ log.warn("申请退款失败:订单状态不允许申请退款,订单ID={}, 订单编号={}, 订单状态={}",
|
|
|
+ orderId, order.getOrderNumber(), orderStatus);
|
|
|
+ return R.fail("只有进行中或已完成的订单可以申请退款");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5. 退款状态校验:已申请退款的订单不允许重复申请
|
|
|
+ String applyRefundStatus = order.getApplyRefundStatus();
|
|
|
+ String appliedStatus = "1"; // 1:已申请
|
|
|
+ String lawyerAgreedStatus = "3"; // 3:律师已同意
|
|
|
+ if (appliedStatus.equals(applyRefundStatus) || lawyerAgreedStatus.equals(applyRefundStatus)) {
|
|
|
+ log.warn("申请退款失败:订单已申请退款,不允许重复申请,订单ID={}, 订单编号={}, 退款状态={}",
|
|
|
+ orderId, order.getOrderNumber(), applyRefundStatus);
|
|
|
+ return R.fail("订单已申请退款,不允许重复申请");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 6. 更新订单的申请退款状态为已申请(1),并更新退款申请时间
|
|
|
+ LambdaUpdateWrapper<LawyerConsultationOrder> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.eq(LawyerConsultationOrder::getId, orderId)
|
|
|
+ .set(LawyerConsultationOrder::getApplyRefundStatus, appliedStatus)
|
|
|
+ .set(LawyerConsultationOrder::getApplyRefundTime, new Date())
|
|
|
+ .set(LawyerConsultationOrder::getUpdatedTime, new Date()).set(LawyerConsultationOrder::getApplyRefundReason, applyRefundReason);
|
|
|
+
|
|
|
+ int updateCount = consultationOrderMapper.update(null, updateWrapper);
|
|
|
+ boolean success = updateCount > 0;
|
|
|
+
|
|
|
+ // 7. 记录操作结果并发送通知
|
|
|
+ if (success) {
|
|
|
+ log.info("申请退款成功,订单ID={}, 订单编号={}, 订单状态={}, 退款状态=已申请",
|
|
|
+ orderId, order.getOrderNumber(), orderStatus);
|
|
|
+
|
|
|
+ // 发送退款申请通知给申请人
|
|
|
+ sendRefundApplyNotice(order, clientUserId);
|
|
|
+
|
|
|
+ return R.data(true, "退款申请已提交,请等待律师处理");
|
|
|
+ } else {
|
|
|
+ log.error("申请退款失败:更新数据库失败,订单ID={}, 订单编号={}", orderId, order.getOrderNumber());
|
|
|
+ return R.fail("申请退款失败,请稍后重试");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户端完成订单
|
|
|
+ * <p>
|
|
|
+ * 完成订单前会进行以下校验和处理:
|
|
|
+ * 1. 参数校验:用户ID和订单ID不能为空
|
|
|
+ * 2. 订单存在性校验:订单必须存在
|
|
|
+ * 3. 订单归属校验:订单必须属于该用户
|
|
|
+ * 4. 订单状态校验:只有进行中(2)状态的订单可以完成
|
|
|
+ * 5. 更新订单状态为已完成(3),并更新完成时间
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @param clientUserId 客户端用户ID
|
|
|
+ * @param orderId 订单ID
|
|
|
+ * @return 完成订单结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R<Boolean> completeOrder(Integer clientUserId, Integer orderId) {
|
|
|
+ log.info("开始完成订单,用户ID={}, 订单ID={}", clientUserId, orderId);
|
|
|
+
|
|
|
+ // 1. 参数校验
|
|
|
+ if (clientUserId == null || clientUserId <= 0) {
|
|
|
+ log.warn("完成订单失败:用户ID为空或无效,clientUserId={}", clientUserId);
|
|
|
+ return R.fail("用户ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (orderId == null || orderId <= 0) {
|
|
|
+ log.warn("完成订单失败:订单ID为空或无效,orderId={}", orderId);
|
|
|
+ return R.fail("订单ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 查询订单信息
|
|
|
+ LawyerConsultationOrder order = consultationOrderMapper.selectById(orderId);
|
|
|
+ if (order == null) {
|
|
|
+ log.warn("完成订单失败:订单不存在,订单ID={}", orderId);
|
|
|
+ return R.fail("订单不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 订单归属校验:订单必须属于该用户
|
|
|
+ if (!clientUserId.equals(order.getClientUserId())) {
|
|
|
+ log.warn("完成订单失败:订单不属于该用户,订单ID={}, 订单用户ID={}, 请求用户ID={}",
|
|
|
+ orderId, order.getClientUserId(), clientUserId);
|
|
|
+ return R.fail("订单不属于该用户,无法完成订单");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 订单状态校验:只有进行中(2)状态的订单可以完成
|
|
|
+ Integer orderStatus = order.getOrderStatus();
|
|
|
+ Integer inProgressStatus = LawyerStatusEnum.INPROGRESS.getStatus(); // 2:进行中
|
|
|
+ Integer completeStatus = LawyerStatusEnum.COMPLETE.getStatus(); // 3:已完成
|
|
|
+
|
|
|
+ if (!inProgressStatus.equals(orderStatus)) {
|
|
|
+ log.warn("完成订单失败:订单状态不允许完成,订单ID={}, 订单编号={}, 订单状态={}",
|
|
|
+ orderId, order.getOrderNumber(), orderStatus);
|
|
|
+ return R.fail("只有进行中的订单可以完成");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5. 更新订单状态为已完成(3),并更新咨询结束时间和更新时间
|
|
|
+ LambdaUpdateWrapper<LawyerConsultationOrder> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ Date now = new Date();
|
|
|
+ updateWrapper.eq(LawyerConsultationOrder::getId, orderId)
|
|
|
+ .set(LawyerConsultationOrder::getOrderStatus, completeStatus)
|
|
|
+ .set(LawyerConsultationOrder::getEndTime, now)
|
|
|
+ .set(LawyerConsultationOrder::getUpdatedTime, now);
|
|
|
+
|
|
|
+ int updateCount = consultationOrderMapper.update(null, updateWrapper);
|
|
|
+ boolean success = updateCount > 0;
|
|
|
+
|
|
|
+ // 6. 记录操作结果
|
|
|
+ if (success) {
|
|
|
+ log.info("完成订单成功,订单ID={}, 订单编号={}, 原状态={}, 新状态=已完成",
|
|
|
+ orderId, order.getOrderNumber(), orderStatus);
|
|
|
+ return R.data(true, "订单已完成");
|
|
|
+ } else {
|
|
|
+ log.error("完成订单失败:更新数据库失败,订单ID={}, 订单编号={}", orderId, order.getOrderNumber());
|
|
|
+ return R.fail("完成订单失败,请稍后重试");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 格式化收益金额(分转元)
|
|
|
*
|
|
|
* @param revenueInCents 收益金额(单位:分)
|
|
|
@@ -1311,6 +1533,128 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
return revenueInYuan.toString();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 发送退款申请通知给申请人
|
|
|
+ *
|
|
|
+ * @param order 订单对象
|
|
|
+ * @param clientUserId 客户端用户ID
|
|
|
+ */
|
|
|
+ private void sendRefundApplyNotice(LawyerConsultationOrder order, Integer clientUserId) {
|
|
|
+ try {
|
|
|
+ LifeNotice lifeNotice = createRefundApplyNotice(order, clientUserId);
|
|
|
+ if (lifeNotice == null) {
|
|
|
+ log.warn("生成退款申请通知失败,订单ID={}, 用户ID={}", order.getId(), clientUserId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ int noticeResult = lifeNoticeMapper.insert(lifeNotice);
|
|
|
+ if (noticeResult <= 0) {
|
|
|
+ log.warn("保存退款申请通知失败,订单ID={}, 用户ID={}", order.getId(), clientUserId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 发送WebSocket消息
|
|
|
+ WebSocketVo webSocketVo = buildWebSocketVo(lifeNotice);
|
|
|
+ webSocketProcess.sendMessage(lifeNotice.getReceiverId(),
|
|
|
+ JSONObject.from(webSocketVo).toJSONString());
|
|
|
+
|
|
|
+ log.info("退款申请通知发送成功,接收人ID={}, 订单编号={}", lifeNotice.getReceiverId(), order.getOrderNumber());
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("发送退款申请通知异常,订单ID={}, 用户ID={}, 异常信息={}",
|
|
|
+ order.getId(), clientUserId, e.getMessage(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建退款申请通知对象
|
|
|
+ *
|
|
|
+ * @param order 订单对象
|
|
|
+ * @param clientUserId 客户端用户ID
|
|
|
+ * @return 通知对象,如果生成失败返回null
|
|
|
+ */
|
|
|
+ private LifeNotice createRefundApplyNotice(LawyerConsultationOrder order, Integer clientUserId) {
|
|
|
+ if (order == null || clientUserId == null) {
|
|
|
+ log.warn("创建退款申请通知失败,订单或用户ID为空");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ LifeNotice lifeNotice = new LifeNotice();
|
|
|
+ lifeNotice.setSenderId(SYSTEM_SENDER_ID);
|
|
|
+ lifeNotice.setBusinessId(order.getId());
|
|
|
+ lifeNotice.setTitle("退款申请通知");
|
|
|
+
|
|
|
+ // 获取申请人接收ID
|
|
|
+ String receiverId = getClientReceiverId(clientUserId);
|
|
|
+ if (org.apache.commons.lang3.StringUtils.isEmpty(receiverId)) {
|
|
|
+ log.warn("获取申请人接收ID失败,用户ID={}", clientUserId);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ lifeNotice.setReceiverId(receiverId);
|
|
|
+
|
|
|
+ // 构建通知消息内容
|
|
|
+ String orderNumber = order.getOrderNumber();
|
|
|
+ String message = String.format("您的编号为%s的订单,申请退款的信息已提交给律师,等待律师同意。律师同意或48小时未处理,系统会将订单金额原路返还,请注意查收。",
|
|
|
+ orderNumber != null ? orderNumber : "");
|
|
|
+
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("title", "退款申请通知");
|
|
|
+ jsonObject.put("message", message);
|
|
|
+ lifeNotice.setContext(jsonObject.toJSONString());
|
|
|
+ lifeNotice.setNoticeType(1);
|
|
|
+
|
|
|
+ return lifeNotice;
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("创建退款申请通知异常,订单ID={}, 用户ID={}, 异常信息={}",
|
|
|
+ order.getId(), clientUserId, e.getMessage(), e);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取客户端用户接收ID
|
|
|
+ *
|
|
|
+ * @param clientUserId 客户端用户ID
|
|
|
+ * @return 接收人ID,格式:user_ + 手机号
|
|
|
+ */
|
|
|
+ private String getClientReceiverId(Integer clientUserId) {
|
|
|
+ if (clientUserId == null || clientUserId <= 0) {
|
|
|
+ log.warn("客户端用户ID为空或无效");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ LifeUser lifeUser = lifeUserMapper.selectById(clientUserId);
|
|
|
+ if (lifeUser != null && org.apache.commons.lang3.StringUtils.isNotEmpty(lifeUser.getUserPhone())) {
|
|
|
+ return "user_" + lifeUser.getUserPhone();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("获取客户端用户手机号异常,用户ID={}, 异常信息={}", clientUserId, e.getMessage(), e);
|
|
|
+ }
|
|
|
+
|
|
|
+ log.warn("获取客户端用户手机号失败,用户ID={}", clientUserId);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建WebSocket消息对象
|
|
|
+ *
|
|
|
+ * @param lifeNotice 通知对象
|
|
|
+ * @return WebSocketVo对象
|
|
|
+ */
|
|
|
+ private WebSocketVo buildWebSocketVo(LifeNotice lifeNotice) {
|
|
|
+ WebSocketVo webSocketVo = new WebSocketVo();
|
|
|
+ webSocketVo.setSenderId(SYSTEM_SENDER_ID);
|
|
|
+ webSocketVo.setReceiverId(lifeNotice.getReceiverId());
|
|
|
+ webSocketVo.setCategory("notice");
|
|
|
+ webSocketVo.setNoticeType("1");
|
|
|
+ webSocketVo.setIsRead(0);
|
|
|
+ webSocketVo.setText(JSONObject.from(lifeNotice).toJSONString());
|
|
|
+ return webSocketVo;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|