|
@@ -1,6 +1,10 @@
|
|
|
package com.zskk.service;
|
|
|
|
|
|
+import java.io.BufferedOutputStream;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -15,11 +19,29 @@ import okhttp3.Request;
|
|
|
import okhttp3.RequestBody;
|
|
|
import okhttp3.Response;
|
|
|
|
|
|
+import com.amazonaws.AmazonServiceException;
|
|
|
+import com.amazonaws.SdkClientException;
|
|
|
+import com.amazonaws.auth.AWSCredentialsProvider;
|
|
|
+import com.amazonaws.auth.AWSStaticCredentialsProvider;
|
|
|
+import com.amazonaws.auth.BasicAWSCredentials;
|
|
|
+import com.amazonaws.client.builder.AwsClientBuilder;
|
|
|
+import com.amazonaws.services.s3.AmazonS3;
|
|
|
+import com.amazonaws.services.s3.AmazonS3ClientBuilder;
|
|
|
+import com.amazonaws.services.s3.model.CannedAccessControlList;
|
|
|
+import com.amazonaws.services.s3.model.PutObjectRequest;
|
|
|
+
|
|
|
+
|
|
|
public class DataService {
|
|
|
|
|
|
private static String GET_EXAM_URL = "https://risserver3.pacsonline.cn/butt/getExam";
|
|
|
|
|
|
private static String SAVE_REPORT_URL = "https://risserver3.pacsonline.cn/butt/saveReport";
|
|
|
+
|
|
|
+ private static String CREATE_REGISTER_URL = "https://risserver3.pacsonline.cn/butt/register";
|
|
|
+
|
|
|
+ private static String SAVE_FILE_URL = "https://risserver3.pacsonline.cn/butt/saveFile";
|
|
|
+
|
|
|
+ private static String SAVE_ANNEX_URL = "https://risserver3.pacsonline.cn/butt/saveAnnex";
|
|
|
|
|
|
private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
|
|
|
|
|
@@ -52,6 +74,64 @@ public class DataService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 创建登记信息
|
|
|
+ *
|
|
|
+ * @param instutionId
|
|
|
+ * @param number
|
|
|
+ */
|
|
|
+ public String createRegisterInfo(Map<String, String> map) {
|
|
|
+ String content = postWithParameters(CREATE_REGISTER_URL, map);
|
|
|
+ JSONObject jsonObject = JSON.parseObject(content);
|
|
|
+ if (!jsonObject.getString("msg").equals("success")) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ String data = jsonObject.getString("data");
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存附件
|
|
|
+ *
|
|
|
+ * @param instutionId
|
|
|
+ * @param number
|
|
|
+ * @throws FileNotFoundException
|
|
|
+ */
|
|
|
+ public void saveAnnex(Map<String, String> map, String filePath) {
|
|
|
+ AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration(PropKit.get("oss_endpoint"), PropKit.get("region"));
|
|
|
+ BasicAWSCredentials credentials = new BasicAWSCredentials(PropKit.get("oss_accessKey"), PropKit.get("oss_secretKey"));
|
|
|
+ AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials);
|
|
|
+ AmazonS3 client = AmazonS3ClientBuilder.standard()
|
|
|
+ .withEndpointConfiguration(endpointConfiguration)
|
|
|
+ .withCredentials(credentialsProvider).build();
|
|
|
+
|
|
|
+ String fileNameStr[] = filePath.split("=");
|
|
|
+ String fileName = fileNameStr[fileNameStr.length - 2];
|
|
|
+ String fileStorePath = getFileWithUrl(filePath, fileName);
|
|
|
+ File file = new File(fileStorePath);
|
|
|
+ String key = PropKit.get("institution_id") + "/" + fileName;
|
|
|
+
|
|
|
+ boolean exists = client.doesObjectExist(PropKit.get("oss_bucketName"), key);
|
|
|
+ if (!exists) {
|
|
|
+ PutObjectRequest request = new PutObjectRequest(PropKit.get("oss_bucketName"), key, file);
|
|
|
+ request.setCannedAcl(CannedAccessControlList.PublicRead);
|
|
|
+ client.putObject(request);
|
|
|
+ boolean bexists = client.doesObjectExist(PropKit.get("oss_bucketName"), key);
|
|
|
+ if (!bexists) {
|
|
|
+ PutObjectRequest request2 = new PutObjectRequest(PropKit.get("oss_bucketName"), key, file);
|
|
|
+ request.setCannedAcl(CannedAccessControlList.PublicRead);
|
|
|
+ client.putObject(request);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ client.shutdown();
|
|
|
+ map.put("url", "https://annex.eos.jinan-4.cmecloud.cn/" + key);
|
|
|
+ map.put("name", key);
|
|
|
+ postWithParameters(SAVE_ANNEX_URL, map);
|
|
|
+
|
|
|
+ file.delete();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
public static String postWithParameters(String url, Map<String, String> map) {
|
|
|
|
|
|
FormBody.Builder formbody = new FormBody.Builder();
|
|
@@ -77,6 +157,38 @@ 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 void main(String[] args) {
|
|
|
Map <String,String> map = new HashMap<String,String>();
|
|
|
map.put("institution_id", "47600001");
|