ws183
2025-04-28 b306d1106b915bb13fd7a02217ae9c65de2fd03d
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
package com.ld.igds.file;
 
import java.io.File;
import java.io.IOException;
import java.util.Map;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import com.bstek.dorado.uploader.UploadFile;
import com.bstek.dorado.uploader.annotation.FileResolver;
import com.ld.igds.util.ContextUtil;
 
/**
 * dorado7附件上传
 * 
 * @author: andy.jia
 * @description:
 * @version:
 * @data:2020年6月24日
 *
 */
@Component
public class MyUploadProcessor {
 
    @Autowired
    private CoreFileService fileService;
 
    /**
     * 
     * myUploadProcessor#tempProcess
     * 上传附件到临时目录,名称自动调整生成,并返回
     * 
     * @param file
     * @param parameter
     * @return
     */
    @FileResolver
    public String tempProcess(UploadFile file, Map<String, Object> parameter) {
        String newFileName = null;
        try {
            String basePath = fileService.getTempFilePath();
 
            newFileName = ContextUtil.getUUID()
                    + file.getFileName().substring(
                            file.getFileName().lastIndexOf("."));
 
            file.transferTo(new File(basePath + newFileName));
 
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
 
        return newFileName;
    }
 
    /**
     * 上传公共文件,如合同、计划等
     * myUploadProcessor#uploadCommonFile
     * @param file
     * @param parameter
     * @return
     */
    @FileResolver
    public String uploadCommonFile(UploadFile file, Map<String, Object> parameter) {
 
        String fileId = null;
        try {
 
            String oldFileName = (String)parameter.get("name");
            if(oldFileName == null){
                //上传失败:附件名称为空。
                return "10";
            }
            //判断oldFileName后缀名是否为pdf
            if(!oldFileName.endsWith(".pdf")) {
                //上传失败:附件不是pdf文件。
                return "20";
            }
            String basePath = fileService.getCommonFilePath(null);
 
            fileId = ContextUtil.getTimeId(1000)
                    + file.getFileName().substring(
                    file.getFileName().lastIndexOf("."));
 
            file.transferTo(new File(basePath + fileId));
 
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
 
        return fileId;
    }
 
}