Browse Source

增加移动云附件功能

LAPTOP-5NTQJPUS\LT 9 months ago
parent
commit
3c437e8ba8

+ 11 - 2
DataFusion/.classpath

@@ -9,20 +9,29 @@
 		</attributes>
 	</classpathentry>
 	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/annotations-13.0.jar"/>
+	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/commons-codec-1.16.0.jar"/>
+	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/commons-logging-1.3.0.jar"/>
 	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/cron4j-2.2.5.jar"/>
 	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/druid-1.1.21.jar"/>
+	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/EOS S3 Java SDK.jar"/>
 	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/fastjson-1.2.62.jar"/>
+	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/httpclient-4.5.14.jar"/>
+	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/httpcore-4.4.16.jar"/>
+	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/jackson-annotations-2.16.0.jar"/>
+	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/jackson-core-2.16.0.jar"/>
+	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/jackson-databind-2.16.0.jar"/>
+	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/jackson-dataformat-cbor-2.16.0.jar"/>
 	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/javax.activation-1.2.0.jar"/>
 	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/jaxb-api-2.3.0.jar"/>
 	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/jaxb-core-2.3.0.jar"/>
 	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/jaxb-impl-2.3.0.jar"/>
+	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/jfinal-4.8-bin-with-src.jar"/>
 	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/kotlin-stdlib-1.3.50.jar"/>
 	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/kotlin-stdlib-common-1.3.50.jar"/>
 	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/mysql-connector-java-8.0.18.jar"/>
 	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/ojdbc6.jar"/>
-	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/okhttp-4.2.2.jar" sourcepath="/Users/liutao/.m2/repository/com/squareup/okhttp3/okhttp/4.2.2/okhttp-4.2.2-sources.jar"/>
+	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/okhttp-4.2.2.jar"/>
 	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/okio-2.2.2.jar"/>
 	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/sqljdbc42.jar"/>
-	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/jfinal-4.8-bin-with-src.jar"/>
 	<classpathentry kind="output" path="WebRoot/WEB-INF/classes"/>
 </classpath>

BIN
DataFusion/WebRoot/WEB-INF/lib/EOS S3 Java SDK.jar


BIN
DataFusion/WebRoot/WEB-INF/lib/commons-codec-1.16.0.jar


BIN
DataFusion/WebRoot/WEB-INF/lib/commons-logging-1.3.0.jar


BIN
DataFusion/WebRoot/WEB-INF/lib/httpclient-4.5.14.jar


BIN
DataFusion/WebRoot/WEB-INF/lib/httpcore-4.4.16.jar


BIN
DataFusion/WebRoot/WEB-INF/lib/jackson-annotations-2.16.0.jar


BIN
DataFusion/WebRoot/WEB-INF/lib/jackson-core-2.16.0.jar


BIN
DataFusion/WebRoot/WEB-INF/lib/jackson-databind-2.16.0.jar


BIN
DataFusion/WebRoot/WEB-INF/lib/jackson-dataformat-cbor-2.16.0.jar


+ 112 - 0
DataFusion/src/com/zskk/service/DataService.java

@@ -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");