|
@@ -1,6 +1,12 @@
|
|
package com.zskk.service;
|
|
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.IOException;
|
|
|
|
+import java.io.InputStream;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import com.alibaba.fastjson.JSON;
|
|
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 String SAVE_ANNEX_URL = "https://risserver3.pacsonline.cn/butt/saveAnnex";
|
|
|
|
|
|
private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
|
|
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 instutionId
|
|
* @param number
|
|
* @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) {
|
|
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) {
|
|
public static void main(String[] args) {
|
|
Map<String, String> map = new HashMap<String, String>();
|
|
Map<String, String> map = new HashMap<String, String>();
|