package org.sxkj.odm.service; import lombok.extern.slf4j.Slf4j; import org.springblade.core.log.exception.ServiceException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import org.sxkj.common.utils.SpringContextUtil; import org.sxkj.odm.config.OdmProperties; import org.sxkj.odm.constant.OdmConstant; import java.io.File; import java.text.MessageFormat; import static org.sxkj.odm.utils.FileUtils.deletedFile; /** * 异步服务处理 * @author zhongrj * @date 2024-09-10 */ @Slf4j @Component public class AsyncService { @Autowired private OdmProperties odmProperties; /** * 异步删除文件 */ @Async public void deleteFileByTaskIdAsync(String taskId){ // 读取对应文件目录列表 String filePath = MessageFormat.format(odmProperties.getWebodmDataBasePath() + OdmConstant.TASK_FILE_PATH, 3) + "/" + taskId; File file = new File(filePath); File[] files = file.listFiles(); if (null==files) { log.error("当前目录 {} 没有找到对应的文件!",filePath); return; } for (File f : files) { deletedFile(f); } } /** * 异步删除文件 */ public boolean deleteFileByTaskId(String taskId){ // 读取对应文件目录列表 String filePath = MessageFormat.format( odmProperties.getWebodmDataBasePath() + OdmConstant.TASK_FILE_PATH, 3) + "/" + taskId; File file = new File(filePath); File[] files = file.listFiles(); if (null==files) { log.error("当前目录 {} 没有找到对应的文件!",filePath); return false; } try { for (File f : files) { deletedFile(f); } }catch (Exception e){ log.error("文件删除异常:{}",e); return false; // throw new ServiceException("文件删除异常:"+ e); } return true; } }