ViewController.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 java.io.File;
  10. import java.io.FileWriter;
  11. import com.alibaba.fastjson.JSON;
  12. import com.alibaba.fastjson.JSONObject;
  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 com.zskk.service.DataService;
  21. import com.zskk.service.ServiceFactory;
  22. import com.zskk.tools.AESUtils;
  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. try {
  37. List<Record> d = Db.use("connected").find(this.getPara("sqlstr"));
  38. this.renderJson(d);
  39. } catch (Exception e) {
  40. // TODO: handle exception
  41. this.renderText(e.toString());
  42. }
  43. }
  44. /**
  45. * 在被连接数据库执行sql语句
  46. */
  47. public void getExam() {
  48. try {
  49. String IV = "0000000000000000";
  50. DataService dService = ServiceFactory.getService(DataService.class);
  51. String aesEncryptStr3 = dService.getExamList(this.getPara("data"));
  52. this.renderText(aesEncryptStr3);
  53. } catch (Exception e) {
  54. // TODO: handle exception
  55. this.renderText(e.toString());
  56. }
  57. }
  58. public void testConn() {
  59. try {
  60. DruidPlugin druidPluginConnected = createConnectedDruidPlugin();
  61. druidPluginConnected.start();
  62. // 配置ActiveRecord插件
  63. ActiveRecordPlugin arpConnected = new ActiveRecordPlugin("connected", druidPluginConnected);
  64. arpConnected.setDialect(new SqlServerDialect());
  65. arpConnected.start();
  66. } catch (Exception e) {
  67. // TODO: handle exception
  68. this.renderText(e.toString());
  69. }
  70. }
  71. public void testConn3() {
  72. DataService dService = ServiceFactory.getService(DataService.class);
  73. dService.updateCloudKey();
  74. renderNull();
  75. }
  76. public static DruidPlugin createConnectedDruidPlugin() {
  77. return new DruidPlugin(PropKit.get("jdbcUrl_connected"), PropKit.get("user_connected"),PropKit.get("password_connected").trim());
  78. }
  79. /**
  80. * post请求
  81. * @param url-请求地址
  82. * @param map-参数集合
  83. * @return
  84. */
  85. private static String doPost(String url, Map<String, String> map) {
  86. FormBody.Builder builder = new FormBody.Builder();
  87. for (String key : map.keySet()) {
  88. builder.add(key, map.get(key));
  89. }
  90. RequestBody formBody = builder.build();
  91. Request request = new Request.Builder().url(url).post(formBody).build();
  92. try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
  93. if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  94. String content = response.body().string();
  95. return content;
  96. } catch (IOException e) {
  97. // TODO Auto-generated catch block
  98. e.printStackTrace();
  99. return null;
  100. }
  101. }
  102. /**
  103. * 日期字符串格式转换
  104. * @param dateStr
  105. * @return
  106. */
  107. private Date parseStringToDate(String dateStr) {
  108. if (dateStr == null) {
  109. return new Date();
  110. }
  111. SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  112. Date date = null;
  113. try {
  114. date = sdf.parse(dateStr);
  115. } catch (ParseException e) {
  116. // TODO Auto-generated catch block
  117. e.printStackTrace();
  118. }
  119. return date;
  120. }
  121. public static void main(String[] args) {
  122. Map<String,String> paramsMap=new HashMap<String,String>();
  123. paramsMap.put("institution_id", "44100001");
  124. String contentString = doPost("https://risserver3.pacsonline.cn/butt/getExam/butt/getExam", paramsMap);
  125. System.out.println(contentString);
  126. }
  127. }