mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-11-04 12:18:42 +08:00 
			
		
		
		
	mall: 完善管理端获得商品浏览记录分页接口
This commit is contained in:
		@@ -1,12 +1,15 @@
 | 
				
			|||||||
package cn.iocoder.yudao.module.product.controller.admin.history;
 | 
					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.CommonResult;
 | 
				
			||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
 | 
					import cn.iocoder.yudao.framework.common.pojo.PageResult;
 | 
				
			||||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 | 
					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.ProductBrowseHistoryPageReqVO;
 | 
				
			||||||
import cn.iocoder.yudao.module.product.controller.admin.history.vo.ProductBrowseHistoryRespVO;
 | 
					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.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.history.ProductBrowseHistoryService;
 | 
				
			||||||
 | 
					import cn.iocoder.yudao.module.product.service.spu.ProductSpuService;
 | 
				
			||||||
import io.swagger.v3.oas.annotations.Operation;
 | 
					import io.swagger.v3.oas.annotations.Operation;
 | 
				
			||||||
import io.swagger.v3.oas.annotations.tags.Tag;
 | 
					import io.swagger.v3.oas.annotations.tags.Tag;
 | 
				
			||||||
import jakarta.annotation.Resource;
 | 
					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.RequestMapping;
 | 
				
			||||||
import org.springframework.web.bind.annotation.RestController;
 | 
					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.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 = "管理后台 - 商品浏览记录")
 | 
					@Tag(name = "管理后台 - 商品浏览记录")
 | 
				
			||||||
@RestController
 | 
					@RestController
 | 
				
			||||||
@@ -27,13 +36,24 @@ public class ProductBrowseHistoryController {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Resource
 | 
					    @Resource
 | 
				
			||||||
    private ProductBrowseHistoryService browseHistoryService;
 | 
					    private ProductBrowseHistoryService browseHistoryService;
 | 
				
			||||||
 | 
					    @Resource
 | 
				
			||||||
 | 
					    private ProductSpuService productSpuService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @GetMapping("/page")
 | 
					    @GetMapping("/page")
 | 
				
			||||||
    @Operation(summary = "获得商品浏览记录分页")
 | 
					    @Operation(summary = "获得商品浏览记录分页")
 | 
				
			||||||
    @PreAuthorize("@ss.hasPermission('product:browse-history:query')")
 | 
					    @PreAuthorize("@ss.hasPermission('product:browse-history:query')")
 | 
				
			||||||
    public CommonResult<PageResult<ProductBrowseHistoryRespVO>> getBrowseHistoryPage(@Valid ProductBrowseHistoryPageReqVO pageReqVO) {
 | 
					    public CommonResult<PageResult<ProductBrowseHistoryRespVO>> getBrowseHistoryPage(@Valid ProductBrowseHistoryPageReqVO pageReqVO) {
 | 
				
			||||||
        PageResult<ProductBrowseHistoryDO> pageResult = browseHistoryService.getBrowseHistoryPage(pageReqVO);
 | 
					        PageResult<ProductBrowseHistoryDO> pageResult = browseHistoryService.getBrowseHistoryPage(pageReqVO);
 | 
				
			||||||
        return success(BeanUtils.toBean(pageResult, ProductBrowseHistoryRespVO.class));
 | 
					        if (CollUtil.isEmpty(pageResult.getList())) {
 | 
				
			||||||
 | 
					            return success(PageResult.empty());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // 得到商品 spu 信息
 | 
				
			||||||
 | 
					        Set<Long> spuIds = convertSet(pageResult.getList(), ProductBrowseHistoryDO::getSpuId);
 | 
				
			||||||
 | 
					        Map<Long, ProductSpuDO> 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()))));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -7,28 +7,28 @@ import lombok.Data;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import java.time.LocalDateTime;
 | 
					import java.time.LocalDateTime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Schema(description = "管理后台 - 商品浏览记录 Response VO")
 | 
					@Schema(description = "管理后台 - 商品浏览记录 Response VO")
 | 
				
			||||||
@Data
 | 
					@Data
 | 
				
			||||||
@ExcelIgnoreUnannotated
 | 
					@ExcelIgnoreUnannotated
 | 
				
			||||||
public class ProductBrowseHistoryRespVO {
 | 
					public class ProductBrowseHistoryRespVO {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Schema(description = "记录编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "26055")
 | 
					    @Schema(description = "编号", requiredMode = REQUIRED, example = "1")
 | 
				
			||||||
    @ExcelProperty("记录编号")
 | 
					 | 
				
			||||||
    private Long id;
 | 
					    private Long id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "4314")
 | 
					    @Schema(description = "商品 SPU 编号", requiredMode = REQUIRED, example = "29502")
 | 
				
			||||||
    @ExcelProperty("用户编号")
 | 
					 | 
				
			||||||
    private Long userId;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Schema(description = "用户是否删除", example = "false")
 | 
					 | 
				
			||||||
    private Boolean userDeleted;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Schema(description = "商品 SPU 编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "42")
 | 
					 | 
				
			||||||
    @ExcelProperty("商品 SPU 编号")
 | 
					 | 
				
			||||||
    private Long spuId;
 | 
					    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;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user