mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-08-14 10:11:53 +08:00
fix:完善商品评论 review 提到的问题
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
package cn.iocoder.yudao.module.product.api.comment;
|
||||
|
||||
import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
|
||||
import cn.iocoder.yudao.module.product.service.comment.ProductCommentService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@@ -22,9 +20,8 @@ public class ProductCommentApiImpl implements ProductCommentApi {
|
||||
private ProductCommentService productCommentService;
|
||||
|
||||
@Override
|
||||
public Long createComment(ProductCommentCreateReqDTO createReqDTO, Long orderId) {
|
||||
ProductCommentDO commentDO = ProductCommentConvert.INSTANCE.convert(createReqDTO, orderId);
|
||||
return productCommentService.createComment(commentDO);
|
||||
public Long createComment(ProductCommentCreateReqDTO createReqDTO) {
|
||||
return productCommentService.createComment(createReqDTO);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -10,43 +10,51 @@ import java.util.List;
|
||||
@Data
|
||||
public class ProductCommentBaseVO {
|
||||
|
||||
@Schema(description = "评价人名称", required = true, example = "小姑凉")
|
||||
@Schema(description = "评价人", requiredMode = Schema.RequiredMode.REQUIRED, example = "16868")
|
||||
@NotNull(message = "评价人不能为空")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "评价订单项", requiredMode = Schema.RequiredMode.REQUIRED, example = "19292")
|
||||
@NotNull(message = "评价订单项不能为空")
|
||||
private Long orderItemId;
|
||||
|
||||
@Schema(description = "评价人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小姑凉")
|
||||
@NotNull(message = "评价人名称不能为空")
|
||||
private String userNickname;
|
||||
|
||||
@Schema(description = "评价人头像", required = true, example = "https://www.iocoder.cn/xx.png")
|
||||
@Schema(description = "评价人头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png")
|
||||
@NotNull(message = "评价人头像不能为空")
|
||||
private String userAvatar;
|
||||
|
||||
@Schema(description = "商品 SPU 编号", required = true, example = "清凉丝滑透气小短袖")
|
||||
@Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉丝滑透气小短袖")
|
||||
@NotNull(message = "商品 SPU 编号不能为空")
|
||||
private Long spuId;
|
||||
|
||||
@Schema(description = "商品 SPU 名称", required = true, example = "赵六")
|
||||
@Schema(description = "商品 SPU 名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
|
||||
@NotNull(message = "商品 SPU 名称不能为空")
|
||||
private String spuName;
|
||||
|
||||
@Schema(description = "商品 SKU 编号", required = true, example = "1")
|
||||
@Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "商品 SKU 编号不能为空")
|
||||
private Long skuId;
|
||||
|
||||
@Schema(description = "评分星级 1-5 分", required = true, example = "5")
|
||||
@Schema(description = "评分星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
|
||||
@NotNull(message = "评分星级不能为空")
|
||||
private Integer scores;
|
||||
|
||||
@Schema(description = "描述星级 1-5 分", required = true, example = "5")
|
||||
@Schema(description = "描述星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
|
||||
@NotNull(message = "描述星级不能为空")
|
||||
private Integer descriptionScores;
|
||||
|
||||
@Schema(description = "服务星级 1-5 分", required = true, example = "5")
|
||||
@Schema(description = "服务星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
|
||||
@NotNull(message = "服务星级分不能为空")
|
||||
private Integer benefitScores;
|
||||
|
||||
@Schema(description = "评论内容", required = true, example = "穿起来非常丝滑凉快")
|
||||
@Schema(description = "评论内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "穿起来非常丝滑凉快")
|
||||
@NotNull(message = "评论内容不能为空")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", required = true, example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xxx.png]")
|
||||
@Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xxx.png]")
|
||||
@Size(max = 9, message = "评论图片地址数组长度不能超过 9 张")
|
||||
private List<String> picUrls;
|
||||
|
||||
|
@@ -5,21 +5,10 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Schema(description = "管理后台 - 商品评价创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ProductCommentCreateReqVO extends ProductCommentBaseVO {
|
||||
|
||||
// TODO @puhui999:是不是也放到父类里?
|
||||
@Schema(description = "评价人", required = true, example = "16868")
|
||||
@NotNull(message = "评价人不能为空")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "评价订单项", required = true, example = "19292")
|
||||
@NotNull(message = "评价订单项不能为空")
|
||||
private Long orderItemId;
|
||||
|
||||
}
|
||||
|
@@ -12,11 +12,11 @@ import javax.validation.constraints.NotNull;
|
||||
@ToString(callSuper = true)
|
||||
public class ProductCommentReplyReqVO {
|
||||
|
||||
@Schema(description = "评价编号", required = true, example = "15721")
|
||||
@Schema(description = "评价编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
|
||||
@NotNull(message = "评价编号不能为空")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "商家回复内容", required = true, example = "谢谢亲")
|
||||
@Schema(description = "商家回复内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "谢谢亲")
|
||||
@NotEmpty(message = "商家回复内容不能为空")
|
||||
private String replyContent;
|
||||
|
||||
|
@@ -13,37 +13,31 @@ import java.time.LocalDateTime;
|
||||
@ToString(callSuper = true)
|
||||
public class ProductCommentRespVO extends ProductCommentBaseVO {
|
||||
|
||||
@Schema(description = "订单项编号", required = true, example = "24965")
|
||||
@Schema(description = "订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24965")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "是否匿名", required = true, example = "false")
|
||||
@Schema(description = "是否匿名", requiredMode = Schema.RequiredMode.REQUIRED, example = "false")
|
||||
private Boolean anonymous;
|
||||
|
||||
@Schema(description = "交易订单编号", required = true, example = "24428")
|
||||
@Schema(description = "交易订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24428")
|
||||
private Long orderId;
|
||||
|
||||
@Schema(description = "评价人 用户编号", required = true, example = "15721")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "交易订单项编号", required = true, example = "8233")
|
||||
private Long orderItemId;
|
||||
|
||||
@Schema(description = "是否可见:[true:显示 false:隐藏]", required = true)
|
||||
@Schema(description = "是否可见:[true:显示 false:隐藏]", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private Boolean visible;
|
||||
|
||||
@Schema(description = "商家是否回复:[1:回复 0:未回复]", required = true)
|
||||
@Schema(description = "商家是否回复:[1:回复 0:未回复]", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private Boolean replyStatus;
|
||||
|
||||
@Schema(description = "回复管理员编号", example = "22212")
|
||||
@Schema(description = "回复管理员编号", example = "9527")
|
||||
private Long replyUserId;
|
||||
|
||||
@Schema(description = "商家回复内容")
|
||||
@Schema(description = "商家回复内容", example = "感谢好评哦亲(づ ̄3 ̄)づ╭❤~")
|
||||
private String replyContent;
|
||||
|
||||
@Schema(description = "商家回复时间")
|
||||
@Schema(description = "商家回复时间", example = "2023-08-08 12:20:55")
|
||||
private LocalDateTime replyTime;
|
||||
|
||||
@Schema(description = "创建时间", required = true)
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
|
@@ -11,11 +11,11 @@ import javax.validation.constraints.NotNull;
|
||||
@ToString(callSuper = true)
|
||||
public class ProductCommentUpdateVisibleReqVO {
|
||||
|
||||
@Schema(description = "评价编号", required = true, example = "15721")
|
||||
@Schema(description = "评价编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
|
||||
@NotNull(message = "评价编号不能为空")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "是否可见", required = true, example = "false")
|
||||
@Schema(description = "是否可见", requiredMode = Schema.RequiredMode.REQUIRED, example = "false")
|
||||
@NotNull(message = "是否可见不能为空")
|
||||
private Boolean visible;
|
||||
|
||||
|
@@ -1,16 +1,23 @@
|
||||
package cn.iocoder.yudao.module.product.controller.app.comment;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO;
|
||||
import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO;
|
||||
import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO;
|
||||
import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
|
||||
import cn.iocoder.yudao.module.product.service.comment.ProductCommentService;
|
||||
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -19,11 +26,11 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@@ -36,7 +43,10 @@ public class AppProductCommentController {
|
||||
@Resource
|
||||
private ProductCommentService productCommentService;
|
||||
|
||||
// TODO @puhui999:可以实现下
|
||||
@Resource
|
||||
@Lazy
|
||||
private ProductSkuService productSkuService;
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获得最近的 n 条商品评价")
|
||||
@Parameters({
|
||||
@@ -45,67 +55,38 @@ public class AppProductCommentController {
|
||||
})
|
||||
public CommonResult<List<AppProductCommentRespVO>> getCommentList(@RequestParam("spuId") Long spuId,
|
||||
@RequestParam(value = "count", defaultValue = "10") Integer count) {
|
||||
List<AppProductPropertyValueDetailRespVO> list = new ArrayList<>();
|
||||
return success(productCommentService.getCommentList(spuId, count));
|
||||
|
||||
AppProductPropertyValueDetailRespVO item1 = new AppProductPropertyValueDetailRespVO();
|
||||
item1.setPropertyId(1L);
|
||||
item1.setPropertyName("颜色");
|
||||
item1.setValueId(1024L);
|
||||
item1.setValueName("红色");
|
||||
list.add(item1);
|
||||
|
||||
AppProductPropertyValueDetailRespVO item2 = new AppProductPropertyValueDetailRespVO();
|
||||
item2.setPropertyId(2L);
|
||||
item2.setPropertyName("尺寸");
|
||||
item2.setValueId(2048L);
|
||||
item2.setValueName("大号");
|
||||
list.add(item2);
|
||||
|
||||
AppProductPropertyValueDetailRespVO item3 = new AppProductPropertyValueDetailRespVO();
|
||||
item3.setPropertyId(3L);
|
||||
item3.setPropertyName("重量");
|
||||
item3.setValueId(3072L);
|
||||
item3.setValueName("500克");
|
||||
list.add(item3);
|
||||
|
||||
// TODO 生成 mock 的数据
|
||||
AppProductCommentRespVO appCommentRespVO = new AppProductCommentRespVO();
|
||||
appCommentRespVO.setUserId((long) (new Random().nextInt(100000) + 10000));
|
||||
appCommentRespVO.setUserNickname("用户" + new Random().nextInt(100));
|
||||
appCommentRespVO.setUserAvatar("https://demo26.crmeb.net/uploads/attach/2021/11/15/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg");
|
||||
appCommentRespVO.setId((long) (new Random().nextInt(100000) + 10000));
|
||||
appCommentRespVO.setAnonymous(new Random().nextBoolean());
|
||||
appCommentRespVO.setOrderId((long) (new Random().nextInt(100000) + 10000));
|
||||
appCommentRespVO.setOrderItemId((long) (new Random().nextInt(100000) + 10000));
|
||||
appCommentRespVO.setReplyStatus(new Random().nextBoolean());
|
||||
appCommentRespVO.setReplyUserId((long) (new Random().nextInt(100000) + 10000));
|
||||
appCommentRespVO.setReplyContent("回复内容" + new Random().nextInt(100));
|
||||
appCommentRespVO.setReplyTime(LocalDateTime.now().minusDays(new Random().nextInt(30)));
|
||||
appCommentRespVO.setCreateTime(LocalDateTime.now().minusDays(new Random().nextInt(30)));
|
||||
appCommentRespVO.setSpuId((long) (new Random().nextInt(100000) + 10000));
|
||||
appCommentRespVO.setSpuName("商品" + new Random().nextInt(100));
|
||||
appCommentRespVO.setSkuId((long) (new Random().nextInt(100000) + 10000));
|
||||
appCommentRespVO.setSkuProperties(list);
|
||||
appCommentRespVO.setScores(new Random().nextInt(5) + 1);
|
||||
appCommentRespVO.setDescriptionScores(new Random().nextInt(5) + 1);
|
||||
appCommentRespVO.setBenefitScores(new Random().nextInt(5) + 1);
|
||||
appCommentRespVO.setContent("评论内容" + new Random().nextInt(100));
|
||||
appCommentRespVO.setPicUrls(Arrays.asList("https://demo26.crmeb.net/uploads/attach/2021/11/15/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg"));
|
||||
|
||||
return success(Arrays.asList(appCommentRespVO));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得商品评价分页")
|
||||
public CommonResult<PageResult<AppProductCommentRespVO>> getCommentPage(@Valid AppCommentPageReqVO pageVO) {
|
||||
return success(productCommentService.getCommentPage(pageVO, Boolean.TRUE));
|
||||
PageResult<AppProductCommentRespVO> page = productCommentService.getCommentPage(pageVO, Boolean.TRUE);
|
||||
Set<Long> skuIds = page.getList().stream().map(AppProductCommentRespVO::getSkuId).collect(Collectors.toSet());
|
||||
List<ProductSkuDO> skuList = productSkuService.getSkuList(skuIds);
|
||||
Map<Long, ProductSkuDO> skuDOMap = new HashMap<>(skuIds.size());
|
||||
if (CollUtil.isNotEmpty(skuList)) {
|
||||
skuDOMap.putAll(skuList.stream().collect(Collectors.toMap(ProductSkuDO::getId, c -> c)));
|
||||
}
|
||||
page.getList().forEach(item -> {
|
||||
// 判断用户是否选择匿名
|
||||
if (ObjectUtil.equal(item.getAnonymous(), true)) {
|
||||
item.setUserNickname(ProductCommentDO.NICKNAME_ANONYMOUS);
|
||||
}
|
||||
ProductSkuDO productSkuDO = skuDOMap.get(item.getSkuId());
|
||||
if (productSkuDO != null) {
|
||||
List<AppProductPropertyValueDetailRespVO> skuProperties = ProductCommentConvert.INSTANCE.convertList01(productSkuDO.getProperties());
|
||||
item.setSkuProperties(skuProperties);
|
||||
}
|
||||
});
|
||||
return success(page);
|
||||
}
|
||||
|
||||
// TODO @puhui:get-statistics;方法改成 getCommentStatistics;getCommentPageTabsCount 也改掉哈
|
||||
@GetMapping("/getCommentStatistics")
|
||||
@Operation(summary = "获得商品的评价统计")
|
||||
public CommonResult<AppCommentStatisticsRespVO> getCommentPage(@Valid @RequestParam("spuId") Long spuId) {
|
||||
return success(productCommentService.getCommentPageTabsCount(spuId, Boolean.TRUE));
|
||||
public CommonResult<AppCommentStatisticsRespVO> getCommentStatistics(@Valid @RequestParam("spuId") Long spuId) {
|
||||
return success(productCommentService.getCommentStatistics(spuId, Boolean.TRUE));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -9,16 +9,16 @@ import lombok.ToString;
|
||||
@ToString(callSuper = true)
|
||||
public class AppCommentStatisticsRespVO {
|
||||
|
||||
@Schema(description = "所有评论数量", required = true, example = "15721")
|
||||
@Schema(description = "所有评论数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
|
||||
private Long allCount;
|
||||
|
||||
@Schema(description = "好评数量", required = true, example = "15721")
|
||||
@Schema(description = "好评数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
|
||||
private Long goodCount;
|
||||
|
||||
@Schema(description = "中评数量", required = true, example = "15721")
|
||||
@Schema(description = "中评数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
|
||||
private Long mediocreCount;
|
||||
|
||||
@Schema(description = "差评数量", required = true, example = "15721")
|
||||
@Schema(description = "差评数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
|
||||
private Long negativeCount;
|
||||
|
||||
}
|
||||
|
@@ -13,43 +13,43 @@ import java.util.List;
|
||||
@ToString(callSuper = true)
|
||||
public class AppProductCommentCreateReqVO {
|
||||
|
||||
@Schema(description = "是否匿名", required = true, example = "true")
|
||||
@Schema(description = "是否匿名", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
|
||||
@NotNull(message = "是否匿名不能为空")
|
||||
private Boolean anonymous;
|
||||
|
||||
@Schema(description = "交易订单项编号", required = true, example = "2312312")
|
||||
@Schema(description = "交易订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2312312")
|
||||
@NotNull(message = "交易订单项编号不能为空")
|
||||
private Long orderItemId;
|
||||
|
||||
@Schema(description = "商品 SPU 编号", required = true, example = "91192")
|
||||
@Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "91192")
|
||||
@NotNull(message = "商品SPU编号不能为空")
|
||||
private Long spuId;
|
||||
|
||||
@Schema(description = "商品 SPU 名称", required = true, example = "清凉丝滑小短袖")
|
||||
@Schema(description = "商品 SPU 名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉丝滑小短袖")
|
||||
@NotNull(message = "商品SPU名称不能为空")
|
||||
private String spuName;
|
||||
|
||||
@Schema(description = "商品 SKU 编号", required = true, example = "81192")
|
||||
@Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "81192")
|
||||
@NotNull(message = "商品SKU编号不能为空")
|
||||
private Long skuId;
|
||||
|
||||
@Schema(description = "评分星级 1-5 分", required = true, example = "5")
|
||||
@Schema(description = "评分星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
|
||||
@NotNull(message = "评分星级 1-5 分不能为空")
|
||||
private Integer scores;
|
||||
|
||||
@Schema(description = "描述星级 1-5 分", required = true, example = "5")
|
||||
@Schema(description = "描述星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
|
||||
@NotNull(message = "描述星级 1-5 分不能为空")
|
||||
private Integer descriptionScores;
|
||||
|
||||
@Schema(description = "服务星级 1-5 分", required = true, example = "5")
|
||||
@Schema(description = "服务星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
|
||||
@NotNull(message = "服务星级 1-5 分不能为空")
|
||||
private Integer benefitScores;
|
||||
|
||||
@Schema(description = "评论内容", required = true, example = "哇,真的很丝滑凉快诶,好评")
|
||||
@Schema(description = "评论内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "哇,真的很丝滑凉快诶,好评")
|
||||
@NotNull(message = "评论内容不能为空")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", required = true, example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xxx.png]")
|
||||
@Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xxx.png]")
|
||||
@Size(max = 9, message = "评论图片地址数组长度不能超过 9 张")
|
||||
private List<String> picUrls;
|
||||
|
||||
|
@@ -23,28 +23,28 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
|
||||
@ToString(callSuper = true)
|
||||
public class AppProductCommentRespVO {
|
||||
|
||||
@Schema(description = "评价人的用户编号", required = true, example = "15721")
|
||||
@Schema(description = "评价人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "评价人名称", required = true, example = "张三")
|
||||
@Schema(description = "评价人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三")
|
||||
private String userNickname;
|
||||
|
||||
@Schema(description = "评价人头像", required = true, example = "https://www.iocoder.cn/xx.png")
|
||||
@Schema(description = "评价人头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png")
|
||||
private String userAvatar;
|
||||
|
||||
@Schema(description = "订单项编号", required = true, example = "24965")
|
||||
@Schema(description = "订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24965")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "是否匿名", required = true, example = "false")
|
||||
@Schema(description = "是否匿名", requiredMode = Schema.RequiredMode.REQUIRED, example = "false")
|
||||
private Boolean anonymous;
|
||||
|
||||
@Schema(description = "交易订单编号", required = true, example = "24428")
|
||||
@Schema(description = "交易订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24428")
|
||||
private Long orderId;
|
||||
|
||||
@Schema(description = "交易订单项编号", required = true, example = "8233")
|
||||
@Schema(description = "交易订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "8233")
|
||||
private Long orderItemId;
|
||||
|
||||
@Schema(description = "商家是否回复", required = true, example = "true")
|
||||
@Schema(description = "商家是否回复", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
|
||||
private Boolean replyStatus;
|
||||
|
||||
@Schema(description = "回复管理员编号", example = "22212")
|
||||
@@ -71,38 +71,38 @@ public class AppProductCommentRespVO {
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "商品SPU编号", required = true, example = "91192")
|
||||
@Schema(description = "商品SPU编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "91192")
|
||||
@NotNull(message = "商品SPU编号不能为空")
|
||||
private Long spuId;
|
||||
|
||||
@Schema(description = "商品SPU名称", required = true, example = "清凉丝滑小短袖")
|
||||
@Schema(description = "商品SPU名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉丝滑小短袖")
|
||||
@NotNull(message = "商品SPU名称不能为空")
|
||||
private String spuName;
|
||||
|
||||
@Schema(description = "商品SKU编号", required = true, example = "81192")
|
||||
@Schema(description = "商品SKU编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "81192")
|
||||
@NotNull(message = "商品SKU编号不能为空")
|
||||
private Long skuId;
|
||||
|
||||
@Schema(description = "商品 SKU 属性", required = true)
|
||||
@Schema(description = "商品 SKU 属性", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private List<AppProductPropertyValueDetailRespVO> skuProperties;
|
||||
|
||||
@Schema(description = "评分星级 1-5 分", required = true, example = "5")
|
||||
@Schema(description = "评分星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
|
||||
@NotNull(message = "评分星级 1-5 分不能为空")
|
||||
private Integer scores;
|
||||
|
||||
@Schema(description = "描述星级 1-5 分", required = true, example = "5")
|
||||
@Schema(description = "描述星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
|
||||
@NotNull(message = "描述星级 1-5 分不能为空")
|
||||
private Integer descriptionScores;
|
||||
|
||||
@Schema(description = "服务星级 1-5 分", required = true, example = "5")
|
||||
@Schema(description = "服务星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
|
||||
@NotNull(message = "服务星级 1-5 分不能为空")
|
||||
private Integer benefitScores;
|
||||
|
||||
@Schema(description = "评论内容", required = true, example = "哇,真的很丝滑凉快诶,好评")
|
||||
@Schema(description = "评论内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "哇,真的很丝滑凉快诶,好评")
|
||||
@NotNull(message = "评论内容不能为空")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", required = true, example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xxx.png]")
|
||||
@Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xxx.png]")
|
||||
@Size(max = 9, message = "评论图片地址数组长度不能超过 9 张")
|
||||
private List<String> picUrls;
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package cn.iocoder.yudao.module.product.convert.comment;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
|
||||
import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentCreateReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentRespVO;
|
||||
@@ -9,6 +10,7 @@ import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductComme
|
||||
import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Named;
|
||||
@@ -59,9 +61,18 @@ public interface ProductCommentConvert {
|
||||
return divide.intValue();
|
||||
}
|
||||
|
||||
@Mapping(target = "orderId", source = "orderId")
|
||||
ProductCommentDO convert(ProductCommentCreateReqDTO createReqDTO);
|
||||
|
||||
@Mapping(target = "scores", expression = "java(convertScores(createReqDTO.getDescriptionScores(), createReqDTO.getBenefitScores()))")
|
||||
ProductCommentDO convert(ProductCommentCreateReqDTO createReqDTO, Long orderId);
|
||||
default ProductCommentDO convert(ProductCommentCreateReqDTO createReqDTO, ProductSpuDO spuDO, MemberUserRespDTO user) {
|
||||
ProductCommentDO commentDO = convert(createReqDTO);
|
||||
commentDO.setUserId(user.getId());
|
||||
commentDO.setUserNickname(user.getNickname());
|
||||
commentDO.setUserAvatar(user.getAvatar());
|
||||
commentDO.setSpuId(spuDO.getId());
|
||||
commentDO.setSpuName(spuDO.getName());
|
||||
return commentDO;
|
||||
}
|
||||
|
||||
@Mapping(target = "userId", constant = "0L")
|
||||
@Mapping(target = "orderId", constant = "0L")
|
||||
@@ -70,4 +81,5 @@ public interface ProductCommentConvert {
|
||||
@Mapping(target = "scores", expression = "java(convertScores(createReq.getDescriptionScores(), createReq.getBenefitScores()))")
|
||||
ProductCommentDO convert(ProductCommentCreateReqVO createReq);
|
||||
|
||||
List<AppProductCommentRespVO> convertList02(List<ProductCommentDO> list);
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.product.dal.mysql.comment;
|
||||
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
@@ -25,19 +26,18 @@ public interface ProductCommentMapper extends BaseMapperX<ProductCommentDO> {
|
||||
}
|
||||
|
||||
// TODO 芋艿:在看看这块
|
||||
// TODO @puhui999:直接使用 scores 来算好评、中评、差评
|
||||
static void appendTabQuery(LambdaQueryWrapperX<ProductCommentDO> queryWrapper, Integer type) {
|
||||
// 构建好评查询语句:好评计算 (商品评分星级+服务评分星级) >= 8
|
||||
// 构建好评查询语句:好评计算 总评 >= 4
|
||||
if (ObjectUtil.equal(type, AppCommentPageReqVO.GOOD_COMMENT)) {
|
||||
queryWrapper.apply("(scores + benefit_scores) >= 8");
|
||||
queryWrapper.apply("scores >= 4");
|
||||
}
|
||||
// 构建中评查询语句:中评计算 (商品评分星级+服务评分星级) > 4 且 (商品评分星级+服务评分星级) < 8
|
||||
// 构建中评查询语句:中评计算 总评 >= 3 且 总评 < 4
|
||||
if (ObjectUtil.equal(type, AppCommentPageReqVO.MEDIOCRE_COMMENT)) {
|
||||
queryWrapper.apply("(scores + benefit_scores) > 4 and (scores + benefit_scores) < 8");
|
||||
queryWrapper.apply("scores >=3 and scores < 4");
|
||||
}
|
||||
// 构建差评查询语句:差评计算 (商品评分星级+服务评分星级) <= 4
|
||||
// 构建差评查询语句:差评计算 总评 < 3
|
||||
if (ObjectUtil.equal(type, AppCommentPageReqVO.NEGATIVE_COMMENT)) {
|
||||
queryWrapper.apply("(scores + benefit_scores) <= 4");
|
||||
queryWrapper.apply("scores < 3");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,10 +52,10 @@ public interface ProductCommentMapper extends BaseMapperX<ProductCommentDO> {
|
||||
return selectPage(reqVO, queryWrapper);
|
||||
}
|
||||
|
||||
default ProductCommentDO selectByUserIdAndOrderIdAndSpuId(Long userId, Long orderId, Long spuId) {
|
||||
default ProductCommentDO selectByUserIdAndOrderItemIdAndSpuId(Long userId, Long orderItemId, Long spuId) {
|
||||
return selectOne(new LambdaQueryWrapperX<ProductCommentDO>()
|
||||
.eq(ProductCommentDO::getUserId, userId)
|
||||
.eq(ProductCommentDO::getOrderId, orderId)
|
||||
.eq(ProductCommentDO::getOrderItemId, orderItemId)
|
||||
.eq(ProductCommentDO::getSpuId, spuId));
|
||||
}
|
||||
|
||||
@@ -68,4 +68,12 @@ public interface ProductCommentMapper extends BaseMapperX<ProductCommentDO> {
|
||||
return selectCount(queryWrapper);
|
||||
}
|
||||
|
||||
default PageResult<ProductCommentDO> selectCommentList(Long spuId, Integer count) {
|
||||
// 构建分页查询条件
|
||||
return selectPage(new PageParam().setPageSize(count), new LambdaQueryWrapperX<ProductCommentDO>()
|
||||
.eqIfPresent(ProductCommentDO::getSpuId, spuId)
|
||||
.orderByDesc(ProductCommentDO::getCreateTime)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package cn.iocoder.yudao.module.product.service.comment;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentCreateReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentPageReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyReqVO;
|
||||
@@ -12,6 +13,8 @@ import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品评论 Service 接口
|
||||
*
|
||||
@@ -65,10 +68,10 @@ public interface ProductCommentService {
|
||||
* 创建评论
|
||||
* 创建商品评论 APP 端创建商品评论使用
|
||||
*
|
||||
* @param commentDO 评论对象
|
||||
* @param createReqDTO 创建请求 dto
|
||||
* @return 返回评论 id
|
||||
*/
|
||||
Long createComment(ProductCommentDO commentDO);
|
||||
Long createComment(ProductCommentCreateReqDTO createReqDTO);
|
||||
|
||||
/**
|
||||
* 获得商品的评价统计
|
||||
@@ -77,6 +80,15 @@ public interface ProductCommentService {
|
||||
* @param visible 是否可见
|
||||
* @return 评价统计
|
||||
*/
|
||||
AppCommentStatisticsRespVO getCommentPageTabsCount(Long spuId, Boolean visible);
|
||||
AppCommentStatisticsRespVO getCommentStatistics(Long spuId, Boolean visible);
|
||||
|
||||
/**
|
||||
* 得到评论列表
|
||||
*
|
||||
* @param spuId 商品 id
|
||||
* @param count 数量
|
||||
* @return {@link Object}
|
||||
*/
|
||||
List<AppProductCommentRespVO> getCommentList(Long spuId, Integer count);
|
||||
|
||||
}
|
||||
|
@@ -1,8 +1,9 @@
|
||||
package cn.iocoder.yudao.module.product.service.comment;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
|
||||
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
|
||||
import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentCreateReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentPageReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyReqVO;
|
||||
@@ -10,7 +11,6 @@ import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommen
|
||||
import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO;
|
||||
import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO;
|
||||
import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO;
|
||||
import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
|
||||
@@ -18,7 +18,6 @@ import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
|
||||
import cn.iocoder.yudao.module.product.dal.mysql.comment.ProductCommentMapper;
|
||||
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
|
||||
import cn.iocoder.yudao.module.product.service.spu.ProductSpuService;
|
||||
import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -26,11 +25,7 @@ import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*;
|
||||
@@ -47,9 +42,6 @@ public class ProductCommentServiceImpl implements ProductCommentService {
|
||||
@Resource
|
||||
private ProductCommentMapper productCommentMapper;
|
||||
|
||||
@Resource
|
||||
private TradeOrderApi tradeOrderApi;
|
||||
|
||||
@Resource
|
||||
private ProductSpuService productSpuService;
|
||||
|
||||
@@ -57,6 +49,9 @@ public class ProductCommentServiceImpl implements ProductCommentService {
|
||||
@Lazy
|
||||
private ProductSkuService productSkuService;
|
||||
|
||||
@Resource
|
||||
private MemberUserApi memberUserApi;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateCommentVisible(ProductCommentUpdateVisibleReqVO updateReqVO) {
|
||||
@@ -85,11 +80,8 @@ public class ProductCommentServiceImpl implements ProductCommentService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void createComment(ProductCommentCreateReqVO createReqVO) {
|
||||
// 校验订单
|
||||
// TODO @puhui999:不校验哈;尽可能解耦
|
||||
Long orderId = tradeOrderApi.validateOrder(createReqVO.getUserId(), createReqVO.getOrderItemId());
|
||||
// 校验评论
|
||||
validateComment(createReqVO.getSpuId(), createReqVO.getUserId(), orderId);
|
||||
validateComment(createReqVO.getSpuId(), createReqVO.getUserId(), createReqVO.getOrderItemId());
|
||||
|
||||
ProductCommentDO commentDO = ProductCommentConvert.INSTANCE.convert(createReqVO);
|
||||
productCommentMapper.insert(commentDO);
|
||||
@@ -97,24 +89,39 @@ public class ProductCommentServiceImpl implements ProductCommentService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long createComment(ProductCommentDO commentDO) {
|
||||
public Long createComment(ProductCommentCreateReqDTO createReqDTO) {
|
||||
// 通过 sku ID 拿到 spu 相关信息
|
||||
ProductSkuDO sku = productSkuService.getSku(createReqDTO.getSkuId());
|
||||
if (sku == null) {
|
||||
throw exception(SKU_NOT_EXISTS);
|
||||
}
|
||||
// 校验 spu 如果存在返回详情
|
||||
ProductSpuDO spuDO = validateSpu(sku.getSpuId());
|
||||
// 校验评论
|
||||
validateComment(commentDO.getSpuId(), commentDO.getUserId(), commentDO.getOrderId());
|
||||
validateComment(spuDO.getId(), createReqDTO.getUserId(), createReqDTO.getOrderId());
|
||||
// 获取用户详细信息
|
||||
MemberUserRespDTO user = memberUserApi.getUser(createReqDTO.getUserId());
|
||||
|
||||
// 创建评论
|
||||
ProductCommentDO commentDO = ProductCommentConvert.INSTANCE.convert(createReqDTO, spuDO, user);
|
||||
productCommentMapper.insert(commentDO);
|
||||
return commentDO.getId();
|
||||
}
|
||||
|
||||
private void validateComment(Long spuId, Long userId, Long orderId) {
|
||||
private void validateComment(Long spuId, Long userId, Long orderItemId) {
|
||||
// 判断当前订单的当前商品用户是否评价过
|
||||
ProductCommentDO exist = productCommentMapper.selectByUserIdAndOrderItemIdAndSpuId(userId, orderItemId, spuId);
|
||||
if (null != exist) {
|
||||
throw exception(ORDER_SPU_COMMENT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private ProductSpuDO validateSpu(Long spuId) {
|
||||
ProductSpuDO spu = productSpuService.getSpu(spuId);
|
||||
if (null == spu) {
|
||||
throw exception(SPU_NOT_EXISTS);
|
||||
}
|
||||
// 判断当前订单的当前商品用户是否评价过
|
||||
ProductCommentDO exist = productCommentMapper.selectByUserIdAndOrderIdAndSpuId(userId, orderId, spuId);
|
||||
if (null != exist) {
|
||||
throw exception(ORDER_SPU_COMMENT_EXISTS);
|
||||
}
|
||||
return spu;
|
||||
}
|
||||
|
||||
private ProductCommentDO validateCommentExists(Long id) {
|
||||
@@ -126,7 +133,7 @@ public class ProductCommentServiceImpl implements ProductCommentService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppCommentStatisticsRespVO getCommentPageTabsCount(Long spuId, Boolean visible) {
|
||||
public AppCommentStatisticsRespVO getCommentStatistics(Long spuId, Boolean visible) {
|
||||
return ProductCommentConvert.INSTANCE.convert(
|
||||
// 查询商品 id = spuId 的所有评论数量
|
||||
productCommentMapper.selectCountBySpuId(spuId, visible, null),
|
||||
@@ -139,29 +146,18 @@ public class ProductCommentServiceImpl implements ProductCommentService {
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AppProductCommentRespVO> getCommentList(Long spuId, Integer count) {
|
||||
// 校验商品 spu 是否存在
|
||||
ProductSpuDO spuDO = validateSpu(spuId);
|
||||
|
||||
return ProductCommentConvert.INSTANCE.convertList02(productCommentMapper.selectCommentList(spuDO.getId(), count).getList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<AppProductCommentRespVO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible) {
|
||||
PageResult<AppProductCommentRespVO> result = ProductCommentConvert.INSTANCE.convertPage02(
|
||||
return ProductCommentConvert.INSTANCE.convertPage02(
|
||||
productCommentMapper.selectPage(pageVO, visible));
|
||||
// TODO @puhui999:要不这块放到 controller 里拼接?
|
||||
Set<Long> skuIds = result.getList().stream().map(AppProductCommentRespVO::getSkuId).collect(Collectors.toSet());
|
||||
List<ProductSkuDO> skuList = productSkuService.getSkuList(skuIds);
|
||||
Map<Long, ProductSkuDO> skuDOMap = new HashMap<>(skuIds.size());
|
||||
if (CollUtil.isNotEmpty(skuList)) {
|
||||
skuDOMap.putAll(skuList.stream().collect(Collectors.toMap(ProductSkuDO::getId, c -> c)));
|
||||
}
|
||||
result.getList().forEach(item -> {
|
||||
// 判断用户是否选择匿名
|
||||
if (ObjectUtil.equal(item.getAnonymous(), true)) {
|
||||
item.setUserNickname(ProductCommentDO.NICKNAME_ANONYMOUS);
|
||||
}
|
||||
ProductSkuDO productSkuDO = skuDOMap.get(item.getSkuId());
|
||||
if (productSkuDO != null) {
|
||||
List<AppProductPropertyValueDetailRespVO> skuProperties = ProductCommentConvert.INSTANCE.convertList01(productSkuDO.getProperties());
|
||||
item.setSkuProperties(skuProperties);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -150,7 +150,7 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest {
|
||||
assertEquals(2, result3.getTotal());
|
||||
|
||||
// 测试分页 tab count
|
||||
AppCommentStatisticsRespVO tabsCount = productCommentService.getCommentPageTabsCount(spuId, Boolean.TRUE);
|
||||
AppCommentStatisticsRespVO tabsCount = productCommentService.getCommentStatistics(spuId, Boolean.TRUE);
|
||||
assertEquals(6, tabsCount.getAllCount());
|
||||
assertEquals(4, tabsCount.getGoodCount());
|
||||
assertEquals(2, tabsCount.getMediocreCount());
|
||||
|
Reference in New Issue
Block a user