From 1ecc50b3c94a712289f385e4d9cbae6758760a28 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Wed, 17 Jul 2024 18:36:48 +0800 Subject: [PATCH] =?UTF-8?q?mall:=20=E5=AE=8C=E5=96=84=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E7=AB=AF=E8=8E=B7=E5=BE=97=E5=95=86=E5=93=81=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=88=86=E9=A1=B5=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProductBrowseHistoryController.java | 22 ++++++++++++++- .../vo/ProductBrowseHistoryRespVO.java | 28 +++++++++---------- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/history/ProductBrowseHistoryController.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/history/ProductBrowseHistoryController.java index b87e4ee44..b97c36001 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/history/ProductBrowseHistoryController.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/history/ProductBrowseHistoryController.java @@ -1,12 +1,15 @@ package cn.iocoder.yudao.module.product.controller.admin.history; +import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.module.product.controller.admin.history.vo.ProductBrowseHistoryPageReqVO; import cn.iocoder.yudao.module.product.controller.admin.history.vo.ProductBrowseHistoryRespVO; import cn.iocoder.yudao.module.product.dal.dataobject.history.ProductBrowseHistoryDO; +import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; import cn.iocoder.yudao.module.product.service.history.ProductBrowseHistoryService; +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 jakarta.annotation.Resource; @@ -17,7 +20,13 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.Map; +import java.util.Optional; +import java.util.Set; + import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; @Tag(name = "管理后台 - 商品浏览记录") @RestController @@ -27,13 +36,24 @@ public class ProductBrowseHistoryController { @Resource private ProductBrowseHistoryService browseHistoryService; + @Resource + private ProductSpuService productSpuService; @GetMapping("/page") @Operation(summary = "获得商品浏览记录分页") @PreAuthorize("@ss.hasPermission('product:browse-history:query')") public CommonResult> getBrowseHistoryPage(@Valid ProductBrowseHistoryPageReqVO pageReqVO) { PageResult pageResult = browseHistoryService.getBrowseHistoryPage(pageReqVO); - return success(BeanUtils.toBean(pageResult, ProductBrowseHistoryRespVO.class)); + if (CollUtil.isEmpty(pageResult.getList())) { + return success(PageResult.empty()); + } + + // 得到商品 spu 信息 + Set spuIds = convertSet(pageResult.getList(), ProductBrowseHistoryDO::getSpuId); + Map spuMap = convertMap(productSpuService.getSpuList(spuIds), ProductSpuDO::getId); + return success(BeanUtils.toBean(pageResult, ProductBrowseHistoryRespVO.class, + vo -> Optional.ofNullable(spuMap.get(vo.getSpuId())) + .ifPresent(spu -> vo.setSpuName(spu.getName()).setPicUrl(spu.getPicUrl()).setPrice(spu.getPrice())))); } } \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/history/vo/ProductBrowseHistoryRespVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/history/vo/ProductBrowseHistoryRespVO.java index 0e2e0cbed..012f1602c 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/history/vo/ProductBrowseHistoryRespVO.java +++ b/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; import java.time.LocalDateTime; +import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; + @Schema(description = "管理后台 - 商品浏览记录 Response VO") @Data @ExcelIgnoreUnannotated public class ProductBrowseHistoryRespVO { - @Schema(description = "记录编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "26055") - @ExcelProperty("记录编号") + @Schema(description = "编号", requiredMode = REQUIRED, example = "1") private Long id; - @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "4314") - @ExcelProperty("用户编号") - private Long userId; - - @Schema(description = "用户是否删除", example = "false") - private Boolean userDeleted; - - @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "42") - @ExcelProperty("商品 SPU 编号") + @Schema(description = "商品 SPU 编号", requiredMode = REQUIRED, example = "29502") private Long spuId; - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) - @ExcelProperty("创建时间") - private LocalDateTime createTime; + // ========== 商品相关字段 ========== + + @Schema(description = "商品 SPU 名称", example = "赵六") + private String spuName; + + @Schema(description = "商品封面图", example = "https://domain/pic.png") + private String picUrl; + + @Schema(description = "商品单价", example = "100") + private Integer price; } \ No newline at end of file