Commit 8bc513a9 by 284718418@qq.com

文件存储地址配置

parent 0e213661
......@@ -326,5 +326,24 @@ public interface JxglEnumInterface {
}
}
/**
* 招聘管理-面试流程:类型,1状态变更,2面试,3Offer,4讨论,5其他
*/
@Getter
enum MslcLogStatus implements JxglEnumInterface {
CHANGEING(1, "状态变更"),
INTERVIEW(2, "面试"), OFFER(3, "Offer"),
DISCUSS(4, "讨论"), OTHER(5, "其他");
private Integer type;
private String name;
MslcLogStatus(Integer type, String name) {
this.type = type;
this.name = name;
}
}
}
......@@ -53,6 +53,15 @@ public class SftpConfiguration {
@Value("${sftp.client.serverUrl}")
private String serverUrl;
@Value("${sftp.client.targetPath}")
private String targetPath;
@Value("${sftp.client.reservedName}")
private boolean reservedName;
@Value("${config-8timer.file-address.type}")
public String fileAddress;
/**
* @Title: getSftpSocket
* @Description: 获取连接
......
......@@ -59,17 +59,8 @@ public class DiskFilesController {
@Autowired
private DiskFilesService diskFilesService;
@Value("${sftp.client.root}")
private String root;
@Value("${sftp.client.targetPath}")
private String targetPath;
@Value("${sftp.client.reservedName}")
private boolean reservedName;
@Value("${sftp.client.serverUrl}")
private String serverUrl;
@Autowired
private SftpConfiguration config;
@ResponseBody
......@@ -112,12 +103,12 @@ public class DiskFilesController {
List<FileInfoDto> imageUrls;
try {
//上传文件到服务器
imageUrls = ftpService.uploadFile(targetPath, file, reservedName);
imageUrls = ftpService.uploadFile(file);
for (FileInfoDto dto : imageUrls) {
//新增资源上传文件
diskFiles.setFileType(dto.getFileSuffix());
//"/home/disk/123456.jpg"
diskFiles.setDiskPath(root + targetPath + "/" + dto.getFileName());
diskFiles.setDiskPath(config.getRoot() + config.getTargetPath() + "/" + dto.getFileName());
diskFiles.setUrlPath(dto.getUrlPath());
diskFiles.setTitle(dto.getResourceFileName());
diskFiles.setFileSize(dto.getFileSize());
......
package cn.timer.api.controller.disk.constant;
/**
* 文件存储地址常量
*
* @author wuqingjun
* @email 284718418@qq.com
* @date 2022-04-02 11:05:49
*/
public class FileAddressConstant {
/**
* aliyun-oss(阿里云OSS)
*/
public static final String ALIYUN_OSS = "aliyun-oss";
/**
* physics-oss(物理机器OSS)
*/
public static final String PHYSICS_OSS = "physics-oss";
}
......@@ -18,12 +18,10 @@ public interface FtpService {
/**
* 上传文件到服务器
* @param targetPath
* @param files
* @param reservedName
* @return
*/
List<FileInfoDto> uploadFile(String targetPath, MultipartFile[] files, boolean reservedName);
List<FileInfoDto> uploadFile(MultipartFile[] files);
/**
* 下载单个文件
*
......
package cn.timer.api.service.impl;
import cn.timer.api.config.sftp.SftpConfiguration;
import cn.timer.api.controller.disk.constant.FileAddressConstant;
import cn.timer.api.dto.disk.FileInfoDto;
import cn.timer.api.service.FtpService;
import cn.timer.api.utils.Md5;
import cn.timer.api.utils.aliyun.OSSUtil;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.SftpException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
......@@ -25,6 +28,8 @@ public class FtpServiceImpl implements FtpService {
@Autowired
private SftpConfiguration config;
@Autowired
private OSSUtil oss;
@Override
......@@ -61,15 +66,18 @@ public class FtpServiceImpl implements FtpService {
}
@Override
public List<FileInfoDto> uploadFile(String targetPath, MultipartFile[] files, boolean reservedName) {
ChannelSftp sftp = config.getSftpSocket();
public List<FileInfoDto> uploadFile(MultipartFile[] files) {
List<FileInfoDto> resultStrs = new ArrayList<FileInfoDto>();
//存储地址判断
if (FileAddressConstant.PHYSICS_OSS.equals(config.getFileAddress())) {
ChannelSftp sftp = config.getSftpSocket();
try {
sftp.cd(config.getRoot());
//log.info("sftp连接host", config.getRoot());
boolean dirs = this.createDirs(targetPath, sftp);
boolean dirs = this.createDirs(config.getTargetPath(), sftp);
if (!dirs) {
log.error("sftp创建目录失败", targetPath);
log.error("sftp创建目录失败", config.getTargetPath());
throw new RuntimeException("上传文件失败");
}
FileInfoDto dto = null;
......@@ -78,7 +86,7 @@ public class FtpServiceImpl implements FtpService {
String fileName = "";
String name = file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf("."));
String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
if (reservedName) {
if (config.isReservedName()) {
fileName = Md5.md5(name + UUID.randomUUID().toString()) + suffix;
} else {
fileName = UUID.randomUUID().toString() + suffix;
......@@ -97,16 +105,18 @@ public class FtpServiceImpl implements FtpService {
resultStrs.add(dto);
}
return resultStrs;
} catch (Exception e) {
log.error("上传文件失败", targetPath, e);
log.error("上传文件失败", config.getTargetPath(), e);
e.printStackTrace();
throw new RuntimeException("上传文件失败");
} finally {
config.returnSftpSocket(sftp);
}
}
} else if (FileAddressConstant.ALIYUN_OSS.equals(config.getFileAddress())) {
}
return resultStrs;
}
/**
......@@ -128,11 +138,11 @@ public class FtpServiceImpl implements FtpService {
log.info("===DownloadFile:" + remotePath + " success from sftp.");
}
return nputStream;
} catch ( SftpException e) {
} catch (SftpException e) {
e.printStackTrace();
} catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
}finally {
} finally {
config.returnSftpSocket(sftp);
}
return nputStream;
......
......@@ -239,6 +239,13 @@ config-8timer:
appid: XOATkGqX6LvCW3i3Eqd5rg6h
secret: UqqNAF1nltMjAOz9yxqHPjZlnjtC2gSS
# 文件存储地址配置 file type:aliyun-oss,physics-oss
# 文件存储地址类型:aliyun-oss(阿里云OSS),physics-oss(物理机器OSS)
# 默认存储物理机器OSS
file-address:
type: physics-oss
#type: aliyun-oss
#导出zip临时地址
zip:
path: 'D:/zip/'
......
......@@ -221,6 +221,13 @@ config-8timer:
appid: XOATkGqX6LvCW3i3Eqd5rg6h
secret: UqqNAF1nltMjAOz9yxqHPjZlnjtC2gSS
# 文件存储地址配置 file type:aliyun-oss,physics-oss
# 文件存储地址类型:aliyun-oss(阿里云OSS),physics-oss(物理机器OSS)
# 默认存储物理机器OSS
file-address:
type: physics-oss
#type: aliyun-oss
#导出zip临时地址
zip:
path: '/data/crm-zip/'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment