123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- 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;
- /**
- * @author shiqian
- * @date 2021年09月06日 18:24
- **/
- @RestController
- @RequestMapping
- public class MoveDataController {
- @Resource
- MoveDataMapper moveDataMapper;
- @GetMapping("/hj/{limit}/{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) {
- 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();
- }
- }
|