|
@@ -1,20 +1,28 @@
|
|
|
package com.zskk.service;
|
|
|
|
|
|
+import java.io.BufferedOutputStream;
|
|
|
import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
-import java.net.URI;
|
|
|
-import java.net.URISyntaxException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
|
import java.nio.file.Paths;
|
|
|
import java.nio.file.StandardOpenOption;
|
|
|
+import java.security.MessageDigest;
|
|
|
+import java.security.NoSuchAlgorithmException;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Random;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.inspurcloud.oss.client.impl.OSSClientImpl;
|
|
|
+import com.inspurcloud.oss.model.ObjectMetadata;
|
|
|
import com.jfinal.kit.PropKit;
|
|
|
|
|
|
import okhttp3.FormBody;
|
|
@@ -35,7 +43,6 @@ public class DataService {
|
|
|
|
|
|
private static final OSSClientImpl OSS_CLIENT = new OSSClientImpl(PropKit.get("oss_endpoint"), PropKit.get("oss_accessKey"), PropKit.get("oss_secretKey"));
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 获取未出报告的检查列表
|
|
|
* @param instutionId
|
|
@@ -70,13 +77,55 @@ public class DataService {
|
|
|
* @param instutionId
|
|
|
* @param number
|
|
|
*/
|
|
|
- public void saveAnnex(String filePath) {
|
|
|
- Map<String, String> map = new HashMap<>();
|
|
|
-
|
|
|
- postWithParameters(SAVE_ANNEX_URL, map);
|
|
|
+ public void saveAnnex(Map <String,String> map, String filePath) {
|
|
|
+ String newUrl = filePath.replaceAll("\\\\", "/") ;
|
|
|
+ String fileNameStr[] = newUrl.split("/");
|
|
|
+ String fileName = fileNameStr[fileNameStr.length-1];
|
|
|
+ String fileStorePath =getFileWithUrl(newUrl, fileName);
|
|
|
+ File file =new File(fileStorePath);
|
|
|
+ String eTag = getFileMd5(file);
|
|
|
+ Boolean eBoolean = OSS_CLIENT.doesObjectExist(PropKit.get("oss_bucketName"), PropKit.get("institution_id")+"/"+eTag);
|
|
|
+ if (!eBoolean) {
|
|
|
+ OSS_CLIENT.putObject(PropKit.get("oss_bucketName"), PropKit.get("institution_id")+"/"+eTag, file);
|
|
|
+ Boolean bBoolean = OSS_CLIENT.doesObjectExist(PropKit.get("oss_bucketName"), PropKit.get("institution_id")+"/"+eTag);
|
|
|
+ if (bBoolean) {
|
|
|
+ file.delete();
|
|
|
+ map.put("url", "https://annex.oss.cn-north-3.inspurcloudoss.com/"+PropKit.get("institution_id")+"/"+eTag);
|
|
|
+ map.put("name", eTag);
|
|
|
+ postWithParameters(SAVE_ANNEX_URL, map);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private String getFileMd5(File file) {
|
|
|
+ StringBuffer sb = new StringBuffer("");
|
|
|
+ try {
|
|
|
+ MessageDigest md = MessageDigest.getInstance("MD5");
|
|
|
+ md.update(FileUtils.readFileToByteArray(file));
|
|
|
+ byte b[] = md.digest();
|
|
|
+ int d;
|
|
|
+ for (int i = 0; i < b.length; i++) {
|
|
|
+ d = b[i];
|
|
|
+ if (d < 0) {
|
|
|
+ d = b[i] & 0xff;
|
|
|
+ // 与上一行效果等同
|
|
|
+ // i += 256;
|
|
|
+ }
|
|
|
+ if (d < 16)
|
|
|
+ sb.append("0");
|
|
|
+ sb.append(Integer.toHexString(d));
|
|
|
+ }
|
|
|
+ System.out.println(sb);
|
|
|
+
|
|
|
+ } catch (NoSuchAlgorithmException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
public static String postWithParameters(String url, Map<String, String> map) {
|
|
|
|
|
|
FormBody.Builder formbody = new FormBody.Builder();
|
|
@@ -102,25 +151,30 @@ public class DataService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static String getWithUrl(String url) {
|
|
|
+ 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);
|
|
|
- byte[] bytes = response.body().bytes();
|
|
|
+ InputStream inputStream = response.body().source().inputStream();
|
|
|
//本地文件夹目录(下载位置)
|
|
|
- String folder = "/home/zskk/";
|
|
|
- //切割出图片名称==》PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png
|
|
|
- String filename = "";
|
|
|
-
|
|
|
- Path filePath = Paths.get(folder + filename);
|
|
|
- //不存在文件 => 创建
|
|
|
- Files.write(filePath, bytes, StandardOpenOption.CREATE);
|
|
|
+ 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();
|
|
|
|
|
|
- System.out.println(response.body().string());
|
|
|
- return filename;
|
|
|
+ return savepath;
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
// TODO Auto-generated catch block
|
|
@@ -135,27 +189,29 @@ public class DataService {
|
|
|
// map.put("institution_id", "47600001");
|
|
|
// map.put("num", "10");
|
|
|
// postWithParameters(GET_EXAM_URL, map);
|
|
|
- System.out.print(GET_EXAM_URL);
|
|
|
- String bucketName = "annex";
|
|
|
- String key = "111/a.pdf";
|
|
|
- File file = new File("/Users/liutao/Desktop/1-销售部标准化操作手册(SOP)v1.0版-销售服务流程-中世康恺20220304.pdf");
|
|
|
- URI abvUri =null;
|
|
|
- try {
|
|
|
- abvUri =new URI("https://annex.oss.cn-north-3.inspurcloudoss.com/111/a.pdf");
|
|
|
- File file2 = new File(abvUri);
|
|
|
-// OSSClientImpl ossClient = new OSSClientImpl(endpoint, accessKey, secretKey);
|
|
|
+
|
|
|
+// getFileWithUrl("https://annex.oss.cn-north-3.inspurcloudoss.com/111/b.pdf");
|
|
|
|
|
|
- //简单文件上传
|
|
|
- OSS_CLIENT.putObject(bucketName, key, file);
|
|
|
- } catch (URISyntaxException e) {
|
|
|
- // TODO Auto-generated catch block
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+
|
|
|
+// String bucketName = "annex";
|
|
|
+// String key = "111/a.pdf";
|
|
|
+// File file = new File("/Users/liutao/Desktop/asdadsad.pdf");
|
|
|
+//
|
|
|
+// String endpoint = "oss.cn-north-3.inspurcloudoss.com";
|
|
|
+// String accessKey = "ZGEzOTY3YWQtNWI1OC00Y2MxLWJmNTgtZWVhN2M0ZjI5NTI4";
|
|
|
+// String secretKey = "YTc1NDQwZjItOWQ1OS00N2E3LTg4YmQtZjNjNjgzNzRjODQ5";
|
|
|
+// OSSClientImpl ossClient = new OSSClientImpl(endpoint, accessKey, secretKey);
|
|
|
+//
|
|
|
+// //简单文件上传
|
|
|
+// ossClient.putObject(bucketName, key, file);
|
|
|
+// ObjectMetadata objectMetadata = ossClient.getObjectMetadata(bucketName, "111/a.pdf");
|
|
|
+//
|
|
|
+// System.out.println(objectMetadata);
|
|
|
|
|
|
//创建OSSClient实例
|
|
|
|
|
|
// Boolean aBoolean = ossClient.doesObjectExist(bucketName, key);
|
|
|
-// System.out.print(aBoolean);
|
|
|
+// System.out.println(aBoolean);
|
|
|
}
|
|
|
|
|
|
}
|