Commit 8f7efbe4e2e5e0db21b0efd7a4289fd66012ee92
1 parent
151e58da
fix:测试 app 商品评论页获取评论分页接口和相关评论分类数量接口,修复测试时发现的问题
Showing
7 changed files
with
110 additions
and
19 deletions
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppCommentController.java
| @@ -9,7 +9,6 @@ import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentCreat | @@ -9,7 +9,6 @@ import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentCreat | ||
| 9 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; | 9 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; |
| 10 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentRespVO; | 10 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentRespVO; |
| 11 | import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert; | 11 | import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert; |
| 12 | -import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; | ||
| 13 | import cn.iocoder.yudao.module.product.service.comment.ProductCommentService; | 12 | import cn.iocoder.yudao.module.product.service.comment.ProductCommentService; |
| 14 | import io.swagger.v3.oas.annotations.Operation; | 13 | import io.swagger.v3.oas.annotations.Operation; |
| 15 | import io.swagger.v3.oas.annotations.tags.Tag; | 14 | import io.swagger.v3.oas.annotations.tags.Tag; |
| @@ -38,8 +37,7 @@ public class AppCommentController { | @@ -38,8 +37,7 @@ public class AppCommentController { | ||
| 38 | @GetMapping("/page") | 37 | @GetMapping("/page") |
| 39 | @Operation(summary = "获得商品评价分页") | 38 | @Operation(summary = "获得商品评价分页") |
| 40 | public CommonResult<PageResult<AppCommentRespVO>> getCommentPage(@Valid AppCommentPageReqVO pageVO) { | 39 | public CommonResult<PageResult<AppCommentRespVO>> getCommentPage(@Valid AppCommentPageReqVO pageVO) { |
| 41 | - PageResult<ProductCommentDO> pageResult = productCommentService.getCommentPage(pageVO, Boolean.TRUE); | ||
| 42 | - return success(ProductCommentConvert.INSTANCE.convertPage02(pageResult)); | 40 | + return success(productCommentService.getCommentPage(pageVO, Boolean.TRUE)); |
| 43 | } | 41 | } |
| 44 | 42 | ||
| 45 | @GetMapping("/get-count") | 43 | @GetMapping("/get-count") |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentRespVO.java
| @@ -5,7 +5,6 @@ import lombok.Data; | @@ -5,7 +5,6 @@ import lombok.Data; | ||
| 5 | import lombok.EqualsAndHashCode; | 5 | import lombok.EqualsAndHashCode; |
| 6 | import lombok.ToString; | 6 | import lombok.ToString; |
| 7 | 7 | ||
| 8 | -import javax.validation.constraints.NotNull; | ||
| 9 | import java.time.LocalDateTime; | 8 | import java.time.LocalDateTime; |
| 10 | import java.util.List; | 9 | import java.util.List; |
| 11 | 10 | ||
| @@ -27,7 +26,7 @@ public class AppCommentRespVO extends AppCommentBaseVO { | @@ -27,7 +26,7 @@ public class AppCommentRespVO extends AppCommentBaseVO { | ||
| 27 | @Schema(description = "订单项编号", required = true, example = "24965") | 26 | @Schema(description = "订单项编号", required = true, example = "24965") |
| 28 | private Long id; | 27 | private Long id; |
| 29 | 28 | ||
| 30 | - @Schema(description = "是否匿名:[0:不匿名 1:匿名]", required = true) | 29 | + @Schema(description = "是否匿名", required = true) |
| 31 | private Boolean anonymous; | 30 | private Boolean anonymous; |
| 32 | 31 | ||
| 33 | @Schema(description = "交易订单编号", required = true, example = "24428") | 32 | @Schema(description = "交易订单编号", required = true, example = "24428") |
| @@ -36,7 +35,7 @@ public class AppCommentRespVO extends AppCommentBaseVO { | @@ -36,7 +35,7 @@ public class AppCommentRespVO extends AppCommentBaseVO { | ||
| 36 | @Schema(description = "交易订单项编号", required = true, example = "8233") | 35 | @Schema(description = "交易订单项编号", required = true, example = "8233") |
| 37 | private Long orderItemId; | 36 | private Long orderItemId; |
| 38 | 37 | ||
| 39 | - @Schema(description = "商家是否回复:[1:回复 0:未回复]", required = true) | 38 | + @Schema(description = "商家是否回复", required = true) |
| 40 | private Boolean replied; | 39 | private Boolean replied; |
| 41 | 40 | ||
| 42 | @Schema(description = "回复管理员编号", example = "22212") | 41 | @Schema(description = "回复管理员编号", example = "22212") |
| @@ -60,4 +59,6 @@ public class AppCommentRespVO extends AppCommentBaseVO { | @@ -60,4 +59,6 @@ public class AppCommentRespVO extends AppCommentBaseVO { | ||
| 60 | @Schema(description = "创建时间", required = true) | 59 | @Schema(description = "创建时间", required = true) |
| 61 | private LocalDateTime createTime; | 60 | private LocalDateTime createTime; |
| 62 | 61 | ||
| 62 | + @Schema(description = "最终评分", required = true) | ||
| 63 | + private Integer finalScore; | ||
| 63 | } | 64 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/comment/ProductCommentDO.java
| @@ -32,20 +32,48 @@ public class ProductCommentDO extends BaseDO { | @@ -32,20 +32,48 @@ public class ProductCommentDO extends BaseDO { | ||
| 32 | * 所有 | 32 | * 所有 |
| 33 | */ | 33 | */ |
| 34 | public static final Integer ALL = 0; | 34 | public static final Integer ALL = 0; |
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * 所有数量 key | ||
| 38 | + */ | ||
| 39 | + public static final String ALL_COUNT = "allCount"; | ||
| 40 | + | ||
| 35 | /** | 41 | /** |
| 36 | * 好评 | 42 | * 好评 |
| 37 | */ | 43 | */ |
| 38 | public static final Integer FAVOURABLE_COMMENT = 1; | 44 | public static final Integer FAVOURABLE_COMMENT = 1; |
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * 好评数量 key | ||
| 48 | + */ | ||
| 49 | + public static final String FAVOURABLE_COMMENT_COUNT = "favourableCommentCount"; | ||
| 50 | + | ||
| 39 | /** | 51 | /** |
| 40 | * 中评 | 52 | * 中评 |
| 41 | */ | 53 | */ |
| 42 | public static final Integer MEDIOCRE_COMMENT = 2; | 54 | public static final Integer MEDIOCRE_COMMENT = 2; |
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * 中评数量 key | ||
| 58 | + */ | ||
| 59 | + public static final String MEDIOCRE_COMMENT_COUNT = "mediocreCommentCount"; | ||
| 60 | + | ||
| 43 | /** | 61 | /** |
| 44 | * 差评 | 62 | * 差评 |
| 45 | */ | 63 | */ |
| 46 | public static final Integer NEGATIVE_COMMENT = 3; | 64 | public static final Integer NEGATIVE_COMMENT = 3; |
| 47 | 65 | ||
| 48 | /** | 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 | + /** | ||
| 49 | * 评论编号,主键自增 | 77 | * 评论编号,主键自增 |
| 50 | */ | 78 | */ |
| 51 | @TableId | 79 | @TableId |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java
| @@ -39,17 +39,17 @@ public interface ProductCommentMapper extends BaseMapperX<ProductCommentDO> { | @@ -39,17 +39,17 @@ public interface ProductCommentMapper extends BaseMapperX<ProductCommentDO> { | ||
| 39 | // 构建好评查询语句 | 39 | // 构建好评查询语句 |
| 40 | if (ObjectUtil.equal(type, ProductCommentDO.FAVOURABLE_COMMENT)) { | 40 | if (ObjectUtil.equal(type, ProductCommentDO.FAVOURABLE_COMMENT)) { |
| 41 | // 好评计算 (商品评分星级+服务评分星级) >= 8 | 41 | // 好评计算 (商品评分星级+服务评分星级) >= 8 |
| 42 | - queryWrapper.apply("(scores + benefitScores) >= 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, ProductCommentDO.MEDIOCRE_COMMENT)) { |
| 46 | // 中评计算 (商品评分星级+服务评分星级) > 4 且 (商品评分星级+服务评分星级) < 8 | 46 | // 中评计算 (商品评分星级+服务评分星级) > 4 且 (商品评分星级+服务评分星级) < 8 |
| 47 | - queryWrapper.apply("(scores + benefitScores) > 4 and (scores + benefitScores) < 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, ProductCommentDO.NEGATIVE_COMMENT)) { |
| 51 | // 差评计算 (商品评分星级+服务评分星级) <= 4 | 51 | // 差评计算 (商品评分星级+服务评分星级) <= 4 |
| 52 | - queryWrapper.apply("(scores + benefitScores) <= 4"); | 52 | + queryWrapper.apply("(scores + benefit_scores) <= 4"); |
| 53 | } | 53 | } |
| 54 | } | 54 | } |
| 55 | 55 |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentService.java
| @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommen | @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommen | ||
| 7 | import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO; | 7 | import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO; |
| 8 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentAdditionalReqVO; | 8 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentAdditionalReqVO; |
| 9 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; | 9 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; |
| 10 | +import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentRespVO; | ||
| 10 | import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; | 11 | import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; |
| 11 | import org.springframework.stereotype.Service; | 12 | import org.springframework.stereotype.Service; |
| 12 | import org.springframework.validation.annotation.Validated; | 13 | import org.springframework.validation.annotation.Validated; |
| @@ -52,7 +53,7 @@ public interface ProductCommentService { | @@ -52,7 +53,7 @@ public interface ProductCommentService { | ||
| 52 | * @param visible 是否可见 | 53 | * @param visible 是否可见 |
| 53 | * @return 商品评价分页 | 54 | * @return 商品评价分页 |
| 54 | */ | 55 | */ |
| 55 | - PageResult<ProductCommentDO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible); | 56 | + PageResult<AppCommentRespVO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible); |
| 56 | 57 | ||
| 57 | /** | 58 | /** |
| 58 | * 创建商品评论 | 59 | * 创建商品评论 |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java
| 1 | package cn.iocoder.yudao.module.product.service.comment; | 1 | package cn.iocoder.yudao.module.product.service.comment; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.util.ObjectUtil; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; | 5 | import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; |
| 5 | import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentPageReqVO; | 6 | import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentPageReqVO; |
| @@ -7,6 +8,8 @@ import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommen | @@ -7,6 +8,8 @@ import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommen | ||
| 7 | import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO; | 8 | import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO; |
| 8 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentAdditionalReqVO; | 9 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentAdditionalReqVO; |
| 9 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; | 10 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; |
| 11 | +import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentRespVO; | ||
| 12 | +import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert; | ||
| 10 | import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; | 13 | import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; |
| 11 | import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; | 14 | import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; |
| 12 | import cn.iocoder.yudao.module.product.dal.mysql.comment.ProductCommentMapper; | 15 | import cn.iocoder.yudao.module.product.dal.mysql.comment.ProductCommentMapper; |
| @@ -18,6 +21,8 @@ import org.springframework.util.StringUtils; | @@ -18,6 +21,8 @@ import org.springframework.util.StringUtils; | ||
| 18 | import org.springframework.validation.annotation.Validated; | 21 | import org.springframework.validation.annotation.Validated; |
| 19 | 22 | ||
| 20 | import javax.annotation.Resource; | 23 | import javax.annotation.Resource; |
| 24 | +import java.math.BigDecimal; | ||
| 25 | +import java.math.RoundingMode; | ||
| 21 | import java.util.HashMap; | 26 | import java.util.HashMap; |
| 22 | import java.util.Map; | 27 | import java.util.Map; |
| 23 | import java.util.Objects; | 28 | import java.util.Objects; |
| @@ -68,19 +73,30 @@ public class ProductCommentServiceImpl implements ProductCommentService { | @@ -68,19 +73,30 @@ public class ProductCommentServiceImpl implements ProductCommentService { | ||
| 68 | public Map<String, Long> getCommentPageTabsCount(Long spuId, Boolean visible) { | 73 | public Map<String, Long> getCommentPageTabsCount(Long spuId, Boolean visible) { |
| 69 | Map<String, Long> countMap = new HashMap<>(4); | 74 | Map<String, Long> countMap = new HashMap<>(4); |
| 70 | // 查询商品 id = spuId 的所有评论数量 | 75 | // 查询商品 id = spuId 的所有评论数量 |
| 71 | - countMap.put("allCount", productCommentMapper.selectTabCount(spuId, visible, ProductCommentDO.ALL)); | 76 | + countMap.put(ProductCommentDO.ALL_COUNT, productCommentMapper.selectTabCount(spuId, visible, ProductCommentDO.ALL)); |
| 72 | // 查询商品 id = spuId 的所有好评数量 | 77 | // 查询商品 id = spuId 的所有好评数量 |
| 73 | - countMap.put("favourableCommentCount", productCommentMapper.selectTabCount(spuId, visible, ProductCommentDO.FAVOURABLE_COMMENT)); | 78 | + countMap.put(ProductCommentDO.FAVOURABLE_COMMENT_COUNT, productCommentMapper.selectTabCount(spuId, visible, ProductCommentDO.FAVOURABLE_COMMENT)); |
| 74 | // 查询商品 id = spuId 的所有中评数量 | 79 | // 查询商品 id = spuId 的所有中评数量 |
| 75 | - countMap.put("mediocreCommentCount", productCommentMapper.selectTabCount(spuId, visible, ProductCommentDO.MEDIOCRE_COMMENT)); | 80 | + countMap.put(ProductCommentDO.MEDIOCRE_COMMENT_COUNT, productCommentMapper.selectTabCount(spuId, visible, ProductCommentDO.MEDIOCRE_COMMENT)); |
| 76 | // 查询商品 id = spuId 的所有差评数量 | 81 | // 查询商品 id = spuId 的所有差评数量 |
| 77 | - countMap.put("negativeCommentCount", productCommentMapper.selectTabCount(spuId, visible, ProductCommentDO.NEGATIVE_COMMENT)); | 82 | + countMap.put(ProductCommentDO.NEGATIVE_COMMENT_COUNT, productCommentMapper.selectTabCount(spuId, visible, ProductCommentDO.NEGATIVE_COMMENT)); |
| 78 | return countMap; | 83 | return countMap; |
| 79 | } | 84 | } |
| 80 | 85 | ||
| 81 | @Override | 86 | @Override |
| 82 | - public PageResult<ProductCommentDO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible) { | ||
| 83 | - return productCommentMapper.selectPage(pageVO, visible); | 87 | + public PageResult<AppCommentRespVO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible) { |
| 88 | + PageResult<AppCommentRespVO> result = ProductCommentConvert.INSTANCE.convertPage02(productCommentMapper.selectPage(pageVO, visible)); | ||
| 89 | + result.getList().forEach(item -> { | ||
| 90 | + // 判断用户是否选择匿名 | ||
| 91 | + if (ObjectUtil.equal(item.getAnonymous(), true)) { | ||
| 92 | + item.setUserNickname(ProductCommentDO.ANONYMOUS_NICKNAME); | ||
| 93 | + } | ||
| 94 | + // 计算评价最终综合评分 最终星数 = (商品评星 + 服务评星) / 2 | ||
| 95 | + BigDecimal sumScore = new BigDecimal(item.getScores() + item.getBenefitScores()); | ||
| 96 | + BigDecimal divide = sumScore.divide(BigDecimal.valueOf(2L), 0, RoundingMode.DOWN); | ||
| 97 | + item.setFinalScore(divide.intValue()); | ||
| 98 | + }); | ||
| 99 | + return result; | ||
| 84 | } | 100 | } |
| 85 | 101 | ||
| 86 | @Override | 102 | @Override |
yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java
| @@ -11,15 +11,22 @@ import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommen | @@ -11,15 +11,22 @@ import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommen | ||
| 11 | import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO; | 11 | import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO; |
| 12 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentAdditionalReqVO; | 12 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentAdditionalReqVO; |
| 13 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; | 13 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; |
| 14 | +import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentRespVO; | ||
| 14 | import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert; | 15 | import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert; |
| 15 | import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; | 16 | import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; |
| 16 | import cn.iocoder.yudao.module.product.dal.mysql.comment.ProductCommentMapper; | 17 | import cn.iocoder.yudao.module.product.dal.mysql.comment.ProductCommentMapper; |
| 17 | import cn.iocoder.yudao.module.product.enums.comment.ProductCommentScoresEnum; | 18 | import cn.iocoder.yudao.module.product.enums.comment.ProductCommentScoresEnum; |
| 19 | +import cn.iocoder.yudao.module.product.service.spu.ProductSpuService; | ||
| 20 | +import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi; | ||
| 18 | import org.junit.jupiter.api.Test; | 21 | import org.junit.jupiter.api.Test; |
| 22 | +import org.springframework.boot.test.mock.mockito.MockBean; | ||
| 19 | import org.springframework.context.annotation.Import; | 23 | import org.springframework.context.annotation.Import; |
| 24 | +import org.springframework.context.annotation.Lazy; | ||
| 20 | 25 | ||
| 21 | import javax.annotation.Resource; | 26 | import javax.annotation.Resource; |
| 27 | +import java.time.LocalDateTime; | ||
| 22 | import java.util.Date; | 28 | import java.util.Date; |
| 29 | +import java.util.Map; | ||
| 23 | 30 | ||
| 24 | import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; | 31 | import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId; |
| 25 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; | 32 | import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals; |
| @@ -39,8 +46,14 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { | @@ -39,8 +46,14 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { | ||
| 39 | private ProductCommentMapper productCommentMapper; | 46 | private ProductCommentMapper productCommentMapper; |
| 40 | 47 | ||
| 41 | @Resource | 48 | @Resource |
| 49 | + @Lazy | ||
| 42 | private ProductCommentServiceImpl productCommentService; | 50 | private ProductCommentServiceImpl productCommentService; |
| 43 | 51 | ||
| 52 | + @MockBean | ||
| 53 | + private TradeOrderApi tradeOrderApi; | ||
| 54 | + @MockBean | ||
| 55 | + private ProductSpuService productSpuService; | ||
| 56 | + | ||
| 44 | public String generateNo() { | 57 | public String generateNo() { |
| 45 | return DateUtil.format(new Date(), "yyyyMMddHHmmss") + RandomUtil.randomInt(100000, 999999); | 58 | return DateUtil.format(new Date(), "yyyyMMddHHmmss") + RandomUtil.randomInt(100000, 999999); |
| 46 | } | 59 | } |
| @@ -70,6 +83,23 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { | @@ -70,6 +83,23 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { | ||
| 70 | o.setScores(ProductCommentScoresEnum.FOUR.getScores()); | 83 | o.setScores(ProductCommentScoresEnum.FOUR.getScores()); |
| 71 | o.setReplied(Boolean.TRUE); | 84 | o.setReplied(Boolean.TRUE); |
| 72 | o.setVisible(Boolean.TRUE); | 85 | o.setVisible(Boolean.TRUE); |
| 86 | + o.setId(generateId()); | ||
| 87 | + o.setUserId(generateId()); | ||
| 88 | + o.setAnonymous(Boolean.TRUE); | ||
| 89 | + o.setOrderId(generateId()); | ||
| 90 | + o.setOrderItemId(generateId()); | ||
| 91 | + o.setSpuId(generateId()); | ||
| 92 | + o.setSkuId(generateId()); | ||
| 93 | + o.setDescriptionScores(ProductCommentScoresEnum.FOUR.getScores()); | ||
| 94 | + o.setBenefitScores(ProductCommentScoresEnum.FOUR.getScores()); | ||
| 95 | + o.setDeliveryScores(ProductCommentScoresEnum.FOUR.getScores()); | ||
| 96 | + o.setContent("真好吃"); | ||
| 97 | + o.setReplyUserId(generateId()); | ||
| 98 | + o.setReplyContent("确实"); | ||
| 99 | + o.setReplyTime(LocalDateTime.now()); | ||
| 100 | + o.setAdditionalTime(LocalDateTime.now()); | ||
| 101 | + o.setCreateTime(LocalDateTime.now()); | ||
| 102 | + o.setUpdateTime(LocalDateTime.now()); | ||
| 73 | }); | 103 | }); |
| 74 | productCommentMapper.insert(productComment); | 104 | productCommentMapper.insert(productComment); |
| 75 | 105 | ||
| @@ -77,7 +107,7 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { | @@ -77,7 +107,7 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { | ||
| 77 | Long spuId = productComment.getSpuId(); | 107 | Long spuId = productComment.getSpuId(); |
| 78 | 108 | ||
| 79 | // 测试 userNickname 不匹配 | 109 | // 测试 userNickname 不匹配 |
| 80 | - productCommentMapper.insert(cloneIgnoreId(productComment, o -> o.setUserNickname("王三"))); | 110 | + productCommentMapper.insert(cloneIgnoreId(productComment, o -> o.setUserNickname("王三").setScores(ProductCommentScoresEnum.ONE.getScores()))); |
| 81 | // 测试 orderId 不匹配 | 111 | // 测试 orderId 不匹配 |
| 82 | productCommentMapper.insert(cloneIgnoreId(productComment, o -> o.setOrderId(generateId()))); | 112 | productCommentMapper.insert(cloneIgnoreId(productComment, o -> o.setOrderId(generateId()))); |
| 83 | // 测试 spuId 不匹配 | 113 | // 测试 spuId 不匹配 |
| @@ -107,8 +137,25 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { | @@ -107,8 +137,25 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { | ||
| 107 | PageResult<ProductCommentDO> all = productCommentService.getCommentPage(new ProductCommentPageReqVO()); | 137 | PageResult<ProductCommentDO> all = productCommentService.getCommentPage(new ProductCommentPageReqVO()); |
| 108 | assertEquals(8, all.getTotal()); | 138 | assertEquals(8, all.getTotal()); |
| 109 | 139 | ||
| 110 | - PageResult<ProductCommentDO> visible = productCommentService.getCommentPage(new AppCommentPageReqVO(), Boolean.TRUE); | ||
| 111 | - assertEquals(7, visible.getTotal()); | 140 | + // 测试获取所有商品分页评论数据 |
| 141 | + PageResult<AppCommentRespVO> result1 = productCommentService.getCommentPage(new AppCommentPageReqVO(), Boolean.TRUE); | ||
| 142 | + assertEquals(7, result1.getTotal()); | ||
| 143 | + | ||
| 144 | + // 测试获取所有商品分页中评数据 | ||
| 145 | + PageResult<AppCommentRespVO> result2 = productCommentService.getCommentPage(new AppCommentPageReqVO().setType(ProductCommentDO.MEDIOCRE_COMMENT), Boolean.TRUE); | ||
| 146 | + assertEquals(2, result2.getTotal()); | ||
| 147 | + | ||
| 148 | + // 测试获取指定 spuId 商品分页中评数据 | ||
| 149 | + PageResult<AppCommentRespVO> result3 = productCommentService.getCommentPage(new AppCommentPageReqVO().setSpuId(spuId).setType(ProductCommentDO.MEDIOCRE_COMMENT), Boolean.TRUE); | ||
| 150 | + assertEquals(2, result3.getTotal()); | ||
| 151 | + | ||
| 152 | + // 测试分页 tab count | ||
| 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)); | ||
| 158 | + | ||
| 112 | } | 159 | } |
| 113 | 160 | ||
| 114 | @Test | 161 | @Test |