Explorar o código

feat(app): 增加热门搜索功能并优化搜索逻辑

- 新增热词查询接口和相关服务方法
- 实现搜索关键词的统计和更新逻辑
- 添加热门搜索相关的实体类和映射
- 优化搜索功能,支持关键词热度统计
- 在 Shiro 配置中添加 APP首页接口的匿名访问权限
SheepHy hai 2 semanas
pai
achega
6da79224ef

+ 1 - 0
national-motion-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java

@@ -100,6 +100,7 @@ public class ShiroConfig {
         filterChainDefinitionMap.put("/auth/2step-code", "anon");//登录验证码
         filterChainDefinitionMap.put("/sys/common/static/**", "anon");//图片预览 &下载文件不限制token
         filterChainDefinitionMap.put("/sys/common/pdf/**", "anon");//pdf预览
+        filterChainDefinitionMap.put("/app/home/**", "anon");//APP首页接口
 
         filterChainDefinitionMap.put("/app/user/**", "anon");//小程序相关
 

+ 13 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/controller/AppHomeController.java

@@ -14,6 +14,7 @@ import org.jeecg.modules.app.vo.HomeVO;
 import org.jeecg.modules.app.vo.MsgInfoVO;
 import org.jeecg.modules.app.vo.MsgVO;
 import org.jeecg.modules.app.vo.PlaceVO;
+import org.jeecg.modules.system.app.entity.AppSearchHot;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
@@ -84,4 +85,16 @@ public class AppHomeController {
     public Result<Object> search(@RequestBody SearchDTO searchDTO){
         return Result.ok(appHomeService.search(searchDTO));
     }
+
+    /**
+     * @Author SheepHy
+     * @Description 热词查询
+     * @Date 17:12 2025/7/7
+     * @return List<AppSearchHot>
+     **/
+    @GetMapping("/getHotSearch")
+    @Operation(summary = "热词查询")
+    public Result<List<AppSearchHot>> getHotSearch(){
+        return Result.ok(appHomeService.getHotSearch());
+    }
 }

+ 10 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/service/IAppHomeService.java

@@ -6,6 +6,9 @@ import org.jeecg.modules.app.dto.SearchDTO;
 import org.jeecg.modules.app.vo.AppBannerVO;
 import org.jeecg.modules.app.vo.HomeVO;
 import org.jeecg.modules.app.vo.PlaceVO;
+import org.jeecg.modules.system.app.entity.AppSearchHot;
+
+import java.util.List;
 
 public interface IAppHomeService {
 
@@ -35,4 +38,11 @@ public interface IAppHomeService {
      **/
     Object search(SearchDTO searchDTO);
 
+    /**
+     * @Author SheepHy
+     * @Description 热词查询
+     * @Date 17:12 2025/7/7
+     * @return List<AppSearchHot>
+     **/
+    List<AppSearchHot> getHotSearch();
 }

+ 22 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/service/impl/AppHomeServiceImpl.java

@@ -9,6 +9,7 @@ import org.jeecg.modules.app.vo.*;
 import org.jeecg.modules.system.app.entity.AppBanner;
 import org.jeecg.modules.system.app.entity.AppCourses;
 import org.jeecg.modules.system.app.entity.AppInstructor;
+import org.jeecg.modules.system.app.entity.AppSearchHot;
 import org.jeecg.modules.system.app.mapper.*;
 import org.jeecg.modules.system.entity.SysDepart;
 import org.jeecg.modules.system.entity.SysUser;
@@ -43,6 +44,8 @@ public class AppHomeServiceImpl implements IAppHomeService {
     private AppCategoryMapper appCategoryMapper;
     @Resource
     private AppGameMapper appGameMapper;
+    @Resource
+    private AppSearchHotMapper appSearchHotMapper;
 
     @Override
     public HomeVO homeInfo() {
@@ -164,6 +167,18 @@ public class AppHomeServiceImpl implements IAppHomeService {
 
     @Override
     public Object search(SearchDTO searchDTO) {
+        AppSearchHot appSearchHot = appSearchHotMapper.selectOne(Wrappers.<AppSearchHot>lambdaQuery()
+                .eq(AppSearchHot::getSearchContent, searchDTO.getKeyword())
+                .last("LIMIT 1"));
+        if(null == appSearchHot){
+            appSearchHotMapper.insert(new AppSearchHot()
+                    .setSearchContent(searchDTO.getKeyword())
+                    .setSearchCount(1)
+                    .setIsActive(1)
+                    .setIsRecommend(0));
+        }else {
+            appSearchHotMapper.updateById(appSearchHot.setSearchCount(appSearchHot.getSearchCount() + 1));
+        }
         switch (searchDTO.getVenueType().charAt(0)) {
             case '0':
                     return convertSearchPlaceVOPage(searchDTO);
@@ -176,6 +191,13 @@ public class AppHomeServiceImpl implements IAppHomeService {
         }
         return new Page<>();
     }
+
+    @Override
+    public List<AppSearchHot> getHotSearch() {
+        return appSearchHotMapper.selectList(Wrappers.<AppSearchHot>lambdaQuery()
+                .last("LIMIT 10").orderByDesc(AppSearchHot::getSearchCount));
+    }
+
     /**
      * @Author SheepHy
      * @Description 全局搜索场地分页查询

+ 16 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/vo/PlaceInfoVO.java

@@ -0,0 +1,16 @@
+package org.jeecg.modules.app.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+@Data
+@Accessors(chain = true)
+@EqualsAndHashCode(callSuper = false)
+@Schema(description="场地详情返回参数")
+public class PlaceInfoVO {
+    @Schema(description = "场地id")
+    private String id;
+
+}

+ 3 - 3
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/system/app/entity/AppSearchHot.java

@@ -28,13 +28,13 @@ public class AppSearchHot implements Serializable {
     @Schema(description = "id")
     private String id;
     @Schema(description = "搜索次数")
-    private String searchCount;
+    private int searchCount;
     @Schema(description = "搜索内容")
     private String searchContent;
     @Schema(description = "是否启用")
-    private String isActive;
+    private int isActive;
     @Schema(description = "是否推荐")
-    private String isRecommend;
+    private int isRecommend;
     @Schema(description = "关联分类ID")
     private String categoryId;
     @Schema(description = "最后一次搜索用户ID")