DataService.java 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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/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. System.out.println(jsonArray);
  34. return jsonArray;
  35. }
  36. /**
  37. * 写入报告
  38. * @param instutionId
  39. * @param number
  40. */
  41. public void saveReport(String instutionId, Integer number) {
  42. Map <String,String> map = new HashMap<String,String>();
  43. postWithParameters(SAVE_REPORT_URL, map);
  44. }
  45. public static String postWithParameters(String url, Map<String, String> map) {
  46. FormBody.Builder formbody = new FormBody.Builder();
  47. for (Map.Entry<String, String> entry : map.entrySet()) {
  48. formbody.add(entry.getKey(), entry.getValue());
  49. }
  50. RequestBody requestBody = formbody.build();
  51. Request request = new Request.Builder()
  52. .url(url)
  53. .post(requestBody)
  54. .build();
  55. try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
  56. if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  57. String content = response.body().string();
  58. System.out.println(content);
  59. return content;
  60. } catch (IOException e) {
  61. // TODO Auto-generated catch block
  62. e.printStackTrace();
  63. return null;
  64. }
  65. }
  66. public static void main(String[] args) {
  67. Map <String,String> map = new HashMap<String,String>();
  68. map.put("institution_id", "47600001");
  69. map.put("num", "10");
  70. postWithParameters(GET_EXAM_URL, map);
  71. }
  72. }