ViewController.java 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. package com.zskk.control;
  2. import java.io.IOException;
  3. import java.text.ParseException;
  4. import java.text.SimpleDateFormat;
  5. import java.util.Date;
  6. import java.util.HashMap;
  7. import java.util.List;
  8. import java.util.Map;
  9. import com.alibaba.fastjson.JSON;
  10. import com.alibaba.fastjson.JSONArray;
  11. import com.alibaba.fastjson.JSONObject;
  12. import com.jfinal.core.Controller;
  13. import com.jfinal.kit.PropKit;
  14. import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
  15. import com.jfinal.plugin.activerecord.Db;
  16. import com.jfinal.plugin.activerecord.Record;
  17. import com.jfinal.plugin.activerecord.dialect.OracleDialect;
  18. import com.jfinal.plugin.activerecord.dialect.SqlServerDialect;
  19. import com.jfinal.plugin.druid.DruidPlugin;
  20. import com.zskk.tools.AESUtils;
  21. import okhttp3.FormBody;
  22. import okhttp3.MediaType;
  23. import okhttp3.OkHttpClient;
  24. import okhttp3.Request;
  25. import okhttp3.RequestBody;
  26. import okhttp3.Response;
  27. public class ViewController extends Controller {
  28. private static final MediaType JSON_CODE = MediaType.get("application/json");
  29. private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
  30. /**
  31. * 在被连接数据库执行sql语句
  32. */
  33. public void executeSql() {
  34. try {
  35. List<Record> d = Db.use("connected").find(this.getPara("sqlstr"));
  36. this.renderJson(d);
  37. } catch (Exception e) {
  38. // TODO: handle exception
  39. this.renderText(e.toString());
  40. }
  41. }
  42. /**
  43. * 获取未出报告的检查列表
  44. * @param instutionId
  45. * @param number
  46. */
  47. public void getExamList() {
  48. String IV = "0000000000000000";
  49. Map <String,String> map = new HashMap<String,String>();
  50. map.put("exam_status","3");
  51. map.put("createAt", "2023-06-01 00:00:00,2023-06-15 12:00:00");
  52. map.put("num", "20");
  53. String aesEncryptStr = AESUtils.aesEncryptStr(JSON.toJSONString(map), PropKit.get("nw_key"),IV);
  54. Map <String,String> mapaes = new HashMap<String,String>();
  55. mapaes.put("data",aesEncryptStr);
  56. String content = postWithParameters("http://127.0.0.1:8082/df/view/getExam", mapaes);
  57. this.renderText(content);
  58. // JSONObject jsonObject = JSON.parseObject(content);
  59. // if (!jsonObject.getString("msg").equals("success")) {
  60. // return null;
  61. // }
  62. String aesDecodeStr ="";
  63. try {
  64. aesDecodeStr = AESUtils.aesDecodeStr(content, PropKit.get("nw_key"),IV);
  65. } catch (Exception e) {
  66. // TODO Auto-generated catch block
  67. e.printStackTrace();
  68. // return null;
  69. }
  70. // JSONArray jsonArray = JSON.parseArray(aesDecodeStr);
  71. // return jsonArray;
  72. // this.renderJson(jsonArray);
  73. }
  74. public void testConn() {
  75. try {
  76. DruidPlugin druidPluginConnected = createConnectedDruidPlugin();
  77. druidPluginConnected.start();
  78. // 配置ActiveRecord插件
  79. ActiveRecordPlugin arpConnected = new ActiveRecordPlugin("connected", druidPluginConnected);
  80. arpConnected.setDialect(new OracleDialect());
  81. arpConnected.start();
  82. } catch (Exception e) {
  83. // TODO: handle exception
  84. this.renderText(e.toString());
  85. }
  86. }
  87. public static DruidPlugin createConnectedDruidPlugin() {
  88. return new DruidPlugin(PropKit.get("jdbcUrl_connected"), PropKit.get("user_connected"),PropKit.get("password_connected").trim());
  89. }
  90. public void testConn2() {
  91. try {
  92. DruidPlugin druidPluginConnected = createConnectedDruidPlugin2(this.getPara("url"),this.getPara("name"),this.getPara("pass"));
  93. druidPluginConnected.start();
  94. // 配置ActiveRecord插件
  95. ActiveRecordPlugin arpConnected = new ActiveRecordPlugin("connected", druidPluginConnected);
  96. arpConnected.setDialect(new OracleDialect());
  97. arpConnected.start();
  98. } catch (Exception e) {
  99. // TODO: handle exception
  100. this.renderText(e.toString());
  101. }
  102. }
  103. public void testWeb() {
  104. try {
  105. JSONObject jsonObject = new JSONObject();
  106. jsonObject.put("functionCode", "queryPatByPatId");
  107. jsonObject.put("userid", "1301");
  108. JSONObject jsonObject2 = new JSONObject();
  109. jsonObject2.put("pattoken", "appuserrequest");
  110. jsonObject2.put("hispatid", this.getPara("hpid"));
  111. jsonObject.put("data", jsonObject2);
  112. // String c=postWithJson(this.getPara("hpid")"http://192.168.100.181:8102/api/tjwebapi/CommQuery",jsonObject);
  113. String c=postWithJson(this.getPara("url","http://192.168.100.181:8102/api/tjwebapi/CommQuery"),jsonObject);
  114. this.renderText(c);
  115. } catch (Exception e) {
  116. // TODO: handle exception
  117. this.renderText(e.toString());
  118. }
  119. }
  120. public String postWithJson(String url, JSONObject jsonObject) {
  121. RequestBody requestBody = RequestBody.create(JSON_CODE, jsonObject.toJSONString());
  122. Request request = new Request.Builder().url(url).post(requestBody).build();
  123. try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
  124. if (!response.isSuccessful())
  125. throw new IOException("Unexpected code " + response);
  126. String content = response.body().string();
  127. System.out.println(content);
  128. return content;
  129. } catch (IOException e) {
  130. // TODO Auto-generated catch block
  131. e.printStackTrace();
  132. return null;
  133. }
  134. }
  135. public static DruidPlugin createConnectedDruidPlugin2(String url,String name,String pass) {
  136. return new DruidPlugin(url, name,pass.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. /**
  162. * 日期字符串格式转换
  163. * @param dateStr
  164. * @return
  165. */
  166. private Date parseStringToDate(String dateStr) {
  167. if (dateStr == null) {
  168. return new Date();
  169. }
  170. SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  171. Date date = null;
  172. try {
  173. date = sdf.parse(dateStr);
  174. } catch (ParseException e) {
  175. // TODO Auto-generated catch block
  176. e.printStackTrace();
  177. }
  178. return date;
  179. }
  180. public static String postWithParameters(String url, Map<String, String> map) {
  181. FormBody.Builder formbody = new FormBody.Builder();
  182. for (Map.Entry<String, String> entry : map.entrySet()) {
  183. formbody.add(entry.getKey(), entry.getValue());
  184. }
  185. RequestBody requestBody = formbody.build();
  186. Request request = new Request.Builder()
  187. .url(url)
  188. .post(requestBody)
  189. .build();
  190. try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
  191. if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  192. String content = response.body().string();
  193. return content;
  194. } catch (IOException e) {
  195. // TODO Auto-generated catch block
  196. e.printStackTrace();
  197. return null;
  198. }
  199. }
  200. public static void main(String[] args) {
  201. Map<String,String> paramsMap=new HashMap<String,String>();
  202. paramsMap.put("institution_id", "44100001");
  203. String contentString = doPost("https://risserver3.pacsonline.cn/butt/getExam/butt/getExam", paramsMap);
  204. System.out.println(contentString);
  205. }
  206. }