mirror of
https://gitee.com/yudaocode/yudao-boot-mini.git
synced 2026-03-22 05:27:15 +08:00
Merge branch 'master-jdk17' of https://gitee.com/zhijiantianya/ruoyi-vue-pro
# Conflicts: # yudao-dependencies/pom.xml # yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java # yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/framework/file/core/client/ftp/FtpFileClientConfig.java # yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/framework/file/core/client/sftp/SftpFileClientConfig.java
This commit is contained in:
@@ -101,7 +101,7 @@
|
||||
<artifactId>commons-net</artifactId> <!-- 文件客户端:解决 ftp 连接 -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jcraft</groupId>
|
||||
<groupId>com.github.mwiede</groupId>
|
||||
<artifactId>jsch</artifactId> <!-- 文件客户端:解决 sftp 连接 -->
|
||||
</dependency>
|
||||
<!-- 文件客户端:解决阿里云、腾讯云、minio 等 S3 连接 -->
|
||||
|
||||
@@ -14,6 +14,11 @@ import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.annotation.security.PermitAll;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@@ -21,11 +26,7 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.annotation.security.PermitAll;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
@@ -99,8 +100,10 @@ public class FileController {
|
||||
if (StrUtil.isEmpty(path)) {
|
||||
throw new IllegalArgumentException("结尾的 path 路径必须传递");
|
||||
}
|
||||
// 解码,解决中文路径的问题 https://gitee.com/zhijiantianya/ruoyi-vue-pro/pulls/807/
|
||||
path = URLUtil.decode(path);
|
||||
// 解码,解决中文路径的问题
|
||||
// https://gitee.com/zhijiantianya/ruoyi-vue-pro/pulls/807/
|
||||
// https://gitee.com/zhijiantianya/ruoyi-vue-pro/pulls/1432/
|
||||
path = URLUtil.decode(path, StandardCharsets.UTF_8, false);
|
||||
|
||||
// 读取内容
|
||||
byte[] content = fileService.getFileContent(configId, path);
|
||||
|
||||
@@ -4,6 +4,7 @@ import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.ftp.Ftp;
|
||||
import cn.hutool.extra.ftp.FtpConfig;
|
||||
import cn.hutool.extra.ftp.FtpException;
|
||||
import cn.hutool.extra.ftp.FtpMode;
|
||||
import cn.iocoder.yudao.module.infra.framework.file.core.client.AbstractFileClient;
|
||||
@@ -18,6 +19,15 @@ import java.io.ByteArrayOutputStream;
|
||||
*/
|
||||
public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> {
|
||||
|
||||
/**
|
||||
* 连接超时时间,单位:毫秒
|
||||
*/
|
||||
private static final Long CONNECTION_TIMEOUT = 3000L;
|
||||
/**
|
||||
* 读写超时时间,单位:毫秒
|
||||
*/
|
||||
private static final Long SO_TIMEOUT = 10000L;
|
||||
|
||||
private Ftp ftp;
|
||||
|
||||
public FtpFileClient(Long id, FtpFileClientConfig config) {
|
||||
@@ -26,9 +36,12 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> {
|
||||
|
||||
@Override
|
||||
protected void doInit() {
|
||||
// 初始化 Ftp 对象
|
||||
this.ftp = new Ftp(config.getHost(), config.getPort(), config.getUsername(), config.getPassword(),
|
||||
CharsetUtil.CHARSET_UTF_8, null, null, FtpMode.valueOf(config.getMode()));
|
||||
// 初始化 Ftp 对象:https://gitee.com/zhijiantianya/yudao-cloud/pulls/207/
|
||||
FtpConfig ftpConfig = new FtpConfig(config.getHost(), config.getPort(), config.getUsername(), config.getPassword(),
|
||||
CharsetUtil.CHARSET_UTF_8, null, null);
|
||||
ftpConfig.setConnectionTimeout(CONNECTION_TIMEOUT);
|
||||
ftpConfig.setSoTimeout(SO_TIMEOUT);
|
||||
this.ftp = new Ftp(ftpConfig, FtpMode.valueOf(config.getMode()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,4 +85,4 @@ public class FtpFileClient extends AbstractFileClient<FtpFileClientConfig> {
|
||||
ftp.reconnectIfTimeout();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package cn.iocoder.yudao.module.infra.framework.file.core.client.ftp;
|
||||
|
||||
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClientConfig;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.URL;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* Ftp 文件客户端的配置类
|
||||
*
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
package cn.iocoder.yudao.module.infra.framework.file.core.client.sftp;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.ftp.FtpConfig;
|
||||
import cn.hutool.extra.ssh.JschRuntimeException;
|
||||
import cn.hutool.extra.ssh.Sftp;
|
||||
import cn.iocoder.yudao.framework.common.util.io.FileUtils;
|
||||
import cn.iocoder.yudao.module.infra.framework.file.core.client.AbstractFileClient;
|
||||
import com.jcraft.jsch.JSch;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -14,6 +19,20 @@ import java.io.File;
|
||||
*/
|
||||
public class SftpFileClient extends AbstractFileClient<SftpFileClientConfig> {
|
||||
|
||||
/**
|
||||
* 连接超时时间,单位:毫秒
|
||||
*/
|
||||
private static final Long CONNECTION_TIMEOUT = 3000L;
|
||||
/**
|
||||
* 读写超时时间,单位:毫秒
|
||||
*/
|
||||
private static final Long SO_TIMEOUT = 10000L;
|
||||
|
||||
static {
|
||||
// 某些旧的 sftp 服务器仅支持 ssh-dss 协议,该协议并不安全,默认不支持该协议,按需添加
|
||||
JSch.setConfig("server_host_key", JSch.getConfig("server_host_key") + ",ssh-dss");
|
||||
}
|
||||
|
||||
private Sftp sftp;
|
||||
|
||||
public SftpFileClient(Long id, SftpFileClientConfig config) {
|
||||
@@ -22,18 +41,27 @@ public class SftpFileClient extends AbstractFileClient<SftpFileClientConfig> {
|
||||
|
||||
@Override
|
||||
protected void doInit() {
|
||||
// 初始化 Ftp 对象
|
||||
this.sftp = new Sftp(config.getHost(), config.getPort(), config.getUsername(), config.getPassword());
|
||||
// 初始化 Sftp 对象
|
||||
FtpConfig ftpConfig = new FtpConfig(config.getHost(), config.getPort(), config.getUsername(), config.getPassword(),
|
||||
CharsetUtil.CHARSET_UTF_8, null, null);
|
||||
ftpConfig.setConnectionTimeout(CONNECTION_TIMEOUT);
|
||||
ftpConfig.setSoTimeout(SO_TIMEOUT);
|
||||
this.sftp = new Sftp(ftpConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String upload(byte[] content, String path, String type) {
|
||||
// 执行写入
|
||||
String filePath = getFilePath(path);
|
||||
String fileName = FileUtil.getName(filePath);
|
||||
String dir = StrUtil.removeSuffix(filePath, fileName);
|
||||
File file = FileUtils.createTempFile(content);
|
||||
reconnectIfTimeout();
|
||||
sftp.mkDirs(FileUtil.getParent(filePath, 1)); // 需要创建父目录,不然会报错
|
||||
sftp.upload(filePath, file);
|
||||
sftp.mkDirs(dir); // 需要创建父目录,不然会报错
|
||||
boolean success = sftp.upload(filePath, file);
|
||||
if (!success) {
|
||||
throw new JschRuntimeException(StrUtil.format("上传文件到目标目录 ({}) 失败", filePath));
|
||||
}
|
||||
// 拼接返回路径
|
||||
return super.formatFileUrl(config.getDomain(), path);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package cn.iocoder.yudao.module.infra.framework.file.core.client.sftp;
|
||||
|
||||
import cn.iocoder.yudao.module.infra.framework.file.core.client.FileClientConfig;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.URL;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* Sftp 文件客户端的配置类
|
||||
*
|
||||
|
||||
@@ -217,7 +217,7 @@ const handleDeleteBatch = async () => {
|
||||
|
||||
const checkedIds = ref<number[]>([])
|
||||
const handleRowCheckboxChange = (records: ${subSimpleClassName}[]) => {
|
||||
checkedIds.value = records.map((item) => item.id);
|
||||
checkedIds.value = records.map((item) => item.id!);
|
||||
}
|
||||
#end
|
||||
#end
|
||||
|
||||
@@ -374,7 +374,7 @@ const handleDeleteBatch = async () => {
|
||||
|
||||
const checkedIds = ref<number[]>([])
|
||||
const handleRowCheckboxChange = (records: ${simpleClassName}[]) => {
|
||||
checkedIds.value = records.map((item) => item.id);
|
||||
checkedIds.value = records.map((item) => item.id!);
|
||||
}
|
||||
#end
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ export function delete${simpleClassName}List(ids: number[]) {
|
||||
|
||||
/** 导出${table.classComment} */
|
||||
export function export${simpleClassName}(params: any) {
|
||||
return requestClient.download('${baseURL}/export-excel', params);
|
||||
return requestClient.download('${baseURL}/export-excel', { params });
|
||||
}
|
||||
|
||||
## 特殊:主子表专属逻辑
|
||||
|
||||
@@ -182,7 +182,7 @@ function handleRowCheckboxChange({
|
||||
}: {
|
||||
records: ${simpleClassName}Api.${simpleClassName}[];
|
||||
}) {
|
||||
checkedIds.value = records.map((item) => item.id);
|
||||
checkedIds.value = records.map((item) => item.id!);
|
||||
}
|
||||
#end
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ function handleRowCheckboxChange({
|
||||
}: {
|
||||
records: ${simpleClassName}Api.${subSimpleClassName}[];
|
||||
}) {
|
||||
checkedIds.value = records.map((item) => item.id);
|
||||
checkedIds.value = records.map((item) => item.id!);
|
||||
}
|
||||
#end
|
||||
#end
|
||||
|
||||
@@ -98,7 +98,7 @@ export function delete${simpleClassName}List(ids: number[]) {
|
||||
|
||||
/** 导出${table.classComment} */
|
||||
export function export${simpleClassName}(params: any) {
|
||||
return requestClient.download('${baseURL}/export-excel', params);
|
||||
return requestClient.download('${baseURL}/export-excel', { params });
|
||||
}
|
||||
|
||||
## 特殊:主子表专属逻辑
|
||||
|
||||
@@ -119,7 +119,7 @@ function handleRowCheckboxChange({
|
||||
}: {
|
||||
records: ${simpleClassName}Api.${simpleClassName}[];
|
||||
}) {
|
||||
checkedIds.value = records.map((item) => item.id);
|
||||
checkedIds.value = records.map((item) => item.id!);
|
||||
}
|
||||
#end
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ function handleRowCheckboxChange({
|
||||
}: {
|
||||
records: ${simpleClassName}Api.${subSimpleClassName}[];
|
||||
}) {
|
||||
checkedIds.value = records.map((item) => item.id);
|
||||
checkedIds.value = records.map((item) => item.id!);
|
||||
}
|
||||
#end
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ export function delete${simpleClassName}List(ids: number[]) {
|
||||
|
||||
/** 导出${table.classComment} */
|
||||
export function export${simpleClassName}(params: any) {
|
||||
return requestClient.download('${baseURL}/export-excel', params);
|
||||
return requestClient.download('${baseURL}/export-excel', { params });
|
||||
}
|
||||
|
||||
## 特殊:主子表专属逻辑
|
||||
|
||||
@@ -177,7 +177,7 @@ function handleRowCheckboxChange({
|
||||
}: {
|
||||
records: ${simpleClassName}Api.${simpleClassName}[];
|
||||
}) {
|
||||
checkedIds.value = records.map((item) => item.id);
|
||||
checkedIds.value = records.map((item) => item.id!);
|
||||
}
|
||||
#end
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ function handleRowCheckboxChange({
|
||||
}: {
|
||||
records: ${simpleClassName}Api.${subSimpleClassName}[];
|
||||
}) {
|
||||
checkedIds.value = records.map((item) => item.id);
|
||||
checkedIds.value = records.map((item) => item.id!);
|
||||
}
|
||||
#end
|
||||
#end
|
||||
|
||||
@@ -98,7 +98,7 @@ export function delete${simpleClassName}List(ids: number[]) {
|
||||
|
||||
/** 导出${table.classComment} */
|
||||
export function export${simpleClassName}(params: any) {
|
||||
return requestClient.download('${baseURL}/export-excel', params);
|
||||
return requestClient.download('${baseURL}/export-excel', { params });
|
||||
}
|
||||
|
||||
## 特殊:主子表专属逻辑
|
||||
|
||||
@@ -113,7 +113,7 @@ function handleRowCheckboxChange({
|
||||
}: {
|
||||
records: ${simpleClassName}Api.${simpleClassName}[];
|
||||
}) {
|
||||
checkedIds.value = records.map((item) => item.id);
|
||||
checkedIds.value = records.map((item) => item.id!);
|
||||
}
|
||||
#end
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ function handleRowCheckboxChange({
|
||||
}: {
|
||||
records: ${simpleClassName}Api.${subSimpleClassName}[];
|
||||
}) {
|
||||
checkedIds.value = records.map((item) => item.id);
|
||||
checkedIds.value = records.map((item) => item.id!);
|
||||
}
|
||||
#end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user