From 10e07c5969b14e853fc2d6b42a208a6965b46b9b Mon Sep 17 00:00:00 2001 From: xiaoguangbin Date: Thu, 5 Dec 2024 16:24:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E8=83=BD=E8=B0=B1=E5=8A=9F=E8=83=BD=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=BE=93=E5=85=A5=E5=92=8C=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=B9=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/GardsSampleDataServiceImpl.java | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/GardsSampleDataServiceImpl.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/GardsSampleDataServiceImpl.java index cd70b9c0..289df3bc 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/GardsSampleDataServiceImpl.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/GardsSampleDataServiceImpl.java @@ -3,6 +3,7 @@ package org.jeecg.modules.system.service.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.ListUtil; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.baomidou.dynamic.datasource.annotation.DS; @@ -38,6 +39,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.interceptor.TransactionAspectSupport; import org.springframework.transaction.support.DefaultTransactionDefinition; +import java.io.File; import java.util.*; import java.util.stream.Collectors; @@ -112,9 +114,9 @@ public class GardsSampleDataServiceImpl extends ServiceImpl failList = new ArrayList<>(); - for (String path:needDel) { - boolean success = ftpUtil.removeFiles(path); - if (!success) { - failList.add(path); + // 删除本地文件 + List fails = new ArrayList<>(); + for (String path : needDel) { + log.info("删除能谱文件:{}", path); + File file = new File(path); + if (file.isDirectory()) { + fails.add(path); + continue; } + boolean success = FileUtil.del(path); + if (!success) fails.add(path); } - if (CollUtil.isNotEmpty(failList)) - return Result.error("Data clearing is complete, but file clearing fails!", failList); + if (CollUtil.isNotEmpty(fails)) + return Result.error("Data clearing is complete, but file clearing fails!", fails); return Result.OK("Data and file cleanup complete!"); }catch (Exception e){ transactionManager.rollback(txStatus);