diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java index 6a8b12778..91020a51c 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java @@ -46,7 +46,7 @@ public class ProductCommentController { @PutMapping("/reply") @Operation(summary = "商家回复") @PreAuthorize("@ss.hasPermission('product:comment:update')") - public CommonResult commentReply(@Valid @RequestBody ProductCommentReplyVO replyVO) { + public CommonResult commentReply(@Valid @RequestBody ProductCommentReplyReqVO replyVO) { productCommentService.replyComment(replyVO, getLoginUserId()); return success(true); } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentReplyVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentReplyReqVO.java similarity index 91% rename from yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentReplyVO.java rename to yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentReplyReqVO.java index a935108dc..927f898cd 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentReplyVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentReplyReqVO.java @@ -7,11 +7,10 @@ import lombok.ToString; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; -// TODO @puhui999:ReqVO @Schema(description = "管理后台 - 商品评价可见修改 Request VO") @Data @ToString(callSuper = true) -public class ProductCommentReplyVO { +public class ProductCommentReplyReqVO { @Schema(description = "评价编号", required = true, example = "15721") @NotNull(message = "评价编号不能为空") diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppProductCommentController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppProductCommentController.java index 6921e6cbf..90a387c80 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppProductCommentController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppProductCommentController.java @@ -1,14 +1,15 @@ package cn.iocoder.yudao.module.product.controller.app.comment; -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.dal.dataobject.comment.ProductCommentDO; +import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO; import cn.iocoder.yudao.module.product.service.comment.ProductCommentService; 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.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; @@ -18,6 +19,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.List; +import java.util.Random; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -30,17 +36,69 @@ public class AppProductCommentController { @Resource private ProductCommentService productCommentService; + @GetMapping("/list") + @Operation(summary = "获得最近的 n 条商品评价") + @Parameters({ + @Parameter(name = "spuId", description = "商品 SPU 编号", required = true, example = "1024"), + @Parameter(name = "count", description = "数量", required = true, example = "10") + }) + public CommonResult> getCommentList(@RequestParam("spuId") Long spuId, + @RequestParam(value = "count", defaultValue = "10") Integer count) { + + List list = new ArrayList<>(); + + 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> getCommentPage(@Valid AppCommentPageReqVO pageVO) { - PageResult result = productCommentService.getCommentPage(pageVO, Boolean.TRUE); - result.getList().forEach(item -> { - // 判断用户是否选择匿名 - if (ObjectUtil.equal(item.getAnonymous(), true)) { - item.setUserNickname(ProductCommentDO.NICKNAME_ANONYMOUS); - } - }); - return success(result); + return success(productCommentService.getCommentPage(pageVO, Boolean.TRUE)); } @GetMapping("/getCommentStatistics") 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 8799c5c75..0e6ef98cc 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 @@ -8,6 +8,11 @@ import lombok.ToString; import javax.validation.constraints.NotNull; +/** + * 用户 APP - 商品评价分页 Request VO + * + * @author HUIHUI + */ @Schema(description = "用户APP - 商品评价分页 Request VO") @Data @EqualsAndHashCode(callSuper = true) diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentBaseVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentBaseVO.java deleted file mode 100644 index 8c989ef18..000000000 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentBaseVO.java +++ /dev/null @@ -1,54 +0,0 @@ -package cn.iocoder.yudao.module.product.controller.app.comment.vo; - -import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; -import java.util.List; - -/** - * 商品评论 Base VO - * - * @author HUIHUI - */ -@Data -public class AppProductCommentBaseVO { - - @Schema(description = "商品SPU编号", required = true, example = "91192") - @NotNull(message = "商品SPU编号不能为空") - private Long spuId; - - @Schema(description = "商品SPU名称", required = true, example = "清凉丝滑小短袖") - @NotNull(message = "商品SPU名称不能为空") - private String spuName; - - @Schema(description = "商品SKU编号", required = true, example = "81192") - @NotNull(message = "商品SKU编号不能为空") - private Long skuId; - - @Schema(description = "商品 SKU 属性", required = true) - private List skuProperties; // TODO puhui999:这个需要从数据库查询哈 - - @Schema(description = "评分星级 1-5分", required = true, example = "5") - @NotNull(message = "评分星级 1-5分不能为空") - private Integer scores; - - @Schema(description = "描述星级 1-5分", required = true, example = "5") - @NotNull(message = "描述星级 1-5分不能为空") - private Integer descriptionScores; - - @Schema(description = "服务星级 1-5分", required = true, example = "5") - @NotNull(message = "服务星级 1-5分不能为空") - private Integer benefitScores; - - @Schema(description = "评论内容", required = true, example = "哇,真的很丝滑凉快诶,好评") - @NotNull(message = "评论内容不能为空") - private String content; - - @Schema(description = "评论图片地址数组,以逗号分隔最多上传9张", required = true, example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xxx.png]") - @Size(max = 9, message = "评论图片地址数组长度不能超过9张") - private List picUrls; - -} diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentCreateReqVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentCreateReqVO.java index 42cdc7e5b..53e797447 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentCreateReqVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentCreateReqVO.java @@ -2,17 +2,21 @@ package cn.iocoder.yudao.module.product.controller.app.comment.vo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; import lombok.ToString; import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.util.List; -// TODO @puhui999:不应该继承 AppProductCommentCreateReqVO +/** + * 用户APP - 商品评价创建 Request VO + * + * @author HUIHUI + */ @Schema(description = "用户APP - 商品评价创建 Request VO") @Data -@EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class AppProductCommentCreateReqVO extends AppProductCommentBaseVO { +public class AppProductCommentCreateReqVO { @Schema(description = "是否匿名", required = true, example = "true") @NotNull(message = "是否匿名不能为空") @@ -22,4 +26,36 @@ public class AppProductCommentCreateReqVO extends AppProductCommentBaseVO { @NotNull(message = "交易订单项编号不能为空") private Long orderItemId; + @Schema(description = "商品SPU编号", required = true, example = "91192") + @NotNull(message = "商品SPU编号不能为空") + private Long spuId; + + @Schema(description = "商品SPU名称", required = true, example = "清凉丝滑小短袖") + @NotNull(message = "商品SPU名称不能为空") + private String spuName; + + @Schema(description = "商品SKU编号", required = true, example = "81192") + @NotNull(message = "商品SKU编号不能为空") + private Long skuId; + + @Schema(description = "评分星级 1-5分", required = true, example = "5") + @NotNull(message = "评分星级 1-5分不能为空") + private Integer scores; + + @Schema(description = "描述星级 1-5分", required = true, example = "5") + @NotNull(message = "描述星级 1-5分不能为空") + private Integer descriptionScores; + + @Schema(description = "服务星级 1-5分", required = true, example = "5") + @NotNull(message = "服务星级 1-5分不能为空") + private Integer benefitScores; + + @Schema(description = "评论内容", required = true, example = "哇,真的很丝滑凉快诶,好评") + @NotNull(message = "评论内容不能为空") + private String content; + + @Schema(description = "评论图片地址数组,以逗号分隔最多上传9张", required = true, example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xxx.png]") + @Size(max = 9, message = "评论图片地址数组长度不能超过9张") + private List picUrls; + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentRespVO.java index 5fb8eb351..e78f996e1 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentRespVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppProductCommentRespVO.java @@ -1,19 +1,27 @@ package cn.iocoder.yudao.module.product.controller.app.comment.vo; +import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import lombok.EqualsAndHashCode; import lombok.ToString; import org.springframework.format.annotation.DateTimeFormat; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; import java.time.LocalDateTime; import java.util.List; -@Schema(description = "用户APP - 商品评价 Response VO") +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +/** + * 用户APP - 商品评价详情 Response VO + * + * @author HUIHUI + */ +@Schema(description = "用户APP - 商品评价详情 Response VO") @Data -@EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class AppProductCommentRespVO extends AppProductCommentBaseVO { +public class AppProductCommentRespVO { @Schema(description = "评价人的用户编号", required = true, example = "15721") private Long userId; @@ -63,4 +71,39 @@ public class AppProductCommentRespVO extends AppProductCommentBaseVO { @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) private LocalDateTime createTime; + @Schema(description = "商品SPU编号", required = true, example = "91192") + @NotNull(message = "商品SPU编号不能为空") + private Long spuId; + + @Schema(description = "商品SPU名称", required = true, example = "清凉丝滑小短袖") + @NotNull(message = "商品SPU名称不能为空") + private String spuName; + + @Schema(description = "商品SKU编号", required = true, example = "81192") + @NotNull(message = "商品SKU编号不能为空") + private Long skuId; + + @Schema(description = "商品 SKU 属性", required = true) + private List skuProperties; + + @Schema(description = "评分星级 1-5分", required = true, example = "5") + @NotNull(message = "评分星级 1-5分不能为空") + private Integer scores; + + @Schema(description = "描述星级 1-5分", required = true, example = "5") + @NotNull(message = "描述星级 1-5分不能为空") + private Integer descriptionScores; + + @Schema(description = "服务星级 1-5分", required = true, example = "5") + @NotNull(message = "服务星级 1-5分不能为空") + private Integer benefitScores; + + @Schema(description = "评论内容", required = true, example = "哇,真的很丝滑凉快诶,好评") + @NotNull(message = "评论内容不能为空") + private String content; + + @Schema(description = "评论图片地址数组,以逗号分隔最多上传9张", required = true, example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xxx.png]") + @Size(max = 9, message = "评论图片地址数组长度不能超过9张") + private List picUrls; + } diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java index ff895f491..9ec7e5cb4 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java @@ -6,7 +6,9 @@ import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommen import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentRespVO; 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.dal.dataobject.comment.ProductCommentDO; +import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Named; @@ -36,6 +38,8 @@ public interface ProductCommentConvert { List convertList(List list); + List convertList01(List properties); + PageResult convertPage(PageResult page); PageResult convertPage02(PageResult pageResult); 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 13c0f47f7..f44c1e334 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 @@ -6,14 +6,10 @@ 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; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentPageReqVO; -import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO; -import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; -import java.time.LocalDateTime; - @Mapper public interface ProductCommentMapper extends BaseMapperX { @@ -55,23 +51,6 @@ public interface ProductCommentMapper extends BaseMapperX { return selectPage(reqVO, queryWrapper); } - default void updateCommentVisible(Long id, Boolean visible) { - LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() - .set(ProductCommentDO::getVisible, visible) - .eq(ProductCommentDO::getId, id); - update(null, lambdaUpdateWrapper); - } - - default void commentReply(ProductCommentReplyVO replyVO, Long loginUserId) { - LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() - .set(ProductCommentDO::getReplyStatus, Boolean.TRUE) - .set(ProductCommentDO::getReplyTime, LocalDateTime.now()) - .set(ProductCommentDO::getReplyUserId, loginUserId) - .set(ProductCommentDO::getReplyContent, replyVO.getReplyContent()) - .eq(ProductCommentDO::getId, replyVO.getId()); - update(null, lambdaUpdateWrapper); - } - default ProductCommentDO selectByUserIdAndOrderIdAndSpuId(Long userId, Long orderId, Long spuId) { return selectOne(new LambdaQueryWrapperX() .eq(ProductCommentDO::getUserId, userId) diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentService.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentService.java index 10592f7b9..c6841770a 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentService.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentService.java @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.product.service.comment; import cn.iocoder.yudao.framework.common.pojo.PageResult; 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.ProductCommentReplyVO; +import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyReqVO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO; @@ -36,15 +36,13 @@ public interface ProductCommentService { */ void updateCommentVisible(ProductCommentUpdateVisibleReqVO updateReqVO); - // TODO @puhui999:replyComment - /** * 商家回复 * * @param replyVO 商家回复 * @param loginUserId 管理后台商家登陆人 ID */ - void replyComment(ProductCommentReplyVO replyVO, Long loginUserId); + void replyComment(ProductCommentReplyReqVO replyVO, Long loginUserId); /** * 获得商品评价分页 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 6dc67beb8..05d38899c 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 @@ -1,25 +1,36 @@ 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.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.ProductCommentReplyVO; +import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyReqVO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO; 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.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; 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.*; @@ -42,6 +53,10 @@ public class ProductCommentServiceImpl implements ProductCommentService { @Resource private ProductSpuService productSpuService; + @Resource + @Lazy + private ProductSkuService productSkuService; + @Override @Transactional(rollbackFor = Exception.class) public void updateCommentVisible(ProductCommentUpdateVisibleReqVO updateReqVO) { @@ -55,7 +70,7 @@ public class ProductCommentServiceImpl implements ProductCommentService { @Override @Transactional(rollbackFor = Exception.class) - public void replyComment(ProductCommentReplyVO replyVO, Long loginUserId) { + public void replyComment(ProductCommentReplyReqVO replyVO, Long loginUserId) { // 校验评论是否存在 ProductCommentDO productCommentDO = validateCommentExists(replyVO.getId()); productCommentDO.setReplyTime(LocalDateTime.now()); @@ -127,7 +142,26 @@ public class ProductCommentServiceImpl implements ProductCommentService { @Override public PageResult getCommentPage(AppCommentPageReqVO pageVO, Boolean visible) { - return ProductCommentConvert.INSTANCE.convertPage02(productCommentMapper.selectPage(pageVO, visible)); + PageResult result = ProductCommentConvert.INSTANCE.convertPage02( + productCommentMapper.selectPage(pageVO, visible)); + Set skuIds = result.getList().stream().map(AppProductCommentRespVO::getSkuId).collect(Collectors.toSet()); + List skuList = productSkuService.getSkuList(skuIds); + Map 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 skuProperties = ProductCommentConvert.INSTANCE.convertList01(productSkuDO.getProperties()); + item.setSkuProperties(skuProperties); + } + }); + return result; } @Override 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 6e4419d4f..ad782bc51 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 @@ -5,7 +5,7 @@ import cn.hutool.core.util.RandomUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentPageReqVO; -import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyVO; +import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyReqVO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentRespVO; import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO; import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; @@ -15,6 +15,7 @@ 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.mysql.comment.ProductCommentMapper; import cn.iocoder.yudao.module.product.enums.comment.ProductCommentScoresEnum; +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.junit.jupiter.api.Test; @@ -52,6 +53,8 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { private TradeOrderApi tradeOrderApi; @MockBean private ProductSpuService productSpuService; + @MockBean + private ProductSkuService productSkuService; public String generateNo() { return DateUtil.format(new Date(), "yyyyMMddHHmmss") + RandomUtil.randomInt(100000, 999999); @@ -183,7 +186,7 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { Long productCommentId = productComment.getId(); - ProductCommentReplyVO replyVO = new ProductCommentReplyVO(); + ProductCommentReplyReqVO replyVO = new ProductCommentReplyReqVO(); replyVO.setId(productCommentId); replyVO.setReplyContent("测试"); productCommentService.replyComment(replyVO, 1L); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java index defc1cee7..d36c0f80a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/AppTradeOrderController.java @@ -148,4 +148,6 @@ public class AppTradeOrderController { return success(productCommentApi.createComment(TradeOrderConvert.INSTANCE.convert04(createReqVO), item.getOrderId())); } + // TODO 合并代码后发现只有商家回复功能 用户追评不要了吗? + }