Commit f5c5d383032efdd1e5bbc5d03a0778cc4eef8ddc
1 parent
806228be
code review:商品评论
Showing
9 changed files
with
28 additions
and
134 deletions
sql/mysql/product_comment.sql deleted
| 1 | --- 1.冗余 SKU 图片地址, 规格 | ||
| 2 | -alter table product_comment | ||
| 3 | - add column sku_pic_url varchar(256) not null comment '图片地址' after sku_id; | ||
| 4 | - | ||
| 5 | -alter table product_comment | ||
| 6 | - add column sku_properties varchar(512) null | ||
| 7 | - comment '属性数组,JSON 格式 [{propertId: , valueId: }, {propertId: , valueId: }]' after sku_pic_url; | ||
| 8 | - | ||
| 9 | --- 2.修复已有数据 | ||
| 10 | -update product_comment pc | ||
| 11 | - join product_sku ps on pc.spu_id = ps.spu_id | ||
| 12 | -set pc.sku_pic_url = ps.pic_url, | ||
| 13 | - pc.sku_properties = ps.properties | ||
| 14 | -where pc.sku_id is not null; | ||
| 15 | \ No newline at end of file | 0 | \ No newline at end of file |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/ProductCommentController.java
| @@ -32,7 +32,7 @@ public class ProductCommentController { | @@ -32,7 +32,7 @@ public class ProductCommentController { | ||
| 32 | @PreAuthorize("@ss.hasPermission('product:comment:query')") | 32 | @PreAuthorize("@ss.hasPermission('product:comment:query')") |
| 33 | public CommonResult<PageResult<ProductCommentRespVO>> getCommentPage(@Valid ProductCommentPageReqVO pageVO) { | 33 | public CommonResult<PageResult<ProductCommentRespVO>> getCommentPage(@Valid ProductCommentPageReqVO pageVO) { |
| 34 | PageResult<ProductCommentDO> pageResult = productCommentService.getCommentPage(pageVO); | 34 | PageResult<ProductCommentDO> pageResult = productCommentService.getCommentPage(pageVO); |
| 35 | - return success(ProductCommentConvert.INSTANCE.convertPage2(pageResult)); | 35 | + return success(ProductCommentConvert.INSTANCE.convertPage(pageResult)); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | @PutMapping("/update-visible") | 38 | @PutMapping("/update-visible") |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/comment/vo/ProductCommentRespVO.java
| 1 | package cn.iocoder.yudao.module.product.controller.admin.comment.vo; | 1 | package cn.iocoder.yudao.module.product.controller.admin.comment.vo; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuBaseVO; | ||
| 3 | import io.swagger.v3.oas.annotations.media.Schema; | 4 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | import lombok.Data; | 5 | import lombok.Data; |
| 5 | import lombok.EqualsAndHashCode; | 6 | import lombok.EqualsAndHashCode; |
| @@ -7,6 +8,7 @@ import lombok.ToString; | @@ -7,6 +8,7 @@ import lombok.ToString; | ||
| 7 | 8 | ||
| 8 | import javax.validation.constraints.NotNull; | 9 | import javax.validation.constraints.NotNull; |
| 9 | import java.time.LocalDateTime; | 10 | import java.time.LocalDateTime; |
| 11 | +import java.util.List; | ||
| 10 | 12 | ||
| 11 | @Schema(description = "管理后台 - 商品评价 Response VO") | 13 | @Schema(description = "管理后台 - 商品评价 Response VO") |
| 12 | @Data | 14 | @Data |
| @@ -23,10 +25,10 @@ public class ProductCommentRespVO extends ProductCommentBaseVO { | @@ -23,10 +25,10 @@ public class ProductCommentRespVO extends ProductCommentBaseVO { | ||
| 23 | @Schema(description = "交易订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24428") | 25 | @Schema(description = "交易订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "24428") |
| 24 | private Long orderId; | 26 | private Long orderId; |
| 25 | 27 | ||
| 26 | - @Schema(description = "是否可见:[true:显示 false:隐藏]", requiredMode = Schema.RequiredMode.REQUIRED) | 28 | + @Schema(description = "是否可见", requiredMode = Schema.RequiredMode.REQUIRED) |
| 27 | private Boolean visible; | 29 | private Boolean visible; |
| 28 | 30 | ||
| 29 | - @Schema(description = "商家是否回复:[1:回复 0:未回复]", requiredMode = Schema.RequiredMode.REQUIRED) | 31 | + @Schema(description = "商家是否回复", requiredMode = Schema.RequiredMode.REQUIRED) |
| 30 | private Boolean replyStatus; | 32 | private Boolean replyStatus; |
| 31 | 33 | ||
| 32 | @Schema(description = "回复管理员编号", example = "9527") | 34 | @Schema(description = "回复管理员编号", example = "9527") |
| @@ -54,4 +56,8 @@ public class ProductCommentRespVO extends ProductCommentBaseVO { | @@ -54,4 +56,8 @@ public class ProductCommentRespVO extends ProductCommentBaseVO { | ||
| 54 | 56 | ||
| 55 | @Schema(description = "商品 SKU 图片地址", example = "https://www.iocoder.cn/yudao.jpg") | 57 | @Schema(description = "商品 SKU 图片地址", example = "https://www.iocoder.cn/yudao.jpg") |
| 56 | private String skuPicUrl; | 58 | private String skuPicUrl; |
| 59 | + | ||
| 60 | + @Schema(description = "商品 SKU 规格值数组") | ||
| 61 | + private List<ProductSkuBaseVO.Property> skuProperties; | ||
| 62 | + | ||
| 57 | } | 63 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/ProductSkuController.java
| 1 | package cn.iocoder.yudao.module.product.controller.admin.sku; | 1 | package cn.iocoder.yudao.module.product.controller.admin.sku; |
| 2 | 2 | ||
| 3 | -import cn.hutool.core.collection.CollUtil; | ||
| 4 | -import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 5 | -import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | ||
| 6 | -import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuOptionRespVO; | ||
| 7 | -import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert; | ||
| 8 | -import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; | ||
| 9 | -import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; | ||
| 10 | -import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; | ||
| 11 | -import cn.iocoder.yudao.module.product.service.spu.ProductSpuService; | ||
| 12 | -import io.swagger.v3.oas.annotations.Operation; | ||
| 13 | import io.swagger.v3.oas.annotations.tags.Tag; | 3 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 14 | import org.springframework.validation.annotation.Validated; | 4 | import org.springframework.validation.annotation.Validated; |
| 15 | -import org.springframework.web.bind.annotation.GetMapping; | ||
| 16 | import org.springframework.web.bind.annotation.RequestMapping; | 5 | import org.springframework.web.bind.annotation.RequestMapping; |
| 17 | import org.springframework.web.bind.annotation.RestController; | 6 | import org.springframework.web.bind.annotation.RestController; |
| 18 | 7 | ||
| 19 | -import javax.annotation.Resource; | ||
| 20 | -import java.util.Collections; | ||
| 21 | -import java.util.List; | ||
| 22 | -import java.util.Map; | ||
| 23 | - | ||
| 24 | -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 25 | -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | ||
| 26 | - | ||
| 27 | -@Tag(name = "管理后台 - 商品 sku") | 8 | +@Tag(name = "管理后台 - 商品 SKU") |
| 28 | @RestController | 9 | @RestController |
| 29 | @RequestMapping("/product/sku") | 10 | @RequestMapping("/product/sku") |
| 30 | @Validated | 11 | @Validated |
| 31 | public class ProductSkuController { | 12 | public class ProductSkuController { |
| 32 | 13 | ||
| 33 | - @Resource | ||
| 34 | - private ProductSkuService productSkuService; | ||
| 35 | - @Resource | ||
| 36 | - private ProductSpuService productSpuService; | ||
| 37 | - | ||
| 38 | - @GetMapping("/get-option-list") | ||
| 39 | - @Operation(summary = "获得商品 SKU 选项的列表") | ||
| 40 | -// @PreAuthorize("@ss.hasPermission('product:sku:query')") | ||
| 41 | - public CommonResult<List<ProductSkuOptionRespVO>> getSkuOptionList() { | ||
| 42 | - // 获得 SKU 列表 | ||
| 43 | - List<ProductSkuDO> skus = productSkuService.getSkuList(); | ||
| 44 | - if (CollUtil.isEmpty(skus)) { | ||
| 45 | - return success(Collections.emptyList()); | ||
| 46 | - } | ||
| 47 | - | ||
| 48 | - // 获得对应的 SPU 映射 | ||
| 49 | - Map<Long, ProductSpuDO> spuMap = productSpuService.getSpuMap(convertSet(skus, ProductSkuDO::getSpuId)); | ||
| 50 | - // 转换为返回结果 | ||
| 51 | - List<ProductSkuOptionRespVO> skuVOs = ProductSkuConvert.INSTANCE.convertList05(skus); | ||
| 52 | - skuVOs.forEach(sku -> MapUtils.findAndThen(spuMap, sku.getSpuId(), | ||
| 53 | - spu -> sku.setSpuId(spu.getId()).setSpuName(spu.getName()))); | ||
| 54 | - return success(skuVOs); | ||
| 55 | - } | ||
| 56 | - | ||
| 57 | } | 14 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuOptionRespVO.java deleted
| 1 | -package cn.iocoder.yudao.module.product.controller.admin.sku.vo; | ||
| 2 | - | ||
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | -import lombok.Data; | ||
| 5 | - | ||
| 6 | -@Schema(description = "管理后台 - 商品 SKU 选项 Response VO") // 用于前端 SELECT 选项 | ||
| 7 | -@Data | ||
| 8 | -public class ProductSkuOptionRespVO { | ||
| 9 | - | ||
| 10 | - @Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | ||
| 11 | - private Long id; | ||
| 12 | - | ||
| 13 | - @Schema(description = "商品 SKU 名字", example = "红色") | ||
| 14 | - private String name; | ||
| 15 | - | ||
| 16 | - @Schema(description = "销售价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") | ||
| 17 | - private String price; | ||
| 18 | - | ||
| 19 | - @Schema(description = "库存", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") | ||
| 20 | - private Integer stock; | ||
| 21 | - | ||
| 22 | - // ========== 商品 SPU 信息 ========== | ||
| 23 | - | ||
| 24 | - @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | ||
| 25 | - private Long spuId; | ||
| 26 | - | ||
| 27 | - @Schema(description = "商品 SPU 名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "iPhone 11") | ||
| 28 | - private String spuName; | ||
| 29 | - | ||
| 30 | -} |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/comment/ProductCommentConvert.java
| 1 | package cn.iocoder.yudao.module.product.convert.comment; | 1 | package cn.iocoder.yudao.module.product.convert.comment; |
| 2 | 2 | ||
| 3 | -import cn.hutool.core.collection.CollUtil; | ||
| 4 | import cn.hutool.core.util.ObjectUtil; | 3 | import cn.hutool.core.util.ObjectUtil; |
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | 5 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| @@ -23,10 +22,7 @@ import java.math.BigDecimal; | @@ -23,10 +22,7 @@ import java.math.BigDecimal; | ||
| 23 | import java.math.RoundingMode; | 22 | import java.math.RoundingMode; |
| 24 | import java.util.List; | 23 | import java.util.List; |
| 25 | import java.util.Map; | 24 | import java.util.Map; |
| 26 | -import java.util.Objects; | ||
| 27 | -import java.util.stream.Collectors; | ||
| 28 | 25 | ||
| 29 | -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | ||
| 30 | import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; | 26 | import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen; |
| 31 | 27 | ||
| 32 | /** | 28 | /** |
| @@ -122,35 +118,15 @@ public interface ProductCommentConvert { | @@ -122,35 +118,15 @@ public interface ProductCommentConvert { | ||
| 122 | 118 | ||
| 123 | List<AppProductCommentRespVO> convertList02(List<ProductCommentDO> list); | 119 | List<AppProductCommentRespVO> convertList02(List<ProductCommentDO> list); |
| 124 | 120 | ||
| 125 | - default ProductCommentDO convert(ProductCommentCreateReqVO createReq, ProductSpuDO spuDO, ProductSkuDO skuDO) { | 121 | + default ProductCommentDO convert(ProductCommentCreateReqVO createReq, ProductSpuDO spu, ProductSkuDO sku) { |
| 126 | ProductCommentDO commentDO = convert(createReq); | 122 | ProductCommentDO commentDO = convert(createReq); |
| 127 | - if (spuDO != null) { | ||
| 128 | - commentDO.setSpuId(spuDO.getId()); | ||
| 129 | - commentDO.setSpuName(spuDO.getName()); | 123 | + if (spu != null) { |
| 124 | + commentDO.setSpuId(spu.getId()).setSpuName(spu.getName()); | ||
| 130 | } | 125 | } |
| 131 | - if (skuDO != null) { | ||
| 132 | - commentDO.setSkuPicUrl(skuDO.getPicUrl()); | ||
| 133 | - commentDO.setSkuProperties(skuDO.getProperties()); | 126 | + if (sku != null) { |
| 127 | + commentDO.setSkuPicUrl(sku.getPicUrl()).setSkuProperties(sku.getProperties()); | ||
| 134 | } | 128 | } |
| 135 | return commentDO; | 129 | return commentDO; |
| 136 | } | 130 | } |
| 137 | 131 | ||
| 138 | - default PageResult<ProductCommentRespVO> convertPage2(PageResult<ProductCommentDO> pageResult) { | ||
| 139 | - Map<Long, List<ProductSkuDO.Property>> propertiesMap = convertMap(pageResult.getList(), | ||
| 140 | - ProductCommentDO::getId, | ||
| 141 | - // 这里会有NULL异常, 需要处理一下 | ||
| 142 | - comment -> CollUtil.emptyIfNull(comment.getSkuProperties())); | ||
| 143 | - | ||
| 144 | - PageResult<ProductCommentRespVO> result = convertPage(pageResult); | ||
| 145 | - for (ProductCommentRespVO vo : result.getList()) { | ||
| 146 | - findAndThen(propertiesMap, vo.getId(), properties -> { | ||
| 147 | - String propertyNames = properties.stream() | ||
| 148 | - .map(ProductSkuDO.Property::getValueName) | ||
| 149 | - .filter(Objects::nonNull) | ||
| 150 | - .collect(Collectors.joining(" ")); | ||
| 151 | - vo.setSpuName(vo.getSpuName() + " " + propertyNames); | ||
| 152 | - }); | ||
| 153 | - } | ||
| 154 | - return result; | ||
| 155 | - } | ||
| 156 | } | 132 | } |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/sku/ProductSkuConvert.java
| @@ -5,7 +5,6 @@ import cn.hutool.core.util.StrUtil; | @@ -5,7 +5,6 @@ import cn.hutool.core.util.StrUtil; | ||
| 5 | import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; | 5 | import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; |
| 6 | import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO; | 6 | import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuUpdateStockReqDTO; |
| 7 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO; | 7 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuCreateOrUpdateReqVO; |
| 8 | -import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuOptionRespVO; | ||
| 9 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO; | 8 | import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuRespVO; |
| 10 | import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; | 9 | import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; |
| 11 | import org.mapstruct.Mapper; | 10 | import org.mapstruct.Mapper; |
| @@ -44,8 +43,6 @@ public interface ProductSkuConvert { | @@ -44,8 +43,6 @@ public interface ProductSkuConvert { | ||
| 44 | 43 | ||
| 45 | List<ProductSkuRespDTO> convertList04(List<ProductSkuDO> list); | 44 | List<ProductSkuRespDTO> convertList04(List<ProductSkuDO> list); |
| 46 | 45 | ||
| 47 | - List<ProductSkuOptionRespVO> convertList05(List<ProductSkuDO> skus); | ||
| 48 | - | ||
| 49 | /** | 46 | /** |
| 50 | * 获得 SPU 的库存变化 Map | 47 | * 获得 SPU 的库存变化 Map |
| 51 | * | 48 | * |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/comment/ProductCommentDO.java
| @@ -73,11 +73,14 @@ public class ProductCommentDO extends BaseDO { | @@ -73,11 +73,14 @@ public class ProductCommentDO extends BaseDO { | ||
| 73 | 73 | ||
| 74 | /** | 74 | /** |
| 75 | * 商品 SPU 编号 | 75 | * 商品 SPU 编号 |
| 76 | + * | ||
| 76 | * 关联 {@link ProductSpuDO#getId()} | 77 | * 关联 {@link ProductSpuDO#getId()} |
| 77 | */ | 78 | */ |
| 78 | private Long spuId; | 79 | private Long spuId; |
| 79 | /** | 80 | /** |
| 80 | * 商品 SPU 名称 | 81 | * 商品 SPU 名称 |
| 82 | + * | ||
| 83 | + * 关联 {@link ProductSpuDO#getName()} | ||
| 81 | */ | 84 | */ |
| 82 | private String spuName; | 85 | private String spuName; |
| 83 | /** | 86 | /** |
| @@ -88,10 +91,14 @@ public class ProductCommentDO extends BaseDO { | @@ -88,10 +91,14 @@ public class ProductCommentDO extends BaseDO { | ||
| 88 | private Long skuId; | 91 | private Long skuId; |
| 89 | /** | 92 | /** |
| 90 | * 商品 SKU 图片地址 | 93 | * 商品 SKU 图片地址 |
| 94 | + * | ||
| 95 | + * 关联 {@link ProductSkuDO#getPicUrl()} | ||
| 91 | */ | 96 | */ |
| 92 | private String skuPicUrl; | 97 | private String skuPicUrl; |
| 93 | /** | 98 | /** |
| 94 | * 属性数组,JSON 格式 | 99 | * 属性数组,JSON 格式 |
| 100 | + * | ||
| 101 | + * 关联 {@link ProductSkuDO#getProperties()} | ||
| 95 | */ | 102 | */ |
| 96 | @TableField(typeHandler = ProductSkuDO.PropertyTypeHandler.class) | 103 | @TableField(typeHandler = ProductSkuDO.PropertyTypeHandler.class) |
| 97 | private List<ProductSkuDO.Property> skuProperties; | 104 | private List<ProductSkuDO.Property> skuProperties; |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/point/MemberPointRecordServiceImpl.java
| @@ -81,17 +81,12 @@ public class MemberPointRecordServiceImpl implements MemberPointRecordService { | @@ -81,17 +81,12 @@ public class MemberPointRecordServiceImpl implements MemberPointRecordService { | ||
| 81 | // 2. 增加积分记录 | 81 | // 2. 增加积分记录 |
| 82 | MemberUserDO user = memberUserService.getUser(userId); | 82 | MemberUserDO user = memberUserService.getUser(userId); |
| 83 | Integer userPoint = ObjectUtil.defaultIfNull(user.getPoint(), 0); | 83 | Integer userPoint = ObjectUtil.defaultIfNull(user.getPoint(), 0); |
| 84 | - // 用户变动后的积分 | ||
| 85 | - Integer totalPoint = userPoint + point; | ||
| 86 | - MemberPointRecordDO recordDO = new MemberPointRecordDO() | ||
| 87 | - .setUserId(userId) | ||
| 88 | - .setBizId(bizId) | ||
| 89 | - .setBizType(bizType.getType()) | ||
| 90 | - .setTitle(bizType.getName()) | ||
| 91 | - .setDescription(StrUtil.format(bizType.getDescription(), point)) | ||
| 92 | - .setPoint(point) | ||
| 93 | - .setTotalPoint(totalPoint); | ||
| 94 | - recordMapper.insert(recordDO); | 84 | + Integer totalPoint = userPoint + point; // 用户变动后的积分 |
| 85 | + MemberPointRecordDO record = new MemberPointRecordDO() | ||
| 86 | + .setUserId(userId).setBizId(bizId).setBizType(bizType.getType()) | ||
| 87 | + .setTitle(bizType.getName()).setDescription(StrUtil.format(bizType.getDescription(), point)) | ||
| 88 | + .setPoint(point).setTotalPoint(totalPoint); | ||
| 89 | + recordMapper.insert(record); | ||
| 95 | 90 | ||
| 96 | // 3. 更新用户积分 | 91 | // 3. 更新用户积分 |
| 97 | memberUserService.updateUserPoint(userId, totalPoint); | 92 | memberUserService.updateUserPoint(userId, totalPoint); |