|
@@ -3,36 +3,34 @@ package com.lsw.controller;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.jfinal.kit.PathKit;
|
|
|
+import org.springframework.web.bind.annotation.CrossOrigin;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.*;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.URL;
|
|
|
import java.util.Date;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.zip.ZipEntry;
|
|
|
-import java.util.zip.ZipOutputStream;
|
|
|
|
|
|
-import static java.time.LocalDateTime.now;
|
|
|
|
|
|
public class ExportController extends BaseController{
|
|
|
private static final int BUFFER_SIZE = 2 * 1024;
|
|
|
|
|
|
public void index() {
|
|
|
-
|
|
|
- String json="{\n" +
|
|
|
- " \"results\": [\n" +
|
|
|
- " {\n" +
|
|
|
- "\t \"accessToken\": \"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhdXRoMCIsImV4cCI6MTY0MzM4OTA4MCwidXNlcm5hbWUiOiJfX2pGRlpZdkxJRzZ1RmM3Q2RCTWcifQ.bMVXPUZu6r7aIgdRiItf4j42v6JYtU_Xlhs25f5pYRk\",\n" +
|
|
|
- " \"index\": [\n" +
|
|
|
- "\t {\"name\":\"159357.jpg\",\"path\":\"http://bpic.588ku.com/element_origin_min_pic/19/03/15/75076c485081d15ed9c224ad3e4ce4a1.jpg\",\"size\":\"39424\",\"userName\":\"SOM\",\"time\":\"2022-12-08 15:41:43\"},\n" +
|
|
|
- "\t {\"name\":\"Deel.xls\",\"path\":\"http://192.168.0.251/obpm/uploads/item/2022/1/a218eab9-2b57-437e-9053-f97c95cec9ac.xls\",\"size\":\"39424\",\"userName\":\"SOM\",\"time\":\"2022-12-08 15:41:43\"},\n" +
|
|
|
- "\t {\"name\":\"席澳冬简历(1).pdf\",\"path\":\"http://192.168.0.251/obpm/uploads/item/2022/1/d6d6518a-69d4-417f-acdf-15e262801860.pdf\",\"size\":\"150965\",\"userName\":\"SOM\",\"time\":\"2022-12-08 15:41:43\"},\n" +
|
|
|
- "\t {\"name\":\"国医大师黄瑾明教授学术信息数据管理平台 评审论证稿(修订模式).doc\",\"path\":\"http://192.168.0.251/obpm/uploads/item/2022/1/a1b2b180-cd21-49a1-a64f-a331bf0d0842.doc\",\"size\":\"1028103\",\"userName\":\"SOM\",\"time\":\"2022-11-28 16:18:02\"}\n" +
|
|
|
- "\t ]\n" +
|
|
|
- " }\n" +
|
|
|
- " ]\n" +
|
|
|
- "}\n";
|
|
|
-
|
|
|
+ System.out.println("zzzzzzzzzzzzzzz");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ String json= getRawData();
|
|
|
|
|
|
|
|
|
|
|
@@ -49,8 +47,8 @@ public class ExportController extends BaseController{
|
|
|
for (int j = 0; j < index.size(); j++) {
|
|
|
|
|
|
String name = index.getJSONObject(j).getString("name");
|
|
|
-
|
|
|
- String path = index.getJSONObject(j).getString("path");
|
|
|
+ String path = "http://192.168.0.251/obpm"+ index.getJSONObject(j).getString("path");
|
|
|
+
|
|
|
|
|
|
downLoadFromUrl(path, name, PathKit.getWebRootPath()+"/download/"+sdf.format(dt)+"/",accessToken);
|
|
|
}
|
|
@@ -59,9 +57,9 @@ public class ExportController extends BaseController{
|
|
|
|
|
|
|
|
|
|
|
|
- String fileSourcePath = PathKit.getWebRootPath()+ "/download/"+sdf.format(dt)+"/";
|
|
|
+ String fileSourcePath = PathKit.getWebRootPath()+ "/download/"+sdf.format(dt)+"/";
|
|
|
|
|
|
- System.out.println("now--"+now());
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -74,9 +72,15 @@ public class ExportController extends BaseController{
|
|
|
System.out.printf(flag2 ? "文件打包成功!" : "文件打包失败!");
|
|
|
|
|
|
|
|
|
- renderFile("http://192.168.0.102:9999/upload/"+sdf.format(dt)+".zip");
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
System.out.println(" 下载======"+ "http://192.168.0.102:9999/upload/"+sdf.format(dt)+".zip");
|
|
|
+
|
|
|
+ renderJson("{'url':'http://192.168.0.102:9999/upload/"+sdf.format(dt)+".zip'}");
|
|
|
}
|
|
|
|
|
|
* 网络Url下载文件
|
|
@@ -99,7 +103,7 @@ public class ExportController extends BaseController{
|
|
|
InputStream inputStream = conn.getInputStream();
|
|
|
|
|
|
byte[] getData = readInputStream(inputStream);
|
|
|
-
|
|
|
+
|
|
|
|
|
|
File saveDir = new File(savePath);
|
|
|
if (!saveDir.exists()) {
|
|
@@ -139,10 +143,6 @@ public class ExportController extends BaseController{
|
|
|
return bos.toByteArray();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
* 压缩成ZIP
|
|
|
* @param srcFilePath 压缩文件路径
|
|
@@ -150,7 +150,6 @@ public class ExportController extends BaseController{
|
|
|
* @param KeepDirStructure 是否保留原来的目录结构,true:保留目录结构;
|
|
|
* false:所有文件跑到压缩包根目录下(注意:不保留目录结构可能会出现同名文件,会压缩失败)
|
|
|
* @throws Exception 压缩失败会抛出异常
|
|
|
-
|
|
|
*/
|
|
|
|
|
|
public static boolean toZip(String srcFilePath, String tarFilePath, boolean KeepDirStructure) {
|
|
@@ -202,7 +201,7 @@ public class ExportController extends BaseController{
|
|
|
|
|
|
byte[] buf = new byte[BUFFER_SIZE];
|
|
|
if (sourceFile.isFile()) {
|
|
|
-
|
|
|
+
|
|
|
zos.putNextEntry(new org.apache.tools.zip.ZipEntry(name));
|
|
|
|
|
|
int len;
|
|
@@ -218,7 +217,7 @@ public class ExportController extends BaseController{
|
|
|
} else {
|
|
|
File[] listFiles = sourceFile.listFiles();
|
|
|
if (listFiles == null || listFiles.length == 0) {
|
|
|
-
|
|
|
+
|
|
|
if (KeepDirStructure) {
|
|
|
|
|
|
zos.putNextEntry(new org.apache.tools.zip.ZipEntry(name + "/"));
|
|
@@ -230,8 +229,8 @@ public class ExportController extends BaseController{
|
|
|
for (File file : listFiles) {
|
|
|
|
|
|
if (KeepDirStructure) {
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
compress(file, zos, name + "/" + file.getName(), KeepDirStructure);
|
|
|
} else {
|
|
|
compress(file, zos, file.getName(), KeepDirStructure);
|
|
@@ -256,4 +255,59 @@ public class ExportController extends BaseController{
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ @CrossOrigin
|
|
|
+ public void outputFile(String fileName) throws IOException {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ String basePath = PathKit.getWebRootPath() +"/upload";
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ String targetPath = basePath+File.separator+fileName;
|
|
|
+ System.out.println("targetPath===="+targetPath);
|
|
|
+
|
|
|
+ HttpServletResponse res = getResponse();
|
|
|
+ res.setContentType("text/html; charset=UTF-8");
|
|
|
+ res.setContentType("application/x-msdownload");
|
|
|
+ res.setHeader("Content-disposition", "attachment;filename="+fileName);
|
|
|
+ OutputStream out = null;
|
|
|
+ try {
|
|
|
+ out = res.getOutputStream();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ InputStream is = new FileInputStream(targetPath);
|
|
|
+ byte[] Buffer = new byte[4096];
|
|
|
+ int size = 0;
|
|
|
+ while((size=is.read(Buffer)) != -1){
|
|
|
+ out.write(Buffer, 0, size);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ out.flush();
|
|
|
+ out.close();
|
|
|
+ is.close();
|
|
|
+ renderNull();
|
|
|
+ }
|
|
|
+
|
|
|
}
|