mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-08-15 18:51:54 +08:00
code review:商品评价哈
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package cn.iocoder.yudao.module.product.api.comment;
|
||||
|
||||
import cn.iocoder.yudao.module.product.api.comment.dto.CommentCreateReqDTO;
|
||||
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;
|
||||
@@ -17,12 +17,14 @@ import javax.annotation.Resource;
|
||||
@Service
|
||||
@Validated
|
||||
public class ProductCommentApiImpl implements ProductCommentApi {
|
||||
|
||||
@Resource
|
||||
private ProductCommentService productCommentService;
|
||||
|
||||
@Override
|
||||
public Long createComment(CommentCreateReqDTO createReqDTO, Long orderId) {
|
||||
public Long createComment(ProductCommentCreateReqDTO createReqDTO, Long orderId) {
|
||||
ProductCommentDO commentDO = ProductCommentConvert.INSTANCE.convert(createReqDTO, orderId);
|
||||
return productCommentService.createComment(commentDO);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -30,15 +30,15 @@ public class ProductCommentBaseVO {
|
||||
@NotNull(message = "商品 SKU 编号不能为空")
|
||||
private Long skuId;
|
||||
|
||||
@Schema(description = "评分星级 1-5分", required = true, example = "5")
|
||||
@Schema(description = "评分星级 1-5 分", required = true, example = "5")
|
||||
@NotNull(message = "评分星级不能为空")
|
||||
private Integer scores;
|
||||
|
||||
@Schema(description = "描述星级 1-5分", required = true, example = "5")
|
||||
@Schema(description = "描述星级 1-5 分", required = true, example = "5")
|
||||
@NotNull(message = "描述星级不能为空")
|
||||
private Integer descriptionScores;
|
||||
|
||||
@Schema(description = "服务星级 1-5分", required = true, example = "5")
|
||||
@Schema(description = "服务星级 1-5 分", required = true, example = "5")
|
||||
@NotNull(message = "服务星级分不能为空")
|
||||
private Integer benefitScores;
|
||||
|
||||
@@ -46,8 +46,8 @@ public class ProductCommentBaseVO {
|
||||
@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张")
|
||||
@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<String> picUrls;
|
||||
|
||||
}
|
||||
|
@@ -13,6 +13,7 @@ import javax.validation.constraints.NotNull;
|
||||
@ToString(callSuper = true)
|
||||
public class ProductCommentCreateReqVO extends ProductCommentBaseVO {
|
||||
|
||||
// TODO @puhui999:是不是也放到父类里?
|
||||
@Schema(description = "评价人", required = true, example = "16868")
|
||||
@NotNull(message = "评价人不能为空")
|
||||
private Long userId;
|
||||
|
@@ -31,7 +31,7 @@ public class ProductCommentPageReqVO extends PageParam {
|
||||
@Schema(description = "商品SPU名称", example = "感冒药")
|
||||
private String spuName;
|
||||
|
||||
@Schema(description = "评分星级 1-5分", example = "5")
|
||||
@Schema(description = "评分星级 1-5 分", example = "5")
|
||||
@InEnum(ProductCommentScoresEnum.class)
|
||||
private Integer scores;
|
||||
|
||||
|
@@ -16,7 +16,7 @@ public class ProductCommentRespVO extends ProductCommentBaseVO {
|
||||
@Schema(description = "订单项编号", required = true, example = "24965")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "是否匿名:[false:不匿名 true:匿名]", required = true, example = "false")
|
||||
@Schema(description = "是否匿名", required = true, example = "false")
|
||||
private Boolean anonymous;
|
||||
|
||||
@Schema(description = "交易订单编号", required = true, example = "24428")
|
||||
|
@@ -36,6 +36,7 @@ public class AppProductCommentController {
|
||||
@Resource
|
||||
private ProductCommentService productCommentService;
|
||||
|
||||
// TODO @puhui999:可以实现下
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获得最近的 n 条商品评价")
|
||||
@Parameters({
|
||||
@@ -44,7 +45,6 @@ public class AppProductCommentController {
|
||||
})
|
||||
public CommonResult<List<AppProductCommentRespVO>> getCommentList(@RequestParam("spuId") Long spuId,
|
||||
@RequestParam(value = "count", defaultValue = "10") Integer count) {
|
||||
|
||||
List<AppProductPropertyValueDetailRespVO> list = new ArrayList<>();
|
||||
|
||||
AppProductPropertyValueDetailRespVO item1 = new AppProductPropertyValueDetailRespVO();
|
||||
@@ -101,6 +101,7 @@ public class AppProductCommentController {
|
||||
return success(productCommentService.getCommentPage(pageVO, Boolean.TRUE));
|
||||
}
|
||||
|
||||
// TODO @puhui:get-statistics;方法改成 getCommentStatistics;getCommentPageTabsCount 也改掉哈
|
||||
@GetMapping("/getCommentStatistics")
|
||||
@Operation(summary = "获得商品的评价统计")
|
||||
public CommonResult<AppCommentStatisticsRespVO> getCommentPage(@Valid @RequestParam("spuId") Long spuId) {
|
||||
|
@@ -8,11 +8,6 @@ import lombok.ToString;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 用户 APP - 商品评价分页 Request VO
|
||||
*
|
||||
* @author HUIHUI
|
||||
*/
|
||||
@Schema(description = "用户APP - 商品评价分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@@ -23,12 +18,10 @@ public class AppCommentPageReqVO extends PageParam {
|
||||
* 好评
|
||||
*/
|
||||
public static final Integer GOOD_COMMENT = 1;
|
||||
|
||||
/**
|
||||
* 中评
|
||||
*/
|
||||
public static final Integer MEDIOCRE_COMMENT = 2;
|
||||
|
||||
/**
|
||||
* 差评
|
||||
*/
|
||||
|
@@ -4,11 +4,6 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* APP 商品评价页评论分类数统计 Response VO
|
||||
*
|
||||
* @author HUIHUI
|
||||
*/
|
||||
@Schema(description = "APP - 商品评价页评论分类数统计 Response VO")
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
|
@@ -8,11 +8,6 @@ import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户APP - 商品评价创建 Request VO
|
||||
*
|
||||
* @author HUIHUI
|
||||
*/
|
||||
@Schema(description = "用户APP - 商品评价创建 Request VO")
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@@ -26,36 +21,36 @@ public class AppProductCommentCreateReqVO {
|
||||
@NotNull(message = "交易订单项编号不能为空")
|
||||
private Long orderItemId;
|
||||
|
||||
@Schema(description = "商品SPU编号", required = true, example = "91192")
|
||||
@Schema(description = "商品 SPU 编号", required = true, example = "91192")
|
||||
@NotNull(message = "商品SPU编号不能为空")
|
||||
private Long spuId;
|
||||
|
||||
@Schema(description = "商品SPU名称", required = true, example = "清凉丝滑小短袖")
|
||||
@Schema(description = "商品 SPU 名称", required = true, example = "清凉丝滑小短袖")
|
||||
@NotNull(message = "商品SPU名称不能为空")
|
||||
private String spuName;
|
||||
|
||||
@Schema(description = "商品SKU编号", required = true, example = "81192")
|
||||
@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分不能为空")
|
||||
@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分不能为空")
|
||||
@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分不能为空")
|
||||
@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张")
|
||||
@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<String> picUrls;
|
||||
|
||||
}
|
||||
|
@@ -60,7 +60,7 @@ public class AppProductCommentRespVO {
|
||||
@Schema(description = "追加评价内容", example = "穿了很久都很丝滑诶")
|
||||
private String additionalContent;
|
||||
|
||||
@Schema(description = "追评评价图片地址数组,以逗号分隔最多上传9张", example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xxx.png]")
|
||||
@Schema(description = "追评评价图片地址数组,以逗号分隔最多上传 9 张", example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xxx.png]")
|
||||
private List<String> additionalPicUrls;
|
||||
|
||||
@Schema(description = "追加评价时间")
|
||||
@@ -86,24 +86,24 @@ public class AppProductCommentRespVO {
|
||||
@Schema(description = "商品 SKU 属性", required = true)
|
||||
private List<AppProductPropertyValueDetailRespVO> skuProperties;
|
||||
|
||||
@Schema(description = "评分星级 1-5分", required = true, example = "5")
|
||||
@NotNull(message = "评分星级 1-5分不能为空")
|
||||
@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分不能为空")
|
||||
@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分不能为空")
|
||||
@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张")
|
||||
@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<String> picUrls;
|
||||
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package cn.iocoder.yudao.module.product.convert.comment;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.product.api.comment.dto.CommentCreateReqDTO;
|
||||
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;
|
||||
import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO;
|
||||
@@ -49,7 +49,7 @@ public interface ProductCommentConvert {
|
||||
*
|
||||
* @param descriptionScores 描述星级
|
||||
* @param benefitScores 服务星级
|
||||
* @return {@link Integer}
|
||||
* @return 综合评分
|
||||
*/
|
||||
@Named("convertScores")
|
||||
default Integer convertScores(Integer descriptionScores, Integer benefitScores) {
|
||||
@@ -61,7 +61,7 @@ public interface ProductCommentConvert {
|
||||
|
||||
@Mapping(target = "orderId", source = "orderId")
|
||||
@Mapping(target = "scores", expression = "java(convertScores(createReqDTO.getDescriptionScores(), createReqDTO.getBenefitScores()))")
|
||||
ProductCommentDO convert(CommentCreateReqDTO createReqDTO, Long orderId);
|
||||
ProductCommentDO convert(ProductCommentCreateReqDTO createReqDTO, Long orderId);
|
||||
|
||||
@Mapping(target = "userId", constant = "0L")
|
||||
@Mapping(target = "orderId", constant = "0L")
|
||||
|
@@ -97,7 +97,7 @@ public class ProductCommentDO extends BaseDO {
|
||||
/**
|
||||
* 评分星级
|
||||
*
|
||||
* 1-5分
|
||||
* 1-5 分
|
||||
*/
|
||||
private Integer scores;
|
||||
/**
|
||||
|
@@ -25,6 +25,7 @@ public interface ProductCommentMapper extends BaseMapperX<ProductCommentDO> {
|
||||
}
|
||||
|
||||
// TODO 芋艿:在看看这块
|
||||
// TODO @puhui999:直接使用 scores 来算好评、中评、差评
|
||||
static void appendTabQuery(LambdaQueryWrapperX<ProductCommentDO> queryWrapper, Integer type) {
|
||||
// 构建好评查询语句:好评计算 (商品评分星级+服务评分星级) >= 8
|
||||
if (ObjectUtil.equal(type, AppCommentPageReqVO.GOOD_COMMENT)) {
|
||||
|
@@ -54,7 +54,8 @@ public interface ProductCommentService {
|
||||
PageResult<AppProductCommentRespVO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible);
|
||||
|
||||
/**
|
||||
* 创建商品评论 后台管理员创建评论使用
|
||||
* 创建商品评论
|
||||
* 后台管理员创建评论使用
|
||||
*
|
||||
* @param createReqVO 商品评价创建 Request VO 对象
|
||||
*/
|
||||
|
@@ -86,6 +86,7 @@ public class ProductCommentServiceImpl implements ProductCommentService {
|
||||
@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);
|
||||
@@ -104,8 +105,6 @@ public class ProductCommentServiceImpl implements ProductCommentService {
|
||||
return commentDO.getId();
|
||||
}
|
||||
|
||||
// TODO 只有创建和更新诶 要不要删除接口
|
||||
|
||||
private void validateComment(Long spuId, Long userId, Long orderId) {
|
||||
ProductSpuDO spu = productSpuService.getSpu(spuId);
|
||||
if (null == spu) {
|
||||
@@ -144,6 +143,7 @@ public class ProductCommentServiceImpl implements ProductCommentService {
|
||||
public PageResult<AppProductCommentRespVO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible) {
|
||||
PageResult<AppProductCommentRespVO> result = 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());
|
||||
|
@@ -126,6 +126,7 @@ CREATE TABLE IF NOT EXISTS `product_property_value` (
|
||||
PRIMARY KEY("id")
|
||||
) COMMENT '规格值';
|
||||
|
||||
-- TODO @puhui999:格式不太对哈
|
||||
CREATE TABLE IF NOT EXISTS `product_comment`
|
||||
(
|
||||
`id`
|
||||
@@ -166,7 +167,7 @@ CREATE TABLE IF NOT EXISTS `product_comment`
|
||||
(
|
||||
1
|
||||
) DEFAULT NULL COMMENT '是否可见true:显示false:隐藏',
|
||||
`scores` tinyint DEFAULT NULL COMMENT '评分星级1-5分',
|
||||
`scores` tinyint DEFAULT NULL COMMENT '评分星级1-5 分',
|
||||
`description_scores` tinyint DEFAULT NULL COMMENT '描述星级1-5 星',
|
||||
`benefit_scores` tinyint DEFAULT NULL COMMENT '服务星级1-5 星',
|
||||
`content` varchar
|
||||
|
Reference in New Issue
Block a user