dick 1 rok temu
rodzic
commit
909e59fac1

+ 44 - 3
src/main/java/cn/cslg/pas/service/query/QueryService.java

@@ -1,14 +1,14 @@
 package cn.cslg.pas.service.query;
 
 import cn.cslg.pas.common.utils.parseQueryToTree.*;
+import com.google.gson.Gson;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
+import java.io.*;
+import java.util.*;
 
 @Service
 @Slf4j
@@ -85,4 +85,45 @@ public class QueryService {
         return strCode;
     }
 
+
+    public void write() {
+        // 创建一个Map对象并添加一些数据
+        Map<String, String> map = new HashMap<>();
+        map.put("key1", "value1");
+        map.put("key2", "value2");
+        map.put("key3", "value3");
+
+        // 将Map存储到文件中
+        try {
+            FileOutputStream fileOut = new FileOutputStream("map.ser");
+            ObjectOutputStream out = new ObjectOutputStream(fileOut);
+            out.writeObject(map);
+            out.close();
+            fileOut.close();
+            System.out.println("Map已经成功存储到文件中");
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    public static Map<String, Object> readJsonFile(String fileName) {
+        Gson gson = new Gson();
+        String json = "";
+        try {
+            File file = new File("target/file/test.json");
+            Reader reader = new InputStreamReader(new FileInputStream(file), "utf-8");
+            int ch = 0;
+            StringBuffer buffer = new StringBuffer();
+            while ((ch = reader.read()) != -1) {
+                buffer.append((char) ch);
+            }
+            reader.close();
+            json = buffer.toString();
+            return gson.fromJson(json, Map.class);
+        } catch (IOException e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
 }

+ 2 - 2
src/main/resources/application-dev.yml

@@ -12,9 +12,9 @@ spring:
         max-wait: -1ms
     timeout: 2000ms
   datasource:
-    url: jdbc:mysql://192.168.1.24:3306/pas_prod2?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=GMT%2B8
+    url: jdbc:mysql://127.0.0.1:3306/pas_prod2?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=GMT%2B8
     username: root
-    password: rrzTwWAYX8Gxh5JH
+    password: root
     driver-class-name: com.mysql.cj.jdbc.Driver
     type: com.alibaba.druid.pool.DruidDataSource
     druid:

+ 5 - 2
src/test/java/cn/cslg/pas/service/PatentPDFServiceTests.java

@@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 
 import java.io.IOException;
+import java.util.Map;
 
 /**
  * @author chenyu
@@ -17,8 +18,10 @@ public class PatentPDFServiceTests {
     private QueryService queryService;
 
     @Test
-    void test() throws IOException {
-        queryService.getText("CN201080016105.6");
+    void test() throws Exception {
+//        queryService.getText("ti=2");
+        Map<String, Object> map = queryService.readJsonFile("aa");
+        map.get("name");
     }
 
 }