czt
9 天以前 db67639449287bcec461916a7dca6003ee5dd03c
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
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 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 fileId = null;
        try {
 
            String basePath = fileService.getFileSavePath("DEPT");
 
            fileId = "aerial-" + ContextUtil.subDeptId(null)
                    + file.getFileName().substring(
                    file.getFileName().lastIndexOf("."));
 
            file.transferTo(new File(basePath + fileId));
 
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
 
        return fileId;
    }
 
    /**
     * 上传出入库附件
     * 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;
    }
 
}