Browse Source

新增移动云上传组件

LAPTOP-5NTQJPUS\LT 1 year ago
parent
commit
e2d1e4ac8f

+ 9 - 0
DataFusion/.classpath

@@ -27,5 +27,14 @@
 	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/jfinal-4.8-bin-with-src.jar"/>
 	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/commons-exec-1.3.jar"/>
 	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/EOS S3 Java SDK.jar"/>
+	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/commons-logging-1.3.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/jackson-core-2.16.0.jar"/>
+	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/jackson-annotations-2.16.0.jar"/>
+	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/httpclient-4.5.14.jar"/>
+	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/commons-codec-1.16.0.jar"/>
+	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/httpcore-4.4.16.jar"/>
+	<classpathentry kind="lib" path="WebRoot/WEB-INF/lib/joda-time-2.12.5.jar"/>
 	<classpathentry kind="output" path="WebRoot/WEB-INF/classes"/>
 </classpath>

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


BIN
DataFusion/WebRoot/WEB-INF/lib/joda-time-2.12.5.jar


+ 159 - 95
DataFusion/src/com/zskk/service/DataService.java

@@ -1,14 +1,17 @@
 package com.zskk.service;
 
+
+import java.io.File;
 import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
+
+
 import java.util.HashMap;
 import java.util.Map;
-import javax.xml.parsers.ParserConfigurationException;
+
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+
 import com.jfinal.kit.PropKit;
 import com.zskk.tools.XmlHelper;
 
@@ -18,111 +21,172 @@ 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 UPDATE_PATIENT_URL = "https://risserver3.pacsonline.cn/butt/saveExam";
-	
-    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 final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
-    
-    /**
-     * 获取未出报告的检查列表
-     * @param instutionId
-     * @param number
-     */
-    public JSONArray getExamList(Integer number) {
-    	Map <String,String> map = new HashMap<String,String>();
-    	map.put("institution_id", PropKit.get("institution_id"));
+	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 UPDATE_PATIENT_URL = "https://risserver3.pacsonline.cn/butt/saveExam";
+
+	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 final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
+
+	/**
+	 * 获取未出报告的检查列表
+	 * 
+	 * @param instutionId
+	 * @param number
+	 */
+	public JSONArray getExamList(Integer number) {
+		Map<String, String> map = new HashMap<String, String>();
+		map.put("institution_id", PropKit.get("institution_id"));
 //    	map.put("institution_id", "43600001");
 
-    	map.put("num", number.toString());
+		map.put("num", number.toString());
 		String content = postWithParameters(GET_EXAM_URL, map);
-	    JSONObject jsonObject = JSON.parseObject(content);
-	    if (!jsonObject.getString("msg").equals("success")) {
+		JSONObject jsonObject = JSON.parseObject(content);
+		if (!jsonObject.getString("msg").equals("success")) {
 			return null;
 		}
-		JSONArray jsonArray = JSON.parseArray(jsonObject.getString("data"));		
+		JSONArray jsonArray = JSON.parseArray(jsonObject.getString("data"));
 		return jsonArray;
-		
+
 	}
-    
-    /**
-     * 写入报告
-     * @param instutionId
-     * @param number
-     */
-    public void saveReport(Map <String,String> map) {
+
+	/**
+	 * 写入报告
+	 * 
+	 * @param instutionId
+	 * @param number
+	 */
+	public void saveReport(Map<String, String> map) {
 		postWithParameters(SAVE_REPORT_URL, map);
-		
+
 	}
-    
-    /**
-     * 更新患者信息
-     * 
-     * @param instutionId
-     * @param number
-     */
-     public void updatePatientInfo(Map<String, String> map) {
-     postWithParameters(UPDATE_PATIENT_URL, map);
-     }
-     
-     /**
-      * 创建登记信息
-      * 
-      * @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
-       */
-       public void saveFile(Map<String, String> map) {
-       postWithParameters(SAVE_FILE_URL, map);
-       }
-
-    public static String postWithParameters(String url, Map<String, String> map) {
-    	
-    	FormBody.Builder formbody = new FormBody.Builder();
-    	
-    	for (Map.Entry<String, String> entry : map.entrySet()) {
-    		formbody.add(entry.getKey(), entry.getValue());
+
+	/**
+	 * 更新患者信息  
+	 * 
+	 * @param instutionId
+	 * @param number
+	 */
+    public void updatePatientInfo(Map<String, String> map) {
+		postWithParameters(UPDATE_PATIENT_URL, map);
+	}
+
+	/**
+	 * 创建登记信息  
+	 * 
+	 * @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;
 		}
-		RequestBody requestBody = formbody.build();
-		
-		Request request = new Request.Builder()
-		        .url(url)
-		        .post(requestBody)
-		        .build();
-
-		    try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
-		      if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
-		      String content = response.body().string();
-		      return content;
-		    } catch (IOException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-				return null;
-			}	
+		String data = jsonObject.getString("data");
+		return data;
 	}
 
+	/**
+	 * 上传登记检查的文件  
+	 * 
+	 * @param instutionId
+	 * @param number
+	 */
+	public static void saveFile(String examid, String filepath) {
+		Map<String, String> map = new HashMap<String, String>();
+		map.put("institution_id", "13000003");
+		postWithParameters(SAVE_FILE_URL, map);
+		// 填写存储桶(Bucket)所在地域对应的 endpoint 和 Region。
+        // 以华东 - 苏州为例,endpoint 填写 https://eos-wuxi-1.cmecloud.cn,Region 填写 wuxi1。
+        String endpoint = "https://eos.jinan-4.cmecloud.cn";
+        String region = "jinan4";
+
+        // 填写 EOS 账号的认证信息,或者子账号的认证信息。
+        String accessKey = "94LX6HHDAV6AS4830IH8";
+        String secretKey = "h3WBubtjzRIMGIi6K3VWBT05LvdXiuNlSifSHKG5";
+
+        // 填写要上传到的存储桶名称,例如'example-bucket'。
+        String bucketName = "annex";
+        // 填写上传后要显示的对象名,例如'object.txt'。
+        String objectName = "43600001/<your-object-name>";
+        // 填写要上传的对象内容,例如'abcde'。
+//        String content = "<your-object-content>";
+        File content =  new File("C:\\Users\\LT\\Desktop\\afe1bc7906a0855b4e7432bf5a81492.jpg");
+
+     // 创建 AmazonS3 实例。
+        AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration(endpoint, region);
+        BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
+        AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials);
+        AmazonS3 client = AmazonS3ClientBuilder.standard()
+                .withEndpointConfiguration(endpointConfiguration)
+                .withCredentials(credentialsProvider).build();
+        // 上传文件。
+        try {
+        	 // 上传同时设置访问权限,例如'Private'私有权限。
+            PutObjectRequest request = new PutObjectRequest(bucketName, objectName, content);
+            request.setCannedAcl(CannedAccessControlList.PublicRead);
+            client.putObject(request);
+            // 关闭 client。
+            client.shutdown();
+        } catch (AmazonServiceException e) {
+            // 上传失败。
+            System.out.println("发生异常 AmazonServiceException,通常原因是请求内容错误。");
+            System.out.println("Error Code: " + e.getErrorCode());
+        } catch (SdkClientException e) {
+            // 上传失败。
+            System.out.println("发生异常 SdkClientException,通常原因是未能连接到 EOS 服务。");
+            System.out.println("Error Message: " + e.getMessage());
+        } finally {
+            if (client != null) {
+                client.shutdown();
+            }
+        }
+    }
+
+	public static String postWithParameters(String url, Map<String, String> map) {
+		FormBody.Builder formbody = new FormBody.Builder();
+
+		for (Map.Entry<String, String> entry : map.entrySet()) {
+			formbody.add(entry.getKey(), entry.getValue());
+		}
+		RequestBody requestBody = formbody.build();
+
+		Request request = new Request.Builder().url(url).post(requestBody).build();
+
+		try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
+			if (!response.isSuccessful())
+				throw new IOException("Unexpected code " + response);
+			String content = response.body().string();
+			return content;
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+			return null;
+		}
+	}
+	
+	public static void main(String[] args) {
+		saveFile("cnb515xp6rq064ds","");
+	}
 
 }

+ 2 - 0
DataFusion/src/com/zskk/task/USReportTask.java

@@ -55,6 +55,8 @@ public class USReportTask implements ITask {
 				}
 				
 				
+				
+				
 
 //    			if (record.getStr("IMPRESSION") == null && record.getStr("DESCRIPTION") == null) {
 //    				continue;