mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 07:11:52 +08:00
✨ MALL:简化商评论的 VO 转化,去除无用的接口
This commit is contained in:
parent
ed34b18d82
commit
50f7be9976
@ -2,19 +2,18 @@ package cn.iocoder.yudao.module.product.controller.admin.comment;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.comment.vo.*;
|
||||
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 io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||
|
||||
@ -32,7 +31,7 @@ public class ProductCommentController {
|
||||
@PreAuthorize("@ss.hasPermission('product:comment:query')")
|
||||
public CommonResult<PageResult<ProductCommentRespVO>> getCommentPage(@Valid ProductCommentPageReqVO pageVO) {
|
||||
PageResult<ProductCommentDO> pageResult = productCommentService.getCommentPage(pageVO);
|
||||
return success(ProductCommentConvert.INSTANCE.convertPage(pageResult));
|
||||
return success(BeanUtils.toBean(pageResult, ProductCommentRespVO.class));
|
||||
}
|
||||
|
||||
@PutMapping("/update-visible")
|
||||
|
@ -1,47 +0,0 @@
|
||||
package cn.iocoder.yudao.module.product.controller.admin.comment.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ProductCommentBaseVO {
|
||||
|
||||
@Schema(description = "评价人", requiredMode = Schema.RequiredMode.REQUIRED, example = "16868")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "评价订单项", requiredMode = Schema.RequiredMode.REQUIRED, example = "19292")
|
||||
private Long orderItemId;
|
||||
|
||||
@Schema(description = "评价人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小姑凉")
|
||||
@NotNull(message = "评价人名称不能为空")
|
||||
private String userNickname;
|
||||
|
||||
@Schema(description = "评价人头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png")
|
||||
@NotNull(message = "评价人头像不能为空")
|
||||
private String userAvatar;
|
||||
|
||||
@Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "商品 SKU 编号不能为空")
|
||||
private Long skuId;
|
||||
|
||||
@Schema(description = "描述星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
|
||||
@NotNull(message = "描述星级不能为空")
|
||||
private Integer descriptionScores;
|
||||
|
||||
@Schema(description = "服务星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
|
||||
@NotNull(message = "服务星级分不能为空")
|
||||
private Integer benefitScores;
|
||||
|
||||
@Schema(description = "评论内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "穿起来非常丝滑凉快")
|
||||
@NotNull(message = "评论内容不能为空")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/xx.png]")
|
||||
@Size(max = 9, message = "评论图片地址数组长度不能超过 9 张")
|
||||
private List<String> picUrls;
|
||||
|
||||
}
|
@ -1,14 +1,49 @@
|
||||
package cn.iocoder.yudao.module.product.controller.admin.comment.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "管理后台 - 商品评价创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ProductCommentCreateReqVO extends ProductCommentBaseVO {
|
||||
public class ProductCommentCreateReqVO {
|
||||
|
||||
@Schema(description = "评价人", requiredMode = Schema.RequiredMode.REQUIRED, example = "16868")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "评价订单项", requiredMode = Schema.RequiredMode.REQUIRED, example = "19292")
|
||||
private Long orderItemId;
|
||||
|
||||
@Schema(description = "评价人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小姑凉")
|
||||
@NotNull(message = "评价人名称不能为空")
|
||||
private String userNickname;
|
||||
|
||||
@Schema(description = "评价人头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png")
|
||||
@NotNull(message = "评价人头像不能为空")
|
||||
private String userAvatar;
|
||||
|
||||
@Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotNull(message = "商品 SKU 编号不能为空")
|
||||
private Long skuId;
|
||||
|
||||
@Schema(description = "描述星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
|
||||
@NotNull(message = "描述星级不能为空")
|
||||
private Integer descriptionScores;
|
||||
|
||||
@Schema(description = "服务星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
|
||||
@NotNull(message = "服务星级分不能为空")
|
||||
private Integer benefitScores;
|
||||
|
||||
@Schema(description = "评论内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "穿起来非常丝滑凉快")
|
||||
@NotNull(message = "评论内容不能为空")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", requiredMode = Schema.RequiredMode.REQUIRED,
|
||||
example = "[https://www.iocoder.cn/xx.png]")
|
||||
@Size(max = 9, message = "评论图片地址数组长度不能超过 9 张")
|
||||
private List<String> picUrls;
|
||||
|
||||
}
|
||||
|
@ -2,32 +2,68 @@ package cn.iocoder.yudao.module.product.controller.admin.comment.vo;
|
||||
|
||||
import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSkuSaveReqVO;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "管理后台 - 商品评价 Response VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ProductCommentRespVO extends ProductCommentBaseVO {
|
||||
public class ProductCommentRespVO {
|
||||
|
||||
@Schema(description = "订单项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24965")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "评价人", requiredMode = Schema.RequiredMode.REQUIRED, example = "16868")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "评价人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小姑凉")
|
||||
private String userNickname;
|
||||
|
||||
@Schema(description = "评价人头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xx.png")
|
||||
private String userAvatar;
|
||||
@Schema(description = "是否匿名", requiredMode = Schema.RequiredMode.REQUIRED, example = "false")
|
||||
private Boolean anonymous;
|
||||
|
||||
@Schema(description = "交易订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24428")
|
||||
private Long orderId;
|
||||
|
||||
@Schema(description = "评价订单项", requiredMode = Schema.RequiredMode.REQUIRED, example = "19292")
|
||||
private Long orderItemId;
|
||||
|
||||
@Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉丝滑透气小短袖")
|
||||
private Long spuId;
|
||||
|
||||
@Schema(description = "商品 SKU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Long skuId;
|
||||
|
||||
@Schema(description = "商品 SPU 名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
|
||||
private String spuName;
|
||||
|
||||
@Schema(description = "商品 SKU 图片地址", example = "https://www.iocoder.cn/yudao.jpg")
|
||||
private String skuPicUrl;
|
||||
|
||||
@Schema(description = "商品 SKU 规格值数组")
|
||||
private List<ProductSkuSaveReqVO.Property> skuProperties;
|
||||
|
||||
@Schema(description = "是否可见", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private Boolean visible;
|
||||
|
||||
@Schema(description = "评分星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
|
||||
private Integer scores;
|
||||
|
||||
@Schema(description = "描述星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
|
||||
private Integer descriptionScores;
|
||||
|
||||
@Schema(description = "服务星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
|
||||
private Integer benefitScores;
|
||||
|
||||
@Schema(description = "评论内容", requiredMode = Schema.RequiredMode.REQUIRED, example = "穿起来非常丝滑凉快")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/xx.png]")
|
||||
private List<String> picUrls;
|
||||
|
||||
@Schema(description = "商家是否回复", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private Boolean replyStatus;
|
||||
|
||||
@ -43,21 +79,4 @@ public class ProductCommentRespVO extends ProductCommentBaseVO {
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "评分星级 1-5 分", requiredMode = Schema.RequiredMode.REQUIRED, example = "5")
|
||||
private Integer scores;
|
||||
|
||||
@Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "清凉丝滑透气小短袖")
|
||||
@NotNull(message = "商品 SPU 编号不能为空")
|
||||
private Long spuId;
|
||||
|
||||
@Schema(description = "商品 SPU 名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "赵六")
|
||||
@NotNull(message = "商品 SPU 名称不能为空")
|
||||
private String spuName;
|
||||
|
||||
@Schema(description = "商品 SKU 图片地址", example = "https://www.iocoder.cn/yudao.jpg")
|
||||
private String skuPicUrl;
|
||||
|
||||
@Schema(description = "商品 SKU 规格值数组")
|
||||
private List<ProductSkuSaveReqVO.Property> skuProperties;
|
||||
|
||||
}
|
||||
|
@ -3,31 +3,21 @@ package cn.iocoder.yudao.module.product.controller.app.comment;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
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.convert.comment.ProductCommentConvert;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
|
||||
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 jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
|
||||
@Tag(name = "用户 APP - 商品评价")
|
||||
@RestController
|
||||
@ -38,43 +28,22 @@ public class AppProductCommentController {
|
||||
@Resource
|
||||
private ProductCommentService productCommentService;
|
||||
|
||||
@Resource
|
||||
@Lazy
|
||||
private ProductSkuService productSkuService;
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获得最近的 n 条商品评价")
|
||||
@Parameters({
|
||||
@Parameter(name = "spuId", description = "商品 SPU 编号", required = true, example = "1024"),
|
||||
@Parameter(name = "count", description = "数量", required = true, example = "10")
|
||||
})
|
||||
public CommonResult<List<AppProductCommentRespVO>> getCommentList(
|
||||
@RequestParam("spuId") Long spuId,
|
||||
@RequestParam(value = "count", defaultValue = "10") Integer count) {
|
||||
return success(productCommentService.getCommentList(spuId, count));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得商品评价分页")
|
||||
public CommonResult<PageResult<AppProductCommentRespVO>> getCommentPage(@Valid AppCommentPageReqVO pageVO) {
|
||||
// 查询评论分页
|
||||
PageResult<ProductCommentDO> commentPageResult = productCommentService.getCommentPage(pageVO, Boolean.TRUE);
|
||||
if (CollUtil.isEmpty(commentPageResult.getList())) {
|
||||
return success(PageResult.empty(commentPageResult.getTotal()));
|
||||
PageResult<ProductCommentDO> pageResult = productCommentService.getCommentPage(pageVO, Boolean.TRUE);
|
||||
if (CollUtil.isEmpty(pageResult.getList())) {
|
||||
return success(PageResult.empty(pageResult.getTotal()));
|
||||
}
|
||||
|
||||
// 拼接返回
|
||||
Set<Long> skuIds = convertSet(commentPageResult.getList(), ProductCommentDO::getSkuId);
|
||||
PageResult<AppProductCommentRespVO> commentVOPageResult = ProductCommentConvert.INSTANCE.convertPage02(
|
||||
commentPageResult, productSkuService.getSkuList(skuIds));
|
||||
return success(commentVOPageResult);
|
||||
}
|
||||
|
||||
// TODO 芋艿:需要搞下
|
||||
@GetMapping("/statistics")
|
||||
@Operation(summary = "获得商品的评价统计")
|
||||
public CommonResult<AppCommentStatisticsRespVO> getCommentStatistics(@Valid @RequestParam("spuId") Long spuId) {
|
||||
return success(productCommentService.getCommentStatistics(spuId, Boolean.TRUE));
|
||||
pageResult.getList().forEach(item -> {
|
||||
if (Boolean.TRUE.equals(item.getAnonymous())) {
|
||||
item.setUserNickname(ProductCommentDO.NICKNAME_ANONYMOUS);
|
||||
}
|
||||
});
|
||||
return success(BeanUtils.toBean(pageResult, AppProductCommentRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,24 +0,0 @@
|
||||
package cn.iocoder.yudao.module.product.controller.app.comment.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
@Schema(description = "APP - 商品评价页评论分类数统计 Response VO")
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
public class AppCommentStatisticsRespVO {
|
||||
|
||||
@Schema(description = "好评数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
|
||||
private Long goodCount;
|
||||
|
||||
@Schema(description = "中评数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
|
||||
private Long mediocreCount;
|
||||
|
||||
@Schema(description = "差评数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15721")
|
||||
private Long negativeCount;
|
||||
|
||||
@Schema(description = "总平均分", requiredMode = Schema.RequiredMode.REQUIRED, example = "3.55")
|
||||
private Double scores;
|
||||
|
||||
}
|
@ -91,7 +91,8 @@ public class AppProductCommentRespVO {
|
||||
@NotNull(message = "评论内容不能为空")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", requiredMode = Schema.RequiredMode.REQUIRED, example = "[https://www.iocoder.cn/xx.png]")
|
||||
@Schema(description = "评论图片地址数组,以逗号分隔最多上传 9 张", requiredMode = Schema.RequiredMode.REQUIRED,
|
||||
example = "[https://www.iocoder.cn/xx.png]")
|
||||
@Size(max = 9, message = "评论图片地址数组长度不能超过 9 张")
|
||||
private List<String> picUrls;
|
||||
|
||||
|
@ -1,29 +1,17 @@
|
||||
package cn.iocoder.yudao.module.product.convert.comment;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
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;
|
||||
import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO;
|
||||
import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO;
|
||||
import cn.iocoder.yudao.module.product.controller.app.property.vo.value.AppProductPropertyValueDetailRespVO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Named;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
|
||||
|
||||
/**
|
||||
* 商品评价 Convert
|
||||
@ -35,48 +23,35 @@ public interface ProductCommentConvert {
|
||||
|
||||
ProductCommentConvert INSTANCE = Mappers.getMapper(ProductCommentConvert.class);
|
||||
|
||||
ProductCommentRespVO convert(ProductCommentDO bean);
|
||||
|
||||
@Mapping(target = "scores", expression = "java(calculateOverallScore(goodCount, mediocreCount, negativeCount))")
|
||||
AppCommentStatisticsRespVO convert(Long goodCount, Long mediocreCount, Long negativeCount);
|
||||
|
||||
@Named("calculateOverallScore")
|
||||
default double calculateOverallScore(long goodCount, long mediocreCount, long negativeCount) {
|
||||
return (goodCount * 5 + mediocreCount * 3 + negativeCount) / (double) (goodCount + mediocreCount + negativeCount);
|
||||
default ProductCommentDO convert(ProductCommentCreateReqDTO createReqDTO,
|
||||
ProductSpuDO spu, ProductSkuDO sku, MemberUserRespDTO user) {
|
||||
ProductCommentDO comment = BeanUtils.toBean(createReqDTO, ProductCommentDO.class)
|
||||
.setScores(convertScores(createReqDTO.getDescriptionScores(), createReqDTO.getBenefitScores()));
|
||||
if (user != null) {
|
||||
comment.setUserId(user.getId()).setUserNickname(user.getNickname()).setUserAvatar(user.getAvatar());
|
||||
}
|
||||
if (spu != null) {
|
||||
comment.setSpuId(spu.getId()).setSpuName(spu.getName());
|
||||
}
|
||||
if (sku != null) {
|
||||
comment.setSkuPicUrl(sku.getPicUrl()).setSkuProperties(sku.getProperties());
|
||||
}
|
||||
return comment;
|
||||
}
|
||||
|
||||
List<ProductCommentRespVO> convertList(List<ProductCommentDO> list);
|
||||
|
||||
PageResult<ProductCommentRespVO> convertPage(PageResult<ProductCommentDO> page);
|
||||
|
||||
PageResult<AppProductCommentRespVO> convertPage01(PageResult<ProductCommentDO> pageResult);
|
||||
|
||||
default PageResult<AppProductCommentRespVO> convertPage02(PageResult<ProductCommentDO> pageResult,
|
||||
List<ProductSkuDO> skuList) {
|
||||
Map<Long, ProductSkuDO> skuMap = CollectionUtils.convertMap(skuList, ProductSkuDO::getId);
|
||||
PageResult<AppProductCommentRespVO> page = convertPage01(pageResult);
|
||||
page.getList().forEach(item -> {
|
||||
// 判断用户是否选择匿名
|
||||
if (ObjectUtil.equal(item.getAnonymous(), true)) {
|
||||
item.setUserNickname(ProductCommentDO.NICKNAME_ANONYMOUS);
|
||||
}
|
||||
// 设置 SKU 规格值
|
||||
findAndThen(skuMap, item.getSkuId(),
|
||||
sku -> item.setSkuProperties(convertList01(sku.getProperties())));
|
||||
});
|
||||
return page;
|
||||
default ProductCommentDO convert(ProductCommentCreateReqVO createReq, ProductSpuDO spu, ProductSkuDO sku) {
|
||||
ProductCommentDO comment = BeanUtils.toBean(createReq, ProductCommentDO.class)
|
||||
.setVisible(true).setUserId(0L).setAnonymous(false)
|
||||
.setScores(convertScores(createReq.getDescriptionScores(), createReq.getBenefitScores()));
|
||||
if (spu != null) {
|
||||
comment.setSpuId(spu.getId()).setSpuName(spu.getName());
|
||||
}
|
||||
if (sku != null) {
|
||||
comment.setSkuPicUrl(sku.getPicUrl()).setSkuProperties(sku.getProperties());
|
||||
}
|
||||
return comment;
|
||||
}
|
||||
|
||||
List<AppProductPropertyValueDetailRespVO> convertList01(List<ProductSkuDO.Property> properties);
|
||||
|
||||
/**
|
||||
* 计算综合评分
|
||||
*
|
||||
* @param descriptionScores 描述星级
|
||||
* @param benefitScores 服务星级
|
||||
* @return 综合评分
|
||||
*/
|
||||
@Named("convertScores")
|
||||
default Integer convertScores(Integer descriptionScores, Integer benefitScores) {
|
||||
// 计算评价最终综合评分 最终星数 = (商品评星 + 服务评星) / 2
|
||||
BigDecimal sumScore = new BigDecimal(descriptionScores + benefitScores);
|
||||
@ -84,50 +59,4 @@ public interface ProductCommentConvert {
|
||||
return divide.intValue();
|
||||
}
|
||||
|
||||
@Mapping(target = "scores",
|
||||
expression = "java(convertScores(createReqDTO.getDescriptionScores(), createReqDTO.getBenefitScores()))")
|
||||
ProductCommentDO convert(ProductCommentCreateReqDTO createReqDTO);
|
||||
|
||||
default ProductCommentDO convert(ProductCommentCreateReqDTO createReqDTO,
|
||||
ProductSpuDO spu, ProductSkuDO sku, MemberUserRespDTO user) {
|
||||
ProductCommentDO comment = convert(createReqDTO).setReplyStatus(false);
|
||||
if (user != null) {
|
||||
comment.setUserId(user.getId());
|
||||
comment.setUserNickname(user.getNickname());
|
||||
comment.setUserAvatar(user.getAvatar());
|
||||
}
|
||||
if (spu != null) {
|
||||
comment.setSpuId(spu.getId());
|
||||
comment.setSpuName(spu.getName());
|
||||
}
|
||||
if (sku != null) {
|
||||
comment.setSkuPicUrl(sku.getPicUrl());
|
||||
comment.setSkuProperties(sku.getProperties());
|
||||
}
|
||||
return comment;
|
||||
}
|
||||
|
||||
@Mapping(target = "visible", constant = "true")
|
||||
@Mapping(target = "replyStatus", constant = "false")
|
||||
@Mapping(target = "userId", constant = "0L")
|
||||
@Mapping(target = "orderId", constant = "0L")
|
||||
@Mapping(target = "orderItemId", constant = "0L")
|
||||
@Mapping(target = "anonymous", expression = "java(Boolean.FALSE)")
|
||||
@Mapping(target = "scores",
|
||||
expression = "java(convertScores(createReq.getDescriptionScores(), createReq.getBenefitScores()))")
|
||||
ProductCommentDO convert(ProductCommentCreateReqVO createReq);
|
||||
|
||||
List<AppProductCommentRespVO> convertList02(List<ProductCommentDO> list);
|
||||
|
||||
default ProductCommentDO convert(ProductCommentCreateReqVO createReq, ProductSpuDO spu, ProductSkuDO sku) {
|
||||
ProductCommentDO commentDO = convert(createReq);
|
||||
if (spu != null) {
|
||||
commentDO.setSpuId(spu.getId()).setSpuName(spu.getName());
|
||||
}
|
||||
if (sku != null) {
|
||||
commentDO.setSkuPicUrl(sku.getPicUrl()).setSkuProperties(sku.getProperties());
|
||||
}
|
||||
return commentDO;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -144,13 +144,6 @@ public class ProductSpuDO extends BaseDO {
|
||||
* 赠送积分
|
||||
*/
|
||||
private Integer giveIntegral;
|
||||
/**
|
||||
* 赠送的优惠劵编号的数组
|
||||
*
|
||||
* 对应 CouponTemplateDO 的 id 属性
|
||||
*/
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private List<Long> giveCouponTemplateIds;
|
||||
|
||||
// TODO @puhui999:字段估计要改成 brokerageType
|
||||
/**
|
||||
|
@ -1,7 +1,6 @@
|
||||
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;
|
||||
@ -59,21 +58,4 @@ public interface ProductCommentMapper extends BaseMapperX<ProductCommentDO> {
|
||||
.eq(ProductCommentDO::getOrderItemId, orderItemId));
|
||||
}
|
||||
|
||||
default Long selectCountBySpuId(Long spuId, Boolean visible, Integer type) {
|
||||
LambdaQueryWrapperX<ProductCommentDO> queryWrapper = new LambdaQueryWrapperX<ProductCommentDO>()
|
||||
.eqIfPresent(ProductCommentDO::getSpuId, spuId)
|
||||
.eqIfPresent(ProductCommentDO::getVisible, visible);
|
||||
// 构建评价查询语句
|
||||
appendTabQuery(queryWrapper, type);
|
||||
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)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,14 +7,10 @@ import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommen
|
||||
import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO;
|
||||
import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品评论 Service 接口
|
||||
*
|
||||
@ -73,22 +69,4 @@ public interface ProductCommentService {
|
||||
*/
|
||||
PageResult<ProductCommentDO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible);
|
||||
|
||||
/**
|
||||
* 获得商品的评价统计
|
||||
*
|
||||
* @param spuId spu id
|
||||
* @param visible 是否可见
|
||||
* @return 评价统计
|
||||
*/
|
||||
AppCommentStatisticsRespVO getCommentStatistics(Long spuId, Boolean visible);
|
||||
|
||||
/**
|
||||
* 得到评论列表
|
||||
*
|
||||
* @param spuId 商品 id
|
||||
* @param count 数量
|
||||
* @return {@link Object}
|
||||
*/
|
||||
List<AppProductCommentRespVO> getCommentList(Long spuId, Integer count);
|
||||
|
||||
}
|
||||
|
@ -9,8 +9,6 @@ import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommen
|
||||
import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentReplyReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.comment.vo.ProductCommentUpdateVisibleReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentPageReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppCommentStatisticsRespVO;
|
||||
import cn.iocoder.yudao.module.product.controller.app.comment.vo.AppProductCommentRespVO;
|
||||
import cn.iocoder.yudao.module.product.convert.comment.ProductCommentConvert;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
|
||||
@ -18,13 +16,12 @@ 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 jakarta.annotation.Resource;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*;
|
||||
@ -54,28 +51,28 @@ public class ProductCommentServiceImpl implements ProductCommentService {
|
||||
@Override
|
||||
public void createComment(ProductCommentCreateReqVO createReqVO) {
|
||||
// 校验 SKU
|
||||
ProductSkuDO skuDO = validateSku(createReqVO.getSkuId());
|
||||
ProductSkuDO sku = validateSku(createReqVO.getSkuId());
|
||||
// 校验 SPU
|
||||
ProductSpuDO spuDO = validateSpu(skuDO.getSpuId());
|
||||
ProductSpuDO spu = validateSpu(sku.getSpuId());
|
||||
|
||||
// 创建评论
|
||||
ProductCommentDO comment = ProductCommentConvert.INSTANCE.convert(createReqVO, spuDO, skuDO);
|
||||
ProductCommentDO comment = ProductCommentConvert.INSTANCE.convert(createReqVO, spu, sku);
|
||||
productCommentMapper.insert(comment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long createComment(ProductCommentCreateReqDTO createReqDTO) {
|
||||
// 校验 SKU
|
||||
ProductSkuDO skuDO = validateSku(createReqDTO.getSkuId());
|
||||
ProductSkuDO sku = validateSku(createReqDTO.getSkuId());
|
||||
// 校验 SPU
|
||||
ProductSpuDO spuDO = validateSpu(skuDO.getSpuId());
|
||||
ProductSpuDO spu = validateSpu(sku.getSpuId());
|
||||
// 校验评论
|
||||
validateCommentExists(createReqDTO.getUserId(), createReqDTO.getOrderId());
|
||||
// 获取用户详细信息
|
||||
MemberUserRespDTO user = memberUserApi.getUser(createReqDTO.getUserId());
|
||||
|
||||
// 创建评论
|
||||
ProductCommentDO comment = ProductCommentConvert.INSTANCE.convert(createReqDTO, spuDO, skuDO, user);
|
||||
ProductCommentDO comment = ProductCommentConvert.INSTANCE.convert(createReqDTO, spu, sku, user);
|
||||
productCommentMapper.insert(comment);
|
||||
return comment.getId();
|
||||
}
|
||||
@ -137,23 +134,6 @@ public class ProductCommentServiceImpl implements ProductCommentService {
|
||||
return productComment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppCommentStatisticsRespVO getCommentStatistics(Long spuId, Boolean visible) {
|
||||
return ProductCommentConvert.INSTANCE.convert(
|
||||
// 查询商品 id = spuId 的所有好评数量
|
||||
productCommentMapper.selectCountBySpuId(spuId, visible, AppCommentPageReqVO.GOOD_COMMENT),
|
||||
// 查询商品 id = spuId 的所有中评数量
|
||||
productCommentMapper.selectCountBySpuId(spuId, visible, AppCommentPageReqVO.MEDIOCRE_COMMENT),
|
||||
// 查询商品 id = spuId 的所有差评数量
|
||||
productCommentMapper.selectCountBySpuId(spuId, visible, AppCommentPageReqVO.NEGATIVE_COMMENT)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AppProductCommentRespVO> getCommentList(Long spuId, Integer count) {
|
||||
return ProductCommentConvert.INSTANCE.convertList02(productCommentMapper.selectCommentList(spuId, count).getList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ProductCommentDO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible) {
|
||||
return productCommentMapper.selectPage(pageVO, visible);
|
||||
|
Loading…
Reference in New Issue
Block a user