|
|
@@ -65,6 +65,7 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
private final StoreCommentMapper storeCommentMapper;
|
|
|
private final LawyerUserViolationMapper lawyerUserViolationMapper;
|
|
|
private final CommentAppealMapper commentAppealMapper;
|
|
|
+ private final OrderReviewMapper orderReviewMapper;
|
|
|
|
|
|
/**
|
|
|
* 系统发送者ID
|
|
|
@@ -2070,10 +2071,10 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
/**
|
|
|
* 设置订单列表的评价状态(commonStatus)
|
|
|
* <p>
|
|
|
- * 根据订单ID查询 store_comment 和 lawyer_user_violation 表,设置每个订单的评价状态:
|
|
|
- * 1. 如果 store_comment 表中 businessType=8 且 businessId=订单ID 的记录不存在,则 commonStatus=1
|
|
|
- * 2. 如果 store_comment 存在,但 lawyer_user_violation 表中 report_context_type=3 且 businessId=store_comment.id 的记录不存在,
|
|
|
- * 或者存在但 processing_status 为 0 或 1,则 commonStatus=2
|
|
|
+ * 根据订单ID查询 lawyer_order_review 和 comment_appeals 表,设置每个订单的评价状态:
|
|
|
+ * 1. 如果 lawyer_order_review 表中 order_id=订单ID 的记录不存在,则 commonStatus=1
|
|
|
+ * 2. 如果 lawyer_order_review 存在,但 comment_appeals 表中 comment_id=lawyer_order_review.id 的记录不存在,
|
|
|
+ * 或者存在但 processing_status(status) 为 0 或 1,则 commonStatus=2
|
|
|
* 3. 其他情况 commonStatus=3
|
|
|
* </p>
|
|
|
*
|
|
|
@@ -2096,19 +2097,18 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 查询 store_comment 表,businessType=8,businessId=订单ID
|
|
|
- Map<Integer, StoreComment> orderIdToCommentMap = queryStoreCommentByOrderIds(orderIds);
|
|
|
+ // 查询 lawyer_order_review 表,order_id=订单ID
|
|
|
+ Map<Integer, OrderReview> orderIdToReviewMap = queryOrderReviewByOrderIds(orderIds);
|
|
|
|
|
|
- // 构建订单ID到订单号的映射(用于查询 comment_appeals)
|
|
|
- Map<Integer, String> orderIdToOrderNumberMap = buildOrderIdToOrderNumberMap(voPage.getRecords());
|
|
|
-
|
|
|
- // 提取 store_comment 的 ID 列表和对应的订单号
|
|
|
- Map<Integer, String> commentIdToOrderNumberMap = buildCommentIdToOrderNumberMap(
|
|
|
- orderIdToCommentMap, orderIdToOrderNumberMap);
|
|
|
+ // 提取 lawyer_order_review 的 ID 列表
|
|
|
+ List<Integer> reviewIds = orderIdToReviewMap.values().stream()
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .map(OrderReview::getId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
|
- // 查询 comment_appeals 表,comment_id=store_comment.id,appeal_number=订单号
|
|
|
- Map<String, CommentAppeal> commentAppealMap = queryCommentAppealsByCommentIdsAndOrderNumbers(
|
|
|
- commentIdToOrderNumberMap);
|
|
|
+ // 查询 comment_appeals 表,comment_id=lawyer_order_review.id
|
|
|
+ Map<Integer, CommentAppeal> reviewIdToAppealMap = queryCommentAppealsByReviewIds(reviewIds);
|
|
|
|
|
|
// 为每个订单设置 commonStatus
|
|
|
for (LawyerConsultationOrderVO orderVO : voPage.getRecords()) {
|
|
|
@@ -2117,7 +2117,7 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
}
|
|
|
|
|
|
String commonStatus = calculateCommonStatus(
|
|
|
- orderVO.getId(), orderVO.getOrderNumber(), orderIdToCommentMap, commentAppealMap);
|
|
|
+ orderVO.getId(), orderIdToReviewMap, reviewIdToAppealMap);
|
|
|
orderVO.setCommonStatus(commonStatus);
|
|
|
}
|
|
|
|
|
|
@@ -2125,37 +2125,36 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 根据订单ID列表查询 store_comment 记录
|
|
|
+ * 根据订单ID列表查询 lawyer_order_review 记录
|
|
|
* <p>
|
|
|
- * 查询条件:businessType=8,businessId=订单ID
|
|
|
- * 如果一个 businessId 存在多条记录,只取最新的一条(按创建时间倒序)
|
|
|
+ * 查询条件:order_id=订单ID
|
|
|
+ * 如果一个 order_id 存在多条记录,只取最新的一条(按创建时间倒序)
|
|
|
* </p>
|
|
|
*
|
|
|
* @param orderIds 订单ID列表
|
|
|
- * @return 订单ID到评论记录的映射,key为订单ID,value为评论记录(每个订单ID对应最新的一条评论)
|
|
|
+ * @return 订单ID到评价记录的映射,key为订单ID,value为评价记录(每个订单ID对应最新的一条评价)
|
|
|
*/
|
|
|
- private Map<Integer, StoreComment> queryStoreCommentByOrderIds(List<Integer> orderIds) {
|
|
|
+ private Map<Integer, OrderReview> queryOrderReviewByOrderIds(List<Integer> orderIds) {
|
|
|
if (CollectionUtils.isEmpty(orderIds)) {
|
|
|
return Collections.emptyMap();
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- LambdaQueryWrapper<StoreComment> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(StoreComment::getBusinessType, 5)
|
|
|
- .in(StoreComment::getBusinessId, orderIds)
|
|
|
- .eq(StoreComment::getDeleteFlag, 0)
|
|
|
- .orderByDesc(StoreComment::getCreatedTime);
|
|
|
+ LambdaQueryWrapper<OrderReview> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.in(OrderReview::getOrderId, orderIds)
|
|
|
+ .eq(OrderReview::getDeleteFlag, 0)
|
|
|
+ .orderByDesc(OrderReview::getCreatedTime);
|
|
|
|
|
|
- List<StoreComment> commentList = storeCommentMapper.selectList(queryWrapper);
|
|
|
+ List<OrderReview> reviewList = orderReviewMapper.selectList(queryWrapper);
|
|
|
|
|
|
- // 按 businessId 分组,每个 businessId 只保留最新的一条记录
|
|
|
- // 由于查询已按创建时间倒序排序,同一个 businessId 的第一条记录即为最新的
|
|
|
- return commentList.stream()
|
|
|
+ // 按 orderId 分组,每个 orderId 只保留最新的一条记录
|
|
|
+ // 由于查询已按创建时间倒序排序,同一个 orderId 的第一条记录即为最新的
|
|
|
+ return reviewList.stream()
|
|
|
.filter(Objects::nonNull)
|
|
|
- .filter(comment -> comment.getId() != null && comment.getBusinessId() != null)
|
|
|
+ .filter(review -> review.getId() != null && review.getOrderId() != null)
|
|
|
.collect(Collectors.toMap(
|
|
|
- StoreComment::getBusinessId,
|
|
|
- comment -> comment,
|
|
|
+ OrderReview::getOrderId,
|
|
|
+ review -> review,
|
|
|
(existing, replacement) -> {
|
|
|
// 由于已按创建时间倒序排序,existing 是先遍历到的记录(即最新的)
|
|
|
// 但为了安全起见,仍然比较创建时间,确保保留最新的记录
|
|
|
@@ -2178,118 +2177,55 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
}
|
|
|
));
|
|
|
} catch (Exception e) {
|
|
|
- log.error("查询 store_comment 记录异常,orderIds={},异常信息:{}", orderIds, e.getMessage(), e);
|
|
|
+ log.error("查询 lawyer_order_review 记录异常,orderIds={},异常信息:{}", orderIds, e.getMessage(), e);
|
|
|
return Collections.emptyMap();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 构建订单ID到订单号的映射
|
|
|
+ * 根据评价ID列表查询 comment_appeals 记录
|
|
|
* <p>
|
|
|
- * 从订单VO列表中提取订单ID和订单号的对应关系
|
|
|
+ * 查询条件:comment_id=评价ID(lawyer_order_review.id)
|
|
|
* </p>
|
|
|
*
|
|
|
- * @param orderList 订单VO列表
|
|
|
- * @return 订单ID到订单号的映射,key为订单ID,value为订单号
|
|
|
+ * @param reviewIds 评价ID列表(lawyer_order_review.id)
|
|
|
+ * @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>
|
|
|
- * 根据订单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>
|
|
|
- * 查询条件:comment_id=评论ID,appeal_number=订单号
|
|
|
- * </p>
|
|
|
- *
|
|
|
- * @param commentIdToOrderNumberMap 评论ID到订单号的映射
|
|
|
- * @return 申诉记录映射,key为"commentId_orderNumber"格式的字符串,value为申诉记录
|
|
|
- */
|
|
|
- private Map<String, CommentAppeal> queryCommentAppealsByCommentIdsAndOrderNumbers(
|
|
|
- Map<Integer, String> commentIdToOrderNumberMap) {
|
|
|
- if (commentIdToOrderNumberMap == null || commentIdToOrderNumberMap.isEmpty()) {
|
|
|
+ private Map<Integer, CommentAppeal> queryCommentAppealsByReviewIds(List<Integer> reviewIds) {
|
|
|
+ if (CollectionUtils.isEmpty(reviewIds)) {
|
|
|
return Collections.emptyMap();
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- // 提取评论ID列表和订单号列表
|
|
|
- List<Integer> commentIds = new ArrayList<>(commentIdToOrderNumberMap.keySet());
|
|
|
- List<String> orderNumbers = new ArrayList<>(commentIdToOrderNumberMap.values());
|
|
|
-
|
|
|
// 构建查询条件
|
|
|
LambdaQueryWrapper<CommentAppeal> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.in(CommentAppeal::getCommentId, commentIds)
|
|
|
- .in(CommentAppeal::getAppealNumber, orderNumbers)
|
|
|
+ queryWrapper.in(CommentAppeal::getCommentId, reviewIds)
|
|
|
.eq(CommentAppeal::getDeleteFlag, DELETE_FLAG_NOT_DELETED);
|
|
|
|
|
|
List<CommentAppeal> appealList = commentAppealMapper.selectList(queryWrapper);
|
|
|
|
|
|
- // 构建映射:key为"commentId_orderNumber",value为申诉记录
|
|
|
- Map<String, CommentAppeal> resultMap = new HashMap<>();
|
|
|
+ // 构建映射:key为评价ID,value为申诉记录
|
|
|
+ // 如果一个评价有多个申诉记录,只取第一个(通常一个评价应该只有一个申诉记录)
|
|
|
+ Map<Integer, CommentAppeal> resultMap = new HashMap<>();
|
|
|
|
|
|
for (CommentAppeal appeal : appealList) {
|
|
|
- if (appeal == null || appeal.getCommentId() == null || appeal.getAppealNumber() == null) {
|
|
|
+ if (appeal == null || appeal.getCommentId() == null) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- // 验证该申诉记录是否匹配对应的订单号
|
|
|
- String expectedOrderNumber = commentIdToOrderNumberMap.get(appeal.getCommentId());
|
|
|
- if (expectedOrderNumber != null && expectedOrderNumber.equals(appeal.getAppealNumber())) {
|
|
|
- String key = appeal.getCommentId() + "_" + appeal.getAppealNumber();
|
|
|
- resultMap.put(key, appeal);
|
|
|
+ // 如果已经存在该评价的申诉记录,保留第一个(先查询到的)
|
|
|
+ if (!resultMap.containsKey(appeal.getCommentId())) {
|
|
|
+ resultMap.put(appeal.getCommentId(), appeal);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- log.debug("查询 comment_appeals 记录成功,commentIds={},查询到记录数={}",
|
|
|
- commentIds, resultMap.size());
|
|
|
+ log.debug("查询 comment_appeals 记录成功,reviewIds={},查询到记录数={}",
|
|
|
+ reviewIds, resultMap.size());
|
|
|
|
|
|
return resultMap;
|
|
|
} catch (Exception e) {
|
|
|
- log.error("查询 comment_appeals 记录异常,commentIdToOrderNumberMap={},异常信息:{}",
|
|
|
- commentIdToOrderNumberMap, e.getMessage(), e);
|
|
|
+ log.error("查询 comment_appeals 记录异常,reviewIds={},异常信息:{}",
|
|
|
+ reviewIds, e.getMessage(), e);
|
|
|
return Collections.emptyMap();
|
|
|
}
|
|
|
}
|
|
|
@@ -2298,52 +2234,48 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
* 计算订单的评价状态
|
|
|
* <p>
|
|
|
* 根据查询结果计算订单的 commonStatus 值:
|
|
|
- * 1. 如果 store_comment 表中没有记录,则 commonStatus=1
|
|
|
- * 2. 如果 comment_appeals 表中没有记录,或者 processing_status 为 0 或 1,则 commonStatus=2
|
|
|
+ * 1. 如果 lawyer_order_review 表中没有记录,则 commonStatus=1
|
|
|
+ * 2. 如果 comment_appeals 表中没有记录,或者 processing_status(status) 为 0 或 1,则 commonStatus=2
|
|
|
* 3. 其他情况 commonStatus=3
|
|
|
* </p>
|
|
|
*
|
|
|
* @param orderId 订单ID
|
|
|
- * @param orderNumber 订单号
|
|
|
- * @param orderIdToCommentMap 订单ID到评论记录的映射
|
|
|
- * @param commentAppealMap 申诉记录映射,key为"commentId_orderNumber"格式
|
|
|
+ * @param orderIdToReviewMap 订单ID到评价记录的映射
|
|
|
+ * @param reviewIdToAppealMap 评价ID到申诉记录的映射
|
|
|
* @return 评价状态字符串("1"、"2"或"3")
|
|
|
*/
|
|
|
private String calculateCommonStatus(Integer orderId,
|
|
|
- String orderNumber,
|
|
|
- Map<Integer, StoreComment> orderIdToCommentMap,
|
|
|
- Map<String, CommentAppeal> commentAppealMap) {
|
|
|
- // 第一步:查询 store_comment 表
|
|
|
- StoreComment comment = orderIdToCommentMap.get(orderId);
|
|
|
+ Map<Integer, OrderReview> orderIdToReviewMap,
|
|
|
+ Map<Integer, CommentAppeal> reviewIdToAppealMap) {
|
|
|
+ // 第一步:查询 lawyer_order_review 表
|
|
|
+ OrderReview review = orderIdToReviewMap.get(orderId);
|
|
|
|
|
|
// 如果关联不出来记录,则 commonStatus=1
|
|
|
- if (comment == null || comment.getId() == null) {
|
|
|
- log.debug("订单未找到评论记录,设置 commonStatus=1,orderId={}", orderId);
|
|
|
+ if (review == null || review.getId() == null) {
|
|
|
+ log.debug("订单未找到评价记录,设置 commonStatus=1,orderId={}", orderId);
|
|
|
return "1";
|
|
|
}
|
|
|
|
|
|
// 第二步:查询 comment_appeals 表
|
|
|
- // 构建查询key:commentId_orderNumber
|
|
|
- String appealKey = comment.getId() + "_" + orderNumber;
|
|
|
- CommentAppeal appeal = commentAppealMap.get(appealKey);
|
|
|
+ CommentAppeal appeal = reviewIdToAppealMap.get(review.getId());
|
|
|
|
|
|
- // 如果关联不出来或者关联出来的 status 为 0 或者 1,则 commonStatus=2
|
|
|
+ // 如果关联不出来或者关联出来的 processing_status(status) 为 0 或者 1,则 commonStatus=2
|
|
|
if (appeal == null) {
|
|
|
- log.debug("评论未找到申诉记录,设置 commonStatus=2,orderId={}, commentId={}, orderNumber={}",
|
|
|
- orderId, comment.getId(), orderNumber);
|
|
|
+ log.debug("评价未找到申诉记录,设置 commonStatus=2,orderId={}, reviewId={}",
|
|
|
+ orderId, review.getId());
|
|
|
return "2";
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
+ if (status == null || status == 0 || status == 2) {
|
|
|
+ log.debug("申诉记录处理状态为0或1,设置 commonStatus=2,orderId={}, reviewId={}, status={}",
|
|
|
+ orderId, review.getId(), status);
|
|
|
return "2";
|
|
|
}
|
|
|
|
|
|
// 其他情况 commonStatus=3
|
|
|
- log.debug("设置 commonStatus=3,orderId={}, commentId={}, orderNumber={}, status={}",
|
|
|
- orderId, comment.getId(), orderNumber, status);
|
|
|
+ log.debug("设置 commonStatus=3,orderId={}, reviewId={}, status={}",
|
|
|
+ orderId, review.getId(), status);
|
|
|
return "3";
|
|
|
}
|
|
|
|