Browse Source

fix:移动 app 商品评论分页相关常量到 AppCommentPageReqVO 中

puhui999 2 years ago
parent
commit
91e357e59d

+ 45 - 0
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentPageReqVO.java

@@ -14,6 +14,51 @@ import javax.validation.constraints.NotNull;
 @ToString(callSuper = true)
 public class AppCommentPageReqVO extends PageParam {
 
+    /**
+     * 所有
+     */
+    public static final Integer ALL = 0;
+
+    /**
+     * 所有数量 key
+     */
+    public static final String ALL_COUNT = "allCount";
+
+    /**
+     * 好评
+     */
+    public static final Integer FAVOURABLE_COMMENT = 1;
+
+    /**
+     * 好评数量 key
+     */
+    public static final String FAVOURABLE_COMMENT_COUNT = "favourableCommentCount";
+
+    /**
+     * 中评
+     */
+    public static final Integer MEDIOCRE_COMMENT = 2;
+
+    /**
+     * 中评数量 key
+     */
+    public static final String MEDIOCRE_COMMENT_COUNT = "mediocreCommentCount";
+
+    /**
+     * 差评
+     */
+    public static final Integer NEGATIVE_COMMENT = 3;
+
+    /**
+     * 差评数量 key
+     */
+    public static final String NEGATIVE_COMMENT_COUNT = "negativeCommentCount";
+
+    /**
+     * 默认匿名昵称
+     */
+    public static final String ANONYMOUS_NICKNAME = "匿名用户";
+
     @Schema(description = "商品SPU编号", example = "29502")
     @NotNull(message = "商品SPU编号不能为空")
     private Long spuId;

+ 0 - 45
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/comment/ProductCommentDO.java

@@ -28,51 +28,6 @@ import java.util.List;
 @AllArgsConstructor
 public class ProductCommentDO extends BaseDO {
 
-    /**
-     * 所有
-     */
-    public static final Integer ALL = 0;
-
-    /**
-     * 所有数量 key
-     */
-    public static final String ALL_COUNT = "allCount";
-
-    /**
-     * 好评
-     */
-    public static final Integer FAVOURABLE_COMMENT = 1;
-
-    /**
-     * 好评数量 key
-     */
-    public static final String FAVOURABLE_COMMENT_COUNT = "favourableCommentCount";
-
-    /**
-     * 中评
-     */
-    public static final Integer MEDIOCRE_COMMENT = 2;
-
-    /**
-     * 中评数量 key
-     */
-    public static final String MEDIOCRE_COMMENT_COUNT = "mediocreCommentCount";
-
-    /**
-     * 差评
-     */
-    public static final Integer NEGATIVE_COMMENT = 3;
-
-    /**
-     * 差评数量 key
-     */
-    public static final String NEGATIVE_COMMENT_COUNT = "negativeCommentCount";
-
-    /**
-     * 默认匿名昵称
-     */
-    public static final String ANONYMOUS_NICKNAME = "匿名用户";
-
     /**
      * 评论编号,主键自增
      */

+ 3 - 3
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java

@@ -37,17 +37,17 @@ public interface ProductCommentMapper extends BaseMapperX<ProductCommentDO> {
 
     static void appendTabQuery(LambdaQueryWrapperX<ProductCommentDO> queryWrapper, Integer type) {
         // 构建好评查询语句
-        if (ObjectUtil.equal(type, ProductCommentDO.FAVOURABLE_COMMENT)) {
+        if (ObjectUtil.equal(type, AppCommentPageReqVO.FAVOURABLE_COMMENT)) {
             // 好评计算 (商品评分星级+服务评分星级) >= 8
             queryWrapper.apply("(scores + benefit_scores) >= 8");
         }
         // 构建中评查询语句
-        if (ObjectUtil.equal(type, ProductCommentDO.MEDIOCRE_COMMENT)) {
+        if (ObjectUtil.equal(type, AppCommentPageReqVO.MEDIOCRE_COMMENT)) {
             // 中评计算 (商品评分星级+服务评分星级) > 4 且 (商品评分星级+服务评分星级) < 8
             queryWrapper.apply("(scores + benefit_scores) > 4 and (scores + benefit_scores) < 8");
         }
         // 构建差评查询语句
-        if (ObjectUtil.equal(type, ProductCommentDO.NEGATIVE_COMMENT)) {
+        if (ObjectUtil.equal(type, AppCommentPageReqVO.NEGATIVE_COMMENT)) {
             // 差评计算 (商品评分星级+服务评分星级) <= 4
             queryWrapper.apply("(scores + benefit_scores) <= 4");
         }

+ 5 - 5
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java

@@ -73,13 +73,13 @@ public class ProductCommentServiceImpl implements ProductCommentService {
     public Map<String, Long> getCommentPageTabsCount(Long spuId, Boolean visible) {
         Map<String, Long> countMap = new HashMap<>(4);
         // 查询商品 id = spuId 的所有评论数量
-        countMap.put(ProductCommentDO.ALL_COUNT, productCommentMapper.selectTabCount(spuId, visible, ProductCommentDO.ALL));
+        countMap.put(AppCommentPageReqVO.ALL_COUNT, productCommentMapper.selectTabCount(spuId, visible, AppCommentPageReqVO.ALL));
         // 查询商品 id = spuId 的所有好评数量
-        countMap.put(ProductCommentDO.FAVOURABLE_COMMENT_COUNT, productCommentMapper.selectTabCount(spuId, visible, ProductCommentDO.FAVOURABLE_COMMENT));
+        countMap.put(AppCommentPageReqVO.FAVOURABLE_COMMENT_COUNT, productCommentMapper.selectTabCount(spuId, visible, AppCommentPageReqVO.FAVOURABLE_COMMENT));
         // 查询商品 id = spuId 的所有中评数量
-        countMap.put(ProductCommentDO.MEDIOCRE_COMMENT_COUNT, productCommentMapper.selectTabCount(spuId, visible, ProductCommentDO.MEDIOCRE_COMMENT));
+        countMap.put(AppCommentPageReqVO.MEDIOCRE_COMMENT_COUNT, productCommentMapper.selectTabCount(spuId, visible, AppCommentPageReqVO.MEDIOCRE_COMMENT));
         // 查询商品 id = spuId 的所有差评数量
-        countMap.put(ProductCommentDO.NEGATIVE_COMMENT_COUNT, productCommentMapper.selectTabCount(spuId, visible, ProductCommentDO.NEGATIVE_COMMENT));
+        countMap.put(AppCommentPageReqVO.NEGATIVE_COMMENT_COUNT, productCommentMapper.selectTabCount(spuId, visible, AppCommentPageReqVO.NEGATIVE_COMMENT));
         return countMap;
     }
 
@@ -89,7 +89,7 @@ public class ProductCommentServiceImpl implements ProductCommentService {
         result.getList().forEach(item -> {
             // 判断用户是否选择匿名
             if (ObjectUtil.equal(item.getAnonymous(), true)) {
-                item.setUserNickname(ProductCommentDO.ANONYMOUS_NICKNAME);
+                item.setUserNickname(AppCommentPageReqVO.ANONYMOUS_NICKNAME);
             }
             // 计算评价最终综合评分 最终星数 = (商品评星 + 服务评星) / 2
             BigDecimal sumScore = new BigDecimal(item.getScores() + item.getBenefitScores());

+ 6 - 6
yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java

@@ -142,19 +142,19 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest {
         assertEquals(7, result1.getTotal());
 
         // 测试获取所有商品分页中评数据
-        PageResult<AppCommentRespVO> result2 = productCommentService.getCommentPage(new AppCommentPageReqVO().setType(ProductCommentDO.MEDIOCRE_COMMENT), Boolean.TRUE);
+        PageResult<AppCommentRespVO> result2 = productCommentService.getCommentPage(new AppCommentPageReqVO().setType(AppCommentPageReqVO.MEDIOCRE_COMMENT), Boolean.TRUE);
         assertEquals(2, result2.getTotal());
 
         // 测试获取指定 spuId 商品分页中评数据
-        PageResult<AppCommentRespVO> result3 = productCommentService.getCommentPage(new AppCommentPageReqVO().setSpuId(spuId).setType(ProductCommentDO.MEDIOCRE_COMMENT), Boolean.TRUE);
+        PageResult<AppCommentRespVO> result3 = productCommentService.getCommentPage(new AppCommentPageReqVO().setSpuId(spuId).setType(AppCommentPageReqVO.MEDIOCRE_COMMENT), Boolean.TRUE);
         assertEquals(2, result3.getTotal());
 
         // 测试分页 tab count
         Map<String, Long> tabsCount = productCommentService.getCommentPageTabsCount(spuId, Boolean.TRUE);
-        assertEquals(6, tabsCount.get(ProductCommentDO.ALL_COUNT));
-        assertEquals(4, tabsCount.get(ProductCommentDO.FAVOURABLE_COMMENT_COUNT));
-        assertEquals(2, tabsCount.get(ProductCommentDO.MEDIOCRE_COMMENT_COUNT));
-        assertEquals(0, tabsCount.get(ProductCommentDO.NEGATIVE_COMMENT_COUNT));
+        assertEquals(6, tabsCount.get(AppCommentPageReqVO.ALL_COUNT));
+        assertEquals(4, tabsCount.get(AppCommentPageReqVO.FAVOURABLE_COMMENT_COUNT));
+        assertEquals(2, tabsCount.get(AppCommentPageReqVO.MEDIOCRE_COMMENT_COUNT));
+        assertEquals(0, tabsCount.get(AppCommentPageReqVO.NEGATIVE_COMMENT_COUNT));
 
     }