From efdb99f8cecc4afb592afad79c761081d5d5cf22 Mon Sep 17 00:00:00 2001 From: lee <4766465@qq.com> Date: Wed, 18 Dec 2024 13:27:00 +0800 Subject: [PATCH] init --- yami-shop-api/src/main/java/com/yami/shop/api/controller/SearchController.java | 80 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 80 insertions(+), 0 deletions(-) diff --git a/yami-shop-api/src/main/java/com/yami/shop/api/controller/SearchController.java b/yami-shop-api/src/main/java/com/yami/shop/api/controller/SearchController.java new file mode 100644 index 0000000..3db1c17 --- /dev/null +++ b/yami-shop-api/src/main/java/com/yami/shop/api/controller/SearchController.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved. + * + * https://www.mall4j.com/ + * + * 未经允许,不可做商业用途! + * + * 版权所有,侵权必究! + */ +package com.yami.shop.api.controller; + + +import cn.hutool.core.collection.CollectionUtil; +import com.yami.shop.bean.dto.HotSearchDto; +import com.yami.shop.common.response.ServerResponseEntity; +import com.yami.shop.service.HotSearchService; +import com.yami.shop.service.ProductService; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; +import io.swagger.v3.oas.annotations.Operation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Collections; +import java.util.List; + +/** + * @author LGH + */ +@RestController +@RequestMapping("/search") +@Tag(name = "搜索接口") +public class SearchController { + + @Autowired + private HotSearchService hotSearchService; + + @Autowired + private ProductService productService; + + @GetMapping("/hotSearchByShopId") + @Operation(summary = "查看店铺热搜" , description = "根据店铺id,热搜数量获取热搜") + @Parameters({ + @Parameter(name = "shopId", description = "店铺id" , required = true), + @Parameter(name = "number", description = "取数" , required = true), + @Parameter(name = "sort", description = "是否按照顺序(0 否 1是)" ), + }) + public ServerResponseEntity<List<HotSearchDto>> hotSearchByShopId(Long shopId, Integer number, Integer sort) { + List<HotSearchDto> list = hotSearchService.getHotSearchDtoByshopId(shopId); + return getListResponseEntity(number, sort, list); + } + + @GetMapping("/hotSearch") + @Operation(summary = "查看全局热搜" , description = "根据店铺id,热搜数量获取热搜") + @Parameters({ + @Parameter(name = "number", description = "取数" , required = true), + @Parameter(name = "sort", description = "是否按照顺序(0 否 1是)" ), + }) + public ServerResponseEntity<List<HotSearchDto>> hotSearch(Integer number, Integer sort) { + List<HotSearchDto> list = hotSearchService.getHotSearchDtoByshopId(0L); + return getListResponseEntity(number, sort, list); + } + + private ServerResponseEntity<List<HotSearchDto>> getListResponseEntity(Integer number, Integer sort, List<HotSearchDto> list) { + if (sort == null || sort == 0) { + Collections.shuffle(list); + } +/* if(sort==1){ + Collections.sort(list, new SeqComparator()); // 根据排序号排序 + }*/ + if (!CollectionUtil.isNotEmpty(list) || list.size() < number) { + return ServerResponseEntity.success(list); + } + + return ServerResponseEntity.success(list.subList(0, number)); + } +} -- Gitblit v1.9.3