jiazx0107
2025-11-18 b0bf6e809ec4990ca8e3de95456c90860e49e2a5
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package com.fzzy.eoms.file;
 
import com.fzzy.eoms.data.ConfigData;
import com.fzzy.eoms.file.mapper.FileServiceMapper;
import com.fzzy.eoms.models.FileInfo;
import com.fzzy.eoms.utils.ContextUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.io.File;
import java.util.Date;
import java.util.List;
 
@Component
public class CoreFileServiceImpl implements CoreFileService {
 
    @Resource
    private FileServiceMapper fileServiceMapper;
    @Resource
    private ConfigData configData;
 
 
    @Override
    public String getStoragePath(Date date) {
        if (null == date)
            date = new Date();
        String basePath = configData.getProfile() + "/" + DateFormatUtils.format(date, "yyyyMM") + "/";
        File file = new File(basePath);
        if (!file.exists()) {
            file.mkdirs();
        }
        return basePath;
    }
 
 
    @Override
    public String getTempFilePath(Date date) {
        String basePath = configData.getProfile() + "TEMP/" + DateFormatUtils.format(date, "yyyyMM") + "/";
        File file = new File(basePath);
        if (!file.exists()) {
            file.mkdirs();
        }
        return basePath;
    }
 
    @Override
    public void addRecord(FileInfo fileData) {
        fileServiceMapper.addFile(fileData);
    }
 
 
    @Override
    public List<FileInfo> listFile(String companyId, String bizId) {
        if (StringUtils.isEmpty(companyId)) {
            companyId = ContextUtil.getDefaultCompanyId();
        }
 
        if (StringUtils.isEmpty(bizId))
            return null;
 
        return fileServiceMapper.listFile(companyId, bizId);
    }
 
    @Override
    public List<FileInfo> listFile(String companyId, String bizId, String bizTag) {
        if (StringUtils.isEmpty(companyId)) {
            companyId = ContextUtil.getDefaultCompanyId();
        }
 
        if (StringUtils.isEmpty(bizId)) return null;
 
        if (StringUtils.isEmpty(bizTag)) return fileServiceMapper.listFile(companyId, bizId);
 
        return fileServiceMapper.listFile2(companyId, bizId, bizTag);
    }
 
    @Override
    public void delFile(String fileId) {
        fileServiceMapper.delFile(fileId);
    }
 
 
    @Override
    public void addRecords(List<FileInfo> files, String bizId, String bizTag, String companyId) {
        if (null == files || files.isEmpty()) {
            return;
        }
 
        if (null == companyId) {
            companyId = ContextUtil.getDefaultCompanyId();
        }
 
        FileInfo fileData;
        for (FileInfo data : files) {
            if (StringUtils.isEmpty(data.getFileName())) {
                continue;
            }
            //如有业务ID则不处理
            if (StringUtils.isNotEmpty(data.getBizId())) {
                continue;
            }
            if (StringUtils.isEmpty(data.getCompanyId())) {
                data.setCompanyId(companyId);
            }
 
            if (null == data.getCreateTime()) {
                data.setCreateTime(new Date());
            }
            if (null == data.getBizTag()) {
                data.setBizTag(bizTag);
            }
            data.setBizId(bizId);
            if (null == data.getFileId()) {
                data.setFileId(ContextUtil.getUUID());
            }
            fileData = new FileInfo();
            fileData.setFileId(data.getFileId());
            fileData.setBizId(data.getBizId());
            fileData.setBizTag(data.getBizTag());
            fileData.setFileName(data.getFileName());
            fileData.setCreateTime(data.getCreateTime());
            fileData.setCompanyId(data.getCompanyId());
            fileServiceMapper.addFile(fileData);
        }
    }
}