|
@@ -1,5 +1,9 @@
|
|
|
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;
|
|
@@ -10,85 +14,65 @@ import com.zskk.service.ServiceFactory;
|
|
|
import com.zskk.service.ThreadPoolService;
|
|
|
import com.zskk.tools.ExecUtil;
|
|
|
|
|
|
+import okhttp3.OkHttpClient;
|
|
|
+import okhttp3.Request;
|
|
|
+import okhttp3.Response;
|
|
|
+
|
|
|
public class CMoveTask implements ITask {
|
|
|
+
|
|
|
+ private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
|
|
|
|
|
|
@Override
|
|
|
public void run() {
|
|
|
// TODO Auto-generated method stub
|
|
|
-// List<Record> count = Db.use("local").find("select * from study where status =4");
|
|
|
-// //同时下载的队列
|
|
|
-// Integer flag = count.size();
|
|
|
-// if (flag >= 5) {
|
|
|
-// return;
|
|
|
-// }
|
|
|
- //延迟10分钟获取影像,并且查找状态为待CMOVE和错误状态的检查
|
|
|
- List<Record> studyidfinds = Db.use("local").find("select * from study where status =1 or status =2 order by createAt desc limit 1");
|
|
|
- if (studyidfinds == null) {
|
|
|
+ Record record = Db.use("connected").findFirst("select * from study where status=1 order by createAt asc");
|
|
|
+ if (record == null) {
|
|
|
return;
|
|
|
}
|
|
|
- for (Record studyidfind : studyidfinds) {
|
|
|
-// flag++;
|
|
|
-// if (flag <= 5) {
|
|
|
- //状态4:下载中
|
|
|
- studyidfind.set("status", 4);
|
|
|
- studyidfind.set("updateAt", parseStringToDateTime());
|
|
|
- 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);
|
|
|
- studyidfind.set("updateAt", parseStringToDateTime());
|
|
|
- Db.use("local").update("study", studyidfind);
|
|
|
- }else {
|
|
|
- //状态2:完成
|
|
|
- studyidfind.set("status", 3);
|
|
|
- studyidfind.set("updateAt", parseStringToDateTime());
|
|
|
- Db.use("local").update("study", studyidfind);
|
|
|
+ record.set("status", 2);
|
|
|
+ Db.use("connected").update("study", record);
|
|
|
+ List<Record> recordList = Db.use("connected").find("select * from tjpacs.V_ZSKK_WEBPACS_IMAGE where STUDYID=?",record.getStr("studyid"));
|
|
|
+ for (Record record2 : recordList) {
|
|
|
+ Request request = new Request.Builder()
|
|
|
+// .url("http://"+record2.getStr("FILEPATH").replace("\\\\", "/"))
|
|
|
+ .url(record2.getStr("HTTP_URL"))
|
|
|
+ .build();
|
|
|
+
|
|
|
+ String fileName = record2.getStr("INSUID");
|
|
|
+
|
|
|
+ try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
|
|
|
+ if (!response.isSuccessful())
|
|
|
+ throw new IOException("Unexpected code " + response);
|
|
|
+ String dirName = "/home/zskk/桌面/DICOM_URL";
|
|
|
+ File file = new File(dirName);
|
|
|
+ if (!file.exists()) {
|
|
|
+ file.mkdir();
|
|
|
+ }
|
|
|
+ if (response != null) {
|
|
|
+ InputStream is = response.body().byteStream();
|
|
|
+ FileOutputStream fos = new FileOutputStream(new File(dirName + "/" + fileName));
|
|
|
+ int len = 0;
|
|
|
+ byte[] buffer = new byte[2048];
|
|
|
+ while (-1 != (len = is.read(buffer))) {
|
|
|
+ fos.write(buffer, 0, len);
|
|
|
}
|
|
|
|
|
|
-// });
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
+ fos.flush();
|
|
|
+ fos.close();
|
|
|
+ is.close();
|
|
|
+ File filen2 = new File(dirName + "/" + fileName);
|
|
|
+ File filen = new File(dirName + "/" + fileName+".dcm");
|
|
|
+ filen2.renameTo(filen);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
-// //延迟10分钟获取影像,并且查找状态为待CMOVE和错误状态的检查
|
|
|
-// List<Record> studyidfindsde = Db.use("local").find("select * from study where status =1 or status =2 and createAt<? order by createAt desc limit 1",parseStringToDate());
|
|
|
-// if (studyidfindsde == null) {
|
|
|
-// return;
|
|
|
-// }
|
|
|
-// for (Record studyidfind : studyidfindsde) {
|
|
|
-//// flag++;
|
|
|
-//// if (flag <= 5) {
|
|
|
-// //状态4:下载中
|
|
|
-// studyidfind.set("status", 4);
|
|
|
-// studyidfind.set("updateAt", parseStringToDateTime());
|
|
|
-// 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);
|
|
|
-// studyidfind.set("updateAt", parseStringToDateTime());
|
|
|
-// Db.use("local").update("study", studyidfind);
|
|
|
-// }else {
|
|
|
-// //状态2:完成
|
|
|
-// studyidfind.set("status", 3);
|
|
|
-// studyidfind.set("updateAt", parseStringToDateTime());
|
|
|
-// Db.use("local").update("study", studyidfind);
|
|
|
-// }
|
|
|
-//
|
|
|
-//// });
|
|
|
-//// }
|
|
|
-//
|
|
|
-//
|
|
|
-// }
|
|
|
-
|
|
|
+ record.set("imageNum", recordList.size());
|
|
|
+ record.set("status", 3);
|
|
|
+ Db.use("connected").update("study", record);
|
|
|
}
|
|
|
|
|
|
@Override
|