|
@@ -1,5 +1,6 @@
|
|
|
package com.trs.digital.module.manager.controller.admin.search.controller;
|
|
package com.trs.digital.module.manager.controller.admin.search.controller;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.extra.ftp.Ftp;
|
|
import cn.hutool.extra.ftp.Ftp;
|
|
|
import cn.hutool.extra.ssh.Sftp;
|
|
import cn.hutool.extra.ssh.Sftp;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
@@ -465,7 +466,7 @@ public class AdvSearchController {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- @CrossOrigin
|
|
|
|
|
|
|
+/* @CrossOrigin
|
|
|
@Operation(summary = "检索-下载")
|
|
@Operation(summary = "检索-下载")
|
|
|
//@PreAuthorize("@ss.hasPermission('adv/search:ftp1')")
|
|
//@PreAuthorize("@ss.hasPermission('adv/search:ftp1')")
|
|
|
@PermitAll
|
|
@PermitAll
|
|
@@ -529,6 +530,78 @@ public class AdvSearchController {
|
|
|
|
|
|
|
|
// 获取字节数组
|
|
// 获取字节数组
|
|
|
return byteArrayOutputStream.toByteArray();
|
|
return byteArrayOutputStream.toByteArray();
|
|
|
|
|
+ }*/
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @CrossOrigin
|
|
|
|
|
+ @Operation(summary = "检索-下载")
|
|
|
|
|
+ //@PreAuthorize("@ss.hasPermission('adv/search:ftp1')")
|
|
|
|
|
+ @PermitAll
|
|
|
|
|
+ @RequestMapping("/download4")
|
|
|
|
|
+ public byte[] download4(@RequestBody AdvSearchSaveLabelsReqVO reqVO) throws IOException {
|
|
|
|
|
+
|
|
|
|
|
+ String filePath = reqVO.getFilePath();
|
|
|
|
|
+ /*String sourcename = reqVO.getSourcename();
|
|
|
|
|
+ String host = "";
|
|
|
|
|
+ String user = "";
|
|
|
|
|
+ String pass = "";
|
|
|
|
|
+
|
|
|
|
|
+ if ("ftp02".equals(sourcename)||"ftp2".equals(sourcename)) {
|
|
|
|
|
+ host = host_1;
|
|
|
|
|
+ user = user_1;
|
|
|
|
|
+ pass = pwd_1;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ host = host_2;
|
|
|
|
|
+ user = user_2;
|
|
|
|
|
+ pass = pwd_2;
|
|
|
|
|
+ }*/
|
|
|
|
|
+ // 创建 FTP 客户端
|
|
|
|
|
+ /*FTPClient client = new FTPClient();
|
|
|
|
|
+ client.setControlEncoding("UTF-8");
|
|
|
|
|
+ client.connect(host, 21);
|
|
|
|
|
+ if (FTPReply.isPositiveCompletion(client.getReplyCode())) {
|
|
|
|
|
+ String userName = user;
|
|
|
|
|
+ String password = pass;
|
|
|
|
|
+ if (StringUtil.isEmpty(userName)) {
|
|
|
|
|
+ userName = "anonymous"; //$NON-NLS-1$
|
|
|
|
|
+ password = ""; //$NON-NLS-1$
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!client.login(userName, password)) {
|
|
|
|
|
+ throw new IOException("user name or password is not correct, please check it."); //$NON-NLS-1$
|
|
|
|
|
+ }
|
|
|
|
|
+ client.setBufferSize(1024 * 1024);
|
|
|
|
|
+ client.setFileType(FTP.BINARY_FILE_TYPE);
|
|
|
|
|
+ }*/
|
|
|
|
|
+ // 获取文件内容
|
|
|
|
|
+// String ftpPath = filePath.replace("\\", "/").substring(filePath.indexOf("/") + 1);
|
|
|
|
|
+ String ftpPath = "/ftp"+filePath;
|
|
|
|
|
+ Sftp sftp = new Sftp(remoteHost, port, username, password);
|
|
|
|
|
+ File destFile = FileUtils.createTempFile();
|
|
|
|
|
+ sftp.download(ftpPath, destFile);
|
|
|
|
|
+ /*String filepath = ftpPath.substring(0, ftpPath.lastIndexOf("/"));
|
|
|
|
|
+ String filename = ftpPath.substring(ftpPath.lastIndexOf("/") + 1);
|
|
|
|
|
+ InputStream inputStream = client.retrieveFileStream(filePath);
|
|
|
|
|
+
|
|
|
|
|
+ // 使用 ByteArrayOutputStream 将文件内容写入字节数组
|
|
|
|
|
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
|
|
+ int bytesRead;
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ //
|
|
|
|
|
+ while ((bytesRead = inputStream.read(buffer)) != -1) {
|
|
|
|
|
+ byteArrayOutputStream.write(buffer, 0, bytesRead);
|
|
|
|
|
+ }
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ // 关闭流和FTP连接
|
|
|
|
|
+ inputStream.close();
|
|
|
|
|
+ client.logout();
|
|
|
|
|
+ client.disconnect();
|
|
|
|
|
+ }*/
|
|
|
|
|
+
|
|
|
|
|
+ // 获取字节数组
|
|
|
|
|
+// return byteArrayOutputStream.toByteArray();
|
|
|
|
|
+ return FileUtil.readBytes(destFile);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|