|
@@ -1,7 +1,12 @@
|
|
|
package com.zskk.control;
|
|
|
|
|
|
+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.InputStream;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
@@ -11,6 +16,8 @@ import java.util.Map;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.aliyun.oss.OSS;
|
|
|
+import com.aliyun.oss.OSSClientBuilder;
|
|
|
import com.jfinal.core.Controller;
|
|
|
import com.jfinal.kit.PropKit;
|
|
|
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
|
|
@@ -211,8 +218,8 @@ public class ViewController extends Controller {
|
|
|
annex_params.put("code", "1.2.8.20200820.1245.20220704114231427");
|
|
|
//附件类型1.mp4 2.pdf 3.jpeg
|
|
|
annex_params.put("annex_class_code", "3");
|
|
|
- DataService dService = ServiceFactory.getService(DataService.class);
|
|
|
- dService.saveAnnex(annex_params, "http://200.200.200.59/bgdata/DJ202207A/DJ20220704A1142/BG2022070400422.jpg");
|
|
|
+// DataService dService = ServiceFactory.getService(DataService.class);
|
|
|
+ saveAnnex(annex_params, "http://200.200.200.59/bgdata/DJ202207A/DJ20220704A1142/BG2022070400422.jpg");
|
|
|
renderText("succ");
|
|
|
|
|
|
} catch (Exception e) {
|
|
@@ -224,6 +231,67 @@ public class ViewController extends Controller {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ public void saveAnnex(Map<String, String> map, String filePath) {
|
|
|
+ OSS OSS_CLIENT = new OSSClientBuilder().build(PropKit.get("oss_endpoint"), PropKit.get("oss_accessKey"), PropKit.get("oss_secretKey"));
|
|
|
+
|
|
|
+ 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 = null;
|
|
|
+ try {
|
|
|
+ inputStream = new FileInputStream(fileStorePath);
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ 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 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 DruidPlugin createConnectedDruidPlugin() {
|
|
|
|
|
|
return new DruidPlugin(PropKit.get("jdbcUrl_connected"), PropKit.get("user_connected"),PropKit.get("password_connected").trim());
|