吉安感知网项目-后端
xiebin
2026-01-06 d207a86cdf1ab52ef8cb7cd83bad8fceab8038cf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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;
    }
}