12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- package com.zskk.service;
- import java.io.IOException;
- import java.util.HashMap;
- import java.util.Map;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.jfinal.kit.PropKit;
- import okhttp3.FormBody;
- import okhttp3.OkHttpClient;
- import okhttp3.Request;
- import okhttp3.RequestBody;
- import okhttp3.Response;
- public class DataService {
-
- private static String GET_EXAM_URL = "https://risserver3.pacsonline.cn/butt/getExam/butt/getExam";
-
- private static String SAVE_REPORT_URL = "https://risserver3.pacsonline.cn/butt/saveReport";
-
- private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
-
- /**
- * 获取未出报告的检查列表
- * @param instutionId
- * @param number
- */
- public JSONArray getExamList(Integer number) {
- Map <String,String> map = new HashMap<String,String>();
- map.put("institution_id", PropKit.get("institution_id"));
- map.put("num", number.toString());
- String content = postWithParameters(GET_EXAM_URL, map);
- JSONObject jsonObject = JSON.parseObject(content);
- if (!jsonObject.getString("msg").equals("success")) {
- return null;
- }
- JSONArray jsonArray = JSON.parseArray(jsonObject.getString("data"));
- System.out.println(jsonArray);
- return jsonArray;
-
- }
-
- /**
- * 写入报告
- * @param instutionId
- * @param number
- */
- public void saveReport(String instutionId, Integer number) {
- Map <String,String> map = new HashMap<String,String>();
- postWithParameters(SAVE_REPORT_URL, map);
-
- }
-
- public static String postWithParameters(String url, Map<String, String> map) {
-
- FormBody.Builder formbody = new FormBody.Builder();
-
- for (Map.Entry<String, String> entry : map.entrySet()) {
- formbody.add(entry.getKey(), entry.getValue());
- }
- RequestBody requestBody = formbody.build();
-
- Request request = new Request.Builder()
- .url(url)
- .post(requestBody)
- .build();
- try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
- if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
- String content = response.body().string();
- System.out.println(content);
- return content;
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return null;
- }
- }
-
- public static void main(String[] args) {
- Map <String,String> map = new HashMap<String,String>();
- map.put("institution_id", "47600001");
- map.put("num", "10");
- postWithParameters(GET_EXAM_URL, map);
- }
- }
|