Commit 8bc513a9 by 284718418@qq.com

文件存储地址配置

parent 0e213661
...@@ -326,5 +326,24 @@ public interface JxglEnumInterface { ...@@ -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 { ...@@ -53,6 +53,15 @@ public class SftpConfiguration {
@Value("${sftp.client.serverUrl}") @Value("${sftp.client.serverUrl}")
private String 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 * @Title: getSftpSocket
* @Description: 获取连接 * @Description: 获取连接
......
...@@ -59,17 +59,8 @@ public class DiskFilesController { ...@@ -59,17 +59,8 @@ public class DiskFilesController {
@Autowired @Autowired
private DiskFilesService diskFilesService; private DiskFilesService diskFilesService;
@Value("${sftp.client.root}") @Autowired
private String root; private SftpConfiguration config;
@Value("${sftp.client.targetPath}")
private String targetPath;
@Value("${sftp.client.reservedName}")
private boolean reservedName;
@Value("${sftp.client.serverUrl}")
private String serverUrl;
@ResponseBody @ResponseBody
...@@ -112,12 +103,12 @@ public class DiskFilesController { ...@@ -112,12 +103,12 @@ public class DiskFilesController {
List<FileInfoDto> imageUrls; List<FileInfoDto> imageUrls;
try { try {
//上传文件到服务器 //上传文件到服务器
imageUrls = ftpService.uploadFile(targetPath, file, reservedName); imageUrls = ftpService.uploadFile(file);
for (FileInfoDto dto : imageUrls) { for (FileInfoDto dto : imageUrls) {
//新增资源上传文件 //新增资源上传文件
diskFiles.setFileType(dto.getFileSuffix()); diskFiles.setFileType(dto.getFileSuffix());
//"/home/disk/123456.jpg" //"/home/disk/123456.jpg"
diskFiles.setDiskPath(root + targetPath + "/" + dto.getFileName()); diskFiles.setDiskPath(config.getRoot() + config.getTargetPath() + "/" + dto.getFileName());
diskFiles.setUrlPath(dto.getUrlPath()); diskFiles.setUrlPath(dto.getUrlPath());
diskFiles.setTitle(dto.getResourceFileName()); diskFiles.setTitle(dto.getResourceFileName());
diskFiles.setFileSize(dto.getFileSize()); 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 { ...@@ -18,12 +18,10 @@ public interface FtpService {
/** /**
* 上传文件到服务器 * 上传文件到服务器
* @param targetPath
* @param files * @param files
* @param reservedName
* @return * @return
*/ */
List<FileInfoDto> uploadFile(String targetPath, MultipartFile[] files, boolean reservedName); List<FileInfoDto> uploadFile(MultipartFile[] files);
/** /**
* 下载单个文件 * 下载单个文件
* *
......
package cn.timer.api.service.impl; package cn.timer.api.service.impl;
import cn.timer.api.config.sftp.SftpConfiguration; 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.dto.disk.FileInfoDto;
import cn.timer.api.service.FtpService; import cn.timer.api.service.FtpService;
import cn.timer.api.utils.Md5; import cn.timer.api.utils.Md5;
import cn.timer.api.utils.aliyun.OSSUtil;
import com.jcraft.jsch.ChannelSftp; import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.SftpException; import com.jcraft.jsch.SftpException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
...@@ -25,6 +28,8 @@ public class FtpServiceImpl implements FtpService { ...@@ -25,6 +28,8 @@ public class FtpServiceImpl implements FtpService {
@Autowired @Autowired
private SftpConfiguration config; private SftpConfiguration config;
@Autowired
private OSSUtil oss;
@Override @Override
...@@ -61,15 +66,18 @@ public class FtpServiceImpl implements FtpService { ...@@ -61,15 +66,18 @@ public class FtpServiceImpl implements FtpService {
} }
@Override @Override
public List<FileInfoDto> uploadFile(String targetPath, MultipartFile[] files, boolean reservedName) { public List<FileInfoDto> uploadFile(MultipartFile[] files) {
ChannelSftp sftp = config.getSftpSocket();
List<FileInfoDto> resultStrs = new ArrayList<FileInfoDto>(); List<FileInfoDto> resultStrs = new ArrayList<FileInfoDto>();
//存储地址判断
if (FileAddressConstant.PHYSICS_OSS.equals(config.getFileAddress())) {
ChannelSftp sftp = config.getSftpSocket();
try { try {
sftp.cd(config.getRoot()); sftp.cd(config.getRoot());
//log.info("sftp连接host", config.getRoot()); //log.info("sftp连接host", config.getRoot());
boolean dirs = this.createDirs(targetPath, sftp); boolean dirs = this.createDirs(config.getTargetPath(), sftp);
if (!dirs) { if (!dirs) {
log.error("sftp创建目录失败", targetPath); log.error("sftp创建目录失败", config.getTargetPath());
throw new RuntimeException("上传文件失败"); throw new RuntimeException("上传文件失败");
} }
FileInfoDto dto = null; FileInfoDto dto = null;
...@@ -78,7 +86,7 @@ public class FtpServiceImpl implements FtpService { ...@@ -78,7 +86,7 @@ public class FtpServiceImpl implements FtpService {
String fileName = ""; String fileName = "";
String name = file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf(".")); String name = file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf("."));
String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
if (reservedName) { if (config.isReservedName()) {
fileName = Md5.md5(name + UUID.randomUUID().toString()) + suffix; fileName = Md5.md5(name + UUID.randomUUID().toString()) + suffix;
} else { } else {
fileName = UUID.randomUUID().toString() + suffix; fileName = UUID.randomUUID().toString() + suffix;
...@@ -97,16 +105,18 @@ public class FtpServiceImpl implements FtpService { ...@@ -97,16 +105,18 @@ public class FtpServiceImpl implements FtpService {
resultStrs.add(dto); resultStrs.add(dto);
} }
return resultStrs;
} catch (Exception e) { } catch (Exception e) {
log.error("上传文件失败", targetPath, e); log.error("上传文件失败", config.getTargetPath(), e);
e.printStackTrace(); e.printStackTrace();
throw new RuntimeException("上传文件失败"); throw new RuntimeException("上传文件失败");
} finally { } finally {
config.returnSftpSocket(sftp); config.returnSftpSocket(sftp);
} }
} } else if (FileAddressConstant.ALIYUN_OSS.equals(config.getFileAddress())) {
}
return resultStrs;
}
/** /**
...@@ -128,11 +138,11 @@ public class FtpServiceImpl implements FtpService { ...@@ -128,11 +138,11 @@ public class FtpServiceImpl implements FtpService {
log.info("===DownloadFile:" + remotePath + " success from sftp."); log.info("===DownloadFile:" + remotePath + " success from sftp.");
} }
return nputStream; return nputStream;
} catch ( SftpException e) { } catch (SftpException e) {
e.printStackTrace(); e.printStackTrace();
} catch (Exception e){ } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
}finally { } finally {
config.returnSftpSocket(sftp); config.returnSftpSocket(sftp);
} }
return nputStream; return nputStream;
......
...@@ -239,6 +239,13 @@ config-8timer: ...@@ -239,6 +239,13 @@ config-8timer:
appid: XOATkGqX6LvCW3i3Eqd5rg6h appid: XOATkGqX6LvCW3i3Eqd5rg6h
secret: UqqNAF1nltMjAOz9yxqHPjZlnjtC2gSS 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临时地址
zip: zip:
path: 'D:/zip/' path: 'D:/zip/'
......
...@@ -221,6 +221,13 @@ config-8timer: ...@@ -221,6 +221,13 @@ config-8timer:
appid: XOATkGqX6LvCW3i3Eqd5rg6h appid: XOATkGqX6LvCW3i3Eqd5rg6h
secret: UqqNAF1nltMjAOz9yxqHPjZlnjtC2gSS 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临时地址
zip: zip:
path: '/data/crm-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