diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentPageReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentPageReqVO.java index fba8766243..8dbff09c38 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentPageReqVO.java +++ b/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; diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/comment/ProductCommentDO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/comment/ProductCommentDO.java index d867b21287..6e0bd04fa3 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/comment/ProductCommentDO.java +++ b/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 = "匿名用户"; - /** * 评论编号,主键自增 */ diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java index d836d0758b..b010167ccd 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java +++ b/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 { static void appendTabQuery(LambdaQueryWrapperX 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"); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java index 0ec70a4e64..edec1c6517 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java +++ b/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 getCommentPageTabsCount(Long spuId, Boolean visible) { Map 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()); diff --git a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java index 2b51f81d37..24d9120252 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java +++ b/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 result2 = productCommentService.getCommentPage(new AppCommentPageReqVO().setType(ProductCommentDO.MEDIOCRE_COMMENT), Boolean.TRUE); + PageResult result2 = productCommentService.getCommentPage(new AppCommentPageReqVO().setType(AppCommentPageReqVO.MEDIOCRE_COMMENT), Boolean.TRUE); assertEquals(2, result2.getTotal()); // 测试获取指定 spuId 商品分页中评数据 - PageResult result3 = productCommentService.getCommentPage(new AppCommentPageReqVO().setSpuId(spuId).setType(ProductCommentDO.MEDIOCRE_COMMENT), Boolean.TRUE); + PageResult result3 = productCommentService.getCommentPage(new AppCommentPageReqVO().setSpuId(spuId).setType(AppCommentPageReqVO.MEDIOCRE_COMMENT), Boolean.TRUE); assertEquals(2, result3.getTotal()); // 测试分页 tab count Map 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)); }