ViewController.java 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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.SimpleDateFormat;
  8. import java.util.ArrayList;
  9. import java.util.Date;
  10. import java.util.List;
  11. import java.util.Map;
  12. import org.w3c.dom.NamedNodeMap;
  13. import org.w3c.dom.NodeList;
  14. import com.jfinal.core.Controller;
  15. import com.jfinal.kit.PropKit;
  16. import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
  17. import com.jfinal.plugin.activerecord.Db;
  18. import com.jfinal.plugin.activerecord.Record;
  19. import com.jfinal.plugin.activerecord.dialect.SqlServerDialect;
  20. import com.jfinal.plugin.druid.DruidPlugin;
  21. import com.zskk.tools.ExecUtil;
  22. import com.zskk.tools.XmlHelper;
  23. import okhttp3.FormBody;
  24. import okhttp3.MediaType;
  25. import okhttp3.OkHttpClient;
  26. import okhttp3.Request;
  27. import okhttp3.RequestBody;
  28. import okhttp3.Response;
  29. public class ViewController extends Controller {
  30. private static final MediaType JSON_CODE = MediaType.get("application/json; charset=utf-8");
  31. private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
  32. /**
  33. * 在被连接数据库执行sql语句
  34. */
  35. public void executeSql() {
  36. List<Record> d = Db.use("connected").find(this.getPara("sqlstr"));
  37. this.renderJson(d);
  38. }
  39. public void exe() {
  40. String dateString = parseStringToDate();
  41. String fileString = dateString.replace("0", "o");
  42. String execCmd = ExecUtil.execCmd("/zskk_system/other/cfind.sh " + dateString + " STUDYUID_" + fileString + ".xml");
  43. if (execCmd.contains("Connection refused")) {
  44. return;
  45. }
  46. this.renderText(execCmd);
  47. }
  48. public void testConn() {
  49. try {
  50. DruidPlugin druidPluginConnected = createConnectedDruidPlugin();
  51. druidPluginConnected.start();
  52. // 配置ActiveRecord插件
  53. ActiveRecordPlugin arpConnected = new ActiveRecordPlugin("connected", druidPluginConnected);
  54. arpConnected.setDialect(new SqlServerDialect());
  55. arpConnected.start();
  56. } catch (Exception e) {
  57. // TODO: handle exception
  58. this.renderText(e.toString());
  59. }
  60. }
  61. public void tempmatch() {
  62. String fileName2String ="";
  63. // List<String> files = new ArrayList<String>();
  64. // File file = new File("/home/zskk/CFIND_XML");
  65. // File[] tempList = file.listFiles();
  66. // for (int m = 0; m < tempList.length; m++) {
  67. // if (tempList[m].isFile()) {
  68. // files.add(tempList[m].toString());
  69. // //文件名,不包含路径
  70. // String fileName = tempList[m].getName();
  71. // fileName2String = fileName2String+fileName+"**";
  72. File fin_floder = new File("/home/zskk/CFIND_XML/tt51.xml");
  73. // 创建从文件读取数据的FileInputStream流
  74. FileInputStream fin;
  75. try {
  76. fin = new FileInputStream(fin_floder);
  77. InputStreamReader isr = null;
  78. isr = new InputStreamReader(fin);
  79. BufferedReader raf = null;
  80. raf = new BufferedReader(isr);
  81. String xmlContent = null;
  82. xmlContent = raf.readLine();
  83. xmlContent = xmlContent.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "");
  84. xmlContent = "<zskk>" + xmlContent + "</zskk>";
  85. XmlHelper xmlHelper = XmlHelper.of(xmlContent);
  86. fileName2String = xmlContent;
  87. // NativeDicomModel节点列表
  88. NodeList nativeDicomModelList = xmlHelper.getNodeList("/zskk/NativeDicomModel");
  89. for (int i = 0; i < nativeDicomModelList.getLength(); i++) {
  90. String qString = "";
  91. String studyuidString = "";
  92. String modalitiesString = "";
  93. // DicomAttribute节点列表
  94. NodeList dicomAttributeList = xmlHelper.getNodeList(nativeDicomModelList.item(i), "DicomAttribute");
  95. for (int j = 0; j < dicomAttributeList.getLength(); j++) {
  96. // DicomAttribute节点属性列表
  97. NamedNodeMap attributeMap = dicomAttributeList.item(j).getAttributes();
  98. if (attributeMap != null && attributeMap.getLength() > 0) {
  99. for (int k = 0; k < attributeMap.getLength(); k++) {
  100. if (attributeMap.item(k).getNodeName().equals("tag")) {
  101. // 获取studyuid
  102. if (attributeMap.item(k).getNodeValue().equals("0020000D")) {
  103. studyuidString = xmlHelper.getString(dicomAttributeList.item(j), "Value");
  104. continue;
  105. }
  106. // 获取检查类型
  107. if (attributeMap.item(k).getNodeValue().equals("00080061")) {
  108. modalitiesString = xmlHelper.getString(dicomAttributeList.item(j), "Value");
  109. }
  110. }
  111. }
  112. }
  113. }
  114. Record studyidfind = Db.use("local").findFirst("select * from study where studyuid = ?",
  115. studyuidString);
  116. if (studyidfind == null) {
  117. Record studyinfo = new Record().set("studyuid", studyuidString).set("modalities", modalitiesString)
  118. .set("status", 1).set("createAt", parseStringToDateTime()).set("updateAt", parseStringToDateTime());
  119. Db.use("local").save("study", studyinfo);
  120. }
  121. }
  122. } catch (IOException e) {
  123. // TODO Auto-generated catch block
  124. e.printStackTrace();
  125. this.renderText(e.toString());
  126. }
  127. // }
  128. // if (tempList[m].isDirectory()) {
  129. // //这里就不递归了,
  130. // }
  131. //
  132. // }
  133. this.renderText(fileName2String);
  134. }
  135. public static DruidPlugin createConnectedDruidPlugin() {
  136. return new DruidPlugin(PropKit.get("jdbcUrl_connected"), PropKit.get("user_connected"),PropKit.get("password_connected").trim());
  137. }
  138. /**
  139. * post请求
  140. * @param url-请求地址
  141. * @param map-参数集合
  142. * @return
  143. */
  144. private static String doPost(String url, Map<String, String> map) {
  145. FormBody.Builder builder = new FormBody.Builder();
  146. for (String key : map.keySet()) {
  147. builder.add(key, map.get(key));
  148. }
  149. RequestBody formBody = builder.build();
  150. Request request = new Request.Builder().url(url).post(formBody).build();
  151. try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
  152. if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  153. String content = response.body().string();
  154. return content;
  155. } catch (IOException e) {
  156. // TODO Auto-generated catch block
  157. e.printStackTrace();
  158. return null;
  159. }
  160. }
  161. private String parseStringToDate() {
  162. SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
  163. Date date = new Date();
  164. long dInteger = date.getTime();
  165. String daString = sdf.format(new Date(dInteger));
  166. return daString;
  167. }
  168. /**
  169. * 日期字符串格式转换年月日时分秒
  170. *
  171. * @param dateStr
  172. * @return
  173. */
  174. private String parseStringToDateTime() {
  175. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  176. Date date = new Date();
  177. String daString = sdf.format(date);
  178. return daString;
  179. }
  180. }