code review:订单评论、订单积分的变更

This commit is contained in:
YunaiV
2023-08-26 10:54:45 +08:00
parent f8952f8e34
commit b75d777670
11 changed files with 114 additions and 122 deletions

View File

@ -38,10 +38,9 @@ public class ProductCommentController {
@PreAuthorize("@ss.hasPermission('product:comment:query')")
public CommonResult<PageResult<ProductCommentRespVO>> getCommentPage(@Valid ProductCommentPageReqVO pageVO) {
PageResult<ProductCommentDO> pageResult = productCommentService.getCommentPage(pageVO);
// 拼接返回
List<ProductSkuDO> skuList = productSkuService.getSkuList(
convertSet(pageResult.getList(), ProductCommentDO::getSkuId));
return success(ProductCommentConvert.INSTANCE.convertPage(pageResult, skuList));
}

View File

@ -117,26 +117,26 @@ public interface ProductCommentConvert {
List<AppProductCommentRespVO> convertList02(List<ProductCommentDO> list);
default ProductCommentDO convert(ProductCommentCreateReqVO createReq, ProductSpuDO spuDO) {
default ProductCommentDO convert(ProductCommentCreateReqVO createReq, ProductSpuDO spu) {
ProductCommentDO commentDO = convert(createReq);
if (spuDO != null) {
commentDO.setSpuId(spuDO.getId());
commentDO.setSpuName(spuDO.getName());
if (spu != null) {
commentDO.setSpuId(spu.getId()).setSpuName(spu.getName());
}
return commentDO;
}
default PageResult<ProductCommentRespVO> convertPage(PageResult<ProductCommentDO> pageResult, List<ProductSkuDO> skuList) {
Map<Long, ProductSkuDO> skuMap = convertMap(skuList, ProductSkuDO::getId);
default PageResult<ProductCommentRespVO> convertPage(PageResult<ProductCommentDO> pageResult,
List<ProductSkuDO> skus) {
PageResult<ProductCommentRespVO> result = convertPage(pageResult);
// 拼接数据
Map<Long, ProductSkuDO> skuMap = convertMap(skus, ProductSkuDO::getId);
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(" "));
// TODO @疯狂:要不写入评论的时候,把商品图片、商品属性,都冗余进去。因为这种东西有“快照”的需求。商品后续会编辑掉
vo.setSkuPicUrl(sku.getPicUrl());
vo.setSpuName(vo.getSpuName() + " " + propertyNames);
});

View File

@ -1,6 +1,5 @@
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;
@ -54,11 +53,10 @@ public interface ProductCommentMapper extends BaseMapperX<ProductCommentDO> {
return selectPage(reqVO, queryWrapper);
}
default ProductCommentDO selectByUserIdAndOrderItemIdAndSpuId(Long userId, Long orderItemId, Long skuId) {
default ProductCommentDO selectByUserIdAndOrderItemId(Long userId, Long orderItemId) {
return selectOne(new LambdaQueryWrapperX<ProductCommentDO>()
.eq(ProductCommentDO::getUserId, userId)
.eq(ProductCommentDO::getOrderItemId, orderItemId)
.eq(ProductCommentDO::getSpuId, skuId));
.eq(ProductCommentDO::getOrderItemId, orderItemId));
}
default Long selectCountBySpuId(Long spuId, Boolean visible, Integer type) {

View File

@ -24,38 +24,6 @@ import java.util.List;
@Validated
public interface ProductCommentService {
/**
* 获得商品评价分页
*
* @param pageReqVO 分页查询
* @return 商品评价分页
*/
PageResult<ProductCommentDO> getCommentPage(ProductCommentPageReqVO pageReqVO);
/**
* 修改评论是否可见
*
* @param updateReqVO 修改评论可见
*/
void updateCommentVisible(ProductCommentUpdateVisibleReqVO updateReqVO);
/**
* 商家回复
*
* @param replyVO 商家回复
* @param loginUserId 管理后台商家登陆人 ID
*/
void replyComment(ProductCommentReplyReqVO replyVO, Long loginUserId);
/**
* 获得商品评价分页
*
* @param pageVO 分页查询
* @param visible 是否可见
* @return 商品评价分页
*/
PageResult<ProductCommentDO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible);
/**
* 创建商品评论
* 后台管理员创建评论使用
@ -73,6 +41,38 @@ public interface ProductCommentService {
*/
Long createComment(ProductCommentCreateReqDTO createReqDTO);
/**
* 修改评论是否可见
*
* @param updateReqVO 修改评论可见
*/
void updateCommentVisible(ProductCommentUpdateVisibleReqVO updateReqVO);
/**
* 商家回复
*
* @param replyVO 商家回复
* @param userId 管理后台商家登陆人 ID
*/
void replyComment(ProductCommentReplyReqVO replyVO, Long userId);
/**
* 【管理员】获得商品评价分页
*
* @param pageReqVO 分页查询
* @return 商品评价分页
*/
PageResult<ProductCommentDO> getCommentPage(ProductCommentPageReqVO pageReqVO);
/**
* 【会员】获得商品评价分页
*
* @param pageVO 分页查询
* @param visible 是否可见
* @return 商品评价分页
*/
PageResult<ProductCommentDO> getCommentPage(AppCommentPageReqVO pageVO, Boolean visible);
/**
* 获得商品的评价统计
*

View File

@ -20,7 +20,6 @@ import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
import cn.iocoder.yudao.module.product.service.spu.ProductSpuService;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
@ -53,71 +52,43 @@ public class ProductCommentServiceImpl implements ProductCommentService {
private MemberUserApi memberUserApi;
@Override
@Transactional(rollbackFor = Exception.class)
public void updateCommentVisible(ProductCommentUpdateVisibleReqVO updateReqVO) {
// 校验评论是否存在
ProductCommentDO productCommentDO = validateCommentExists(updateReqVO.getId());
productCommentDO.setVisible(updateReqVO.getVisible());
// 更新可见状态
productCommentMapper.updateById(productCommentDO);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void replyComment(ProductCommentReplyReqVO replyVO, Long loginUserId) {
// 校验评论是否存在
ProductCommentDO productCommentDO = validateCommentExists(replyVO.getId());
productCommentDO.setReplyTime(LocalDateTime.now());
productCommentDO.setReplyUserId(loginUserId);
productCommentDO.setReplyStatus(Boolean.TRUE);
productCommentDO.setReplyContent(replyVO.getReplyContent());
// 回复评论
productCommentMapper.updateById(productCommentDO);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void createComment(ProductCommentCreateReqVO createReqVO) {
// 校验商品
ProductSpuDO spuDO = validateProduct(createReqVO.getSkuId());
ProductSpuDO spu = validateSpuBySkuId(createReqVO.getSkuId());
ProductCommentDO commentDO = ProductCommentConvert.INSTANCE.convert(createReqVO, spuDO);
productCommentMapper.insert(commentDO);
// 创建评论
ProductCommentDO comment = ProductCommentConvert.INSTANCE.convert(createReqVO, spu);
productCommentMapper.insert(comment);
}
@Override
@Transactional(rollbackFor = Exception.class)
public Long createComment(ProductCommentCreateReqDTO createReqDTO) {
// 校验商品
ProductSpuDO spuDO = validateProduct(createReqDTO.getSkuId());
ProductSpuDO spuDO = validateSpuBySkuId(createReqDTO.getSkuId());
// 校验评论
validateComment(spuDO.getId(), createReqDTO.getUserId(), createReqDTO.getOrderId());
validateCommentExists(createReqDTO.getUserId(), createReqDTO.getOrderId());
// 获取用户详细信息
MemberUserRespDTO user = memberUserApi.getUser(createReqDTO.getUserId());
// 创建评论
ProductCommentDO commentDO = ProductCommentConvert.INSTANCE.convert(createReqDTO, spuDO, user);
productCommentMapper.insert(commentDO);
return commentDO.getId();
ProductCommentDO comment = ProductCommentConvert.INSTANCE.convert(createReqDTO, spuDO, user);
productCommentMapper.insert(comment);
return comment.getId();
}
private void validateComment(Long skuId, Long userId, Long orderItemId) {
// 判断当前订单的当前商品用户是否评价过
ProductCommentDO exist = productCommentMapper.selectByUserIdAndOrderItemIdAndSpuId(userId, orderItemId, skuId);
if (null != exist) {
/**
* 判断当前订单的当前商品用户是否评价过
*
* @param userId 用户编号
* @param orderItemId 订单项编号
*/
private void validateCommentExists(Long userId, Long orderItemId) {
ProductCommentDO exist = productCommentMapper.selectByUserIdAndOrderItemId(userId, orderItemId);
if (exist != null) {
throw exception(COMMENT_ORDER_EXISTS);
}
}
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) {
@ -134,6 +105,33 @@ public class ProductCommentServiceImpl implements ProductCommentService {
return spu;
}
private ProductSpuDO validateSpuBySkuId(Long skuId) {
// 通过 sku ID 拿到 spu 相关信息
ProductSkuDO sku = validateSku(skuId);
// 校验 spu 如果存在返回详情
return validateSpu(sku.getSpuId());
}
@Override
public void updateCommentVisible(ProductCommentUpdateVisibleReqVO updateReqVO) {
// 校验评论是否存在
validateCommentExists(updateReqVO.getId());
// 更新可见状态
productCommentMapper.updateById(new ProductCommentDO().setId(updateReqVO.getId())
.setVisible(true));
}
@Override
public void replyComment(ProductCommentReplyReqVO replyVO, Long userId) {
// 校验评论是否存在
validateCommentExists(replyVO.getId());
// 回复评论
productCommentMapper.updateById(new ProductCommentDO().setId(replyVO.getId())
.setReplyTime(LocalDateTime.now()).setReplyUserId(userId)
.setReplyStatus(Boolean.TRUE).setReplyContent(replyVO.getReplyContent()));
}
private ProductCommentDO validateCommentExists(Long id) {
ProductCommentDO productComment = productCommentMapper.selectById(id);
if (productComment == null) {

View File

@ -667,6 +667,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
TradeOrderItemAfterSaleStatusEnum.SUCCESS.getStatus()));
}
// TODO @疯狂:直接 this 调用async 不生效哈。全局搜下 getSelf();
@Async
protected void addUserExperienceAsync(Long userId, Integer payPrice, Long orderId) {
int bizType = MemberExperienceBizTypeEnum.ORDER.getType();