DataService.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.OkHttpClient;
  11. import okhttp3.Request;
  12. import okhttp3.RequestBody;
  13. import okhttp3.Response;
  14. public class DataService {
  15. private static String GET_EXAM_URL = "https://risserver3.pacsonline.cn/butt/getExam";
  16. private static String SAVE_REPORT_URL = "https://risserver3.pacsonline.cn/butt/saveReport";
  17. private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
  18. /**
  19. * 获取未出报告的检查列表
  20. * @param instutionId
  21. * @param number
  22. */
  23. public JSONArray getExamList(Integer number) {
  24. Map <String,String> map = new HashMap<String,String>();
  25. map.put("institution_id", PropKit.get("institution_id"));
  26. map.put("num", number.toString());
  27. String content = postWithParameters(GET_EXAM_URL, map);
  28. JSONObject jsonObject = JSON.parseObject(content);
  29. if (!jsonObject.getString("msg").equals("success")) {
  30. return null;
  31. }
  32. JSONArray jsonArray = JSON.parseArray(jsonObject.getString("data"));
  33. return jsonArray;
  34. }
  35. /**
  36. * 写入报告
  37. * @param instutionId
  38. * @param number
  39. */
  40. public void saveReport(Map <String,String> map) {
  41. postWithParameters(SAVE_REPORT_URL, map);
  42. }
  43. public static String postWithParameters(String url, Map<String, String> map) {
  44. FormBody.Builder formbody = new FormBody.Builder();
  45. for (Map.Entry<String, String> entry : map.entrySet()) {
  46. formbody.add(entry.getKey(), entry.getValue());
  47. }
  48. RequestBody requestBody = formbody.build();
  49. Request request = new Request.Builder()
  50. .url(url)
  51. .post(requestBody)
  52. .build();
  53. try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
  54. if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  55. String content = response.body().string();
  56. return content;
  57. } catch (IOException e) {
  58. // TODO Auto-generated catch block
  59. e.printStackTrace();
  60. return null;
  61. }
  62. }
  63. public static void main(String[] args) {
  64. Map <String,String> map = new HashMap<String,String>();
  65. map.put("institution_id", "47600001");
  66. map.put("num", "10");
  67. postWithParameters(GET_EXAM_URL, map);
  68. }
  69. }