|
|
@@ -198,6 +198,37 @@ public class ProductReviewServiceImpl extends ServiceImpl<ProductReviewMapper, P
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 商品详情页评价列表(R3,能力键 {@code shop.review.list},公开只读)。
|
|
|
+ *
|
|
|
+ * <p>读 {@link ProductReviewMapper#statsByProduct} 聚合 total + avgRating,
|
|
|
+ * 读 {@link ProductReviewMapper#listByProduct} 分页 records,组装只读视图
|
|
|
+ * {@code {total, avgRating, records}}。仅展示态 status=1、按 review_at DESC 倒序由 Mapper XML 保证。</p>
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> listByProduct(Long productId, int page, int size) {
|
|
|
+ int pageNum = Math.max(page, 1);
|
|
|
+ int pageSize = Math.max(size, 1);
|
|
|
+ int offset = (pageNum - 1) * pageSize;
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+
|
|
|
+ // 1) 星级聚合:total + avgRating(Mapper XML 已限定 status=1 且 AVG(rating))
|
|
|
+ Map<String, Object> stats = reviewMapper.statsByProduct(productId);
|
|
|
+ if (stats != null) {
|
|
|
+ result.put("total", stats.get("total"));
|
|
|
+ result.put("avgRating", stats.get("avgRating"));
|
|
|
+ } else {
|
|
|
+ result.put("total", 0L);
|
|
|
+ result.put("avgRating", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2) 评价记录分页(含商家回复,按 review_at DESC 倒序)
|
|
|
+ List<ProductReview> records = reviewMapper.listByProduct(productId, offset, pageSize);
|
|
|
+ result.put("records", records == null ? Collections.emptyList() : records);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 90 天评价窗口判定:confirmTime 存在且 >= now - 90d。
|
|
|
*/
|