Commit 91e357e59d3058217872c9ca9f2ad122ffaa7fef

Authored by puhui999
1 parent 8f7efbe4

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

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; @@ -14,6 +14,51 @@ import javax.validation.constraints.NotNull;
14 @ToString(callSuper = true) 14 @ToString(callSuper = true)
15 public class AppCommentPageReqVO extends PageParam { 15 public class AppCommentPageReqVO extends PageParam {
16 16
  17 + /**
  18 + * 所有
  19 + */
  20 + public static final Integer ALL = 0;
  21 +
  22 + /**
  23 + * 所有数量 key
  24 + */
  25 + public static final String ALL_COUNT = "allCount";
  26 +
  27 + /**
  28 + * 好评
  29 + */
  30 + public static final Integer FAVOURABLE_COMMENT = 1;
  31 +
  32 + /**
  33 + * 好评数量 key
  34 + */
  35 + public static final String FAVOURABLE_COMMENT_COUNT = "favourableCommentCount";
  36 +
  37 + /**
  38 + * 中评
  39 + */
  40 + public static final Integer MEDIOCRE_COMMENT = 2;
  41 +
  42 + /**
  43 + * 中评数量 key
  44 + */
  45 + public static final String MEDIOCRE_COMMENT_COUNT = "mediocreCommentCount";
  46 +
  47 + /**
  48 + * 差评
  49 + */
  50 + public static final Integer NEGATIVE_COMMENT = 3;
  51 +
  52 + /**
  53 + * 差评数量 key
  54 + */
  55 + public static final String NEGATIVE_COMMENT_COUNT = "negativeCommentCount";
  56 +
  57 + /**
  58 + * 默认匿名昵称
  59 + */
  60 + public static final String ANONYMOUS_NICKNAME = "匿名用户";
  61 +
17 @Schema(description = "商品SPU编号", example = "29502") 62 @Schema(description = "商品SPU编号", example = "29502")
18 @NotNull(message = "商品SPU编号不能为空") 63 @NotNull(message = "商品SPU编号不能为空")
19 private Long spuId; 64 private Long spuId;
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/comment/ProductCommentDO.java
@@ -29,51 +29,6 @@ import java.util.List; @@ -29,51 +29,6 @@ import java.util.List;
29 public class ProductCommentDO extends BaseDO { 29 public class ProductCommentDO extends BaseDO {
30 30
31 /** 31 /**
32 - * 所有  
33 - */  
34 - public static final Integer ALL = 0;  
35 -  
36 - /**  
37 - * 所有数量 key  
38 - */  
39 - public static final String ALL_COUNT = "allCount";  
40 -  
41 - /**  
42 - * 好评  
43 - */  
44 - public static final Integer FAVOURABLE_COMMENT = 1;  
45 -  
46 - /**  
47 - * 好评数量 key  
48 - */  
49 - public static final String FAVOURABLE_COMMENT_COUNT = "favourableCommentCount";  
50 -  
51 - /**  
52 - * 中评  
53 - */  
54 - public static final Integer MEDIOCRE_COMMENT = 2;  
55 -  
56 - /**  
57 - * 中评数量 key  
58 - */  
59 - public static final String MEDIOCRE_COMMENT_COUNT = "mediocreCommentCount";  
60 -  
61 - /**  
62 - * 差评  
63 - */  
64 - public static final Integer NEGATIVE_COMMENT = 3;  
65 -  
66 - /**  
67 - * 差评数量 key  
68 - */  
69 - public static final String NEGATIVE_COMMENT_COUNT = "negativeCommentCount";  
70 -  
71 - /**  
72 - * 默认匿名昵称  
73 - */  
74 - public static final String ANONYMOUS_NICKNAME = "匿名用户";  
75 -  
76 - /**  
77 * 评论编号,主键自增 32 * 评论编号,主键自增
78 */ 33 */
79 @TableId 34 @TableId
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> { @@ -37,17 +37,17 @@ public interface ProductCommentMapper extends BaseMapperX<ProductCommentDO> {
37 37
38 static void appendTabQuery(LambdaQueryWrapperX<ProductCommentDO> queryWrapper, Integer type) { 38 static void appendTabQuery(LambdaQueryWrapperX<ProductCommentDO> queryWrapper, Integer type) {
39 // 构建好评查询语句 39 // 构建好评查询语句
40 - if (ObjectUtil.equal(type, ProductCommentDO.FAVOURABLE_COMMENT)) { 40 + if (ObjectUtil.equal(type, AppCommentPageReqVO.FAVOURABLE_COMMENT)) {
41 // 好评计算 (商品评分星级+服务评分星级) >= 8 41 // 好评计算 (商品评分星级+服务评分星级) >= 8
42 queryWrapper.apply("(scores + benefit_scores) >= 8"); 42 queryWrapper.apply("(scores + benefit_scores) >= 8");
43 } 43 }
44 // 构建中评查询语句 44 // 构建中评查询语句
45 - if (ObjectUtil.equal(type, ProductCommentDO.MEDIOCRE_COMMENT)) { 45 + if (ObjectUtil.equal(type, AppCommentPageReqVO.MEDIOCRE_COMMENT)) {
46 // 中评计算 (商品评分星级+服务评分星级) > 4 且 (商品评分星级+服务评分星级) < 8 46 // 中评计算 (商品评分星级+服务评分星级) > 4 且 (商品评分星级+服务评分星级) < 8
47 queryWrapper.apply("(scores + benefit_scores) > 4 and (scores + benefit_scores) < 8"); 47 queryWrapper.apply("(scores + benefit_scores) > 4 and (scores + benefit_scores) < 8");
48 } 48 }
49 // 构建差评查询语句 49 // 构建差评查询语句
50 - if (ObjectUtil.equal(type, ProductCommentDO.NEGATIVE_COMMENT)) { 50 + if (ObjectUtil.equal(type, AppCommentPageReqVO.NEGATIVE_COMMENT)) {
51 // 差评计算 (商品评分星级+服务评分星级) <= 4 51 // 差评计算 (商品评分星级+服务评分星级) <= 4
52 queryWrapper.apply("(scores + benefit_scores) <= 4"); 52 queryWrapper.apply("(scores + benefit_scores) <= 4");
53 } 53 }
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 { @@ -73,13 +73,13 @@ public class ProductCommentServiceImpl implements ProductCommentService {
73 public Map<String, Long> getCommentPageTabsCount(Long spuId, Boolean visible) { 73 public Map<String, Long> getCommentPageTabsCount(Long spuId, Boolean visible) {
74 Map<String, Long> countMap = new HashMap<>(4); 74 Map<String, Long> countMap = new HashMap<>(4);
75 // 查询商品 id = spuId 的所有评论数量 75 // 查询商品 id = spuId 的所有评论数量
76 - countMap.put(ProductCommentDO.ALL_COUNT, productCommentMapper.selectTabCount(spuId, visible, ProductCommentDO.ALL)); 76 + countMap.put(AppCommentPageReqVO.ALL_COUNT, productCommentMapper.selectTabCount(spuId, visible, AppCommentPageReqVO.ALL));
77 // 查询商品 id = spuId 的所有好评数量 77 // 查询商品 id = spuId 的所有好评数量
78 - countMap.put(ProductCommentDO.FAVOURABLE_COMMENT_COUNT, productCommentMapper.selectTabCount(spuId, visible, ProductCommentDO.FAVOURABLE_COMMENT)); 78 + countMap.put(AppCommentPageReqVO.FAVOURABLE_COMMENT_COUNT, productCommentMapper.selectTabCount(spuId, visible, AppCommentPageReqVO.FAVOURABLE_COMMENT));
79 // 查询商品 id = spuId 的所有中评数量 79 // 查询商品 id = spuId 的所有中评数量
80 - countMap.put(ProductCommentDO.MEDIOCRE_COMMENT_COUNT, productCommentMapper.selectTabCount(spuId, visible, ProductCommentDO.MEDIOCRE_COMMENT)); 80 + countMap.put(AppCommentPageReqVO.MEDIOCRE_COMMENT_COUNT, productCommentMapper.selectTabCount(spuId, visible, AppCommentPageReqVO.MEDIOCRE_COMMENT));
81 // 查询商品 id = spuId 的所有差评数量 81 // 查询商品 id = spuId 的所有差评数量
82 - countMap.put(ProductCommentDO.NEGATIVE_COMMENT_COUNT, productCommentMapper.selectTabCount(spuId, visible, ProductCommentDO.NEGATIVE_COMMENT)); 82 + countMap.put(AppCommentPageReqVO.NEGATIVE_COMMENT_COUNT, productCommentMapper.selectTabCount(spuId, visible, AppCommentPageReqVO.NEGATIVE_COMMENT));
83 return countMap; 83 return countMap;
84 } 84 }
85 85
@@ -89,7 +89,7 @@ public class ProductCommentServiceImpl implements ProductCommentService { @@ -89,7 +89,7 @@ public class ProductCommentServiceImpl implements ProductCommentService {
89 result.getList().forEach(item -> { 89 result.getList().forEach(item -> {
90 // 判断用户是否选择匿名 90 // 判断用户是否选择匿名
91 if (ObjectUtil.equal(item.getAnonymous(), true)) { 91 if (ObjectUtil.equal(item.getAnonymous(), true)) {
92 - item.setUserNickname(ProductCommentDO.ANONYMOUS_NICKNAME); 92 + item.setUserNickname(AppCommentPageReqVO.ANONYMOUS_NICKNAME);
93 } 93 }
94 // 计算评价最终综合评分 最终星数 = (商品评星 + 服务评星) / 2 94 // 计算评价最终综合评分 最终星数 = (商品评星 + 服务评星) / 2
95 BigDecimal sumScore = new BigDecimal(item.getScores() + item.getBenefitScores()); 95 BigDecimal sumScore = new BigDecimal(item.getScores() + item.getBenefitScores());
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 { @@ -142,19 +142,19 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest {
142 assertEquals(7, result1.getTotal()); 142 assertEquals(7, result1.getTotal());
143 143
144 // 测试获取所有商品分页中评数据 144 // 测试获取所有商品分页中评数据
145 - PageResult<AppCommentRespVO> result2 = productCommentService.getCommentPage(new AppCommentPageReqVO().setType(ProductCommentDO.MEDIOCRE_COMMENT), Boolean.TRUE); 145 + PageResult<AppCommentRespVO> result2 = productCommentService.getCommentPage(new AppCommentPageReqVO().setType(AppCommentPageReqVO.MEDIOCRE_COMMENT), Boolean.TRUE);
146 assertEquals(2, result2.getTotal()); 146 assertEquals(2, result2.getTotal());
147 147
148 // 测试获取指定 spuId 商品分页中评数据 148 // 测试获取指定 spuId 商品分页中评数据
149 - PageResult<AppCommentRespVO> result3 = productCommentService.getCommentPage(new AppCommentPageReqVO().setSpuId(spuId).setType(ProductCommentDO.MEDIOCRE_COMMENT), Boolean.TRUE); 149 + PageResult<AppCommentRespVO> result3 = productCommentService.getCommentPage(new AppCommentPageReqVO().setSpuId(spuId).setType(AppCommentPageReqVO.MEDIOCRE_COMMENT), Boolean.TRUE);
150 assertEquals(2, result3.getTotal()); 150 assertEquals(2, result3.getTotal());
151 151
152 // 测试分页 tab count 152 // 测试分页 tab count
153 Map<String, Long> tabsCount = productCommentService.getCommentPageTabsCount(spuId, Boolean.TRUE); 153 Map<String, Long> tabsCount = productCommentService.getCommentPageTabsCount(spuId, Boolean.TRUE);
154 - assertEquals(6, tabsCount.get(ProductCommentDO.ALL_COUNT));  
155 - assertEquals(4, tabsCount.get(ProductCommentDO.FAVOURABLE_COMMENT_COUNT));  
156 - assertEquals(2, tabsCount.get(ProductCommentDO.MEDIOCRE_COMMENT_COUNT));  
157 - assertEquals(0, tabsCount.get(ProductCommentDO.NEGATIVE_COMMENT_COUNT)); 154 + assertEquals(6, tabsCount.get(AppCommentPageReqVO.ALL_COUNT));
  155 + assertEquals(4, tabsCount.get(AppCommentPageReqVO.FAVOURABLE_COMMENT_COUNT));
  156 + assertEquals(2, tabsCount.get(AppCommentPageReqVO.MEDIOCRE_COMMENT_COUNT));
  157 + assertEquals(0, tabsCount.get(AppCommentPageReqVO.NEGATIVE_COMMENT_COUNT));
158 158
159 } 159 }
160 160