wangting
2024-09-27 a3e87f78ee262ca9bb7d9b0c997639d5f3295890
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
package com.vci.client.uif.actions.client;
 
import java.text.MessageFormat;
import java.util.Map;
import java.util.Map.Entry;
 
import com.vci.client.LogonApplication;
import com.vci.client.bof.ClientBusinessObject;
import com.vci.client.bof.ClientLinkObject;
import com.vci.client.common.objects.UserEntityObject;
import com.vci.client.ui.exception.VCIException;
import com.vci.client.ui.locale.LocaleDisplay;
import com.vci.client.ui.process.QANProcessBar;
import com.vci.client.ui.process.QANProcessBarFrame;
import com.vci.client.ui.swing.VCIOptionPane;
import com.vci.client.uif.engine.common.IDataNode;
import com.vci.client.workflow.delegate.FlowInstanceClientDelegate;
import com.vci.client.workflow.delegate.ProcessCustomClientDelegate;
import com.vci.client.workflow.task.TodoTaskByPlatformDialog;
import com.vci.corba.common.VCIError;
import com.vci.corba.workflow.data.MapTransfersInfo;
import com.vci.mw.ClientContextVariable;
 
/**
 * 执行流程 Action
 * <p>执行流程</p>
 * @author liudi
 *
 */
public class EndWorkFlowAction extends AbstractBusionessOperationAction {
 
    @Override
    public String getKey() {
        return "endprocess";
    }
    
    @Override
    public boolean checkHasRight(){
        // 按BO进行数据权限检查
        setDataRightCheckType(RightCheckConstants.RIGHT_CHECK_TYPE_B);
        return super.checkHasRight();
    }
 
    /* (non-Javadoc)
     * @see plm.uif.actions.client.BusinessOperationAction#doPost()
     */
    @Override
    public boolean doPost() {
        // 获取选择的数据
        // 数据的实际类型一般为 IDataNode
        Object[] objs = getDataModel().getSelectObjects();
//        paramsMap = getButtonParams();
        
        UserEntityObject userEntityObject = new UserEntityObject();
        String ip = ClientContextVariable.getInvocationInfo().clientIPInfo;
        String loginUserName = ClientContextVariable.getInvocationInfo().userName;
        userEntityObject.setIp(ip);
        userEntityObject.setUserName(loginUserName);
        userEntityObject.setModules("");
        final FlowInstanceClientDelegate delegate = new FlowInstanceClientDelegate(userEntityObject);
        ProcessCustomClientDelegate processDelegate = new ProcessCustomClientDelegate(userEntityObject);
        String boLcstatus = "";
        String[] executionIds = new String[objs.length];
        for(int objectIndex=0;objectIndex<objs.length;objectIndex++){
            IDataNode idn = (IDataNode) objs[objectIndex];
            Map<String, String> valueMap = idn.getValueMap();
            int j=0;
            for(Entry<String, String> entrySet : valueMap.entrySet()){
                if(entrySet.getKey()!=null&&entrySet.getKey().equals("Executionid".toLowerCase())){
                    executionIds[j] = entrySet.getValue();
                    j++;
                }
            }
            boLcstatus = getBoLcStatus(boLcstatus, idn);
//            if(!boLcstatus.toLowerCase().equals("Completed".toLowerCase())){
//                String pattern = LocaleDisplay.getI18nString(
//                        "plm617.action.endworkflow.message", "UIFModelAction", LogonApplication.frame.getLocale());
//                pattern = MessageFormat.format(pattern, "");
//                VCIOptionPane.showMessage(LogonApplication.frame, pattern);
//                return false;
//            }
        }
        try {
            if(VCIOptionPane.showQuestion(LogonApplication.frame, "确定要中止该流程吗?")==0){
                String deploymentIdByExecutionId = processDelegate.getDeploymentIdByExecutionId(executionIds[0]);
                final String exeId = executionIds[0]; 
                if(deploymentIdByExecutionId==null||"".equals(deploymentIdByExecutionId)){
                    VCIOptionPane.showMessage(LogonApplication.frame, "流程已经完成,不能取消");
                }else{
                    final QANProcessBarFrame frame = new QANProcessBarFrame();
                    QANProcessBar bar = new QANProcessBar(new Thread() {
                        public void run() {
                            boolean b = false;
                            frame.setContent("正在进行处理数据,请稍等......");
                            try {
                                delegate.endProcessInstanceByplatform(exeId);
                            } catch (Exception e) {
                                frame.setProcessBarCancel(true);
                                UIFUtils.showErrorMessage(ClientContextVariable.getFrame(),e);
                            } finally {
                                frame.setProcessBarCancel(true);
                            }
                        }
                    }, frame, frame, "中止流程......",
                            false);
                    bar.setVisible(true);
                    UIFUtils.showMessage(ClientContextVariable.getFrame(), "流程取消成功!");
                }
                return true;
            }else{
                return false;
            }
        } catch (VCIError e) {
            e.printStackTrace();
            return false;
        }
    }
    private String getBoLcStatus(String boLcstatus, IDataNode idn) {
        if (idn.getMaterObject() instanceof ClientBusinessObject) {
            boLcstatus = ((ClientBusinessObject)idn.getMaterObject()).getLcStatus();
        } else if (idn.getMaterObject() instanceof ClientLinkObject) {
            if (idn.isForward()) {
                boLcstatus = ((ClientLinkObject)idn.getMaterObject()).getAttributeValue("lcstatus");
            } else {
                boLcstatus = ((ClientLinkObject)idn.getMaterObject()).getAttributeValue("lcstatus");
            }
        }
        return boLcstatus;
    }
}