DATA_BASE删除数据时,因为文件路径问题提示删除失败问题修改
This commit is contained in:
parent
9e2a90bb51
commit
01fd821a10
|
@ -356,6 +356,45 @@ public class FTPUtil {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 批量删除FTP文件 返回删除失败的文件路径
|
||||
* */
|
||||
public boolean removeFiles(String path){
|
||||
boolean success = false;
|
||||
// 连接FTP服务
|
||||
final FTPClient ftpClient = this.LoginFTP();
|
||||
//判断ftp是否连接成功
|
||||
if (ObjectUtil.isNull(ftpClient)){
|
||||
log.error("FTPUtil.removeFiles(): FTPClient is null");
|
||||
}
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = ftpClient.retrieveFileStream(path);
|
||||
//读取文件路径的流 如果文件存在则读取流数据不为空
|
||||
if (Objects.nonNull(inputStream)) {
|
||||
//删除文件
|
||||
success = ftpClient.deleteFile(path);
|
||||
}
|
||||
//日志输出文件删除状态
|
||||
log.info(path + " Delete Status:"+success);
|
||||
} catch (Exception e) {
|
||||
log.error("FTPUtil.removeFiles()删除文件[{}]失败: {}", path, e.getMessage());
|
||||
} finally {
|
||||
// 关闭FTP连接
|
||||
try {
|
||||
if (Objects.nonNull(inputStream)) {
|
||||
inputStream.close();
|
||||
}
|
||||
if (ObjectUtil.isNotNull(ftpClient)) {
|
||||
ftpClient.disconnect();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
/*
|
||||
* 批量删除FTP文件 返回删除失败的文件路径
|
||||
* */
|
||||
|
@ -369,12 +408,19 @@ public class FTPUtil {
|
|||
return paths;
|
||||
}
|
||||
for (String path : paths) {
|
||||
boolean success = false;
|
||||
try {
|
||||
if (StrUtil.isBlank(path)) continue;
|
||||
boolean success = ftpClient.deleteFile(path);
|
||||
if (success) continue;
|
||||
failList.add(path);
|
||||
log.error("FTPUtil.removeFiles()删除文件[{}]失败", path);
|
||||
if (StrUtil.isBlank(path)) {
|
||||
continue;
|
||||
}
|
||||
if (Objects.nonNull(ftpClient.retrieveFileStream(path))) {
|
||||
success = ftpClient.deleteFile(path);
|
||||
log.info(path + " Delete Status:"+success);
|
||||
} else {
|
||||
log.info(path + " Delete Status:false");
|
||||
failList.add(path);
|
||||
log.error("FTPUtil.removeFiles()删除文件[{}]失败", path);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
failList.add(path);
|
||||
log.error("FTPUtil.removeFiles()删除文件[{}]失败: {}", path, e.getMessage());
|
||||
|
@ -382,8 +428,9 @@ public class FTPUtil {
|
|||
}
|
||||
// 关闭FTP连接
|
||||
try {
|
||||
if (ObjectUtil.isNotNull(ftpClient))
|
||||
if (ObjectUtil.isNotNull(ftpClient)) {
|
||||
ftpClient.disconnect();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ import lombok.Data;
|
|||
@Data
|
||||
public class AnalysesDto {
|
||||
|
||||
private Integer sampleId;
|
||||
|
||||
private String baselinePath;
|
||||
|
||||
private String lcPath;
|
||||
|
|
|
@ -19,6 +19,6 @@ public interface GardsSampleDataMapper extends BaseMapper<GardsSampleDataSystem>
|
|||
void delBatch(@Param("tableNames") List<String> tableNames,
|
||||
@Param("sampleId") Integer sampleId);
|
||||
|
||||
AnalysesDto getAnalysis(@Param("owner") String owner,
|
||||
List<AnalysesDto> getAnalysis(@Param("owner") String owner,
|
||||
@Param("sampleId") Integer sampleId);
|
||||
}
|
||||
|
|
|
@ -25,11 +25,12 @@
|
|||
|
||||
<select id="getAnalysis" resultType="org.jeecg.modules.base.dto.AnalysesDto">
|
||||
SELECT
|
||||
BASELINE_PATH,
|
||||
LC_PATH,
|
||||
SCAC_PATH,
|
||||
LOG_PATH,
|
||||
REPORT_PAHT
|
||||
SAMPLE_ID sampleId,
|
||||
BASELINE_PATH baselinePath,
|
||||
LC_PATH lcPath,
|
||||
SCAC_PATH scacPath,
|
||||
LOG_PATH logPath,
|
||||
REPORT_PAHT reportPath
|
||||
FROM
|
||||
${owner}.GARDS_ANALYSES
|
||||
WHERE
|
||||
|
|
|
@ -171,7 +171,13 @@ public class GardsSampleDataServiceImpl extends ServiceImpl<GardsSampleDataMappe
|
|||
if (CollUtil.isEmpty(needDel))
|
||||
return Result.OK("Data cleaning is complete. No files need to be cleaned!");
|
||||
// 删除FTP文件
|
||||
List<String> failList = ftpUtil.removeFiles(needDel);
|
||||
List<String> failList = new ArrayList<>();
|
||||
for (String path:needDel) {
|
||||
boolean success = ftpUtil.removeFiles(path);
|
||||
if (!success) {
|
||||
failList.add(path);
|
||||
}
|
||||
}
|
||||
if (CollUtil.isNotEmpty(failList))
|
||||
return Result.error("Data clearing is complete, but file clearing fails!", failList);
|
||||
return Result.OK("Data and file cleanup complete!");
|
||||
|
@ -208,23 +214,30 @@ public class GardsSampleDataServiceImpl extends ServiceImpl<GardsSampleDataMappe
|
|||
private List<String> manOrAutoPath(String savePath, String logPath,
|
||||
Integer sampleId, String owner){
|
||||
List<String> fileList = new ArrayList<>();
|
||||
AnalysesDto AnalysesDto = baseMapper.getAnalysis(owner, sampleId);
|
||||
if (ObjectUtil.isNull(AnalysesDto))
|
||||
return fileList;
|
||||
String baselinePath = AnalysesDto.getBaselinePath();
|
||||
if (StrUtil.isNotBlank(baselinePath))
|
||||
fileList.add(savePath + baselinePath);
|
||||
String lcPath = AnalysesDto.getLcPath();
|
||||
if (StrUtil.isNotBlank(lcPath))
|
||||
fileList.add(savePath + lcPath);
|
||||
String scacPath = AnalysesDto.getScacPath();
|
||||
if (StrUtil.isNotBlank(scacPath))
|
||||
fileList.add(savePath + scacPath);
|
||||
if (StrUtil.isNotBlank(AnalysesDto.getLogPath()))
|
||||
fileList.add(logPath + AnalysesDto.getLogPath());
|
||||
String reportPath = AnalysesDto.getReportPath();
|
||||
if (StrUtil.isNotBlank(reportPath))
|
||||
fileList.add(savePath + reportPath + FileTypeEnum.txt.getType());
|
||||
List<AnalysesDto> AnalysesDtoList = baseMapper.getAnalysis(owner, sampleId);
|
||||
if (CollectionUtils.isNotEmpty(AnalysesDtoList)) {
|
||||
for (AnalysesDto AnalysesDto:AnalysesDtoList) {
|
||||
String baselinePath = AnalysesDto.getBaselinePath();
|
||||
if (StrUtil.isNotBlank(baselinePath)) {
|
||||
fileList.add(savePath + baselinePath);
|
||||
}
|
||||
String lcPath = AnalysesDto.getLcPath();
|
||||
if (StrUtil.isNotBlank(lcPath)) {
|
||||
fileList.add(savePath + lcPath);
|
||||
}
|
||||
String scacPath = AnalysesDto.getScacPath();
|
||||
if (StrUtil.isNotBlank(scacPath)) {
|
||||
fileList.add(savePath + scacPath);
|
||||
}
|
||||
if (StrUtil.isNotBlank(AnalysesDto.getLogPath())) {
|
||||
fileList.add(logPath + AnalysesDto.getLogPath());
|
||||
}
|
||||
String reportPath = AnalysesDto.getReportPath();
|
||||
if (StrUtil.isNotBlank(reportPath)) {
|
||||
fileList.add(savePath + reportPath + FileTypeEnum.txt.getType());
|
||||
}
|
||||
}
|
||||
}
|
||||
return fileList;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user