MoveDataController.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package com.boman.gen.controller;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.boman.gen.mapper.MoveDataMapper;
  5. import com.google.gson.JsonArray;
  6. import com.google.gson.JsonElement;
  7. import com.google.gson.JsonObject;
  8. import com.google.gson.JsonParser;
  9. import org.springframework.web.bind.annotation.GetMapping;
  10. import org.springframework.web.bind.annotation.PathVariable;
  11. import org.springframework.web.bind.annotation.RequestMapping;
  12. import org.springframework.web.bind.annotation.RestController;
  13. import javax.annotation.Resource;
  14. import java.io.BufferedWriter;
  15. import java.io.File;
  16. import java.io.FileReader;
  17. import java.io.FileWriter;
  18. import java.util.List;
  19. /**
  20. * @author shiqian
  21. * @date 2021年09月06日 18:24
  22. **/
  23. @RestController
  24. @RequestMapping
  25. public class MoveDataController {
  26. @Resource
  27. MoveDataMapper moveDataMapper;
  28. @GetMapping("/hj/{limit}/{offset}")
  29. public String moveData(@PathVariable("limit") int limit, @PathVariable("offset") int offset) {
  30. List<JSONObject> select = moveDataMapper.select(limit, offset);
  31. return JSON.toJSONString(select);
  32. }
  33. @GetMapping("/selectY/{limit}/{offset}")
  34. public String selectY(@PathVariable("limit") int limit, @PathVariable("offset") int offset) {
  35. List<JSONObject> select = moveDataMapper.select(limit, offset);
  36. return JSON.toJSONString(select);
  37. }
  38. private static void jsonToExcel() throws Exception {
  39. JsonParser jsonParser = new JsonParser();
  40. JsonArray asJsonArray = (JsonArray) jsonParser.parse(new FileReader("F:\\desk\\hj_hj_all.json"));
  41. for (int i = 0; i < asJsonArray.size(); i++) {
  42. JsonElement jsonElement = asJsonArray.get(i);
  43. JsonObject featuresObj = jsonElement.getAsJsonObject();
  44. String zjlx = getString(featuresObj, "zjlx");
  45. String zjhm = getString(featuresObj, "zjhm");
  46. String hh = getString(featuresObj, "hh");
  47. String xz = getString(featuresObj, "xz");
  48. String hjdxz = getString(featuresObj, "hjdxz");
  49. String yhzgx = getString(featuresObj, "yhzgx");
  50. String hzxm = getString(featuresObj, "hzxm");
  51. String hzzjlx = getString(featuresObj, "hzzjlx");
  52. String hzsfhm = getString(featuresObj, "hzsfhm");
  53. String xm = getString(featuresObj, "xm");
  54. String csrq = getString(featuresObj, "csrq");
  55. String xb = getString(featuresObj, "xb");
  56. String hhid = getString(featuresObj, "hhid");
  57. String hklx = getString(featuresObj, "hklx");
  58. String swrq = getString(featuresObj, "swrq");
  59. String akmlxdh = getString(featuresObj, "akmlxdh");
  60. String lxdh = getString(featuresObj, "lxdh");
  61. String akmdz = getString(featuresObj, "akmdz");
  62. String sqlStr = "insert into hj_hj (zjlx, zjhm, hh, xz, hjdxz, yhzgx,hzxm,hzzjlx, hzsfhm,xm,csrq,xb,hhid,hklx,swrq,akmlxdh,lxdh,akmdz) " +
  63. "values (" + zjlx + ", " + zjhm + ", " + hh + ", " + xz + ", " + hjdxz + ", " + yhzgx + ", "
  64. + hzxm + ", " + hzzjlx + ", " + hzsfhm + " , " + xm + ", " + csrq + ", " + xb + ", " + hhid
  65. + ", " + hklx + ", " + swrq + ", " + akmlxdh + ", " + lxdh + ", " + akmdz + "); -- " + i + "\r\n";
  66. System.err.println("count: " + i + ", " + sqlStr);
  67. File file = new File("F:\\desk\\hj_hj_all.sql");
  68. if (!file.exists()) {
  69. file.createNewFile();
  70. }
  71. FileWriter fileWriter = new FileWriter(file, true);
  72. BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
  73. bufferedWriter.write(sqlStr);
  74. bufferedWriter.close();
  75. }
  76. }
  77. private static String getString(JsonObject featuresObj, String type) {
  78. JsonElement zjlx = featuresObj.get(type);
  79. if (null == zjlx) {
  80. return "''";
  81. }
  82. // String zjlx1 = zjlx.toString().replace("\"", "");
  83. return zjlx.toString();
  84. }
  85. public static void main(String[] args) throws Exception {
  86. System.out.println();
  87. jsonToExcel();
  88. }
  89. }