Browse Source

优化poi查询

chenendian 1 month ago
parent
commit
1becac58ef

+ 18 - 8
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/controller/yzt/searchController.java

@@ -1,6 +1,7 @@
 package com.onemap.apply.controller.yzt;
 
 import com.onemap.apply.domain.yzt.CollectionDTO;
+import com.onemap.apply.domain.yzt.PoiDTO;
 import com.onemap.apply.domain.yzt.PoiSearchDTO;
 import com.onemap.apply.service.yzt.ISearchService;
 import com.onemap.common.core.web.controller.BaseController;
@@ -9,6 +10,7 @@ import com.onemap.common.security.utils.SecurityUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.List;
 import java.util.Map;
 
 
@@ -61,18 +63,21 @@ public class searchController extends BaseController {
     }
 
 
-
     /**
+     *
      * 分词查询list
      *
      * @return
      */
     @PostMapping("/poiSearchList")
     public RequestResult poiSearchList(@RequestBody PoiSearchDTO poiSearchDTO) {
-        if(poiSearchDTO.getOffset() != null && poiSearchDTO.getLimit() != null) {
-            poiSearchDTO.setOffset(0);
+        try {
+            List<PoiDTO> res = searchService.poiSearch(poiSearchDTO);
+            return RequestResult.success("查询成功!", res);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return RequestResult.error("查询失败!");
         }
-        return searchService.poi(poiSearchDTO);
     }
 
 
@@ -81,14 +86,19 @@ public class searchController extends BaseController {
      *
      * @return
      */
-    @GetMapping("/getPoiByName")
+    @RequestMapping("/getPoiByName")
     public RequestResult getPoiByName(@RequestBody PoiSearchDTO poiSearchDTO) {
-        //return searchService.poi(poiSearchDTO);
-        return RequestResult.success("查询成功!", null);
-    }
+        try {
+            PoiDTO res = searchService.getPoiByName(poiSearchDTO);
+            return RequestResult.success("查询成功!", res);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return RequestResult.error("查询失败!");
+        }
 
 
 
+    }
 
 
 

+ 2 - 3
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/mapper/yzt/SearchMapper.java

@@ -22,9 +22,8 @@ public interface SearchMapper {
 
     Integer bookmarkcount(@Param("name") String name, @Param("type") String type);
 
-    List<PoiDTO>  getPoiByName(@Param("nameList") String nameList);
-
-    List<PoiDTO> poiLikeName(@Param("nameList") String nameList, @Param("limit") Integer limit, @Param("offset") Integer offset);
+    PoiDTO  getPoiByName(@Param("name") String name);
 
+    List<PoiDTO> poiLikeName(@Param("name") String name,@Param("nameList") List<String> nameList, @Param("limit") Integer limit, @Param("offset") Integer offset);
 
 }

+ 23 - 0
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/service/impl/yzt/SearchServiceImpl.java

@@ -75,4 +75,27 @@ public class SearchServiceImpl implements ISearchService {
         }
         return RequestResult.error("删除失败!", 0);
     }
+
+
+    @Override
+    @Slave
+    public List<PoiDTO> poiSearch(PoiSearchDTO poiSearchDTO) {
+        if (poiSearchDTO.getOffset() == null || poiSearchDTO.getOffset() <0 ) {
+            poiSearchDTO.setOffset(0);
+        }
+        List<PoiDTO> res = searchMapper.poiLikeName(poiSearchDTO.getName(), poiSearchDTO.getChildrenWord(), poiSearchDTO.getLimit(), poiSearchDTO.getOffset());
+        return res;
+    }
+
+
+    @Override
+    @Slave
+    public PoiDTO getPoiByName(PoiSearchDTO poiSearchDTO) {
+        PoiDTO res = searchMapper.getPoiByName(poiSearchDTO.getName());
+        return res;
+    }
+
+
+
+
 }

+ 10 - 0
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/service/yzt/ISearchService.java

@@ -1,9 +1,12 @@
 package com.onemap.apply.service.yzt;
 
 import com.onemap.apply.domain.yzt.CollectionDTO;
+import com.onemap.apply.domain.yzt.PoiDTO;
 import com.onemap.apply.domain.yzt.PoiSearchDTO;
 import com.onemap.common.core.web.domain.RequestResult;
+import com.onemap.common.datasource.annotation.Slave;
 
+import java.util.List;
 import java.util.Map;
 
 public interface ISearchService {
@@ -15,4 +18,11 @@ public interface ISearchService {
     RequestResult bookmarkAdd(CollectionDTO collectionDTO);
 
     RequestResult bookmarkDel(String id);
+
+
+    List<PoiDTO> poiSearch(PoiSearchDTO poiSearchDTO);
+
+
+    PoiDTO getPoiByName(PoiSearchDTO poiSearchDTO);
+
 }

+ 11 - 16
onemap-modules/onemap-apply/src/main/resources/mapper/postgresql/yzt/SearchMapper.xml

@@ -35,31 +35,26 @@
 
     <select id="getPoiByName" parameterType="java.lang.String" resultType="com.onemap.apply.domain.yzt.PoiDTO">
         select t.name,t.adress,public.st_x ( t.geom ) x,public.st_y ( t.geom ) y
-        from  poi t  where 1=1
-         <if test="nameList != null and nameList.size()>0">
-             and t.name in
-             <foreach collection="nameList" item="name" open="(" separator="," close=")">
-                 #{name}
-             </foreach>
-        </if>
+        from  poi t  where t.name  = #{name}  limit 1 offset  0
     </select>
 
 
     <select id="poiLikeName"  resultType="com.onemap.apply.domain.yzt.PoiDTO">
+<!--        select t.name,t.adress,public.st_x ( t.geom ) x,public.st_y ( t.geom ) y-->
+<!--        from  poi t  where 1=1-->
+<!--         <if test="nameList != null and nameList.size()>0">-->
+<!--             and t.name in-->
+<!--             <foreach collection="nameList" item="name" open="(" separator="," close=")">-->
+<!--                 #{name}-->
+<!--             </foreach>-->
+<!--        </if>-->
         select t.name,t.adress,public.st_x ( t.geom ) x,public.st_y ( t.geom ) y
-        from  poi t  where 1=1
-         <if test="nameList != null and nameList.size()>0">
-             and t.name in
-             <foreach collection="nameList" item="name" open="(" separator="," close=")">
-                 #{name}
-             </foreach>
-        </if>
+        from  poi t where
+        t.name like '%'|| #{name} || '%'
         limit ${limit} offset  ${offset}
     </select>
 
 
 
 
-
-
 </mapper>