Commit 65ef6ff5eda58f1876efda90c760f53ab080178d
Merge branch 'develop' of https://gitee.com/zhijiantianya/ruoyi-vue-pro into develop
Showing
2 changed files
with
34 additions
and
14 deletions
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/history/ProductBrowseHistoryController.java
| 1 | 1 | package cn.iocoder.yudao.module.product.controller.admin.history; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 3 | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 4 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | 6 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 6 | 7 | import cn.iocoder.yudao.module.product.controller.admin.history.vo.ProductBrowseHistoryPageReqVO; |
| 7 | 8 | import cn.iocoder.yudao.module.product.controller.admin.history.vo.ProductBrowseHistoryRespVO; |
| 8 | 9 | import cn.iocoder.yudao.module.product.dal.dataobject.history.ProductBrowseHistoryDO; |
| 10 | +import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO; | |
| 9 | 11 | import cn.iocoder.yudao.module.product.service.history.ProductBrowseHistoryService; |
| 12 | +import cn.iocoder.yudao.module.product.service.spu.ProductSpuService; | |
| 10 | 13 | import io.swagger.v3.oas.annotations.Operation; |
| 11 | 14 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 12 | 15 | import jakarta.annotation.Resource; |
| ... | ... | @@ -17,7 +20,13 @@ import org.springframework.web.bind.annotation.GetMapping; |
| 17 | 20 | import org.springframework.web.bind.annotation.RequestMapping; |
| 18 | 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 | 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 | 31 | @Tag(name = "管理后台 - 商品浏览记录") |
| 23 | 32 | @RestController |
| ... | ... | @@ -27,13 +36,24 @@ public class ProductBrowseHistoryController { |
| 27 | 36 | |
| 28 | 37 | @Resource |
| 29 | 38 | private ProductBrowseHistoryService browseHistoryService; |
| 39 | + @Resource | |
| 40 | + private ProductSpuService productSpuService; | |
| 30 | 41 | |
| 31 | 42 | @GetMapping("/page") |
| 32 | 43 | @Operation(summary = "获得商品浏览记录分页") |
| 33 | 44 | @PreAuthorize("@ss.hasPermission('product:browse-history:query')") |
| 34 | 45 | public CommonResult<PageResult<ProductBrowseHistoryRespVO>> getBrowseHistoryPage(@Valid ProductBrowseHistoryPageReqVO pageReqVO) { |
| 35 | 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 | 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 | 7 | |
| 8 | 8 | import java.time.LocalDateTime; |
| 9 | 9 | |
| 10 | +import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED; | |
| 11 | + | |
| 10 | 12 | @Schema(description = "管理后台 - 商品浏览记录 Response VO") |
| 11 | 13 | @Data |
| 12 | 14 | @ExcelIgnoreUnannotated |
| 13 | 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 | 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 | 35 | \ No newline at end of file | ... | ... |