ViewController.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. package com.zskk.control;
  2. import java.io.File;
  3. import java.io.FileOutputStream;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.text.ParseException;
  7. import java.text.SimpleDateFormat;
  8. import java.util.Date;
  9. import java.util.HashMap;
  10. import java.util.List;
  11. import java.util.Map;
  12. import com.alibaba.fastjson.JSON;
  13. import com.jfinal.core.Controller;
  14. import com.jfinal.kit.PropKit;
  15. import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
  16. import com.jfinal.plugin.activerecord.Db;
  17. import com.jfinal.plugin.activerecord.Record;
  18. import com.jfinal.plugin.activerecord.dialect.SqlServerDialect;
  19. import com.jfinal.plugin.druid.DruidPlugin;
  20. import okhttp3.FormBody;
  21. import okhttp3.MediaType;
  22. import okhttp3.OkHttpClient;
  23. import okhttp3.Request;
  24. import okhttp3.RequestBody;
  25. import okhttp3.Response;
  26. public class ViewController extends Controller {
  27. private static final MediaType JSON_CODE = MediaType.get("application/json; charset=utf-8");
  28. private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
  29. /**
  30. * 在被连接数据库执行sql语句
  31. */
  32. public void executeSql() {
  33. try {
  34. List<Record> d = Db.use("connected").find(this.getPara("sqlstr"));
  35. this.renderJson(d);
  36. } catch (Exception e) {
  37. // TODO: handle exception
  38. this.renderText(e.toString());
  39. }
  40. }
  41. public void testConn() {
  42. try {
  43. DruidPlugin druidPluginConnected = createConnectedDruidPlugin();
  44. druidPluginConnected.start();
  45. // 配置ActiveRecord插件
  46. ActiveRecordPlugin arpConnected = new ActiveRecordPlugin("connected", druidPluginConnected);
  47. arpConnected.setDialect(new SqlServerDialect());
  48. arpConnected.start();
  49. } catch (Exception e) {
  50. // TODO: handle exception
  51. this.renderText(e.toString());
  52. }
  53. }
  54. public void name() {
  55. try {
  56. // List<Record> record = Db.use("connected").find("select * from v_webpacs_image where rownum <10 and IMAGEDATE>to_date('"+parseStringToDate()+"','yyyy-mm-dd hh24:mi:ss')");
  57. // for (Record record2 : record) {
  58. Request request = new Request.Builder()
  59. .url("http://172.16.17.71:808/CT64\\\\20201119\\\\Xu Gang\\\\CT.1.2.840.113704.1.111.2528.1605799032.9683".replace("\\\\", "/"))
  60. .build();
  61. // String fileName = record2.getStr("IMAGE_UID");
  62. String fileName = "aaaa";
  63. try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
  64. if (!response.isSuccessful())
  65. throw new IOException("Unexpected code " + response);
  66. String dirName = "./down";
  67. File file = new File(dirName);
  68. if (!file.exists()) {
  69. file.mkdir();
  70. }
  71. if (response != null) {
  72. InputStream is = response.body().byteStream();
  73. FileOutputStream fos = new FileOutputStream(new File(dirName + "/" + fileName));
  74. int len = 0;
  75. byte[] buffer = new byte[2048];
  76. while (-1 != (len = is.read(buffer))) {
  77. fos.write(buffer, 0, len);
  78. }
  79. fos.flush();
  80. fos.close();
  81. is.close();
  82. File filen2 = new File(dirName + "/" + fileName);
  83. File filen = new File(dirName + "/" + fileName+".dcm");
  84. filen2.renameTo(filen);
  85. }
  86. } catch (IOException e) {
  87. // TODO Auto-generated catch block
  88. this.renderText("1*"+e.toString());
  89. }
  90. // }
  91. } catch (Exception e) {
  92. // TODO: handle exception
  93. this.renderText(e.toString());
  94. }
  95. }
  96. public static DruidPlugin createConnectedDruidPlugin() {
  97. return new DruidPlugin(PropKit.get("jdbcUrl_connected"), PropKit.get("user_connected"),PropKit.get("password_connected").trim());
  98. }
  99. /**
  100. * post请求
  101. * @param url-请求地址
  102. * @param map-参数集合
  103. * @return
  104. */
  105. private static String doPost(String url, Map<String, String> map) {
  106. FormBody.Builder builder = new FormBody.Builder();
  107. for (String key : map.keySet()) {
  108. builder.add(key, map.get(key));
  109. }
  110. RequestBody formBody = builder.build();
  111. Request request = new Request.Builder().url(url).post(formBody).build();
  112. try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
  113. if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  114. String content = response.body().string();
  115. return content;
  116. } catch (IOException e) {
  117. // TODO Auto-generated catch block
  118. e.printStackTrace();
  119. return null;
  120. }
  121. }
  122. /**
  123. * 日期字符串格式转换
  124. * @param dateStr
  125. * @return
  126. */
  127. private String parseStringToDate() {
  128. SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  129. Date date = new Date();
  130. long dInteger =date.getTime()-65000;
  131. String daString = sdf.format(new Date(dInteger));
  132. return daString;
  133. }
  134. public static void main(String[] args) {
  135. Map<String,String> paramsMap=new HashMap<String,String>();
  136. paramsMap.put("institution_id", "44100001");
  137. String contentString = doPost("https://risserver3.pacsonline.cn/butt/getExam/butt/getExam", paramsMap);
  138. System.out.println(contentString);
  139. }
  140. }