DataService.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. package com.zskk.service;
  2. import java.io.IOException;
  3. import java.util.HashMap;
  4. import java.util.Map;
  5. import com.alibaba.fastjson.JSON;
  6. import com.alibaba.fastjson.JSONArray;
  7. import com.alibaba.fastjson.JSONObject;
  8. import com.jfinal.kit.PropKit;
  9. import okhttp3.FormBody;
  10. import okhttp3.MediaType;
  11. import okhttp3.OkHttpClient;
  12. import okhttp3.Request;
  13. import okhttp3.RequestBody;
  14. import okhttp3.Response;
  15. public class DataService {
  16. private static String GET_EXAM_URL = "https://risserver3.pacsonline.cn/butt/getExam";
  17. private static String SAVE_REPORT_URL = "https://risserver3.pacsonline.cn/butt/saveReport";
  18. private static String UPDATE_PATIENT_URL = "https://risserver3.pacsonline.cn/butt/saveExam";
  19. private static String FEE_URL = "https://risserver3.pacsonline.cn/film/callback";
  20. private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
  21. private static final MediaType JSON_TYPE = MediaType.parse("application/json; charset=utf-8");
  22. /**
  23. * 获取未出报告的检查列表
  24. * @param instutionId
  25. * @param number
  26. */
  27. public JSONArray getExamList(Integer number) {
  28. Map <String,String> map = new HashMap<String,String>();
  29. map.put("institution_id", PropKit.get("institution_id"));
  30. map.put("num", number.toString());
  31. String content = postWithParameters(GET_EXAM_URL, map);
  32. JSONObject jsonObject = JSON.parseObject(content);
  33. if (!jsonObject.getString("msg").equals("success")) {
  34. return null;
  35. }
  36. JSONArray jsonArray = JSON.parseArray(jsonObject.getString("data"));
  37. return jsonArray;
  38. }
  39. /**
  40. * 写入报告
  41. * @param instutionId
  42. * @param number
  43. */
  44. public void saveReport(Map <String,String> map) {
  45. postWithParameters(SAVE_REPORT_URL, map);
  46. }
  47. /**
  48. * 更新患者信息
  49. * @param instutionId
  50. * @param number
  51. */
  52. public void updatePatientInfo(Map<String, String> map) {
  53. postWithParameters(UPDATE_PATIENT_URL, map);
  54. }
  55. /*
  56. * 医院代收
  57. */
  58. public void fee(JSONObject jsonObject) {
  59. postWithJson(FEE_URL, jsonObject);
  60. }
  61. /*
  62. * 医院代收
  63. */
  64. public JSONObject getReport(String code) {
  65. String content = getWithUrl("http://192.168.31.10:874/df/view/executeSql?sqlstr=select * from reportinfo where 检查编号 = " + code);
  66. JSONArray jsonArray = JSON.parseArray(content);
  67. if (jsonArray.size()>0) {
  68. JSONObject jsonObject = null;
  69. for (Object object : jsonArray) {
  70. jsonObject = JSON.parseObject(object.toString());
  71. }
  72. return jsonObject;
  73. }else {
  74. return null;
  75. }
  76. }
  77. public static String postWithParameters(String url, Map<String, String> map) {
  78. FormBody.Builder formbody = new FormBody.Builder();
  79. for (Map.Entry<String, String> entry : map.entrySet()) {
  80. formbody.add(entry.getKey(), entry.getValue());
  81. }
  82. RequestBody requestBody = formbody.build();
  83. Request request = new Request.Builder()
  84. .url(url)
  85. .post(requestBody)
  86. .build();
  87. try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
  88. if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  89. String content = response.body().string();
  90. return content;
  91. } catch (IOException e) {
  92. // TODO Auto-generated catch block
  93. e.printStackTrace();
  94. return null;
  95. }
  96. }
  97. public String postWithJson(String url, JSONObject jsonObject) {
  98. RequestBody requestBody = RequestBody.create(JSON_TYPE, jsonObject.toJSONString());
  99. Request request = new Request.Builder().url(url).post(requestBody).build();
  100. try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
  101. if (!response.isSuccessful())
  102. throw new IOException("Unexpected code " + response);
  103. String content = response.body().string();
  104. System.out.println(content);
  105. return content;
  106. } catch (IOException e) {
  107. // TODO Auto-generated catch block
  108. e.printStackTrace();
  109. return null;
  110. }
  111. }
  112. public String getWithUrl(String url) {
  113. Request request = new Request.Builder()
  114. .url(url)
  115. .build();
  116. try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
  117. if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  118. String content = response.body().string();
  119. System.out.println(content);
  120. return content;
  121. } catch (IOException e) {
  122. // TODO Auto-generated catch block
  123. e.printStackTrace();
  124. return null;
  125. }
  126. }
  127. public static void main(String[] args) {
  128. Map <String,String> map = new HashMap<String,String>();
  129. map.put("institution_id", "47600001");
  130. map.put("num", "10");
  131. postWithParameters(GET_EXAM_URL, map);
  132. }
  133. }