david-PC\david
2018-06-12 f240ac3ccd37c541cab2c21cfc433d3510999a3c
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
package frame.file.office;
 
 
import java.util.List;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
 
import frame.file.FileIO;
import frame.file.FileIOContainer;
import frame.file.FileIOItem;
import frame.file.UploadResult;
import frame.file.db.DataBaseTranslator;
import frame.file.office.excel.ExcelHandler;
import frame.file.office.excel.ExcelLoaders;
import frame.util.Util;
 
public class LoadManager {
    private boolean isSuccess;
    private Logger logger;
    private String ioCode;
    private FileIO fileIO;
    private UploadResult result;
    
    public LoadManager(UploadResult result) {
        this.result = result;
        this.logger  = LoggerFactory.getLogger(this.getClass());
    }
    
    public LoadManager(UploadResult result, String ioCode) {
        this.result = result;
        this.ioCode = ioCode;
        fileIO = FileIOContainer.get(ioCode);
        this.logger  = LoggerFactory.getLogger(this.getClass());
    }
    
    public boolean execute() throws Exception {
        boolean isSuccess = true;
        
        if (fileIO == null) {
            if (Util.isEmptyStr(ioCode)) {
                result.fail("error_IONotExist", "上载定义没有配置");
                throw new Exception("no iocode ");
            }
            else {
                fileIO = FileIOContainer.get(ioCode);
                if (fileIO == null) {
                    result.fail("error_IONotExist", "上载定义没有配置");
                    throw new Exception("no iocode mapping in FileioContainer");
                }
                doExecute();
            }
        }
        else {
            doExecute();
        }
        
        return isSuccess;
    }
    
    private void doExecute() throws Exception {
        //TODO 处理前事件
        fileIO.execHandlers(result, "begin");
        ExcelLoaders excelLoaders = new ExcelLoaders(logger);
        excelLoaders.setRequest();
        isSuccess = excelLoaders.load(result, fileIO);
        
        List<FileIOItem> dbList = fileIO.getItemList(FileIOTypeCode.Db);
        
        for (FileIOItem fileIOItem : dbList) {
            isSuccess = DataBaseTranslator.translate(result,fileIOItem);
        }
        
        List<FileIOItem> outputList = fileIO.getItemList(FileIOTypeCode.Output);
        
         //4. after save
        fileIO.execHandlers(result, "end");
        
    }
 
    public String getIoCode() {
        return ioCode;
    }
 
    public void setIoCode(String ioCode) {
        this.ioCode = ioCode;
    }
    
    
}