feat: sftp
This commit is contained in:
@@ -132,7 +132,7 @@ public class SchisandraOssAliController {
|
||||
* @return: com.schisandra.oss.common.entity.Result<java.lang.String>
|
||||
* @date: 2024/7/5 13:55
|
||||
*/
|
||||
@GetMapping("listAliDir")
|
||||
@GetMapping("listDir")
|
||||
public Result<String> listAliDir(@RequestParam String userId,@RequestParam String bucket,@RequestParam String prefix) throws Exception {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
AliOssClient bean = SpringUtil.getBean(userId);
|
||||
@@ -194,7 +194,7 @@ public class SchisandraOssAliController {
|
||||
* @return: void
|
||||
* @date: 2024/6/26 14:34
|
||||
*/
|
||||
@PostMapping("uploadAliFile")
|
||||
@PostMapping("uploadFile")
|
||||
public Result<OssInfo> uploadAliFile(@RequestParam String userId, @RequestParam MultipartFile file, @RequestParam String fileName, @RequestParam String bucket) throws IOException {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(fileName, "不能为空");
|
||||
@@ -227,7 +227,7 @@ public class SchisandraOssAliController {
|
||||
* @return: voiD
|
||||
* @date: 2024/6/26 13:56
|
||||
*/
|
||||
@GetMapping("downloadAliFile")
|
||||
@GetMapping("downloadFile")
|
||||
public void getAliFile(@RequestParam String bucket, @RequestParam String userId, @RequestParam String filePath, HttpServletResponse response) throws Exception {
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
@@ -246,8 +246,8 @@ public class SchisandraOssAliController {
|
||||
* @return: void
|
||||
* @date: 2024/6/26 14:34
|
||||
*/
|
||||
@PostMapping("deleteAliFile")
|
||||
public Result deleteMinioFile(@RequestParam String bucket, @RequestParam String userId, @RequestParam String filePath) {
|
||||
@PostMapping("deleteFile")
|
||||
public Result deleteAliFile(@RequestParam String bucket, @RequestParam String userId, @RequestParam String filePath) {
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(filePath, "不能为空");
|
||||
@@ -264,8 +264,8 @@ public class SchisandraOssAliController {
|
||||
* @return: com.schisandra.oss.common.entity.Result
|
||||
* @date: 2024/6/27 9:41
|
||||
*/
|
||||
@PostMapping("renameAliFile")
|
||||
public Result renameMinioFile(@RequestParam String userId, @RequestParam String bucket, @RequestParam String oldFileName, @RequestParam String newFileName) throws IOException {
|
||||
@PostMapping("renameFile")
|
||||
public Result renameAliFile(@RequestParam String userId, @RequestParam String bucket, @RequestParam String oldFileName, @RequestParam String newFileName) throws IOException {
|
||||
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
|
@@ -49,7 +49,7 @@ public class SchisandraOssQiniuController {
|
||||
* @return: com.schisandra.oss.common.entity.Result<java.lang.String>
|
||||
* @date: 2024/6/26 13:55
|
||||
*/
|
||||
@GetMapping("listQiniuDir")
|
||||
@GetMapping("listDir")
|
||||
public Result<String> listQiniuInfo(@RequestParam String userId, @RequestParam String prefix, @RequestParam String bucket) throws Exception {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
QiNiuOssClient bean = SpringUtil.getBean(userId);
|
||||
@@ -63,7 +63,7 @@ public class SchisandraOssQiniuController {
|
||||
* @return: com.schisandra.oss.common.entity.Result
|
||||
* @date: 2024/6/27 9:41
|
||||
*/
|
||||
@PostMapping("renameQiniuFile")
|
||||
@PostMapping("renameFile")
|
||||
public Result renameQiniuFile(@RequestParam String userId, @RequestParam String bucket, @RequestParam String oldFileName, @RequestParam String newFileName) throws IOException {
|
||||
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
@@ -87,7 +87,7 @@ public class SchisandraOssQiniuController {
|
||||
* @return: com.schisandra.oss.common.entity.Result
|
||||
* @date: 2024/6/27 9:52
|
||||
*/
|
||||
@PostMapping("copyQiniuFile")
|
||||
@PostMapping("copyFile")
|
||||
public Result copyQiniuFile(@RequestParam String userId, @RequestParam String bucket, @RequestParam String oldFilePath, @RequestParam String newFilePath) throws IOException {
|
||||
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
@@ -112,7 +112,7 @@ public class SchisandraOssQiniuController {
|
||||
* @author sjm
|
||||
* @date: 2024/7/8 13:56
|
||||
*/
|
||||
@GetMapping("downloadQiniuFile")
|
||||
@GetMapping("downloadFile")
|
||||
public void download_open(@RequestParam String userId,@RequestParam String endpoint, @RequestParam String filename,HttpServletResponse response) throws IOException {
|
||||
QiNiuOssClient bean = SpringUtil.getBean(userId);
|
||||
bean.getQiNiuOssConfig().setEndpoint(endpoint);
|
||||
@@ -132,7 +132,7 @@ public class SchisandraOssQiniuController {
|
||||
* @return: void
|
||||
* @date: 2024/7/8 14:34
|
||||
*/
|
||||
@PostMapping("deleteQiniuFile")
|
||||
@PostMapping("deleteFile")
|
||||
public Result deleteQiniuFile(@RequestParam String bucket, @RequestParam String userId, @RequestParam String filePath) {
|
||||
Preconditions.checkNotNull(bucket, "不能为空");
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
@@ -150,7 +150,7 @@ public class SchisandraOssQiniuController {
|
||||
* @return: void
|
||||
* @date: 2024/7/8 14:34
|
||||
*/
|
||||
@PostMapping("uploadQiniuFile")
|
||||
@PostMapping("uploadFile")
|
||||
public Result<OssInfo> uploadQiniuFile(@RequestParam String userId, @RequestParam MultipartFile file, @RequestParam String fileName, @RequestParam String bucket) throws IOException {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(fileName, "不能为空");
|
||||
@@ -234,7 +234,7 @@ public class SchisandraOssQiniuController {
|
||||
@PostMapping("init")
|
||||
public void initQiniu(@RequestParam String userId) {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("SchisandraOssMinioController.init.userId:{}", userId);
|
||||
log.info("SchisandraOssQiniuController.init.userId:{}", userId);
|
||||
}
|
||||
Preconditions.checkNotNull(userId, "用户id不能为空!");
|
||||
|
||||
|
@@ -0,0 +1,311 @@
|
||||
package com.schisandra.oss.application.controller;
|
||||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.schisandra.oss.application.convert.SchisandraOssSftpDTOConverter;
|
||||
import com.schisandra.oss.application.dto.SchisandraOssSftpDTO;
|
||||
import com.schisandra.oss.application.oss.core.ali.AliOssClient;
|
||||
import com.schisandra.oss.application.oss.core.ftp.FtpOssClient;
|
||||
import com.schisandra.oss.application.oss.core.ftp.FtpOssConfiguration;
|
||||
import com.schisandra.oss.application.oss.core.qiniu.QiNiuOssClient;
|
||||
import com.schisandra.oss.application.oss.core.sftp.SftpOssClient;
|
||||
import com.schisandra.oss.application.oss.core.sftp.SftpOssConfiguration;
|
||||
import com.schisandra.oss.application.oss.model.OssInfo;
|
||||
import com.schisandra.oss.common.entity.Result;
|
||||
import com.schisandra.oss.domain.bo.SchisandraOssSftpBO;
|
||||
import com.schisandra.oss.domain.redis.RedisUtil;
|
||||
import com.schisandra.oss.domain.service.SchisandraOssSftpDomainService;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* sftp存储配置表 controller
|
||||
*
|
||||
* @author landaiqing
|
||||
* @since 2024-07-12 15:44:04
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/oss/sftp/")
|
||||
@Slf4j
|
||||
public class SchisandraOssSftpController {
|
||||
|
||||
@Resource
|
||||
private SchisandraOssSftpDomainService schisandraOssSftpDomainService;
|
||||
|
||||
@Resource
|
||||
private SftpOssConfiguration sftpOssConfiguration;
|
||||
|
||||
private final String USER_OSS_PREFIX = "oss:user:heat";
|
||||
@Resource
|
||||
RedisUtil redisUtil;
|
||||
|
||||
|
||||
/**
|
||||
* @description: 拷贝文件
|
||||
* @param: [userId, bucket, oldFilePath, newFilePath]
|
||||
* @return: com.schisandra.oss.common.entity.Result
|
||||
* @date: 2024/6/27 9:52
|
||||
*/
|
||||
@PostMapping("copyFile")
|
||||
public Result copySftpFile(@RequestParam String userId, @RequestParam String oldFilePath, @RequestParam String newFilePath) throws IOException {
|
||||
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(oldFilePath, "不能为空");
|
||||
Preconditions.checkNotNull(newFilePath, "不能为空");
|
||||
QiNiuOssClient bean = SpringUtil.getBean(userId);
|
||||
try {
|
||||
bean.copy(oldFilePath, newFilePath);
|
||||
}catch (Exception e){
|
||||
return Result.fail(e.getMessage());
|
||||
}
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 重命名
|
||||
*/
|
||||
@PostMapping("renameFile")
|
||||
public Result renameSftpFile(@RequestParam String userId, @RequestParam String oldFileName, @RequestParam String newFileName) throws IOException {
|
||||
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(oldFileName, "不能为空");
|
||||
Preconditions.checkNotNull(newFileName, "不能为空");
|
||||
SftpOssClient bean = SpringUtil.getBean(userId);
|
||||
try {
|
||||
bean.rename(oldFileName, newFileName);
|
||||
}catch (Exception e){
|
||||
return Result.fail(e.getMessage());
|
||||
}
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description: 获取文件目录信息
|
||||
* @param: [target, userId, dirName]
|
||||
* @return: com.schisandra.oss.common.entity.Result<java.lang.String>
|
||||
*/
|
||||
@GetMapping("listDir")
|
||||
public Result<String> listSftpInfo(@RequestParam String userId, @RequestParam String prefix) throws Exception {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
SftpOssClient bean = SpringUtil.getBean(userId);
|
||||
return Result.ok(bean.listfile(prefix));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*/
|
||||
@PostMapping("deleteFile")
|
||||
public Result deleteSftpFile(@RequestParam String userId, @RequestParam String fileName) {
|
||||
SftpOssClient bean = SpringUtil.getBean(userId);
|
||||
bean.delete(fileName);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
*/
|
||||
|
||||
@GetMapping("downloadFile")
|
||||
public void downloadSftpFile(@RequestParam String userId, @RequestParam String filename, HttpServletResponse response) throws IOException {
|
||||
SftpOssClient bean = SpringUtil.getBean(userId);
|
||||
ServletOutputStream output = response.getOutputStream();
|
||||
|
||||
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setContentType("application/vnd.ms-excel");
|
||||
response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(filename, "utf-8"));
|
||||
bean.downLoad(output,filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*/
|
||||
@PostMapping("uploadFile")
|
||||
@SneakyThrows
|
||||
public Result<OssInfo> uploadSftpFile(@RequestParam String userId , @RequestParam MultipartFile file, @RequestParam String fileName) {
|
||||
Preconditions.checkNotNull(userId, "不能为空");
|
||||
Preconditions.checkNotNull(fileName, "不能为空");
|
||||
|
||||
|
||||
//设置热力图
|
||||
Date date =new Date();
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String formattedDate = dateFormat.format(date);
|
||||
String key = redisUtil.buildKey(USER_OSS_PREFIX+":"+userId,formattedDate);
|
||||
int count=1;
|
||||
if (redisUtil.exist(key)){
|
||||
count= Integer.parseInt(redisUtil.get(key));
|
||||
redisUtil.set(key, String.valueOf(count+1));
|
||||
}else {
|
||||
redisUtil.set(key, String.valueOf(1));
|
||||
}
|
||||
|
||||
// 获取文件输入流
|
||||
InputStream is = file.getInputStream();
|
||||
SftpOssClient bean = SpringUtil.getBean(userId);
|
||||
|
||||
return Result.ok(bean.upLoad(is, fileName, true));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description: sftp初始化
|
||||
* @param: []
|
||||
* @return: void
|
||||
* @date: 2024/7/12 13:34
|
||||
*/
|
||||
@PostMapping("init")
|
||||
public void initSftp(@RequestParam String userId) {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("SchisandraOssSftpController.init.userId:{}", userId);
|
||||
}
|
||||
Preconditions.checkNotNull(userId, "用户id不能为空!");
|
||||
|
||||
Result result = sftpOssConfiguration.sftpOssClient(userId);
|
||||
if (result != null) {
|
||||
log.info("用户: {}-> sftp 初始化完成!", userId);
|
||||
} else {
|
||||
log.error("用户: {}-> sftp 初始化失败!", userId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增sftp存储配置表
|
||||
*/
|
||||
@RequestMapping("add")
|
||||
public Result<Boolean> add(@RequestBody SchisandraOssSftpDTO schisandraOssSftpDTO) {
|
||||
|
||||
try {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("SchisandraOssSftpController.add.dto:{}", JSON.toJSONString(schisandraOssSftpDTO));
|
||||
}
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getId(), "不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getUserId(), "不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getHost(), "主机不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getPort(), "端口不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getBasePath(), "不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getUser(), "不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getPassword(), "不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getCharset(), "编码不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getConnectionTimeout(), "连接超时时长,单位毫秒不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getSoTimeout(), "Socket连接超时时长,单位毫秒不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getServerLanguageCode(), "设置服务器语言不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getSystemKey(), "设置服务器系统关键词不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getPartSize(), "分片大小,默认5MB不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getTaskNum(), "并发线程数,默认等于CPU的核数不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getStatus(), "状态不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getOpenAdvancedSetup(), "是否开启高级设置不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getCreatedBy(), "创建人不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getCreatedTime(), "创建时间不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getUpdateTime(), "更新时间不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getUpdateBy(), "更新人不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getIsDeleted(), "是否删除 0 未删除 1已删除不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getExtraJson(), "额外字段不能为空");
|
||||
SchisandraOssSftpBO SchisandraOssSftpBO = SchisandraOssSftpDTOConverter.INSTANCE.convertDTOToBO(schisandraOssSftpDTO);
|
||||
return Result.ok(schisandraOssSftpDomainService.add(SchisandraOssSftpBO));
|
||||
} catch (Exception e) {
|
||||
log.error("SchisandraOssSftpController.register.error:{}", e.getMessage(), e);
|
||||
return Result.fail("新增sftp存储配置表失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改sftp存储配置表
|
||||
*/
|
||||
@RequestMapping("update")
|
||||
public Result<Boolean> update(@RequestBody SchisandraOssSftpDTO schisandraOssSftpDTO) {
|
||||
|
||||
try {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("SchisandraOssSftpController.update.dto:{}", JSON.toJSONString(schisandraOssSftpDTO));
|
||||
}
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getId(), "不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getUserId(), "不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getHost(), "主机不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getPort(), "端口不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getBasePath(), "不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getUser(), "不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getPassword(), "不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getCharset(), "编码不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getConnectionTimeout(), "连接超时时长,单位毫秒不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getSoTimeout(), "Socket连接超时时长,单位毫秒不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getServerLanguageCode(), "设置服务器语言不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getSystemKey(), "设置服务器系统关键词不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getPartSize(), "分片大小,默认5MB不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getTaskNum(), "并发线程数,默认等于CPU的核数不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getStatus(), "状态不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getOpenAdvancedSetup(), "是否开启高级设置不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getCreatedBy(), "创建人不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getCreatedTime(), "创建时间不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getUpdateTime(), "更新时间不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getUpdateBy(), "更新人不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getIsDeleted(), "是否删除 0 未删除 1已删除不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getExtraJson(), "额外字段不能为空");
|
||||
SchisandraOssSftpBO schisandraOssSftpBO = SchisandraOssSftpDTOConverter.INSTANCE.convertDTOToBO(schisandraOssSftpDTO);
|
||||
return Result.ok(schisandraOssSftpDomainService.update(schisandraOssSftpBO));
|
||||
} catch (Exception e) {
|
||||
log.error("SchisandraOssSftpController.update.error:{}", e.getMessage(), e);
|
||||
return Result.fail("更新sftp存储配置表信息失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除sftp存储配置表
|
||||
*/
|
||||
@RequestMapping("delete")
|
||||
public Result<Boolean> delete(@RequestBody SchisandraOssSftpDTO schisandraOssSftpDTO) {
|
||||
|
||||
try {
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("SchisandraOssSftpController.delete.dto:{}", JSON.toJSONString(schisandraOssSftpDTO));
|
||||
}
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getId(), "不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getUserId(), "不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getHost(), "主机不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getPort(), "端口不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getBasePath(), "不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getUser(), "不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getPassword(), "不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getCharset(), "编码不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getConnectionTimeout(), "连接超时时长,单位毫秒不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getSoTimeout(), "Socket连接超时时长,单位毫秒不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getServerLanguageCode(), "设置服务器语言不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getSystemKey(), "设置服务器系统关键词不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getPartSize(), "分片大小,默认5MB不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getTaskNum(), "并发线程数,默认等于CPU的核数不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getStatus(), "状态不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getOpenAdvancedSetup(), "是否开启高级设置不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getCreatedBy(), "创建人不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getCreatedTime(), "创建时间不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getUpdateTime(), "更新时间不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getUpdateBy(), "更新人不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getIsDeleted(), "是否删除 0 未删除 1已删除不能为空");
|
||||
Preconditions.checkNotNull(schisandraOssSftpDTO.getExtraJson(), "额外字段不能为空");
|
||||
SchisandraOssSftpBO schisandraOssSftpBO = SchisandraOssSftpDTOConverter.INSTANCE.convertDTOToBO(schisandraOssSftpDTO);
|
||||
return Result.ok(schisandraOssSftpDomainService.delete(schisandraOssSftpBO));
|
||||
} catch (Exception e) {
|
||||
log.error("SchisandraOssSftpController.delete.error:{}", e.getMessage(), e);
|
||||
return Result.fail("删除sftp存储配置表信息失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
package com.schisandra.oss.application.convert;
|
||||
|
||||
import com.schisandra.oss.application.dto.SchisandraOssSftpDTO;
|
||||
import com.schisandra.oss.domain.bo.SchisandraOssSftpBO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* sftp存储配置表 dto转换器
|
||||
*
|
||||
* @author landaiqing
|
||||
* @since 2024-07-12 15:44:04
|
||||
*/
|
||||
@Mapper
|
||||
public interface SchisandraOssSftpDTOConverter {
|
||||
|
||||
SchisandraOssSftpDTOConverter INSTANCE = Mappers.getMapper(SchisandraOssSftpDTOConverter.class);
|
||||
|
||||
SchisandraOssSftpBO convertDTOToBO(SchisandraOssSftpDTO schisandraOssSftpDTO);
|
||||
SchisandraOssSftpDTO convertBOToDTO(SchisandraOssSftpBO schisandraOssSftpBO);
|
||||
|
||||
}
|
@@ -0,0 +1,128 @@
|
||||
package com.schisandra.oss.application.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* sftp存储配置表 dto
|
||||
*
|
||||
* @author landaiqing
|
||||
* @since 2024-07-12 15:44:04
|
||||
*/
|
||||
@Data
|
||||
public class SchisandraOssSftpDTO implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 主机
|
||||
*/
|
||||
private String host;
|
||||
|
||||
/**
|
||||
* 端口
|
||||
*/
|
||||
private Integer port;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String basePath;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String user;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 编码
|
||||
*/
|
||||
private String charset;
|
||||
|
||||
/**
|
||||
* 连接超时时长,单位毫秒
|
||||
*/
|
||||
private Long connectionTimeout;
|
||||
|
||||
/**
|
||||
* Socket连接超时时长,单位毫秒
|
||||
*/
|
||||
private Date soTimeout;
|
||||
|
||||
/**
|
||||
* 设置服务器语言
|
||||
*/
|
||||
private String serverLanguageCode;
|
||||
|
||||
/**
|
||||
* 设置服务器系统关键词
|
||||
*/
|
||||
private String systemKey;
|
||||
|
||||
/**
|
||||
* 分片大小,默认5MB
|
||||
*/
|
||||
private Integer partSize;
|
||||
|
||||
/**
|
||||
* 并发线程数,默认等于CPU的核数
|
||||
*/
|
||||
private Integer taskNum;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 是否开启高级设置
|
||||
*/
|
||||
private String openAdvancedSetup;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createdBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createdTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 是否删除 0 未删除 1已删除
|
||||
*/
|
||||
private Integer isDeleted;
|
||||
|
||||
/**
|
||||
* 额外字段
|
||||
*/
|
||||
private String extraJson;
|
||||
|
||||
}
|
||||
|
@@ -116,7 +116,6 @@ public class QiNiuOssClient implements StandardOssClient {
|
||||
long y = Long.parseLong(x)*1000;
|
||||
String result = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(y));
|
||||
info.setCreateTime(result);
|
||||
System.out.println(item.key);
|
||||
infos.add(info);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1 @@
|
||||
/**
|
@@ -0,0 +1,239 @@
|
||||
package com.schisandra.oss.application.oss.core.sftp;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.file.FileNameUtil;
|
||||
import cn.hutool.core.io.unit.DataSizeUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.ReflectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.ssh.Sftp;
|
||||
|
||||
import com.jcraft.jsch.*;
|
||||
import com.schisandra.oss.application.oss.core.StandardOssClient;
|
||||
import com.schisandra.oss.application.oss.core.sftp.model.SftpOssConfig;
|
||||
import com.schisandra.oss.application.oss.exception.OssException;
|
||||
import com.schisandra.oss.application.oss.model.DirectoryOssInfo;
|
||||
import com.schisandra.oss.application.oss.model.FileOssInfo;
|
||||
import com.schisandra.oss.application.oss.model.OssInfo;
|
||||
import com.schisandra.oss.application.oss.utils.OssPathUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
import static java.nio.file.Files.getLastModifiedTime;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class SftpOssClient implements StandardOssClient {
|
||||
|
||||
public static final String SFTP_OBJECT_NAME = "sftp";
|
||||
|
||||
private Sftp sftp;
|
||||
private SftpOssConfig sftpOssConfig;
|
||||
|
||||
@Override
|
||||
public OssInfo upLoad(InputStream is, String targetName, Boolean isOverride) {
|
||||
String key = getKey(targetName, true);
|
||||
String parentPath = OssPathUtil.convertPath(Paths.get(key).getParent().toString(), true);
|
||||
if (!sftp.exist(parentPath)) {
|
||||
sftp.mkDirs(parentPath);
|
||||
}
|
||||
if (isOverride || !sftp.exist(key)) {
|
||||
sftp.upload(parentPath, FileNameUtil.getName(targetName), is);
|
||||
}
|
||||
return getInfo(targetName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OssInfo upLoadCheckPoint(File file, String targetName) {
|
||||
String key = getKey(targetName, true);
|
||||
String parentPath = OssPathUtil.convertPath(Paths.get(key).getParent().toString(), true);
|
||||
if (!sftp.exist(parentPath)) {
|
||||
sftp.mkDirs(parentPath);
|
||||
}
|
||||
sftp.put(file.getPath(), parentPath, new DefaultSftpProgressMonitor(file.length()), Sftp.Mode.RESUME);
|
||||
return getInfo(targetName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downLoad(OutputStream os, String targetName) {
|
||||
sftp.download(getKey(targetName, true), os);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downLoadCheckPoint(File localFile, String targetName) {
|
||||
try {
|
||||
OssInfo ossInfo = getInfo(targetName, false);
|
||||
long skip = localFile.exists() ? localFile.length() : 0;
|
||||
OutputStream os = new FileOutputStream(localFile);
|
||||
ChannelSftp sftpClient = sftp.getClient();
|
||||
sftpClient.get(getKey(targetName, true), os, new DefaultSftpProgressMonitor(Convert.toLong(ossInfo.getLength())), Sftp.Mode.RESUME.ordinal(), skip);
|
||||
} catch (Exception e) {
|
||||
throw new OssException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(String targetName) {
|
||||
String key = getKey(targetName, true);
|
||||
if (isDirectory(targetName)) {
|
||||
sftp.delDir(key);
|
||||
} else {
|
||||
sftp.delFile(key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copy(String sourceName, String targetName, Boolean isOverride) {
|
||||
log.warn("sftp协议不支持copy命令");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move(String sourceName, String targetName, Boolean isOverride) {
|
||||
log.warn("sftp协议不支持move命令");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rename(String sourceName, String targetName, Boolean isOverride) {
|
||||
String newSourceName = getKey(sourceName, true);
|
||||
String newTargetName = getKey(targetName, true);
|
||||
try {
|
||||
if (isOverride || !isExist(newTargetName)) {
|
||||
sftp.getClient().rename(newSourceName, newTargetName);
|
||||
}
|
||||
} catch (SftpException e) {
|
||||
log.error("{}重命名为{}失败,错误信息为:", newSourceName, newTargetName, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public OssInfo getInfo(String targetName, Boolean isRecursion) {
|
||||
String key = getKey(targetName, true);
|
||||
OssInfo ossInfo = getBaseInfo(key);
|
||||
if (isRecursion && sftp.isDir(key)) {
|
||||
List<ChannelSftp.LsEntry> lsEntries = sftp.lsEntries(key);
|
||||
List<OssInfo> fileOssInfos = new ArrayList<>();
|
||||
List<OssInfo> directoryInfos = new ArrayList<>();
|
||||
for (ChannelSftp.LsEntry lsEntry : lsEntries) {
|
||||
SftpATTRS attrs = lsEntry.getAttrs();
|
||||
String target = OssPathUtil.convertPath(targetName + StrUtil.SLASH + lsEntry.getFilename(), true);
|
||||
if (attrs.isDir()) {
|
||||
directoryInfos.add(getInfo(target, true));
|
||||
} else {
|
||||
fileOssInfos.add(getInfo(target, false));
|
||||
}
|
||||
}
|
||||
ReflectUtil.setFieldValue(ossInfo, "fileInfos", fileOssInfos);
|
||||
ReflectUtil.setFieldValue(ossInfo, "directoryInfos", directoryInfos);
|
||||
}
|
||||
return ossInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isExist(String targetName) {
|
||||
return sftp.exist(getKey(targetName, true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isFile(String targetName) {
|
||||
return !isDirectory(targetName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isDirectory(String targetName) {
|
||||
return sftp.isDir(getKey(targetName, true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBasePath() {
|
||||
return sftpOssConfig.getBasePath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getClientObject() {
|
||||
return new HashMap<String, Object>() {
|
||||
{
|
||||
put(SFTP_OBJECT_NAME, getSftp());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private OssInfo getBaseInfo(String targetName) {
|
||||
String name = FileNameUtil.getName(targetName);
|
||||
String path = OssPathUtil.replaceKey(name, getBasePath(), true);
|
||||
ChannelSftp.LsEntry targetLsEntry = null;
|
||||
OssInfo ossInfo;
|
||||
if (sftp.isDir(targetName)) {
|
||||
ossInfo = new DirectoryOssInfo();
|
||||
List<ChannelSftp.LsEntry> lsEntries = sftp.lsEntries(OssPathUtil.convertPath(Paths.get(targetName).getParent().toString(), true));
|
||||
for (ChannelSftp.LsEntry lsEntry : lsEntries) {
|
||||
if (lsEntry.getFilename().equals(name)) {
|
||||
targetLsEntry = lsEntry;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ossInfo = new FileOssInfo();
|
||||
List<ChannelSftp.LsEntry> lsEntries = sftp.lsEntries(targetName);
|
||||
if (!lsEntries.isEmpty()) {
|
||||
targetLsEntry = lsEntries.get(0);
|
||||
}
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(targetLsEntry)) {
|
||||
SftpATTRS sftpattrs = targetLsEntry.getAttrs();
|
||||
if (!sftpattrs.isDir()) {
|
||||
ossInfo = new FileOssInfo();
|
||||
}
|
||||
ossInfo.setName(name);
|
||||
ossInfo.setPath(path);
|
||||
ossInfo.setLength(Convert.toStr(sftpattrs.getSize()));
|
||||
ossInfo.setCreateTime(DateUtil.date(sftpattrs.getMTime() * 1000L).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||
ossInfo.setLastUpdateTime(DateUtil.date(sftpattrs.getATime() * 1000L).toString(DatePattern.NORM_DATETIME_PATTERN));
|
||||
}
|
||||
return ossInfo;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public List<OssInfo> listfile(String prefix) {
|
||||
|
||||
List<ChannelSftp.LsEntry> files = sftp.lsEntries(prefix);
|
||||
List<OssInfo> infos = new ArrayList<>();
|
||||
for (ChannelSftp.LsEntry file : files) {
|
||||
OssInfo info = new OssInfo();
|
||||
info.setName(file.getFilename());
|
||||
info.setLength(DataSizeUtil.format(file.getAttrs().getSize()));
|
||||
|
||||
String path = prefix + StrUtil.SLASH + file.getFilename();
|
||||
info.setPath(prefix + StrUtil.SLASH + file.getFilename());
|
||||
|
||||
if(isDirectory(path))
|
||||
info.setIsDir(true);
|
||||
else
|
||||
info.setIsDir(false);
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
|
||||
Date date = (Date) sdf.parse(file.getAttrs().getMtimeString());
|
||||
String formatStr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
|
||||
info.setCreateTime(formatStr);
|
||||
infos.add(info);
|
||||
}
|
||||
return infos;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,76 @@
|
||||
package com.schisandra.oss.application.oss.core.sftp;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.hutool.extra.ssh.Sftp;
|
||||
import com.schisandra.oss.application.convert.SchisandraOssSftpDTOConverter;
|
||||
import com.schisandra.oss.application.dto.SchisandraOssSftpDTO;
|
||||
import com.schisandra.oss.application.oss.core.StandardOssClient;
|
||||
import com.schisandra.oss.application.oss.core.sftp.model.SftpOssConfig;
|
||||
import com.schisandra.oss.common.entity.Result;
|
||||
import com.schisandra.oss.domain.bo.SchisandraOssSftpBO;
|
||||
import com.schisandra.oss.domain.service.SchisandraOssSftpDomainService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class SftpOssConfiguration {
|
||||
@Resource
|
||||
SftpOssConfiguration sftpOssConfiguration;
|
||||
|
||||
@Resource
|
||||
private SchisandraOssSftpDomainService schisandraOssSftpDomainService;
|
||||
|
||||
public static final String DEFAULT_BEAN_NAME = "sftpOssClient";
|
||||
|
||||
public SchisandraOssSftpDTO getSchisandraOssSftpDTO(String userId) {
|
||||
CompletableFuture<SchisandraOssSftpDTO> futurePrice = CompletableFuture.supplyAsync(() -> {
|
||||
SchisandraOssSftpBO sftpBO = schisandraOssSftpDomainService.getSftpOssConfig(userId);
|
||||
SchisandraOssSftpDTO sftpDTO = SchisandraOssSftpDTOConverter.INSTANCE.convertBOToDTO(sftpBO);
|
||||
return sftpDTO;
|
||||
});
|
||||
SchisandraOssSftpDTO sftp = futurePrice.join();
|
||||
if (ObjectUtil.isEmpty(sftp)) {
|
||||
log.error("sftp配置信息获取失败");
|
||||
return null;
|
||||
}
|
||||
return sftp;
|
||||
}
|
||||
|
||||
|
||||
public Result sftpOssClient(String userId) {
|
||||
try {
|
||||
SchisandraOssSftpDTO sftp = sftpOssConfiguration.getSchisandraOssSftpDTO(userId);
|
||||
if (sftp == null) return null;
|
||||
SftpOssConfig sftpOssConfig = new SftpOssConfig();
|
||||
sftpOssConfig.setBasePath(sftp.getBasePath());
|
||||
sftpOssConfig.setHost(sftp.getHost());
|
||||
sftpOssConfig.setPort(sftp.getPort());
|
||||
sftpOssConfig.setPassword(sftp.getPassword());
|
||||
sftpOssConfig.setCharset(sftp.getCharset());
|
||||
sftpOssConfig.init();
|
||||
|
||||
SpringUtil.registerBean(userId, sftpOssClient(sftpOssConfig));
|
||||
return Result.ok();
|
||||
} catch (Exception e) {
|
||||
log.error("SftpOssConfiguration.qiniuOssClient:{}", e.getMessage(), e);
|
||||
return Result.fail();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public StandardOssClient sftpOssClient(SftpOssConfig sftpOssConfig) {
|
||||
return new SftpOssClient(sftp(sftpOssConfig), sftpOssConfig);
|
||||
}
|
||||
|
||||
public Sftp sftp(SftpOssConfig sftpOssConfig) {
|
||||
return new Sftp(sftpOssConfig.toFtpConfig());
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
package com.schisandra.oss.application.oss.core.sftp.model;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* @author 陈敏
|
||||
* @version SftpOssClientConfig.java, v 1.0 2022/5/9 0:27 chenmin Exp $
|
||||
* Created on 2022/5/9
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class SftpOssClientConfig {
|
||||
/**
|
||||
* 连接超时时长,单位毫秒
|
||||
*/
|
||||
private long connectionTimeout;
|
||||
/**
|
||||
* Socket连接超时时长,单位毫秒
|
||||
*/
|
||||
private long soTimeout;
|
||||
/**
|
||||
* 设置服务器语言
|
||||
*/
|
||||
private String serverLanguageCode;
|
||||
/**
|
||||
* 设置服务器系统关键词
|
||||
*/
|
||||
private String systemKey;
|
||||
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
package com.schisandra.oss.application.oss.core.sftp.model;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import cn.hutool.extra.ftp.FtpConfig;
|
||||
|
||||
import com.schisandra.oss.application.oss.utils.OssPathUtil;
|
||||
import lombok.Data;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
* @author 陈敏
|
||||
* @version SftpOssConfig.java, v 1.1 2022/2/20 9:06 chenmin Exp $
|
||||
* Created on 2022/2/20
|
||||
*/
|
||||
@Data
|
||||
public class SftpOssConfig {
|
||||
|
||||
private String basePath;
|
||||
|
||||
/**
|
||||
* 主机
|
||||
*/
|
||||
private String host;
|
||||
/**
|
||||
* 端口
|
||||
*/
|
||||
private int port;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String user;
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
/**
|
||||
* 编码
|
||||
*/
|
||||
private String charset;
|
||||
|
||||
private SftpOssClientConfig clientConfig;
|
||||
|
||||
public void init() {
|
||||
basePath = OssPathUtil.valid(basePath);
|
||||
}
|
||||
|
||||
public FtpConfig toFtpConfig() {
|
||||
FtpConfig ftpConfig = new FtpConfig();
|
||||
BeanUtil.copyProperties(this, ftpConfig,
|
||||
new CopyOptions().setIgnoreNullValue(true).setIgnoreProperties("basePath", "clientConfig"));
|
||||
BeanUtil.copyProperties(this.getClientConfig(), ftpConfig, new CopyOptions().setIgnoreNullValue(true));
|
||||
return ftpConfig;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,127 @@
|
||||
package com.schisandra.oss.domain.bo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
/**
|
||||
* sftp存储配置表 bo
|
||||
*
|
||||
* @author landaiqing
|
||||
* @since 2024-07-12 15:44:04
|
||||
*/
|
||||
@Data
|
||||
public class SchisandraOssSftpBO implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 主机
|
||||
*/
|
||||
private String host;
|
||||
|
||||
/**
|
||||
* 端口
|
||||
*/
|
||||
private Integer port;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String basePath;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String user;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 编码
|
||||
*/
|
||||
private String charset;
|
||||
|
||||
/**
|
||||
* 连接超时时长,单位毫秒
|
||||
*/
|
||||
private Long connectionTimeout;
|
||||
|
||||
/**
|
||||
* Socket连接超时时长,单位毫秒
|
||||
*/
|
||||
private Date soTimeout;
|
||||
|
||||
/**
|
||||
* 设置服务器语言
|
||||
*/
|
||||
private String serverLanguageCode;
|
||||
|
||||
/**
|
||||
* 设置服务器系统关键词
|
||||
*/
|
||||
private String systemKey;
|
||||
|
||||
/**
|
||||
* 分片大小,默认5MB
|
||||
*/
|
||||
private Integer partSize;
|
||||
|
||||
/**
|
||||
* 并发线程数,默认等于CPU的核数
|
||||
*/
|
||||
private Integer taskNum;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 是否开启高级设置
|
||||
*/
|
||||
private String openAdvancedSetup;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createdBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createdTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 是否删除 0 未删除 1已删除
|
||||
*/
|
||||
private Integer isDeleted;
|
||||
|
||||
/**
|
||||
* 额外字段
|
||||
*/
|
||||
private String extraJson;
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,22 @@
|
||||
package com.schisandra.oss.domain.convert;
|
||||
|
||||
import com.schisandra.oss.domain.bo.SchisandraOssSftpBO;
|
||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssSftp;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* sftp存储配置表 bo转换器
|
||||
*
|
||||
* @author landaiqing
|
||||
* @since 2024-07-12 15:44:04
|
||||
*/
|
||||
@Mapper
|
||||
public interface SchisandraOssSftpBOConverter {
|
||||
|
||||
SchisandraOssSftpBOConverter INSTANCE = Mappers.getMapper(SchisandraOssSftpBOConverter.class);
|
||||
|
||||
SchisandraOssSftp convertBOToEntity(SchisandraOssSftpBO schisandraOssSftpBO);
|
||||
SchisandraOssSftpBO convertEntityToBO(SchisandraOssSftp schisandraOssSftp);
|
||||
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
package com.schisandra.oss.domain.service;
|
||||
|
||||
import com.schisandra.oss.domain.bo.SchisandraOssQiniuBO;
|
||||
import com.schisandra.oss.domain.bo.SchisandraOssSftpBO;
|
||||
|
||||
/**
|
||||
* sftp存储配置表 领域service
|
||||
*
|
||||
* @author landaiqing
|
||||
* @since 2024-07-12 15:44:04
|
||||
*/
|
||||
public interface SchisandraOssSftpDomainService {
|
||||
|
||||
/**
|
||||
* 添加 sftp存储配置表 信息
|
||||
*/
|
||||
Boolean add(SchisandraOssSftpBO schisandraOssSftpBO);
|
||||
|
||||
/**
|
||||
* 更新 sftp存储配置表 信息
|
||||
*/
|
||||
Boolean update(SchisandraOssSftpBO schisandraOssSftpBO);
|
||||
|
||||
/**
|
||||
* 删除 sftp存储配置表 信息
|
||||
*/
|
||||
Boolean delete(SchisandraOssSftpBO schisandraOssSftpBO);
|
||||
|
||||
SchisandraOssSftpBO getSftpOssConfig(String userId);
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
package com.schisandra.oss.domain.service.impl;
|
||||
|
||||
import com.schisandra.oss.common.enums.IsDeletedFlagEnum;
|
||||
import com.schisandra.oss.domain.bo.SchisandraOssFtpBO;
|
||||
import com.schisandra.oss.domain.convert.SchisandraOssFtpBOConverter;
|
||||
import com.schisandra.oss.domain.convert.SchisandraOssSftpBOConverter;
|
||||
import com.schisandra.oss.domain.bo.SchisandraOssSftpBO;
|
||||
import com.schisandra.oss.domain.service.SchisandraOssSftpDomainService;
|
||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssFtp;
|
||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssSftp;
|
||||
import com.schisandra.oss.infra.basic.service.SchisandraOssSftpService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* sftp存储配置表 领域service实现了
|
||||
*
|
||||
* @author landaiqing
|
||||
* @since 2024-07-12 15:44:04
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SchisandraOssSftpDomainServiceImpl implements SchisandraOssSftpDomainService {
|
||||
|
||||
@Resource
|
||||
private SchisandraOssSftpService schisandraOssSftpService;
|
||||
|
||||
@Override
|
||||
public Boolean add(SchisandraOssSftpBO schisandraOssSftpBO) {
|
||||
SchisandraOssSftp schisandraOssSftp = SchisandraOssSftpBOConverter.INSTANCE.convertBOToEntity(schisandraOssSftpBO);
|
||||
schisandraOssSftp.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
|
||||
return schisandraOssSftpService.insert(schisandraOssSftp) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean update(SchisandraOssSftpBO schisandraOssSftpBO) {
|
||||
SchisandraOssSftp schisandraOssSftp = SchisandraOssSftpBOConverter.INSTANCE.convertBOToEntity(schisandraOssSftpBO);
|
||||
return schisandraOssSftpService.update(schisandraOssSftp) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean delete(SchisandraOssSftpBO schisandraOssSftpBO) {
|
||||
SchisandraOssSftp schisandraOssSftp = new SchisandraOssSftp();
|
||||
schisandraOssSftp.setId(schisandraOssSftpBO.getId());
|
||||
schisandraOssSftp.setIsDeleted(IsDeletedFlagEnum.DELETED.getCode());
|
||||
return schisandraOssSftpService.update(schisandraOssSftp) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchisandraOssSftpBO getSftpOssConfig(String userId) {
|
||||
SchisandraOssSftp schisandraOssSftp = schisandraOssSftpService.getSftpOssConfig(userId);
|
||||
SchisandraOssSftpBO schisandraOssSftpBO = SchisandraOssSftpBOConverter.INSTANCE.convertEntityToBO(schisandraOssSftp);
|
||||
return schisandraOssSftpBO;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
package com.schisandra.oss.infra.basic.dao;
|
||||
|
||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssSftp;
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* sftp存储配置表 表数据库访问层
|
||||
*
|
||||
* @author landaiqing
|
||||
* @since 2024-07-12 15:44:04
|
||||
*/
|
||||
@Repository
|
||||
public interface SchisandraOssSftpDao extends BaseMapper<SchisandraOssSftp> {
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,155 @@
|
||||
package com.schisandra.oss.infra.basic.entity;
|
||||
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* sftp存储配置表 实体类
|
||||
*
|
||||
* @author landaiqing
|
||||
* @since 2024-07-12 15:44:04
|
||||
*/
|
||||
@Data
|
||||
@Table("schisandra_oss_sftp")
|
||||
public class SchisandraOssSftp implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Id(value = "id", keyType = KeyType.Auto)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Column("user_id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 主机
|
||||
*/
|
||||
@Column("host")
|
||||
private String host;
|
||||
|
||||
/**
|
||||
* 端口
|
||||
*/
|
||||
@Column("port")
|
||||
private Integer port;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Column("basePath")
|
||||
private String basePath;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Column("user")
|
||||
private String user;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Column("password")
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 编码
|
||||
*/
|
||||
@Column("charset")
|
||||
private String charset;
|
||||
|
||||
/**
|
||||
* 连接超时时长,单位毫秒
|
||||
*/
|
||||
@Column("connection_timeout")
|
||||
private Long connectionTimeout;
|
||||
|
||||
/**
|
||||
* Socket连接超时时长,单位毫秒
|
||||
*/
|
||||
@Column("so_timeout")
|
||||
private Date soTimeout;
|
||||
|
||||
/**
|
||||
* 设置服务器语言
|
||||
*/
|
||||
@Column("server_language_code")
|
||||
private String serverLanguageCode;
|
||||
|
||||
/**
|
||||
* 设置服务器系统关键词
|
||||
*/
|
||||
@Column("system_key")
|
||||
private String systemKey;
|
||||
|
||||
/**
|
||||
* 分片大小,默认5MB
|
||||
*/
|
||||
@Column("part_size")
|
||||
private Integer partSize;
|
||||
|
||||
/**
|
||||
* 并发线程数,默认等于CPU的核数
|
||||
*/
|
||||
@Column("task_num")
|
||||
private Integer taskNum;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@Column("status")
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 是否开启高级设置
|
||||
*/
|
||||
@Column("open_advanced_setup")
|
||||
private String openAdvancedSetup;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@Column("created_by")
|
||||
private String createdBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Column("created_time")
|
||||
private Date createdTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@Column("update_time")
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
@Column("update_by")
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 是否删除 0 未删除 1已删除
|
||||
*/
|
||||
@Column("is_deleted")
|
||||
private Integer isDeleted;
|
||||
|
||||
/**
|
||||
* 额外字段
|
||||
*/
|
||||
@Column("extra_json")
|
||||
private String extraJson;
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,47 @@
|
||||
package com.schisandra.oss.infra.basic.service;
|
||||
|
||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssFtp;
|
||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssSftp;
|
||||
|
||||
/**
|
||||
* sftp存储配置表 表服务接口
|
||||
*
|
||||
* @author landaiqing
|
||||
* @since 2024-07-12 15:44:04
|
||||
*/
|
||||
public interface SchisandraOssSftpService {
|
||||
|
||||
/**
|
||||
* 通过ID查询单条数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 实例对象
|
||||
*/
|
||||
SchisandraOssSftp queryById(Long id);
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
*
|
||||
* @param schisandraOssSftp 实例对象
|
||||
* @return 实例对象
|
||||
*/
|
||||
int insert(SchisandraOssSftp schisandraOssSftp);
|
||||
|
||||
/**
|
||||
* 修改数据
|
||||
*
|
||||
* @param schisandraOssSftp 实例对象
|
||||
* @return 实例对象
|
||||
*/
|
||||
int update(SchisandraOssSftp schisandraOssSftp);
|
||||
|
||||
/**
|
||||
* 通过主键删除数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean deleteById(Long id);
|
||||
|
||||
SchisandraOssSftp getSftpOssConfig(String userId);
|
||||
}
|
@@ -0,0 +1,73 @@
|
||||
package com.schisandra.oss.infra.basic.service.impl;
|
||||
|
||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssFtp;
|
||||
import com.schisandra.oss.infra.basic.entity.SchisandraOssSftp;
|
||||
import com.schisandra.oss.infra.basic.dao.SchisandraOssSftpDao;
|
||||
import com.schisandra.oss.infra.basic.entity.table.SchisandraOssFtpTableDef;
|
||||
import com.schisandra.oss.infra.basic.entity.table.SchisandraOssSftpTableDef;
|
||||
import com.schisandra.oss.infra.basic.service.SchisandraOssSftpService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* sftp存储配置表 表服务实现类
|
||||
*
|
||||
* @author landaiqing
|
||||
* @since 2024-07-12 15:44:04
|
||||
*/
|
||||
@Service("SchisandraOssSftpService")
|
||||
public class SchisandraOssSftpServiceImpl implements SchisandraOssSftpService {
|
||||
|
||||
@Resource
|
||||
private SchisandraOssSftpDao schisandraOssSftpDao;
|
||||
|
||||
/**
|
||||
* 通过ID查询单条数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 实例对象
|
||||
*/
|
||||
@Override
|
||||
public SchisandraOssSftp queryById(Long id) {
|
||||
return this.schisandraOssSftpDao.selectOneById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
*
|
||||
* @param schisandraOssSftp 实例对象
|
||||
* @return 实例对象
|
||||
*/
|
||||
@Override
|
||||
public int insert(SchisandraOssSftp schisandraOssSftp) {
|
||||
return this.schisandraOssSftpDao.insertSelective(schisandraOssSftp);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改数据
|
||||
*
|
||||
* @param schisandraOssSftp 实例对象
|
||||
* @return 实例对象
|
||||
*/
|
||||
@Override
|
||||
public int update(SchisandraOssSftp schisandraOssSftp) {
|
||||
return this.schisandraOssSftpDao.update(schisandraOssSftp,true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过主键删除数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 是否成功
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteById(Long id) {
|
||||
return this.schisandraOssSftpDao.deleteById(id) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchisandraOssSftp getSftpOssConfig(String userId) {
|
||||
return schisandraOssSftpDao.selectOneByCondition(SchisandraOssSftpTableDef.SCHISANDRA_OSS_SFTP.USER_ID.eq(userId));
|
||||
}
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.schisandra.oss.infra.basic.dao.SchisandraOssSftpDao">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.schisandra.oss.infra.basic.entity.SchisandraOssSftp">
|
||||
<id column="id" jdbcType="BIGINT" property="id"/>
|
||||
<result column="user_id" jdbcType="BIGINT" property="userId"/>
|
||||
<result column="host" jdbcType="VARCHAR" property="host"/>
|
||||
<result column="port" jdbcType="INTEGER" property="port"/>
|
||||
<result column="basePath" jdbcType="VARCHAR" property="basePath"/>
|
||||
<result column="user" jdbcType="VARCHAR" property="user"/>
|
||||
<result column="password" jdbcType="VARCHAR" property="password"/>
|
||||
<result column="charset" jdbcType="VARCHAR" property="charset"/>
|
||||
<result column="connection_timeout" jdbcType="BIGINT" property="connectionTimeout"/>
|
||||
<result column="so_timeout" jdbcType="TIMESTAMP" property="soTimeout"/>
|
||||
<result column="server_language_code" jdbcType="VARCHAR" property="serverLanguageCode"/>
|
||||
<result column="system_key" jdbcType="VARCHAR" property="systemKey"/>
|
||||
<result column="part_size" jdbcType="INTEGER" property="partSize"/>
|
||||
<result column="task_num" jdbcType="INTEGER" property="taskNum"/>
|
||||
<result column="status" jdbcType="VARCHAR" property="status"/>
|
||||
<result column="open_advanced_setup" jdbcType="VARCHAR" property="openAdvancedSetup"/>
|
||||
<result column="created_by" jdbcType="VARCHAR" property="createdBy"/>
|
||||
<result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
|
||||
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
|
||||
<result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
|
||||
<result column="is_deleted" jdbcType="INTEGER" property="isDeleted"/>
|
||||
<result column="extra_json" jdbcType="VARCHAR" property="extraJson"/>
|
||||
</resultMap>
|
||||
|
||||
</mapper>
|
Reference in New Issue
Block a user