DESKTOP-6LTVLN7\Liumouren пре 3 недеља
родитељ
комит
2e807404e0

+ 4 - 4
pom.xml

@@ -43,12 +43,12 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-web</artifactId>
 <!--        本地运行要注释掉,打war包的时候要放开-->
-            <!--<exclusions>
+            <exclusions>
                 <exclusion>
                     <groupId>org.springframework.boot</groupId>
                     <artifactId>spring-boot-starter-tomcat</artifactId>
                 </exclusion>
-            </exclusions>-->
+            </exclusions>
         </dependency>
         <!-- MySQL 驱动依赖 -->
         <!--        <dependency>-->
@@ -252,7 +252,7 @@
                 </executions>
             </plugin>
         </plugins>
-        <resources>
+        <!--<resources>
             <resource>
                 <directory>src/main/resources</directory>
             </resource>
@@ -263,7 +263,7 @@
                     <include>*.jar</include>
                 </includes>
             </resource>
-        </resources>
+        </resources>-->
     </build>
 
 </project>

+ 14 - 0
src/main/java/com/skyversation/poiaddr/controller/CorporateLibraryController.java

@@ -228,6 +228,20 @@ public class CorporateLibraryController {
         return "处理完成!用时" + (endTime - startTime) / 1000 + "秒!";
     }
 
+    /**
+     * fileRootPath:单个文件目录
+     * pageSize: 批次请求数据条数
+     *
+     * @return
+     */
+    @PostMapping(value = "/saveFileDataToPg3")
+    public Object saveFileDataToPg3(@RequestParam(name = "fileRootPath") String fileRootPath, @RequestParam(name = "pageSize") Integer pageSize) {
+        // 记录程序开始时间
+        long startTime = System.currentTimeMillis();
+        yyskAddressStandardizationService.readFileToPg3(fileRootPath, pageSize);
+        long endTime = System.currentTimeMillis();
+        return "处理完成!用时" + (endTime - startTime) / 1000 + "秒!";
+    }
     /**
      * 先获取文件内容,然后根据address当做key,standardAddress和经纬度作为value
      * 读取结果文件,然后存成Map,接着获取经纬度

+ 44 - 0
src/main/java/com/skyversation/poiaddr/service/impl/YyskAddressStandardizationServiceImpl.java

@@ -553,6 +553,50 @@ public class YyskAddressStandardizationServiceImpl {
         }
     }
 
+    public void readFileToPg3(String fileRootPath, Integer pageSize) {
+        try {
+            List<Map<String, Object>> fileData = ExcelReaderUtils.readExcel(fileRootPath);
+            JSONObject dataList = new JSONObject();
+//          操作类型 1:新增,2:更新3:删除
+            dataList.put("optFlag", 1);
+            JSONArray datas = new JSONArray();
+            // 定义输入格式并解析字符串
+            DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyyMMdd");
+            for (int i = 0; i < fileData.size(); i++) {
+                long startTime = System.currentTimeMillis();
+                Map<String, Object> item = fileData.get(i);
+                JSONObject data = new JSONObject();
+                for (String key : item.keySet()) {
+                    if (key.equals("updatetime")) {
+                        LocalDate date = LocalDate.parse(item.get(key).toString(), inputFormatter);
+                        // 转换为 LocalDateTime(默认时间为 00:00:00)
+                        LocalDateTime dateTime = date.atStartOfDay();
+                        // 定义输出格式并格式化日期时间
+                        DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss");
+                        String output = dateTime.format(outputFormatter);
+                        data.put(key, output);
+                    } else {
+                        data.put(key, item.get(key));
+                    }
+                }
+                datas.add(data);
+                if (i != 0 && (i % (pageSize - 1) == 0 || i == datas.size() - 1)) {
+                    dataList.put("data", datas);
+                    try {
+                        System.out.println(AddressQueryEngine.getInstance().putDataToSJ_Big_Data3(dataList));
+                        long endTime = System.currentTimeMillis();
+                        System.out.println("处理单批次用时" + (endTime - startTime) / 1000 + "秒!");
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                    datas.clear();
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
     public static String getCurrentDateTime() {
         LocalDateTime now = LocalDateTime.now();
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

+ 6 - 6
src/main/resources/application.properties

@@ -9,13 +9,13 @@ spring.servlet.multipart.max-request-size=300MB
 #spring.datasource.password=root
 #spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
 # \u6570\u636E\u5E93\u914D\u7F6E\uFF08\u672C\u5730\u8C03\u8BD5\u73AF\u5883\uFF09
-spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/postgres?stringtype=unspecified&u003fuseUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&serverTimezone=PRC&useSSL=false&tinyInt1isBit=false
-spring.datasource.username=postgres
-spring.datasource.password=WE176852439@lmx
-#spring.datasource.url=jdbc:postgresql://121.43.55.7:5433/postgres?stringtype=unspecified&u003fuseUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&serverTimezone=PRC&useSSL=false&tinyInt1isBit=false
+#spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/postgres?stringtype=unspecified&u003fuseUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&serverTimezone=PRC&useSSL=false&tinyInt1isBit=false
 #spring.datasource.username=postgres
-#spring.datasource.password=SKYversation@0816
-#spring.datasource.driver-class-name=org.postgresql.Driver
+#spring.datasource.password=WE176852439@lmx
+spring.datasource.url=jdbc:postgresql://121.43.55.7:5433/postgres?stringtype=unspecified&u003fuseUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&serverTimezone=PRC&useSSL=false&tinyInt1isBit=false
+spring.datasource.username=postgres
+spring.datasource.password=SKYversation@0816
+spring.datasource.driver-class-name=org.postgresql.Driver
 # JPA\u914D\u7F6E
 spring.jpa.hibernate.ddl-auto=update
 #spring.jpa.show-sql=true