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];
|
}
|
}
|