田源
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package com.vci.client.uif.actions.client;
 
import java.util.Map;
import java.util.Map.Entry;
 
import javax.swing.JFrame;
 
import com.vci.client.common.objects.UserEntityObject;
import com.vci.client.logon.base.TabPanelManage;
import com.vci.client.ui.exception.VCIException;
import com.vci.client.ui.process.QANProcessBar;
import com.vci.client.ui.process.QANProcessBarFrame;
import com.vci.client.uif.engine.common.IDataNode;
import com.vci.client.workflow.delegate.ProcessCustomClientDelegate;
import com.vci.client.workflow.task.TodoTaskByPlatformDialog;
import com.vci.corba.common.VCIError;
import com.vci.mw.ClientContextVariable;
 
/**
 * 执行流程 Action
 * <p>执行流程</p>
 * @author liudi
 *
 */
public class ExecuteWorkFlowAction extends AbstractBusionessOperationAction {
 
    @Override
    public String getKey() {
        return "executetask";
    }
 
    private Object[] objs  = new Object[0];
    private String outcome = "";
    private String[] taskOids = new String[objs.length];
    private String[] executionIds = new String[objs.length];
    private String[] taskNames = new String[objs.length];
    private String[] taskStatuss = new String[objs.length];
    private ProcessCustomClientDelegate getProcessCustomClientDelegate(){
        UserEntityObject userEntityObject = new UserEntityObject();
        String ip = ClientContextVariable.getInvocationInfo().clientIPInfo;
        String loginUserName = ClientContextVariable.getInvocationInfo().userName;
        userEntityObject.setIp(ip);
        userEntityObject.setUserName(loginUserName);
        userEntityObject.setModules("");
        ProcessCustomClientDelegate delegate = new ProcessCustomClientDelegate(userEntityObject);
        return delegate;
    }
    
    private void checkExecutable(){
        taskOids = new String[objs.length];
        executionIds = new String[objs.length];
        taskNames = new String[objs.length];
        taskStatuss = new String[objs.length];
        for (int objectIndex = 0; objectIndex < objs.length; objectIndex++) {
            IDataNode idn = (IDataNode) objs[objectIndex];
            Map<String, String> valueMap = idn.getValueMap();
                int i=0;
                int j=0;
                int k=0;
                int s=0;
                boolean subFlag = false;
                int subint =0;
            for(Entry<String, String> entrySet : valueMap.entrySet()){
                String value = entrySet.getValue();
                if(entrySet.getKey()!=null&&entrySet.getKey().equals("TaskOID".toLowerCase())){
                    taskOids[i] = value;
                    i++;
                }
                if(entrySet.getKey()!=null&&entrySet.getKey().equals("Executionid".toLowerCase())){
                    executionIds[j] = value;
                    String replace = value.replace(".", ",");
                    String[] split = replace.split(",");
                    if(split.length>2){
                        subFlag = true;
                    }else{
                        subFlag = false;
                    }
                    j++;
                }
                if(entrySet.getKey()!=null&&entrySet.getKey().equals("Name".toLowerCase())){
                    taskNames[k] = value;
                    k++;
                }
                if(entrySet.getKey()!=null&&entrySet.getKey().equals("lcstatus".toLowerCase())){
                    taskStatuss[s] = value;
                    s++;
                }
            }
            taskNames[0] = taskNames[0].substring(taskNames[0].lastIndexOf("-")+1);
        } 
    }
    @Override
    public boolean doPost() {
        // 获取选择的数据
        // 数据的实际类型一般为 IDataNode
        objs = getDataModel().getSelectObjects();
        ProcessCustomClientDelegate delegate = getProcessCustomClientDelegate();
        checkExecutable();
        // 用户名
        String[] userName = new String[] {};
        if("Completed".toLowerCase().equals(taskStatuss[0].toLowerCase())){
            UIFUtils.showMessage(ClientContextVariable.getFrame(), "任务已经完成!");
            return false;
        }
        TodoTaskByPlatformDialog dialog = new TodoTaskByPlatformDialog(executionIds[0],taskOids[0], taskNames[0],taskStatuss[0]);
        dialog.setTitle("执行任务");
        dialog.setVisible(true);
        boolean b = false;
        if(dialog.isSaveFlag()){
            outcome = dialog.getOutCome() == null ? "" : dialog.getOutCome();
            String approvalNote = dialog.getDesc() == null ? "" : dialog.getDesc();
            userName = !"".equals(dialog.getNextUser()) ? new String[]{dialog.getNextUser()} : new String[0];
            b = completeTask(delegate, taskOids, outcome, approvalNote, userName);
            if(b){
                UIFUtils.showMessage(ClientContextVariable.getFrame(), "执行成功!");
            }
        
            // 根据配置 close 决定,流程正常执行完毕,是否从顶级UI中关闭此窗口
            // 默认行为:如果没有配置值,则执行关闭;如果配置了值,当且仅当值为true时,执行关闭;否则不关闭
            // 即:默认关闭
            String close = getParameterValue(ValueType.ButtonConfig, "close", -1);
            Boolean closeValue = (close != null && "false".equalsIgnoreCase(close))? false : true;
            if(closeValue){
                TabPanelManage.getInstance().getTabPanel().remove(TabPanelManage.getInstance().getTabPanel().getSelectedIndex());
            }
        }
        return b;
    }
    private boolean completeTask(
            final ProcessCustomClientDelegate delegate,
            final String[] taskOids, final String outcome, final String approvalNote, final String[] userName){
        final boolean[] ress = {false};
        final QANProcessBarFrame frame  = new QANProcessBarFrame();
        final QANProcessBar bar = new QANProcessBar(new Thread(new Runnable() {
            @Override
            public void run() {
                try{
                    frame.setContent("正在提交流程,请稍等...");
                    String jbpmDeploymentId = delegate.getDeploymentIdByExecutionId(executionIds[0]);
                    String nextTaskName = delegate.getNextTaskNameByJbpmId(jbpmDeploymentId, taskNames[0], outcome);
//                        String[][]  properties = new String[][]{new String[]{"Oid","RevisionOid","NameOid","BTMName"},
//                                                                new String[]{}};
                    ress[0] = delegate.completeTaskByPlatform(
                            taskOids[0], outcome, nextTaskName, approvalNote , userName);
                }catch(VCIError e){
                    frame.setProcessBarCancel(true);
                    UIFUtils.showErrorMessage(ClientContextVariable.getFrame(), e);
                } catch (VCIException e) {
                    e.printStackTrace();
                    UIFUtils.showErrorMessage(ClientContextVariable.getFrame(), e);
                } finally{
                    frame.setProcessBarCancel(true);
                }
            }
        }), (JFrame) ClientContextVariable.getFrame(), frame, "执行流程", false);
        bar.setVisible(true);
        return ress[0];
    }
}