mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-26 17:21:53 +08:00
商品:完善后台商品评论功能
This commit is contained in:
parent
da8b2eab6d
commit
2132de9dd1
@ -5,7 +5,9 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|||||||
import cn.iocoder.yudao.module.product.controller.admin.comment.vo.*;
|
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.convert.comment.ProductCommentConvert;
|
||||||
import cn.iocoder.yudao.module.product.dal.dataobject.comment.ProductCommentDO;
|
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.comment.ProductCommentService;
|
||||||
|
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
@ -14,8 +16,10 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
|
||||||
|
|
||||||
@Tag(name = "管理后台 - 商品评价")
|
@Tag(name = "管理后台 - 商品评价")
|
||||||
@ -26,13 +30,19 @@ public class ProductCommentController {
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ProductCommentService productCommentService;
|
private ProductCommentService productCommentService;
|
||||||
|
@Resource
|
||||||
|
private ProductSkuService productSkuService;
|
||||||
|
|
||||||
@GetMapping("/page")
|
@GetMapping("/page")
|
||||||
@Operation(summary = "获得商品评价分页")
|
@Operation(summary = "获得商品评价分页")
|
||||||
@PreAuthorize("@ss.hasPermission('product:comment:query')")
|
@PreAuthorize("@ss.hasPermission('product:comment:query')")
|
||||||
public CommonResult<PageResult<ProductCommentRespVO>> getCommentPage(@Valid ProductCommentPageReqVO pageVO) {
|
public CommonResult<PageResult<ProductCommentRespVO>> getCommentPage(@Valid ProductCommentPageReqVO pageVO) {
|
||||||
PageResult<ProductCommentDO> pageResult = productCommentService.getCommentPage(pageVO);
|
PageResult<ProductCommentDO> pageResult = productCommentService.getCommentPage(pageVO);
|
||||||
return success(ProductCommentConvert.INSTANCE.convertPage(pageResult));
|
|
||||||
|
List<ProductSkuDO> skuList = productSkuService.getSkuList(
|
||||||
|
convertSet(pageResult.getList(), ProductCommentDO::getSkuId));
|
||||||
|
|
||||||
|
return success(ProductCommentConvert.INSTANCE.convertPage(pageResult, skuList));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/update-visible")
|
@PutMapping("/update-visible")
|
||||||
@ -51,7 +61,7 @@ public class ProductCommentController {
|
|||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/create")
|
@PostMapping("/create")
|
||||||
@Operation(summary = "添加自评")
|
@Operation(summary = "添加自评")
|
||||||
@PreAuthorize("@ss.hasPermission('product:comment:update')")
|
@PreAuthorize("@ss.hasPermission('product:comment:update')")
|
||||||
public CommonResult<Boolean> createComment(@Valid @RequestBody ProductCommentCreateReqVO createReqVO) {
|
public CommonResult<Boolean> createComment(@Valid @RequestBody ProductCommentCreateReqVO createReqVO) {
|
||||||
|
@ -11,11 +11,9 @@ import java.util.List;
|
|||||||
public class ProductCommentBaseVO {
|
public class ProductCommentBaseVO {
|
||||||
|
|
||||||
@Schema(description = "评价人", requiredMode = Schema.RequiredMode.REQUIRED, example = "16868")
|
@Schema(description = "评价人", requiredMode = Schema.RequiredMode.REQUIRED, example = "16868")
|
||||||
@NotNull(message = "评价人不能为空")
|
|
||||||
private Long userId;
|
private Long userId;
|
||||||
|
|
||||||
@Schema(description = "评价订单项", requiredMode = Schema.RequiredMode.REQUIRED, example = "19292")
|
@Schema(description = "评价订单项", requiredMode = Schema.RequiredMode.REQUIRED, example = "19292")
|
||||||
@NotNull(message = "评价订单项不能为空")
|
|
||||||
private Long orderItemId;
|
private Long orderItemId;
|
||||||
|
|
||||||
@Schema(description = "评价人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小姑凉")
|
@Schema(description = "评价人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小姑凉")
|
||||||
|
@ -52,4 +52,6 @@ public class ProductCommentRespVO extends ProductCommentBaseVO {
|
|||||||
@NotNull(message = "商品 SPU 名称不能为空")
|
@NotNull(message = "商品 SPU 名称不能为空")
|
||||||
private String spuName;
|
private String spuName;
|
||||||
|
|
||||||
|
@Schema(description = "商品 SKU 图片地址", example = "https://www.iocoder.cn/yudao.jpg")
|
||||||
|
private String skuPicUrl;
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.product.convert.comment;
|
|||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||||
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
|
||||||
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
|
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.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.ProductCommentCreateReqVO;
|
||||||
@ -23,6 +22,11 @@ import java.math.BigDecimal;
|
|||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品评价 Convert
|
* 商品评价 Convert
|
||||||
@ -60,7 +64,7 @@ public interface ProductCommentConvert {
|
|||||||
item.setUserNickname(ProductCommentDO.NICKNAME_ANONYMOUS);
|
item.setUserNickname(ProductCommentDO.NICKNAME_ANONYMOUS);
|
||||||
}
|
}
|
||||||
// 设置 SKU 规格值
|
// 设置 SKU 规格值
|
||||||
MapUtils.findAndThen(skuMap, item.getSkuId(),
|
findAndThen(skuMap, item.getSkuId(),
|
||||||
sku -> item.setSkuProperties(convertList01(sku.getProperties())));
|
sku -> item.setSkuProperties(convertList01(sku.getProperties())));
|
||||||
});
|
});
|
||||||
return page;
|
return page;
|
||||||
@ -101,6 +105,8 @@ public interface ProductCommentConvert {
|
|||||||
return commentDO;
|
return commentDO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Mapping(target = "visible", constant = "true")
|
||||||
|
@Mapping(target = "replyStatus", constant = "false")
|
||||||
@Mapping(target = "userId", constant = "0L")
|
@Mapping(target = "userId", constant = "0L")
|
||||||
@Mapping(target = "orderId", constant = "0L")
|
@Mapping(target = "orderId", constant = "0L")
|
||||||
@Mapping(target = "orderItemId", constant = "0L")
|
@Mapping(target = "orderItemId", constant = "0L")
|
||||||
@ -111,4 +117,30 @@ public interface ProductCommentConvert {
|
|||||||
|
|
||||||
List<AppProductCommentRespVO> convertList02(List<ProductCommentDO> list);
|
List<AppProductCommentRespVO> convertList02(List<ProductCommentDO> list);
|
||||||
|
|
||||||
|
default ProductCommentDO convert(ProductCommentCreateReqVO createReq, ProductSpuDO spuDO) {
|
||||||
|
ProductCommentDO commentDO = convert(createReq);
|
||||||
|
if (spuDO != null) {
|
||||||
|
commentDO.setSpuId(spuDO.getId());
|
||||||
|
commentDO.setSpuName(spuDO.getName());
|
||||||
|
}
|
||||||
|
return commentDO;
|
||||||
|
}
|
||||||
|
|
||||||
|
default PageResult<ProductCommentRespVO> convertPage(PageResult<ProductCommentDO> pageResult, List<ProductSkuDO> skuList) {
|
||||||
|
Map<Long, ProductSkuDO> skuMap = convertMap(skuList, ProductSkuDO::getId);
|
||||||
|
|
||||||
|
PageResult<ProductCommentRespVO> result = convertPage(pageResult);
|
||||||
|
for (ProductCommentRespVO vo : result.getList()) {
|
||||||
|
findAndThen(skuMap, vo.getSkuId(), sku -> {
|
||||||
|
String propertyNames = sku.getProperties().stream()
|
||||||
|
.map(ProductSkuDO.Property::getValueName)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.collect(Collectors.joining(" "));
|
||||||
|
|
||||||
|
vo.setSkuPicUrl(sku.getPicUrl());
|
||||||
|
vo.setSpuName(vo.getSpuName() + " " + propertyNames);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ public interface ProductCommentMapper extends BaseMapperX<ProductCommentDO> {
|
|||||||
.eqIfPresent(ProductCommentDO::getOrderId, reqVO.getOrderId())
|
.eqIfPresent(ProductCommentDO::getOrderId, reqVO.getOrderId())
|
||||||
.eqIfPresent(ProductCommentDO::getSpuId, reqVO.getSpuId())
|
.eqIfPresent(ProductCommentDO::getSpuId, reqVO.getSpuId())
|
||||||
.eqIfPresent(ProductCommentDO::getScores, reqVO.getScores())
|
.eqIfPresent(ProductCommentDO::getScores, reqVO.getScores())
|
||||||
|
.eqIfPresent(ProductCommentDO::getReplyStatus, reqVO.getReplyStatus())
|
||||||
.betweenIfPresent(ProductCommentDO::getCreateTime, reqVO.getCreateTime())
|
.betweenIfPresent(ProductCommentDO::getCreateTime, reqVO.getCreateTime())
|
||||||
.likeIfPresent(ProductCommentDO::getSpuName, reqVO.getSpuName())
|
.likeIfPresent(ProductCommentDO::getSpuName, reqVO.getSpuName())
|
||||||
.orderByDesc(ProductCommentDO::getId));
|
.orderByDesc(ProductCommentDO::getId));
|
||||||
|
@ -80,23 +80,18 @@ public class ProductCommentServiceImpl implements ProductCommentService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void createComment(ProductCommentCreateReqVO createReqVO) {
|
public void createComment(ProductCommentCreateReqVO createReqVO) {
|
||||||
// 校验评论
|
// 校验商品
|
||||||
validateComment(createReqVO.getSkuId(), createReqVO.getUserId(), createReqVO.getOrderItemId());
|
ProductSpuDO spuDO = validateProduct(createReqVO.getSkuId());
|
||||||
|
|
||||||
ProductCommentDO commentDO = ProductCommentConvert.INSTANCE.convert(createReqVO);
|
ProductCommentDO commentDO = ProductCommentConvert.INSTANCE.convert(createReqVO, spuDO);
|
||||||
productCommentMapper.insert(commentDO);
|
productCommentMapper.insert(commentDO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Long createComment(ProductCommentCreateReqDTO createReqDTO) {
|
public Long createComment(ProductCommentCreateReqDTO createReqDTO) {
|
||||||
// 通过 sku ID 拿到 spu 相关信息
|
// 校验商品
|
||||||
ProductSkuDO sku = productSkuService.getSku(createReqDTO.getSkuId());
|
ProductSpuDO spuDO = validateProduct(createReqDTO.getSkuId());
|
||||||
if (sku == null) {
|
|
||||||
throw exception(SKU_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
// 校验 spu 如果存在返回详情
|
|
||||||
ProductSpuDO spuDO = validateSpu(sku.getSpuId());
|
|
||||||
// 校验评论
|
// 校验评论
|
||||||
validateComment(spuDO.getId(), createReqDTO.getUserId(), createReqDTO.getOrderId());
|
validateComment(spuDO.getId(), createReqDTO.getUserId(), createReqDTO.getOrderId());
|
||||||
// 获取用户详细信息
|
// 获取用户详细信息
|
||||||
@ -116,6 +111,21 @@ public class ProductCommentServiceImpl implements ProductCommentService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ProductSpuDO validateProduct(Long skuId) {
|
||||||
|
// 通过 sku ID 拿到 spu 相关信息
|
||||||
|
ProductSkuDO sku = validateSku(skuId);
|
||||||
|
// 校验 spu 如果存在返回详情
|
||||||
|
return validateSpu(sku.getSpuId());
|
||||||
|
}
|
||||||
|
|
||||||
|
private ProductSkuDO validateSku(Long skuId) {
|
||||||
|
ProductSkuDO sku = productSkuService.getSku(skuId);
|
||||||
|
if (sku == null) {
|
||||||
|
throw exception(SKU_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
return sku;
|
||||||
|
}
|
||||||
|
|
||||||
private ProductSpuDO validateSpu(Long spuId) {
|
private ProductSpuDO validateSpu(Long spuId) {
|
||||||
ProductSpuDO spu = productSpuService.getSpu(spuId);
|
ProductSpuDO spu = productSpuService.getSpu(spuId);
|
||||||
if (null == spu) {
|
if (null == spu) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package cn.iocoder.yudao.module.product.service.sku;
|
package cn.iocoder.yudao.module.product.service.sku;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.collection.ListUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO;
|
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO;
|
||||||
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO;
|
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO;
|
||||||
@ -74,6 +75,9 @@ public class ProductSkuServiceImpl implements ProductSkuService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ProductSkuDO> getSkuList(Collection<Long> ids) {
|
public List<ProductSkuDO> getSkuList(Collection<Long> ids) {
|
||||||
|
if (CollUtil.isEmpty(ids)) {
|
||||||
|
return ListUtil.empty();
|
||||||
|
}
|
||||||
return productSkuMapper.selectBatchIds(ids);
|
return productSkuMapper.selectBatchIds(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user