fix:修改FTP为本地文件

This commit is contained in:
nieziyan 2024-04-24 09:34:59 +08:00
parent a025eb5098
commit 6335a3f588

View File

@ -1,8 +1,10 @@
package org.jeecg.modules.system.service.impl; package org.jeecg.modules.system.service.impl;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil; import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.dynamic.datasource.annotation.DS;
@ -13,6 +15,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlRunner; import com.baomidou.mybatisplus.extension.toolkit.SqlRunner;
import com.google.common.io.Files;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.QueryRequest; import org.jeecg.common.api.QueryRequest;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
@ -47,9 +50,6 @@ public class GardsSampleDataServiceImpl extends ServiceImpl<GardsSampleDataMappe
@Autowired @Autowired
private RedisUtil redisUtil; private RedisUtil redisUtil;
@Autowired
private FTPUtil ftpUtil;
@Autowired @Autowired
private SpectrumPathProperties pathProperties; private SpectrumPathProperties pathProperties;
@ -110,9 +110,9 @@ public class GardsSampleDataServiceImpl extends ServiceImpl<GardsSampleDataMappe
TransactionDefinition txDef = new DefaultTransactionDefinition(); TransactionDefinition txDef = new DefaultTransactionDefinition();
final TransactionStatus txStatus = transactionManager.getTransaction(txDef); final TransactionStatus txStatus = transactionManager.getTransaction(txDef);
try { try {
String ftpRootPath = ftpUtil.getFtpRootPath(); String rootPath = pathProperties.getRootPath();
String savePath = ftpRootPath + pathProperties.getSaveFilePath() + StrUtil.SLASH; String savePath = rootPath + pathProperties.getSaveFilePath() + StrUtil.SLASH;
String logPath = ftpRootPath + pathProperties.getLogPath() + StrUtil.SLASH; String logPath = rootPath + pathProperties.getLogPath() + StrUtil.SLASH;
/* 删除数据库数据 */ /* 删除数据库数据 */
// 过滤掉多余的表 // 过滤掉多余的表
String ORIGINAL = "ORIGINAL";String RNAUTO = "RNAUTO";String RNMAN = "RNMAN"; String ORIGINAL = "ORIGINAL";String RNAUTO = "RNAUTO";String RNMAN = "RNMAN";
@ -170,16 +170,14 @@ public class GardsSampleDataServiceImpl extends ServiceImpl<GardsSampleDataMappe
needDel = needDel.stream().filter(StrUtil::isNotBlank).collect(Collectors.toList()); needDel = needDel.stream().filter(StrUtil::isNotBlank).collect(Collectors.toList());
if (CollUtil.isEmpty(needDel)) if (CollUtil.isEmpty(needDel))
return Result.OK("Data cleaning is complete. No files need to be cleaned!"); return Result.OK("Data cleaning is complete. No files need to be cleaned!");
// 删除FTP文件 // 删除本地文件
List<String> failList = new ArrayList<>(); List<String> fails = new ArrayList<>();
for (String path:needDel) { for (String path : needDel) {
boolean success = ftpUtil.removeFiles(path); boolean success = FileUtil.del(path);
if (!success) { if (!success) fails.add(path);
failList.add(path);
}
} }
if (CollUtil.isNotEmpty(failList)) if (CollUtil.isNotEmpty(fails))
return Result.error("Data clearing is complete, but file clearing fails!", failList); return Result.error("Data clearing is complete, but file clearing fails!", fails);
return Result.OK("Data and file cleanup complete!"); return Result.OK("Data and file cleanup complete!");
}catch (Exception e){ }catch (Exception e){
transactionManager.rollback(txStatus); transactionManager.rollback(txStatus);
@ -215,27 +213,25 @@ public class GardsSampleDataServiceImpl extends ServiceImpl<GardsSampleDataMappe
Integer sampleId, String owner){ Integer sampleId, String owner){
List<String> fileList = new ArrayList<>(); List<String> fileList = new ArrayList<>();
List<AnalysesDto> AnalysesDtoList = baseMapper.getAnalysis(owner, sampleId); List<AnalysesDto> AnalysesDtoList = baseMapper.getAnalysis(owner, sampleId);
if (CollectionUtils.isNotEmpty(AnalysesDtoList)) { for (AnalysesDto AnalysesDto:AnalysesDtoList) {
for (AnalysesDto AnalysesDto:AnalysesDtoList) { String baselinePath = AnalysesDto.getBaselinePath();
String baselinePath = AnalysesDto.getBaselinePath(); if (StrUtil.isNotBlank(baselinePath)) {
if (StrUtil.isNotBlank(baselinePath)) { fileList.add(savePath + baselinePath);
fileList.add(savePath + baselinePath); }
} String lcPath = AnalysesDto.getLcPath();
String lcPath = AnalysesDto.getLcPath(); if (StrUtil.isNotBlank(lcPath)) {
if (StrUtil.isNotBlank(lcPath)) { fileList.add(savePath + lcPath);
fileList.add(savePath + lcPath); }
} String scacPath = AnalysesDto.getScacPath();
String scacPath = AnalysesDto.getScacPath(); if (StrUtil.isNotBlank(scacPath)) {
if (StrUtil.isNotBlank(scacPath)) { fileList.add(savePath + scacPath);
fileList.add(savePath + scacPath); }
} if (StrUtil.isNotBlank(AnalysesDto.getLogPath())) {
if (StrUtil.isNotBlank(AnalysesDto.getLogPath())) { fileList.add(logPath + AnalysesDto.getLogPath());
fileList.add(logPath + AnalysesDto.getLogPath()); }
} String reportPath = AnalysesDto.getReportPath();
String reportPath = AnalysesDto.getReportPath(); if (StrUtil.isNotBlank(reportPath)) {
if (StrUtil.isNotBlank(reportPath)) { fileList.add(savePath + reportPath + FileTypeEnum.txt.getType());
fileList.add(savePath + reportPath + FileTypeEnum.txt.getType());
}
} }
} }
return fileList; return fileList;