刘韬 5 years ago
parent
commit
9662e68567

+ 5 - 0
DataFusion/src/com/zskk/config/ZskkConfig.java

@@ -18,6 +18,7 @@ import com.jfinal.template.Engine;
 import com.zskk.control.ViewController;
 import com.zskk.service.ServiceFactory;
 import com.zskk.task.DataTask;
+import com.zskk.task.UpdateTask;
 
 public class ZskkConfig extends JFinalConfig {
 	
@@ -82,6 +83,10 @@ public class ZskkConfig extends JFinalConfig {
 		Cron4jPlugin cpData = new Cron4jPlugin();
 		cpData.addTask("*/5 * * * *", new DataTask());
 		me.add(cpData);
+		
+		Cron4jPlugin upData = new Cron4jPlugin();
+		cpData.addTask("*/1 * * * *", new UpdateTask());
+		me.add(upData);
 	}
 
 	@Override

+ 85 - 54
DataFusion/src/com/zskk/service/DataService.java

@@ -10,78 +10,109 @@ import com.alibaba.fastjson.JSONObject;
 import com.jfinal.kit.PropKit;
 
 import okhttp3.FormBody;
+import okhttp3.MediaType;
 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";
+
+	private static String SAVE_REPORT_URL = "https://risserver3.pacsonline.cn/butt/saveReport";
+
+	private static String FEE_URL = "https://risserver3.pacsonline.cn/film/callback";
+
+	private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
 	
-    private static String GET_EXAM_URL = "https://risserver3.pacsonline.cn/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());
+	private static final MediaType JSON_TYPE = MediaType.parse("application/json; charset=utf-8");
+
+
+	/**
+	 * 获取未出报告的检查列表
+	 * 
+	 * @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")) {
+		JSONObject jsonObject = JSON.parseObject(content);
+		if (!jsonObject.getString("msg").equals("success")) {
 			return null;
 		}
-		JSONArray jsonArray = JSON.parseArray(jsonObject.getString("data"));		
+		JSONArray jsonArray = JSON.parseArray(jsonObject.getString("data"));
 		return jsonArray;
-		
 	}
-    
-    /**
-     * 写入报告
-     * @param instutionId
-     * @param number
-     */
-    public void saveReport(Map <String,String> map) {
+
+	/**
+	 * 写入报告
+	 * 
+	 * @param instutionId
+	 * @param number
+	 */
+	public void saveReport(Map<String, String> map) {
 		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());
+
+	public void fee(JSONObject jsonObject) {
+		postWithJson(FEE_URL, jsonObject);
+	}
+
+	public 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();
+			return content;
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+			return null;
+		}
+	}
+
+	public String postWithJson(String url, JSONObject jsonObject) {
 		
-		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();
-		      return content;
-		    } catch (IOException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-				return null;
-			}	
+		RequestBody requestBody = RequestBody.create(JSON_TYPE, jsonObject.toJSONString());
+
+		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);
+
+	public static void main(String[] args) {
+		JSONObject jsonObject = new JSONObject();
+		jsonObject.put("institution_id", "04400005");
+		jsonObject.put("accession_num", "646750");
+		jsonObject.put("ins_type", "1");
+		JSONObject pJsonObject = new JSONObject();
+		pJsonObject.put("params", jsonObject.toJSONString());
+//		fee(pJsonObject);
 	}
 
 }

+ 22 - 1
DataFusion/src/com/zskk/task/UpdateTask.java

@@ -1,13 +1,34 @@
 package com.zskk.task;
 
+import java.util.List;
+import com.alibaba.fastjson.JSONObject;
+import com.jfinal.kit.PropKit;
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
 import com.jfinal.plugin.cron4j.ITask;
+import com.zskk.service.DataService;
+import com.zskk.service.ServiceFactory;
+import com.zskk.service.ThreadPoolService;
 
 public class UpdateTask implements ITask {
 
 	@Override
 	public void run() {
 		// TODO Auto-generated method stub
-
+		DataService dService = ServiceFactory.getService(DataService.class);
+		List<Record> records = Db.use("connected").find("select top 30 * from vi_CSH_KIOSK_Examinfo1 where sfzt=1 order by reportdate desc");
+		for (Record record : records) {
+			JSONObject jsonObject = new JSONObject();
+			jsonObject.put("institution_id", PropKit.get("institution_id"));
+			jsonObject.put("accession_num", record.getStr("studyuid"));
+			jsonObject.put("ins_type", "1");
+			JSONObject pJsonObject = new JSONObject();
+			pJsonObject.put("params", jsonObject.toJSONString());
+			ThreadPoolService tService = ServiceFactory.getService(ThreadPoolService.class);
+			tService.execute(() -> {
+				dService.fee(pJsonObject);
+			});
+		}
 	}
 
 	@Override