mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-26 01:01:52 +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')")
|
@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.convertPage2(pageResult));
|
return success(ProductCommentConvert.INSTANCE.convertPage(pageResult));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/update-visible")
|
@PutMapping("/update-visible")
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package cn.iocoder.yudao.module.product.controller.admin.comment.vo;
|
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 io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
@ -7,6 +8,7 @@ import lombok.ToString;
|
|||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Schema(description = "管理后台 - 商品评价 Response VO")
|
@Schema(description = "管理后台 - 商品评价 Response VO")
|
||||||
@Data
|
@Data
|
||||||
@ -23,10 +25,10 @@ public class ProductCommentRespVO extends ProductCommentBaseVO {
|
|||||||
@Schema(description = "交易订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24428")
|
@Schema(description = "交易订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24428")
|
||||||
private Long orderId;
|
private Long orderId;
|
||||||
|
|
||||||
@Schema(description = "是否可见:[true:显示 false:隐藏]", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "是否可见", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
private Boolean visible;
|
private Boolean visible;
|
||||||
|
|
||||||
@Schema(description = "商家是否回复:[1:回复 0:未回复]", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "商家是否回复", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
private Boolean replyStatus;
|
private Boolean replyStatus;
|
||||||
|
|
||||||
@Schema(description = "回复管理员编号", example = "9527")
|
@Schema(description = "回复管理员编号", example = "9527")
|
||||||
@ -54,4 +56,8 @@ public class ProductCommentRespVO extends ProductCommentBaseVO {
|
|||||||
|
|
||||||
@Schema(description = "商品 SKU 图片地址", example = "https://www.iocoder.cn/yudao.jpg")
|
@Schema(description = "商品 SKU 图片地址", example = "https://www.iocoder.cn/yudao.jpg")
|
||||||
private String skuPicUrl;
|
private String skuPicUrl;
|
||||||
|
|
||||||
|
@Schema(description = "商品 SKU 规格值数组")
|
||||||
|
private List<ProductSkuBaseVO.Property> skuProperties;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,57 +1,14 @@
|
|||||||
package cn.iocoder.yudao.module.product.controller.admin.sku;
|
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 io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import org.springframework.validation.annotation.Validated;
|
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.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
@Tag(name = "管理后台 - 商品 SKU")
|
||||||
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")
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/product/sku")
|
@RequestMapping("/product/sku")
|
||||||
@Validated
|
@Validated
|
||||||
public class ProductSkuController {
|
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;
|
package cn.iocoder.yudao.module.product.convert.comment;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
|
||||||
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;
|
||||||
@ -23,10 +22,7 @@ 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;
|
import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -122,35 +118,15 @@ public interface ProductCommentConvert {
|
|||||||
|
|
||||||
List<AppProductCommentRespVO> convertList02(List<ProductCommentDO> list);
|
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);
|
ProductCommentDO commentDO = convert(createReq);
|
||||||
if (spuDO != null) {
|
if (spu != null) {
|
||||||
commentDO.setSpuId(spuDO.getId());
|
commentDO.setSpuId(spu.getId()).setSpuName(spu.getName());
|
||||||
commentDO.setSpuName(spuDO.getName());
|
|
||||||
}
|
}
|
||||||
if (skuDO != null) {
|
if (sku != null) {
|
||||||
commentDO.setSkuPicUrl(skuDO.getPicUrl());
|
commentDO.setSkuPicUrl(sku.getPicUrl()).setSkuProperties(sku.getProperties());
|
||||||
commentDO.setSkuProperties(skuDO.getProperties());
|
|
||||||
}
|
}
|
||||||
return commentDO;
|
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.ProductSkuRespDTO;
|
||||||
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.ProductSkuCreateOrUpdateReqVO;
|
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.controller.admin.sku.vo.ProductSkuRespVO;
|
||||||
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
|
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
@ -44,8 +43,6 @@ public interface ProductSkuConvert {
|
|||||||
|
|
||||||
List<ProductSkuRespDTO> convertList04(List<ProductSkuDO> list);
|
List<ProductSkuRespDTO> convertList04(List<ProductSkuDO> list);
|
||||||
|
|
||||||
List<ProductSkuOptionRespVO> convertList05(List<ProductSkuDO> skus);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得 SPU 的库存变化 Map
|
* 获得 SPU 的库存变化 Map
|
||||||
*
|
*
|
||||||
|
@ -73,11 +73,14 @@ public class ProductCommentDO extends BaseDO {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品 SPU 编号
|
* 商品 SPU 编号
|
||||||
|
*
|
||||||
* 关联 {@link ProductSpuDO#getId()}
|
* 关联 {@link ProductSpuDO#getId()}
|
||||||
*/
|
*/
|
||||||
private Long spuId;
|
private Long spuId;
|
||||||
/**
|
/**
|
||||||
* 商品 SPU 名称
|
* 商品 SPU 名称
|
||||||
|
*
|
||||||
|
* 关联 {@link ProductSpuDO#getName()}
|
||||||
*/
|
*/
|
||||||
private String spuName;
|
private String spuName;
|
||||||
/**
|
/**
|
||||||
@ -88,10 +91,14 @@ public class ProductCommentDO extends BaseDO {
|
|||||||
private Long skuId;
|
private Long skuId;
|
||||||
/**
|
/**
|
||||||
* 商品 SKU 图片地址
|
* 商品 SKU 图片地址
|
||||||
|
*
|
||||||
|
* 关联 {@link ProductSkuDO#getPicUrl()}
|
||||||
*/
|
*/
|
||||||
private String skuPicUrl;
|
private String skuPicUrl;
|
||||||
/**
|
/**
|
||||||
* 属性数组,JSON 格式
|
* 属性数组,JSON 格式
|
||||||
|
*
|
||||||
|
* 关联 {@link ProductSkuDO#getProperties()}
|
||||||
*/
|
*/
|
||||||
@TableField(typeHandler = ProductSkuDO.PropertyTypeHandler.class)
|
@TableField(typeHandler = ProductSkuDO.PropertyTypeHandler.class)
|
||||||
private List<ProductSkuDO.Property> skuProperties;
|
private List<ProductSkuDO.Property> skuProperties;
|
||||||
|
@ -81,17 +81,12 @@ public class MemberPointRecordServiceImpl implements MemberPointRecordService {
|
|||||||
// 2. 增加积分记录
|
// 2. 增加积分记录
|
||||||
MemberUserDO user = memberUserService.getUser(userId);
|
MemberUserDO user = memberUserService.getUser(userId);
|
||||||
Integer userPoint = ObjectUtil.defaultIfNull(user.getPoint(), 0);
|
Integer userPoint = ObjectUtil.defaultIfNull(user.getPoint(), 0);
|
||||||
// 用户变动后的积分
|
Integer totalPoint = userPoint + point; // 用户变动后的积分
|
||||||
Integer totalPoint = userPoint + point;
|
MemberPointRecordDO record = new MemberPointRecordDO()
|
||||||
MemberPointRecordDO recordDO = new MemberPointRecordDO()
|
.setUserId(userId).setBizId(bizId).setBizType(bizType.getType())
|
||||||
.setUserId(userId)
|
.setTitle(bizType.getName()).setDescription(StrUtil.format(bizType.getDescription(), point))
|
||||||
.setBizId(bizId)
|
.setPoint(point).setTotalPoint(totalPoint);
|
||||||
.setBizType(bizType.getType())
|
recordMapper.insert(record);
|
||||||
.setTitle(bizType.getName())
|
|
||||||
.setDescription(StrUtil.format(bizType.getDescription(), point))
|
|
||||||
.setPoint(point)
|
|
||||||
.setTotalPoint(totalPoint);
|
|
||||||
recordMapper.insert(recordDO);
|
|
||||||
|
|
||||||
// 3. 更新用户积分
|
// 3. 更新用户积分
|
||||||
memberUserService.updateUserPoint(userId, totalPoint);
|
memberUserService.updateUserPoint(userId, totalPoint);
|
||||||
|
Loading…
Reference in New Issue
Block a user