ViewController.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. package com.zskk.control;
  2. import java.io.BufferedReader;
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.IOException;
  6. import java.io.InputStreamReader;
  7. import java.text.ParseException;
  8. import java.text.SimpleDateFormat;
  9. import java.util.Date;
  10. import java.util.HashMap;
  11. import java.util.List;
  12. import java.util.Map;
  13. import org.w3c.dom.NamedNodeMap;
  14. import org.w3c.dom.NodeList;
  15. import com.alibaba.fastjson.JSON;
  16. import com.jfinal.core.Controller;
  17. import com.jfinal.kit.PropKit;
  18. import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
  19. import com.jfinal.plugin.activerecord.Db;
  20. import com.jfinal.plugin.activerecord.Record;
  21. import com.jfinal.plugin.activerecord.dialect.SqlServerDialect;
  22. import com.jfinal.plugin.druid.DruidPlugin;
  23. import com.zskk.tools.XmlHelper;
  24. import okhttp3.FormBody;
  25. import okhttp3.MediaType;
  26. import okhttp3.OkHttpClient;
  27. import okhttp3.Request;
  28. import okhttp3.RequestBody;
  29. import okhttp3.Response;
  30. public class ViewController extends Controller {
  31. private static final MediaType JSON_CODE = MediaType.get("application/json; charset=utf-8");
  32. private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
  33. /**
  34. * 在被连接数据库执行sql语句
  35. */
  36. public void executeSql() {
  37. List<Record> d = Db.use("connected").find(this.getPara("sqlstr"));
  38. this.renderJson(d);
  39. }
  40. public void testConn() {
  41. try {
  42. DruidPlugin druidPluginConnected = createConnectedDruidPlugin();
  43. druidPluginConnected.start();
  44. // 配置ActiveRecord插件
  45. ActiveRecordPlugin arpConnected = new ActiveRecordPlugin("connected", druidPluginConnected);
  46. arpConnected.setDialect(new SqlServerDialect());
  47. arpConnected.start();
  48. } catch (Exception e) {
  49. // TODO: handle exception
  50. this.renderText(e.toString());
  51. }
  52. }
  53. public void mysql() {
  54. String dateString = parseStringToDate();
  55. String fileString = dateString.replace("0", "o");
  56. File fin_floder = new File("/home/zskk/CFIND_XML/STUDYUID_" + fileString + "1.xml");
  57. // 创建从文件读取数据的FileInputStream流
  58. FileInputStream fin;
  59. String s = null;
  60. String d = "";
  61. try {
  62. fin = new FileInputStream(fin_floder);
  63. InputStreamReader isr = null;
  64. isr = new InputStreamReader(fin);
  65. BufferedReader raf = null;
  66. raf = new BufferedReader(isr);
  67. s = raf.readLine();
  68. s = s.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "");
  69. s = "<zskk>" + s + "</zskk>";
  70. // System.out.println(s);
  71. XmlHelper xmlHelper = XmlHelper.of(s);
  72. NodeList nodeList = xmlHelper.getNodeList("/zskk/NativeDicomModel/DicomAttribute");
  73. for (int i = 0; i < nodeList.getLength(); i++) {
  74. NamedNodeMap as = nodeList.item(i).getAttributes();
  75. if (as != null && as.getLength() > 0) {
  76. for (int j = 0; j < as.getLength(); j++) {
  77. if (as.item(j).getNodeName().equals("tag")) {
  78. if (as.item(j).getNodeValue().equals("0020000D")) {
  79. // String b = xmlHelper.getString("/zskk/NativeDicomModel[" + i + "]/DicomAttribute[" + j + "]/Value");
  80. // System.out.println(xmlHelper.getString(nodeList.item(i), "Value"));
  81. String studyuidString = xmlHelper.getString(nodeList.item(i), "Value");
  82. d=d+studyuidString;
  83. // Record studyidfind = Db.use("local").findFirst("select * from study where studyuid = ?",
  84. // studyuidString);
  85. // if (studyidfind == null) {
  86. // Record studyinfo = new Record().set("studyuid", studyuidString);
  87. // Db.use("local").save("study", studyinfo);
  88. // }
  89. }
  90. }
  91. }
  92. }
  93. }
  94. } catch (IOException e) {
  95. // TODO Auto-generated catch block
  96. e.printStackTrace();
  97. renderText(e.toString());
  98. }
  99. renderText(d);
  100. }
  101. public static DruidPlugin createConnectedDruidPlugin() {
  102. return new DruidPlugin(PropKit.get("jdbcUrl_connected"), PropKit.get("user_connected"),PropKit.get("password_connected").trim());
  103. }
  104. /**
  105. * post请求
  106. * @param url-请求地址
  107. * @param map-参数集合
  108. * @return
  109. */
  110. private static String doPost(String url, Map<String, String> map) {
  111. FormBody.Builder builder = new FormBody.Builder();
  112. for (String key : map.keySet()) {
  113. builder.add(key, map.get(key));
  114. }
  115. RequestBody formBody = builder.build();
  116. Request request = new Request.Builder().url(url).post(formBody).build();
  117. try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
  118. if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  119. String content = response.body().string();
  120. return content;
  121. } catch (IOException e) {
  122. // TODO Auto-generated catch block
  123. e.printStackTrace();
  124. return null;
  125. }
  126. }
  127. private String parseStringToDate() {
  128. SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
  129. Date date = new Date();
  130. long dInteger = date.getTime() - 86400000;
  131. String daString = sdf.format(new Date(dInteger));
  132. return daString;
  133. }
  134. }