|
|
@@ -12,6 +12,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
import shop.alien.entity.store.*;
|
|
|
import shop.alien.entity.store.dto.LawyerUserViolationDto;
|
|
|
import shop.alien.entity.store.vo.LawyerUserViolationVo;
|
|
|
@@ -109,10 +110,11 @@ public class LawyerUserViolationServiceImpl extends ServiceImpl<LawyerUserViolat
|
|
|
* 用户举报处理
|
|
|
* <p>
|
|
|
* 处理用户举报信息,包括:
|
|
|
- * 1. 检查订单是否已被举报(一笔订单只能举报一次)
|
|
|
- * 2. 保存举报记录到数据库
|
|
|
- * 3. 向举报人发送受理通知
|
|
|
- * 4. 根据举报内容类型,向被举报人发送通知(如需要)
|
|
|
+ * 1. 参数校验
|
|
|
+ * 2. 查询订单信息并设置举报人和被举报人ID
|
|
|
+ * 3. 检查订单是否已被举报(一笔订单只能举报一次)
|
|
|
+ * 4. 保存举报记录到数据库
|
|
|
+ * 5. 向举报人发送受理通知
|
|
|
* </p>
|
|
|
*
|
|
|
* @param lawyerUserViolation 举报信息对象,不能为null
|
|
|
@@ -124,31 +126,28 @@ public class LawyerUserViolationServiceImpl extends ServiceImpl<LawyerUserViolat
|
|
|
@Override
|
|
|
public int userReporting(LawyerUserViolation lawyerUserViolation) {
|
|
|
// 参数校验
|
|
|
- if (lawyerUserViolation == null) {
|
|
|
- log.warn("用户举报参数为空");
|
|
|
+ validateReportingParams(lawyerUserViolation);
|
|
|
+
|
|
|
+ String orderNumber = lawyerUserViolation.getOrderNumber();
|
|
|
+
|
|
|
+ // 查询订单信息并设置举报人和被举报人ID
|
|
|
+ LawyerConsultationOrder consultationOrder = queryAndSetUserIds(lawyerUserViolation, orderNumber);
|
|
|
+ if (consultationOrder == null) {
|
|
|
+ log.warn("订单不存在或已删除,订单号:{}", orderNumber);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- String reportedUserId = lawyerUserViolation.getReportedUserId();
|
|
|
- String reportingUserId = lawyerUserViolation.getReportingUserId();
|
|
|
- String orderId = lawyerUserViolation.getOrderId();
|
|
|
- log.info("开始处理用户举报,被举报用户ID:{},举报用户ID:{},订单ID:{}",
|
|
|
- reportedUserId, reportingUserId, orderId);
|
|
|
-
|
|
|
try {
|
|
|
// 检查订单是否已被举报(一笔订单只能举报一次)
|
|
|
- if (StringUtils.isNotEmpty(orderId)) {
|
|
|
- boolean hasReported = checkOrderAlreadyReported(orderId);
|
|
|
- if (hasReported) {
|
|
|
- log.warn("订单已被举报,订单ID:{}", orderId);
|
|
|
- throw new RuntimeException("该订单已被举报,无法重复举报");
|
|
|
- }
|
|
|
+ boolean hasReported = checkOrderAlreadyReported(orderNumber);
|
|
|
+ if (hasReported) {
|
|
|
+ log.warn("订单已被举报,订单号:{}", orderNumber);
|
|
|
+ throw new RuntimeException("该订单已被举报,无法重复举报");
|
|
|
}
|
|
|
|
|
|
// 保存举报记录
|
|
|
- int result = lawyerUserViolationMapper.insert(lawyerUserViolation);
|
|
|
+ int result = saveViolationRecord(lawyerUserViolation, consultationOrder);
|
|
|
if (result <= 0) {
|
|
|
- log.warn("用户举报记录保存失败,被举报用户ID:{},举报用户ID:{}", reportedUserId, reportingUserId);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
@@ -157,48 +156,108 @@ public class LawyerUserViolationServiceImpl extends ServiceImpl<LawyerUserViolat
|
|
|
// 向举报人发送受理通知
|
|
|
sendReportNoticeToReporter(lawyerUserViolation);
|
|
|
|
|
|
-// String reportContextType = lawyerUserViolation.getReportContextType();
|
|
|
-// if (StringUtils.isNotEmpty(reportContextType) && reportContextType.contains("6")) {
|
|
|
-// sendReportNoticeToReported(lawyerUserViolation);
|
|
|
-// }
|
|
|
-
|
|
|
log.info("用户举报处理完成,举报ID:{}", lawyerUserViolation.getId());
|
|
|
return result;
|
|
|
|
|
|
} catch (RuntimeException e) {
|
|
|
- // 重新抛出业务异常,保持原有异常信息
|
|
|
+ log.error("用户举报处理业务异常,订单号:{},异常信息:{}", orderNumber, e.getMessage());
|
|
|
throw e;
|
|
|
} catch (Exception e) {
|
|
|
- log.error("用户举报处理异常,被举报用户ID:{},举报用户ID:{},异常信息:{}",
|
|
|
- reportedUserId, reportingUserId, e.getMessage(), e);
|
|
|
+ log.error("用户举报处理异常,订单号:{},异常信息:{}", orderNumber, e.getMessage(), e);
|
|
|
throw new RuntimeException("用户举报处理失败:" + e.getMessage(), e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 校验举报参数
|
|
|
+ *
|
|
|
+ * @param lawyerUserViolation 举报信息对象
|
|
|
+ * @throws RuntimeException 当参数无效时抛出
|
|
|
+ */
|
|
|
+ private void validateReportingParams(LawyerUserViolation lawyerUserViolation) {
|
|
|
+ if (lawyerUserViolation == null) {
|
|
|
+ log.warn("用户举报参数为空");
|
|
|
+ throw new RuntimeException("举报信息不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ String orderNumber = lawyerUserViolation.getOrderNumber();
|
|
|
+ if (StringUtils.isEmpty(orderNumber)) {
|
|
|
+ log.warn("用户举报订单号为空");
|
|
|
+ throw new RuntimeException("订单号不能为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询订单信息并设置举报人和被举报人ID
|
|
|
+ *
|
|
|
+ * @param lawyerUserViolation 举报信息对象
|
|
|
+ * @param orderNumber 订单号
|
|
|
+ * @return 咨询订单对象,如果订单不存在返回null
|
|
|
+ */
|
|
|
+ private LawyerConsultationOrder queryAndSetUserIds(LawyerUserViolation lawyerUserViolation, String orderNumber) {
|
|
|
+ LambdaQueryWrapper<LawyerConsultationOrder> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(LawyerConsultationOrder::getOrderNumber, orderNumber)
|
|
|
+ .eq(LawyerConsultationOrder::getDeleteFlag, 0)
|
|
|
+ .last("LIMIT 1");
|
|
|
+
|
|
|
+ List<LawyerConsultationOrder> orderList = consultationOrderMapper.selectList(queryWrapper);
|
|
|
+ if (CollectionUtils.isEmpty(orderList)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ LawyerConsultationOrder consultationOrder = orderList.get(0);
|
|
|
+ // 设置被举报人ID(律师用户ID)
|
|
|
+ if (consultationOrder.getLawyerUserId() != null) {
|
|
|
+ lawyerUserViolation.setReportedUserId(consultationOrder.getLawyerUserId().toString());
|
|
|
+ }
|
|
|
+ // 设置举报人ID(客户用户ID)
|
|
|
+ if (consultationOrder.getClientUserId() != null) {
|
|
|
+ lawyerUserViolation.setReportingUserId(consultationOrder.getClientUserId().toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ return consultationOrder;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存举报记录
|
|
|
+ *
|
|
|
+ * @param lawyerUserViolation 举报信息对象
|
|
|
+ * @param consultationOrder 咨询订单对象
|
|
|
+ * @return 插入成功的记录数,失败返回0
|
|
|
+ */
|
|
|
+ private int saveViolationRecord(LawyerUserViolation lawyerUserViolation, LawyerConsultationOrder consultationOrder) {
|
|
|
+ int result = lawyerUserViolationMapper.insert(lawyerUserViolation);
|
|
|
+ if (result <= 0) {
|
|
|
+ log.warn("用户举报记录保存失败,被举报用户ID:{},举报用户ID:{}",
|
|
|
+ consultationOrder.getLawyerUserId(), consultationOrder.getClientUserId());
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 检查订单是否已被举报
|
|
|
* <p>
|
|
|
* 根据订单ID查询是否已存在举报记录(一笔订单只能举报一次)
|
|
|
* </p>
|
|
|
*
|
|
|
- * @param orderId 订单ID
|
|
|
+ * @param orderNumber 订单号
|
|
|
* @return true-已举报,false-未举报
|
|
|
*/
|
|
|
- private boolean checkOrderAlreadyReported(String orderId) {
|
|
|
- if (StringUtils.isEmpty(orderId)) {
|
|
|
+ private boolean checkOrderAlreadyReported(String orderNumber) {
|
|
|
+ if (StringUtils.isEmpty(orderNumber)) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
LambdaQueryWrapper<LawyerUserViolation> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(LawyerUserViolation::getOrderId, orderId)
|
|
|
+ queryWrapper.eq(LawyerUserViolation::getOrderNumber, orderNumber)
|
|
|
.last("LIMIT 1");
|
|
|
|
|
|
LawyerUserViolation existingReport = lawyerUserViolationMapper.selectOne(queryWrapper);
|
|
|
return existingReport != null;
|
|
|
} catch (Exception e) {
|
|
|
- log.error("检查订单举报状态异常,订单ID:{},异常信息:{}",
|
|
|
- orderId, e.getMessage(), e);
|
|
|
+ log.error("检查订单举报状态异常,订单号:{},异常信息:{}",
|
|
|
+ orderNumber, e.getMessage(), e);
|
|
|
// 查询异常时,为了安全起见,返回true,阻止重复举报
|
|
|
return true;
|
|
|
}
|
|
|
@@ -755,7 +814,7 @@ public class LawyerUserViolationServiceImpl extends ServiceImpl<LawyerUserViolat
|
|
|
if (PROCESSING_STATUS_APPROVED.equals(processingStatus)) {
|
|
|
// 审批通过
|
|
|
LambdaUpdateWrapper<LawyerConsultationOrder> lawyerConsultationOrderLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
- lawyerConsultationOrderLambdaUpdateWrapper.eq(LawyerConsultationOrder::getOrderNumber, violation.getOrderId());
|
|
|
+ lawyerConsultationOrderLambdaUpdateWrapper.eq(LawyerConsultationOrder::getOrderNumber, violation.getOrderNumber());
|
|
|
lawyerConsultationOrderLambdaUpdateWrapper.set(LawyerConsultationOrder::getOrderStatus, LawyerStatusEnum.REFUNDED.getStatus());
|
|
|
consultationOrderMapper.update(null, lawyerConsultationOrderLambdaUpdateWrapper);
|
|
|
}
|
|
|
@@ -855,7 +914,7 @@ public class LawyerUserViolationServiceImpl extends ServiceImpl<LawyerUserViolat
|
|
|
*/
|
|
|
private NotificationInfo buildReportedNotification(LawyerUserViolation violation) {
|
|
|
NotificationInfo notificationInfo = new NotificationInfo();
|
|
|
- String orderId = violation.getOrderId();
|
|
|
+ String orderId = violation.getOrderNumber();
|
|
|
String message = String.format("用户对编号为%s的订单进行申诉,经核实,用户举报属实,"
|
|
|
+ "订单金额将会退还给用户。", orderId);
|
|
|
notificationInfo.setMessage(message);
|