DataService.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 FEE_URL = "https://risserver3.pacsonline.cn/film/callback";
  19. private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
  20. private static final MediaType JSON_TYPE = MediaType.parse("application/json; charset=utf-8");
  21. /**
  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. *
  42. * @param instutionId
  43. * @param number
  44. */
  45. public void saveReport(Map<String, String> map) {
  46. postWithParameters(SAVE_REPORT_URL, map);
  47. }
  48. public void fee(JSONObject jsonObject) {
  49. postWithJson(FEE_URL, jsonObject);
  50. }
  51. public String postWithParameters(String url, Map<String, String> map) {
  52. FormBody.Builder formbody = new FormBody.Builder();
  53. for (Map.Entry<String, String> entry : map.entrySet()) {
  54. formbody.add(entry.getKey(), entry.getValue());
  55. }
  56. RequestBody requestBody = formbody.build();
  57. Request request = new Request.Builder().url(url).post(requestBody).build();
  58. try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
  59. if (!response.isSuccessful())
  60. throw new IOException("Unexpected code " + response);
  61. String content = response.body().string();
  62. return content;
  63. } catch (IOException e) {
  64. // TODO Auto-generated catch block
  65. e.printStackTrace();
  66. return null;
  67. }
  68. }
  69. public String postWithJson(String url, JSONObject jsonObject) {
  70. RequestBody requestBody = RequestBody.create(JSON_TYPE, jsonObject.toJSONString());
  71. Request request = new Request.Builder().url(url).post(requestBody).build();
  72. try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
  73. if (!response.isSuccessful())
  74. throw new IOException("Unexpected code " + response);
  75. String content = response.body().string();
  76. System.out.println(content);
  77. return content;
  78. } catch (IOException e) {
  79. // TODO Auto-generated catch block
  80. e.printStackTrace();
  81. return null;
  82. }
  83. }
  84. public static void main(String[] args) {
  85. JSONObject jsonObject = new JSONObject();
  86. jsonObject.put("institution_id", "04400005");
  87. jsonObject.put("accession_num", "646750");
  88. jsonObject.put("ins_type", "1");
  89. JSONObject pJsonObject = new JSONObject();
  90. pJsonObject.put("params", jsonObject.toJSONString());
  91. // fee(pJsonObject);
  92. }
  93. }