刘韬 3 年之前
父節點
當前提交
a8ff04ef04
共有 2 個文件被更改,包括 67 次插入60 次删除
  1. 60 53
      DataFusion/src/com/zskk/service/DataService.java
  2. 7 7
      DataFusion/src/com/zskk/task/CheckTask.java

+ 60 - 53
DataFusion/src/com/zskk/service/DataService.java

@@ -1,6 +1,12 @@
 package com.zskk.service;
 
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Map;
 import com.alibaba.fastjson.JSON;
@@ -30,7 +36,8 @@ public class DataService {
 	private static String SAVE_ANNEX_URL = "https://risserver3.pacsonline.cn/butt/saveAnnex";
 
 	private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
-
+	
+    OSS OSS_CLIENT = new OSSClientBuilder().build(PropKit.get("oss_endpoint"), PropKit.get("oss_accessKey"), PropKit.get("oss_secretKey"));
 
 	/**
 	 * 获取未出报告的检查列表
@@ -108,27 +115,28 @@ public class DataService {
 	 * 
 	 * @param instutionId
 	 * @param number
+	 * @throws FileNotFoundException 
 	 */
-//	public void saveAnnex(Map<String, String> map, String filePath) {
-//		String fileNameStr[] = filePath.split("/");
-//		String fileName = fileNameStr[fileNameStr.length - 1];
-//		String fileStorePath = getFileWithUrl(filePath, fileName);
-//		File file = new File(fileStorePath);
-//		String key = PropKit.get("institution_id") + "/" + fileName;
-//
-//		Boolean eBoolean = OSS_CLIENT.doesObjectExist(PropKit.get("oss_bucketName"), key);
-//		if (!eBoolean) {
-//			OSS_CLIENT.putObject(PropKit.get("oss_bucketName"), key, file);
-//			Boolean bBoolean = OSS_CLIENT.doesObjectExist(PropKit.get("oss_bucketName"), key);
-//			if (bBoolean) {
-//				file.delete();
-//				map.put("url", "https://zskk-image.oss-cn-beijing.aliyuncs.com/" + key);
-//				map.put("name", key);
-//				postWithParameters(SAVE_ANNEX_URL, map);
-//			}
-//		}
-//
-//	}
+	public void saveAnnex(Map<String, String> map, String filePath) throws FileNotFoundException {
+		String fileNameStr[] = filePath.split("/");
+		String fileName = fileNameStr[fileNameStr.length - 1];
+		String fileStorePath = getFileWithUrl(filePath, fileName);
+		File file = new File(fileStorePath);
+		String key = PropKit.get("institution_id") + "/" + fileName;
+        InputStream inputStream = new FileInputStream(fileStorePath);            
+		Boolean eBoolean = OSS_CLIENT.doesObjectExist(PropKit.get("oss_bucketName"), key);
+		if (!eBoolean) {
+			OSS_CLIENT.putObject(PropKit.get("oss_bucketName"), key, inputStream);
+			Boolean bBoolean = OSS_CLIENT.doesObjectExist(PropKit.get("oss_bucketName"), key);
+			if (bBoolean) {
+				file.delete();
+				map.put("url", "https://zskk-image.oss-cn-beijing.aliyuncs.com/" + key);
+				map.put("name", key);
+				postWithParameters(SAVE_ANNEX_URL, map);
+			}
+		}
+
+	}
 
 	public static String postWithParameters(String url, Map<String, String> map) {
 
@@ -174,38 +182,37 @@ public class DataService {
 		}
 	}
 
-//	public static String getFileWithUrl(String url, String filename) {
-//
-//		Request request = new Request.Builder().url(url).build();
-//		try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
-//			if (!response.isSuccessful())
-//				throw new IOException("Unexpected code " + response);
-//			InputStream inputStream = response.body().source().inputStream();
-//			// 本地文件夹目录(下载位置)
-//			String folder = PropKit.get("oss_localPath");
-//			// 下载文件保存位置
-//			String savepath = folder + "/" + filename;
-//			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(
-//					new FileOutputStream(new File(savepath)));
-//			byte[] data = new byte[1024];
-//			int len;
-//			int available = inputStream.available();
-//			while ((len = inputStream.read(data)) != -1) {
-//				bufferedOutputStream.write(data, 0, len);
-//			}
-//			bufferedOutputStream.flush();
-//			bufferedOutputStream.close();
-//			inputStream.close();
-//
-//			return savepath;
-//
-//		} catch (IOException e) {
-//			// TODO Auto-generated catch block
-//			e.printStackTrace();
-//			return "";
-//
-//		}
-//	}
+	public static String getFileWithUrl(String url, String filename) {
+
+		Request request = new Request.Builder().url(url).build();
+		try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
+			if (!response.isSuccessful())
+				throw new IOException("Unexpected code " + response);
+			InputStream inputStream = response.body().source().inputStream();
+			// 本地文件夹目录(下载位置)
+			String folder = PropKit.get("oss_localPath");
+			// 下载文件保存位置
+			String savepath = folder + "/" + filename;
+			BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(new File(savepath)));
+			byte[] data = new byte[1024];
+			int len;
+			int available = inputStream.available();
+			while ((len = inputStream.read(data)) != -1) {
+				bufferedOutputStream.write(data, 0, len);
+			}
+			bufferedOutputStream.flush();
+			bufferedOutputStream.close();
+			inputStream.close();
+
+			return savepath;
+
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+			return "";
+
+		}
+	}
 
 	public static void main(String[] args) {
 		Map<String, String> map = new HashMap<String, String>();

+ 7 - 7
DataFusion/src/com/zskk/task/CheckTask.java

@@ -84,13 +84,13 @@ public class CheckTask implements ITask {
 				tService.execute(() -> {
 					dService.saveReport(params);
 				});
-//				Map<String, String> annex_params = new HashMap<>();
-//				annex_params.put("institution_id", PropKit.get("institution_id"));
-//				annex_params.put("type", "4");
-//				annex_params.put("code", record.getStr("studyuid"));
-//				//附件类型1.mp4 2.pdf 3.jpeg
-//				annex_params.put("annex_class_code", "3");
-//	      		dService.saveAnnex(annex_params, record.getStr("reportpath"));
+				Map<String, String> annex_params = new HashMap<>();
+				annex_params.put("institution_id", PropKit.get("institution_id"));
+				annex_params.put("type", "4");
+				annex_params.put("code", record.getStr("studyuid"));
+				//附件类型1.mp4 2.pdf 3.jpeg
+				annex_params.put("annex_class_code", "3");
+	      		dService.saveAnnex(annex_params, record.getStr("reportpath"));
 			} catch (Exception e) {
 				// TODO: handle exception
 				continue;