|
|
@@ -64,6 +64,7 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
private final LifeMessageMapper lifeMessageMapper;
|
|
|
private final StoreCommentMapper storeCommentMapper;
|
|
|
private final LawyerUserViolationMapper lawyerUserViolationMapper;
|
|
|
+ private final CommentAppealMapper commentAppealMapper;
|
|
|
|
|
|
/**
|
|
|
* 系统发送者ID
|
|
|
@@ -71,6 +72,11 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
private static final String SYSTEM_SENDER_ID = "system";
|
|
|
|
|
|
/**
|
|
|
+ * 删除标记:未删除
|
|
|
+ */
|
|
|
+ private static final Integer DELETE_FLAG_NOT_DELETED = 0;
|
|
|
+
|
|
|
+ /**
|
|
|
* 金额单位转换:分转元
|
|
|
*/
|
|
|
private static final int FEN_TO_YUAN = 100;
|
|
|
@@ -2083,14 +2089,16 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
// 查询 store_comment 表,businessType=8,businessId=订单ID
|
|
|
Map<Integer, StoreComment> orderIdToCommentMap = queryStoreCommentByOrderIds(orderIds);
|
|
|
|
|
|
- // 提取 store_comment 的 ID 列表
|
|
|
- List<Integer> commentIds = orderIdToCommentMap.values().stream()
|
|
|
- .map(StoreComment::getId)
|
|
|
- .filter(Objects::nonNull)
|
|
|
- .collect(Collectors.toList());
|
|
|
+ // 构建订单ID到订单号的映射(用于查询 comment_appeals)
|
|
|
+ Map<Integer, String> orderIdToOrderNumberMap = buildOrderIdToOrderNumberMap(voPage.getRecords());
|
|
|
+
|
|
|
+ // 提取 store_comment 的 ID 列表和对应的订单号
|
|
|
+ Map<Integer, String> commentIdToOrderNumberMap = buildCommentIdToOrderNumberMap(
|
|
|
+ orderIdToCommentMap, orderIdToOrderNumberMap);
|
|
|
|
|
|
- // 查询 lawyer_user_violation 表,report_context_type=3,businessId=store_comment.id
|
|
|
- Map<Integer, LawyerUserViolation> commentIdToViolationMap = queryLawyerUserViolationByCommentIds(commentIds);
|
|
|
+ // 查询 comment_appeals 表,comment_id=store_comment.id,appeal_number=订单号
|
|
|
+ Map<String, CommentAppeal> commentAppealMap = queryCommentAppealsByCommentIdsAndOrderNumbers(
|
|
|
+ commentIdToOrderNumberMap);
|
|
|
|
|
|
// 为每个订单设置 commonStatus
|
|
|
for (LawyerConsultationOrderVO orderVO : voPage.getRecords()) {
|
|
|
@@ -2098,7 +2106,8 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- String commonStatus = calculateCommonStatus(orderVO.getId(), orderIdToCommentMap, commentIdToViolationMap);
|
|
|
+ String commonStatus = calculateCommonStatus(
|
|
|
+ orderVO.getId(), orderVO.getOrderNumber(), orderIdToCommentMap, commentAppealMap);
|
|
|
orderVO.setCommonStatus(commonStatus);
|
|
|
}
|
|
|
|
|
|
@@ -2122,7 +2131,7 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
|
|
|
try {
|
|
|
LambdaQueryWrapper<StoreComment> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(StoreComment::getBusinessType, 8)
|
|
|
+ queryWrapper.eq(StoreComment::getBusinessType, 5)
|
|
|
.in(StoreComment::getBusinessId, orderIds)
|
|
|
.eq(StoreComment::getDeleteFlag, 0)
|
|
|
.orderByDesc(StoreComment::getCreatedTime);
|
|
|
@@ -2165,88 +2174,112 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 根据评论ID列表查询 lawyer_user_violation 记录
|
|
|
+ * 构建订单ID到订单号的映射
|
|
|
+ * <p>
|
|
|
+ * 从订单VO列表中提取订单ID和订单号的对应关系
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @param orderList 订单VO列表
|
|
|
+ * @return 订单ID到订单号的映射,key为订单ID,value为订单号
|
|
|
+ */
|
|
|
+ private Map<Integer, String> buildOrderIdToOrderNumberMap(List<LawyerConsultationOrderVO> orderList) {
|
|
|
+ if (CollectionUtils.isEmpty(orderList)) {
|
|
|
+ return Collections.emptyMap();
|
|
|
+ }
|
|
|
+
|
|
|
+ return orderList.stream()
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .filter(order -> order.getId() != null && StringUtils.hasText(order.getOrderNumber()))
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ LawyerConsultationOrderVO::getId,
|
|
|
+ LawyerConsultationOrderVO::getOrderNumber,
|
|
|
+ (existing, replacement) -> existing
|
|
|
+ ));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建评论ID到订单号的映射
|
|
|
* <p>
|
|
|
- * 查询条件:report_context_type=3,businessId=评论ID
|
|
|
+ * 根据订单ID到评论记录的映射和订单ID到订单号的映射,构建评论ID到订单号的映射
|
|
|
* </p>
|
|
|
+ *
|
|
|
+ * @param orderIdToCommentMap 订单ID到评论记录的映射
|
|
|
+ * @param orderIdToOrderNumberMap 订单ID到订单号的映射
|
|
|
+ * @return 评论ID到订单号的映射,key为评论ID,value为订单号
|
|
|
+ */
|
|
|
+ private Map<Integer, String> buildCommentIdToOrderNumberMap(
|
|
|
+ Map<Integer, StoreComment> orderIdToCommentMap,
|
|
|
+ Map<Integer, String> orderIdToOrderNumberMap) {
|
|
|
+ Map<Integer, String> resultMap = new HashMap<>();
|
|
|
+
|
|
|
+ for (Map.Entry<Integer, StoreComment> entry : orderIdToCommentMap.entrySet()) {
|
|
|
+ Integer orderId = entry.getKey();
|
|
|
+ StoreComment comment = entry.getValue();
|
|
|
+
|
|
|
+ if (comment == null || comment.getId() == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ String orderNumber = orderIdToOrderNumberMap.get(orderId);
|
|
|
+ if (StringUtils.hasText(orderNumber)) {
|
|
|
+ resultMap.put(comment.getId(), orderNumber);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据评论ID和订单号列表查询 comment_appeals 记录
|
|
|
* <p>
|
|
|
- * 注意:如果 LawyerUserViolation 表有 businessId 字段,直接通过 businessId 关联
|
|
|
- * 如果没有 businessId 字段,可能需要通过其他字段(如 order_number)间接关联
|
|
|
+ * 查询条件:comment_id=评论ID,appeal_number=订单号
|
|
|
* </p>
|
|
|
*
|
|
|
- * @param commentIds 评论ID列表
|
|
|
- * @return 评论ID到举报记录的映射,key为评论ID,value为举报记录
|
|
|
+ * @param commentIdToOrderNumberMap 评论ID到订单号的映射
|
|
|
+ * @return 申诉记录映射,key为"commentId_orderNumber"格式的字符串,value为申诉记录
|
|
|
*/
|
|
|
- private Map<Integer, LawyerUserViolation> queryLawyerUserViolationByCommentIds(List<Integer> commentIds) {
|
|
|
- if (CollectionUtils.isEmpty(commentIds)) {
|
|
|
+ private Map<String, CommentAppeal> queryCommentAppealsByCommentIdsAndOrderNumbers(
|
|
|
+ Map<Integer, String> commentIdToOrderNumberMap) {
|
|
|
+ if (commentIdToOrderNumberMap == null || commentIdToOrderNumberMap.isEmpty()) {
|
|
|
return Collections.emptyMap();
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- // 使用 QueryWrapper 构建查询条件,直接使用字段名
|
|
|
- // 使用 selectMaps 方法获取所有字段(包括 business_id,即使实体类中没有定义)
|
|
|
- QueryWrapper<LawyerUserViolation> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.select("id", "business_id", "report_context_type", "processing_status", "delete_flag")
|
|
|
- .eq("report_context_type", "3")
|
|
|
- .eq("delete_flag", 0)
|
|
|
- .in("business_id", commentIds);
|
|
|
-
|
|
|
- // 使用 selectMaps 获取 Map 列表,可以获取所有字段值
|
|
|
- List<Map<String, Object>> violationMapList = lawyerUserViolationMapper.selectMaps(queryWrapper);
|
|
|
+ // 提取评论ID列表和订单号列表
|
|
|
+ List<Integer> commentIds = new ArrayList<>(commentIdToOrderNumberMap.keySet());
|
|
|
+ List<String> orderNumbers = new ArrayList<>(commentIdToOrderNumberMap.values());
|
|
|
|
|
|
- // 构建评论ID到举报记录的映射
|
|
|
- // 从 Map 中提取 business_id 和 processing_status,构建 LawyerUserViolation 对象
|
|
|
- Map<Integer, LawyerUserViolation> resultMap = new HashMap<>();
|
|
|
-
|
|
|
- for (Map<String, Object> violationMap : violationMapList) {
|
|
|
- Object businessIdObj = violationMap.get("business_id");
|
|
|
- if (businessIdObj == null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- Integer businessId;
|
|
|
- if (businessIdObj instanceof Integer) {
|
|
|
- businessId = (Integer) businessIdObj;
|
|
|
- } else if (businessIdObj instanceof Number) {
|
|
|
- businessId = ((Number) businessIdObj).intValue();
|
|
|
- } else {
|
|
|
- try {
|
|
|
- businessId = Integer.parseInt(businessIdObj.toString());
|
|
|
- } catch (NumberFormatException e) {
|
|
|
- log.warn("business_id 转换失败,跳过该记录,businessIdObj={}", businessIdObj);
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (!commentIds.contains(businessId)) {
|
|
|
+ // 构建查询条件
|
|
|
+ LambdaQueryWrapper<CommentAppeal> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.in(CommentAppeal::getCommentId, commentIds)
|
|
|
+ .in(CommentAppeal::getAppealNumber, orderNumbers)
|
|
|
+ .eq(CommentAppeal::getDeleteFlag, DELETE_FLAG_NOT_DELETED);
|
|
|
+
|
|
|
+ List<CommentAppeal> appealList = commentAppealMapper.selectList(queryWrapper);
|
|
|
+
|
|
|
+ // 构建映射:key为"commentId_orderNumber",value为申诉记录
|
|
|
+ Map<String, CommentAppeal> resultMap = new HashMap<>();
|
|
|
+
|
|
|
+ for (CommentAppeal appeal : appealList) {
|
|
|
+ if (appeal == null || appeal.getCommentId() == null || appeal.getAppealNumber() == null) {
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
- // 创建 LawyerUserViolation 对象并设置关键字段
|
|
|
- LawyerUserViolation violation = new LawyerUserViolation();
|
|
|
- Object idObj = violationMap.get("id");
|
|
|
- if (idObj instanceof Integer) {
|
|
|
- violation.setId((Integer) idObj);
|
|
|
- } else if (idObj instanceof Number) {
|
|
|
- violation.setId(((Number) idObj).intValue());
|
|
|
- }
|
|
|
-
|
|
|
- Object processingStatusObj = violationMap.get("processing_status");
|
|
|
- if (processingStatusObj != null) {
|
|
|
- violation.setProcessingStatus(processingStatusObj.toString());
|
|
|
+
|
|
|
+ // 验证该申诉记录是否匹配对应的订单号
|
|
|
+ String expectedOrderNumber = commentIdToOrderNumberMap.get(appeal.getCommentId());
|
|
|
+ if (expectedOrderNumber != null && expectedOrderNumber.equals(appeal.getAppealNumber())) {
|
|
|
+ String key = appeal.getCommentId() + "_" + appeal.getAppealNumber();
|
|
|
+ resultMap.put(key, appeal);
|
|
|
}
|
|
|
-
|
|
|
- resultMap.put(businessId, violation);
|
|
|
}
|
|
|
-
|
|
|
- log.debug("查询 lawyer_user_violation 记录成功,commentIds={},查询到记录数={}",
|
|
|
+
|
|
|
+ log.debug("查询 comment_appeals 记录成功,commentIds={},查询到记录数={}",
|
|
|
commentIds, resultMap.size());
|
|
|
-
|
|
|
+
|
|
|
return resultMap;
|
|
|
-
|
|
|
} catch (Exception e) {
|
|
|
- log.error("查询 lawyer_user_violation 记录异常,commentIds={},异常信息:{}", commentIds, e.getMessage(), e);
|
|
|
- // 如果查询失败(可能是字段不存在),返回空映射
|
|
|
+ log.error("查询 comment_appeals 记录异常,commentIdToOrderNumberMap={},异常信息:{}",
|
|
|
+ commentIdToOrderNumberMap, e.getMessage(), e);
|
|
|
return Collections.emptyMap();
|
|
|
}
|
|
|
}
|
|
|
@@ -2254,17 +2287,22 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
/**
|
|
|
* 计算订单的评价状态
|
|
|
* <p>
|
|
|
- * 根据查询结果计算订单的 commonStatus 值
|
|
|
+ * 根据查询结果计算订单的 commonStatus 值:
|
|
|
+ * 1. 如果 store_comment 表中没有记录,则 commonStatus=1
|
|
|
+ * 2. 如果 comment_appeals 表中没有记录,或者 processing_status 为 0 或 1,则 commonStatus=2
|
|
|
+ * 3. 其他情况 commonStatus=3
|
|
|
* </p>
|
|
|
*
|
|
|
- * @param orderId 订单ID
|
|
|
- * @param orderIdToCommentMap 订单ID到评论记录的映射
|
|
|
- * @param commentIdToViolationMap 评论ID到举报记录的映射
|
|
|
+ * @param orderId 订单ID
|
|
|
+ * @param orderNumber 订单号
|
|
|
+ * @param orderIdToCommentMap 订单ID到评论记录的映射
|
|
|
+ * @param commentAppealMap 申诉记录映射,key为"commentId_orderNumber"格式
|
|
|
* @return 评价状态字符串("1"、"2"或"3")
|
|
|
*/
|
|
|
private String calculateCommonStatus(Integer orderId,
|
|
|
+ String orderNumber,
|
|
|
Map<Integer, StoreComment> orderIdToCommentMap,
|
|
|
- Map<Integer, LawyerUserViolation> commentIdToViolationMap) {
|
|
|
+ Map<String, CommentAppeal> commentAppealMap) {
|
|
|
// 第一步:查询 store_comment 表
|
|
|
StoreComment comment = orderIdToCommentMap.get(orderId);
|
|
|
|
|
|
@@ -2274,25 +2312,28 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
return "1";
|
|
|
}
|
|
|
|
|
|
- // 第二步:查询 lawyer_user_violation 表
|
|
|
- LawyerUserViolation violation = commentIdToViolationMap.get(comment.getId());
|
|
|
+ // 第二步:查询 comment_appeals 表
|
|
|
+ // 构建查询key:commentId_orderNumber
|
|
|
+ String appealKey = comment.getId() + "_" + orderNumber;
|
|
|
+ CommentAppeal appeal = commentAppealMap.get(appealKey);
|
|
|
|
|
|
- // 如果关联不出来或者关联出来的 processing_status 为 0 或者 1,则 commonStatus=2
|
|
|
- if (violation == null) {
|
|
|
- log.debug("评论未找到举报记录,设置 commonStatus=2,orderId={}, commentId={}", orderId, comment.getId());
|
|
|
+ // 如果关联不出来或者关联出来的 status 为 0 或者 1,则 commonStatus=2
|
|
|
+ if (appeal == null) {
|
|
|
+ log.debug("评论未找到申诉记录,设置 commonStatus=2,orderId={}, commentId={}, orderNumber={}",
|
|
|
+ orderId, comment.getId(), orderNumber);
|
|
|
return "2";
|
|
|
}
|
|
|
|
|
|
- String processingStatus = violation.getProcessingStatus();
|
|
|
- if (processingStatus == null || "0".equals(processingStatus) || "1".equals(processingStatus)) {
|
|
|
- log.debug("举报记录处理状态为0或1,设置 commonStatus=2,orderId={}, commentId={}, processingStatus={}",
|
|
|
- orderId, comment.getId(), processingStatus);
|
|
|
+ Integer status = appeal.getStatus();
|
|
|
+ if (status == null || status == 0 || status == 1) {
|
|
|
+ log.debug("申诉记录处理状态为0或1,设置 commonStatus=2,orderId={}, commentId={}, orderNumber={}, status={}",
|
|
|
+ orderId, comment.getId(), orderNumber, status);
|
|
|
return "2";
|
|
|
}
|
|
|
|
|
|
// 其他情况 commonStatus=3
|
|
|
- log.debug("设置 commonStatus=3,orderId={}, commentId={}, processingStatus={}",
|
|
|
- orderId, comment.getId(), processingStatus);
|
|
|
+ log.debug("设置 commonStatus=3,orderId={}, commentId={}, orderNumber={}, status={}",
|
|
|
+ orderId, comment.getId(), orderNumber, status);
|
|
|
return "3";
|
|
|
}
|
|
|
|