shiqian 3 жил өмнө
parent
commit
e8da6e916f

+ 5 - 5
boman-modules/boman-gen/pom.xml

@@ -85,11 +85,11 @@
             <scope>compile</scope>
         </dependency>
 
-<!--        <dependency>-->
-<!--            <groupId>com.google.code.gson</groupId>-->
-<!--            <artifactId>gson</artifactId>-->
-<!--            <version>2.7</version>-->
-<!--        </dependency>-->
+        <dependency>
+            <groupId>com.google.code.gson</groupId>
+            <artifactId>gson</artifactId>
+            <version>2.7</version>
+        </dependency>
     </dependencies>
 
     <build>

+ 66 - 3
boman-modules/boman-gen/src/main/java/com/boman/gen/controller/MoveDataController.java

@@ -3,12 +3,20 @@ package com.boman.gen.controller;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.boman.gen.mapper.MoveDataMapper;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
 import java.util.List;
 
 /**
@@ -24,14 +32,69 @@ public class MoveDataController {
 
 
     @GetMapping("/hj/{limit}/{offset}")
-    public String moveData(@PathVariable("limit") int limit, @PathVariable("offset") int offset){
+    public String moveData(@PathVariable("limit") int limit, @PathVariable("offset") int offset) {
         List<JSONObject> select = moveDataMapper.select(limit, offset);
         return JSON.toJSONString(select);
     }
 
     @GetMapping("/selectY/{limit}/{offset}")
-    public String selectY(@PathVariable("limit") int limit, @PathVariable("offset") int offset){
+    public String selectY(@PathVariable("limit") int limit, @PathVariable("offset") int offset) {
         List<JSONObject> select = moveDataMapper.select(limit, offset);
         return JSON.toJSONString(select);
     }
-}
+
+    private static void jsonToExcel() throws Exception {
+        JsonParser jsonParser = new JsonParser();
+        JsonArray asJsonArray = (JsonArray) jsonParser.parse(new FileReader("F:\\desk\\hj_hj_all.json"));
+        for (int i = 0; i < asJsonArray.size(); i++) {
+            JsonElement jsonElement = asJsonArray.get(i);
+            JsonObject featuresObj = jsonElement.getAsJsonObject();
+            String zjlx = getString(featuresObj, "zjlx");
+            String zjhm = getString(featuresObj, "zjhm");
+            String hh = getString(featuresObj, "hh");
+            String xz = getString(featuresObj, "xz");
+            String hjdxz = getString(featuresObj, "hjdxz");
+            String yhzgx = getString(featuresObj, "yhzgx");
+            String hzxm = getString(featuresObj, "hzxm");
+            String hzzjlx = getString(featuresObj, "hzzjlx");
+            String hzsfhm = getString(featuresObj, "hzsfhm");
+            String xm = getString(featuresObj, "xm");
+            String csrq = getString(featuresObj, "csrq");
+            String xb = getString(featuresObj, "xb");
+            String hhid = getString(featuresObj, "hhid");
+            String hklx = getString(featuresObj, "hklx");
+            String swrq = getString(featuresObj, "swrq");
+            String akmlxdh = getString(featuresObj, "akmlxdh");
+            String lxdh = getString(featuresObj, "lxdh");
+            String akmdz = getString(featuresObj, "akmdz");
+
+            String sqlStr = "insert into hj_hj (zjlx, zjhm, hh, xz, hjdxz, yhzgx,hzxm,hzzjlx, hzsfhm,xm,csrq,xb,hhid,hklx,swrq,akmlxdh,lxdh,akmdz) " +
+                    "values (" + zjlx + ", " + zjhm + ", " + hh + ", " + xz + ", " + hjdxz + ", " + yhzgx + ", "
+                    + hzxm + ", " + hzzjlx + ", " + hzsfhm + " , " + xm + ", " + csrq + ", " + xb + ", " + hhid
+                    + ", " + hklx + ", " + swrq + ", " + akmlxdh + ", " + lxdh + ", " + akmdz + "); -- " + i + "\r\n";
+            System.err.println("count: " + i + ", " + sqlStr);
+            File file = new File("F:\\desk\\hj_hj_all.sql");
+            if (!file.exists()) {
+                file.createNewFile();
+            }
+            FileWriter fileWriter = new FileWriter(file, true);
+            BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
+            bufferedWriter.write(sqlStr);
+            bufferedWriter.close();
+        }
+    }
+
+    private static String getString(JsonObject featuresObj, String type) {
+        JsonElement zjlx = featuresObj.get(type);
+        if (null == zjlx) {
+            return "''";
+        }
+//        String zjlx1 = zjlx.toString().replace("\"", "");
+        return zjlx.toString();
+    }
+
+    public static void main(String[] args) throws Exception {
+        System.out.println();
+        jsonToExcel();
+    }
+}