浏览代码

增加geo查询工具类

xiewj 1 年之前
父节点
当前提交
6a6039f3ec

+ 2 - 0
4dkankan-utils-filestorage/src/main/java/com/fdkankan/filestorage/aliyun/AliyunOssTemplate.java

@@ -422,6 +422,7 @@ public class AliyunOssTemplate implements FileStorageTemplate {
     @Override
     public void copyFolder(String sourceBucketName, String sourcePath, String targetBucketName, String targetPath) {
         try {
+            log.info("复制开始{}->>{}",sourceBucketName,sourceBucketName);
             List<String> files = this.getFileFolder(sourceBucketName, sourcePath);
             if (ObjectUtils.isEmpty(files)) {
                 return;
@@ -429,6 +430,7 @@ public class AliyunOssTemplate implements FileStorageTemplate {
             files.parallelStream().forEach(file -> {
                 this.copyObject(sourceBucketName, file, targetBucketName ,file.replace(sourcePath, targetPath));
             });
+            log.info("复制结束");
         } catch (Exception e) {
             log.error("列举文件目录失败,key:" + sourcePath, e);
         }

+ 52 - 0
4dkankan-utils-geo-query/pom.xml

@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>4dkankan-utils</artifactId>
+        <groupId>com.fdkankan</groupId>
+        <version>3.0.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>4dkankan-utils-geo-query</artifactId>
+
+    <properties>
+        <fastjson.version>2.0.6</fastjson.version>
+        <hutool.version>5.8.6</hutool.version>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-classic</artifactId>
+            <version>1.2.11</version>
+        </dependency>
+        <!-- 阿里JSON解析器 -->
+        <dependency>
+            <groupId>com.alibaba.fastjson2</groupId>
+            <artifactId>fastjson2</artifactId>
+            <version>${fastjson.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>${hutool.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.locationtech.jts</groupId>
+            <artifactId>jts-core</artifactId>
+            <version>1.18.2</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-autoconfigure</artifactId>
+            <version>2.3.12.RELEASE</version>
+        </dependency>
+
+
+    </dependencies>
+
+</project>

文件差异内容过多而无法显示
+ 1697 - 0
4dkankan-utils-geo-query/src/main/java/com/fdkankan/geo/AreaCityQuery.java


+ 24 - 0
4dkankan-utils-geo-query/src/main/java/com/fdkankan/geo/GeoAutoConfiguration.java

@@ -0,0 +1,24 @@
+//package com.fdkankan.geo;
+//
+//import lombok.extern.slf4j.Slf4j;
+//import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+//import org.springframework.boot.context.properties.ConfigurationProperties;
+//import org.springframework.context.annotation.Bean;
+//import org.springframework.context.annotation.Configuration;
+//
+///**
+// * @author Xiewj
+// * @date 2023/8/28
+// */
+//@Configuration
+//@Slf4j
+//public class GeoAutoConfiguration {
+//
+//    @Bean
+//    @ConfigurationProperties(prefix = "geo")
+//    @ConditionalOnMissingBean(GeoConfig.class)
+//    public GeoConfig printAfterInitBean() {
+//        return new GeoConfig();
+//    }
+//
+//}

+ 26 - 0
4dkankan-utils-geo-query/src/main/java/com/fdkankan/geo/GeoConfig.java

@@ -0,0 +1,26 @@
+//package com.fdkankan.geo;
+//
+//import lombok.Data;
+//import org.springframework.beans.factory.InitializingBean;
+//import org.springframework.beans.factory.annotation.Value;
+//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+//
+///**
+// * @author Xiewj
+// * @date 2024/3/15
+// */
+//@Data
+//@ConditionalOnProperty(prefix  = "geo",name = "dataFilePath")
+//public class GeoConfig  implements InitializingBean {
+//
+////    @Value("${GeoQuery.dataFilePath:/mnt/geoQuery/GeoJSON.json}")
+//    private String dataFilePath;
+//
+////    @Value("${GeoQuery.saveWkbsFilePath:/mnt/geoQuery/GeoJSON.wkbs}")
+//    private String saveWkbsFilePath;
+//    @Override
+//    public void afterPropertiesSet() throws Exception {
+//        System.out.println(dataFilePath);
+//        System.out.println(saveWkbsFilePath);
+//    }
+//}

+ 117 - 0
4dkankan-utils-geo-query/src/main/java/com/fdkankan/geo/GeoQueryUtil.java

@@ -0,0 +1,117 @@
+package com.fdkankan.geo;
+
+
+
+
+
+
+
+import lombok.Data;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.stereotype.Component;
+import org.springframework.util.ResourceUtils;
+
+import javax.annotation.PostConstruct;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Serializable;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+
+/**
+ * @author Xiewj
+ * @date 2024/3/15
+ */
+@Slf4j
+@Getter
+@Setter
+@Configuration(value = "GeoQueryUtil")
+@ConditionalOnProperty(prefix  = "geoquery",name = "dataFilePath")
+@ConfigurationProperties(prefix = "geoquery")
+public class GeoQueryUtil {
+    @Value("${geoquery.dataFilePath:/mnt/geoQuery/GeoJSON.json}")
+    private String dataFilePath;
+
+    @Value("${geoquery.saveWkbsFilePath:/mnt/geoQuery/GeoJSON.wkbs}")
+    private String saveWkbsFilePath;
+
+
+    @PostConstruct
+    void init() {
+        File dataFile = new File(dataFilePath);
+        if (!dataFile.exists()) {
+            if (!dataFile.getParentFile().exists()){
+                dataFile.getParentFile().mkdirs();
+            }
+            // 从资源文件中读取数据
+            try {
+                ClassPathResource classPathResource = new ClassPathResource("GeoJSON.json");
+                InputStream is = classPathResource.getInputStream();
+                Files.copy(is, Paths.get(dataFile.getPath()), StandardCopyOption.REPLACE_EXISTING);
+                log.info("File copied from resources to dataFilePath.");
+            } catch (IOException e) {
+                log.error("Error copying file from resources: " + e.getMessage());
+            }
+        }
+        File saveWkbsFile = new File(saveWkbsFilePath);
+        if (!saveWkbsFile.exists()) {
+            if (!saveWkbsFile.getParentFile().exists()){
+                saveWkbsFile.getParentFile().mkdirs();
+            }
+            // 从资源文件中读取数据
+            try {
+                ClassPathResource classPathResource = new ClassPathResource("GeoJSON.wkbs");
+                InputStream is = classPathResource.getInputStream();
+                Files.copy(is, Paths.get(saveWkbsFile.getPath()), StandardCopyOption.REPLACE_EXISTING);
+                log.info("File copied from resources to saveWkbsFilePath.");
+            } catch (IOException e) {
+                log.error("Error copying file from resources: " + e.getMessage());
+            }
+        }
+        AreaCityQuery.Init_StoreInWkbsFile(dataFilePath, saveWkbsFilePath, true);
+        System.out.println(AreaCityQuery.GetInitInfo().toString()); //打印初始化详细信息,包括性能信息
+    }
+   public boolean queryPoint(String location) throws Exception {
+       String[] split = location.split(",");
+       if (split.length<2){
+           return false;
+       }
+       double lng= Double.parseDouble(split[0]);
+       double lat= Double.parseDouble(split[1]);
+       AreaCityQuery.QueryResult res1=AreaCityQuery.QueryPoint(lng, lat, null, null);
+       if (res1!=null &&res1.Result.size()>0){
+           log.info("查询结果:{},{}",true,res1);
+           return true;
+       }else {
+           log.info("查询结果:{},{}",false,res1);
+           return false;
+       }
+    }
+    public boolean queryPoint(Double lng,Double lat) throws Exception {
+        AreaCityQuery.QueryResult res1=AreaCityQuery.QueryPoint(lng, lat, null, null);
+        if (res1!=null &&res1.Result.size()>0){
+            log.info("查询结果:{},{}",true,res1);
+            return true;
+        }else {
+            log.info("查询结果:{},{}",false,res1);
+            return false;
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        GeoQueryUtil queryUtil  = new GeoQueryUtil();
+        System.out.println( queryUtil.queryPoint("109.47237681083061,30.265446034566555"));
+        System.out.println( queryUtil. queryPoint("134.345421050937,34.090524661738"));
+    }
+}

文件差异内容过多而无法显示
+ 52 - 0
4dkankan-utils-geo-query/src/main/resources/GeoJSON.json


文件差异内容过多而无法显示
+ 794 - 0
4dkankan-utils-geo-query/src/main/resources/GeoJSON.wkbs


+ 4 - 0
4dkankan-utils-geo-query/src/main/resources/META-INF/spring.factories

@@ -0,0 +1,4 @@
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.fdkankan.geo.GeoQueryUtil
+#geoquery:
+#dataFilePath: /mnt/GeoJSON.json
+#saveWkbsFilePath: /mnt/GeoJSON.wkbs

+ 1 - 0
pom.xml

@@ -31,6 +31,7 @@
         <module>4dkankan-utils-reg</module>
         <module>4dkankan-utils-filestorage</module>
         <module>4dkankan-utils-disruptormq</module>
+        <module>4dkankan-utils-geo-query</module>
     </modules>
 
     <groupId>com.fdkankan</groupId>