田源
2025-01-09 8a166a60cfd1a2e593ffa103d10c0dc224fc8628
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
132
133
134
135
136
137
138
139
package com.vci.client.uif.actions.client;
 
import java.util.Map;
 
import com.vci.client.bof.ClientBusinessObject;
import com.vci.client.bof.ClientLinkObject;
import com.vci.client.fm.FileObject;
import com.vci.client.uif.engine.common.IDataNode;
import com.vci.mw.ClientContextVariable;
 
/**
 * 文档文件下载按钮
 * 对于下载操作,需要在按钮中配置fileObject oid所在字段
 * 下载操作始终针对的是BO对象,如果按钮获得的输入时LO时加载LO的FROM端或TO端对象
 * 加一个参数是否调用系统的默认打开方式
 * @author VCI-STGK006
 *
 */
public class DownloadAction extends AbstractBatchBusionessOperationAction {
 
    /**
     * 操作方法
     */
    private UIFUtils operation =
            new UIFUtils();
    
    /**
     * 文件上传下载方法
     */
    private FileOperation fopreation = new FileOperation(); 
    
    public DownloadAction(){
        super();
    }
    
    @Override
    public String getKey() {
        return DOWNLOAD;
    }
    
    @Override
    public boolean checkHasRight(){
        // 按BO进行数据权限检查
        setDataRightCheckType(RightCheckConstants.RIGHT_CHECK_TYPE_B);
        return super.checkHasRight();
    }
 
    @SuppressWarnings("unchecked")
    @Override
    public boolean doPost() {
        try {
            //显示创建窗口
            Map<String, String> paramsMap = getButtonParams();
            String oidField = paramsMap.get("oid");
            String direction = paramsMap.get("direction");
            String open = paramsMap.get("open");
            if(oidField == null || oidField.equals("")){
                oidField = "oid";
            }
            if(direction == null || direction.equals("")){
                direction = "true";
            }
            if(open == null || open.equals("")){
                open = "false";
            }
            
            //基本信息
            boolean isOpen = open.equals("true")? true : false;
            boolean isDirection = direction.equals("false")? false : true;
            
            //得到用户选择数据
            Object[] selectedObjects = getDataModel().getSelectObjects();
 
            //根据不同的参数获得所有FileObject对象的OID
            String[] foOids = new String[selectedObjects.length];
            for(int i = 0; i< selectedObjects.length; i++){
                if(selectedObjects[i] instanceof Map){
                    foOids[i] = ((Map<String, String>) selectedObjects[i]).get("OID");
                } else if (selectedObjects[i] instanceof IDataNode){
                    Object mainObject = ((IDataNode)selectedObjects[i]).getMaterObject();
                    if(mainObject instanceof ClientBusinessObject){
                        foOids[i] = ((ClientBusinessObject) mainObject).getAttributeValue(oidField);
                    } else if(mainObject instanceof ClientLinkObject){
                        String oid = "";
                        String btmName = "";
                        if(isDirection){
                            oid = ((ClientLinkObject) mainObject).getLinkObject().toOid;
                            btmName = ((ClientLinkObject) mainObject).getLinkObject().toBTName;
                        } else {
                            oid = ((ClientLinkObject) mainObject).getLinkObject().fromOid;
                            btmName = ((ClientLinkObject) mainObject).getLinkObject().fromBTName;
                        }
                        //加载BO对象
                        ClientBusinessObject cbo = operation.reloadClientBusinessObject(
                                ClientContextVariable.getFrame(), oid, btmName);
                        if(cbo != null){
                            foOids[i] = cbo.getAttributeValue(oidField);
                        }
                    }
                }
            }
            //判断附件是否存在
            if(foOids == null || foOids.length < 1 
                    || (foOids.length == 1 && (foOids[0] == null || foOids[0].equals("")))){
                UIFUtils.showMessage(null, "uifmodel.plm.uif.actions.download.filenotexist", "");
                return false;
            }
            //判断是下载文件还是打开文件
            if(isOpen){
                if(!fopreation.openFile(foOids)){
                    UIFUtils.showErrorMessage(ClientContextVariable.getFrame(),
                            "uifmodel.plm.uif.actions.downloadfileerror", new Exception("文件不存在!"));
                }
            } else {
                FileObject[] fos = fopreation.downloadFile(ClientContextVariable.getFrame(), foOids, "");
                if(fos == null){
                    return false;
                }
                String fileName = "";
                if(fos.length > 0 && fos.length <= 5){
                    for(FileObject fo : fos){
                        fileName += ";" + fo.getBusinessObject().name;
                    }
                }
                if(!fileName.equals("")){
                    fileName = fileName.substring(1);
                }
                UIFUtils.showMessage(ClientContextVariable.getFrame(),
                        "uifmodel.plm.uif.actions.downloadfilesuccessmsg",fileName);
            }
            return false;
        } catch (Exception e){
            UIFUtils.showErrorMessage(ClientContextVariable.getFrame(),
                    "uifmodel.plm.uif.actions.downloadfileerror", e);
            return false;
        }
    }
 
}