|
|
@@ -62,6 +62,8 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
private final WebSocketProcess webSocketProcess;
|
|
|
|
|
|
private final LifeMessageMapper lifeMessageMapper;
|
|
|
+ private final StoreCommentMapper storeCommentMapper;
|
|
|
+ private final LawyerUserViolationMapper lawyerUserViolationMapper;
|
|
|
|
|
|
/**
|
|
|
* 系统发送者ID
|
|
|
@@ -669,6 +671,9 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
|
|
|
// 设置订单价格字符串
|
|
|
setOrderPriceStrForOrderList(voPage);
|
|
|
+
|
|
|
+ // 设置评价状态
|
|
|
+ setCommonStatusForOrderList(voPage);
|
|
|
}
|
|
|
|
|
|
// 判断工作日信息
|
|
|
@@ -2046,6 +2051,251 @@ 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
|
|
|
+ * 3. 其他情况 commonStatus=3
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @param voPage 订单分页对象
|
|
|
+ */
|
|
|
+ private void setCommonStatusForOrderList(IPage<LawyerConsultationOrderVO> voPage) {
|
|
|
+ if (voPage == null || CollectionUtils.isEmpty(voPage.getRecords())) {
|
|
|
+ log.debug("订单列表为空,跳过设置评价状态");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 提取订单ID列表
|
|
|
+ List<Integer> orderIds = voPage.getRecords().stream()
|
|
|
+ .map(LawyerConsultationOrderVO::getId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(orderIds)) {
|
|
|
+ log.debug("订单ID列表为空,跳过设置评价状态");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询 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());
|
|
|
+
|
|
|
+ // 查询 lawyer_user_violation 表,report_context_type=3,businessId=store_comment.id
|
|
|
+ Map<Integer, LawyerUserViolation> commentIdToViolationMap = queryLawyerUserViolationByCommentIds(commentIds);
|
|
|
+
|
|
|
+ // 为每个订单设置 commonStatus
|
|
|
+ for (LawyerConsultationOrderVO orderVO : voPage.getRecords()) {
|
|
|
+ if (orderVO == null || orderVO.getId() == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ String commonStatus = calculateCommonStatus(orderVO.getId(), orderIdToCommentMap, commentIdToViolationMap);
|
|
|
+ orderVO.setCommonStatus(commonStatus);
|
|
|
+ }
|
|
|
+
|
|
|
+ log.debug("设置订单评价状态完成,订单数量={}", voPage.getRecords().size());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据订单ID列表查询 store_comment 记录
|
|
|
+ * <p>
|
|
|
+ * 查询条件:businessType=8,businessId=订单ID
|
|
|
+ * 如果一个 businessId 存在多条记录,只取最新的一条(按创建时间倒序)
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @param orderIds 订单ID列表
|
|
|
+ * @return 订单ID到评论记录的映射,key为订单ID,value为评论记录(每个订单ID对应最新的一条评论)
|
|
|
+ */
|
|
|
+ private Map<Integer, StoreComment> queryStoreCommentByOrderIds(List<Integer> orderIds) {
|
|
|
+ if (CollectionUtils.isEmpty(orderIds)) {
|
|
|
+ return Collections.emptyMap();
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ LambdaQueryWrapper<StoreComment> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(StoreComment::getBusinessType, 8)
|
|
|
+ .in(StoreComment::getBusinessId, orderIds)
|
|
|
+ .eq(StoreComment::getDeleteFlag, 0)
|
|
|
+ .orderByDesc(StoreComment::getCreatedTime);
|
|
|
+
|
|
|
+ List<StoreComment> commentList = storeCommentMapper.selectList(queryWrapper);
|
|
|
+
|
|
|
+ // 按 businessId 分组,每个 businessId 只保留最新的一条记录
|
|
|
+ // 由于查询已按创建时间倒序排序,同一个 businessId 的第一条记录即为最新的
|
|
|
+ return commentList.stream()
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .filter(comment -> comment.getId() != null && comment.getBusinessId() != null)
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ StoreComment::getBusinessId,
|
|
|
+ comment -> comment,
|
|
|
+ (existing, replacement) -> {
|
|
|
+ // 由于已按创建时间倒序排序,existing 是先遍历到的记录(即最新的)
|
|
|
+ // 但为了安全起见,仍然比较创建时间,确保保留最新的记录
|
|
|
+ if (existing.getCreatedTime() != null && replacement.getCreatedTime() != null) {
|
|
|
+ // existing.getCreatedTime() >= replacement.getCreatedTime()(因为已排序)
|
|
|
+ return existing.getCreatedTime().after(replacement.getCreatedTime())
|
|
|
+ || existing.getCreatedTime().equals(replacement.getCreatedTime())
|
|
|
+ ? existing
|
|
|
+ : replacement;
|
|
|
+ } else if (existing.getCreatedTime() != null) {
|
|
|
+ // existing 有创建时间,replacement 没有,保留 existing
|
|
|
+ return existing;
|
|
|
+ } else if (replacement.getCreatedTime() != null) {
|
|
|
+ // replacement 有创建时间,existing 没有,保留 replacement
|
|
|
+ return replacement;
|
|
|
+ } else {
|
|
|
+ // 都没有创建时间,保留已存在的记录(先遍历到的,即排序后的第一条)
|
|
|
+ return existing;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询 store_comment 记录异常,orderIds={},异常信息:{}", orderIds, e.getMessage(), e);
|
|
|
+ return Collections.emptyMap();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据评论ID列表查询 lawyer_user_violation 记录
|
|
|
+ * <p>
|
|
|
+ * 查询条件:report_context_type=3,businessId=评论ID
|
|
|
+ * </p>
|
|
|
+ * <p>
|
|
|
+ * 注意:如果 LawyerUserViolation 表有 businessId 字段,直接通过 businessId 关联
|
|
|
+ * 如果没有 businessId 字段,可能需要通过其他字段(如 order_number)间接关联
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @param commentIds 评论ID列表
|
|
|
+ * @return 评论ID到举报记录的映射,key为评论ID,value为举报记录
|
|
|
+ */
|
|
|
+ private Map<Integer, LawyerUserViolation> queryLawyerUserViolationByCommentIds(List<Integer> commentIds) {
|
|
|
+ if (CollectionUtils.isEmpty(commentIds)) {
|
|
|
+ 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到举报记录的映射
|
|
|
+ // 从 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)) {
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+
|
|
|
+ resultMap.put(businessId, violation);
|
|
|
+ }
|
|
|
+
|
|
|
+ log.debug("查询 lawyer_user_violation 记录成功,commentIds={},查询到记录数={}",
|
|
|
+ commentIds, resultMap.size());
|
|
|
+
|
|
|
+ return resultMap;
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询 lawyer_user_violation 记录异常,commentIds={},异常信息:{}", commentIds, e.getMessage(), e);
|
|
|
+ // 如果查询失败(可能是字段不存在),返回空映射
|
|
|
+ return Collections.emptyMap();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算订单的评价状态
|
|
|
+ * <p>
|
|
|
+ * 根据查询结果计算订单的 commonStatus 值
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @param orderId 订单ID
|
|
|
+ * @param orderIdToCommentMap 订单ID到评论记录的映射
|
|
|
+ * @param commentIdToViolationMap 评论ID到举报记录的映射
|
|
|
+ * @return 评价状态字符串("1"、"2"或"3")
|
|
|
+ */
|
|
|
+ private String calculateCommonStatus(Integer orderId,
|
|
|
+ Map<Integer, StoreComment> orderIdToCommentMap,
|
|
|
+ Map<Integer, LawyerUserViolation> commentIdToViolationMap) {
|
|
|
+ // 第一步:查询 store_comment 表
|
|
|
+ StoreComment comment = orderIdToCommentMap.get(orderId);
|
|
|
+
|
|
|
+ // 如果关联不出来记录,则 commonStatus=1
|
|
|
+ if (comment == null || comment.getId() == null) {
|
|
|
+ log.debug("订单未找到评论记录,设置 commonStatus=1,orderId={}", orderId);
|
|
|
+ return "1";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 第二步:查询 lawyer_user_violation 表
|
|
|
+ LawyerUserViolation violation = commentIdToViolationMap.get(comment.getId());
|
|
|
+
|
|
|
+ // 如果关联不出来或者关联出来的 processing_status 为 0 或者 1,则 commonStatus=2
|
|
|
+ if (violation == null) {
|
|
|
+ log.debug("评论未找到举报记录,设置 commonStatus=2,orderId={}, commentId={}", orderId, comment.getId());
|
|
|
+ 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);
|
|
|
+ return "2";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 其他情况 commonStatus=3
|
|
|
+ log.debug("设置 commonStatus=3,orderId={}, commentId={}, processingStatus={}",
|
|
|
+ orderId, comment.getId(), processingStatus);
|
|
|
+ return "3";
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|