mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 15:21:53 +08:00
code review:商品评论
This commit is contained in:
parent
806228be8b
commit
f5c5d38303
@ -1,14 +0,0 @@
|
||||
-- 1.冗余 SKU 图片地址, 规格
|
||||
alter table product_comment
|
||||
add column sku_pic_url varchar(256) not null comment '图片地址' after sku_id;
|
||||
|
||||
alter table product_comment
|
||||
add column sku_properties varchar(512) null
|
||||
comment '属性数组,JSON 格式 [{propertId: , valueId: }, {propertId: , valueId: }]' after sku_pic_url;
|
||||
|
||||
-- 2.修复已有数据
|
||||
update product_comment pc
|
||||
join product_sku ps on pc.spu_id = ps.spu_id
|
||||
set pc.sku_pic_url = ps.pic_url,
|
||||
pc.sku_properties = ps.properties
|
||||
where pc.sku_id is not null;
|
@ -32,7 +32,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.convertPage2(pageResult));
|
||||
return success(ProductCommentConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
@PutMapping("/update-visible")
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.iocoder.yudao.module.product.controller.admin.comment.vo;
|
||||
|
||||
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@ -7,6 +8,7 @@ import lombok.ToString;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "管理后台 - 商品评价 Response VO")
|
||||
@Data
|
||||
@ -23,10 +25,10 @@ public class ProductCommentRespVO extends ProductCommentBaseVO {
|
||||
@Schema(description = "交易订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24428")
|
||||
private Long orderId;
|
||||
|
||||
@Schema(description = "是否可见:[true:显示 false:隐藏]", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@Schema(description = "是否可见", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private Boolean visible;
|
||||
|
||||
@Schema(description = "商家是否回复:[1:回复 0:未回复]", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@Schema(description = "商家是否回复", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private Boolean replyStatus;
|
||||
|
||||
@Schema(description = "回复管理员编号", example = "9527")
|
||||
@ -54,4 +56,8 @@ public class ProductCommentRespVO extends ProductCommentBaseVO {
|
||||
|
||||
@Schema(description = "商品 SKU 图片地址", example = "https://www.iocoder.cn/yudao.jpg")
|
||||
private String skuPicUrl;
|
||||
|
||||
@Schema(description = "商品 SKU 规格值数组")
|
||||
private List<ProductSkuBaseVO.Property> skuProperties;
|
||||
|
||||
}
|
||||
|
@ -1,57 +1,14 @@
|
||||
package cn.iocoder.yudao.module.product.controller.admin.sku;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuOptionRespVO;
|
||||
import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
|
||||
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
|
||||
import cn.iocoder.yudao.module.product.service.spu.ProductSpuService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
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.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
|
||||
@Tag(name = "管理后台 - 商品 sku")
|
||||
@Tag(name = "管理后台 - 商品 SKU")
|
||||
@RestController
|
||||
@RequestMapping("/product/sku")
|
||||
@Validated
|
||||
public class ProductSkuController {
|
||||
|
||||
@Resource
|
||||
private ProductSkuService productSkuService;
|
||||
@Resource
|
||||
private ProductSpuService productSpuService;
|
||||
|
||||
@GetMapping("/get-option-list")
|
||||
@Operation(summary = "获得商品 SKU 选项的列表")
|
||||
// @PreAuthorize("@ss.hasPermission('product:sku:query')")
|
||||
public CommonResult<List<ProductSkuOptionRespVO>> getSkuOptionList() {
|
||||
// 获得 SKU 列表
|
||||
List<ProductSkuDO> skus = productSkuService.getSkuList();
|
||||
if (CollUtil.isEmpty(skus)) {
|
||||
return success(Collections.emptyList());
|
||||
}
|
||||
|
||||
// 获得对应的 SPU 映射
|
||||
Map<Long, ProductSpuDO> spuMap = productSpuService.getSpuMap(convertSet(skus, ProductSkuDO::getSpuId));
|
||||
// 转换为返回结果
|
||||
List<ProductSkuOptionRespVO> skuVOs = ProductSkuConvert.INSTANCE.convertList05(skus);
|
||||
skuVOs.forEach(sku -> MapUtils.findAndThen(spuMap, sku.getSpuId(),
|
||||
spu -> sku.setSpuId(spu.getId()).setSpuName(spu.getName())));
|
||||
return success(skuVOs);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,30 +0,0 @@
|
||||
package cn.iocoder.yudao.module.product.controller.admin.sku.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(description = "管理后台 - 商品 SKU 选项 Response VO") // 用于前端 SELECT 选项
|
||||
@Data
|
||||
public class ProductSkuOptionRespVO {
|
||||
|
||||
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "商品 SKU 名字", example = "红色")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "销售价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
|
||||
private String price;
|
||||
|
||||
@Schema(description = "库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
|
||||
private Integer stock;
|
||||
|
||||
// ========== 商品 SPU 信息 ==========
|
||||
|
||||
@Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Long spuId;
|
||||
|
||||
@Schema(description = "商品 SPU 名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "iPhone 11")
|
||||
private String spuName;
|
||||
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package cn.iocoder.yudao.module.product.convert.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.framework.common.util.collection.CollectionUtils;
|
||||
@ -23,10 +22,7 @@ import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.List;
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -122,35 +118,15 @@ public interface ProductCommentConvert {
|
||||
|
||||
List<AppProductCommentRespVO> convertList02(List<ProductCommentDO> list);
|
||||
|
||||
default ProductCommentDO convert(ProductCommentCreateReqVO createReq, ProductSpuDO spuDO, ProductSkuDO skuDO) {
|
||||
default ProductCommentDO convert(ProductCommentCreateReqVO createReq, ProductSpuDO spu, ProductSkuDO sku) {
|
||||
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());
|
||||
}
|
||||
if (skuDO != null) {
|
||||
commentDO.setSkuPicUrl(skuDO.getPicUrl());
|
||||
commentDO.setSkuProperties(skuDO.getProperties());
|
||||
if (sku != null) {
|
||||
commentDO.setSkuPicUrl(sku.getPicUrl()).setSkuProperties(sku.getProperties());
|
||||
}
|
||||
return commentDO;
|
||||
}
|
||||
|
||||
default PageResult<ProductCommentRespVO> convertPage2(PageResult<ProductCommentDO> pageResult) {
|
||||
Map<Long, List<ProductSkuDO.Property>> propertiesMap = convertMap(pageResult.getList(),
|
||||
ProductCommentDO::getId,
|
||||
// 这里会有NULL异常, 需要处理一下
|
||||
comment -> CollUtil.emptyIfNull(comment.getSkuProperties()));
|
||||
|
||||
PageResult<ProductCommentRespVO> result = convertPage(pageResult);
|
||||
for (ProductCommentRespVO vo : result.getList()) {
|
||||
findAndThen(propertiesMap, vo.getId(), properties -> {
|
||||
String propertyNames = properties.stream()
|
||||
.map(ProductSkuDO.Property::getValueName)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.joining(" "));
|
||||
vo.setSpuName(vo.getSpuName() + " " + propertyNames);
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO;
|
||||
import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuOptionRespVO;
|
||||
import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO;
|
||||
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
|
||||
import org.mapstruct.Mapper;
|
||||
@ -44,8 +43,6 @@ public interface ProductSkuConvert {
|
||||
|
||||
List<ProductSkuRespDTO> convertList04(List<ProductSkuDO> list);
|
||||
|
||||
List<ProductSkuOptionRespVO> convertList05(List<ProductSkuDO> skus);
|
||||
|
||||
/**
|
||||
* 获得 SPU 的库存变化 Map
|
||||
*
|
||||
|
@ -73,11 +73,14 @@ public class ProductCommentDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 商品 SPU 编号
|
||||
*
|
||||
* 关联 {@link ProductSpuDO#getId()}
|
||||
*/
|
||||
private Long spuId;
|
||||
/**
|
||||
* 商品 SPU 名称
|
||||
*
|
||||
* 关联 {@link ProductSpuDO#getName()}
|
||||
*/
|
||||
private String spuName;
|
||||
/**
|
||||
@ -88,10 +91,14 @@ public class ProductCommentDO extends BaseDO {
|
||||
private Long skuId;
|
||||
/**
|
||||
* 商品 SKU 图片地址
|
||||
*
|
||||
* 关联 {@link ProductSkuDO#getPicUrl()}
|
||||
*/
|
||||
private String skuPicUrl;
|
||||
/**
|
||||
* 属性数组,JSON 格式
|
||||
*
|
||||
* 关联 {@link ProductSkuDO#getProperties()}
|
||||
*/
|
||||
@TableField(typeHandler = ProductSkuDO.PropertyTypeHandler.class)
|
||||
private List<ProductSkuDO.Property> skuProperties;
|
||||
|
@ -81,17 +81,12 @@ public class MemberPointRecordServiceImpl implements MemberPointRecordService {
|
||||
// 2. 增加积分记录
|
||||
MemberUserDO user = memberUserService.getUser(userId);
|
||||
Integer userPoint = ObjectUtil.defaultIfNull(user.getPoint(), 0);
|
||||
// 用户变动后的积分
|
||||
Integer totalPoint = userPoint + point;
|
||||
MemberPointRecordDO recordDO = new MemberPointRecordDO()
|
||||
.setUserId(userId)
|
||||
.setBizId(bizId)
|
||||
.setBizType(bizType.getType())
|
||||
.setTitle(bizType.getName())
|
||||
.setDescription(StrUtil.format(bizType.getDescription(), point))
|
||||
.setPoint(point)
|
||||
.setTotalPoint(totalPoint);
|
||||
recordMapper.insert(recordDO);
|
||||
Integer totalPoint = userPoint + point; // 用户变动后的积分
|
||||
MemberPointRecordDO record = new MemberPointRecordDO()
|
||||
.setUserId(userId).setBizId(bizId).setBizType(bizType.getType())
|
||||
.setTitle(bizType.getName()).setDescription(StrUtil.format(bizType.getDescription(), point))
|
||||
.setPoint(point).setTotalPoint(totalPoint);
|
||||
recordMapper.insert(record);
|
||||
|
||||
// 3. 更新用户积分
|
||||
memberUserService.updateUserPoint(userId, totalPoint);
|
||||
|
Loading…
Reference in New Issue
Block a user