Commit 401de3034479bf8787b22fc4e9f6c6b7f9f03c73
1 parent
65ef6ff5
【代码优化】MALL:完善管理端获得商品浏览记录分页接口
Showing
2 changed files
with
14 additions
and
4 deletions
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/history/ProductBrowseHistoryController.java
| ... | ... | @@ -22,10 +22,8 @@ import org.springframework.web.bind.annotation.RestController; |
| 22 | 22 | |
| 23 | 23 | import java.util.Map; |
| 24 | 24 | import java.util.Optional; |
| 25 | -import java.util.Set; | |
| 26 | 25 | |
| 27 | 26 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 28 | -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | |
| 29 | 27 | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; |
| 30 | 28 | |
| 31 | 29 | @Tag(name = "管理后台 - 商品浏览记录") |
| ... | ... | @@ -49,8 +47,8 @@ public class ProductBrowseHistoryController { |
| 49 | 47 | } |
| 50 | 48 | |
| 51 | 49 | // 得到商品 spu 信息 |
| 52 | - Set<Long> spuIds = convertSet(pageResult.getList(), ProductBrowseHistoryDO::getSpuId); | |
| 53 | - Map<Long, ProductSpuDO> spuMap = convertMap(productSpuService.getSpuList(spuIds), ProductSpuDO::getId); | |
| 50 | + Map<Long, ProductSpuDO> spuMap = productSpuService.getSpuMap( | |
| 51 | + convertSet(pageResult.getList(), ProductBrowseHistoryDO::getSpuId)); | |
| 54 | 52 | return success(BeanUtils.toBean(pageResult, ProductBrowseHistoryRespVO.class, |
| 55 | 53 | vo -> Optional.ofNullable(spuMap.get(vo.getSpuId())) |
| 56 | 54 | .ifPresent(spu -> vo.setSpuName(spu.getName()).setPicUrl(spu.getPicUrl()).setPrice(spu.getPrice())))); | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuService.java
| 1 | 1 | package cn.iocoder.yudao.module.product.service.spu; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | |
| 4 | 5 | import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuPageReqVO; |
| 5 | 6 | import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuSaveReqVO; |
| 6 | 7 | import cn.iocoder.yudao.module.product.controller.admin.spu.vo.ProductSpuUpdateStatusReqVO; |
| ... | ... | @@ -59,6 +60,17 @@ public interface ProductSpuService { |
| 59 | 60 | List<ProductSpuDO> getSpuList(Collection<Long> ids); |
| 60 | 61 | |
| 61 | 62 | /** |
| 63 | + * 获得商品 SPU Map | |
| 64 | + * | |
| 65 | + * @param ids 编号数组 | |
| 66 | + * @return 商品 SPU Map | |
| 67 | + */ | |
| 68 | + default Map<Long, ProductSpuDO> getSpuMap(Collection<Long> ids) { | |
| 69 | + List<ProductSpuDO> list = getSpuList(ids); | |
| 70 | + return CollectionUtils.convertMap(list, ProductSpuDO::getId); | |
| 71 | + } | |
| 72 | + | |
| 73 | + /** | |
| 62 | 74 | * 获得指定状态的商品 SPU 列表 |
| 63 | 75 | * |
| 64 | 76 | * @param status 状态 | ... | ... |