Compare commits

...

2 Commits

Author SHA1 Message Date
28ce473568 Merge pull request '客服-最近浏览-字段缺失补充' (#64) from cxw into master
Some checks failed
continuous-integration/drone/push Build is failing
Reviewed-on: #64
2024-10-23 14:09:44 +08:00
8f6e7e168a 客服-最近浏览-字段缺失补充 2024-10-23 12:53:21 +08:00
2 changed files with 46 additions and 2 deletions

View File

@ -1,12 +1,16 @@
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.controller.app.history.vo.AppProductBrowseHistoryRespVO;
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 org.springframework.security.access.prepost.PreAuthorize;
@ -18,7 +22,11 @@ import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.*;
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
@ -28,13 +36,35 @@ public class ProductBrowseHistoryController {
@Resource
private ProductBrowseHistoryService browseHistoryService;
@Resource
private ProductSpuService productSpuService;
@GetMapping("/page")
@Operation(summary = "获得商品浏览记录分页")
@PreAuthorize("@ss.hasPermission('product:browse-history:query')")
public CommonResult<PageResult<ProductBrowseHistoryRespVO>> getBrowseHistoryPage(@Valid ProductBrowseHistoryPageReqVO pageReqVO) {
PageResult<ProductBrowseHistoryDO> pageResult = browseHistoryService.getBrowseHistoryPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, ProductBrowseHistoryRespVO.class));
if (CollUtil.isEmpty(pageResult.getList())) {
return success(PageResult.empty());
}
// 创建空结果列表
List<ProductBrowseHistoryRespVO> resultList = new ArrayList<>();
// 得到商品 spu 信息
Set<Long> spuIds = convertSet(pageResult.getList(), ProductBrowseHistoryDO::getSpuId);
// 得到集合
Map<Long, ProductSpuDO> spuMap = convertMap(productSpuService.getSpuList(spuIds), ProductSpuDO::getId);
for (ProductBrowseHistoryRespVO productBrowseHistoryRespVO : BeanUtils.toBean(pageResult.getList(), ProductBrowseHistoryRespVO.class)) {
ProductSpuDO productSpuDO = spuMap.get(productBrowseHistoryRespVO.getSpuId());
productBrowseHistoryRespVO.setPicUrl(productSpuDO.getPicUrl());
productBrowseHistoryRespVO.setPrice(productSpuDO.getPrice());
productBrowseHistoryRespVO.setSpuName(productSpuDO.getName());
productBrowseHistoryRespVO.setIntroduction(productSpuDO.getIntroduction());
resultList.add(productBrowseHistoryRespVO);
}
PageResult<ProductBrowseHistoryRespVO> result = new PageResult<>();
result.setTotal(pageResult.getTotal());
result.setList(resultList);
return success(result);
}
}

View File

@ -31,4 +31,18 @@ public class ProductBrowseHistoryRespVO {
@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;
@Schema(description = "介绍", example = "100")
private String introduction;
}