Commit bb8e44a26840d5b6ad9a39d55ce7478cd54dcf81
1 parent
1e1a22c2
mall + product:增加评论 mock 逻辑
Showing
4 changed files
with
80 additions
and
16 deletions
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/AppCommentController.java
| 1 | package cn.iocoder.yudao.module.product.controller.app.comment; | 1 | package cn.iocoder.yudao.module.product.controller.app.comment; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.map.MapUtil; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.module.member.api.user.MemberUserApi; | 6 | import cn.iocoder.yudao.module.member.api.user.MemberUserApi; |
| @@ -7,16 +8,20 @@ import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; | @@ -7,16 +8,20 @@ import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; | ||
| 7 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentCreateReqVO; | 8 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentCreateReqVO; |
| 8 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; | 9 | import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO; |
| 9 | 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.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO; | ||
| 10 | import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert; | 12 | import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert; |
| 11 | import cn.iocoder.yudao.module.product.service.comment.ProductCommentService; | 13 | import cn.iocoder.yudao.module.product.service.comment.ProductCommentService; |
| 12 | import io.swagger.v3.oas.annotations.Operation; | 14 | import io.swagger.v3.oas.annotations.Operation; |
| 15 | +import io.swagger.v3.oas.annotations.Parameter; | ||
| 16 | +import io.swagger.v3.oas.annotations.Parameters; | ||
| 13 | import io.swagger.v3.oas.annotations.tags.Tag; | 17 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 14 | import org.springframework.validation.annotation.Validated; | 18 | import org.springframework.validation.annotation.Validated; |
| 15 | import org.springframework.web.bind.annotation.*; | 19 | import org.springframework.web.bind.annotation.*; |
| 16 | 20 | ||
| 17 | import javax.annotation.Resource; | 21 | import javax.annotation.Resource; |
| 18 | import javax.validation.Valid; | 22 | import javax.validation.Valid; |
| 19 | -import java.util.Map; | 23 | +import java.time.LocalDateTime; |
| 24 | +import java.util.*; | ||
| 20 | 25 | ||
| 21 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 26 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 22 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | 27 | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| @@ -34,6 +39,66 @@ public class AppCommentController { | @@ -34,6 +39,66 @@ public class AppCommentController { | ||
| 34 | @Resource | 39 | @Resource |
| 35 | private MemberUserApi memberUserApi; | 40 | private MemberUserApi memberUserApi; |
| 36 | 41 | ||
| 42 | + @GetMapping("/list") | ||
| 43 | + @Operation(summary = "获得最近的 n 条商品评价") | ||
| 44 | + @Parameters({ | ||
| 45 | + @Parameter(name = "spuId", description = "商品 SPU 编号", required = true, example = "1024"), | ||
| 46 | + @Parameter(name = "count", description = "数量", required = true, example = "10") | ||
| 47 | + }) | ||
| 48 | + public CommonResult<List<AppCommentRespVO>> getCommentList(@RequestParam("spuId") Long spuId, | ||
| 49 | + @RequestParam(value = "count", defaultValue = "10") Integer count) { | ||
| 50 | + | ||
| 51 | + List<AppProductPropertyValueDetailRespVO> list = new ArrayList<>(); | ||
| 52 | + | ||
| 53 | + AppProductPropertyValueDetailRespVO item1 = new AppProductPropertyValueDetailRespVO(); | ||
| 54 | + item1.setPropertyId(1L); | ||
| 55 | + item1.setPropertyName("颜色"); | ||
| 56 | + item1.setValueId(1024L); | ||
| 57 | + item1.setValueName("红色"); | ||
| 58 | + list.add(item1); | ||
| 59 | + | ||
| 60 | + AppProductPropertyValueDetailRespVO item2 = new AppProductPropertyValueDetailRespVO(); | ||
| 61 | + item2.setPropertyId(2L); | ||
| 62 | + item2.setPropertyName("尺寸"); | ||
| 63 | + item2.setValueId(2048L); | ||
| 64 | + item2.setValueName("大号"); | ||
| 65 | + list.add(item2); | ||
| 66 | + | ||
| 67 | + AppProductPropertyValueDetailRespVO item3 = new AppProductPropertyValueDetailRespVO(); | ||
| 68 | + item3.setPropertyId(3L); | ||
| 69 | + item3.setPropertyName("重量"); | ||
| 70 | + item3.setValueId(3072L); | ||
| 71 | + item3.setValueName("500克"); | ||
| 72 | + list.add(item3); | ||
| 73 | + | ||
| 74 | + // TODO 生成 mock 的数据 | ||
| 75 | + AppCommentRespVO appCommentRespVO = new AppCommentRespVO(); | ||
| 76 | + appCommentRespVO.setUserId((long) (new Random().nextInt(100000) + 10000)); | ||
| 77 | + appCommentRespVO.setUserNickname("用户" + new Random().nextInt(100)); | ||
| 78 | + appCommentRespVO.setUserAvatar("https://demo26.crmeb.net/uploads/attach/2021/11/15/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg"); | ||
| 79 | + appCommentRespVO.setId((long) (new Random().nextInt(100000) + 10000)); | ||
| 80 | + appCommentRespVO.setAnonymous(new Random().nextBoolean()); | ||
| 81 | + appCommentRespVO.setOrderId((long) (new Random().nextInt(100000) + 10000)); | ||
| 82 | + appCommentRespVO.setOrderItemId((long) (new Random().nextInt(100000) + 10000)); | ||
| 83 | + appCommentRespVO.setReplyStatus(new Random().nextBoolean()); | ||
| 84 | + appCommentRespVO.setReplyUserId((long) (new Random().nextInt(100000) + 10000)); | ||
| 85 | + appCommentRespVO.setReplyContent("回复内容" + new Random().nextInt(100)); | ||
| 86 | + appCommentRespVO.setReplyTime(LocalDateTime.now().minusDays(new Random().nextInt(30))); | ||
| 87 | + appCommentRespVO.setCreateTime(LocalDateTime.now().minusDays(new Random().nextInt(30))); | ||
| 88 | + appCommentRespVO.setFinalScore(new Random().nextInt(5) + 1); | ||
| 89 | + appCommentRespVO.setSpuId((long) (new Random().nextInt(100000) + 10000)); | ||
| 90 | + appCommentRespVO.setSpuName("商品" + new Random().nextInt(100)); | ||
| 91 | + appCommentRespVO.setSkuId((long) (new Random().nextInt(100000) + 10000)); | ||
| 92 | + appCommentRespVO.setSkuProperties(list); | ||
| 93 | + appCommentRespVO.setScores(new Random().nextInt(5) + 1); | ||
| 94 | + appCommentRespVO.setDescriptionScores(new Random().nextInt(5) + 1); | ||
| 95 | + appCommentRespVO.setBenefitScores(new Random().nextInt(5) + 1); | ||
| 96 | + appCommentRespVO.setContent("评论内容" + new Random().nextInt(100)); | ||
| 97 | + appCommentRespVO.setPicUrls(Arrays.asList("https://demo26.crmeb.net/uploads/attach/2021/11/15/a79f5d2ea6bf0c3c11b2127332dfe2df.jpg")); | ||
| 98 | + | ||
| 99 | + return success(Arrays.asList(appCommentRespVO)); | ||
| 100 | + } | ||
| 101 | + | ||
| 37 | @GetMapping("/page") | 102 | @GetMapping("/page") |
| 38 | @Operation(summary = "获得商品评价分页") | 103 | @Operation(summary = "获得商品评价分页") |
| 39 | public CommonResult<PageResult<AppCommentRespVO>> getCommentPage(@Valid AppCommentPageReqVO pageVO) { | 104 | public CommonResult<PageResult<AppCommentRespVO>> getCommentPage(@Valid AppCommentPageReqVO pageVO) { |
| @@ -41,10 +106,15 @@ public class AppCommentController { | @@ -41,10 +106,15 @@ public class AppCommentController { | ||
| 41 | } | 106 | } |
| 42 | 107 | ||
| 43 | // TODO @puhui999:方法名改成 getCommentStatistics?然后搞个对应的 vo?想了下,这样更优雅 | 108 | // TODO @puhui999:方法名改成 getCommentStatistics?然后搞个对应的 vo?想了下,这样更优雅 |
| 44 | - @GetMapping("/get-count") | 109 | + @GetMapping("/statistics") |
| 45 | @Operation(summary = "获得商品的评价统计") // TODO @puhui999:@RequestParam 哈,针对 spuId | 110 | @Operation(summary = "获得商品的评价统计") // TODO @puhui999:@RequestParam 哈,针对 spuId |
| 46 | - public CommonResult<Map<String, Long>> getCommentPage(@Valid Long spuId) { | ||
| 47 | - return success(productCommentService.getCommentPageTabsCount(spuId, Boolean.TRUE)); | 111 | + public CommonResult<Map<String, Object>> getCommentStatistics(@Valid Long spuId) { |
| 112 | + // TODO 生成 mock 的数据 | ||
| 113 | + if (true) { | ||
| 114 | + return success(MapUtil.<String, Object>builder("allCount", 10L).put("goodPercent", "10.33").build()); | ||
| 115 | + } | ||
| 116 | + return null; | ||
| 117 | +// return success(productCommentService.getCommentPageTabsCount(spuId, Boolean.TRUE)); | ||
| 48 | } | 118 | } |
| 49 | 119 | ||
| 50 | @PostMapping(value = "/create") | 120 | @PostMapping(value = "/create") |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentBaseVO.java
| 1 | package cn.iocoder.yudao.module.product.controller.app.comment.vo; | 1 | package cn.iocoder.yudao.module.product.controller.app.comment.vo; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO; | ||
| 3 | import io.swagger.v3.oas.annotations.media.Schema; | 4 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | import lombok.Data; | 5 | import lombok.Data; |
| 5 | 6 | ||
| @@ -7,7 +8,7 @@ import javax.validation.constraints.NotNull; | @@ -7,7 +8,7 @@ import javax.validation.constraints.NotNull; | ||
| 7 | import javax.validation.constraints.Size; | 8 | import javax.validation.constraints.Size; |
| 8 | import java.util.List; | 9 | import java.util.List; |
| 9 | 10 | ||
| 10 | -// TODO @puhui999:把 Product 前缀给补下哈 | 11 | +// TODO @puhui999:C 端可以不要 base 哈。 |
| 11 | @Data | 12 | @Data |
| 12 | public class AppCommentBaseVO { | 13 | public class AppCommentBaseVO { |
| 13 | 14 | ||
| @@ -23,6 +24,9 @@ public class AppCommentBaseVO { | @@ -23,6 +24,9 @@ public class AppCommentBaseVO { | ||
| 23 | @NotNull(message = "商品SKU编号不能为空") | 24 | @NotNull(message = "商品SKU编号不能为空") |
| 24 | private Long skuId; | 25 | private Long skuId; |
| 25 | 26 | ||
| 27 | + @Schema(description = "商品 SKU 属性", required = true) | ||
| 28 | + private List<AppProductPropertyValueDetailRespVO> skuProperties; // TODO puhui999:这个需要从数据库查询哈 | ||
| 29 | + | ||
| 26 | @Schema(description = "评分星级 1-5分", required = true) | 30 | @Schema(description = "评分星级 1-5分", required = true) |
| 27 | @NotNull(message = "评分星级 1-5分不能为空") | 31 | @NotNull(message = "评分星级 1-5分不能为空") |
| 28 | private Integer scores; | 32 | private Integer scores; |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/app/comment/vo/AppCommentRespVO.java
| @@ -6,7 +6,6 @@ import lombok.EqualsAndHashCode; | @@ -6,7 +6,6 @@ import lombok.EqualsAndHashCode; | ||
| 6 | import lombok.ToString; | 6 | import lombok.ToString; |
| 7 | 7 | ||
| 8 | import java.time.LocalDateTime; | 8 | import java.time.LocalDateTime; |
| 9 | -import java.util.List; | ||
| 10 | 9 | ||
| 11 | @Schema(description = "用户APP - 商品评价 Response VO") | 10 | @Schema(description = "用户APP - 商品评价 Response VO") |
| 12 | @Data | 11 | @Data |
| @@ -49,15 +48,6 @@ public class AppCommentRespVO extends AppCommentBaseVO { | @@ -49,15 +48,6 @@ public class AppCommentRespVO extends AppCommentBaseVO { | ||
| 49 | @Schema(description = "商家回复时间") | 48 | @Schema(description = "商家回复时间") |
| 50 | private LocalDateTime replyTime; | 49 | private LocalDateTime replyTime; |
| 51 | 50 | ||
| 52 | - @Schema(description = "追加评价内容") | ||
| 53 | - private String additionalContent; | ||
| 54 | - | ||
| 55 | - @Schema(description = "追评评价图片地址数组,以逗号分隔最多上传9张") | ||
| 56 | - private List<String> additionalPicUrls; | ||
| 57 | - | ||
| 58 | - @Schema(description = "追加评价时间") | ||
| 59 | - private LocalDateTime additionalTime; | ||
| 60 | - | ||
| 61 | @Schema(description = "创建时间", required = true) | 51 | @Schema(description = "创建时间", required = true) |
| 62 | private LocalDateTime createTime; | 52 | private LocalDateTime createTime; |
| 63 | 53 |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/comment/ProductCommentDO.java
| @@ -35,7 +35,7 @@ public class ProductCommentDO extends BaseDO { | @@ -35,7 +35,7 @@ public class ProductCommentDO extends BaseDO { | ||
| 35 | private Long id; | 35 | private Long id; |
| 36 | 36 | ||
| 37 | /** | 37 | /** |
| 38 | - * 评价人 用户编号 | 38 | + * 评价人的用户编号 |
| 39 | * | 39 | * |
| 40 | * 关联 MemberUserDO 的 id 编号 | 40 | * 关联 MemberUserDO 的 id 编号 |
| 41 | */ | 41 | */ |