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文件 返回删除失败的文件路径
|
* 批量删除FTP文件 返回删除失败的文件路径
|
||||||
* */
|
* */
|
||||||
|
@ -369,12 +408,19 @@ public class FTPUtil {
|
||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
for (String path : paths) {
|
for (String path : paths) {
|
||||||
|
boolean success = false;
|
||||||
try {
|
try {
|
||||||
if (StrUtil.isBlank(path)) continue;
|
if (StrUtil.isBlank(path)) {
|
||||||
boolean success = ftpClient.deleteFile(path);
|
continue;
|
||||||
if (success) 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);
|
failList.add(path);
|
||||||
log.error("FTPUtil.removeFiles()删除文件[{}]失败", path);
|
log.error("FTPUtil.removeFiles()删除文件[{}]失败", path);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
failList.add(path);
|
failList.add(path);
|
||||||
log.error("FTPUtil.removeFiles()删除文件[{}]失败: {}", path, e.getMessage());
|
log.error("FTPUtil.removeFiles()删除文件[{}]失败: {}", path, e.getMessage());
|
||||||
|
@ -382,8 +428,9 @@ public class FTPUtil {
|
||||||
}
|
}
|
||||||
// 关闭FTP连接
|
// 关闭FTP连接
|
||||||
try {
|
try {
|
||||||
if (ObjectUtil.isNotNull(ftpClient))
|
if (ObjectUtil.isNotNull(ftpClient)) {
|
||||||
ftpClient.disconnect();
|
ftpClient.disconnect();
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ import lombok.Data;
|
||||||
@Data
|
@Data
|
||||||
public class AnalysesDto {
|
public class AnalysesDto {
|
||||||
|
|
||||||
|
private Integer sampleId;
|
||||||
|
|
||||||
private String baselinePath;
|
private String baselinePath;
|
||||||
|
|
||||||
private String lcPath;
|
private String lcPath;
|
||||||
|
|
|
@ -19,6 +19,6 @@ public interface GardsSampleDataMapper extends BaseMapper<GardsSampleDataSystem>
|
||||||
void delBatch(@Param("tableNames") List<String> tableNames,
|
void delBatch(@Param("tableNames") List<String> tableNames,
|
||||||
@Param("sampleId") Integer sampleId);
|
@Param("sampleId") Integer sampleId);
|
||||||
|
|
||||||
AnalysesDto getAnalysis(@Param("owner") String owner,
|
List<AnalysesDto> getAnalysis(@Param("owner") String owner,
|
||||||
@Param("sampleId") Integer sampleId);
|
@Param("sampleId") Integer sampleId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,11 +25,12 @@
|
||||||
|
|
||||||
<select id="getAnalysis" resultType="org.jeecg.modules.base.dto.AnalysesDto">
|
<select id="getAnalysis" resultType="org.jeecg.modules.base.dto.AnalysesDto">
|
||||||
SELECT
|
SELECT
|
||||||
BASELINE_PATH,
|
SAMPLE_ID sampleId,
|
||||||
LC_PATH,
|
BASELINE_PATH baselinePath,
|
||||||
SCAC_PATH,
|
LC_PATH lcPath,
|
||||||
LOG_PATH,
|
SCAC_PATH scacPath,
|
||||||
REPORT_PAHT
|
LOG_PATH logPath,
|
||||||
|
REPORT_PAHT reportPath
|
||||||
FROM
|
FROM
|
||||||
${owner}.GARDS_ANALYSES
|
${owner}.GARDS_ANALYSES
|
||||||
WHERE
|
WHERE
|
||||||
|
|
|
@ -171,7 +171,13 @@ public class GardsSampleDataServiceImpl extends ServiceImpl<GardsSampleDataMappe
|
||||||
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文件
|
// 删除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))
|
if (CollUtil.isNotEmpty(failList))
|
||||||
return Result.error("Data clearing is complete, but file clearing fails!", failList);
|
return Result.error("Data clearing is complete, but file clearing fails!", failList);
|
||||||
return Result.OK("Data and file cleanup complete!");
|
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,
|
private List<String> manOrAutoPath(String savePath, String logPath,
|
||||||
Integer sampleId, String owner){
|
Integer sampleId, String owner){
|
||||||
List<String> fileList = new ArrayList<>();
|
List<String> fileList = new ArrayList<>();
|
||||||
AnalysesDto AnalysesDto = baseMapper.getAnalysis(owner, sampleId);
|
List<AnalysesDto> AnalysesDtoList = baseMapper.getAnalysis(owner, sampleId);
|
||||||
if (ObjectUtil.isNull(AnalysesDto))
|
if (CollectionUtils.isNotEmpty(AnalysesDtoList)) {
|
||||||
return fileList;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user