sgj
5 天以前 f71f31780ed55200f3e370e61c81cfd05feb34bd
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
129
130
131
package com.fzzy.igds;
 
import com.bstek.dorado.uploader.UploadFile;
import com.bstek.dorado.uploader.annotation.FileResolver;
import com.fzzy.igds.service.FileService;
import com.fzzy.igds.utils.ContextUtil;
import com.ruoyi.common.config.FrameworkConfig;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateFormatUtils;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.Map;
 
/**
 * @Description Dorado7 附件上传公共管理层
 * @Author CZT
 * @Date 2025/12/05 10:05
 */
@Slf4j
@Component
public class FileUploadManage {
 
    @Resource
    private FileService fileService;
 
    /**
     * 上传库区鸟瞰图
     * fileUploadManage#imgFile
     *
     * @param file
     * @param parameter
     * @return
     */
    @FileResolver
    public String imgFile(UploadFile file, Map<String, Object> parameter) {
 
        String filePath = null;
        try {
 
            String basePath = fileService.getFileSavePath("DEPT");
 
            //新文件名
            String fileId = "aerial-" + ContextUtil.subDeptId(null)
                    + file.getFileName().substring(
                    file.getFileName().lastIndexOf("."));
            //文件全路径
            filePath = basePath + fileId;
            //保存
            file.transferTo(new File(filePath));
 
            //替换后文件全路径
            filePath = filePath.replace(FrameworkConfig.getProfile(), "/profile/");
 
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
 
        return filePath;
    }
 
    /**
     * 上传出入库附件
     * fileUploadManage#inoutFile
     *
     * @param file
     * @param parameter
     * @return
     */
    @FileResolver
    public String inoutFile(UploadFile file, Map<String, Object> parameter) {
        //流程
        String bizTag = (String) parameter.get("bizTag");
        String newFileName = null;
        try {
            String basePath = fileService.getFileSavePath("INOUT");
            // 获取新的ID
            newFileName = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
            if(StringUtils.isNotEmpty(bizTag)){
                newFileName = bizTag + "_" + newFileName;
            }
            // 文件后缀名
            String suffixName = file.getFileName().substring(file.getFileName().lastIndexOf("."));
            // 合成新的文件名
 
            newFileName = newFileName + suffixName;
            file.transferTo(new File(basePath + newFileName));
 
        } catch (Exception e) {
            e.printStackTrace();
        }
        return newFileName;
    }
 
    /**
     * 上传出入库导入Excel模板
     * fileUploadManage#uploadExcel
     * @param file
     * @param parameter
     * @return
     */
    @FileResolver
    public String uploadExcel(UploadFile file, Map<String, Object> parameter) {
        String newFileName = null;
        try {
            String basePath = fileService.getFileSavePath("TEMP");
 
            newFileName = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
            newFileName = "EXCEL" + "_" + newFileName;
 
            // 文件后缀名
            String suffixName = file.getFileName().substring(file.getFileName().lastIndexOf("."));
 
            // 合成新的文件名
            newFileName = newFileName + suffixName;
            file.transferTo(new File(basePath + newFileName));
 
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
 
        return newFileName;
    }
}