浏览代码

bug修复

zhangchen 4 周之前
父节点
当前提交
a85f58065b

+ 9 - 0
alien-entity/src/main/java/shop/alien/entity/store/vo/LifeUserOrderCommentVo.java

@@ -4,6 +4,9 @@ import com.fasterxml.jackson.annotation.JsonInclude;
 import lombok.Data;
 import shop.alien.entity.store.LifeUserOrder;
 
+import java.util.Date;
+import java.util.List;
+
 @Data
 @JsonInclude
 public class LifeUserOrderCommentVo extends LifeUserOrder {
@@ -21,4 +24,10 @@ public class LifeUserOrderCommentVo extends LifeUserOrder {
     private String businessTypesName;
 
     private String storeName;
+
+    private String score;
+
+    private Date commentDate;
+
+    private List<String> imgUrls;
 }

+ 46 - 0
alien-store/src/main/java/shop/alien/store/service/impl/StoreCommentServiceImpl.java

@@ -809,6 +809,52 @@ public class StoreCommentServiceImpl extends ServiceImpl<StoreCommentMapper, Sto
                 record.setGroupBuyImgUrl(imgUrlBuilder.toString());
             }
         }
+
+
+        List<LifeUserOrderCommentVo> lifeUserOrderCommentVos =  commentOrderPage.getRecords();
+        if(CollectionUtils.isEmpty(lifeUserOrderCommentVos)){
+            return commentOrderPage;
+        }
+        List<String> orderIds = lifeUserOrderCommentVos.stream().map(LifeUserOrderCommentVo::getId).collect(Collectors.toList());
+        List<StoreComment> storeCommentList = storeCommentMapper.selectList(new QueryWrapper<StoreComment>().inSql("business_id", String.join(",", orderIds)).eq("business_type", 5));
+        if(CollectionUtils.isEmpty(storeCommentList)){
+            return commentOrderPage;
+        }
+        Map<Integer, StoreComment> commentIdToMap = storeCommentList.stream()
+                .collect(Collectors.toMap(
+                        StoreComment::getBusinessId,
+                        Function.identity(),
+                        (existing, replacement) -> existing  // 若有重复id(理论上不会),保留第一个
+                ));
+        if(CollectionUtils.isEmpty(commentIdToMap)){
+            return commentOrderPage;
+        }
+        for(LifeUserOrderCommentVo lifeUserOrderCommentVo : commentOrderPage.getRecords()){
+            Integer orderId = Integer.parseInt(lifeUserOrderCommentVo.getId());
+
+            if(commentIdToMap.containsKey(orderId)){
+                StoreComment storeComment = commentIdToMap.get(orderId);
+                lifeUserOrderCommentVo.setScore(storeComment.getScore().toString());
+                lifeUserOrderCommentVo.setCommentDate(storeComment.getCreatedTime());
+                String imgIds = storeComment.getImgId();
+
+                if(StringUtils.isNotEmpty(imgIds)){
+                    LambdaQueryWrapper<StoreImg> storeImgLambdaQueryWrapper = new LambdaQueryWrapper<>();
+                    List<String> imgIdList = Arrays.stream(imgIds.split(","))
+                            .map(String::trim)
+                            .collect(Collectors.toList());
+                    storeImgLambdaQueryWrapper.in(StoreImg::getId, imgIdList);
+                    List<StoreImg> storeImgList = storeImgMapper.selectList(storeImgLambdaQueryWrapper);
+                    if(CollectionUtils.isNotEmpty(storeImgList)){
+                        List<String> imgUrlList = storeImgList.stream()    // 转换为 Stream
+                                .map(StoreImg::getImgUrl)                  // 映射,提取 name 字段
+                                .collect(Collectors.toList());
+                        lifeUserOrderCommentVo.setImgUrls(imgUrlList);
+                    }
+                }
+            }
+        }
+
         return commentOrderPage;
     }
 }