fix:完善商品评论 review 提到的问题

This commit is contained in:
puhui999 2023-06-20 18:12:39 +08:00
parent 8dfb298376
commit 700d95a43d
28 changed files with 310 additions and 296 deletions

View File

@ -9,14 +9,12 @@ import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDT
*/
public interface ProductCommentApi {
// TODO @puhuiLong orderId 放到 createReqDTO 里噶
/**
* 创建评论
*
* @param createReqDTO 评论参数
* @param orderId 订单 id
* @return 返回评论创建后的 id
*/
Long createComment(ProductCommentCreateReqDTO createReqDTO, Long orderId);
Long createComment(ProductCommentCreateReqDTO createReqDTO);
}

View File

@ -16,21 +16,15 @@ public class ProductCommentCreateReqDTO {
* 商品 SKU 编号
*/
private Long skuId;
/**
* 订单编号
*/
private Long orderId;
/**
* 交易订单项编号
*/
private Long orderItemId;
// TODO @huihuispuIdspuName 去查询哇通过 skuId
/**
* 商品 SPU 编号
*/
private Long spuId;
/**
* 商品 SPU 名称
*/
private String spuName;
/**
* 评分星级 1-5
*/
@ -60,14 +54,6 @@ public class ProductCommentCreateReqDTO {
* 评价人
*/
private Long userId;
// TODO @puhui999是不是 userNicknameuserAvatar 去掉通过 userId 查询
/**
* 评价人名称
*/
private String userNickname;
/**
* 评价人头像
*/
private String userAvatar;
}

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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 @puhuiget-statistics方法改成 getCommentStatisticsgetCommentPageTabsCount 也改掉哈
@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));
}
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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);
}

View File

@ -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)
);
}
}

View File

@ -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);
}

View File

@ -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

View File

@ -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());

View File

@ -2,7 +2,11 @@ package cn.iocoder.yudao.module.promotion.convert.seckill.seckillactivity;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.*;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityCreateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityDetailRespVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityRespVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityUpdateReqVO;
import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.product.SeckillProductCreateReqVO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillActivityDO;
import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.seckillactivity.SeckillProductDO;
import org.mapstruct.Mapper;
@ -20,7 +24,7 @@ public interface SeckillActivityConvert {
SeckillActivityConvert INSTANCE = Mappers.getMapper(SeckillActivityConvert.class);
SeckillProductDO convert(SeckillActivityBaseVO.Product product);
SeckillProductDO convert(SeckillProductCreateReqVO product);
SeckillActivityDO convert(SeckillActivityCreateReqVO bean);
@ -42,12 +46,12 @@ public interface SeckillActivityConvert {
* @param productVO 前端传入的商品
* @return 是否匹配
*/
default boolean isEquals(SeckillProductDO productDO, SeckillActivityBaseVO.Product productVO) {
default boolean isEquals(SeckillProductDO productDO, SeckillProductCreateReqVO productVO) {
return ObjectUtil.equals(productDO.getSpuId(), productVO.getSpuId())
&& ObjectUtil.equals(productDO.getSkuId(), productVO.getSkuId())
&& ObjectUtil.equals(productDO.getSeckillPrice(), productVO.getSeckillPrice());
//&& ObjectUtil.equals(productDO.getQuota(), productVO.getQuota())
//&& ObjectUtil.equals(productDO.getLimitCount(), productVO.getLimitCount());
//&& ObjectUtil.equals(productDO.getQuota(), productVO.getQuota())
//&& ObjectUtil.equals(productDO.getLimitCount(), productVO.getLimitCount());
}
/**

View File

@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
import cn.iocoder.yudao.module.pay.api.notify.dto.PayOrderNotifyReqDTO;
import cn.iocoder.yudao.module.product.api.comment.ProductCommentApi;
import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO;
import cn.iocoder.yudao.module.product.api.property.ProductPropertyValueApi;
import cn.iocoder.yudao.module.product.api.property.dto.ProductPropertyValueDetailRespDTO;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.*;
@ -35,6 +36,7 @@ import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.
import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_ITEM_NOT_FOUND;
import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_NOT_FOUND;
@Tag(name = "用户 App - 交易订单")
@RestController
@ -138,16 +140,20 @@ public class AppTradeOrderController {
@PostMapping("/item/create-comment")
@Operation(summary = "创建交易订单项的评价")
public CommonResult<Long> createOrderItemComment(@RequestBody AppTradeOrderItemCommentCreateReqVO createReqVO) {
// 校验订单项订单项存在订单就存在
// TODO @puhui999要去查询订单是不是自己的不然别人模拟请求哈
TradeOrderItemDO item = tradeOrderService.getOrderItem(createReqVO.getUserId(), createReqVO.getOrderItemId());
if (item == null) {
Long loginUserId = getLoginUserId();
// 先通过订单项 ID 查询订单项是否存在
TradeOrderItemDO orderItemDO = tradeOrderService.getOrderItemByIdAndUserId(createReqVO.getOrderItemId(), loginUserId);
if (orderItemDO == null) {
throw exception(ORDER_ITEM_NOT_FOUND);
}
// 校验订单
TradeOrderDO orderDO = tradeOrderService.getOrderByIdAndUserId(orderItemDO.getOrderId(), loginUserId);
if (orderDO == null) {
throw exception(ORDER_NOT_FOUND);
}
return success(productCommentApi.createComment(TradeOrderConvert.INSTANCE.convert04(createReqVO), item.getOrderId()));
ProductCommentCreateReqDTO productCommentCreateReqDTO = TradeOrderConvert.INSTANCE.convert04(createReqVO, orderItemDO);
return success(productCommentApi.createComment(productCommentCreateReqDTO));
}
// TODO 合并代码后发现只有商家回复功能 用户追评不要了吗不要了哈
}

View File

@ -21,7 +21,7 @@ public class AppTradeOrderSettlementReqVO {
@Deprecated // TODO 芋艿后续干掉这个字段对于前端不需要关注这个
private Integer type;
@Schema(description = "商品项数组", required = true)
@Schema(description = "商品项数组", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "商品不能为空")
private List<Item> items;

View File

@ -12,13 +12,13 @@ import java.util.List;
@Data
public class AppTradeOrderSettlementRespVO {
@Schema(description = "购物项数组", required = true)
@Schema(description = "购物项数组", requiredMode = Schema.RequiredMode.REQUIRED)
private List<Item> items;
@Schema(description = "费用", required = true)
@Schema(description = "费用", requiredMode = Schema.RequiredMode.REQUIRED)
private Price price;
@Schema(description = "收件地址", required = true)
@Schema(description = "收件地址", requiredMode = Schema.RequiredMode.REQUIRED)
private Address address;
@Schema(description = "购物项")
@ -27,29 +27,29 @@ public class AppTradeOrderSettlementRespVO {
// ========== SPU 信息 ==========
@Schema(description = "SPU 编号", required = true, example = "2048")
@Schema(description = "SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2048")
private Long spuId;
@Schema(description = "SPU 名字", required = true, example = "Apple iPhone 12")
@Schema(description = "SPU 名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "Apple iPhone 12")
private String spuName;
// ========== SKU 信息 ==========
@Schema(description = "SKU 编号", required = true, example = "1024")
@Schema(description = "SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer skuId;
@Schema(description = "价格,单位:分", required = true, example = "100")
@Schema(description = "价格,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
private Integer price;
@Schema(description = "图片地址", required = true, example = "https://www.iocoder.cn/1.png")
@Schema(description = "图片地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png")
private String picUrl;
@Schema(description = "属性数组", required = true, example = "100")
@Schema(description = "属性数组", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
private List<AppProductPropertyValueDetailRespVO> properties;
// ========== 购物车信息 ==========
@Schema(description = "购物车编号", required = true, example = "100")
@Schema(description = "购物车编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
private Long cartId;
@Schema(description = "购买数量", required = true, example = "1")
@Schema(description = "购买数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer count;
}
@ -60,19 +60,19 @@ public class AppTradeOrderSettlementRespVO {
@AllArgsConstructor
public static class Price {
@Schema(description = "商品原价(总),单位:分", required = true, example = "500")
@Schema(description = "商品原价(总),单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "500")
private Integer totalPrice;
@Schema(description = "运费金额,单位:分", required = true, example = "50")
@Schema(description = "运费金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "50")
private Integer deliveryPrice;
@Schema(description = "优惠劵减免金额,单位:分", required = true, example = "100")
@Schema(description = "优惠劵减免金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
private Integer couponPrice;
@Schema(description = "积分抵扣的金额,单位:分", required = true, example = "50")
@Schema(description = "积分抵扣的金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "50")
private Integer pointPrice;
@Schema(description = "实际支付金额(总),单位:分", required = true, example = "450")
@Schema(description = "实际支付金额(总),单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "450")
private Integer payPrice;
}
@ -81,34 +81,34 @@ public class AppTradeOrderSettlementRespVO {
@Data
public static class Address {
@Schema(description = "编号", required = true, example = "1")
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long id;
@Schema(description = "收件人名称", required = true, example = "小王")
@Schema(description = "收件人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小王")
private String name;
@Schema(description = "手机号", required = true, example = "15601691300")
@Schema(description = "手机号", requiredMode = Schema.RequiredMode.REQUIRED, example = "15601691300")
private String mobile;
@Schema(description = "省份编号", required = true, example = "1")
@Schema(description = "省份编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer provinceId;
@Schema(description = "省份名字", required = true, example = "北京")
@Schema(description = "省份名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "北京")
private String provinceName;
@Schema(description = "城市编号", required = true, example = "1")
@Schema(description = "城市编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer cityId;
@Schema(description = "城市名字", required = true, example = "北京")
@Schema(description = "城市名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "北京")
private String cityName;
@Schema(description = "地区编号", required = true, example = "1")
@Schema(description = "地区编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer districtId;
@Schema(description = "地区名字", required = true, example = "朝阳区")
@Schema(description = "地区名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "朝阳区")
private String districtName;
@Schema(description = "详细地址", required = true, example = "望京悠乐汇 A 座")
@Schema(description = "详细地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "望京悠乐汇 A 座")
private String detailAddress;
@Schema(description = "是否默认收件地址", required = true, example = "true")
@Schema(description = "是否默认收件地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
private Boolean defaulted;
}

View File

@ -11,59 +11,33 @@ import java.util.List;
@Data
public class AppTradeOrderItemCommentCreateReqVO {
@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;
// TODO @puhuispuIdspuNameskuId 直接查询出来
@Schema(description = "商品SPU编号", required = true, example = "29502")
@NotNull(message = "商品SPU编号不能为空")
private Long spuId;
@Schema(description = "商品SPU名称", required = true, example = "丝滑飘逸小短裙")
@NotNull(message = "商品SPU名称不能为空")
private String spuName;
@Schema(description = "商品SKU编号", required = true, example = "3082")
@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/xx.png]")
@Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/xx.png, https://www.iocoder.cn/xx.png]")
@Size(max = 9, message = "评论图片地址数组长度不能超过 9 张")
private List<String> picUrls;
@Schema(description = "评价人名称", required = true, example = "小姑凉")
@NotNull(message = "评价人名称不能为空")
private String userNickname;
// TODO @puhuiuserAvataruserAvataruserId 直接查询出来
@Schema(description = "评价人头像", required = true, example = "https://www.iocoder.cn/xx.png")
@NotNull(message = "评价人头像不能为空")
private String userAvatar;
@Schema(description = "评价人", required = true, example = "16868")
@NotNull(message = "评价人不能为空")
private Long userId;
}

View File

@ -10,15 +10,15 @@ import java.util.List;
@Data
public class AppTradeOrderItemRespVO {
@Schema(description = "编号", required = true, example = "1")
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long id;
@Schema(description = "商品 SPU 编号", required = true, example = "1")
@Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long spuId;
@Schema(description = "商品 SPU 名称", required = true, example = "芋道源码")
@Schema(description = "商品 SPU 名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道源码")
private String spuName;
@Schema(description = "商品 SKU 编号", required = true, example = "1")
@Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long skuId;
/**
@ -26,18 +26,18 @@ public class AppTradeOrderItemRespVO {
*/
private List<AppProductPropertyValueDetailRespVO> properties;
@Schema(description = "商品图片", required = true, example = "https://www.iocoder.cn/1.png")
@Schema(description = "商品图片", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/1.png")
private String picUrl;
@Schema(description = "购买数量", required = true, example = "1")
@Schema(description = "购买数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer count;
@Schema(description = "是否评价", required = true, example = "true")
@Schema(description = "是否评价", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
private Boolean commentStatus;
// ========== 价格 + 支付基本信息 ==========
@Schema(description = "商品原价(单)", required = true, example = "100")
@Schema(description = "商品原价(单)", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
private Integer price;
// ========== 营销基本信息 ==========
@ -46,7 +46,7 @@ public class AppTradeOrderItemRespVO {
// ========== 售后基本信息 ==========
@Schema(description = "售后状态", required = true, example = "1")
@Schema(description = "售后状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer afterSaleStatus;
}

View File

@ -259,7 +259,17 @@ public interface TradeOrderConvert {
AppTradeOrderItemRespVO convert03(TradeOrderItemDO bean);
ProductCommentCreateReqDTO convert04(AppTradeOrderItemCommentCreateReqVO createReqVO);
@Mapping(target = "skuId", source = "tradeOrderItemDO.skuId")
@Mapping(target = "orderId", source = "tradeOrderItemDO.orderId")
@Mapping(target = "orderItemId", source = "tradeOrderItemDO.id")
@Mapping(target = "scores", source = "createReqVO.scores")
@Mapping(target = "descriptionScores", source = "createReqVO.descriptionScores")
@Mapping(target = "benefitScores", source = "createReqVO.benefitScores")
@Mapping(target = "content", source = "createReqVO.content")
@Mapping(target = "picUrls", source = "createReqVO.picUrls")
@Mapping(target = "anonymous", source = "createReqVO.anonymous")
@Mapping(target = "userId", source = "tradeOrderItemDO.userId")
ProductCommentCreateReqDTO convert04(AppTradeOrderItemCommentCreateReqVO createReqVO, TradeOrderItemDO tradeOrderItemDO);
default TradePriceCalculateReqBO convert(Long userId, AppTradeOrderSettlementReqVO settlementReqVO,
List<TradeCartDO> cartList) {

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.trade.dal.mysql.order;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;
@ -24,4 +25,9 @@ public interface TradeOrderItemMapper extends BaseMapperX<TradeOrderItemDO> {
return selectList(TradeOrderItemDO::getOrderId, orderIds);
}
default TradeOrderItemDO selectOrderItemByIdAndUserId(Long orderItemId, Long loginUserId) {
return selectOne(new LambdaQueryWrapperX<TradeOrderItemDO>()
.eq(TradeOrderItemDO::getId, orderItemId)
.eq(TradeOrderItemDO::getUserId, loginUserId));
}
}

View File

@ -50,4 +50,10 @@ public interface TradeOrderMapper extends BaseMapperX<TradeOrderDO> {
.eqIfPresent(TradeOrderDO::getStatus, status)
.eqIfPresent(TradeOrderDO::getCommentStatus, commentStatus));
}
default TradeOrderDO selectOrderByIdAndUserId(Long orderId, Long loginUserId) {
return selectOne(new LambdaQueryWrapperX<TradeOrderDO>()
.eq(TradeOrderDO::getId, orderId)
.eq(TradeOrderDO::getUserId, loginUserId));
}
}

View File

@ -160,4 +160,21 @@ public interface TradeOrderService {
*/
List<TradeOrderItemDO> getOrderItemListByOrderId(Collection<Long> orderIds);
/**
* 得到订单项通过 订单项 id 和用户 id
*
* @param orderItemId 订单项 id
* @param loginUserId 登录用户 id
* @return 得到订单项
*/
TradeOrderItemDO getOrderItemByIdAndUserId(Long orderItemId, Long loginUserId);
/**
* 得到订单通过 id 用户 id
*
* @param orderId 订单 id
* @param loginUserId 登录用户 id
* @return 得到订单
*/
TradeOrderDO getOrderByIdAndUserId(Long orderId, Long loginUserId);
}

View File

@ -565,6 +565,16 @@ public class TradeOrderServiceImpl implements TradeOrderService {
return tradeOrderItemMapper.selectListByOrderId(orderIds);
}
@Override
public TradeOrderItemDO getOrderItemByIdAndUserId(Long orderItemId, Long loginUserId) {
return tradeOrderItemMapper.selectOrderItemByIdAndUserId(orderItemId, loginUserId);
}
@Override
public TradeOrderDO getOrderByIdAndUserId(Long orderId, Long loginUserId) {
return tradeOrderMapper.selectOrderByIdAndUserId(orderId, loginUserId);
}
/**
* 判断指定订单的所有订单项是不是都售后成功
*