刘韬 3 年之前
父节点
当前提交
f2d1f5287d

+ 4 - 4
DataFusion/src/com/zskk/config/ZskkConfig.java

@@ -17,7 +17,7 @@ import com.jfinal.template.Engine;
 import com.zskk.control.ViewController;
 import com.zskk.service.ServiceFactory;
 import com.zskk.task.CFindTask;
-import com.zskk.task.CMoveTask;
+import com.zskk.task.DownloadTask;
 import com.zskk.task.DataTask;
 import com.zskk.task.InfoTask;
 import com.zskk.task.UpdateTask;
@@ -115,9 +115,9 @@ public class ZskkConfig extends JFinalConfig {
 //		me.add(cgData);
 //		
 //		//comve获取检查影像
-//		Cron4jPlugin mvData = new Cron4jPlugin();
-//		mvData.addTask("*/1 * * * *", new CMoveTask());
-//		me.add(mvData);
+		Cron4jPlugin mvData = new Cron4jPlugin();
+		mvData.addTask("*/1 * * * *", new DownloadTask());
+		me.add(mvData);
 //		
 //		//更新患者信息检查影像
 //		Cron4jPlugin ifData = new Cron4jPlugin();

+ 0 - 79
DataFusion/src/com/zskk/task/CMoveTask.java

@@ -1,79 +0,0 @@
-package com.zskk.task;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.List;
-
-import com.jfinal.plugin.activerecord.Db;
-import com.jfinal.plugin.activerecord.Record;
-import com.jfinal.plugin.cron4j.ITask;
-import com.zskk.service.ServiceFactory;
-import com.zskk.service.ThreadPoolService;
-import com.zskk.tools.ExecUtil;
-
-public class CMoveTask implements ITask {
-
-	@Override
-	public void run() {
-		// TODO Auto-generated method stub
-		Integer max = 5;
-		List<Record> count = Db.use("local").find("select * from study where status =4");
-		//同时下载的队列
-		Integer flag = count.size();
-		if (flag >= max) {
-			return;
-		}
-		List<Record> studyidfinds = Db.use("local").find("select * from study where status =1 or status =2 order by createAt asc limit 8");
-		if (studyidfinds == null) {
-			return;
-		}
-		for (Record studyidfind : studyidfinds) {
-			flag++;
-			if (flag > max) {
-				return;
-			}
-			//状态4:下载中
-			studyidfind.set("status", 4);
-			Db.use("local").update("study", studyidfind);
-			
-			ThreadPoolService tService = ServiceFactory.getService(ThreadPoolService.class);
-			tService.execute(() -> {
-				String execCmd = ExecUtil.execCmd("/zskk_system/other/cmove.sh " + studyidfind.getStr("studyuid"));
-				if (execCmd.contains("Connection refused")) {
-					//状态2:错误
-					studyidfind.set("status", 2);
-					Db.use("local").update("study", studyidfind);
-				}else {
-					//状态2:完成
-					studyidfind.set("status", 3);
-					Db.use("local").update("study", studyidfind);
-				}
-				
-			});	
-			
-		}
-		
-	}
-
-	@Override
-	public void stop() {
-		// TODO Auto-generated method stub
-
-	}
-	
-	/**
-	 * 日期字符串格式转换
-	 * 
-	 * @param dateStr
-	 * @return
-	 */
-	private String parseStringToDate() {
-		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-		Date date = new Date();
-		long dInteger = date.getTime() - 600000;
-		String daString = sdf.format(new Date(dInteger));
-		return daString;
-
-	}
-
-}

+ 136 - 0
DataFusion/src/com/zskk/task/DownloadTask.java

@@ -0,0 +1,136 @@
+package com.zskk.task;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.Random;
+
+import com.jfinal.plugin.activerecord.Db;
+import com.jfinal.plugin.activerecord.Record;
+import com.jfinal.plugin.cron4j.ITask;
+import com.zskk.service.ServiceFactory;
+import com.zskk.service.ThreadPoolService;
+import com.zskk.tools.ExecUtil;
+
+import okhttp3.Call;
+import okhttp3.Callback;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.Response;
+import okhttp3.ResponseBody;
+import oracle.net.aso.i;
+
+public class DownloadTask implements ITask {
+
+	@Override
+	public void run() {
+		// TODO Auto-generated method stub
+		OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
+
+		Integer max = 2;
+		List<Record> count = Db.use("local").find("select * from study where status =4");
+		//同时下载的队列
+		Integer flag = count.size();
+		if (flag >= max) {
+			return;
+		}
+		List<Record> studyidfinds = Db.use("local").find("select * from study where status =1 or status =2 order by createAt asc limit 5");
+		if (studyidfinds == null) {
+			return;
+		}
+		for (Record studyidfind : studyidfinds) {
+			flag++;
+			if (flag > max) {
+				return;
+			}
+			//状态4:下载中
+			studyidfind.set("status", 4);
+			Db.use("local").update("study", studyidfind);
+			List<Record> dicomfind = Db.use("connected_dicom").find("select * from dicominfo where studyuid=?",studyidfind.getStr("studyuid"));
+			for (Record record : dicomfind) {
+				Request request = new Request.Builder()
+				        .url(record.getStr("URL"))
+				        .build();
+
+				OKHTTP_CLIENT.newCall(request).enqueue(new Callback() {
+				      @Override public void onFailure(Call call, IOException e) {
+				        e.printStackTrace();
+				      }
+
+				      @Override public void onResponse(Call call, Response response) throws IOException {
+				        try (ResponseBody responseBody = response.body()) {
+				          if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
+		                    writeFile(response,studyidfind.getStr("studyuid"));
+				        }
+				      }
+				    });
+			}
+			studyidfind.set("status", 3);
+			Db.use("local").update("study", studyidfind);
+		}
+		
+	}
+
+	@Override
+	public void stop() {
+		// TODO Auto-generated method stub
+
+	}
+	
+	private void writeFile(Response response, String uid) {
+        InputStream is = null;
+        FileOutputStream fos = null;
+        is = response.body().byteStream();
+        String path = "/home/lenovo/CFIND_XML";
+        Random r = new Random(1);
+        Integer ran1 = r.nextInt(1000);
+        File file = new File(path, uid+ran1.toString()+".dcm");
+        try {
+            fos = new FileOutputStream(file);
+            byte[] bytes = new byte[1024];
+            int len = 0;
+            //获取下载的文件的大小
+            long fileSize = response.body().contentLength();
+            long sum = 0;
+            int porSize = 0;
+            while ((len = is.read(bytes)) != -1) {
+                fos.write(bytes);
+                sum += len;
+                porSize = (int) ((sum * 1.0f / fileSize) * 100);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                if (is != null) {
+                    is.close();
+                }
+                if (fos != null) {
+                    fos.close();
+                }
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+	
+	/**
+	 * 日期字符串格式转换
+	 * 
+	 * @param dateStr
+	 * @return
+	 */
+	private String parseStringToDate() {
+		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+		Date date = new Date();
+		long dInteger = date.getTime() - 600000;
+		String daString = sdf.format(new Date(dInteger));
+		return daString;
+
+	}
+
+}

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

@@ -74,7 +74,7 @@ public class UpdateTask implements ITask {
 	private String parseStringToDateTime() {
 		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 		Date date = new Date();
-		Date dateBefore = new Date(date.getTime()-6000000);
+		Date dateBefore = new Date(date.getTime()-600000);
 		String daString = sdf.format(dateBefore);
 		return daString;