Bladeren bron

配套资源 通过经纬度及半径查询范围内的点位

zhouwang 4 dagen geleden
bovenliggende
commit
5fe2ac1ab8

+ 14 - 0
src/main/java/com/lqkj/supporting/controller/ResourcesInfoController.java

@@ -1,6 +1,8 @@
1 1
 package com.lqkj.supporting.controller;
2 2
 
3 3
 import java.util.List;
4
+
5
+import org.apache.ibatis.annotations.Param;
4 6
 import org.springframework.security.access.prepost.PreAuthorize;
5 7
 import org.springframework.beans.factory.annotation.Autowired;
6 8
 import org.springframework.web.bind.annotation.GetMapping;
@@ -109,4 +111,16 @@ public class ResourcesInfoController extends BaseController
109 111
     {
110 112
         return resultByRows(resourcesInfoService.deleteResourcesInfoByInfoIds(infoIds));
111 113
     }
114
+
115
+    /**
116
+     * 根据geom查询资源点位对象
117
+     * @param location 点位对象
118
+     * @param distance 距离
119
+     * @return 点位集合
120
+     */
121
+    @GetMapping("/listByGeom")
122
+    public List<ResourcesInfo> selectResourcesInfoListByGeom(@Param("location") String location, @Param("distance") int distance ){
123
+        return resourcesInfoService.selectResourcesInfoListByGeom(location,distance);
124
+    }
125
+
112 126
 }

+ 17 - 0
src/main/java/com/lqkj/supporting/controller/ResourcesTypeController.java

@@ -1,6 +1,8 @@
1 1
 package com.lqkj.supporting.controller;
2 2
 
3 3
 import java.util.List;
4
+import java.util.Map;
5
+
4 6
 import org.springframework.security.access.prepost.PreAuthorize;
5 7
 import org.springframework.beans.factory.annotation.Autowired;
6 8
 import org.springframework.web.bind.annotation.GetMapping;
@@ -114,4 +116,19 @@ public class ResourcesTypeController extends BaseController
114 116
     {
115 117
         return resultByRows(resourcesTypeService.deleteResourcesTypeByTypeIds(typeIds));
116 118
     }
119
+
120
+
121
+
122
+
123
+    /**
124
+     *  资源类型列表 分组返回每个类型对应的点位数量
125
+     *
126
+     * @return 资源类型集合
127
+     */
128
+    @GetMapping("/listGroupByTypeLabel")
129
+    public Map<String, List<ResourcesType>> selectResourcesTypeListGroupByTypeLabel(){
130
+        return resourcesTypeService.selectResourcesTypeMapByTypeLabel();
131
+    }
132
+
133
+
117 134
 }

+ 10 - 0
src/main/java/com/lqkj/supporting/entity/ResourcesInfo.java

@@ -38,6 +38,8 @@ public class ResourcesInfo extends BaseEntity
38 38
 
39 39
     private String typeName;
40 40
 
41
+    private int distance;
42
+
41 43
     public void setInfoId(Integer infoId)
42 44
     {
43 45
         this.infoId = infoId;
@@ -92,6 +94,14 @@ public class ResourcesInfo extends BaseEntity
92 94
         this.typeName = typeName;
93 95
     }
94 96
 
97
+    public int getDistance() {
98
+        return distance;
99
+    }
100
+
101
+    public void setDistance(int distance) {
102
+        this.distance = distance;
103
+    }
104
+
95 105
     @Override
96 106
     public String toString() {
97 107
         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)

+ 11 - 0
src/main/java/com/lqkj/supporting/entity/ResourcesType.java

@@ -38,6 +38,9 @@ public class ResourcesType extends BaseEntity
38 38
     @Excel(name = "备注")
39 39
     private String memo;
40 40
 
41
+
42
+    private int count;
43
+
41 44
     public void setTypeId(Integer typeId)
42 45
     {
43 46
         this.typeId = typeId;
@@ -93,6 +96,14 @@ public class ResourcesType extends BaseEntity
93 96
         return memo;
94 97
     }
95 98
 
99
+    public int getCount() {
100
+        return count;
101
+    }
102
+
103
+    public void setCount(int count) {
104
+        this.count = count;
105
+    }
106
+
96 107
     @Override
97 108
     public String toString() {
98 109
         return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)

+ 13 - 0
src/main/java/com/lqkj/supporting/mapper/ResourcesInfoMapper.java

@@ -3,6 +3,8 @@ package com.lqkj.supporting.mapper;
3 3
 import java.util.List;
4 4
 import org.apache.ibatis.annotations.Mapper;
5 5
 import com.lqkj.supporting.entity.ResourcesInfo;
6
+import org.apache.ibatis.annotations.Select;
7
+import org.springframework.data.repository.query.Param;
6 8
 
7 9
 /**
8 10
  * 资源点位对象Mapper接口
@@ -60,4 +62,15 @@ public interface ResourcesInfoMapper
60 62
      * @return 结果
61 63
      */
62 64
     public int deleteResourcesInfoByInfoIds(Integer[] infoIds);
65
+
66
+    /**
67
+     * 根据geom查询资源点位对象
68
+     * @param location 点位对象
69
+     * @param distance 距离
70
+     * @return 点位集合
71
+     */
72
+//    @Select("select info_id,type_id,info_name,location,memo,CAST(st_distancesphere(ST_SetSRID(st_geomfromgeojson(location),4326), st_geomfromgeojson(#{location})) AS NUMERIC(10,2)) distance from resources_info  \n" +
73
+//            "        where st_distancesphere(ST_SetSRID(st_geomfromgeojson(location),4326), st_geomfromgeojson(#{location})) <= :distance \n" +
74
+//            "        order by st_distancesphere(ST_SetSRID(st_geomfromgeojson(location),4326), st_geomfromgeojson(#{location})) limit 5")
75
+    public List<ResourcesInfo> selectResourcesInfoListByGeom(Object location,int distance);
63 76
 }

+ 18 - 0
src/main/java/com/lqkj/supporting/mapper/ResourcesTypeMapper.java

@@ -3,6 +3,7 @@ package com.lqkj.supporting.mapper;
3 3
 import java.util.List;
4 4
 import org.apache.ibatis.annotations.Mapper;
5 5
 import com.lqkj.supporting.entity.ResourcesType;
6
+import org.apache.ibatis.annotations.Select;
6 7
 
7 8
 /**
8 9
  * 资源类型Mapper接口
@@ -60,4 +61,21 @@ public interface ResourcesTypeMapper
60 61
      * @return 结果
61 62
      */
62 63
     public int deleteResourcesTypeByTypeIds(Integer[] typeIds);
64
+
65
+
66
+
67
+
68
+    /**
69
+     * 资源类型列表 分组返回每个类型对应的点位数量
70
+     *
71
+     * @return 资源类型集合
72
+     */
73
+    @Select("SELECT ei.type_label, ei.type_id,ei.type_name,ei.icon,COUNT(ri.type_id) \n" +
74
+            "            FROM resources_type ei \n" +
75
+            "            LEFT JOIN resources_info ri ON ei.type_id = ri.type_id \n" +
76
+            "            GROUP BY ei.type_label ,ei.type_id,ei.type_name")
77
+    public List<ResourcesType> selectResourcesTypeListGroupByTypeLabel();
78
+
79
+
80
+
63 81
 }

+ 19 - 0
src/main/java/com/lqkj/supporting/service/ResourcesInfoService.java

@@ -130,4 +130,23 @@ public class ResourcesInfoService {
130 130
     public int deleteResourcesInfoByInfoId(Integer infoId) {
131 131
         return resourcesInfoMapper.deleteResourcesInfoByInfoId(infoId);
132 132
     }
133
+
134
+    /**
135
+     * 根据geom查询资源点位对象
136
+     * @param location 点位对象
137
+     * @param distance 距离
138
+     * @return 点位集合
139
+     */
140
+    public List<ResourcesInfo> selectResourcesInfoListByGeom(String location,int distance){
141
+        Point point = GeoUtils.createPoint(location);
142
+        JSONObject jsonObject = GeoUtils.readFromGeometry(point);
143
+        List<ResourcesInfo> resourcesInfos = resourcesInfoMapper.selectResourcesInfoListByGeom(jsonObject, distance);
144
+        if (!CollectionUtils.isEmpty(resourcesInfos)) {
145
+            resourcesInfos.forEach(this::paseGeom);
146
+        }
147
+
148
+        return resourcesInfos;
149
+    }
150
+
151
+
133 152
 }

+ 25 - 0
src/main/java/com/lqkj/supporting/service/ResourcesTypeService.java

@@ -1,11 +1,18 @@
1 1
 package com.lqkj.supporting.service;
2 2
 
3
+import java.util.Collections;
3 4
 import java.util.List;
5
+import java.util.Map;
6
+import java.util.function.Function;
7
+import java.util.stream.Collectors;
8
+
4 9
 import org.springframework.beans.factory.annotation.Autowired;
5 10
 import org.springframework.stereotype.Service;
6 11
 import com.lqkj.supporting.mapper.ResourcesTypeMapper;
7 12
 import com.lqkj.supporting.entity.ResourcesType;
8 13
 import com.lqkj.common.utils.uuid.IdUtils;
14
+import org.springframework.util.CollectionUtils;
15
+
9 16
 /**
10 17
  * 资源类型Service业务层处理
11 18
  *
@@ -88,4 +95,22 @@ public class ResourcesTypeService
88 95
     {
89 96
         return resourcesTypeMapper.deleteResourcesTypeByTypeId(typeId);
90 97
     }
98
+
99
+    /**
100
+     * 资源类型列表 分组返回每个类型对应的点位数量
101
+     *
102
+     * @return 资源类型集合
103
+     */
104
+    public Map<String, List<ResourcesType>> selectResourcesTypeMapByTypeLabel() {
105
+        List<ResourcesType> resourcesTypes = resourcesTypeMapper.selectResourcesTypeListGroupByTypeLabel();
106
+        if (!CollectionUtils.isEmpty(resourcesTypes)) {
107
+            return resourcesTypes.stream()
108
+                    .collect(Collectors.groupingBy(ResourcesType::getTypeLabel));
109
+        }
110
+        return Collections.emptyMap();
111
+    }
112
+
113
+
114
+
115
+
91 116
 }

+ 2 - 2
src/main/resources/db/migration/V1_17__20250507.sql

@@ -57,8 +57,8 @@ VALUES ('配套资源分类', 'supporting_resources_classify', 't', '超级管
57 57
 
58 58
 INSERT INTO "public"."sys_dict_data" ("dict_sort", "dict_label", "dict_value", "dict_type", "css_class", "list_class", "is_default", "status", "create_by", "create_time", "update_by", "update_time", "remark", "icon", "park_id")
59 59
        VALUES (1, '企业服务', '企业服务', 'supporting_resources_classify', NULL, 'default', 'f', 't', '超级管理员', now(), NULL, NULL, NULL, NULL, NULL),
60
-              (2, '便民服务', '企业服务', 'supporting_resources_classify', NULL, 'default', 'f', 't', '超级管理员', now(), NULL, NULL, NULL, NULL, NULL),
61
-              (3, '交通服务', '企业服务', 'supporting_resources_classify', NULL, 'default', 'f', 't', '超级管理员', now(), NULL, NULL, NULL, NULL, NULL);
60
+              (2, '便民服务', '便民服务', 'supporting_resources_classify', NULL, 'default', 'f', 't', '超级管理员', now(), NULL, NULL, NULL, NULL, NULL),
61
+              (3, '交通服务', '交通服务', 'supporting_resources_classify', NULL, 'default', 'f', 't', '超级管理员', now(), NULL, NULL, NULL, NULL, NULL);
62 62
 
63 63
 
64 64
 

+ 38 - 0
src/main/resources/mapper/supporting/ResourcesInfoMapper.xml

@@ -11,6 +11,7 @@
11 11
 		<result property="memo"    column="memo"    />
12 12
 		<result property="location"    column="location"   jdbcType="OTHER"
13 13
 				typeHandler="com.lqkj.framework.sql.JsonbTypeHandler"/>
14
+		<result property="distance" column="distance" />
14 15
 	</resultMap>
15 16
 
16 17
 	<sql id="selectResourcesInfoVo">
@@ -69,4 +70,41 @@
69 70
 			#{infoId}
70 71
 		</foreach>
71 72
 	</delete>
73
+
74
+
75
+<!--	<select id="selectResourcesInfoListByGeom" resultType="ResourcesInfo">-->
76
+
77
+<!--		select info_id,-->
78
+<!--		       type_id,-->
79
+<!--		       info_name,-->
80
+<!--		       location,-->
81
+<!--		       memo,-->
82
+<!--		       CAST(st_distancesphere(ST_SetSRID(st_geomfromgeojson(location,jdbcType=OTHER,typeHandler=com.lqkj.framework.sql.JsonbTypeHandler),4326),-->
83
+<!--		st_geomfromgeojson(#{location,jdbcType=OTHER,typeHandler=com.lqkj.framework.sql.JsonbTypeHandler})) AS NUMERIC(10,2)) distance-->
84
+<!--		from resources_info-->
85
+<!--		where st_distancesphere(ST_SetSRID(st_geomfromgeojson(location,jdbcType=OTHER,typeHandler=com.lqkj.framework.sql.JsonbTypeHandler),4326), st_geomfromgeojson(#{location,jdbcType=OTHER,typeHandler=com.lqkj.framework.sql.JsonbTypeHandler})) <= #{distance}-->
86
+<!--		order by st_distancesphere(ST_SetSRID(st_geomfromgeojson(location,jdbcType=OTHER,typeHandler=com.lqkj.framework.sql.JsonbTypeHandler),4326), st_geomfromgeojson(#{location,jdbcType=OTHER,typeHandler=com.lqkj.framework.sql.JsonbTypeHandler})) limit 5-->
87
+<!--	</select>-->
88
+	<select id="selectResourcesInfoListByGeom" resultMap="ResourcesInfoResult">
89
+		 <![CDATA[
90
+		select
91
+			info_id,
92
+			type_id,
93
+			info_name,
94
+			location,
95
+			memo,
96
+			CAST(st_distancesphere(
97
+					ST_SetSRID(st_geomfromgeojson(location), 4326),
98
+					st_geomfromgeojson(#{location,jdbcType=OTHER,typeHandler=com.lqkj.framework.sql.JsonbTypeHandler})
99
+				 ) AS NUMERIC(10,2)) distance
100
+		from resources_info
101
+		where st_distancesphere(
102
+					  ST_SetSRID(st_geomfromgeojson(location), 4326),
103
+					  st_geomfromgeojson(#{location,jdbcType=OTHER,typeHandler=com.lqkj.framework.sql.JsonbTypeHandler})
104
+			  ) <= #{distance}
105
+		order by distance
106
+			limit 5
107
+		]]>
108
+	</select>
109
+
72 110
 </mapper>