Commit f69d8503a2e17995010c78eceb9bb94e9afe6371

Authored by wangzhs
1 parent c1935fba

[新增][商品评价]

1. 实体类
2. h2.sql
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/comment/ProductCommentDO.java
1 1 package cn.iocoder.yudao.module.product.dal.dataobject.comment;
2 2  
3 3 import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  4 +import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
4 5 import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
5   -import cn.iocoder.yudao.module.product.enums.comment.ProductCommentAuditStatusEnum;
6 6 import com.baomidou.mybatisplus.annotation.KeySequence;
7 7 import com.baomidou.mybatisplus.annotation.TableField;
8 8 import com.baomidou.mybatisplus.annotation.TableId;
... ... @@ -18,7 +18,7 @@ import java.util.List;
18 18 *
19 19 * @author 芋道源码
20 20 */
21   -@TableName("product_comment")
  21 +@TableName(value = "product_comment", autoResultMap = true)
22 22 @KeySequence("product_comment_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
23 23 @Data
24 24 @EqualsAndHashCode(callSuper = true)
... ... @@ -33,97 +33,139 @@ public class ProductCommentDO extends BaseDO {
33 33 */
34 34 @TableId
35 35 private Long id;
  36 +
36 37 /**
37   - * 商品 SPU 编号
38   - *
39   - * 关联 {@link ProductSpuDO#getId()}
  38 + * 评价人 用户编号
  39 + * <p>
  40 + * 关联 MemberUserDO 的 id 编号
40 41 */
41   - private Long spuId;
  42 + private Long userId;
  43 +
  44 + /**
  45 + * 评价人名称
  46 + */
  47 + private Long userNickname;
  48 +
  49 + /**
  50 + * 评价人头像
  51 + */
  52 + private Long userAvatar;
  53 +
  54 + /**
  55 + * 是否匿名
  56 + */
  57 + private Boolean anonymous;
  58 +
42 59 /**
43 60 * 交易订单编号
44   - *
  61 + * <p>
45 62 * 关联 TradeOrderDO 的 id 编号
46 63 */
47 64 private Long orderId;
  65 +
48 66 /**
49 67 * 交易订单项编号
50   - *
  68 + * <p>
51 69 * 关联 TradeOrderItemDO 的 id 编号
52 70 */
53 71 private Long orderItemId;
  72 +
54 73 /**
55   - * 审核状态
56   - *
57   - * 枚举 {@link ProductCommentAuditStatusEnum}
  74 + * 商品 SPU 编号
  75 + * <p>
  76 + * 关联 {@link ProductSpuDO#getId()}
58 77 */
59   - private Integer auditStatus;
  78 + private Long spuId;
60 79  
61 80 /**
62   - * 用户编号
63   - *
64   - * 关联 MemberUserDO 的 id 编号
  81 + * 商品 SKU 编号
  82 + * <p>
  83 + * 关联 {@link ProductSkuDO#getId()}
65 84 */
66   - private Long userId;
  85 + private Long skuId;
  86 +
67 87 /**
68   - * 用户 IP
  88 + * 是否可见
  89 + * <p>
  90 + * 1:显示 0:隐藏
69 91 */
70   - private String userIp;
  92 + private Boolean visible;
  93 +
71 94 /**
72   - * 是否匿名
  95 + * 评分星级
  96 + * <p>
  97 + * 1-5分
73 98 */
74   - private Boolean anonymous;
75   - /**
76   - * 评论内容
77   - */
78   - private String content;
  99 + private Integer scores;
  100 +
79 101 /**
80   - * 评论图片地址数组
  102 + * 描述星级
  103 + * <p>
  104 + * 1-5 星
81 105 */
82   - @TableField(typeHandler = JacksonTypeHandler.class)
83   - private List<String> picUrls;
  106 + private Integer descriptionScores;
  107 +
84 108 /**
85   - * 描述相符星级
86   - *
  109 + * 服务星级
  110 + * <p>
87 111 * 1-5 星
88 112 */
89   - private Integer descriptionScore;
  113 + private Integer benefitScores;
  114 +
90 115 /**
91   - * 商品评论星级
92   - *
  116 + * 配送星级
  117 + * <p>
93 118 * 1-5 星
94 119 */
95   - private Integer productScore;
  120 + private Integer deliveryScores;
  121 +
96 122 /**
97   - * 服务评论星级
98   - *
99   - * 1-5 星
  123 + * 评论内容
100 124 */
101   - private Integer serviceScore;
  125 + private String content;
  126 +
102 127 /**
103   - * 物流评论星级
104   - *
105   - * 1-5 星
  128 + * 评论图片地址数组
106 129 */
107   - private Integer expressComment;
  130 + @TableField(typeHandler = JacksonTypeHandler.class)
  131 + private List<String> picUrls;
108 132  
109 133 /**
110 134 * 商家是否回复
111 135 */
112 136 private Boolean replied;
  137 +
  138 + /**
  139 + * 回复管理员编号
  140 + * <p>
  141 + * 关联 AdminUserDO 的 id 编号
  142 + */
  143 + private Long replyUserId;
  144 +
113 145 /**
114 146 * 商家回复内容
115 147 */
116 148 private String replyContent;
  149 +
117 150 /**
118 151 * 商家回复时间
119 152 */
120 153 private LocalDateTime replyTime;
121 154  
122 155 /**
123   - * 有用的计数
124   - *
125   - * 其他用户看到评论时,可点击「有用」按钮
  156 + * 追加评价内容
  157 + */
  158 + private String additionalContent;
  159 +
  160 + /**
  161 + * 追评评价图片地址数组
  162 + */
  163 + @TableField(typeHandler = JacksonTypeHandler.class)
  164 + private List<String> additionalPicUrls;
  165 +
  166 + /**
  167 + * 追加评价时间
126 168 */
127   - private Integer usefulCount;
  169 + private LocalDateTime additionalCreateTime;
128 170  
129 171 }
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/comment/ProductCommentMapper.java 0 → 100644
  1 +package cn.iocoder.yudao.module.product.dal.mysql.comment;
  2 +
  3 +
  4 +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  5 +import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
  6 +import org.apache.ibatis.annotations.Mapper;
  7 +
  8 +
  9 +/**
  10 + * 商品评论 Mapper
  11 + *
  12 + * @author wangzhs
  13 + */
  14 +@Mapper
  15 +public interface ProductCommentMapper extends BaseMapperX<ProductCommentDO> {
  16 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentService.java 0 → 100644
  1 +package cn.iocoder.yudao.module.product.service.comment;
  2 +
  3 +import org.springframework.stereotype.Service;
  4 +import org.springframework.validation.annotation.Validated;
  5 +
  6 +/**
  7 + * 商品评论 Service 接口
  8 + *
  9 + * @author wangzhs
  10 + */
  11 +@Service
  12 +@Validated
  13 +public interface ProductCommentService {
  14 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.module.product.service.comment;
  2 +
  3 +/**
  4 + * 商品评论 Service 实现类
  5 + *
  6 + * @author wangzhs
  7 + */
  8 +public class ProductCommentServiceImpl implements ProductCommentService {
  9 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java 0 → 100644
  1 +package cn.iocoder.yudao.module.product.service.comment;
  2 +
  3 +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
  4 +import cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO;
  5 +import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
  6 +import cn.iocoder.yudao.module.product.dal.mysql.comment.ProductCommentMapper;
  7 +import org.junit.jupiter.api.Test;
  8 +import org.springframework.context.annotation.Import;
  9 +
  10 +import javax.annotation.Resource;
  11 +
  12 +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
  13 +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
  14 +
  15 +/**
  16 + * {@link ProductCommentServiceImpl} 的单元测试类
  17 + *
  18 + * @author wangzhs
  19 + */
  20 +@Import(ProductCommentServiceImpl.class)
  21 +public class ProductCommentServiceImplTest extends BaseDbUnitTest {
  22 +
  23 + @Resource
  24 + private ProductCommentMapper productCommentMapper;
  25 +
  26 + @Test
  27 + public void testCreateCommentAndGet_success() {
  28 + // mock 测试
  29 + ProductCommentDO productComment = randomPojo(ProductCommentDO.class);
  30 + productCommentMapper.insert(productComment);
  31 +
  32 + // 断言
  33 + // 校验记录的属性是否正确
  34 + ProductCommentDO comment = productCommentMapper.selectById(productComment.getId());
  35 + assertPojoEquals(productComment, comment);
  36 + }
  37 +
  38 +
  39 +}
... ...
yudao-module-mall/yudao-module-product-biz/src/test/resources/sql/clean.sql
... ... @@ -2,3 +2,4 @@ DELETE FROM &quot;product_sku&quot;;
2 2 DELETE FROM "product_spu";
3 3 DELETE FROM "product_brand";
4 4 DELETE FROM "product_category";
  5 +DELETE FROM "product_comment";
... ...
yudao-module-mall/yudao-module-product-biz/src/test/resources/sql/create_tables.sql
... ... @@ -82,3 +82,35 @@ CREATE TABLE IF NOT EXISTS `product_brand` (
82 82 `deleted` bit(1) NOT NULL DEFAULT 0 COMMENT '是否删除',
83 83 PRIMARY KEY (`id`)
84 84 ) COMMENT '商品品牌';
  85 +
  86 +CREATE TABLE IF NOT EXISTS `product_comment` (
  87 + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '评价编号',
  88 + `user_id` bigint NOT NULL COMMENT ' 评价ID 用户编号',
  89 + `user_nickname` varchar(128) NOT NULL COMMENT '评价人名称',
  90 + `user_avatar` varchar(255) NOT NULL COMMENT '评价人头像',
  91 + `anonymous` bit(1) NOT NULL DEFAULT 0 COMMENT '是否匿名 0:不匿名 1:匿名',
  92 + `order_id` bigint NOT NULL COMMENT '交易订单编号',
  93 + `order_item_id` bigint NOT NULL COMMENT '交易订单项编号',
  94 + `spu_id` bigint NOT NULL COMMENT '商品SPU编号',
  95 + `sku_id` bigint NOT NULL COMMENT '商品SKU编号',
  96 + `visible` bit(1) NOT NULL DEFAULT 1 COMMENT '是否可见 1:显示 0:隐藏',
  97 + `scores` int NOT NULL COMMENT '评分星级 1-5分',
  98 + `description_scores` int NOT NULL COMMENT '描述星级 1-5分',
  99 + `benefit_scores` int NOT NULL COMMENT '服务星级 1-5分',
  100 + `delivery_scores` int NOT NULL COMMENT '配送星级 1-5分',
  101 + `content` varchar(2000) NOT NULL COMMENT '评论内容',
  102 + `pic_urls` varchar(1024) DEFAULT '' COMMENT '评论图片地址数组,以逗号分隔最多上传9张',
  103 + `replied` bit(1) NOT NULL DEFAULT 0 COMMENT '商家是否回复 1:回复 0:未回复',
  104 + `reply_user_id` bigint COMMENT '回复管理员编号',
  105 + `reply_content` varchar(2000) COMMENT '商家回复内容',
  106 + `reply_time` datetime COMMENT '商家回复时间',
  107 + `additional_content` varchar(2000) COMMENT '追加评价内容',
  108 + `additional_pic_urls` varchar(1024) COMMENT '追评评价图片地址数组,以逗号分隔最多上传9张',
  109 + `additional_create_time` datetime COMMENT '追加评价时间',
  110 + `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  111 + `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  112 + `creator` varchar DEFAULT NULL COMMENT '创建人',
  113 + `updater` varchar DEFAULT NULL COMMENT '更新人',
  114 + `deleted` bit(1) NOT NULL DEFAULT 0 COMMENT '是否删除',
  115 + PRIMARY KEY (`id`)
  116 +) COMMENT '商品评价';
85 117 \ No newline at end of file
... ...