Commit 65ef6ff5eda58f1876efda90c760f53ab080178d

Authored by YunaiV
2 parents 63303539 a1aa0551

Merge branch 'develop' of https://gitee.com/zhijiantianya/ruoyi-vue-pro into develop

yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/history/ProductBrowseHistoryController.java
1 package cn.iocoder.yudao.module.product.controller.admin.history; 1 package cn.iocoder.yudao.module.product.controller.admin.history;
2 2
  3 +import cn.hutool.core.collection.CollUtil;
3 import cn.iocoder.yudao.framework.common.pojo.CommonResult; 4 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
4 import cn.iocoder.yudao.framework.common.pojo.PageResult; 5 import cn.iocoder.yudao.framework.common.pojo.PageResult;
5 import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 6 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
6 import cn.iocoder.yudao.module.product.controller.admin.history.vo.ProductBrowseHistoryPageReqVO; 7 import cn.iocoder.yudao.module.product.controller.admin.history.vo.ProductBrowseHistoryPageReqVO;
7 import cn.iocoder.yudao.module.product.controller.admin.history.vo.ProductBrowseHistoryRespVO; 8 import cn.iocoder.yudao.module.product.controller.admin.history.vo.ProductBrowseHistoryRespVO;
8 import cn.iocoder.yudao.module.product.dal.dataobject.history.ProductBrowseHistoryDO; 9 import cn.iocoder.yudao.module.product.dal.dataobject.history.ProductBrowseHistoryDO;
  10 +import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
9 import cn.iocoder.yudao.module.product.service.history.ProductBrowseHistoryService; 11 import cn.iocoder.yudao.module.product.service.history.ProductBrowseHistoryService;
  12 +import cn.iocoder.yudao.module.product.service.spu.ProductSpuService;
10 import io.swagger.v3.oas.annotations.Operation; 13 import io.swagger.v3.oas.annotations.Operation;
11 import io.swagger.v3.oas.annotations.tags.Tag; 14 import io.swagger.v3.oas.annotations.tags.Tag;
12 import jakarta.annotation.Resource; 15 import jakarta.annotation.Resource;
@@ -17,7 +20,13 @@ import org.springframework.web.bind.annotation.GetMapping; @@ -17,7 +20,13 @@ import org.springframework.web.bind.annotation.GetMapping;
17 import org.springframework.web.bind.annotation.RequestMapping; 20 import org.springframework.web.bind.annotation.RequestMapping;
18 import org.springframework.web.bind.annotation.RestController; 21 import org.springframework.web.bind.annotation.RestController;
19 22
  23 +import java.util.Map;
  24 +import java.util.Optional;
  25 +import java.util.Set;
  26 +
20 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; 27 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  28 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
  29 +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
21 30
22 @Tag(name = "管理后台 - 商品浏览记录") 31 @Tag(name = "管理后台 - 商品浏览记录")
23 @RestController 32 @RestController
@@ -27,13 +36,24 @@ public class ProductBrowseHistoryController { @@ -27,13 +36,24 @@ public class ProductBrowseHistoryController {
27 36
28 @Resource 37 @Resource
29 private ProductBrowseHistoryService browseHistoryService; 38 private ProductBrowseHistoryService browseHistoryService;
  39 + @Resource
  40 + private ProductSpuService productSpuService;
30 41
31 @GetMapping("/page") 42 @GetMapping("/page")
32 @Operation(summary = "获得商品浏览记录分页") 43 @Operation(summary = "获得商品浏览记录分页")
33 @PreAuthorize("@ss.hasPermission('product:browse-history:query')") 44 @PreAuthorize("@ss.hasPermission('product:browse-history:query')")
34 public CommonResult<PageResult<ProductBrowseHistoryRespVO>> getBrowseHistoryPage(@Valid ProductBrowseHistoryPageReqVO pageReqVO) { 45 public CommonResult<PageResult<ProductBrowseHistoryRespVO>> getBrowseHistoryPage(@Valid ProductBrowseHistoryPageReqVO pageReqVO) {
35 PageResult<ProductBrowseHistoryDO> pageResult = browseHistoryService.getBrowseHistoryPage(pageReqVO); 46 PageResult<ProductBrowseHistoryDO> pageResult = browseHistoryService.getBrowseHistoryPage(pageReqVO);
36 - return success(BeanUtils.toBean(pageResult, ProductBrowseHistoryRespVO.class)); 47 + if (CollUtil.isEmpty(pageResult.getList())) {
  48 + return success(PageResult.empty());
  49 + }
  50 +
  51 + // 得到商品 spu 信息
  52 + Set<Long> spuIds = convertSet(pageResult.getList(), ProductBrowseHistoryDO::getSpuId);
  53 + Map<Long, ProductSpuDO> spuMap = convertMap(productSpuService.getSpuList(spuIds), ProductSpuDO::getId);
  54 + return success(BeanUtils.toBean(pageResult, ProductBrowseHistoryRespVO.class,
  55 + vo -> Optional.ofNullable(spuMap.get(vo.getSpuId()))
  56 + .ifPresent(spu -> vo.setSpuName(spu.getName()).setPicUrl(spu.getPicUrl()).setPrice(spu.getPrice()))));
37 } 57 }
38 58
39 } 59 }
40 \ No newline at end of file 60 \ No newline at end of file
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/history/vo/ProductBrowseHistoryRespVO.java
@@ -7,28 +7,28 @@ import lombok.Data; @@ -7,28 +7,28 @@ import lombok.Data;
7 7
8 import java.time.LocalDateTime; 8 import java.time.LocalDateTime;
9 9
  10 +import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;
  11 +
10 @Schema(description = "管理后台 - 商品浏览记录 Response VO") 12 @Schema(description = "管理后台 - 商品浏览记录 Response VO")
11 @Data 13 @Data
12 @ExcelIgnoreUnannotated 14 @ExcelIgnoreUnannotated
13 public class ProductBrowseHistoryRespVO { 15 public class ProductBrowseHistoryRespVO {
14 16
15 - @Schema(description = "记录编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "26055")  
16 - @ExcelProperty("记录编号") 17 + @Schema(description = "编号", requiredMode = REQUIRED, example = "1")
17 private Long id; 18 private Long id;
18 19
19 - @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "4314")  
20 - @ExcelProperty("用户编号")  
21 - private Long userId; 20 + @Schema(description = "商品 SPU 编号", requiredMode = REQUIRED, example = "29502")
  21 + private Long spuId;
  22 +
  23 + // ========== 商品相关字段 ==========
22 24
23 - @Schema(description = "用户是否删除", example = "false")  
24 - private Boolean userDeleted; 25 + @Schema(description = "商品 SPU 名称", example = "赵六")
  26 + private String spuName;
25 27
26 - @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "42")  
27 - @ExcelProperty("商品 SPU 编号")  
28 - private Long spuId; 28 + @Schema(description = "商品封面图", example = "https://domain/pic.png")
  29 + private String picUrl;
29 30
30 - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)  
31 - @ExcelProperty("创建时间")  
32 - private LocalDateTime createTime; 31 + @Schema(description = "商品单价", example = "100")
  32 + private Integer price;
33 33
34 } 34 }
35 \ No newline at end of file 35 \ No newline at end of file