package com.vci.server.workflow.server.template;
|
|
import java.awt.BasicStroke;
|
import java.awt.Color;
|
import java.awt.Graphics2D;
|
import java.awt.image.BufferedImage;
|
import java.io.BufferedReader;
|
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayOutputStream;
|
import java.io.File;
|
import java.io.FileInputStream;
|
import java.io.IOException;
|
import java.io.InputStream;
|
import java.io.InputStreamReader;
|
import java.lang.reflect.InvocationTargetException;
|
import java.math.BigDecimal;
|
import java.sql.Connection;
|
import java.sql.PreparedStatement;
|
import java.sql.ResultSet;
|
import java.sql.SQLException;
|
import java.sql.Statement;
|
import java.sql.Timestamp;
|
import java.text.DateFormat;
|
import java.text.ParseException;
|
import java.text.SimpleDateFormat;
|
import java.util.ArrayList;
|
import java.util.Arrays;
|
import java.util.Calendar;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.HashSet;
|
import java.util.Hashtable;
|
import java.util.Iterator;
|
import java.util.LinkedHashMap;
|
import java.util.LinkedList;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Map.Entry;
|
import java.util.Set;
|
import java.util.zip.ZipInputStream;
|
|
import javax.imageio.ImageIO;
|
|
import org.apache.commons.lang3.StringUtils;
|
import org.dom4j.Attribute;
|
import org.dom4j.Document;
|
import org.dom4j.Element;
|
import org.dom4j.io.SAXReader;
|
import org.hibernate.HibernateException;
|
import org.hibernate.Query;
|
import org.hibernate.SQLQuery;
|
import org.hibernate.Session;
|
import org.hibernate.criterion.Projections;
|
import org.hibernate.criterion.Restrictions;
|
import org.hibernate.jdbc.Work;
|
import org.jbpm.api.Execution;
|
import org.jbpm.api.ExecutionService;
|
import org.jbpm.api.ProcessDefinition;
|
import org.jbpm.api.ProcessEngine;
|
import org.jbpm.api.ProcessInstance;
|
import org.jbpm.api.RepositoryService;
|
import org.jbpm.api.TaskService;
|
import org.jbpm.api.activity.ActivityBehaviour;
|
import org.jbpm.api.cmd.Command;
|
import org.jbpm.api.cmd.Environment;
|
import org.jbpm.api.listener.EventListener;
|
import org.jbpm.api.model.ActivityCoordinates;
|
import org.jbpm.api.task.Participation;
|
import org.jbpm.api.task.Task;
|
import org.jbpm.jpdl.internal.activity.TaskActivity;
|
import org.jbpm.pvm.internal.env.EnvironmentFactory;
|
import org.jbpm.pvm.internal.env.EnvironmentImpl;
|
import org.jbpm.pvm.internal.model.Activity;
|
import org.jbpm.pvm.internal.model.ActivityImpl;
|
import org.jbpm.pvm.internal.model.EventImpl;
|
import org.jbpm.pvm.internal.model.ExecutionImpl;
|
import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
|
import org.jbpm.pvm.internal.model.Transition;
|
import org.jbpm.pvm.internal.model.TransitionImpl;
|
import org.jbpm.pvm.internal.task.ParticipationImpl;
|
import org.jbpm.pvm.internal.task.TaskDefinitionImpl;
|
import org.jbpm.pvm.internal.task.TaskImpl;
|
|
import com.vci.omd.constants.BusinessConstants;
|
import com.vci.omd.utils.ObjectTool;
|
import com.vci.common.log.ServerWithLog4j;
|
import com.vci.common.objects.QueryParam;
|
import com.vci.common.objects.QueryResult;
|
import com.vci.common.objects.UserEntity;
|
import com.vci.common.qt.object.Condition;
|
import com.vci.common.qt.object.QTConstants;
|
import com.vci.common.qt.object.QueryTemplate;
|
import com.vci.common.utility.ObjectUtility;
|
import com.vci.common.exception.VciException;
|
import com.vci.corba.common.VCIError;
|
import com.vci.corba.common.data.UserEntityInfo;
|
import com.vci.corba.omd.data.BusinessObject;
|
import com.vci.corba.omd.data.LinkObject;
|
import com.vci.corba.workflow.data.CustomInfo;
|
import com.vci.corba.workflow.data.FlowInstanceInfo;
|
import com.vci.corba.workflow.data.FlowTaskInfo;
|
import com.vci.corba.workflow.data.ProcessDefinitionInfo;
|
import com.vci.corba.workflow.data.ProcessTaskInfo;
|
import com.vci.corba.workflow.data.PropertyInfo;
|
import com.vci.corba.workflow.data.SubprocessTemInfo;
|
import com.vci.server.base.persistence.dao.BaseService;
|
import com.vci.server.base.persistence.dao.HibernateCallback;
|
import com.vci.server.base.persistence.dao.HibernateSessionFactory;
|
import com.vci.server.base.persistence.dao.HibernateTemplate;
|
import com.vci.server.base.persistence.dao.JDBCCallback;
|
import com.vci.server.base.persistence.dao.JDBCRunType;
|
import com.vci.server.base.persistence.dao.JDBCTemplate;
|
import com.vci.server.base.utility.OQueryHelper;
|
import com.vci.server.base.utility.ServerServiceProvider;
|
import com.vci.server.workflow.common.FlowConstants;
|
import com.vci.server.workflow.common.ZipUtil;
|
import com.vci.server.workflow.common.resouce.WorkflowProperties;
|
import com.vci.server.workflow.common.task.FlowApproveHistory;
|
import com.vci.server.workflow.dao.FlowInstanceDaoImpl;
|
import com.vci.server.workflow.dao.NodeHideDaoImpl;
|
import com.vci.server.workflow.dao.PLFlowObjectDaoImpl;
|
import com.vci.server.workflow.dao.PlflowapproveopinionDaoImpl;
|
import com.vci.server.workflow.dao.ProcessTaskDaoImpl;
|
import com.vci.server.workflow.dao.ProcessTaskPropertyDaoImpl;
|
import com.vci.server.workflow.dao.RMTemplateProcessDaoImpl;
|
import com.vci.server.workflow.dao.TaskDescDaoImpl;
|
import com.vci.server.workflow.dao.TaskRevokeDaoImpl;
|
import com.vci.server.workflow.dao.TasksAssignedDaoImpl;
|
import com.vci.server.workflow.objects.FlowInstance;
|
import com.vci.server.workflow.objects.NodeHide;
|
import com.vci.server.workflow.objects.PLFlowObject;
|
import com.vci.server.workflow.objects.Plflowapproveopinion;
|
import com.vci.server.workflow.objects.ProcessTask;
|
import com.vci.server.workflow.objects.ProcessTaskProperty;
|
import com.vci.server.workflow.objects.RMTemplateProcess;
|
import com.vci.server.workflow.objects.TaskCCSObject;
|
import com.vci.server.workflow.objects.TaskDescSObject;
|
import com.vci.server.workflow.objects.TaskRevokeSObject;
|
import com.vci.server.workflow.server.JbpmEngine;
|
import com.vci.server.workflow.server.ServerErrorTool;
|
import com.vci.server.workflow.server.WorkFlowCahe;
|
import com.vci.server.workflow.server.event.Sign;
|
import com.vci.server.workflow.server.interfaces.CustomUserClassInterface;
|
import com.vci.server.workflow.server.interfaces.IWorkflowUserService;
|
import com.vci.server.workflow.server.interfaces.PLMWorkItemInterface;
|
import com.vci.server.workflow.server.service.WorkFlowService;
|
|
public class ProcessTemplateService extends BaseService {
|
|
private String fileSeparator = System.getProperty("file.separator");
|
HashMap<String, Document> templateMap = new HashMap<String, Document>();
|
|
// 调用plmworkitem类保存workitem对象
|
String workitemClass = WorkflowProperties.getStringProperty("workflow.plmworkitem");
|
|
PLMWorkItemInterface _pwiService = null;
|
|
// 是否为批量执行的标志 默认不是批量执行 add by changmk 20170629
|
private boolean batchExecuteTaskFlag = false;
|
|
private boolean getBatchExecuteTaskFlag() {
|
return batchExecuteTaskFlag;
|
}
|
|
private void setBatchExecuteTaskFlag(boolean batchExecuteTaskFlag) {
|
this.batchExecuteTaskFlag = batchExecuteTaskFlag;
|
}
|
|
public ProcessTemplateService(UserEntity userEntity) {
|
super(userEntity);
|
|
InitWIService();
|
}
|
|
public ProcessTemplateService() {
|
InitWIService();
|
}
|
|
private void InitWIService() {
|
try {
|
_pwiService = (PLMWorkItemInterface) (Class.forName(workitemClass).newInstance());
|
} catch (InstantiationException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
} catch (IllegalAccessException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
} catch (ClassNotFoundException e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
}
|
|
public boolean deployProcess(final byte[] jbpmImage, String jbpmXml, String graphXml,
|
final String processCategoryId, final ProcessTaskInfo[] processTaskInfos) {
|
try {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
String name = "flow" + System.currentTimeMillis();
|
String path = System.getProperty("user.home") + fileSeparator + ".flow" + fileSeparator + name;
|
// 如果目录不存在,创建目录
|
if (!new File(path).getParentFile().exists()) {
|
new File(path).mkdirs();
|
}
|
Map<String, InputStream> map = new Hashtable<String, InputStream>();
|
InputStream is = new ByteArrayInputStream(jbpmImage);
|
map.put(name + ".png", is);
|
|
InputStream jpdlIs = new ByteArrayInputStream(jbpmXml.getBytes("utf-8"));
|
map.put(name + ".jpdl.xml", jpdlIs);
|
|
InputStream graphIs = new ByteArrayInputStream(graphXml.getBytes("utf-8"));
|
map.put(name + ".graph", graphIs);
|
ZipUtil.saveZip(path + ".zip", map);
|
File file = new File(path + ".zip");
|
FileInputStream fis = new FileInputStream(file);
|
ZipInputStream zin = new ZipInputStream(fis);
|
final String deployId = processEngine.getRepositoryService().createDeployment()
|
.addResourcesFromZipInputStream(zin).deploy();
|
final long deploymentId = Long.parseLong(deployId);
|
|
InputStream inputStrem = new ByteArrayInputStream(jbpmXml.getBytes("utf-8"));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStrem, "utf-8"));
|
|
SAXReader saxr = new SAXReader();
|
Document doc = saxr.read(reader);
|
String jbpmDeploymentId = String.valueOf(deploymentId);
|
|
WorkFlowCahe.setMap(jbpmDeploymentId, doc);
|
|
Session session = HibernateSessionFactory.getSession();
|
session.flush();
|
|
String id = ObjectUtility.getNewObjectID36();
|
Date date = new Date();
|
long time = date.getTime();
|
Timestamp createTS = new Timestamp(time);
|
System.out.println(createTS);
|
StringBuilder insertPlflowapproveopinion = new StringBuilder();
|
insertPlflowapproveopinion.append("insert into plprocesstemplate");
|
insertPlflowapproveopinion
|
.append(" (ploid, plcategoryoid, pljbpmdeploymentid, plcreatetime, plcreateuser, plstatus) ");
|
insertPlflowapproveopinion.append(" values ");
|
insertPlflowapproveopinion.append(" ('" + id + "', '" + processCategoryId + "', '" + deploymentId
|
+ "', ?, '" + userEntity.getUserName() + "','0') ");
|
SQLQuery createSQLQuery = session.createSQLQuery(insertPlflowapproveopinion.toString());
|
createSQLQuery.setTimestamp(0, date);
|
createSQLQuery.executeUpdate();
|
|
// ProcessTemplateDaoImpl impl = new ProcessTemplateDaoImpl();
|
// ProcessTemplate object = new ProcessTemplate();
|
// String id = ObjectUtility.getNewObjectID36();
|
// object.setId(id);
|
// object.setJbpmDeploymentId(deploymentId);
|
// object.setProcessCategoryId(processCategoryId);
|
// object.setCreateUser(userEntity.getUserName());
|
// object.setStatus("0");
|
// impl.saveOrUpdate(object);
|
|
ProcessTaskDaoImpl taskImpl = new ProcessTaskDaoImpl();
|
ProcessTaskPropertyDaoImpl propertyImpl = new ProcessTaskPropertyDaoImpl();
|
TaskDescDaoImpl taskDescDaoImpl = new TaskDescDaoImpl();
|
TaskRevokeDaoImpl taskrevokeImpl = new TaskRevokeDaoImpl();
|
|
for (ProcessTaskInfo processTaskInfo : processTaskInfos) {
|
ProcessTask taskproperty = new ProcessTask();
|
id = ObjectUtility.getNewObjectID36();
|
taskproperty.setId(id);
|
taskproperty.setDeploymentId(deployId);
|
taskproperty.setTaskName(processTaskInfo.taskName);
|
taskproperty.setTaskType(processTaskInfo.taskType);
|
if (processTaskInfo.taskTypeProperties.length > 0) {
|
String taskPropertyId = ObjectUtility.getNewObjectID36();
|
saveProperty(propertyImpl, processTaskInfo.taskTypeProperties, taskPropertyId);
|
taskproperty.setTaskTypePropertyId(taskPropertyId);
|
}
|
saveTaskDesc(taskDescDaoImpl, processTaskInfo, jbpmDeploymentId);
|
saveRevoke(taskrevokeImpl, processTaskInfo, jbpmDeploymentId);
|
taskImpl.save(taskproperty);
|
}
|
HibernateSessionFactory.getSession().flush();
|
return true;
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return false;
|
}
|
|
public boolean updateProcess(final byte[] jbpmImage, String jbpmXml, String graphXml,
|
final String processCategoryId, final ProcessTaskInfo[] processTaskInfos, String deployId) {
|
try {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
String name = "flow" + System.currentTimeMillis();
|
String path = System.getProperty("user.home") + fileSeparator + ".flow" + fileSeparator + name;
|
// 如果目录不存在,创建目录
|
if (!new File(path).getParentFile().exists()) {
|
new File(path).mkdirs();
|
}
|
Map<String, InputStream> map = new Hashtable<String, InputStream>();
|
InputStream is = new ByteArrayInputStream(jbpmImage);
|
map.put(name + ".png", is);
|
|
InputStream jpdlIs = new ByteArrayInputStream(jbpmXml.getBytes("utf-8"));
|
// map.put(name + ".jpdl.xml", jpdlIs);
|
|
InputStream graphIs = new ByteArrayInputStream(graphXml.getBytes("utf-8"));
|
// map.put(name + ".graph", graphIs);
|
// ZipUtil.saveZip(path + ".zip", map);
|
// File file = new File(path + ".zip");
|
// FileInputStream fis = new FileInputStream(file);
|
// ZipInputStream zin = new ZipInputStream(fis);
|
// processEngine.getRepositoryService().updateDeploymentResource(deployId, name
|
// + ".jpdl.xml", jpdlIs);
|
// HibernateSessionFactory.getSession().clear();
|
// Transaction trans = HibernateSessionFactory.getSession().beginTransaction();
|
// processEngine.getRepositoryService().updateDeploymentResource(deployId, name
|
// + ".jpdl.xml", jpdlIs);
|
// HibernateSessionFactory.getSession().flush();
|
// processEngine.getRepositoryService().updateDeploymentResource(deployId, name
|
// + ".graph", graphIs);
|
// HibernateSessionFactory.getSession().flush();
|
// processEngine.getRepositoryService().updateDeploymentResource(deployId, name
|
// + ".png", is);
|
/*
|
* final long deploymentId = Long.parseLong(deployId);
|
*
|
* InputStream inputStrem = new ByteArrayInputStream(
|
* jbpmXml.getBytes("utf-8")); BufferedReader reader = new BufferedReader(new
|
* InputStreamReader( inputStrem, "utf-8"));
|
*
|
* SAXReader saxr = new SAXReader(); Document doc = saxr.read(reader); String
|
* jbpmDeploymentId = String.valueOf(deploymentId);
|
*
|
* WorkFlowCahe.setMap(jbpmDeploymentId, doc);
|
*
|
* Session session = HibernateSessionFactory.getSession(); // session.flush();
|
*
|
* String id = ObjectUtility.getNewObjectID36(); Date date = new Date(); long
|
* time = date.getTime(); Timestamp create = new Timestamp(time); StringBuilder
|
* insertPlflowapproveopinion = new StringBuilder();
|
* insertPlflowapproveopinion.append("insert into plprocesstemplate");
|
* insertPlflowapproveopinion
|
* .append(" (ploid, plcategoryoid, pljbpmdeploymentid, plcreatetime, plcreateuser, plstatus) "
|
* ); insertPlflowapproveopinion.append(" values ");
|
* insertPlflowapproveopinion.append(" ('" + id + "', '" + processCategoryId +
|
* "', '" + deploymentId + "', ?, '" + userEntity.getUserName() + "','0') ");
|
* SQLQuery createSQLQuery = session
|
* .createSQLQuery(insertPlflowapproveopinion.toString());
|
* createSQLQuery.setTimestamp(0, create); //createSQLQuery.executeUpdate();
|
*
|
* // ProcessTemplateDaoImpl impl = new ProcessTemplateDaoImpl(); //
|
* ProcessTemplate object = new ProcessTemplate(); // String id = new
|
* ObjectUtility().getNewObjectID36(); // object.setId(id); //
|
* object.setJbpmDeploymentId(deploymentId); //
|
* object.setProcessCategoryId(processCategoryId); //
|
* object.setCreateUser(userEntity.getUserName()); // object.setStatus("0"); //
|
* impl.saveOrUpdate(object);
|
*
|
* ProcessTaskDaoImpl taskImpl = new ProcessTaskDaoImpl();
|
* ProcessTaskPropertyDaoImpl propertyImpl = new ProcessTaskPropertyDaoImpl();
|
* TaskDescDaoImpl taskDescDaoImpl = new TaskDescDaoImpl(); TaskRevokeDaoImpl
|
* taskrevokeImpl = new TaskRevokeDaoImpl();
|
*
|
* for (ProcessTaskInfo processTaskInfo : processTaskInfos) { ProcessTask
|
* taskproperty = new ProcessTask(); id = new
|
* ObjectUtility().getNewObjectID36(); taskproperty.setId(id);
|
* taskproperty.setDeploymentId(deployId);
|
* taskproperty.setTaskName(processTaskInfo.taskName);
|
* taskproperty.setTaskType(processTaskInfo.taskType); if
|
* (processTaskInfo.taskTypeProperties.length > 0) { String taskPropertyId = new
|
* ObjectUtility() .getNewObjectID36(); saveProperty(propertyImpl,
|
* processTaskInfo.taskTypeProperties, taskPropertyId);
|
* taskproperty.setTaskTypePropertyId(taskPropertyId); }
|
* saveTaskDesc(taskDescDaoImpl, processTaskInfo, jbpmDeploymentId);
|
* saveRevoke(taskrevokeImpl, processTaskInfo, jbpmDeploymentId);
|
* taskImpl.save(taskproperty); } HibernateSessionFactory.getSession().flush();
|
*/
|
// trans.commit();
|
return true;
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return false;
|
}
|
|
private void saveProperty(ProcessTaskPropertyDaoImpl propertyImpl, PropertyInfo[] properties,
|
String taskPropertyId) {
|
for (int i = 0; i < properties.length; i++) {
|
ProcessTaskProperty property = new ProcessTaskProperty();
|
String propertyId = ObjectUtility.getNewObjectID36();
|
property.setId(propertyId);
|
property.setTaskPropertyId(taskPropertyId);
|
property.setProperty(properties[i].property);
|
property.setValue(properties[i].value);
|
propertyImpl.save(property);
|
}
|
}
|
|
private void saveTaskDesc(TaskDescDaoImpl taskDescDaoImpl, ProcessTaskInfo processTaskInfo, String deploymentId) {
|
CustomInfo[] customUserInfos = processTaskInfo.customUserInfos;
|
if (customUserInfos.length != 0) {
|
for (int i = 0; i < customUserInfos.length; i++) {
|
TaskDescSObject object = new TaskDescSObject();
|
String newObjectID36 = ObjectUtility.getNewObjectID36();
|
object.setId(newObjectID36);
|
object.setPljbpmdeploymentid(String.valueOf(deploymentId));
|
object.setPltask(processTaskInfo.taskName);
|
object.setPltreatment((int) processTaskInfo.pltreatment);
|
object.setPltaskdesc(processTaskInfo.taskDesc);
|
object.setPopUserDialog(processTaskInfo.popUserDialog);
|
object.setPlcustomclassname(customUserInfos[i].className);
|
object.setPlcustomparam(customUserInfos[i].value);
|
taskDescDaoImpl.save(object);
|
}
|
} else {
|
TaskDescSObject object = new TaskDescSObject();
|
String newObjectID36 = ObjectUtility.getNewObjectID36();
|
object.setId(newObjectID36);
|
object.setPljbpmdeploymentid(String.valueOf(deploymentId));
|
object.setPltask(processTaskInfo.taskName);
|
object.setPltreatment((int) processTaskInfo.pltreatment);
|
object.setPltaskdesc(processTaskInfo.taskDesc);
|
object.setPopUserDialog(processTaskInfo.popUserDialog);
|
object.setPlcustomclassname("");
|
object.setPlcustomparam("");
|
taskDescDaoImpl.save(object);
|
}
|
}
|
|
private void saveRevoke(TaskRevokeDaoImpl taskrevokeImpl, ProcessTaskInfo processTaskInfo, String deploymentId) {
|
PropertyInfo[] revokeInfos = processTaskInfo.revokeInfos;
|
String revoke = processTaskInfo.revoke;
|
if (revokeInfos != null && revokeInfos.length != 0) {
|
if ("on".equals(revoke.toLowerCase())) {
|
for (int i = 0; i < revokeInfos.length; i++) {
|
TaskRevokeSObject object = new TaskRevokeSObject();
|
String newObjectID36 = ObjectUtility.getNewObjectID36();
|
object.setId(newObjectID36);
|
object.setPljbpmdeploymentid(String.valueOf(deploymentId));
|
object.setPltask(processTaskInfo.taskName);
|
object.setPlclassname(revokeInfos[i].value);
|
object.setPlrevoke(revoke);
|
taskrevokeImpl.save(object);
|
}
|
}
|
} else {
|
TaskRevokeSObject object = new TaskRevokeSObject();
|
String newObjectID36 = ObjectUtility.getNewObjectID36();
|
object.setId(newObjectID36);
|
object.setPljbpmdeploymentid(String.valueOf(deploymentId));
|
object.setPltask(processTaskInfo.taskName);
|
object.setPlclassname("");
|
object.setPlrevoke(revoke);
|
taskrevokeImpl.save(object);
|
}
|
}
|
|
/**
|
* 获取任务描述列表
|
*
|
* @param taskName
|
* @param deploymentId
|
* @return
|
*/
|
public List<TaskDescSObject> getTaskDescList(final String taskName, final String deploymentId) {
|
TaskDescDaoImpl taskDescDaoImpl = new TaskDescDaoImpl();
|
String hsql = " from TaskDescSObject t where t.pltask = '" + taskName + "' and t.pljbpmdeploymentid = '"
|
+ deploymentId + "'";
|
return taskDescDaoImpl.findEntities(hsql);
|
|
}
|
|
public List<ProcessDefinitionInfo> getProcessDefinitions(final String processCategoryId) {
|
Map<String, ProcessDefinitionInfo> pds = new HashMap<String, ProcessDefinitionInfo>();
|
List<String> deployIds = new ArrayList<String>();
|
StringBuilder sql = new StringBuilder();
|
sql.append("SELECT d.DEPLOYMENT_, d.OBJNAME_, d.KEY_, d.STRINGVAL_, d.LONGVAL_,p.PLSTATUS");
|
sql.append(" FROM JBPM4_DEPLOYPROP d left join PLPROCESSTEMPLATE p on d.DEPLOYMENT_=p.PLJBPMDEPLOYMENTID");
|
sql.append(" where d.KEY_ <> 'langid' and p.PLCATEGORYOID=? order by d.OBJNAME_, d.DEPLOYMENT_, d.KEY_");
|
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
createSQLQuery.setString(0, processCategoryId);
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List list = createSQLQuery.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] obj = (Object[]) list.get(i);
|
String deployId = String.valueOf(obj[0]) + "";
|
String name = (String) obj[1];
|
String key = (String) obj[2];
|
String stringValue = (String) obj[3];
|
int longValue = ((BigDecimal) obj[4]) == null ? 1 : ((BigDecimal) obj[4]).intValue();
|
int status = ((BigDecimal) obj[5]) == null ? 1 : ((BigDecimal) obj[5]).intValue();
|
ProcessDefinitionInfo processDefinitionInfo = pds.get(deployId);
|
if (processDefinitionInfo == null) {
|
processDefinitionInfo = new ProcessDefinitionInfo();
|
processDefinitionInfo.jbpmDeploymentId = deployId;
|
processDefinitionInfo.name = name == null ? "" : name;
|
processDefinitionInfo.status = String.valueOf(status) == null ? "" : String.valueOf(status);
|
pds.put(deployId, processDefinitionInfo);
|
}
|
if (key.equals("pdid")) {
|
processDefinitionInfo.id = stringValue == null ? "" : stringValue;
|
} else if (key.equals("pdkey")) {
|
processDefinitionInfo.key = stringValue == null ? "" : stringValue;
|
} else if (key.equals("pdversion")) {
|
processDefinitionInfo.version = longValue;
|
}
|
|
if (!deployIds.contains(deployId)) {
|
deployIds.add(deployId);
|
}
|
}
|
} catch (Exception ex) {
|
ex.printStackTrace();
|
} finally {
|
|
}
|
|
List<ProcessDefinitionInfo> result = new ArrayList<ProcessDefinitionInfo>();
|
for (String deployId : deployIds) {
|
result.add(pds.get(deployId));
|
}
|
return result;
|
}
|
|
/**
|
* 获取所有启用流程定义信息
|
*
|
* @return
|
*/
|
public List<ProcessDefinitionInfo> getAllProcessDefinitions() {
|
Map<String, ProcessDefinitionInfo> pds = new HashMap<String, ProcessDefinitionInfo>();
|
List<String> deployIds = new ArrayList<String>();
|
StringBuilder sql = new StringBuilder();
|
sql.append("SELECT d.DEPLOYMENT_, d.OBJNAME_, d.KEY_, d.STRINGVAL_, d.LONGVAL_");
|
sql.append(" FROM JBPM4_DEPLOYPROP d left join PLPROCESSTEMPLATE p on d.DEPLOYMENT_=p.PLJBPMDEPLOYMENTID");
|
sql.append(" where d.KEY_ <> 'langid' and p.plstatus = '1' order by d.OBJNAME_, d.DEPLOYMENT_, d.KEY_");
|
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List list = createSQLQuery.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] obj = (Object[]) list.get(i);
|
String deployId = String.valueOf(obj[0]) + "";
|
String name = (String) obj[1];
|
String key = (String) obj[2];
|
String stringValue = (String) obj[3];
|
int longValue = ((BigDecimal) obj[4]) == null ? 1 : ((BigDecimal) obj[4]).intValue();
|
ProcessDefinitionInfo processDefinitionInfo = pds.get(deployId);
|
if (processDefinitionInfo == null) {
|
processDefinitionInfo = new ProcessDefinitionInfo();
|
processDefinitionInfo.jbpmDeploymentId = deployId;
|
processDefinitionInfo.name = name == null ? "" : name;
|
pds.put(deployId, processDefinitionInfo);
|
}
|
if (key.equals("pdid")) {
|
processDefinitionInfo.id = stringValue == null ? "" : stringValue;
|
} else if (key.equals("pdkey")) {
|
processDefinitionInfo.key = stringValue == null ? "" : stringValue;
|
} else if (key.equals("pdversion")) {
|
processDefinitionInfo.version = longValue;
|
}
|
|
if (!deployIds.contains(deployId)) {
|
deployIds.add(deployId);
|
}
|
}
|
} catch (Exception ex) {
|
ex.printStackTrace();
|
} finally {
|
|
}
|
|
List<ProcessDefinitionInfo> result = new ArrayList<ProcessDefinitionInfo>();
|
for (String deployId : deployIds) {
|
result.add(pds.get(deployId));
|
}
|
return result;
|
}
|
|
private List<ProcessDefinitionInfo> getProcessDefinitionInfoByCustomFilter(LinkedHashMap<String, String> values) {
|
Map<String, ProcessDefinitionInfo> pds = new HashMap<String, ProcessDefinitionInfo>();
|
List<String> deployIds = new LinkedList<String>();
|
StringBuilder sql = new StringBuilder();
|
sql.append("SELECT d.DEPLOYMENT_, d.OBJNAME_, d.KEY_, d.STRINGVAL_, d.LONGVAL_,plstatus");
|
sql.append(" FROM JBPM4_DEPLOYPROP d left join PLPROCESSTEMPLATE p on d.DEPLOYMENT_=p.PLJBPMDEPLOYMENTID");
|
// new
|
sql.append(" where d.KEY_ <> 'langid' ");
|
Iterator<String> its = values.keySet().iterator();
|
while (its.hasNext()) {
|
String key = its.next();
|
if (!(values.get(key).equals(""))) { // add by liujw
|
sql.append(" and p." + key + "=? ");
|
}
|
}
|
sql.append(" order by d.objname_ asc,d.longval_ asc");
|
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
// new
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
its = values.keySet().iterator();
|
int index = 0;
|
while (its.hasNext()) {
|
String key = its.next();
|
String value = values.get(key);
|
if (!value.equals("")) {// add by liujw
|
createSQLQuery.setString(index++, value);
|
}
|
}
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List<?> list = createSQLQuery.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] obj = (Object[]) list.get(i);
|
String deployId = String.valueOf(obj[0]) + "";
|
String name = (String) obj[1];
|
String key = (String) obj[2];
|
String stringValue = (String) obj[3];
|
int longValue = ((BigDecimal) obj[4]) == null ? 1 : ((BigDecimal) obj[4]).intValue();
|
String status = String.valueOf(obj[5]) + "";
|
ProcessDefinitionInfo processDefinitionInfo = pds.get(deployId);
|
if (processDefinitionInfo == null) {
|
processDefinitionInfo = new ProcessDefinitionInfo();
|
processDefinitionInfo.jbpmDeploymentId = deployId;
|
processDefinitionInfo.name = name == null ? "" : name;
|
processDefinitionInfo.status = status;
|
pds.put(deployId, processDefinitionInfo);
|
}
|
if (key.equals("pdid")) {
|
processDefinitionInfo.id = stringValue == null ? "" : stringValue;
|
} else if (key.equals("pdkey")) {
|
processDefinitionInfo.key = stringValue == null ? "" : stringValue;
|
} else if (key.equals("pdversion")) {
|
processDefinitionInfo.version = longValue;
|
}
|
|
if (!deployIds.contains(deployId)) {
|
deployIds.add(deployId);
|
}
|
}
|
} catch (Exception ex) {
|
ex.printStackTrace();
|
} finally {
|
|
}
|
|
List<ProcessDefinitionInfo> result = new ArrayList<ProcessDefinitionInfo>();
|
for (String deployId : deployIds) {
|
result.add(pds.get(deployId));
|
}
|
return result;
|
}
|
|
private List<ProcessDefinitionInfo> getProcessDefinitionInfoByCustomFilterByPage(
|
LinkedHashMap<String, String> values, String processCategoryId, int pageSize, int pageIndex) {
|
Map<String, ProcessDefinitionInfo> pds = new HashMap<String, ProcessDefinitionInfo>();
|
List<String> deployIds = new ArrayList<String>();
|
StringBuilder sql = new StringBuilder();
|
if (pageIndex <= 0) {
|
pageIndex = 1;
|
}
|
// int startRownum = (pageIndex - 1) * pageSize*3 + 1;
|
// /**单个流程在数据表里存储了三条数据,分页是需要*3才能正确查询到对应的流程模板**/
|
// int endRownum = pageIndex * pageSize*3;
|
int startRownum = (pageIndex - 1) * pageSize + 1;
|
/** 单个流程在数据表里存储了三条数据,分页是需要*3才能正确查询到对应的流程模板 **/
|
int endRownum = pageIndex * pageSize;
|
|
sql.append("select * from ( SELECT A.*,ROWNUM RN FROM(");
|
sql.append("SELECT d.DEPLOYMENT_, d.OBJNAME_, d.KEY_, d.STRINGVAL_, d.LONGVAL_,plstatus");
|
sql.append(" FROM JBPM4_DEPLOYPROP d left join PLPROCESSTEMPLATE p on d.DEPLOYMENT_=p.PLJBPMDEPLOYMENTID");
|
// new
|
// sql.append(" where d.KEY_ <> 'langid' ");
|
sql.append(" where d.KEY_ = 'pdid' ");
|
Iterator<String> its = values.keySet().iterator();
|
while (its.hasNext()) {
|
String key = its.next();
|
if (!(values.get(key).equals(""))) {
|
sql.append(" and d." + key + " like ? ");
|
}
|
}
|
if (!processCategoryId.equals("")) {
|
sql.append(" and p.PLCATEGORYOID" + " = '" + processCategoryId + "' ");
|
}
|
sql.append(" order by d.objname_ asc, d.longval_ asc ) A ) WHERE RN <= '" + String.valueOf(endRownum)
|
+ "' AND RN >= '" + String.valueOf(startRownum) + "'");
|
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
|
its = values.keySet().iterator();
|
int index = 0;
|
while (its.hasNext()) {
|
String key = its.next();
|
String value = values.get(key);
|
|
if (!value.equals("")) {//
|
createSQLQuery.setString(index++, "%" + value + "%");
|
}
|
}
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List list = createSQLQuery.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] obj = (Object[]) list.get(i);
|
String deployId = String.valueOf(obj[0]) + "";
|
String name = (String) obj[1];
|
String key = (String) obj[2];
|
String stringValue = (String) obj[3];
|
int longValue = ((BigDecimal) obj[4]) == null ? 1 : ((BigDecimal) obj[4]).intValue();
|
String status = String.valueOf(obj[5]) + "";
|
ProcessDefinitionInfo processDefinitionInfo = pds.get(deployId);
|
if (processDefinitionInfo == null) {
|
processDefinitionInfo = new ProcessDefinitionInfo();
|
processDefinitionInfo.jbpmDeploymentId = deployId;
|
processDefinitionInfo.name = name == null ? "" : name;
|
processDefinitionInfo.status = status == null ? "" : status;
|
pds.put(deployId, processDefinitionInfo);
|
}
|
if (key.equals("pdid")) {
|
processDefinitionInfo.id = stringValue == null ? "" : stringValue;
|
// } else if (key.equals("pdkey")) {
|
processDefinitionInfo.key = name == null ? "" : name;
|
// } else if (key.equals("pdversion")) {
|
int substring = Integer
|
.parseInt(stringValue.substring(stringValue.lastIndexOf("-") + 1, stringValue.length()));
|
processDefinitionInfo.version = substring;// longValue;
|
// processDefinitionInfo.hide = hide;
|
}
|
|
if (!deployIds.contains(deployId)) {
|
deployIds.add(deployId);
|
}
|
}
|
} catch (Exception ex) {
|
ex.printStackTrace();
|
} finally {
|
|
}
|
|
List<ProcessDefinitionInfo> result = new LinkedList<ProcessDefinitionInfo>();
|
for (String deployId : deployIds) {
|
result.add(pds.get(deployId));
|
}
|
return result;
|
}
|
|
public List<ProcessDefinition> getProcessDefinition(final String rmTemplateId, final String processType) {
|
RMTemplateProcess object = (RMTemplateProcess) new HibernateTemplate().run(new HibernateCallback() {
|
public Object execute() throws HibernateException {
|
RMTemplateProcessDaoImpl impl = new RMTemplateProcessDaoImpl();
|
String hql = "from RMTemplateProcess t where t.rmTemplateId = ? and t.processType = ?";
|
return impl.findEntity(hql, new Object[] { rmTemplateId, processType });
|
}
|
});
|
if (object != null) {
|
String jbpmDeploymentId = object.getJbpmDeploymentId();
|
|
RepositoryService repositoryService = JbpmEngine.getProcessEngine().getRepositoryService();
|
List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery()
|
.deploymentId(jbpmDeploymentId).list();
|
return list;
|
} else {
|
return new ArrayList<ProcessDefinition>();
|
}
|
}
|
|
public void saveRMTemplateProcess(final String rmTemplateId, final String[] processTypes,
|
final String[] jbpmDeploymentIds) {
|
new HibernateTemplate().run(new HibernateCallback() {
|
public Object execute() throws HibernateException {
|
RMTemplateProcessDaoImpl impl = new RMTemplateProcessDaoImpl();
|
for (int i = 0; i < processTypes.length; i++) {
|
// 先删除原来的配置
|
String hql = "from RMTemplateProcess t where t.rmTemplateId = ? and t.processType = ?";
|
RMTemplateProcess t = impl.findEntity(hql, new Object[] { rmTemplateId, processTypes[i] });
|
if (t != null) {
|
impl.delete(t);
|
}
|
// 添加新的
|
if (!jbpmDeploymentIds[i].equals("")) {
|
RMTemplateProcess object = new RMTemplateProcess();
|
String id = ObjectUtility.getNewObjectID36();
|
object.setId(id);
|
object.setRmTemplateId(rmTemplateId);
|
object.setProcessType(processTypes[i]);
|
object.setJbpmDeploymentId(jbpmDeploymentIds[i]);
|
impl.saveOrUpdate(object);
|
}
|
}
|
return null;
|
}
|
});
|
}
|
|
public boolean deleteRMTemplateProcess(final String rmTemplateId) {
|
return (Boolean) new HibernateTemplate().run(new HibernateCallback() {
|
public Object execute() throws HibernateException {
|
RMTemplateProcessDaoImpl impl = new RMTemplateProcessDaoImpl();
|
impl.deleteByKey(rmTemplateId);
|
return true;
|
}
|
});
|
}
|
|
public byte[] getProcessResource(String jbpmDeploymentId, String resourceType) throws Exception {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
RepositoryService repositoryService = processEngine.getRepositoryService();
|
Set<String> resourceNames = repositoryService.getResourceNames(jbpmDeploymentId);
|
for (String resourceName : resourceNames) {
|
if (resourceName.endsWith(resourceType)) {
|
InputStream is = repositoryService.getResourceAsStream(jbpmDeploymentId, resourceName);
|
byte[] result = InputStreamToByte(is);
|
return result;
|
}
|
}
|
return new byte[0];
|
}
|
|
/**
|
* 获取下一步任务候选人,如果只有用户的任务,用此方法
|
*
|
* @param jbpmDeploymentId
|
* @param taskName
|
* @param outcome
|
* @return
|
* @throws Exception
|
*/
|
public String[] getNextCandidates(String jbpmDeploymentId, String taskName, String outcome) throws Exception {
|
Document doc = WorkFlowCahe.getTemplateMap().get(jbpmDeploymentId);
|
if (doc != null) {
|
|
Element root = doc.getRootElement();
|
if ("".equals(taskName)) {
|
taskName = getTaskName(root);
|
}
|
|
taskName = getNextTaskName(jbpmDeploymentId, root, taskName, outcome);
|
if (taskName.length() > 0) {
|
List<String> result = getUsers(root, taskName);
|
ServerWithLog4j.logger.debug("result:" + result);
|
if (result != null) {
|
return result.toArray(new String[0]);
|
}
|
}
|
}
|
return new String[0];
|
}
|
|
/**
|
* 装载流程模板和流程部署的
|
*
|
* @param jbpmDeploymentId
|
*/
|
public void loadWorkFlowTemplate(String jbpmDeploymentId) {
|
byte[] processXml;
|
try {
|
processXml = getProcessResource(jbpmDeploymentId, ".xml");
|
InputStream in = new ByteArrayInputStream(processXml);
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
|
|
SAXReader saxr = new SAXReader();
|
Document doc = saxr.read(reader);
|
WorkFlowCahe.setMap(jbpmDeploymentId, doc);
|
ServerWithLog4j.logger.debug("jbpmDeploymentId=" + jbpmDeploymentId + ":Doc=" + doc);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
}
|
|
/**
|
* 获取下一步任务候选人,如果包含用户,组,角色的任务,用此方法
|
*
|
* @param jbpmDeploymentId
|
* @param taskName
|
* @param outcome
|
* @return
|
* @throws Exception
|
*/
|
public String getNextCandidatesAndRoleAndDept(String jbpmDeploymentId, String taskName, String outcome)
|
throws Exception {
|
byte[] processXml = getProcessResource(jbpmDeploymentId, ".xml");
|
InputStream in = new ByteArrayInputStream(processXml);
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
|
|
SAXReader saxr = new SAXReader();
|
Document doc = saxr.read(reader);
|
Element root = doc.getRootElement();
|
if ("".equals(taskName)) {
|
taskName = getTaskName(root);
|
}
|
|
taskName = getNextTaskName(jbpmDeploymentId, root, taskName, outcome);
|
if (taskName.length() > 0) {
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
String cellName = element.attributeValue(FlowConstants.XMLNAME);
|
if (taskName.equals(cellName)) {
|
// 只查询出多个候选人的用户列表
|
Attribute usersAttribute = element.attribute(FlowConstants.XMLUSERS);
|
if (usersAttribute != null) {
|
String userName = usersAttribute.getValue();
|
return userName;
|
}
|
Attribute usersAttribute1 = element.attribute(FlowConstants.XMLUSER);
|
if (usersAttribute1 != null) {
|
String userName = usersAttribute1.getValue();
|
return userName;
|
}
|
}
|
}
|
}
|
return null;
|
}
|
|
/**
|
* 如果只有用户的任务,用此方法 获取当前任务处理人
|
*
|
* @param jbpmDeploymentId
|
* @param taskName
|
* @param outcome
|
* @return
|
* @throws Exception
|
*/
|
public String[] getCurCandidates(String jbpmDeploymentId, String taskName, String outcome, String executionId)
|
throws Exception {
|
if (executionId != null && !"".equals(executionId)) {
|
String superExcutionId = this.getParentExcutionId(executionId);
|
if (superExcutionId.equals(executionId)) {
|
// 父流程执行到子流程
|
String subProessId = getTaskSubProcessID(jbpmDeploymentId, taskName);
|
// 子流程不存在
|
if (subProessId == null || subProessId.equals("")) {
|
Document doc = WorkFlowCahe.getTemplateMap().get(jbpmDeploymentId);
|
if (doc != null) {
|
Element root = doc.getRootElement();
|
List<String> result = getUsers(root, taskName);
|
ServerWithLog4j.logger.debug("result:" + result);
|
if (result != null) {
|
return result.toArray(new String[0]);
|
}
|
}
|
} else {// 存在子流程
|
String subjbpmDeploymentId = String.valueOf(this.getDeploymentID(subProessId));
|
String subTaskName = this.getFirstProcessTask(subjbpmDeploymentId).getTaskName();
|
Document doc = WorkFlowCahe.getTemplateMap().get(subjbpmDeploymentId);
|
if (doc != null) {
|
Element root = doc.getRootElement();
|
List<String> result = getUsers(root, subTaskName);
|
ServerWithLog4j.logger.debug("result:" + result);
|
if (result != null) {
|
return result.toArray(new String[0]);
|
}
|
}
|
}
|
} else {
|
// 子流程执行到父流程
|
if ("结束".equals(taskName)) {
|
String subProcessId = this.getProcessDefinitionByDeployId(jbpmDeploymentId).id;
|
String superDeployId = this.getDeploymentIdByExecutionId(superExcutionId);
|
String superCurName = getNextSuperTaskBySubProId(superDeployId, subProcessId);
|
String superNextName[] = getNextTaskNames(superDeployId, superCurName, "");
|
if (superNextName != null && superNextName.length > 0) {
|
Document doc = WorkFlowCahe.getTemplateMap().get(superDeployId);
|
if (doc != null) {
|
Element root = doc.getRootElement();
|
List<String> result = getUsers(root, superNextName[0]);
|
ServerWithLog4j.logger.debug("result:" + result);
|
if (result != null) {
|
return result.toArray(new String[0]);
|
}
|
}
|
} else {
|
return new String[0];
|
}
|
} else {
|
Document doc = WorkFlowCahe.getTemplateMap().get(jbpmDeploymentId);
|
if (doc == null) {
|
loadWorkFlowTemplate(jbpmDeploymentId);
|
doc = WorkFlowCahe.getTemplateMap().get(jbpmDeploymentId);
|
}
|
if (doc != null) {
|
Element root = doc.getRootElement();
|
List<String> result = getUsers(root, taskName);
|
ServerWithLog4j.logger.debug("result:" + result);
|
if (result != null) {
|
return result.toArray(new String[0]);
|
}
|
}
|
|
}
|
}
|
} else {
|
Document doc = WorkFlowCahe.getTemplateMap().get(jbpmDeploymentId);
|
if (doc == null) {
|
loadWorkFlowTemplate(jbpmDeploymentId);
|
doc = WorkFlowCahe.getTemplateMap().get(jbpmDeploymentId);
|
}
|
if (doc != null) {
|
Element root = doc.getRootElement();
|
List<String> result = getUsers(root, taskName);
|
ServerWithLog4j.logger.debug("result:" + result);
|
if (result != null) {
|
return result.toArray(new String[0]);
|
}
|
}
|
}
|
|
return new String[0];
|
}
|
|
/**
|
* 如果包含组、角色、用户三类的候选人用此方法。
|
*
|
* @param jbpmDeploymentId
|
* @param taskName
|
* @param outcome
|
* @return
|
* @throws Exception
|
*/
|
public String[] getAllCandidatesForTask(String jbpmDeploymentId, String taskName, String outcome) throws Exception {
|
byte[] processXml = getProcessResource(jbpmDeploymentId, ".xml");
|
InputStream in = new ByteArrayInputStream(processXml);
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
|
|
SAXReader saxr = new SAXReader();
|
Document doc = saxr.read(reader);
|
Element root = doc.getRootElement();
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
String cellName = element.attributeValue(FlowConstants.XMLNAME);
|
if (taskName.equals(cellName)) {
|
// 只查询出多个候选人的用户列表
|
Attribute usersAttribute = element.attribute(FlowConstants.XMLUSERS);
|
if (usersAttribute != null) {
|
String userName = usersAttribute.getValue();
|
String[] splits = userName.split(";");
|
return splits;
|
}
|
Attribute usersAttribute1 = element.attribute(FlowConstants.XMLUSER);
|
if (usersAttribute1 != null) {
|
String userName = usersAttribute1.getValue();
|
String[] splits = userName.split(";");
|
return splits;
|
}
|
}
|
}
|
return new String[0];
|
}
|
|
/**
|
* 获取任务名称
|
*
|
* @param root
|
* @return
|
*/
|
private String getTaskName(Element root) {
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
String cellType = element.getName();
|
if (FlowConstants.XMLSTART.equals(cellType)) {
|
Element transitionElement = element.element(FlowConstants.TRANSITION);
|
return transitionElement.attributeValue(FlowConstants.XMLTARGET);
|
}
|
}
|
return "";
|
}
|
|
/**
|
* 获取所有任务名称
|
*
|
* @param jbpmDeploymentId
|
* @return
|
* @throws Exception
|
*/
|
public String[] getAllTaskNames(String jbpmDeploymentId) throws Exception {
|
// Document doc = WorkFlowCahe.getTemplateMap().get(jbpmDeploymentId);
|
byte[] processXml = getProcessResource(jbpmDeploymentId, ".xml");
|
InputStream in = new ByteArrayInputStream(processXml);
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
|
|
SAXReader saxr = new SAXReader();
|
Document doc = saxr.read(reader);
|
Element root = doc.getRootElement();
|
ArrayList<String> taskNameList = new ArrayList<String>();
|
ArrayList<String> stateList = new ArrayList<String>();
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
String cellType = element.getName();
|
if ("start".equals(cellType)) {
|
List<Element> joinElems = new ArrayList<Element>();
|
List<Element> cElements = new ArrayList<Element>();
|
getTaskNamesFromTransition(taskNameList, element, root, joinElems);
|
cElements.addAll(joinElems);
|
if (joinElems != null) {
|
for (Element joinElem : cElements) {
|
joinElems.remove(joinElem);
|
getTaskNamesFromTransition(taskNameList, joinElem, root, joinElems);
|
}
|
}
|
break;
|
|
}
|
|
}
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
String cellType = element.getName();
|
Attribute nameAttr = element.attribute("name");
|
if (nameAttr == null) {
|
continue;
|
}
|
String eleName = nameAttr.getValue().trim();
|
if (!"task".equals(cellType)) {
|
stateList.add(eleName);
|
}
|
}
|
for (int j = 0; j < stateList.size(); j++) {
|
for (int i = 0; i < taskNameList.size(); i++) {
|
if (taskNameList.get(i).equals(stateList.get(j))) {
|
taskNameList.remove(taskNameList.get(i));
|
}
|
}
|
}
|
return (String[]) taskNameList.toArray(new String[taskNameList.size()]);
|
}
|
|
private Element getElemByName(Element root, String taskName, boolean subFlag) {
|
String[] subTask = new String[0];
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
Attribute nameAttr = element.attribute("name");
|
if (nameAttr == null) {
|
continue;
|
}
|
String subProcess = element.attributeValue("sub-process-key");
|
// 如果有子流程节点,通过遍历得到deployId
|
if (subProcess != null && subFlag) {
|
String subDeplId = getDeployIdByProcessDefintionId(subProcess);
|
try {
|
subTask = getAllTaskNames(subDeplId);
|
} catch (Exception e) {
|
// TODO Auto-generated catch block
|
e.printStackTrace();
|
}
|
// 转换任务节点格式为:任务(子流程名称:deployId)
|
if (subTask != null && subTask.length > 0) {
|
String[] newTask = subTask;
|
for (int i = 0; i < subTask.length; i++) {
|
newTask[i] = subTask[i] + "(" + subProcess + ":" + subDeplId + ")";
|
}
|
subTask = newTask;
|
}
|
ServerWithLog4j.logger.debug("subDeplId===" + subDeplId);
|
}
|
String eleName = nameAttr.getValue().trim();
|
if (eleName.equals(taskName)) {
|
if (subTask.length > 0) {
|
String text = "";
|
for (int i = 0; i < subTask.length; i++) {
|
text += subTask[i] + ";";
|
}
|
element.setText(text);
|
}
|
return element;
|
}
|
}
|
return null;
|
}
|
|
// private List<String> nodeList = new ArrayList<String>();
|
private String[] nodes = { FlowConstants.XMLEND, FlowConstants.XMLFORK, FlowConstants.XMLJOIN,
|
FlowConstants.DECISION };
|
// private HashMap<String, String> datamap = new HashMap<String, String>();
|
private Map<String, String> linkDataMap = new HashMap<String, String>();
|
|
private void getTaskNamesFromTransition(ArrayList<String> taskNameList, Element element, Element root,
|
List<Element> joinElem) throws Exception {
|
ServerWithLog4j.logger.debug("当前节点================= " + element.attributeValue("name"));
|
for (Iterator<?> elementIterator = element.elementIterator("transition"); elementIterator.hasNext();) {
|
Element transitionEl = (Element) elementIterator.next();
|
Attribute transitionAtt = transitionEl.attribute("to");
|
String taskName = transitionAtt.getValue().trim();
|
String subProcess = element.attributeValue("sub-process-key");
|
boolean subFlag = false;
|
if (subProcess != null && !"".equals(subProcess)) {
|
subFlag = true;
|
}
|
ServerWithLog4j.logger.debug("下一任务节点 = " + taskName);
|
Element taskElem = getElemByName(root, taskName, subFlag);
|
if (taskElem == null) {
|
throw new Exception("流程模板中节点-" + taskName + "-不存在!");
|
}
|
if (taskElem != null && FlowConstants.XMLFORK.equals(taskElem.getName())) {
|
getTaskNamesFromTransition(taskNameList, taskElem, root, joinElem);
|
/*
|
* Iterator children = taskElem.elementIterator(); while (children.hasNext()) {
|
* Element childElem = (Element) children.next(); String childType =
|
* childElem.getName(); if (childType.equals(FlowConstants.TRANSITION)) {
|
* Attribute attribute = childElem .attribute(FlowConstants.XMLTARGET); String
|
* attrValue = attribute.getValue(); Element toElem = getElemByName(root,
|
* attrValue); getTaskNamesFromTransition(taskNameList, taskElem, root,
|
* joinElem); } }
|
*/
|
}
|
if (taskElem != null && FlowConstants.XMLJOIN.equals(taskElem.getName())) {
|
if (!joinElem.contains(taskElem)) {
|
joinElem.add(taskElem);
|
}
|
if (Arrays.asList(nodes).contains(element.getName())) {
|
continue;
|
} else {
|
return;
|
}
|
}
|
if (taskElem != null && FlowConstants.DECISION.equals(taskElem.getName())) {
|
getTaskNamesFromTransition(taskNameList, taskElem, root, joinElem);
|
}
|
if (!taskNameList.contains(taskName) && !Arrays.asList(nodes).contains(taskElem.getName())) {
|
if (subFlag) {
|
String str = taskElem.getText();
|
String[] subPro = str.split(";");
|
for (int i = 0; i < subPro.length; i++) {
|
taskNameList.add(subPro[i]);
|
}
|
}
|
taskNameList.add(taskName);
|
getTaskNamesFromTransition(taskNameList, taskElem, root, joinElem);
|
}
|
}
|
}
|
|
private String getNameByTrainsition(String transitionVal, Element root) {
|
String taskName = "";
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
String cellType = element.getName();
|
|
if ("task".equals(cellType) || "end".equals(cellType) || FlowConstants.DECISION.equals(cellType)
|
|| "join".equals(cellType) || "fork".equals(cellType)) {
|
Attribute attribute = element.attribute("name");
|
String cellName = attribute.getValue();
|
if (transitionVal.equals(cellName)) {
|
taskName = cellName;
|
}
|
}
|
}
|
return taskName;
|
}
|
|
/**
|
* 通过任务名称获得该任务的路由
|
*
|
* @param jbpmDeploymentId
|
* @param taskName
|
* @return
|
* @throws Exception
|
*/
|
public String[] getOutComesByTaskName(String jbpmDeploymentId, String taskName) throws Exception {
|
ArrayList<String> taskNameList = new ArrayList<String>();
|
byte processXml[] = getProcessResource(jbpmDeploymentId, ".xml");
|
InputStream in = new ByteArrayInputStream(processXml);
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
|
SAXReader saxr = new SAXReader();
|
Document doc = saxr.read(reader);
|
Element root = doc.getRootElement();
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
String cellType = element.getName();
|
|
if ("start".equals(cellType) || "task".equals(cellType) || "end".equals(cellType)
|
|| FlowConstants.DECISION.equals(cellType) || "join".equals(cellType) || "fork".equals(cellType)) {
|
Attribute attribute = element.attribute("name");
|
String taskNameValue = attribute.getValue();
|
if (taskNameValue.equals(taskName)) {
|
for (Iterator<?> elementIterator = element.elementIterator("transition"); elementIterator
|
.hasNext();) {
|
Element transitionEl = (Element) elementIterator.next();
|
Attribute transitionAtt = transitionEl.attribute("name");
|
String transitionVal = transitionAtt.getValue();
|
taskNameList.add(transitionVal);
|
}
|
}
|
}
|
}
|
return (String[]) taskNameList.toArray(new String[taskNameList.size()]);
|
}
|
|
/**
|
* 获取任务对应的自定义Url路径
|
*
|
* @param jbpmDeploymentId
|
* @return
|
* @throws Exception
|
*/
|
public String getUrlPath(String jbpmDeploymentId, String taskName) throws Exception {
|
byte[] processXml = getProcessResource(jbpmDeploymentId, ".xml");
|
InputStream in = new ByteArrayInputStream(processXml);
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
|
|
SAXReader saxr = new SAXReader();
|
Document doc = saxr.read(reader);
|
Element root = doc.getRootElement();
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
String cellType = element.getName();
|
if (FlowConstants.XMLTASK.equals(cellType)) {
|
Attribute attribute = element.attribute(FlowConstants.XMLNAME);
|
String name = attribute.getValue();
|
if (name.equals(taskName)) {
|
Attribute urlPathAttr = element.attribute(FlowConstants.URL_PATH);
|
if (urlPathAttr != null) {
|
return urlPathAttr.getValue() == null ? "" : urlPathAttr.getValue();
|
}
|
}
|
}
|
}
|
return "";
|
}
|
|
/**
|
* 获取路由对应的自定义Url路径
|
*
|
* @param jbpmDeploymentId
|
* @return
|
* @throws Exception
|
*/
|
public String[] getTrainsitionUrlPath(String jbpmDeploymentId, String taskName, String trainsitionName)
|
throws Exception {
|
byte[] processXml = getProcessResource(jbpmDeploymentId, ".xml");
|
InputStream in = new ByteArrayInputStream(processXml);
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
|
|
SAXReader saxr = new SAXReader();
|
Document doc = saxr.read(reader);
|
Element root = doc.getRootElement();
|
List<String> list = new ArrayList<String>();
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
String cellType = element.getName();
|
if (FlowConstants.XMLTASK.equals(cellType)) {
|
Attribute attribute = element.attribute(FlowConstants.XMLNAME);
|
String name = attribute.getValue();
|
if (name.equals(taskName)) {
|
for (Iterator<?> trainsitionElIt = element.elementIterator(); trainsitionElIt.hasNext();) {
|
Element next = (Element) trainsitionElIt.next();
|
Attribute trainsitionNameAttr = next.attribute(FlowConstants.XMLNAME);
|
String trainsitionNameAttrVal = trainsitionNameAttr == null ? ""
|
: trainsitionNameAttr.getValue();
|
if (trainsitionName.equals(trainsitionNameAttrVal)) {
|
Attribute urlPathAttr = next.attribute(FlowConstants.URL_PATH);
|
if (urlPathAttr != null) {
|
list.add(urlPathAttr.getValue() == null ? "" : urlPathAttr.getValue());
|
}
|
}
|
}
|
}
|
}
|
}
|
return list.toArray(new String[] {});
|
}
|
|
/**
|
* 取得下个任务
|
*
|
* @param jbpmDeploymentId
|
* @param taskName
|
* @param outcome
|
* @return
|
* @throws Exception
|
*/
|
public String[] getNextTaskNames(String jbpmDeploymentId, String taskName, String outcome) throws Exception {
|
byte[] processXml = getProcessResource(jbpmDeploymentId, ".xml");
|
InputStream in = new ByteArrayInputStream(processXml);
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
|
|
SAXReader saxr = new SAXReader();
|
Document doc = saxr.read(reader);
|
Element root = doc.getRootElement();
|
if ("".equals(taskName)) {
|
taskName = getTaskName(root);
|
}
|
|
taskName = getNextTaskName(jbpmDeploymentId, root, taskName, outcome);
|
|
// 获取判断节点
|
String decisionName = getDecisionName(root, taskName, outcome);
|
if (decisionName != null && !"".equals(decisionName)) {
|
taskName = decisionName;
|
}
|
|
// 获取分支节点
|
String forkName = getForkName(root, taskName, outcome);
|
if (forkName != null && !"".equals(forkName)) {
|
taskName = forkName;
|
}
|
|
String joinName = this.getJoinName(root, taskName, outcome);
|
if (joinName != null && !"".equals(joinName)) {
|
taskName = joinName;
|
}
|
|
if (taskName.length() > 0) {
|
String[] result = taskName.split(",");
|
ServerWithLog4j.logger.debug("result:" + result);
|
if (result != null) {
|
return result;
|
}
|
}
|
return new String[0];
|
}
|
|
/**
|
* 取得下个任务
|
*
|
* @param jbpmDeploymentId
|
* @param taskName
|
* @param outcome
|
* @return
|
* @throws Exception
|
*/
|
public String[] getNextNamesFortask(String jbpmDeploymentId, String taskName, String outcome) throws Exception {
|
byte[] processXml = getProcessResource(jbpmDeploymentId, ".xml");
|
InputStream in = new ByteArrayInputStream(processXml);
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
|
|
SAXReader saxr = new SAXReader();
|
Document doc = saxr.read(reader);
|
Element root = doc.getRootElement();
|
if ("".equals(taskName)) {
|
taskName = getTaskName(root);
|
}
|
|
taskName = getNextTaskName(jbpmDeploymentId, root, taskName, outcome);
|
String decisionName = getDecisionName(root, taskName, outcome);
|
if (decisionName != null && !"".equals(decisionName)) {
|
taskName = decisionName;
|
}
|
if (taskName.length() > 0) {
|
String[] result = taskName.split(",");
|
ServerWithLog4j.logger.debug("result:" + result);
|
if (result != null) {
|
return result;
|
}
|
}
|
return new String[0];
|
}
|
|
/**
|
* 获取流向名称
|
*
|
* @param jbpmDeploymentId
|
* @param root
|
* @param taskName
|
* @return
|
*/
|
public String[] getTrainName(String jbpmDeploymentId, String taskName, String outcome) {
|
byte[] processXml;
|
try {
|
processXml = getProcessResource(jbpmDeploymentId, ".xml");
|
InputStream in = new ByteArrayInputStream(processXml);
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
|
|
SAXReader saxr = new SAXReader();
|
Document doc = saxr.read(reader);
|
Element root = doc.getRootElement();
|
|
List<Element> transitions = new ArrayList<Element>();
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
String cellType = element.getName();
|
String cellName = element.attributeValue(FlowConstants.XMLNAME);
|
if (FlowConstants.XMLTASK.equals(cellType) && cellName.equals(taskName)) {// 任务节点
|
for (Iterator<?> b = element.elementIterator(); b.hasNext();) {
|
Element next = (Element) b.next();
|
if (next.getName().equals(FlowConstants.TRANSITION)) {
|
transitions.add(next);
|
}
|
}
|
}
|
}
|
|
List<String> list = new ArrayList<String>();
|
for (Element element : transitions) {
|
|
String attributeValue = element.attributeValue(FlowConstants.XMLTARGET);
|
String name = element.attributeValue(FlowConstants.XMLNAME);
|
if (name.contains(outcome)) {
|
list.add(attributeValue);
|
}
|
}
|
String[] trainName = new String[list.size()];
|
for (int i = 0; i < list.size(); i++) {
|
trainName[i] = list.get(i);
|
}
|
return trainName;
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return new String[] {};
|
}
|
|
private String getNextTaskName(String jbpmDeploymentId, Element root, String taskName, String outcome) {
|
if (root == null) {
|
byte[] processXml;
|
try {
|
processXml = getProcessResource(jbpmDeploymentId, ".xml");
|
InputStream in = new ByteArrayInputStream(processXml);
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
|
|
SAXReader saxr = new SAXReader();
|
Document doc = saxr.read(reader);
|
root = doc.getRootElement();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
// 选获取taskName的所有transition
|
List<Element> transitions = new ArrayList<Element>();
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
String cellType = element.getName();
|
String cellName = element.attributeValue(FlowConstants.XMLNAME);
|
if (FlowConstants.XMLTASK.equals(cellType) && cellName.equals(taskName)) {// 任务节点
|
for (Iterator<?> b = element.elementIterator(); b.hasNext();) {
|
Element next = (Element) b.next();
|
if (next.getName().equals(FlowConstants.TRANSITION)) {
|
transitions.add(next);
|
break;
|
}
|
}
|
} else if (FlowConstants.SUBPROCESS.equals(cellType) && cellName.equals(taskName)) {// 子流程节点
|
for (Iterator<?> b = element.elementIterator(); b.hasNext();) {
|
Element next = (Element) b.next();
|
if (next.getName().equals(FlowConstants.TRANSITION)) {
|
transitions.add(next);
|
break;
|
}
|
}
|
}
|
}
|
|
if (transitions.size() == 1) {// 如果只有一个transition,那么不需要判断outcome
|
return transitions.get(0).attributeValue(FlowConstants.XMLTARGET);
|
}
|
|
for (Element element : transitions) {
|
|
String attributeValue = element.attributeValue(FlowConstants.XMLTARGET);
|
String name = element.attributeValue(FlowConstants.XMLNAME);
|
if (name.equals(outcome)) {
|
|
return attributeValue;
|
}
|
}
|
return "";
|
}
|
|
private String getSubProcessIdBySubTaskName(String jbpmDeploymentId, String taskName) {
|
Element root = null;
|
byte[] processXml;
|
try {
|
processXml = getProcessResource(jbpmDeploymentId, ".xml");
|
InputStream in = new ByteArrayInputStream(processXml);
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
|
|
SAXReader saxr = new SAXReader();
|
Document doc = saxr.read(reader);
|
root = doc.getRootElement();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
if (root == null) {
|
return "";
|
}
|
// 选获取taskName的所有transition
|
// List<Element> transitions = new ArrayList<Element>();
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
String cellType = element.getName();
|
String cellName = element.attributeValue(FlowConstants.XMLNAME);
|
if (FlowConstants.SUBPROCESS.equals(cellType) && cellName.equals(taskName)) {// 任务节点
|
return element.attributeValue(FlowConstants.SUBPROCESSID);
|
}
|
}
|
|
return "";
|
}
|
|
private String getForkTaskName(Element root, String taskName, String outcome) {
|
// 选获取taskName的所有transition
|
List<Element> transitions = new ArrayList<Element>();
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
String cellType = element.getName();
|
String cellName = element.attributeValue(FlowConstants.XMLNAME);
|
if (FlowConstants.XMLFORK.equals(cellType) && cellName.equals(taskName)) {// 任务节点
|
for (Iterator<?> b = element.elementIterator(); b.hasNext();) {
|
Element next = (Element) b.next();
|
if (next.getName().equals(FlowConstants.TRANSITION)) {
|
transitions.add(next);
|
}
|
}
|
}
|
}
|
|
if (transitions.size() == 1) {// 如果只有一个transition,那么不需要判断outcome
|
return transitions.get(0).attributeValue(FlowConstants.XMLTARGET);
|
}
|
String taskNames = "";
|
// int i = 0;
|
for (Element element : transitions) {
|
|
String attributeValue = element.attributeValue(FlowConstants.XMLTARGET);
|
taskNames += "," + attributeValue;
|
}
|
if (taskNames.length() != 0) {
|
return taskNames.substring(1);
|
}
|
return "";
|
}
|
|
private String getDecisionName(Element root, String taskName, String outcome) {
|
// 选获取taskName的所有transition
|
List<Element> transitions = new ArrayList<Element>();
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
String cellType = element.getName();
|
String cellName = element.attributeValue(FlowConstants.XMLNAME);
|
if (FlowConstants.DECISION.equals(cellType) && cellName.equals(taskName)) {// 任务节点
|
for (Iterator<?> b = element.elementIterator(); b.hasNext();) {
|
Element next = (Element) b.next();
|
if (next.getName().equals(FlowConstants.TRANSITION)) {
|
transitions.add(next);
|
}
|
}
|
}
|
}
|
|
if (transitions.size() == 1) {// 如果只有一个transition,那么不需要判断outcome
|
return transitions.get(0).attributeValue(FlowConstants.XMLTARGET);
|
}
|
String taskNames = "";
|
// int i = 0;
|
for (Element element : transitions) {
|
|
String attributeValue = element.attributeValue(FlowConstants.XMLTARGET);
|
taskNames += "," + attributeValue;
|
}
|
if (taskNames.length() != 0) {
|
return taskNames.substring(1);
|
}
|
return "";
|
}
|
|
private String getForkName(Element root, String taskName, String outcome) {
|
// 选获取taskName的所有transition
|
List<Element> transitions = new ArrayList<Element>();
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
String cellType = element.getName();
|
String cellName = element.attributeValue(FlowConstants.XMLNAME);
|
if (FlowConstants.XMLFORK.equals(cellType) && cellName.equals(taskName)) {// 任务节点
|
for (Iterator<?> b = element.elementIterator(); b.hasNext();) {
|
Element next = (Element) b.next();
|
if (next.getName().equals(FlowConstants.TRANSITION)) {
|
transitions.add(next);
|
}
|
}
|
}
|
}
|
|
if (transitions.size() == 1) {// 如果只有一个transition,那么不需要判断outcome
|
return transitions.get(0).attributeValue(FlowConstants.XMLTARGET);
|
}
|
String taskNames = "";
|
// int i = 0;
|
for (Element element : transitions) {
|
|
String attributeValue = element.attributeValue(FlowConstants.XMLTARGET);
|
taskNames += "," + attributeValue;
|
}
|
if (taskNames.length() != 0) {
|
return taskNames.substring(1);
|
}
|
return "";
|
}
|
|
private String getJoinName(Element root, String taskName, String outcome) {
|
// 选获取taskName的所有transition
|
List<Element> transitions = new ArrayList<Element>();
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
String cellType = element.getName();
|
String cellName = element.attributeValue(FlowConstants.XMLNAME);
|
if (FlowConstants.XMLJOIN.equals(cellType) && cellName.equals(taskName)) {// 任务节点
|
for (Iterator<?> b = element.elementIterator(); b.hasNext();) {
|
Element next = (Element) b.next();
|
if (next.getName().equals(FlowConstants.TRANSITION)) {
|
transitions.add(next);
|
}
|
}
|
}
|
}
|
|
if (transitions.size() == 1) {// 如果只有一个transition,那么不需要判断outcome
|
return transitions.get(0).attributeValue(FlowConstants.XMLTARGET);
|
}
|
String taskNames = "";
|
// int i = 0;
|
for (Element element : transitions) {
|
|
String attributeValue = element.attributeValue(FlowConstants.XMLTARGET);
|
taskNames += "," + attributeValue;
|
}
|
if (taskNames.length() != 0) {
|
return taskNames.substring(1);
|
}
|
return "";
|
}
|
|
private List<String> getUsers(Element root, String nextTaskName) {
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
String cellName = element.attributeValue(FlowConstants.XMLNAME);
|
if (nextTaskName.equals(cellName)) {
|
// 自定义弹出窗口
|
String userDialogControl = WorkflowProperties.getStringProperty("workflow.UserDialog");
|
ServerWithLog4j.logger.debug("userDialogControl:" + userDialogControl);
|
if (userDialogControl != null && !"".equals(userDialogControl)) {
|
Element eventElement = element.element(FlowConstants.ASSIFNMENT_HANDLER);
|
if (eventElement != null) {
|
for (Iterator<?> b = eventElement.elementIterator(); b.hasNext();) {
|
Element fieldElement = (Element) b.next();// 多个field
|
// element
|
if (fieldElement.getName().equals(FlowConstants.EVENT_FIELD)) {
|
for (Iterator<?> c = fieldElement.elementIterator(); c.hasNext();) {
|
Element stringElement = (Element) c.next();
|
if (stringElement.getName().equals(FlowConstants.EVENT_STRING)) {
|
String userName = stringElement.attributeValue(FlowConstants.EVENT_VALUE);
|
ServerWithLog4j.logger.debug("userName:" + userName);
|
String[] splits = userName.split(",");
|
return Arrays.asList(splits);
|
}
|
}
|
}
|
}
|
} else {
|
// 只查询出多个候选人的用户列表
|
Attribute usersAttribute = element.attribute(FlowConstants.XMLUSERS);
|
if (usersAttribute != null) {
|
String userName = usersAttribute.getValue();
|
// String[] splits = userName.split(",");
|
return Arrays.asList(userName);
|
}
|
Attribute usersAttribute1 = element.attribute(FlowConstants.XMLUSER);
|
if (usersAttribute1 != null) {
|
String userName = usersAttribute1.getValue();
|
// String[] splits = userName.split(",");
|
return Arrays.asList(userName);
|
}
|
}
|
} else {
|
|
// 只查询出多个候选人的用户列表
|
Attribute usersAttribute = element.attribute(FlowConstants.XMLUSERS);
|
if (usersAttribute != null) {
|
String userName = usersAttribute.getValue();
|
// String[] splits = userName.split(",");
|
return Arrays.asList(userName);
|
}
|
Attribute usersAttribute1 = element.attribute(FlowConstants.XMLUSER);
|
if (usersAttribute1 != null) {
|
String userName = usersAttribute1.getValue();
|
// String[] splits = userName.split(",");
|
return Arrays.asList(userName);
|
}
|
}
|
}
|
}
|
return null;
|
}
|
|
/**
|
* 委托人
|
*
|
* @param jbpmDeploymentId
|
* @param taskName
|
* @param outcome
|
* @return
|
* @throws Exception
|
*/
|
public String[] getCurConstituents(String jbpmDeploymentId, String taskName, String outcome) throws Exception {
|
// byte[] processXml = getProcessResource(jbpmDeploymentId, ".xml");
|
// InputStream in = new ByteArrayInputStream(processXml);
|
// BufferedReader reader = new BufferedReader(new InputStreamReader(in,
|
// "utf-8"));
|
//
|
// SAXReader saxr = new SAXReader();
|
// Document doc = saxr.read(reader);
|
// Element root = doc.getRootElement();
|
|
Document doc = WorkFlowCahe.getTemplateMap().get(jbpmDeploymentId);
|
if (doc != null) {
|
Element root = doc.getRootElement();
|
List<String> result = getConstituents(root, taskName);
|
ServerWithLog4j.logger.debug("result:" + result);
|
if (result != null) {
|
return result.toArray(new String[0]);
|
}
|
}
|
return new String[0];
|
}
|
|
private List<String> getConstituents(Element root, String nextTaskName) {
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
String cellName = element.attributeValue(FlowConstants.XMLNAME);
|
if (nextTaskName.equals(cellName)) {
|
|
// 只查询出多个候选人的用户列表
|
Attribute usersAttribute = element.attribute(FlowConstants.XMLCONSTITUENT);
|
if (usersAttribute != null) {
|
String userName = usersAttribute.getValue();
|
String[] splits = userName.split(",");
|
return Arrays.asList(splits);
|
}
|
}
|
}
|
return null;
|
}
|
|
private static byte[] InputStreamToByte(InputStream is) throws IOException {
|
ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
|
int ch;
|
while ((ch = is.read()) != -1) {
|
bytestream.write(ch);
|
}
|
byte imgdata[] = bytestream.toByteArray();
|
bytestream.close();
|
return imgdata;
|
}
|
|
/**
|
* 获取任务下的阶段名称
|
*
|
* @param processDefinitionKey
|
* @returnf
|
* @throws VCIError
|
*/
|
public String getTaskPhaseName(String processDefinitionKey, String jbpmdeploymentid, FlowInstanceInfo var)
|
throws VCIError {
|
String phaseName = "";
|
// Connection cn = new HibernateTemplate().getSessionConnection();
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
Map<String, Object> variables = new HashMap<String, Object>();
|
variables.put("process_applicant", var.applicant);
|
// Object[] params = new Object[] {};
|
|
ProcessInstance processInstance = processEngine.getExecutionService()
|
.startProcessInstanceById(processDefinitionKey, variables);
|
String proccessInstanceId = processInstance.getId();
|
TaskService taskService = processEngine.getTaskService();
|
List<Task> list = taskService.createTaskQuery().assignee(getUserEntity().getUserName())
|
.processInstanceId(proccessInstanceId).list();
|
if (list.size() > 1) {
|
throw new VCIError("320216", new String[] {});
|
}
|
Task task = taskService.createTaskQuery().assignee(getUserEntity().getUserName())
|
.processInstanceId(proccessInstanceId).uniqueResult();
|
String activityName = "";
|
if (task == null) {
|
task = taskService.createTaskQuery().candidate(getUserEntity().getUserName())
|
.processInstanceId(proccessInstanceId).uniqueResult();
|
if (task == null) {
|
return "";
|
} else {
|
activityName = task.getActivityName();
|
}
|
} else {
|
activityName = task.getActivityName();
|
}
|
Session session = HibernateSessionFactory.getSession();
|
StringBuffer sb = new StringBuffer();
|
sb.append(" select b.plvalue ").append(" from PLPROCESSTASK a, PLPROCESSTASKPROPERTY b ")
|
.append(" where a.pltasktypeproperty = b.pltaskproperty ").append(" and a.pljbpmdeploymentid = '"
|
+ jbpmdeploymentid + "' and a.pltaskname = '" + activityName + "' ");
|
SQLQuery createSQLQuery = session.createSQLQuery(sb.toString());
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List<?> list2 = createSQLQuery.list();
|
if (list2 != null && list2.size() > 0) {
|
phaseName = String.valueOf(list2.get(0));
|
}
|
return phaseName + "," + activityName;
|
|
}
|
|
/**
|
* 启动流程
|
*
|
* @param processDefinitionKey 流程ID
|
* @param var 流程实例参数
|
* @param objId 流程数据对象ID
|
* @param userNames 从客户端指定的候选人
|
* @param outcome 路由名称
|
* @return
|
* @throws VCIError
|
*/
|
public boolean startProcessInstanceByKey(String processDefinitionKey, FlowInstanceInfo var, String[] objId,
|
String[] userNames, String outcome) throws VCIError {
|
try {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
Map<String, Object> variables = new HashMap<String, Object>();
|
variables.put("process_applicant", var.applicant);
|
variables.put("userName", getUserEntity().getUserName());
|
variables.put("userIP", getUserEntity().getIp());
|
variables.put("userModule", getUserEntity().getModule());
|
variables.put("flowInstanceInfo", var);
|
// 将传入的候选人注入到流程数据中,以便在初始事件中获取
|
variables.put("userNameNext", userNames);
|
// 流程数据ID列表
|
variables.put("objIds", objId);
|
// 标识流程流程是否启动完成,以便利用该值在判断第一个任务的初始事件是否需要执行相关事件处理
|
variables.put("ProcessStarted", "false");
|
List<String> participants = new ArrayList<String>();
|
for (String participant : userNames) {
|
participants.add(participant);
|
}
|
variables.put("participants", participants);
|
|
variables.put("globalParam", var.partList == null ? "" : var.partList);
|
|
ProcessInstance processInstance = processEngine.getExecutionService()
|
.startProcessInstanceById(processDefinitionKey, variables);
|
FlowInstance flowInstance = new FlowInstance();
|
String flowInstanceId = ObjectUtility.getNewObjectID36();
|
flowInstance.setId(flowInstanceId);
|
String proccessInstanceId = processInstance.getId();
|
TaskService taskService = processEngine.getTaskService();
|
boolean mulityPeo = false;
|
|
Object OUTCOME_SETTING_VALUE = processEngine.getExecutionService().getVariable(proccessInstanceId,
|
"OUTCOME_SETTING_VALUE");
|
if (OUTCOME_SETTING_VALUE != null) {
|
var.outcome = OUTCOME_SETTING_VALUE.toString();
|
}
|
// add by wangxl 2013.04.02 end
|
|
Task task = taskService.createTaskQuery().processInstanceId(proccessInstanceId).uniqueResult();
|
// flowInstance.setExecutionid(proccessInstanceId);
|
flowInstance.setExecutionid(task.getExecutionId());
|
flowInstance.setApplicant(var.applicant);
|
flowInstance.setCreator(var.creator);
|
flowInstance.setTemplatePuid(var.templatePuid);
|
flowInstance.setTemplateName(var.templateName);
|
flowInstance.setClsfOid(var.clsfOid);
|
flowInstance.setTableName(var.tableName);
|
flowInstance.setDesc(var.desc);
|
String processType = var.processType;
|
flowInstance.setProcessType(processType);
|
flowInstance.setUserEntity(userEntity);
|
|
// add by liud 2012-12-25
|
flowInstance.setTaskType(var.taskType);
|
|
FlowInstanceDaoImpl impl = new FlowInstanceDaoImpl();
|
impl.save(flowInstance);// 保存流程实例的变量
|
if (!"EBOM".equalsIgnoreCase(processType) && !"MBOM".equalsIgnoreCase(processType)) {
|
processType = "rm";
|
}
|
variables.put("processEngine", processEngine);
|
variables.put("processInstance", processInstance);
|
variables.put("flowInstance.TableName", flowInstance.getTableName());
|
|
// 插入流程数据对象表
|
int length = objId.length;
|
List<PLFlowObject> flowObjects = new ArrayList<PLFlowObject>();
|
for (int i = 0; i < length; i++) {
|
PLFlowObject flowObject = new PLFlowObject();
|
flowObject.setPloid(ObjectUtility.getNewObjectID36());
|
flowObject.setPlexecutionid(task.getExecutionId());
|
flowObject.setPlobjectid(objId[i]);
|
flowObject.setPlprocesstype(processType);
|
flowObjects.add(flowObject);
|
PLFlowObjectDaoImpl flowObjectDaoImpl = new PLFlowObjectDaoImpl();
|
flowObjectDaoImpl.save(flowObject);
|
}
|
|
variables.put("flowObjects", flowObjects);
|
taskService.setVariables(task.getId(), variables);
|
// 多候选人的情况下,获得当前的候选人
|
if (mulityPeo) {
|
taskService.takeTask(task.getId(), getUserEntity().getUserName());
|
}
|
if (outcome == null || "".equals(outcome)) {
|
outcome = var.outcome;
|
}
|
if ("".equals(outcome) || outcome == null) {
|
taskService.completeTask(task.getId());
|
} else {
|
taskService.completeTask(task.getId(), outcome);
|
}
|
|
// // 插入流程执行情况表
|
Plflowapproveopinion plflowapproveopinion = new Plflowapproveopinion();
|
String ploid = ObjectUtility.getNewObjectID36();
|
plflowapproveopinion.setPloid(ploid);
|
plflowapproveopinion.setPltaskid(task.getId());
|
plflowapproveopinion.setPlapproveopinion("提交任务");
|
plflowapproveopinion.setPlapprovenote(var.desc);
|
PlflowapproveopinionDaoImpl flowapproveopinionDaoImpl = new PlflowapproveopinionDaoImpl();
|
flowapproveopinionDaoImpl.save(plflowapproveopinion);
|
|
// 获取deploymentID
|
BigDecimal deploymentId = getDeploymentID(processDefinitionKey);
|
String strDeploymentId = String.valueOf(deploymentId);
|
// 如果是分支,则会取得多个任务
|
List<Task> nextTasks = taskService.createTaskQuery().processInstanceId(task.getExecutionId()).list();
|
if (nextTasks != null && nextTasks.size() > 1) {
|
|
} else {
|
|
Task nextTask = taskService.createTaskQuery().processInstanceId(task.getExecutionId()).uniqueResult();
|
// 取出下一步任务
|
String nextTaskId = nextTask.getId();
|
String activityName = nextTask.getActivityName();
|
|
String[] customUsers = new String[0];
|
String[] userNamesNew = new String[0];
|
|
// 获取任务节点扩展信息
|
List<TaskDescSObject> taskDescList = this.getTaskDescList(activityName, strDeploymentId);
|
int pltreatment = 0;
|
if (taskDescList != null) {
|
pltreatment = ((TaskDescSObject) taskDescList.get(0)).getPltreatment();
|
}
|
|
// add by xchao 2013.05.19 bgien
|
|
/**
|
* 解决的问题:'清空当前任务自定义候选人处理类计算出的候选人’ 由于完善当前任务节点时,会执行一个的任务的‘自定义候选人事件’(如果定义了)及其‘初始事件’
|
* 而在‘自定义候选人事件’中会注入CustomUserNames值,即自定义候选人, 而如果当前节点定义了自定义候选人事件,而一个节点未定义,
|
* 此时在CustomUserNames是在当前节点上计算出的值,是能处理当前节点的候选人 因此在完成当前节点时,如果下一个节点未定义自定义候选人处理类,
|
* 则需要清空CustomUserNames的值,以还原数据状态
|
*
|
* 在此处执行是因为,执行到这里,对于当前任务已经执行的‘完成任务’, 同时一个任务的初始事件而且已经执行完成,
|
* 后面的代码段通过通过API接口修改一个任务的处理人 为了解决‘当前任务自定义候选人对一个任务的感染’, 因此在本段尝试执行清空动作,以清除可能在感染。
|
*/
|
// List<TaskDescSObject> taskDescList =
|
// this.getTaskDescList(activityName, strDeploymentId);
|
if (taskDescList != null) {
|
for (int i = 0; i < taskDescList.size(); i++) {
|
TaskDescSObject taskDescSObject = taskDescList.get(i);
|
String customclass = taskDescSObject.getPlcustomclassname();
|
// String param = taskDescSObject.getPlcustomparam();
|
if (customclass != null && !"".equals(customclass)) {
|
// 对于解决 '清空当前任务自定义候选人处理类计算出的候选人’
|
// 此条件中不需要执行任何逻辑
|
} else {
|
// 对于解决'清空当前任务自定义候选人处理类计算出的候选人’
|
// 根据 nextTaskId 查出的 activityName 节点未定义‘自定义候选人’
|
// 因此,需要清空在当前任务节点中计算出的
|
HashMap<String, Object> map = new HashMap<String, Object>();
|
map.put("CustomUserNames", new String[] {});
|
taskService.setVariables(nextTaskId, map);
|
}
|
}
|
}
|
|
// add by xchao 2013.05.19 end
|
|
Object variable = taskService.getVariable(nextTaskId, "CustomUserNames");
|
if (variable instanceof String[]) {
|
String[] v = (String[]) variable;
|
if (v != null) {
|
customUsers = v;
|
}
|
}
|
if (customUsers != null) {
|
userNamesNew = new String[customUsers.length];
|
}
|
if (userNames != null) {
|
userNamesNew = new String[customUsers.length + userNames.length];
|
}
|
System.arraycopy(customUsers, 0, userNamesNew, 0, customUsers.length);
|
System.arraycopy(userNames, 0, userNamesNew, customUsers.length, userNames.length);
|
userNames = userNamesNew;
|
// 如果是1,则说明是会签,不对任务重新设置候选人
|
if (pltreatment == 0) {
|
// 重新设置候选人
|
for (int k = 0; k < userNames.length; k++) {
|
String userName = userNames[k];
|
if (userName.trim().length() > 0) {
|
// TaskService taskService =
|
// processEngine.getTaskService();
|
|
List<Participation> taskParticipations = taskService.getTaskParticipations(nextTaskId);
|
// 先删除原来的任务候选人
|
if (k == 0) {
|
// 放回任务
|
taskService.assignTask(nextTaskId, null);
|
|
for (Participation participation : taskParticipations) {
|
taskService.removeTaskParticipatingUser(nextTaskId, participation.getUserId(),
|
Participation.CANDIDATE);
|
}
|
}
|
|
taskService.addTaskParticipatingUser(nextTaskId, userName, Participation.CANDIDATE);
|
}
|
}
|
|
}
|
}
|
|
return true;
|
} catch (Exception e) {
|
e.printStackTrace();
|
throw new VCIError();
|
}
|
}
|
|
/**
|
* 流程启动,设置用户
|
*
|
* @param processDefinitionKey
|
* @param var
|
* @param objId
|
* @param userNames
|
* @param outcome
|
* @param taskAndUserMap
|
* @return
|
* @throws VCIError
|
*/
|
public String startPocessSetUser(String processDefinitionKey, FlowInstanceInfo var, String[] objId,
|
String[] userNames, String outcome, Map<String, String[]> taskAndUserMap) throws VCIError {
|
String executionId = "";
|
try {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
Map<String, Object> variables = new HashMap<String, Object>();
|
variables.put("process_applicant", var.applicant);
|
variables.put("userName", getUserEntity().getModule());
|
|
variables.put("globalParam", var.partList == null ? "" : var.partList);
|
// 流程数据ID列表
|
variables.put("objIds", objId);
|
|
List<String> participants = new ArrayList<String>();
|
for (String participant : userNames) {
|
participants.add(participant);
|
}
|
variables.put("participants", participants);
|
|
String deploymentId = getdeploymentIdBySql(processDefinitionKey);
|
|
ServerWithLog4j.logger.debug("startProcessInstanceById开始!");
|
ProcessInstance processInstance = processEngine.getExecutionService()
|
.startProcessInstanceById(processDefinitionKey, variables);
|
ServerWithLog4j.logger.debug("startProcessInstanceById结束!");
|
FlowInstance flowInstance = new FlowInstance();
|
String flowInstanceId = ObjectUtility.getNewObjectID36();
|
flowInstance.setId(flowInstanceId);
|
String proccessInstanceId = processInstance.getId();
|
// 流程启动时,设置任务与候选人之间的关系。
|
configTaskAndUser(processEngine, deploymentId, processInstance.getId(), objId, taskAndUserMap);
|
TaskService taskService = processEngine.getTaskService();
|
Task task = taskService.createTaskQuery().assignee(getUserEntity().getUserName())
|
.processInstanceId(proccessInstanceId).uniqueResult();
|
boolean mulityPeo = false;
|
if (task == null) {
|
task = taskService.createTaskQuery().candidate(getUserEntity().getUserName())
|
.processInstanceId(proccessInstanceId).uniqueResult();
|
mulityPeo = true;
|
}
|
if (task == null) {
|
// 对不起,你没有该任务!请于管理员联系!
|
throw new VCIError("0", new String[] { "对不起,你没有该任务!请于管理员联系!" });
|
}
|
executionId = task.getExecutionId();
|
flowInstance.setExecutionid(task.getExecutionId());
|
flowInstance.setApplicant(var.applicant);
|
flowInstance.setCreator(var.creator);
|
flowInstance.setTemplatePuid(var.templatePuid);
|
flowInstance.setTemplateName(var.templateName);
|
flowInstance.setClsfOid(var.clsfOid);
|
flowInstance.setTableName(var.tableName);
|
flowInstance.setDesc(var.desc);
|
String processType = var.processType;
|
flowInstance.setProcessType(processType);
|
flowInstance.setProcessName(var.processName);
|
flowInstance.setUserEntity(userEntity);
|
|
FlowInstanceDaoImpl impl = new FlowInstanceDaoImpl();
|
impl.save(flowInstance);// 保存流程实例的变量
|
if (!"EBOM".equalsIgnoreCase(processType) && !"MBOM".equalsIgnoreCase(processType)) {
|
processType = "rm";
|
}
|
|
// 插入流程数据对象表
|
int length = objId.length;
|
for (int i = 0; i < length; i++) {
|
PLFlowObject flowObject = new PLFlowObject();
|
flowObject.setPloid(ObjectUtility.getNewObjectID36());
|
flowObject.setPlexecutionid(task.getExecutionId());
|
flowObject.setPlobjectid(objId[i]);
|
flowObject.setPlprocesstype(processType);
|
flowObject.setInitStatus("");
|
PLFlowObjectDaoImpl flowObjectDaoImpl = new PLFlowObjectDaoImpl();
|
flowObjectDaoImpl.save(flowObject);
|
}
|
|
// 多候选人的情况下,获得当前的候选人
|
if (mulityPeo) {
|
taskService.takeTask(task.getId(), getUserEntity().getUserName());
|
}
|
|
// 获取deploymentID
|
// BigDecimal deploymentId = getDeploymentID(processDefinitionKey);
|
// String strDeploymentId = String.valueOf(deploymentId);
|
|
variables.put("deploymentId", deploymentId);
|
|
variables.put("flowInstance.TableName", flowInstance.getTableName());
|
|
// 如果配置了用户选择插件,则执行以下操作
|
String userServiceImplClass = WorkflowProperties.getStringProperty("workflow.userService");
|
|
if (userServiceImplClass != null && !"".equals(userServiceImplClass)) {
|
IWorkflowUserService puService = (IWorkflowUserService) (Class.forName(userServiceImplClass)
|
.newInstance());
|
String[] canditates = new String[userNames.length];
|
for (int i = 0; i < userNames.length; i++) {
|
canditates[i] = userNames[i];
|
}
|
userNames = puService.getAllUsers2Task(canditates, getUserEntity().getModule());
|
}
|
|
variables.put("content", outcome);
|
taskService.setVariables(task.getId(), variables);
|
ServerWithLog4j.logger.debug("completeTask开始!");
|
if (outcome != null && !"".equals(outcome)) {
|
taskService.completeTask(task.getId(), outcome);
|
} else {
|
taskService.completeTask(task.getId());
|
}
|
ServerWithLog4j.logger.debug("completeTask结束!");
|
|
// // 插入流程执行情况表
|
Plflowapproveopinion plflowapproveopinion = new Plflowapproveopinion();
|
String ploid = ObjectUtility.getNewObjectID36();
|
plflowapproveopinion.setPloid(ploid);
|
plflowapproveopinion.setPltaskid(task.getId());
|
plflowapproveopinion.setPlapproveopinion("提交任务");
|
plflowapproveopinion.setPlapprovenote(var.desc);
|
// 记录执行者
|
plflowapproveopinion.setPlassgin(getUserEntity().getUserName());
|
|
PlflowapproveopinionDaoImpl flowapproveopinionDaoImpl = new PlflowapproveopinionDaoImpl();
|
flowapproveopinionDaoImpl.save(plflowapproveopinion);
|
|
// 下一步任务
|
List<Task> nextTasks = taskService.createTaskQuery().processInstanceId(task.getExecutionId()).list();
|
for (Task nextTask : nextTasks) {
|
String activityName = "";
|
if (nextTask == null) {
|
String[] execIDs = task.getExecutionId().replace(".", ",").split(",");
|
activityName = getNextTaskName(deploymentId, null, task.getActivityName(), outcome);
|
List<Task> list = taskService.createTaskQuery().processInstanceId(execIDs[0] + "." + execIDs[1])
|
.list();
|
for (int i = 0; i < list.size(); i++) {
|
if (list.get(i).getActivityName().equals(activityName)) {
|
nextTask = list.get(i);
|
}
|
}
|
} else {
|
activityName = nextTask.getActivityName();
|
}
|
List<?> taskDescList = this.getTaskDescList(activityName, deploymentId);
|
int pltreatment = 0;
|
if (taskDescList != null) {
|
pltreatment = ((TaskDescSObject) taskDescList.get(0)).getPltreatment();
|
}
|
|
String nextTaskId = nextTask.getId();
|
|
// 如果是1,则说明是会签,不对任务重新设置候选人
|
if (pltreatment == 0) {
|
String userName = "";
|
String cUserName = this.getNextTaskAssigner(task.getExecutionId(), nextTask.getName());
|
userNames = cUserName.split(",");
|
for (int k = 0; k < userNames.length; k++) {
|
userName = userName + "," + userNames[k];
|
if (userNames.length > 0) {
|
List<Participation> taskParticipations = taskService.getTaskParticipations(nextTaskId);
|
// 先删除原来的任务候选人
|
if (k == 0) {
|
// nextTask.setAssignee(userNames[k]);
|
for (Participation participation : taskParticipations) {
|
taskService.removeTaskParticipatingUser(nextTaskId, participation.getUserId(),
|
Participation.CANDIDATE);
|
}
|
}
|
taskService.addTaskParticipatingUser(nextTaskId, userNames[k], Participation.CANDIDATE);
|
|
}
|
}
|
}
|
}
|
|
return executionId;
|
} catch (Exception e) {
|
e.printStackTrace();
|
throw new VCIError();
|
}
|
}
|
|
/**
|
* 流程启动,设置用户
|
*
|
* @param processDefinitionKey
|
* @param var
|
* @param objId
|
* @param userNames
|
* @param outcome
|
* @param taskAndUserMap
|
* @param keys 流程参数设置的key
|
* @param values 流程参数设置的value
|
* @return
|
* @throws VCIError
|
*/
|
public String startPocessSetUser(String processDefinitionKey, FlowInstanceInfo var, String[] objId,
|
String[] userNames, String outcome, Map<String, String[]> taskAndUserMap, String[] keys, String[] values)
|
throws VCIError {
|
String executionId = "";
|
try {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
Map<String, Object> variables = new HashMap<String, Object>();
|
variables.put("process_applicant", var.applicant);
|
variables.put("userName", getUserEntity().getModule());
|
|
variables.put("globalParam", var.partList == null ? "" : var.partList);
|
// 流程数据ID列表
|
variables.put("objIds", objId);
|
|
if (keys != null) {
|
for (int i = 0; i < keys.length; i++) {
|
variables.put(keys[i], values[i]);
|
}
|
}
|
List<String> participants = new ArrayList<String>();
|
for (String participant : userNames) {
|
participants.add(participant);
|
}
|
variables.put("participants", participants);
|
|
String deploymentId = getdeploymentIdBySql(processDefinitionKey);
|
|
ServerWithLog4j.logger.debug("startProcessInstanceById开始!");
|
ProcessInstance processInstance = processEngine.getExecutionService()
|
.startProcessInstanceById(processDefinitionKey, variables);
|
ServerWithLog4j.logger.debug("startProcessInstanceById结束!");
|
FlowInstance flowInstance = new FlowInstance();
|
String flowInstanceId = ObjectUtility.getNewObjectID36();
|
flowInstance.setId(flowInstanceId);
|
String proccessInstanceId = processInstance.getId();
|
// 流程启动时,设置任务与候选人之间的关系。
|
configTaskAndUser(processEngine, deploymentId, processInstance.getId(), objId, taskAndUserMap);
|
TaskService taskService = processEngine.getTaskService();
|
Task task = taskService.createTaskQuery().assignee(getUserEntity().getUserName())
|
.processInstanceId(proccessInstanceId).uniqueResult();
|
boolean mulityPeo = false;
|
if (task == null) {
|
task = taskService.createTaskQuery().candidate(getUserEntity().getUserName())
|
.processInstanceId(proccessInstanceId).uniqueResult();
|
mulityPeo = true;
|
}
|
if (task == null) {
|
// 对不起,你没有该任务!请于管理员联系!
|
throw new VCIError("0", new String[] { "对不起,你没有该任务!请于管理员联系!" });
|
}
|
executionId = task.getExecutionId();
|
flowInstance.setExecutionid(task.getExecutionId());
|
flowInstance.setApplicant(var.applicant);
|
flowInstance.setCreator(var.creator);
|
flowInstance.setTemplatePuid(var.templatePuid);
|
flowInstance.setTemplateName(var.templateName);
|
flowInstance.setClsfOid(var.clsfOid);
|
flowInstance.setTableName(var.tableName);
|
flowInstance.setDesc(var.desc);
|
String processType = var.processType;
|
flowInstance.setProcessType(processType);
|
flowInstance.setProcessName(var.processName);
|
flowInstance.setUserEntity(userEntity);
|
|
FlowInstanceDaoImpl impl = new FlowInstanceDaoImpl();
|
impl.save(flowInstance);// 保存流程实例的变量
|
if (!"EBOM".equalsIgnoreCase(processType) && !"MBOM".equalsIgnoreCase(processType)) {
|
processType = "rm";
|
}
|
|
// 插入流程数据对象表
|
int length = objId.length;
|
for (int i = 0; i < length; i++) {
|
PLFlowObject flowObject = new PLFlowObject();
|
flowObject.setPloid(ObjectUtility.getNewObjectID36());
|
flowObject.setPlexecutionid(task.getExecutionId());
|
flowObject.setPlobjectid(objId[i]);
|
flowObject.setPlprocesstype(processType);
|
flowObject.setInitStatus("");
|
PLFlowObjectDaoImpl flowObjectDaoImpl = new PLFlowObjectDaoImpl();
|
flowObjectDaoImpl.save(flowObject);
|
}
|
|
// 多候选人的情况下,获得当前的候选人
|
if (mulityPeo) {
|
taskService.takeTask(task.getId(), getUserEntity().getUserName());
|
}
|
|
// 获取deploymentID
|
// BigDecimal deploymentId = getDeploymentID(processDefinitionKey);
|
// String strDeploymentId = String.valueOf(deploymentId);
|
|
variables.put("deploymentId", deploymentId);
|
|
variables.put("flowInstance.TableName", flowInstance.getTableName());
|
|
// 如果配置了用户选择插件,则执行以下操作
|
String userServiceImplClass = WorkflowProperties.getStringProperty("workflow.userService");
|
|
if (userServiceImplClass != null && !"".equals(userServiceImplClass)) {
|
IWorkflowUserService puService = (IWorkflowUserService) (Class.forName(userServiceImplClass)
|
.newInstance());
|
String[] canditates = new String[userNames.length];
|
for (int i = 0; i < userNames.length; i++) {
|
canditates[i] = userNames[i];
|
}
|
userNames = puService.getAllUsers2Task(canditates, getUserEntity().getModule());
|
}
|
|
variables.put("content", outcome);
|
taskService.setVariables(task.getId(), variables);
|
ServerWithLog4j.logger.debug("completeTask开始!");
|
if (outcome != null && !"".equals(outcome)) {
|
taskService.completeTask(task.getId(), outcome);
|
} else {
|
taskService.completeTask(task.getId());
|
}
|
ServerWithLog4j.logger.debug("completeTask结束!");
|
|
// // 插入流程执行情况表
|
Plflowapproveopinion plflowapproveopinion = new Plflowapproveopinion();
|
String ploid = ObjectUtility.getNewObjectID36();
|
plflowapproveopinion.setPloid(ploid);
|
plflowapproveopinion.setPltaskid(task.getId());
|
plflowapproveopinion.setPlapproveopinion("提交任务");
|
plflowapproveopinion.setPlapprovenote(var.desc);
|
// 记录执行者
|
plflowapproveopinion.setPlassgin(getUserEntity().getUserName());
|
|
PlflowapproveopinionDaoImpl flowapproveopinionDaoImpl = new PlflowapproveopinionDaoImpl();
|
flowapproveopinionDaoImpl.save(plflowapproveopinion);
|
|
// 下一步任务
|
Task nextTask = taskService.createTaskQuery().processInstanceId(task.getExecutionId()).uniqueResult();
|
String activityName = "";
|
if (nextTask == null) {
|
String[] execIDs = task.getExecutionId().replace(".", ",").split(",");
|
activityName = getNextTaskName(deploymentId, null, task.getActivityName(), outcome);
|
List<Task> list = taskService.createTaskQuery().processInstanceId(execIDs[0] + "." + execIDs[1]).list();
|
for (int i = 0; i < list.size(); i++) {
|
if (list.get(i).getActivityName().equals(activityName)) {
|
nextTask = list.get(i);
|
}
|
}
|
} else {
|
activityName = nextTask.getActivityName();
|
}
|
List<?> taskDescList = this.getTaskDescList(activityName, deploymentId);
|
int pltreatment = 0;
|
if (taskDescList != null) {
|
pltreatment = ((TaskDescSObject) taskDescList.get(0)).getPltreatment();
|
}
|
|
String nextTaskId = nextTask.getId();
|
|
// 如果是1,则说明是会签,不对任务重新设置候选人
|
if (pltreatment == 0) {
|
String userName = "";
|
for (int k = 0; k < userNames.length; k++) {
|
userName = userName + "," + userNames[k];
|
if (userNames.length > 0) {
|
List<Participation> taskParticipations = taskService.getTaskParticipations(nextTaskId);
|
// 先删除原来的任务候选人
|
if (k == 0) {
|
// nextTask.setAssignee(userNames[k]);
|
for (Participation participation : taskParticipations) {
|
taskService.removeTaskParticipatingUser(nextTaskId, participation.getUserId(),
|
Participation.CANDIDATE);
|
}
|
}
|
taskService.addTaskParticipatingUser(nextTaskId, userNames[k], Participation.CANDIDATE);
|
|
}
|
}
|
}
|
|
return executionId;
|
} catch (Exception e) {
|
e.printStackTrace();
|
throw new VCIError();
|
}
|
}
|
|
/**
|
* 流程启动(PLM)平台使用
|
*
|
* @param processDefinitionKey 流程名称-版本号 (xxx-1)
|
* @param var 流程实例对象 FlowInstanceInfo flowInstanceInfo = new
|
* FlowInstanceInfo(); flowInstanceInfo.creator =
|
* loginUserName;//当前用户
|
* flowInstanceInfo.templatePuid = "";// 资源模板id
|
* flowInstanceInfo.clsfOid =""; //资源分类id String
|
* processType =
|
* getRequest().getParameter("btmname");//业务类型名称
|
* flowInstanceInfo.tableName = processType;
|
* flowInstanceInfo.applicant = loginUserName;
|
* //流程发起人(登录用户名) String processDec =
|
* parameterMap.get("processdesc")==null?"":parameterMap.get("processdesc")[0];//流程描述
|
* flowInstanceInfo.desc = processDec == null? "" :
|
* processDec; flowInstanceInfo.processType =
|
* "add";//流程类型 暂时不用 flowInstanceInfo.templateName =
|
* parameterMap.get("templateid")[0];//模板名称
|
* flowInstanceInfo.partList = "";//不用 String
|
* processName =
|
* parameterMap.get("processname")==null?"":parameterMap.get("processname")[0];//流程名称
|
* flowInstanceInfo.processName = processName ==
|
* null ? "" : processName;
|
*
|
* @param objId 数据对象id,这里是数组
|
* @param userNames 下一步处理人名称
|
* ({user:user1,user:user2....,role:role1,role:role2....,department:department1,department:department2....})
|
* @param outcome 路由名称
|
* @param taskAndUserMap 任务和用户的关系数组
|
* [任务1:({user:user1,user:user2....,role:role1,role:role2....,depart:depart1,depart:depart2....}),任务2:({user:user1,user:user2....,role:role1,role:role2....,depart:depart1,depart:depart2....})。。。。]
|
* @param variables 变量:在事件中所需要的变量,在启动流程时设置 (key:value(Object))
|
* @return
|
* @throws VCIError
|
*
|
*/
|
|
public String startPocessByPLM(String processDefinitionKey, FlowInstanceInfo var, String[] objId,
|
String[] userNames, String outcome, Map<String, String[]> taskAndUserMap, Map<String, Object> variables)
|
throws VCIError {
|
String processInstanceId = "";
|
try {
|
System.out.println("startPocessByPLM-0");
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
variables.put("process_applicant", var.applicant);
|
variables.put("userName", getUserEntity().getUserName());
|
variables.put("var", var);
|
|
variables.put("globalParam", var.partList == null ? "" : var.partList);
|
|
// List<String> participants = new ArrayList<String>();
|
// for (String participant : userNames) {
|
// participants.add(participant);
|
// }
|
// variables.put("participants", participants);
|
|
// 流程数据ID列表
|
variables.put("objId", objId);
|
|
String getdeploymentId = getdeploymentIdBySql(processDefinitionKey);
|
|
ProcessTask ptask = getFirstProcessTask(getdeploymentId);
|
if (ptask == null)
|
return "";
|
|
String fTask = ptask.getTaskName();
|
List<String> participants = new ArrayList<String>();
|
if (taskAndUserMap.containsKey(fTask)) {
|
for (String participant : taskAndUserMap.get(fTask)) {
|
participants.add(participant);
|
}
|
} else {
|
for (String participant : userNames) {
|
participants.add(participant);
|
}
|
}
|
variables.put("participants", participants);
|
|
ServerWithLog4j.logger.debug("startProcessInstanceById开始!");
|
|
ProcessInstance processInstance = processEngine.getExecutionService()
|
.startProcessInstanceById(processDefinitionKey, variables);
|
|
ServerWithLog4j.logger.debug("startProcessInstanceById结束!");
|
|
FlowInstance flowInstance = new FlowInstance();
|
String flowInstanceId = ObjectUtility.getNewObjectID36();
|
flowInstance.setId(flowInstanceId);
|
processInstanceId = processInstance.getId();
|
System.out.println("startPocessByPLM-1");
|
// 流程启动时,设置任务与候选人之间的关系。
|
configTaskAndUser(processEngine, getdeploymentId, processInstance.getId(), objId, taskAndUserMap);
|
|
flowInstance.setExecutionid(processInstanceId);
|
flowInstance.setApplicant(var.applicant);
|
flowInstance.setCreator(var.creator);
|
flowInstance.setTemplatePuid(var.templatePuid);
|
flowInstance.setTemplateName(var.templateName);
|
flowInstance.setClsfOid(var.clsfOid);
|
flowInstance.setTableName(var.tableName);
|
flowInstance.setDesc(var.desc);
|
String processType = var.processType;
|
flowInstance.setProcessType(processType);
|
flowInstance.setProcessName(var.processName);
|
flowInstance.setTaskType(var.taskType);
|
flowInstance.setUserEntity(userEntity);
|
|
FlowInstanceDaoImpl impl = new FlowInstanceDaoImpl();
|
impl.save(flowInstance);// 保存流程实例的变量
|
System.out.println("startPocessByPLM-2");
|
|
// 插入流程数据对象表
|
int length = objId.length;
|
for (int i = 0; i < length; i++) {
|
PLFlowObject flowObject = new PLFlowObject();
|
flowObject.setPloid(ObjectUtility.getNewObjectID36());
|
flowObject.setPlexecutionid(processInstanceId);
|
flowObject.setPlobjectid(objId[i]);
|
flowObject.setPlprocesstype(processType);
|
flowObject.setInitStatus("");
|
PLFlowObjectDaoImpl flowObjectDaoImpl = new PLFlowObjectDaoImpl();
|
flowObjectDaoImpl.save(flowObject);
|
}
|
|
System.out.println("startPocessByPLM-3");
|
|
// workflowinstance业务类型目前是在workitem中保存数据的,但是如果第一个节点有多个处理人时,就会出现多条相同的数据。
|
// weidy@2018-08-22 由此修改到此处保存
|
if (isWorkFlowInstanceExist()) {
|
cunstructWorkFlowInstanceObj(processInstanceId, var.processName, var.desc, var.tableName, objId);
|
}
|
System.out.println("startPocessByPLM-4");
|
|
TaskService taskService = processEngine.getTaskService();
|
// TaskQuery q = taskService.createTaskQuery().processInstanceId(processInstanceId);
|
// List<Task> list = q.list();
|
// if(list.size()>1){
|
// for(int i=0;i<list.size();i++){
|
// Task task = list.get(i);
|
// for(Entry<String, String[]> es : taskAndUserMap.entrySet()){
|
// String key = es.getKey();
|
// if(key.equals(task.getName())){
|
// String taskId = task.getId();
|
// String executionid = task.getExecutionId();
|
//
|
// // 如果配置了用户选择插件,则执行以下操作
|
// String userServiceImplClass = Jbpm4Properties
|
// .getStringProperty("workflow.userService");
|
//
|
// if (userServiceImplClass != null
|
// && !"".equals(userServiceImplClass)) {
|
// IWorkflowUserService puService = (IWorkflowUserService) (Class
|
// .forName(userServiceImplClass).newInstance());
|
// String[] value = es.getValue();
|
// String[] canditates = new String[value.length];
|
// for (int j = 0; j < value.length; j++) {
|
// canditates[j] = value[j];
|
// }
|
// userNames = puService.getAllUsers2Task(canditates,
|
// getUserEntity().getModule());
|
// }
|
//
|
// //出差设置的候选人
|
// List<String> taskassignList = new ArrayList<String>();
|
// for(int k = 0; k < userNames.length; k++){
|
// TasksAssigned tasksAssignedByUserName = getTasksAssignedByUserName(userNames[k]);
|
// String taskassign = tasksAssignedByUserName.getTasksName();
|
// if(taskassign==null||"".equals(taskassign)){
|
// taskassign = userNames[k];
|
// }
|
// String[] split = taskassign.split(",");
|
// for(String s : split){
|
// if(!taskassignList.contains(s)){
|
// taskassignList.add(s);
|
// }
|
// }
|
// }
|
// if(taskassignList!=null&&taskassignList.size()>0){
|
// userNames = taskassignList.toArray(new String[0]);
|
// }
|
//
|
// for (int k = 0; k < userNames.length; k++) {
|
//
|
// List<Participation> taskParticipations = taskService
|
// .getTaskParticipations(taskId);
|
// // 先删除原来的任务候选人
|
// if (k == 0) {
|
// if (userNames.length == 1) {
|
// task.setAssignee(userNames[k]);
|
// }
|
// for (Participation participation : taskParticipations) {
|
// taskService.removeTaskParticipatingUser(taskId,
|
// participation.getUserId(),
|
// Participation.CANDIDATE);
|
// }
|
// }
|
// taskService.addTaskParticipatingUser(taskId, userNames[k],
|
// Participation.CANDIDATE);
|
//
|
// if(workitemClass!=null&&!"".equals(workitemClass)){
|
//
|
// callPLMworkitemSave(var, objId, userNames,
|
// task, taskId, executionid, k);
|
// }
|
// }
|
// }
|
//
|
// }
|
//
|
//
|
//// Date date = new Date();
|
//// long time = date.getTime();
|
//// Timestamp excutionTimen = new Timestamp(time);
|
//// saveWorkItemHist(taskId, "发起流程", boDelegate,
|
//// bofBoDelegate, loDelegate, task, objId,
|
//// var.tableName, var.desc, excutionTimen, var.processName);
|
// }
|
// }else{
|
|
String userServiceImplClass = WorkflowProperties.getStringProperty("workflow.userService");
|
|
Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).uniqueResult();
|
if (taskAndUserMap.containsKey(task.getName())) {
|
String[] users = taskAndUserMap.get(task.getName());
|
|
List<Task> subTasks = taskService.getSubTasks(task.getId());
|
if (subTasks.size() > 0) {
|
for (int i = 0; i < subTasks.size(); i++) {
|
Task subTask = subTasks.get(i);
|
|
String taskId = subTask.getId();
|
String executionid = subTask.getExecutionId();
|
|
// 如果配置了用户选择插件,则执行以下操作
|
|
if (!StringUtils.isEmpty(userServiceImplClass)) { // != null &&
|
// !"".equals(userServiceImplClass)) {
|
IWorkflowUserService puService = (IWorkflowUserService) (Class.forName(userServiceImplClass)
|
.newInstance());
|
// String[] value = users;
|
String[] canditates = new String[users.length];
|
for (int j = 0; j < users.length; j++) {
|
canditates[j] = users[j];
|
}
|
userNames = puService.getAllUsers2Task(canditates, getUserEntity().getModule());
|
}
|
|
// 出差设置的候选人
|
List<String> taskassignList = new ArrayList<String>();
|
for (int k = 0; k < userNames.length; k++) {
|
TasksAssigned tasksAssignedByUserName = getTasksAssignedByUserName(userNames[k]);
|
String taskassign = tasksAssignedByUserName.getTasksName();
|
if (taskassign == null || "".equals(taskassign)) {
|
taskassign = userNames[k];
|
}
|
String[] split = taskassign.split(",");
|
for (String s : split) {
|
if (!taskassignList.contains(s)) {
|
taskassignList.add(s);
|
}
|
}
|
}
|
if (taskassignList != null && taskassignList.size() > 0) {
|
userNames = taskassignList.toArray(new String[0]);
|
}
|
|
for (int k = 0; k < userNames.length; k++) {
|
|
List<Participation> taskParticipations = taskService.getTaskParticipations(taskId);
|
// 先删除原来的任务候选人
|
if (k == 0) {
|
if (userNames.length == 1) {
|
subTask.setAssignee(userNames[k]);
|
}
|
for (Participation participation : taskParticipations) {
|
taskService.removeTaskParticipatingUser(taskId, participation.getUserId(),
|
Participation.CANDIDATE);
|
}
|
}
|
|
String[] subAssigns = subTask.getAssignee().split(",");
|
for (String subAssign : subAssigns) {
|
String parsSubAssign = subAssign.substring(subAssign.indexOf(":") + 1,
|
subAssign.length());
|
if (parsSubAssign.equals(userNames[k])) {
|
taskService.addTaskParticipatingUser(taskId, userNames[k], Participation.CANDIDATE);
|
|
if (workitemClass != null && !"".equals(workitemClass)) {
|
callPLMworkitemSave(var, objId, userNames, subTask, taskId, executionid, k,
|
variables);
|
}
|
}
|
}
|
}
|
}
|
} else {
|
String taskId = task.getId();
|
String executionid = task.getExecutionId();
|
|
// 如果配置了用户选择插件,则执行以下操作
|
// String userServiceImplClass = Jbpm4Properties
|
// .getStringProperty("workflow.userService");
|
|
if (userServiceImplClass != null && !"".equals(userServiceImplClass)) {
|
IWorkflowUserService puService = (IWorkflowUserService) (Class.forName(userServiceImplClass)
|
.newInstance());
|
// String[] value = es.getValue();
|
String[] canditates = new String[users.length];
|
for (int i = 0; i < users.length; i++) {
|
canditates[i] = users[i];
|
}
|
userNames = puService.getAllUsers2Task(canditates, getUserEntity().getModule());
|
}
|
// 出差设置的候选人
|
List<String> taskassignList = new ArrayList<String>();
|
for (int k = 0; k < userNames.length; k++) {
|
TasksAssigned tasksAssignedByUserName = getTasksAssignedByUserName(userNames[k]);
|
String taskassign = tasksAssignedByUserName.getTasksName();
|
if (taskassign == null || "".equals(taskassign)) {
|
taskassign = userNames[k];
|
}
|
String[] split = taskassign.split(",");
|
for (String s : split) {
|
if (!taskassignList.contains(s)) {
|
taskassignList.add(s);
|
}
|
}
|
}
|
if (taskassignList != null && taskassignList.size() > 0) {
|
userNames = taskassignList.toArray(new String[0]);
|
}
|
for (int k = 0; k < userNames.length; k++) {
|
|
List<Participation> taskParticipations = taskService.getTaskParticipations(taskId);
|
// 先删除原来的任务候选人
|
if (k == 0) {
|
if (userNames.length == 1) {
|
task.setAssignee(userNames[k]);
|
}
|
for (Participation participation : taskParticipations) {
|
taskService.removeTaskParticipatingUser(taskId, participation.getUserId(),
|
Participation.CANDIDATE);
|
}
|
}
|
taskService.addTaskParticipatingUser(taskId, userNames[k], Participation.CANDIDATE);
|
|
if (workitemClass != null && !"".equals(workitemClass)) {
|
callPLMworkitemSave(var, objId, userNames, task, taskId, executionid, k, variables);
|
}
|
}
|
}
|
|
System.out.println("startPocessByPLM-5");
|
|
// }
|
// Date date = new Date();
|
// long time = date.getTime();
|
// Timestamp excutionTimen = new Timestamp(time);
|
// saveWorkItemHist(taskId, "发起流程", boDelegate,
|
// bofBoDelegate, loDelegate, task, objId,
|
// var.tableName, var.desc, excutionTimen, var.processName);
|
}
|
return processInstanceId;
|
} catch (VCIError e) {
|
e.printStackTrace();
|
throw e;
|
} catch (Exception e) {
|
e.printStackTrace();
|
if (e.getCause() != null && e.getCause() instanceof VCIError) {
|
throw (VCIError) e.getCause();
|
}
|
throw ServerErrorTool.getVCIError("启动流程的过程中出现错误!" + e.toString(), e);
|
}
|
}
|
|
/**
|
* 调用plmworkitem的save方法
|
*
|
* @param var
|
* @param objId
|
* @param userNames
|
* @param task
|
* @param taskId
|
* @param executionid
|
* @param k
|
* @throws ClassNotFoundException
|
* @throws NoSuchMethodException
|
* @throws IllegalAccessException
|
* @throws InvocationTargetException
|
* @throws InstantiationException
|
* @throws IllegalArgumentException
|
* @throws VCIError
|
*/
|
private void callPLMworkitemSave(FlowInstanceInfo var, String[] objId, String[] userNames, Task task, String taskId,
|
String executionid, int k, Map variables)
|
throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException,
|
IllegalArgumentException, InstantiationException, VCIError {
|
// PLMWorkItemInterface pwService = (PLMWorkItemInterface)
|
// (Class.forName(workitemClass).newInstance());
|
if (_pwiService != null) {
|
String userName = userNames[k];
|
_pwiService.saveForStart(var, task, userName, taskId, executionid, objId, variables);
|
}
|
}
|
|
/**
|
* 调用plmworkitem的save方法
|
*
|
* @param var
|
* @param objId
|
* @param userNames
|
* @param task
|
* @param taskId
|
* @param executionid
|
* @param k
|
* @param variables
|
* @throws ClassNotFoundException
|
* @throws NoSuchMethodException
|
* @throws IllegalAccessException
|
* @throws InvocationTargetException
|
* @throws IllegalArgumentException
|
* @throws InstantiationException
|
* @throws VCIError
|
*/
|
private void callPLMworkitemSave_v1(FlowInstanceInfo var, String[] objId, String[] userNames, Task task,
|
String taskId, String executionid, int k, Map variables, String[] objectProperty,
|
String[][] objectPropertyValues)
|
throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException,
|
IllegalArgumentException, InstantiationException, VCIError {
|
// PLMWorkItemInterface pwService = (PLMWorkItemInterface)
|
// (Class.forName(workitemClass).newInstance());
|
if (_pwiService != null) {
|
String userName = userNames[k];
|
_pwiService.saveForStart_v1(var, task, userName, taskId, executionid, objId, variables, objectProperty,
|
objectPropertyValues);
|
}
|
}
|
|
/**
|
* 流程启动前配置模版的任务和用户。启动后,还可以再次指定任务的候选人。 在工作流中,以后启动后指定的任务候选人,为最终的任务候选人。
|
*
|
* @param processDefinitionKey
|
* @param objId
|
* @param userNames
|
* @param activityName
|
* @return
|
*/
|
private String[] setTaskUserList(String processDefinitionKey, String[] objId, String[] userNames,
|
String activityName) {
|
String[] userList = this.userList(processDefinitionKey, objId, activityName);
|
// 如果任务节点选择了用户,则覆盖掉流程启动前对任务设置的用户。
|
boolean userControlFlag = false;
|
if (userNames != null) {
|
if (userNames.length > 0) {
|
userControlFlag = false;
|
} else {
|
userControlFlag = true;
|
}
|
}
|
|
if (userList != null && userControlFlag) {
|
userNames = userList;
|
}
|
return userNames;
|
}
|
|
/**
|
* 通过模板的名称获取流程部署ID
|
*
|
* @param processDefinitionKey
|
* @return
|
*/
|
private String getdeploymentIdBySql(String processDefinitionKey) {
|
String deploymentIdSql = "select a.deployment_ from jbpm4_deployprop a where a.key_ = 'pdid' and a.stringval_ = ?";
|
Session session = HibernateSessionFactory.getSession();
|
String deploymentID = "";
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(deploymentIdSql.toString());
|
createSQLQuery.setString(0, processDefinitionKey);
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List<?> list = createSQLQuery.list();
|
if (list != null && list.size() > 0) {
|
deploymentID = String.valueOf(list.get(0));
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
return deploymentID;
|
}
|
|
/**
|
* 获取某个任务的全部用户
|
*
|
* @param taskName 任务名称
|
* @param deploymentId 部署ID
|
* @return
|
*/
|
public List<String> getAllUserListForTask(String taskName, String deploymentId, String outcome) {
|
List<String> allUserList = new ArrayList<String>();
|
List<TaskDescSObject> taskDescList = this.getTaskDescList(taskName, deploymentId);
|
try {
|
String curCandidates = getNextCandidatesAndRoleAndDept(deploymentId, taskName, outcome);
|
allUserList.add(curCandidates);
|
} catch (Exception e1) {
|
e1.printStackTrace();
|
}
|
for (TaskDescSObject taskDescSObject : taskDescList) {
|
String plcustomclassname = taskDescSObject.getPlcustomclassname();
|
String plcustomparam = taskDescSObject.getPlcustomparam();
|
Class<?> cls;
|
try {
|
cls = Class.forName(plcustomclassname);
|
CustomUserClassInterface res = (CustomUserClassInterface) cls.getConstructor().newInstance();
|
List<String> customUserList = res.getCustomUserList(plcustomparam);
|
for (String customUser : customUserList) {
|
allUserList.add(customUser);
|
}
|
} catch (ClassNotFoundException e) {
|
e.printStackTrace();
|
} catch (IllegalArgumentException e) {
|
e.printStackTrace();
|
} catch (SecurityException e) {
|
e.printStackTrace();
|
} catch (InstantiationException e) {
|
e.printStackTrace();
|
} catch (IllegalAccessException e) {
|
e.printStackTrace();
|
} catch (InvocationTargetException e) {
|
e.printStackTrace();
|
} catch (NoSuchMethodException e) {
|
e.printStackTrace();
|
}
|
}
|
return allUserList;
|
}
|
|
/**
|
* 将自定义用户添加到任务候选人中
|
*
|
* @param taskService
|
* @param taskDescList
|
* @param nextTaskId
|
*/
|
private void setCustomUserForAssgin(TaskService taskService, List<?> taskDescList, String nextTaskId) {
|
for (int i = 0; i < taskDescList.size(); i++) {
|
TaskDescSObject taskDescSObject = (TaskDescSObject) taskDescList.get(i);
|
String plcustomclassname = taskDescSObject.getPlcustomclassname();
|
String plcustomparam = taskDescSObject.getPlcustomparam();
|
if (plcustomclassname != null && !"".equals(plcustomclassname)) {
|
Class<?> cls;
|
try {
|
cls = Class.forName(plcustomclassname);
|
CustomUserClassInterface res = (CustomUserClassInterface) cls.getConstructor().newInstance();
|
List<String> customUserList = res.getCustomUserList(plcustomparam);
|
List<Participation> taskParticipations = taskService.getTaskParticipations(nextTaskId);
|
// 先删除原来的任务候选人
|
for (Participation participation : taskParticipations) {
|
taskService.removeTaskParticipatingUser(nextTaskId, participation.getUserId(),
|
Participation.CANDIDATE);
|
}
|
for (String customUser : customUserList) {
|
taskService.addTaskParticipatingUser(nextTaskId, customUser, Participation.CANDIDATE);
|
}
|
} catch (ClassNotFoundException e) {
|
e.printStackTrace();
|
} catch (IllegalArgumentException e) {
|
e.printStackTrace();
|
} catch (SecurityException e) {
|
e.printStackTrace();
|
} catch (InstantiationException e) {
|
e.printStackTrace();
|
} catch (IllegalAccessException e) {
|
e.printStackTrace();
|
} catch (InvocationTargetException e) {
|
e.printStackTrace();
|
} catch (NoSuchMethodException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
}
|
|
/**
|
* 获取流程部署ID
|
*
|
* @param processDefinitionKey
|
* @param impl
|
* @return
|
*/
|
public BigDecimal getDeploymentID(String processDefinitionKey) {
|
FlowInstanceDaoImpl impl = new FlowInstanceDaoImpl();
|
String sql = "select a.deployment_ from jbpm4_deployprop a where a.stringval_ ='" + processDefinitionKey + "'";
|
List<?> deploymenIds = impl.findEntitesBySQL(sql, new Object[0], new HashMap());
|
BigDecimal deploymentId = (BigDecimal) deploymenIds.get(0);
|
return deploymentId;
|
}
|
|
private String getObjectStatus__(FlowInstanceInfo var, String objId) {
|
String res = "0,0";
|
Session session = HibernateSessionFactory.getSession();
|
StringBuffer sql = new StringBuffer();
|
String processType = var.processType;
|
// Object[] params = new Object[] { objId };
|
int flag = 0;
|
if ("EBOM".equalsIgnoreCase(processType)) {
|
flag = 1;
|
sql.append("select STATUS from EBOMPRODTABLE where PRODID = ?");
|
} else if ("MBOM".equalsIgnoreCase(processType)) {
|
flag = 2;
|
sql.append("select l.operation,l.status from MBOMPRODTABLE l "
|
+ "where l.prodoid = (select d.plprodid || '/' || d.plversion from PLMBOMPROD d where d.ploid = ?)");
|
} else {
|
flag = 3;
|
sql.append("select PLSTATUS from ");
|
sql.append(var.tableName);
|
sql.append(" where PLOID = ?");
|
}
|
ServerWithLog4j.logger.debug("work_flow_sql = " + sql.toString());
|
final Integer[] flagArray = new Integer[] { flag };
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List<?> list = createSQLQuery.list();
|
if (flagArray[0] != 1) {
|
if (list != null && list.size() > 0) {
|
res = String.valueOf(list.get(0));
|
}
|
}
|
return res;
|
}
|
|
private String getObjectStatus(FlowInstanceInfo var, String objId) {
|
return getObjectStatus__(var, objId);
|
}
|
|
/**
|
* 代办任务查询总数
|
*
|
* @param pluseroid
|
* @param expandSql 扩展查询条件
|
* @return
|
*/
|
public int queryTodoTaskCount(String pluseroid, String expandSql) {
|
StringBuilder sql = new StringBuilder();
|
int res = 0;
|
sql.append("select count(*) from( ");
|
sql.append("select DBID_, taskName,createTime, EXECUTION_, PLDESC,plprocesstype,PROCESSNAME ");
|
sql.append(" from( ");
|
|
sql.append(
|
"(select t1.DBID_, t1.NAME_ as taskName, t1.CREATE_ as createTime, t1.EXECUTION_ID_ as EXECUTION_, i.PLDESC,i.plprocesstype,i.PROCESSNAME");
|
sql.append(" from JBPM4_TASK t1 left join PLFLOWINSTANCE i on t1.EXECUTION_ID_ like (i.PLEXECUTIONID||'%')");
|
sql.append(" where t1.ASSIGNEE_=?");
|
sql.append(" )union(");
|
|
sql.append(
|
" select t.DBID_, t.NAME_ as taskName, t.CREATE_ as createTime, t.EXECUTION_ID_, i.PLDESC,i.plprocesstype,i.PROCESSNAME");
|
sql.append(
|
" from JBPM4_TASK t cross join JBPM4_PARTICIPATION participat1_ left join PLFLOWINSTANCE i on t.EXECUTION_ID_ like (i.PLEXECUTIONID||'%')");
|
sql.append(
|
" where participat1_.TASK_=t.DBID_ and participat1_.TYPE_='candidate' and participat1_.USERID_ = ? ");
|
sql.append(" and (t.ASSIGNEE_ is null) )");
|
|
sql.append(" ) ");
|
sql.append(" where 1=1 ");
|
sql.append(" and EXECUTION_ is not null ");
|
if (expandSql != null && !"".equals(expandSql)) {
|
sql.append(expandSql);
|
}
|
sql.append(" ) ");
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
createSQLQuery.setString(0, pluseroid);
|
createSQLQuery.setString(1, pluseroid);
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List<?> list = createSQLQuery.list();
|
if (list != null && list.size() > 0) {
|
res = Integer.parseInt(String.valueOf(list.get(0)));
|
}
|
} catch (Exception ex) {
|
ex.printStackTrace();
|
} finally {
|
|
}
|
return res;
|
}
|
|
/**
|
* 待办任务
|
*
|
* @param pluseroid
|
* @param first
|
* @param pageSize
|
* @param taskType
|
* @param SQL
|
* @return
|
*/
|
public FlowTaskInfo[] getTodoTaskByUserId(String pluseroid, int first, int pageSize, String taskType, String SQL) {
|
List<FlowTaskInfo> flowTaskInfos = new ArrayList<FlowTaskInfo>();
|
|
StringBuilder sql = new StringBuilder();
|
sql.append(
|
"select DBID_, taskName, createTime, EXECUTION_ID_, PLDESC ,PLTEMPLATENAME,PLCREATOR,plprocesstype,PROCESSNAME");
|
sql.append(" from( ");
|
sql.append(
|
"select rownum rn, DBID_, taskName,createTime, EXECUTION_ID_, PLDESC ,PLTEMPLATENAME,PLCREATOR,plprocesstype,PROCESSNAME");
|
sql.append(" from( ");
|
sql.append(
|
"(select t1.DBID_, t1.NAME_ as taskName, t1.CREATE_ as createTime, t1.EXECUTION_ID_, i.PLDESC, i.PLTEMPLATENAME,i.pltasktype,i.plcreator,i.plprocesstype,i.PROCESSNAME");
|
sql.append(" from JBPM4_TASK t1 left join PLFLOWINSTANCE i on t1.EXECUTION_ID_ like(i.PLEXECUTIONID||'%')");
|
sql.append(" where t1.ASSIGNEE_=?");
|
sql.append(" )union(");
|
sql.append(
|
" select t.DBID_, t.NAME_, t.CREATE_ as createTime, t.EXECUTION_ID_, i.PLDESC, i.PLTEMPLATENAME,i.pltasktype,i.plcreator,i.plprocesstype,i.PROCESSNAME");
|
sql.append(
|
" from JBPM4_TASK t cross join JBPM4_PARTICIPATION participat1_ left join PLFLOWINSTANCE i on t.EXECUTION_ID_ like(i.PLEXECUTIONID||'%')");
|
sql.append(" where participat1_.TASK_=t.DBID_ and participat1_.TYPE_='candidate' and participat1_.USERID_=? ");// and
|
// (t.ASSIGNEE_
|
// is
|
// null)
|
sql.append(")");
|
// add by xchao 2013.06.06 end
|
// 排序参数
|
String orderBy = " order by createTime desc";
|
sql.append(orderBy);
|
sql.append(" ) ");
|
sql.append(" where 1=1 ");
|
String[] taskTypes = null;
|
if (taskType != null && !"".equals(taskType)) {
|
sql.append(" and pltasktype in ( ");
|
taskTypes = taskType.split(",");
|
for (int i = 0; i < taskTypes.length; i++) {
|
sql.append("?");
|
if (i < taskTypes.length - 1) {
|
sql.append(",");
|
}
|
}
|
sql.append(" )");
|
}
|
if (SQL != null && !"".equals(SQL)) {
|
sql.append(SQL);
|
}
|
if (first == 0 && pageSize == 0) {
|
sql.append(" and EXECUTION_ID_ is not null ");
|
sql.append(orderBy);
|
sql.append(" ) ");
|
} else {
|
sql.append(" and rownum <= " + first * pageSize);
|
sql.append(" and EXECUTION_ID_ is not null ");
|
sql.append(orderBy);
|
sql.append(")");
|
sql.append(" where rn >" + (first - 1) * pageSize);
|
}
|
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
createSQLQuery.setString(0, pluseroid);
|
createSQLQuery.setString(1, pluseroid);
|
if (taskType != null && !"".equals(taskType)) {
|
for (int i = 0; i < taskTypes.length; i++) {
|
createSQLQuery.setString(2 + i, taskTypes[i]);
|
}
|
}
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List<?> list = createSQLQuery.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] object = (Object[]) list.get(i);
|
FlowTaskInfo flowHistoryTaskInfo = new FlowTaskInfo();
|
String taskId = String.valueOf(object[0]);
|
String taskName = (String) object[1];
|
Timestamp createTime = (Timestamp) object[2];
|
String executionId = (String) object[3];
|
String desc = (String) object[4];
|
String applyPerson = (String) object[6];
|
String processType = (String) object[7];
|
String plprocessName = (String) object[8];
|
flowHistoryTaskInfo.id = taskId == null ? "" : taskId;
|
flowHistoryTaskInfo.name = taskName == null ? "" : taskName;
|
flowHistoryTaskInfo.createTime = createTime.getTime();
|
flowHistoryTaskInfo.executionId = executionId == null ? "" : executionId;
|
flowHistoryTaskInfo.desc = desc == null ? "" : desc;
|
flowHistoryTaskInfo.applyPerson = applyPerson == null ? "" : applyPerson;
|
flowHistoryTaskInfo.templateName = (String) (object[5] == null ? "" : object[5]);
|
flowHistoryTaskInfo.processType = processType == null ? "" : processType;
|
flowHistoryTaskInfo.processName = plprocessName == null ? "" : plprocessName;
|
flowTaskInfos.add(flowHistoryTaskInfo);
|
}
|
} catch (Exception ex) {
|
ex.printStackTrace();
|
} finally {
|
|
}
|
return flowTaskInfos.toArray(new FlowTaskInfo[0]);
|
}
|
|
/**
|
* 待办任务(可查询,可排序)
|
*
|
* @param pluseroid
|
* @param first
|
* @param pageSize
|
* @param taskType
|
* @param SQL 自定义查询条件
|
* @param orderStr 自定义排序字段(以order by开头)
|
* @return
|
*/
|
public FlowTaskInfo[] getTodoTaskCompositorByUserId(String pluseroid, int first, int pageSize, String taskType,
|
String SQL, String orderStr) {
|
List<FlowTaskInfo> flowTaskInfos = new ArrayList<FlowTaskInfo>();
|
// 开始时间
|
long startTime = System.currentTimeMillis();
|
ServerWithLog4j.logger.debug("startTime:" + startTime);
|
StringBuilder sql = new StringBuilder();
|
sql.append(
|
"select DBID_, taskName, createTime, EXECUTION_ID_, PLDESC ,PLTEMPLATENAME,PLCREATOR,plprocesstype,PROCESSNAME");
|
sql.append(" from( ");
|
sql.append(
|
"select rownum rn, DBID_, taskName,createTime, EXECUTION_ID_, PLDESC ,PLTEMPLATENAME,PLCREATOR,plprocesstype,PROCESSNAME");
|
sql.append(" from( ");
|
sql.append(
|
"(select t1.DBID_, t1.NAME_ as taskName, t1.CREATE_ as createTime, t1.EXECUTION_ID_, i.PLDESC, i.PLTEMPLATENAME,i.pltasktype,i.plcreator,i.plprocesstype,i.PROCESSNAME");
|
sql.append(" from JBPM4_TASK t1 left join PLFLOWINSTANCE i on t1.EXECUTION_ID_ like (i.PLEXECUTIONID||'%')");
|
sql.append(" where t1.ASSIGNEE_=?");
|
sql.append(" )union(");
|
sql.append(
|
" select t.DBID_, t.NAME_, t.CREATE_ as createTime, t.EXECUTION_ID_, i.PLDESC, i.PLTEMPLATENAME,i.pltasktype,i.plcreator,i.plprocesstype,i.PROCESSNAME");
|
sql.append(
|
" from JBPM4_TASK t cross join JBPM4_PARTICIPATION participat1_ left join PLFLOWINSTANCE i on t.EXECUTION_ID_ like (i.PLEXECUTIONID||'%')");
|
sql.append(" where participat1_.TASK_=t.DBID_ and participat1_.TYPE_='candidate' and participat1_.USERID_=? ");// and
|
// (t.ASSIGNEE_
|
// is
|
// null)
|
sql.append(")");
|
// add by xchao 2013.06.06 end
|
// 排序参数
|
String orderBy = " order by createTime desc";
|
if (orderStr != null && !"".equals(orderStr)) {
|
orderBy = " " + orderStr + " ";
|
}
|
sql.append(orderBy);
|
sql.append(" ) ");
|
sql.append(" where 1=1 ");
|
String[] taskTypes = null;
|
if (taskType != null && !"".equals(taskType)) {
|
sql.append(" and pltasktype in ( ");
|
taskTypes = taskType.split(",");
|
for (int i = 0; i < taskTypes.length; i++) {
|
sql.append("?");
|
if (i < taskTypes.length - 1) {
|
sql.append(",");
|
}
|
}
|
sql.append(" )");
|
}
|
if (SQL != null && !"".equals(SQL)) {
|
sql.append(SQL);
|
}
|
if (first == 0 && pageSize == 0) {
|
sql.append(" and EXECUTION_ID_ is not null ");
|
// sql.append(orderBy);
|
sql.append(" ) ");
|
} else {
|
sql.append(" and rownum <= " + first * pageSize);
|
sql.append(" and EXECUTION_ID_ is not null ");
|
// sql.append(orderBy);
|
sql.append(")");
|
sql.append(" where rn >" + (first - 1) * pageSize);
|
}
|
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
createSQLQuery.setString(0, pluseroid);
|
createSQLQuery.setString(1, pluseroid);
|
if (taskType != null && !"".equals(taskType)) {
|
for (int i = 0; i < taskTypes.length; i++) {
|
createSQLQuery.setString(2 + i, taskTypes[i]);
|
}
|
}
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List<?> list = createSQLQuery.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] object = (Object[]) list.get(i);
|
FlowTaskInfo flowHistoryTaskInfo = new FlowTaskInfo();
|
String taskId = String.valueOf(object[0]);
|
String taskName = (String) object[1];
|
Timestamp createTime = (Timestamp) object[2];
|
String executionId = (String) object[3];
|
String desc = (String) object[4];
|
String applyPerson = (String) object[6];
|
String processType = (String) object[7];
|
String plprocessName = (String) object[8];
|
flowHistoryTaskInfo.id = taskId == null ? "" : taskId;
|
flowHistoryTaskInfo.name = taskName == null ? "" : taskName;
|
flowHistoryTaskInfo.createTime = createTime.getTime();
|
flowHistoryTaskInfo.executionId = executionId == null ? "" : executionId;
|
flowHistoryTaskInfo.desc = desc == null ? "" : desc;
|
flowHistoryTaskInfo.applyPerson = applyPerson == null ? "" : applyPerson;
|
flowHistoryTaskInfo.templateName = (String) (object[5] == null ? "" : object[5]);
|
flowHistoryTaskInfo.processType = processType == null ? "" : processType;
|
flowHistoryTaskInfo.processName = plprocessName == null ? "" : plprocessName;
|
flowTaskInfos.add(flowHistoryTaskInfo);
|
}
|
} catch (Exception ex) {
|
ex.printStackTrace();
|
} finally {
|
|
}
|
// 结束时间
|
long endTime = System.currentTimeMillis();
|
ServerWithLog4j.logger.debug("endTime:" + endTime);
|
ServerWithLog4j.logger.debug("程序运行时间:" + (endTime - startTime) + "ms");
|
return flowTaskInfos.toArray(new FlowTaskInfo[0]);
|
}
|
|
/**
|
* 跟踪任务
|
*
|
* @param pluseroid
|
* @param first
|
* @param pageSize
|
* @param taskType
|
* @param querySQL
|
* @return
|
*/
|
public FlowTaskInfo[] getTrackTaskByUserId(String pluseroid, int first, int pageSize, String taskType,
|
String querySQL) {
|
// ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
|
List<FlowTaskInfo> flowTaskInfos = new ArrayList<FlowTaskInfo>();
|
StringBuilder sql = new StringBuilder();
|
sql.append(
|
" select distinct EXECUTION_, activityname_, max(CREATE_) CREATE_, PLDESC, PLTEMPLATENAME,PLCREATOR,PROCESSNAME from (");
|
// 我发起的流程脚本
|
sql.append(
|
" select DBID_, activityname_, CREATE_, EXECUTION_, PLDESC, PLTEMPLATENAME,PLCREATOR,state_,PROCESSNAME");
|
sql.append(" from ( ");
|
sql.append(
|
" select rownum rn,DBID_, activityname_, CREATE_, EXECUTION_, PLDESC, PLTEMPLATENAME,PLCREATOR ,state_,PROCESSNAME");
|
sql.append(" from( ");
|
sql.append(
|
"select k.DBID_, n.activityname_, k.CREATE_, k.EXECUTION_, e.PLDESC, e.PLTEMPLATENAME,e.pltasktype,e.PLCREATOR,k.state_,e.PROCESSNAME");
|
sql.append(" from PLFLOWINSTANCE e join jbpm4_execution n on n.id_ like(e.plexecutionid||'%') ");
|
sql.append(" and e.plapplicant = ? ");
|
sql.append(
|
" join JBPM4_HIST_TASK k on n.id_ = k.execution_ and k.state_ is null and n.activityname_ is not null ");
|
sql.append(" order by k.create_ desc");
|
sql.append(" )where 1=1 ");
|
if (taskType != null && !"".equals(taskType)) {
|
sql.append(" and pltasktype in ( ");
|
String[] taskTypes = taskType.split(",");
|
String taskTypesStr = "";
|
for (int i = 0; i < taskTypes.length; i++) {
|
taskTypesStr += "'" + taskTypes[i] + "',";
|
}
|
sql.append(taskTypesStr.substring(0, taskTypesStr.length() - 1));
|
sql.append(" )");
|
}
|
if (querySQL != "") {
|
sql.append(querySQL);
|
}
|
sql.append(" and rownum <= " + first * pageSize);
|
sql.append(" ) ");
|
sql.append(" where rn >" + (first - 1) * pageSize);
|
|
sql.append("union");
|
|
// 我参与的流程脚本
|
sql.append(
|
" select DBID_, activityname_, CREATE_, EXECUTION_, PLDESC, PLTEMPLATENAME,PLCREATOR,state_,PROCESSNAME");
|
sql.append(" from ( ");
|
sql.append(
|
" select rownum rn,DBID_, activityname_, CREATE_, EXECUTION_, PLDESC, PLTEMPLATENAME,PLCREATOR,state_,PROCESSNAME ");
|
sql.append(" from( ");
|
sql.append(
|
"select k.DBID_, n.activityname_, k.CREATE_, k.EXECUTION_, e.PLDESC, e.PLTEMPLATENAME,e.pltasktype,e.PLCREATOR,k.state_,e.PROCESSNAME");
|
sql.append(" from PLFLOWINSTANCE e join jbpm4_execution n on n.id_ like(e.plexecutionid||'%') ");
|
sql.append(
|
" join JBPM4_HIST_TASK k on e.plexecutionid = k.execution_ and n.activityname_ is not null and k.assignee_=?");
|
sql.append(" order by k.create_ desc");
|
sql.append(" )where 1=1 ");
|
if (taskType != null && !"".equals(taskType)) {
|
sql.append(" and pltasktype in ( ");
|
String[] taskTypes1 = taskType.split(",");
|
String taskTypes1Str = "";
|
for (int i = 0; i < taskTypes1.length; i++) {
|
taskTypes1Str += "'" + taskTypes1[i] + "',";
|
}
|
sql.append(taskTypes1Str.substring(0, taskTypes1Str.length() - 1));
|
sql.append(" )");
|
}
|
if (querySQL != "") {
|
sql.append(querySQL);
|
}
|
sql.append(" and rownum <= " + first * pageSize);
|
sql.append(" ) ");
|
sql.append(" where rn >" + (first - 1) * pageSize);
|
sql.append(") group by EXECUTION_,activityname_,PLDESC,PLTEMPLATENAME,PLCREATOR,PROCESSNAME "
|
+ " order by CREATE_ desc");
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
createSQLQuery.setString(0, pluseroid);
|
createSQLQuery.setString(1, pluseroid);
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
List<?> list = createSQLQuery.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] object = (Object[]) list.get(i);
|
FlowTaskInfo flowTaskInfo = new FlowTaskInfo();
|
String taskId = "";
|
|
String executionId = String.valueOf(object[0]);
|
String taskName = (String) object[1];
|
Timestamp createTime = (Timestamp) object[2];
|
String desc = (String) object[3];
|
String applyPerson = (String) object[5];
|
String processname = (String) object[6];
|
flowTaskInfo.id = taskId == null ? "" : taskId;
|
flowTaskInfo.name = taskName == null ? "" : taskName;
|
flowTaskInfo.createTime = createTime.getTime();
|
flowTaskInfo.executionId = executionId == null ? "" : executionId;
|
flowTaskInfo.desc = desc == null ? "" : desc;
|
flowTaskInfo.templateName = (String) (object[4] == null ? "" : object[4]);
|
flowTaskInfo.applyPerson = applyPerson == null ? "" : applyPerson;
|
flowTaskInfo.processName = processname == null ? "" : processname;
|
flowTaskInfos.add(flowTaskInfo);
|
}
|
} catch (Exception ex) {
|
ex.printStackTrace();
|
} finally {
|
|
}
|
|
return flowTaskInfos.toArray(new FlowTaskInfo[0]);
|
}
|
|
/**
|
* 跟踪任务
|
*
|
* @param pluseroid
|
* @param first
|
* @param pageSize
|
* @param taskType
|
* @param querySQL
|
* @return
|
*/
|
public FlowTaskInfo[] getTrackTaskCompositorByUserId(String pluseroid, int first, int pageSize, String taskType,
|
String querySQL, String orderStr) {
|
// ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
|
List<FlowTaskInfo> flowTaskInfos = new ArrayList<FlowTaskInfo>();
|
StringBuilder sql = new StringBuilder();
|
sql.append(
|
" select distinct EXECUTION_, activityname_, max(CREATE_) CREATE_, PLDESC, PLTEMPLATENAME,PLCREATOR from (");
|
// 我发起的流程脚本
|
sql.append(" select DBID_, activityname_, CREATE_, EXECUTION_, PLDESC, PLTEMPLATENAME,PLCREATOR,state_");
|
sql.append(" from ( ");
|
sql.append(
|
" select rownum rn,DBID_, activityname_, CREATE_, EXECUTION_, PLDESC, PLTEMPLATENAME,PLCREATOR ,state_");
|
sql.append(" from( ");
|
sql.append(
|
"select k.DBID_, n.activityname_, k.CREATE_, k.EXECUTION_, e.PLDESC, e.PLTEMPLATENAME,e.pltasktype,e.PLCREATOR,k.state_");
|
sql.append(" from PLFLOWINSTANCE e join jbpm4_execution n on n.id_ like(e.plexecutionid||'%') ");
|
sql.append(" and e.plapplicant = ? ");
|
sql.append(
|
" join JBPM4_HIST_TASK k on n.id_ = k.execution_ and k.state_ is null and n.activityname_ is not null ");
|
// sql.append(" order by k.create_ desc");
|
sql.append(" )where 1=1 ");
|
if (taskType != null && !"".equals(taskType)) {
|
sql.append(" and pltasktype in ( ");
|
String[] taskTypes = taskType.split(",");
|
String taskTypesStr = "";
|
for (int i = 0; i < taskTypes.length; i++) {
|
taskTypesStr += "'" + taskTypes[i] + "',";
|
}
|
sql.append(taskTypesStr.substring(0, taskTypesStr.length() - 1));
|
sql.append(" )");
|
}
|
if (querySQL != "") {
|
sql.append(querySQL);
|
}
|
sql.append(" and rownum <= " + first * pageSize);
|
sql.append(" ) ");
|
sql.append(" where rn >" + (first - 1) * pageSize);
|
|
sql.append("union");
|
|
// 我参与的流程脚本
|
sql.append(" select DBID_, activityname_, CREATE_, EXECUTION_, PLDESC, PLTEMPLATENAME,PLCREATOR,state_");
|
sql.append(" from ( ");
|
sql.append(
|
" select rownum rn,DBID_, activityname_, CREATE_, EXECUTION_, PLDESC, PLTEMPLATENAME,PLCREATOR,state_ ");
|
sql.append(" from( ");
|
sql.append(
|
"select k.DBID_, n.activityname_, k.CREATE_, k.EXECUTION_, e.PLDESC, e.PLTEMPLATENAME,e.pltasktype,e.PLCREATOR,k.state_");
|
sql.append(" from PLFLOWINSTANCE e join jbpm4_execution n on n.id_ like(e.plexecutionid||'%') ");
|
sql.append(
|
" join JBPM4_HIST_TASK k on e.plexecutionid = k.execution_ and n.activityname_ is not null and k.assignee_=?");
|
// sql.append(" order by k.create_ desc");
|
sql.append(" )where 1=1 ");
|
if (taskType != null && !"".equals(taskType)) {
|
sql.append(" and pltasktype in ( ");
|
String[] taskTypes1 = taskType.split(",");
|
String taskTypes1Str = "";
|
for (int i = 0; i < taskTypes1.length; i++) {
|
taskTypes1Str += "'" + taskTypes1[i] + "',";
|
}
|
sql.append(taskTypes1Str.substring(0, taskTypes1Str.length() - 1));
|
sql.append(" )");
|
}
|
if (querySQL != "") {
|
sql.append(querySQL);
|
}
|
sql.append(" and rownum <= " + first * pageSize);
|
sql.append(" ) ");
|
sql.append(" where rn >" + (first - 1) * pageSize);
|
// 排序
|
String orderBy = " order by CREATE_ desc";
|
if (orderStr != null && !"".equals(orderStr)) {
|
orderBy = " " + orderStr + " ";
|
}
|
sql.append(") group by EXECUTION_,activityname_,PLDESC,PLTEMPLATENAME,PLCREATOR " + orderBy);
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
createSQLQuery.setString(0, pluseroid);
|
createSQLQuery.setString(1, pluseroid);
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
List<?> list = createSQLQuery.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] object = (Object[]) list.get(i);
|
FlowTaskInfo flowTaskInfo = new FlowTaskInfo();
|
String taskId = "";
|
|
String executionId = String.valueOf(object[0]);
|
String taskName = (String) object[1];
|
Timestamp createTime = (Timestamp) object[2];
|
String desc = (String) object[3];
|
String applyPerson = (String) object[5];
|
flowTaskInfo.id = taskId == null ? "" : taskId;
|
flowTaskInfo.name = taskName == null ? "" : taskName;
|
flowTaskInfo.createTime = createTime.getTime();
|
flowTaskInfo.executionId = executionId == null ? "" : executionId;
|
flowTaskInfo.desc = desc == null ? "" : desc;
|
flowTaskInfo.templateName = (String) (object[4] == null ? "" : object[4]);
|
flowTaskInfo.applyPerson = applyPerson == null ? "" : applyPerson;
|
flowTaskInfos.add(flowTaskInfo);
|
}
|
} catch (Exception ex) {
|
ex.printStackTrace();
|
} finally {
|
|
}
|
|
return flowTaskInfos.toArray(new FlowTaskInfo[0]);
|
}
|
|
public int queryTraceTaskCount(String pluseroid, String expandSql) {
|
int res = 0;
|
StringBuilder sql = new StringBuilder();
|
|
sql.append(
|
" select Count(*) from ( select distinct EXECUTION_, activityname_, max(CREATE_) CREATE_, PLDESC, PLTEMPLATENAME,PLCREATOR from (");
|
// 我发起的流程脚本
|
sql.append(" select DBID_, activityname_, CREATE_, EXECUTION_, PLDESC, PLTEMPLATENAME,PLCREATOR,state_");
|
sql.append(" from ( ");
|
sql.append(
|
" select rownum rn,DBID_, activityname_, CREATE_, EXECUTION_, PLDESC, PLTEMPLATENAME,PLCREATOR ,state_");
|
sql.append(" from( ");
|
sql.append(
|
"select k.DBID_, n.activityname_, k.CREATE_, k.EXECUTION_, e.PLDESC, e.PLTEMPLATENAME,e.pltasktype,e.PLCREATOR,k.state_");
|
sql.append(" from PLFLOWINSTANCE e join jbpm4_execution n on n.id_ like(e.plexecutionid||'%') ");
|
sql.append(" and e.plapplicant = ? ");
|
sql.append(
|
" join JBPM4_HIST_TASK k on k.execution_ like(e.plexecutionid||'%') and k.state_ is null and n.activityname_ is not null ");
|
sql.append(" order by k.create_ desc");
|
sql.append(" )where 1=1 ");
|
|
if (expandSql != null && !"".equals(expandSql)) {
|
sql.append(expandSql);
|
}
|
sql.append(" ) ");
|
|
sql.append("union");
|
|
// 我参与的流程脚本
|
sql.append(" select DBID_, activityname_, CREATE_, EXECUTION_, PLDESC, PLTEMPLATENAME,PLCREATOR,state_");
|
sql.append(" from ( ");
|
sql.append(
|
" select rownum rn,DBID_, activityname_, CREATE_, EXECUTION_, PLDESC, PLTEMPLATENAME,PLCREATOR,state_ ");
|
sql.append(" from( ");
|
sql.append(
|
"select k.DBID_, n.activityname_, k.CREATE_, k.EXECUTION_, e.PLDESC, e.PLTEMPLATENAME,e.pltasktype,e.PLCREATOR,k.state_");
|
sql.append(" from PLFLOWINSTANCE e join jbpm4_execution n on e.plexecutionid = n.id_ ");
|
sql.append(
|
" join JBPM4_HIST_TASK k on e.plexecutionid = k.execution_ and n.activityname_ is not null and k.assignee_=?");
|
sql.append(" order by k.create_ desc");
|
sql.append(" )where 1=1 ");
|
|
if (expandSql != null && !"".equals(expandSql)) {
|
sql.append(expandSql);
|
}
|
sql.append(" ) ");
|
sql.append(") ");
|
sql.append("group by EXECUTION_,activityname_,PLDESC,PLTEMPLATENAME,PLCREATOR ) ");
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
createSQLQuery.setString(0, pluseroid);
|
createSQLQuery.setString(1, pluseroid);
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List<?> list = createSQLQuery.list();
|
if (list != null && list.size() > 0) {
|
res = Integer.parseInt(String.valueOf(list.get(0)));
|
}
|
|
} catch (Exception ex) {
|
ex.printStackTrace();
|
} finally {
|
|
}
|
|
return res;
|
}
|
|
/**
|
* 我发起的流程 2013-4-9
|
*
|
* @param pluseroid
|
* @param first
|
* @param pageSize
|
* @param expandSql
|
* @return
|
*/
|
public FlowTaskInfo[] getMyTrackProcessByUserId(String pluseroid, int first, int pageSize, String expandSql) {
|
// ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
|
List<FlowTaskInfo> flowTaskInfos = new ArrayList<FlowTaskInfo>();
|
StringBuilder sql = new StringBuilder();
|
sql.append(
|
" select createTime, EXECUTION_, PLDESC, plprocesstype, plclsfoid, state_ ,processname,PLTEMPLATENAME");
|
sql.append(" from ( ");
|
sql.append(
|
" select rownum rn, createTime, EXECUTION_, PLDESC, plprocesstype, plclsfoid, state_,processname,PLTEMPLATENAME");
|
sql.append(" from( ");
|
sql.append(
|
" select createTime, EXECUTION_, PLDESC, plprocesstype, plclsfoid, state_,processname,PLTEMPLATENAME");
|
sql.append(" from( ");
|
sql.append(
|
"select k.start_ as createTime, k.id_ as EXECUTION_, e.PLDESC, e.plprocesstype, e.plclsfoid, k.state_,e.processname,e.PLTEMPLATENAME");
|
sql.append(" from PLFLOWINSTANCE e join jbpm4_hist_procinst k on e.plexecutionid = k.id_ ");
|
sql.append(" where 1=1 ");
|
if (!"sysAdmin".equals(pluseroid)) {
|
sql.append(" and e.plapplicant = ? ");
|
}
|
sql.append(" ) where 1=1 ");
|
if (expandSql != null && !"".equals(expandSql)) {
|
sql.append(expandSql);
|
}
|
sql.append("order by createTime desc");
|
sql.append(" ))where 1=1 ");
|
sql.append(" and rn <= " + first * pageSize);
|
sql.append(" and rn >" + (first - 1) * pageSize);
|
ServerWithLog4j.logger.debug("track task sql=" + sql);
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
|
if (!"sysAdmin".equals(pluseroid)) {
|
createSQLQuery.setString(0, pluseroid);
|
}
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
List<?> list = createSQLQuery.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] object = (Object[]) list.get(i);
|
FlowTaskInfo flowTaskInfo = new FlowTaskInfo();
|
String taskId = "";
|
|
String taskName = "";
|
Timestamp createTime = (Timestamp) object[0];
|
String executionId = String.valueOf(object[1]);
|
String desc = (String) object[2];
|
String processType = (String) object[3];
|
String flowState = (String) object[5];
|
// 添加分类路径
|
String plclsfoid = String.valueOf(object[4]);
|
String processName = (String) object[6];
|
String templateName = (String) object[7];
|
flowTaskInfo.plclsfoid = plclsfoid == null ? "" : plclsfoid;
|
|
// 获得发起人名称
|
List<FlowApproveHistory> historyActivityByProInsId = this.getHistoryActivityByExcetionID(session,
|
executionId);
|
if (historyActivityByProInsId != null && historyActivityByProInsId.size() > 0) {
|
String assignee = historyActivityByProInsId.get(0).getAssignee();
|
flowTaskInfo.plAssgin = assignee == null ? "" : assignee;
|
}
|
|
flowTaskInfo.id = taskId == null ? "" : taskId;
|
flowTaskInfo.name = taskName == null ? "" : taskName;
|
flowTaskInfo.createTime = createTime.getTime();
|
flowTaskInfo.executionId = executionId == null ? "" : executionId;
|
flowTaskInfo.desc = desc == null ? "" : desc;
|
flowTaskInfo.processType = processType == null ? "" : processType;
|
flowTaskInfo.flowState = flowState == null ? "" : flowState;
|
flowTaskInfo.processName = processName == null ? "" : processName;
|
flowTaskInfo.templateName = templateName == null ? "" : templateName;
|
flowTaskInfos.add(flowTaskInfo);
|
}
|
} catch (Exception ex) {
|
ex.printStackTrace();
|
} finally {
|
|
}
|
|
return flowTaskInfos.toArray(new FlowTaskInfo[0]);
|
}
|
|
/**
|
* 我发起的流程 2013-4-9
|
*
|
* @param pluseroid
|
* @param first
|
* @param pageSize
|
* @param expandSql
|
* @return
|
*/
|
public FlowTaskInfo[] getMyTrackProcessCompositorByUserId(String pluseroid, int first, int pageSize,
|
String expandSql, String orderStr) {
|
// ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
|
List<FlowTaskInfo> flowTaskInfos = new ArrayList<FlowTaskInfo>();
|
StringBuilder sql = new StringBuilder();
|
sql.append(
|
" select createTime, EXECUTION_, PLDESC, plprocesstype, plclsfoid, state_ ,processname,PLTEMPLATENAME");
|
sql.append(" from ( ");
|
sql.append(
|
" select rownum rn, createTime, EXECUTION_, PLDESC, plprocesstype, plclsfoid, state_,processname,PLTEMPLATENAME");
|
sql.append(" from( ");
|
sql.append(
|
" select createTime, EXECUTION_, PLDESC, plprocesstype, plclsfoid, state_,processname,PLTEMPLATENAME");
|
sql.append(" from( ");
|
sql.append(
|
"select k.start_ as createTime, k.id_ as EXECUTION_, e.PLDESC, e.plprocesstype, e.plclsfoid, k.state_,e.processname,e.PLTEMPLATENAME");
|
sql.append(" from PLFLOWINSTANCE e join jbpm4_hist_procinst k on e.plexecutionid = k.id_ ");
|
sql.append(" where 1=1 ");
|
if (!"sysAdmin".equals(pluseroid)) {
|
sql.append(" and e.plapplicant = ? ");
|
}
|
sql.append(" ) where 1=1 ");
|
if (expandSql != null && !"".equals(expandSql)) {
|
sql.append(expandSql);
|
}
|
// 排序
|
String orderBy = "order by createTime desc";
|
if (orderStr != null && !"".equals(orderStr)) {
|
orderBy = " " + orderStr + " ";
|
}
|
sql.append(orderBy);
|
sql.append(" ))where 1=1 ");
|
sql.append(" and rn <= " + first * pageSize);
|
sql.append(" and rn >" + (first - 1) * pageSize);
|
ServerWithLog4j.logger.debug("track task sql=" + sql);
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
|
if (!"sysAdmin".equals(pluseroid)) {
|
createSQLQuery.setString(0, pluseroid);
|
}
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
List<?> list = createSQLQuery.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] object = (Object[]) list.get(i);
|
FlowTaskInfo flowTaskInfo = new FlowTaskInfo();
|
String taskId = "";
|
|
String taskName = "";
|
Timestamp createTime = (Timestamp) object[0];
|
String executionId = String.valueOf(object[1]);
|
String desc = (String) object[2];
|
String processType = (String) object[3];
|
String flowState = (String) object[5];
|
// 添加分类路径
|
String plclsfoid = String.valueOf(object[4]);
|
String processName = (String) object[6];
|
String templateName = (String) object[7];
|
flowTaskInfo.plclsfoid = plclsfoid == null ? "" : plclsfoid;
|
|
// 获得发起人名称
|
List<FlowApproveHistory> historyActivityByProInsId = this.getHistoryActivityByExcetionID(session,
|
executionId);
|
if (historyActivityByProInsId != null && historyActivityByProInsId.size() > 0) {
|
String assignee = historyActivityByProInsId.get(0).getAssignee();
|
flowTaskInfo.plAssgin = assignee == null ? "" : assignee;
|
}
|
|
flowTaskInfo.id = taskId == null ? "" : taskId;
|
flowTaskInfo.name = taskName == null ? "" : taskName;
|
flowTaskInfo.createTime = createTime.getTime();
|
flowTaskInfo.executionId = executionId == null ? "" : executionId;
|
flowTaskInfo.desc = desc == null ? "" : desc;
|
flowTaskInfo.processType = processType == null ? "" : processType;
|
flowTaskInfo.flowState = flowState == null ? "" : flowState;
|
flowTaskInfo.processName = processName == null ? "" : processName;
|
flowTaskInfo.templateName = templateName == null ? "" : templateName;
|
flowTaskInfos.add(flowTaskInfo);
|
}
|
} catch (Exception ex) {
|
ex.printStackTrace();
|
} finally {
|
|
}
|
|
return flowTaskInfos.toArray(new FlowTaskInfo[0]);
|
}
|
|
/**
|
* 我发起的流程总数
|
*
|
* @param pluseroid
|
* @param expandSql
|
* @return
|
*/
|
public int queryMyTraceProcessCount(String pluseroid, String expandSql) {
|
int res = 0;
|
StringBuilder sql = new StringBuilder();
|
|
sql.append(
|
"select Count(*) from(select * from (select k.start_ as createTime, k.id_ as EXECUTION_, e.PLDESC, e.plprocesstype, e.plclsfoid, k.state_,e.processname");
|
sql.append(" from PLFLOWINSTANCE e join jbpm4_hist_procinst k on e.plexecutionid = k.id_ ");
|
sql.append(" where 1=1 ");
|
if (!"sysAdmin".equals(pluseroid)) {
|
sql.append(" and e.plapplicant = ? ");
|
}
|
sql.append(" ) where 1=1 ");
|
if (expandSql != null && !"".equals(expandSql)) {
|
sql.append(expandSql);
|
}
|
sql.append(" ) ");
|
ServerWithLog4j.logger.debug("track task count sql=" + sql);
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
if (!"sysAdmin".equals(pluseroid)) {
|
createSQLQuery.setString(0, pluseroid);
|
}
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List<?> list = createSQLQuery.list();
|
if (list != null && list.size() > 0) {
|
res = Integer.parseInt(String.valueOf(list.get(0)));
|
}
|
|
} catch (Exception ex) {
|
ex.printStackTrace();
|
} finally {
|
|
}
|
|
return res;
|
}
|
|
/**
|
* 流程监控
|
*
|
* @param pluseroid
|
* @param first
|
* @param pageSize
|
* @param taskType
|
* @param querySQL
|
* @return
|
*/
|
public FlowTaskInfo[] getProcessControlByUserId(String pluseroid, int first, int pageSize, String taskType,
|
String querySQL) {
|
|
List<FlowTaskInfo> flowTaskInfos = new ArrayList<FlowTaskInfo>();
|
StringBuilder sql = new StringBuilder();
|
sql.append(" select dbid,taskname,CREATE_,endtime,executionid,PLDESC,pltemplatename, PLCREATOR from(");
|
// 已完成流程
|
sql.append(
|
" select distinct executionid, rownum as rn, PLCREATOR,CREATE_,endtime,taskname,dbid,PLDESC,pltemplatename from (");
|
sql.append(
|
" select i.plexecutionid as executionid,i.plcreator as PLCREATOR,hp.start_ as CREATE_,hp.end_ as endtime,hp.endactivity_ as taskname,hp.dbid_ as dbid,i.pltasktype as pltasktype,i.pldesc as PLDESC,i.pltemplatename as pltemplatename from PLFLOWINSTANCE i");
|
sql.append(" left join JBPM4_HIST_PROCINST hp on i.plexecutionid = hp.ID_ ");
|
sql.append(" right join jbpm4_execution e on hp.id_ like(hp.id_||'%') where hp.endactivity_ is not null ");
|
sql.append(" union ");
|
// 未完成流程
|
sql.append(
|
" select i.plexecutionid as executionid,i.plcreator as PLCREATOR,hp.start_ as CREATE_,hp.end_ as endtime,e.activityname_ as taskname,hp.dbid_ as dbid,i.pltasktype as pltasktype,i.pldesc as PLDESC,i.pltemplatename as pltemplatename from PLFLOWINSTANCE i");
|
sql.append(" left join JBPM4_HIST_PROCINST hp on i.plexecutionid = hp.ID_ ");
|
sql.append(" right join jbpm4_execution e on hp.id_ like (hp.id_||'%') where e.activityname_ is not null) ");
|
sql.append(" where 1=1 ");
|
if (taskType != null && !"".equals(taskType)) {
|
sql.append(" and pltasktype in ( ");
|
String[] taskTypes = taskType.split(",");
|
String taskTypesStr = "";
|
for (int i = 0; i < taskTypes.length; i++) {
|
taskTypesStr += "'" + taskTypes[i] + "',";
|
}
|
sql.append(taskTypesStr.substring(0, taskTypesStr.length() - 1));
|
sql.append(" )");
|
}
|
// String sqldept = "";
|
if (querySQL != "") {
|
if (querySQL.contains("#")) {
|
String SQL1 = querySQL.substring(0, querySQL.indexOf("#"));
|
// sqldept = querySQL.substring(querySQL.indexOf("#") + 1);
|
sql.append(SQL1);
|
} else {
|
sql.append(querySQL);
|
}
|
}
|
if (first == 0 && pageSize == 0) {
|
sql.append(" ) ");
|
} else {
|
sql.append(" and rownum <= " + first * pageSize);
|
sql.append(" ) ");
|
sql.append(" where rn >" + (first - 1) * pageSize);
|
}
|
sql.append(" and dbid is not null order by create_ desc ");
|
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
List<?> list = createSQLQuery.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] object = (Object[]) list.get(i);
|
FlowTaskInfo flowHistoryTaskInfo = new FlowTaskInfo();
|
String taskId = String.valueOf(object[0]);
|
String taskName = (String) object[1];
|
Timestamp createTime = (Timestamp) object[2];
|
Timestamp endTime = (Timestamp) object[3];
|
String executionId = (String) object[4];
|
String desc = (String) object[5];
|
String templateName = (String) object[6];
|
String createUser = (String) object[7];
|
flowHistoryTaskInfo.id = taskId == null ? "" : taskId;
|
flowHistoryTaskInfo.name = taskName == null ? "" : taskName;
|
if (createTime != null) {
|
flowHistoryTaskInfo.createTime = createTime.getTime();
|
} else {
|
flowHistoryTaskInfo.createTime = 0;
|
}
|
if (endTime != null) {
|
flowHistoryTaskInfo.endTime = endTime.getTime();
|
} else {
|
flowHistoryTaskInfo.endTime = 0;
|
}
|
|
flowHistoryTaskInfo.executionId = executionId == null ? "" : executionId;
|
flowHistoryTaskInfo.desc = desc == null ? "" : desc;
|
flowHistoryTaskInfo.templateName = templateName == null ? "" : templateName;
|
flowHistoryTaskInfo.applyPerson = createUser == null ? "" : createUser;
|
flowTaskInfos.add(flowHistoryTaskInfo);
|
}
|
} catch (Exception ex) {
|
ex.printStackTrace();
|
} finally {
|
|
}
|
|
return flowTaskInfos.toArray(new FlowTaskInfo[0]);
|
}
|
|
/**
|
* 监控流程数量
|
*
|
* @param pluseroid
|
* @param taskType
|
* @return
|
*/
|
public int queryProcessControlCount(String pluseroid, String taskType) {
|
int res = 0;
|
StringBuilder sql = new StringBuilder();
|
|
sql.append(" select Count(*) from (");
|
// 已完成流程
|
sql.append(
|
" select distinct executionid, rownum as rn, creator,starttime,endtime,taskname,dbid,pldesc,pltemplatename from (");
|
sql.append(
|
" select i.plexecutionid as executionid,i.plcreator as creator,hp.start_ as starttime,hp.end_ as endtime,hp.endactivity_ as taskname,hp.dbid_ as dbid,i.pltasktype as pltasktype,i.pldesc as pldesc,i.pltemplatename as pltemplatename from PLFLOWINSTANCE i");
|
sql.append(" left join JBPM4_HIST_PROCINST hp on i.plexecutionid = hp.ID_ ");
|
sql.append(" left join jbpm4_execution e on e.id_ = hp.id_ where hp.endactivity_ is not null ");
|
sql.append(" union ");
|
// 未完成流程
|
sql.append(
|
" select i.plexecutionid as executionid,i.plcreator as creator,hp.start_ as starttime,hp.end_ as endtime,e.activityname_ as taskname,hp.dbid_ as dbid,i.pltasktype as pltasktype,i.pldesc as pldesc,i.pltemplatename as pltemplatename from PLFLOWINSTANCE i");
|
sql.append(" left join JBPM4_HIST_PROCINST hp on i.plexecutionid = hp.ID_ ");
|
sql.append(" left join jbpm4_execution e on e.id_ = hp.id_ where e.activityname_ is not null) ");
|
sql.append(" where 1=1 ");
|
sql.append(" and pltasktype in ( ");
|
String[] taskTypes = taskType.split(",");
|
String taskTypesStr = "";
|
for (int i = 0; i < taskTypes.length; i++) {
|
taskTypesStr += "'" + taskTypes[i] + "',";
|
}
|
sql.append(taskTypesStr.substring(0, taskTypesStr.length() - 1));
|
sql.append(" )");
|
sql.append(" ) ");
|
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List<?> list = createSQLQuery.list();
|
if (list != null && list.size() > 0) {
|
res = Integer.parseInt(String.valueOf(list.get(0)));
|
}
|
|
} catch (Exception ex) {
|
ex.printStackTrace();
|
}
|
|
return res;
|
}
|
|
/**
|
* 任务完成
|
*
|
* @param taskId 任务id
|
* @param outcome 路由名称
|
* @param nextTaskName 下一步任务名称
|
* @param approvalNote 流程意见
|
* @param userNames 下一步执行人名称
|
* @return
|
* @throws VCIError
|
*/
|
public boolean completeTaskByPlatform(String taskId, String outcome, String nextTaskName, String approvalNote,
|
String[] userNames) throws VCIError {
|
long startTime = System.currentTimeMillis();
|
ServerWithLog4j.logger.debug("开始时间:" + (startTime / 1000));
|
try {
|
boolean flag = false;
|
Map<String, List<String>> taskAndUesrMap = new HashMap<String, List<String>>();
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
String[] nextTaskUserNames = userNames;
|
Plflowapproveopinion plflowapproveopinion = new Plflowapproveopinion();
|
String ploid = ObjectUtility.getNewObjectID36();
|
plflowapproveopinion.setPloid(ploid);
|
plflowapproveopinion.setPltaskid(taskId);
|
plflowapproveopinion.setPlapprovenote(approvalNote);
|
// 记录执行者
|
plflowapproveopinion.setPlassgin(getUserEntity().getUserName());
|
|
TaskService taskService = processEngine.getTaskService();
|
Task task = taskService.getTask(taskId);
|
if (task == null) {
|
throw new VCIError("任务已经完成!", new String[] {});
|
}
|
String processinstansid = processEngine.getExecutionService().findExecutionById(task.getExecutionId())
|
.getProcessInstance().getId();
|
if (userNames != null && userNames.length != 0) {
|
{
|
String user = Arrays.toString(userNames);
|
user = user.substring(1, user.length() - 1);
|
String sql = "update jbpm4_taskanduserconfigex set username = '" + user
|
+ "' where processinstansid = '" + processinstansid + "' and taskname = '" + nextTaskName
|
+ "'";
|
HibernateSessionFactory.getSession().createSQLQuery(sql).executeUpdate();
|
|
}
|
}
|
|
// 获取deploymentID
|
String deploymentId = getDeploymentIdByExecutionId(task.getExecutionId());
|
List<?> taskDescList = this.getTaskDescList(task.getActivityName(), deploymentId);
|
|
int pltreatment = 0;
|
if (taskDescList != null && taskDescList.size() > 0) {
|
pltreatment = ((TaskDescSObject) taskDescList.get(0)).getPltreatment();
|
}
|
|
// boolean endnodeFlag = false;
|
List<String> pariticipants = new ArrayList<String>();
|
for (int k = 0; k < userNames.length; k++) {
|
pariticipants.add(userNames[k]);
|
}
|
|
if (userNames == null || userNames.length == 0) {
|
String sql = "select a.username from JBPM4_TASKANDUSERCONFIGEX a where a.PROCESSINSTANSID = '"
|
+ processinstansid + "' and a.taskname = '" + nextTaskName + "'";
|
//无意义代码
|
// HibernateSessionFactory.getSession().createSQLQuery(sql)
|
// .executeUpdate();
|
List list = HibernateSessionFactory.getSession().createSQLQuery(sql).list();
|
|
if (list != null && list.size() > 0) {
|
String valueOf = String.valueOf(list.get(0));
|
String[] split = valueOf.split(",");
|
|
// add by xchao 2014.06.24 begin
|
// 解析任务上定义的负责人
|
// 如果配置了用户选择插件,则执行以下操作
|
String userServiceImplClass = WorkflowProperties.getStringProperty("workflow.userService");
|
if (userServiceImplClass != null && !"".equals(userServiceImplClass)) {
|
IWorkflowUserService puService = (IWorkflowUserService) (Class.forName(userServiceImplClass)
|
.newInstance());
|
String[] userNameList = puService.getAllUsers2Task(split, getUserEntity().getModule());
|
for (String userName : userNameList) {
|
if (!pariticipants.contains(userName)) {
|
pariticipants.add(userName);
|
}
|
}
|
}
|
// add by xchao 2014.06.24 end
|
}
|
}
|
|
// add by xchao 2014.06.24 begin
|
// 重新赋值,以便后面的基于直接基于 userNames 进行创建workitem
|
userNames = pariticipants.toArray(new String[] {});
|
// add by xchao 2014.06.24 end
|
|
Map<String, Object> variables = new HashMap<String, Object>();
|
variables.put("content", nextTaskName);
|
variables.put("OUTCOME", outcome);
|
variables.put("participants", pariticipants);
|
variables.put("userName", getUserEntity().getUserName());
|
variables.put("IP", getUserEntity().getIp());
|
variables.put("module", getUserEntity().getModule());
|
variables.put("approvalNote", approvalNote);
|
|
processEngine.getTaskService().setVariables(taskId, variables);
|
|
// 流程对象ids
|
String[] ObjectOids = null;
|
TaskService taskServices = processEngine.getTaskService();
|
String[] execIDs = task.getExecutionId().replace(".", ",").split(",");
|
String excutionid = "";
|
|
if (execIDs.length > 2) {
|
excutionid = execIDs[0] + "." + execIDs[1];
|
} else {
|
excutionid = task.getExecutionId();
|
}
|
// System.out.println("=【3】==================================================================================");
|
|
List<Task> histlistTask = taskService.createTaskQuery().processInstanceId(excutionid).list();
|
|
// 获取父流程的excutionid
|
String curProcessExcutionId = getWorkFlowRelatedObjectQuerySql(taskServices, processEngine, excutionid);
|
|
// 获取下一步父流程
|
ExecutionImpl superTaskImpl = getParentExection(taskService, processEngine, excutionid);
|
ObjectOids = updataWorkItem(taskId, task.getExecutionId(), null);
|
|
// boolean countFlag = false;
|
|
try {
|
// 如果是1,则说明是会签,不对任务重新设置候选人
|
if (pltreatment == 0) {
|
if ("".equals(outcome)) {
|
if (StringUtils.isBlank(nextTaskName)) { // 如果沒有指定下一步的任务节点,则直接完成任务
|
processEngine.getTaskService().completeTask(taskId);
|
plflowapproveopinion.setPlapproveopinion("提交任务");
|
} else {
|
// 指定了下一步的任务节点,则查询两个任务之间的路由,没有路由则创建动态路由进行跳转 Jason 2022-12-09
|
outcome = completeTaskByDynamicTransiton(taskId, nextTaskName);
|
plflowapproveopinion.setPlapproveopinion(outcome);
|
}
|
} else {
|
processEngine.getTaskService().completeTask(taskId, outcome, variables);
|
plflowapproveopinion.setPlapproveopinion(outcome);
|
}
|
flag = true;
|
} else {
|
Task joinTask = null;
|
joinTask = task;
|
|
Execution parent = processEngine.getExecutionService().findExecutionById(task.getExecutionId())
|
.getParent();
|
String activityName = ((ExecutionImpl) parent).getActivityName();
|
List<Task> tasks = taskService.createTaskQuery().activityName(activityName).list();
|
for (Task t : tasks) {
|
if (t.getExecutionId().equals(parent.getId())) {
|
task = t;
|
break;
|
}
|
}
|
Map<String, Object> v = new HashMap<String, Object>();
|
v.put(Sign.VAR_SIGN, outcome);
|
taskService.setVariables(joinTask.getId(), v);
|
Sign sign = new Sign(task.getId(), joinTask, outcome, getUserEntity().getUserName(), deploymentId);
|
taskService.setVariables(task.getId(), v);
|
|
Boolean execute = processEngine.execute(sign);
|
String[] trainNames = getTrainName(deploymentId, task.getActivityName(), outcome);
|
// countFlag = true;
|
nextTaskName = trainNames[0];
|
if (execute) {
|
String counterOutCome = (String) taskService.getVariable(task.getId(), Sign.VAR_SIGN_RESULT);
|
if (StringUtils.isBlank(counterOutCome)) {
|
counterOutCome = outcome;
|
}
|
Map<String, Object> map = new HashMap<String, Object>();
|
map.put("OUTCOME", counterOutCome);
|
// map.put("plflowapproveopinion", plflowapproveopinion);
|
map.put("approvalNote", approvalNote);
|
taskId = task.getId();
|
if (taskService.getSubTasks(taskId).size() != 0) {
|
taskService.takeTask(taskId, getUserEntity().getUserName());
|
}
|
taskService.completeTask(taskId, counterOutCome, map);
|
}
|
|
plflowapproveopinion.setPlapproveopinion(outcome);
|
flag = execute;
|
}
|
} catch (Throwable e) {
|
e.printStackTrace();
|
}
|
|
// System.out.println("=【4】==================================================================================");
|
// System.out.println(" PLOID = " + plflowapproveopinion.getPloid());
|
// System.out.println(" pltaskid = " + plflowapproveopinion.getPltaskid());
|
// System.out.println(" Plapproveopinion = " +
|
// plflowapproveopinion.getPlapproveopinion());
|
// System.out.println(" Plapprovenote = " +
|
// plflowapproveopinion.getPlapprovenote());
|
// System.out.println(" Plassgin = " + plflowapproveopinion.getPlassgin());
|
|
new PlflowapproveopinionDaoImpl().save(plflowapproveopinion);
|
if (flag) {
|
// TODO 获取下一步任务
|
List<Task> listTask = getCurrentTask(taskService, processEngine, excutionid);
|
if (listTask.size() == 0 && superTaskImpl != null) {
|
listTask = taskService.createTaskQuery().processInstanceId(superTaskImpl.getId()).list();
|
}
|
List<Task> currentTaskList = new ArrayList<Task>();
|
currentTaskList.addAll(listTask);
|
for (Task cTask : listTask) {
|
for (Task bTask : histlistTask) {
|
if (cTask.getName().equals(bTask.getName())) {
|
currentTaskList.remove(cTask);
|
break;
|
}
|
}
|
}
|
listTask = currentTaskList;
|
if (listTask != null && listTask.size() > 0) {
|
List<String> userList = new ArrayList<String>();
|
for (int i = 0; i < listTask.size(); i++) {
|
userList = new ArrayList<String>();
|
Task task2 = listTask.get(i);
|
StringBuffer sql = new StringBuffer();
|
sql.append("select a.username from JBPM4_TASKANDUSERCONFIGEX a "
|
+ "where a.PROCESSINSTANSID = '" + curProcessExcutionId + "'");
|
sql.append(" and a.taskname = '" + task2.getName() + "' ");
|
//无意义代码
|
// HibernateSessionFactory.getSession().createSQLQuery(sql.toString())
|
// .executeUpdate();
|
List<?> list = HibernateSessionFactory.getSession().createSQLQuery(sql.toString()).list();
|
if (list != null && list.size() > 0) {
|
String valueOf = String.valueOf(list.get(0));
|
String[] split = valueOf.split(",");
|
// 解析任务上定义的负责人
|
// 如果配置了用户选择插件,则执行以下操作
|
String userServiceImplClass = WorkflowProperties.getStringProperty("workflow.userService");
|
if (userServiceImplClass != null && !"".equals(userServiceImplClass)) {
|
IWorkflowUserService puService = (IWorkflowUserService) (Class
|
.forName(userServiceImplClass).newInstance());
|
String[] userNameList = new String[0];
|
if (nextTaskUserNames != null && nextTaskUserNames.length > 0) {
|
userNameList = puService.getAllUsers2Task(nextTaskUserNames,
|
getUserEntity().getModule());
|
} else {
|
userNameList = puService.getAllUsers2Task(split, getUserEntity().getModule());
|
}
|
|
for (String un : userNameList) {
|
if (!userList.contains(un)) {
|
userList.add(un);
|
}
|
}
|
}
|
taskAndUesrMap.put(task2.getActivityName(), userList);
|
}
|
}
|
|
String sql = "select t.pltablename,t.pldesc,t.processname from PLFLOWINSTANCE t where t.plexecutionid ='"
|
+ curProcessExcutionId + "'";
|
SQLQuery createSQLQuery = HibernateSessionFactory.getSession().createSQLQuery(sql);
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List<?> list = createSQLQuery.list();
|
String btmType = "";
|
String btmDesc = "";
|
String processName = "";
|
for (int i = 0; i < list.size(); i++) {
|
Object[] object = (Object[]) list.get(i);
|
btmType = String.valueOf(object[0]);
|
btmDesc = (String) object[1] == null ? "" : (String) object[1];
|
processName = (String) object[2];
|
}
|
Date date = new Date();
|
long time = date.getTime();
|
// Timestamp excutionTimen = new Timestamp(time);
|
// 暂时不用
|
for (int j = 0; j < listTask.size(); j++) {
|
Task newTask = listTask.get(j);
|
if (newTask == null) {
|
return true;
|
}
|
List<Task> subTasks = taskService.getSubTasks(newTask.getId());
|
if (subTasks.size() > 0) {
|
for (int i = 0; i < subTasks.size(); i++) {
|
Task subTask = subTasks.get(i);
|
String nextTaskId = subTask.getId();
|
userNames = getCurUserName(newTask, taskAndUesrMap);
|
|
// add by xhcao 2014.06.24 begin
|
for (int m = 0; m < userNames.length; m++) {
|
String subAssign = subTask.getAssignee();
|
String parsSubAssign = subAssign.substring(subAssign.indexOf(":") + 1,
|
subAssign.length());
|
if (parsSubAssign.equals(userNames[m])) {
|
saveForComplete(userNames, ObjectOids, subTask, btmType, btmDesc, processName,
|
nextTaskId, m);
|
}
|
}
|
// add by xchao 2014.06.24 end
|
|
setCustomUserForAssgin(taskServices, taskDescList, nextTaskId);
|
}
|
} else {
|
String nextTaskId = newTask.getId();
|
userNames = getCurUserName(newTask, taskAndUesrMap);
|
|
// add by xhcao 2014.06.24 begin
|
for (int m = 0; m < userNames.length; m++) {
|
saveForComplete(userNames, ObjectOids, newTask, btmType, btmDesc, processName,
|
nextTaskId, m);
|
|
List<Participation> taskParticipations = taskService.getTaskParticipations(nextTaskId);
|
if (m == 0) {
|
for (Participation participation : taskParticipations) {
|
taskService.removeTaskParticipatingUser(nextTaskId, participation.getUserId(),
|
Participation.CANDIDATE);
|
}
|
}
|
taskService.addTaskParticipatingUser(nextTaskId, userNames[m], Participation.CANDIDATE);
|
}
|
// add by xchao 2014.06.24 end
|
|
setCustomUserForAssgin(taskServices, taskDescList, nextTaskId);
|
|
}
|
}
|
|
}
|
|
} else {
|
return true;
|
}
|
Execution executedProcessInstance = processEngine.getExecutionService()
|
.findExecutionById(task.getExecutionId());
|
if (isWorkFlowInstanceExist() && executedProcessInstance == null) {
|
completeWorkflowInstance(task.getExecutionId());
|
}
|
long endTime = System.currentTimeMillis();
|
ServerWithLog4j.logger.debug("结束时间:" + (endTime / 1000));
|
ServerWithLog4j.logger.debug("耗时:" + ((endTime - startTime) / 1000));
|
return flag;
|
} catch (VCIError ve) {
|
// ve.printStackTrace();
|
ServerWithLog4j.logger.error("completeTaskByPlatform-1", ve);
|
throw ve;
|
} catch (Exception e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("completeTaskByPlatform-2", e);
|
|
if (e.getCause() != null && e.getCause() instanceof VCIError) {
|
throw (VCIError) e.getCause();
|
}
|
throw ServerErrorTool.getVCIError("执行流程过程中出现错误!", e);
|
}
|
}
|
|
/**
|
* 完成任务,根据目标任务查询路由,如果没有路由,则创建动态路由完成任务并跳转到指定活动
|
*
|
* @param task
|
* @param destActivityName
|
* @param createTransitionName
|
* @throws VCIError
|
*/
|
public String completeTaskByDynamicTransiton(String taskId, String destTask) throws VCIError {
|
// 这里不会影响事物
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
TaskService taskService = processEngine.getTaskService();
|
Task task = taskService.getTask(taskId);
|
if (task == null) {
|
throw new VCIError("任务已经完成!", new String[] {});
|
}
|
ExecutionService execService = processEngine.getExecutionService();
|
|
String outTran = null;
|
EnvironmentImpl envImpl = ((EnvironmentFactory) processEngine).openEnvironment();
|
try {
|
|
// 动态回退
|
ExecutionImpl e = (ExecutionImpl) execService.findExecutionById(task.getExecutionId());
|
ActivityImpl curActivity = e.getActivity();
|
|
List<Transition> lstTran = curActivity.getOutgoingTransitions();
|
List<String> lstOutcome = new ArrayList<String>();
|
for (Transition tran : lstTran) {
|
Activity actDest = tran.getDestination();
|
lstOutcome.add(actDest.getName());
|
if (actDest.getName().equals(destTask)) {
|
outTran = tran.getName();
|
}
|
}
|
|
// 没找到合适的路由,则创建动态路由
|
if (StringUtils.isBlank(outTran)) {
|
outTran = "[动态路由]提交到[" + destTask + "]";
|
ProcessDefinitionImpl processDefinitionImpl = curActivity.getProcessDefinition();
|
|
// 生成一个transition
|
ActivityImpl destActivityImpl = processDefinitionImpl.findActivity(destTask);
|
TransitionImpl toApply = curActivity.createOutgoingTransition();
|
toApply.setSource(curActivity);
|
toApply.setDestination(destActivityImpl);
|
toApply.setName(outTran);
|
}
|
|
// 根据路由完成任务
|
taskService.completeTask(task.getId(), outTran);
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
outTran = "";
|
} finally {
|
envImpl.close();
|
}
|
return outTran;
|
}
|
|
/**
|
* 获取当前流程的关联对象的excutionid
|
*
|
* @param taskService
|
* @param processEngine
|
* @param excutionid
|
* @return
|
*/
|
private String getWorkFlowRelatedObjectQuerySql(TaskService taskService, ProcessEngine processEngine,
|
String excutionid) {
|
ExecutionImpl impl = (ExecutionImpl) processEngine.getExecutionService().findExecutionById(excutionid);
|
if (impl != null) {
|
// 获取父流程
|
ExecutionImpl superimpl = impl.getSuperProcessExecution();
|
if (superimpl == null) {
|
return excutionid;
|
} else {
|
return getWorkFlowRelatedObjectQuerySql(taskService, processEngine, superimpl.getId());
|
}
|
}
|
|
return excutionid;
|
}
|
|
private String getParentExcutionId(String excutionid) {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
ExecutionImpl impl = (ExecutionImpl) processEngine.getExecutionService().findExecutionById(excutionid);
|
if (impl != null) {
|
// 获取父流程
|
ExecutionImpl superimpl = impl.getSuperProcessExecution();
|
if (superimpl == null) {
|
return excutionid;
|
} else {
|
return getParentExcutionId(superimpl.getId());
|
}
|
}
|
|
return excutionid;
|
}
|
|
/**
|
* 获取当前流程的父流程实例
|
*
|
* @param taskService
|
* @param processEngine
|
* @param excutionid
|
* @return
|
*/
|
private ExecutionImpl getParentExection(TaskService taskService, ProcessEngine processEngine, String excutionid) {
|
// List<Task> listTask = taskService.createTaskQuery().processInstanceId(excutionid).list();
|
ExecutionImpl impl = (ExecutionImpl) processEngine.getExecutionService().findExecutionById(excutionid);
|
if (impl != null) {
|
// 获取父流程
|
ExecutionImpl superimpl = impl.getSuperProcessExecution();
|
return superimpl;
|
} else {
|
return impl;
|
}
|
}
|
|
/**
|
* 获取当前流程的任务节点
|
*
|
* @param taskService
|
* @param processEngine
|
* @param excutionid
|
* @return
|
*/
|
private List<Task> getCurrentTask(TaskService taskService, ProcessEngine processEngine, String excutionid) {
|
List<Task> listTask = taskService.createTaskQuery().processInstanceId(excutionid).list();
|
ExecutionImpl impl = (ExecutionImpl) processEngine.getExecutionService().findExecutionById(excutionid);
|
ExecutionImpl superTaskImpl = getParentExection(taskService, processEngine, excutionid);
|
if (listTask != null && listTask.size() > 0) {
|
if (superTaskImpl != null) {
|
for (int i = 0; i < listTask.size(); i++) {
|
String processId = ((TaskImpl) listTask.get(i)).getProcessInstance().getProcessDefinitionId();
|
listTask.get(i).setName(listTask.get(i).getName() + "(" + processId + ":"
|
+ this.getDeploymentIdByExecutionId(listTask.get(i).getExecutionId()) + ")");
|
}
|
}
|
return listTask;
|
}
|
if (impl != null) {
|
// 获取父流程
|
ExecutionImpl superimpl = impl.getSuperProcessExecution();
|
if (superimpl != null) {
|
listTask = taskService.createTaskQuery().processInstanceId(superimpl.getId()).list();
|
}
|
// 获取子流程
|
ExecutionImpl subimpl = impl.getSubProcessInstance();
|
if (subimpl != null) {
|
listTask = taskService.createTaskQuery().processInstanceId(subimpl.getId()).list();
|
for (int i = 0; i < listTask.size(); i++) {
|
String processId = ((TaskImpl) listTask.get(i)).getProcessInstance().getProcessDefinitionId();
|
listTask.get(i).setName(listTask.get(i).getName() + "(" + processId + ":"
|
+ this.getDeploymentIdByExecutionId(listTask.get(i).getExecutionId()) + ")");
|
}
|
}
|
}
|
return listTask;
|
}
|
|
/**
|
* 获取下一节点负责人
|
*
|
* @param taskService
|
* @param processEngine
|
* @param excutionid
|
* @return
|
* @author cmk
|
*/
|
private String[] getCurUserName(Task newTask, Map<String, List<String>> taskAndUesrMap) {
|
String[] userNames = new String[0];
|
TaskImpl taskImpl = (TaskImpl) newTask;
|
Iterator<ParticipationImpl> itor = taskImpl.getParticipations().iterator();
|
String curUserName = null;
|
while (itor.hasNext()) {
|
ParticipationImpl pimpl = itor.next();
|
curUserName = pimpl.getUserId();
|
}
|
List<String> taskUserName = taskAndUesrMap.get(newTask.getActivityName());
|
if (taskUserName == null) {
|
userNames = new String[] { curUserName };
|
} else {
|
userNames = taskAndUesrMap.get(newTask.getActivityName()).toArray(new String[] {});
|
}
|
// 出差设置的候选人
|
List<String> taskassignList = new ArrayList<String>();
|
for (int k = 0; k < userNames.length; k++) {
|
TasksAssigned tasksAssignedByUserName = getTasksAssignedByUserName(userNames[k]);
|
String taskassign = tasksAssignedByUserName.getTasksName();
|
if (taskassign == null || "".equals(taskassign)) {
|
taskassign = userNames[k];
|
}
|
String[] split = taskassign.split(",");
|
for (String s : split) {
|
if (!taskassignList.contains(s)) {
|
taskassignList.add(s);
|
}
|
}
|
}
|
if (taskassignList != null && taskassignList.size() > 0) {
|
userNames = taskassignList.toArray(new String[0]);
|
}
|
|
return userNames;
|
}
|
|
/**
|
* 执行多条同一流程模板、任务节点、任务负责人的流程
|
*
|
* @param taskIds
|
* @param outcome
|
* @param nextTaskName
|
* @param approvalNote
|
* @param userNames
|
* @param objectProperty
|
* @param objectPropertyValues
|
* @return
|
* @throws VCIError
|
* @author changmk
|
*/
|
public boolean completeTasksByPlatform_v1(String[] taskIds, String outcome, String nextTaskName,
|
String approvalNote, UserEntityInfo userEntityInfo, String[] userNames, String[] objectProperty,
|
String[][] objectPropertyValues) throws VCIError {
|
boolean flag = true;
|
// 设置批量执行标志 add by changmk 20170628
|
setBatchExecuteTaskFlag(true);
|
|
if (objectPropertyValues.length == taskIds.length) {
|
for (int i = 0; i < taskIds.length; ++i) {
|
String taskId = taskIds[i];
|
if (!("".equals(taskId))) {
|
String[][] objectPropertyValue = new String[1][];
|
objectPropertyValue[0] = objectPropertyValues[i];
|
flag = completeTaskByPlatform_v1(taskId, outcome, nextTaskName, approvalNote, userEntityInfo,
|
userNames, objectProperty, objectPropertyValue);
|
if (!(flag)) {
|
break;
|
}
|
}
|
}
|
}
|
|
return flag;
|
}
|
|
/**
|
* 获取代理人用户,有则转换责任用户
|
*
|
* @param userId
|
* @return
|
* @throws ParseException
|
*/
|
private String[] getVicegerent(String[] nextTaskUserArr) {
|
List<String> taskUserList = new ArrayList<String>();
|
|
for (int j = 0; j < nextTaskUserArr.length; j++) {
|
String taskItem = nextTaskUserArr[j];
|
if (taskItem.indexOf("user:") == 0) {
|
String[] userArr = taskItem.split(":");
|
|
String querySql = "select u.id,u.name,v.vicetime,v.lastmodifytime "
|
+ "from platformlt_vicegerent v left join platformbtm_user u " + "on u.oid = v.t_oid "
|
+ "where v.f_oid in " + "(select oid from platformbtm_user where id = '" + userArr[1] + "')";
|
|
String[][] result = new String[0][0];
|
try {
|
result = ServerServiceProvider.getOQService().queryBySqlWithoutKey(querySql);
|
} catch (VCIError e) {
|
// 未设置代理人
|
taskUserList.add(taskItem);
|
}
|
if (result != null && result.length > 0) {
|
for (int i = 0; i < result.length; i++) {
|
|
String viceTime = result[i][2];
|
String modifyTime = result[i][3];
|
boolean deadlineFlag = judgeDelayTaskUser(viceTime, modifyTime);
|
if (deadlineFlag) {
|
taskUserList.add("user:" + result[i][0]);
|
} else {
|
taskUserList.add(taskItem);
|
}
|
}
|
}
|
} else {
|
taskUserList.add(taskItem);
|
}
|
}
|
return taskUserList.toArray(new String[0]);
|
}
|
|
/**
|
* 判断代理人是否在设置期限内
|
*
|
* @param viceTime
|
* @param modifyTime
|
* @return
|
*/
|
private boolean judgeDelayTaskUser(String viceTime, String modifyTime) {
|
boolean flag = false;
|
DateFormat formater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
Date modifyDate = new Date();
|
int viceDays = 30;
|
try {
|
// 最后修改日期
|
modifyDate = formater.parse(modifyTime);
|
viceDays = Integer.parseInt(viceTime);
|
} catch (ParseException e) {
|
modifyDate = new Date();
|
viceDays = 30;
|
}
|
// 当前日期
|
Date currentTime = Calendar.getInstance().getTime();
|
|
int trueViceDays = (int) ((currentTime.getTime() - modifyDate.getTime()) / (1000 * 3600 * 24));
|
if (trueViceDays <= viceDays) {
|
flag = true;
|
}
|
return flag;
|
}
|
|
/**
|
* 任务完成 平台使用
|
*
|
* @param taskId 任务id
|
* @param outcome 路由名称
|
* @param nextTaskName 下一步任务名称
|
* @param approvalNote 流程意见
|
* @param userNames 下一步执行人名称
|
* ({user:user1.....,role:role1.....,department:department1.....})
|
* @param objectProperty 流程携带参数
|
* 至少包含(oid,btmName,revesionOid,nameOid)+其他自定义使用参数
|
* @param objectPropertyValues 流程携带参数值
|
* @return
|
* @throws VCIError
|
*/
|
public boolean completeTaskByPlatform_v1(String taskId, String outcome, String nextTaskName, String approvalNote,
|
UserEntityInfo userEntityInfo, String[] userNames, String[] objectProperty, String[][] objectPropertyValues)
|
throws VCIError {
|
long startTime = System.currentTimeMillis();
|
ServerWithLog4j.logger.debug("开始时间:" + (startTime / 1000));
|
try {
|
// 替换任务代理人
|
// 不允许使用user这个业务类型了,所以代理人不能用这个
|
// userNames = getVicegerent(userNames);
|
|
boolean flag = false;
|
Map<String, List<String>> taskAndUesrMap = new HashMap<String, List<String>>();
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
|
Plflowapproveopinion plflowapproveopinion = new Plflowapproveopinion();
|
String ploid = ObjectUtility.getNewObjectID36();
|
plflowapproveopinion.setPloid(ploid);
|
plflowapproveopinion.setPltaskid(taskId);
|
plflowapproveopinion.setPlapprovenote(approvalNote);
|
// 记录执行者
|
plflowapproveopinion.setPlassgin(userEntityInfo.userName);
|
// plflowapproveopinion.setPlassgin(getUserEntity().getUserName());
|
ServerWithLog4j.logger.debug(
|
"===============completeTaskByPlatform_v1==========username:" + getUserEntity().getUserName());
|
TaskService taskService = processEngine.getTaskService();
|
Task task = taskService.getTask(taskId);
|
if (task == null) {
|
throw new VCIError("任务已经完成!", new String[] {});
|
}
|
ExecutionService executionService = processEngine.getExecutionService();
|
Execution execution = executionService.findExecutionById(task.getExecutionId());
|
Execution processInstance = execution.getProcessInstance();
|
// String processInstanceId = processInstance.getId();
|
String processinstansid = processInstance.getId();
|
// 设置任务执行人
|
// taskService.assignTask(taskId, getUserEntity().getUserName());
|
// taskService.assignTask(taskId, userEntityInfo.userName);
|
|
//processInstanceId没用,改为processinstansid
|
// String processinstansid = processEngine.getExecutionService()
|
// .findExecutionById(task.getExecutionId())
|
// .getProcessInstance().getId();
|
|
// 获取父流程的excutionid
|
String curProcessExcutionId = getWorkFlowRelatedObjectQuerySql(taskService, processEngine,
|
task.getExecutionId());
|
String[] cexecIDs = curProcessExcutionId.replace(".", ",").split(",");
|
if (cexecIDs.length > 2) {
|
curProcessExcutionId = cexecIDs[0] + "." + cexecIDs[1];
|
}
|
// 获取deploymentID---获取是不是会签
|
String deploymentId = getDeploymentIdByExecutionId(task.getExecutionId());
|
List<?> taskDescList = this.getTaskDescList(task.getActivityName(), deploymentId);
|
int pltreatment = 0;
|
if (taskDescList != null && taskDescList.size() > 0) {
|
pltreatment = ((TaskDescSObject) taskDescList.get(0)).getPltreatment();
|
}
|
// 获取下一步父流程
|
ExecutionImpl superTaskImpl = getParentExection(taskService, processEngine, task.getExecutionId());
|
if (userNames != null && userNames.length != 0) {
|
// boolean isSubProFlag = true;
|
String formatName = nextTaskName;
|
// 父流程执行过程中
|
if (curProcessExcutionId.equals(task.getExecutionId())) {
|
boolean subtaskflag = true;
|
String judgeSql = "select distinct t.taskname from jbpm4_taskanduserconfigex t where t.processinstansid = '"
|
+ processinstansid + "' ";
|
//无意义代码
|
// HibernateSessionFactory.getSession().createSQLQuery(judgeSql)
|
// .executeUpdate();
|
List<?> judgelist = HibernateSessionFactory.getSession().createSQLQuery(judgeSql).list();
|
if (judgelist != null && judgelist.size() > 0) {
|
for (int i = 0; i < judgelist.size(); i++) {
|
String taskele = (String) judgelist.get(i);
|
if (taskele.equals(nextTaskName)) {
|
subtaskflag = false;
|
break;
|
}
|
}
|
}
|
if (subtaskflag) {
|
String jbpmDeploymentId = getDeploymentIdByExecutionId(curProcessExcutionId);
|
String processDefinitionId = getSubProcessIdBySubTaskName(jbpmDeploymentId, nextTaskName);
|
BigDecimal subDeployId = getDeploymentID(processDefinitionId);
|
String subTaskName = this.getFirstProcessTask(String.valueOf(subDeployId)).getTaskName();
|
formatName = subTaskName + "(" + processDefinitionId + ":" + String.valueOf(subDeployId) + ")";
|
}
|
} else {// 子流程执行过程中
|
if ("结束".equals(nextTaskName)) {
|
String subDeploymentId = getDeploymentIdByExecutionId(task.getExecutionId());
|
String subProcessId = this.getProcessDefinitionByDeployId(subDeploymentId).id;
|
String superDeployId = this.getDeploymentIdByExecutionId(curProcessExcutionId);
|
String superCurName = getNextSuperTaskBySubProId(superDeployId, subProcessId);
|
String superNextName[] = getNextTaskNames(superDeployId, superCurName, "同意");// 路由线设置的名称为“同意”时
|
if (superNextName != null && superNextName.length > 0) {
|
formatName = superNextName[0];
|
}
|
} else if (pltreatment == 0) {
|
String subDeployId = getDepolymentID(task.getExecutionId());
|
String definitionId = execution.getProcessInstance().getProcessDefinitionId();
|
if ("".equals(nextTaskName)) {
|
nextTaskName = task.getActivityName();
|
}
|
formatName = nextTaskName + "(" + definitionId + ":" + subDeployId + ")";
|
} else if (pltreatment == 1) {
|
formatName = nextTaskName;
|
// modify by weidy@2018-06-13 在会签任务执行的时候,也会认为是子流程,但是为下一节点设置的负责人时,任务名称不能使用
|
// 所以我们判断是不是会签,是会签的时候就只取下一步负责人
|
}
|
}
|
|
String user = Arrays.toString(userNames);
|
user = user.substring(1, user.length() - 1);
|
String sql = "update jbpm4_taskanduserconfigex set username = '" + user + "' where processinstansid = '"
|
+ curProcessExcutionId + "' and taskname = '" + formatName + "'";
|
HibernateSessionFactory.getSession().createSQLQuery(sql).executeUpdate();
|
}
|
|
boolean endnodeFlag = false;
|
List<String> pariticipants = new ArrayList<String>();
|
for (int k = 0; k < userNames.length; k++) {
|
pariticipants.add(userNames[k]);
|
}
|
if (userNames == null || userNames.length == 0) {
|
String sql = "select a.username from JBPM4_TASKANDUSERCONFIGEX a where a.PROCESSINSTANSID = '"
|
+ processinstansid + "' and a.taskname = '" + nextTaskName + "'";
|
//重复,无意义代码
|
// HibernateSessionFactory.getSession().createSQLQuery(sql)
|
// .executeUpdate();
|
List<?> list = HibernateSessionFactory.getSession().createSQLQuery(sql).list();
|
if (list != null && list.size() > 0) {
|
String valueOf = String.valueOf(list.get(0));
|
String[] split = valueOf.split(",");
|
// for (int i = 0; i < split.length; i++) {
|
// pariticipants.add(split[i].trim());
|
// }
|
|
// add by xchao 2014.06.24 begin
|
// 解析任务上定义的负责人
|
// 如果配置了用户选择插件,则执行以下操作
|
String userServiceImplClass = WorkflowProperties.getStringProperty("workflow.userService");
|
if (userServiceImplClass != null && !"".equals(userServiceImplClass)) {
|
IWorkflowUserService puService = (IWorkflowUserService) (Class.forName(userServiceImplClass)
|
.newInstance());
|
String[] userNameList = puService.getAllUsers2Task(split, userEntityInfo.modules);
|
// String[] userNameList = puService.getAllUsers2Task(split, getUserEntity().getModule());
|
for (String userName : userNameList) {
|
if (!pariticipants.contains(userName)) {
|
pariticipants.add(userName);
|
}
|
}
|
}
|
// add by xchao 2014.06.24 end
|
}
|
}
|
// add by xchao 2014.06.24 begin
|
// 重新赋值,以便后面的基于直接基于 userNames 进行创建workitem
|
// userNames = pariticipants.toArray(new String[]{});
|
// add by xchao 2014.06.24 end
|
|
Map<String, Object> variables = new HashMap<String, Object>();
|
variables.put("content", nextTaskName);
|
variables.put("OUTCOME", outcome);
|
variables.put("participants", pariticipants);
|
// variables.put("userName", getUserEntity().getUserName());
|
// variables.put("IP", getUserEntity().getIp());
|
// variables.put("module", getUserEntity().getModule());
|
variables.put("userName", userEntityInfo.userName);
|
variables.put("IP", userEntityInfo.ip);
|
variables.put("module", userEntityInfo.modules);
|
ServerWithLog4j.logger.debug(
|
"===========com.vci.rmip.workflow.server.template.ProcessTemplateService.completeTaskByPlatform_v1===========username:"
|
+ getUserEntity().getUserName());
|
|
// variables.put("processEngine", processEngine);
|
// variables.put("plflowapproveopinion", plflowapproveopinion);
|
variables.put("approvalNote", approvalNote);
|
if (objectPropertyValues != null) {
|
for (int i = 0; i < objectPropertyValues.length; i++) {
|
String oid = "";
|
Map<String, String> cMap = new HashMap<String, String>();
|
for (int j1 = 0; j1 < objectPropertyValues[i].length; j1++) {
|
cMap.put(objectProperty[j1], objectPropertyValues[i][j1]);
|
if (oid.equals("") && "Oid".equals(objectProperty[j1])) {
|
oid = objectPropertyValues[i][j1];
|
}
|
// variables .put(objectProperty[j1], new
|
// String[]{objectPropertyValues[i][j1]});
|
}
|
variables.put(oid, cMap);
|
}
|
}
|
// add by changmk 20170616 start 获取workitem关联的数据
|
String[][] allObjectPropertyValues = null;
|
Object obj = JbpmEngine.getProcessEngine().getTaskService().getVariable(task.getId(),
|
"objectPropertyValues");
|
if (obj != null && obj instanceof String[][]) {
|
allObjectPropertyValues = (String[][]) obj;
|
}
|
// add by changmk 20170616 end
|
// variables.putAll(globalMap);
|
processEngine.getTaskService().setVariables(taskId, variables);
|
|
// 流程对象ids
|
String[] objectOids = null;
|
objectOids = updataWorkItem(taskId, task.getExecutionId(), userEntityInfo);
|
// 如果是1,则说明是会签,不对任务重新设置候选人
|
if (pltreatment == 0) {
|
if ("".equals(outcome)) {
|
// processEngine.getTaskService().completeTask(taskId);
|
// plflowapproveopinion.setPlapproveopinion("提交任务");
|
if (StringUtils.isBlank(nextTaskName)) { // 如果沒有指定下一步的任务节点,则直接完成任务
|
processEngine.getTaskService().completeTask(taskId);
|
plflowapproveopinion.setPlapproveopinion("提交任务");
|
} else {
|
// 指定了下一步的任务节点,则查询两个任务之间的路由,没有路由则创建动态路由进行跳转 Jason 2022-12-09
|
outcome = completeTaskByDynamicTransiton(taskId, nextTaskName);
|
plflowapproveopinion.setPlapproveopinion(outcome);
|
}
|
} else {
|
processEngine.getTaskService().completeTask(taskId, outcome, variables);
|
plflowapproveopinion.setPlapproveopinion(outcome);
|
}
|
flag = true;
|
} else {
|
// List<Task> joinTasks = taskService
|
// .findPersonalTasks(getUserEntity().getUserName());
|
// boolean executeFlag = false;
|
// List<Task> subTasks = taskService.getSubTasks(task.getId());
|
Task joinTask = null;
|
// for (int j = 0; j < joinTasks.size(); j++) {
|
//// for (int i = 0; i < subTasks.size(); i++) {
|
//// if ((subTasks.get(i).getName().equals(joinTasks.get(j)
|
//// .getName()))
|
//// && (subTasks.get(i).getId().equals(joinTasks
|
//// .get(j).getId()))) {
|
//// joinTask = joinTasks.get(j);
|
////// executeFlag = true;
|
//// break;
|
//// }
|
// String name = task.getName();
|
// name = name.substring(name.lastIndexOf("-")+1);
|
// if ((name.equals(joinTasks.get(j)
|
// .getName()))
|
// && (task.getId().equals(joinTasks
|
// .get(j).getId()))) {
|
// joinTask = joinTasks.get(j);
|
//// executeFlag = true;
|
// break;
|
// }
|
//// }
|
// }
|
joinTask = task;
|
|
Execution parent = processEngine.getExecutionService().findExecutionById(task.getExecutionId())
|
.getParent();
|
String activityName = ((ExecutionImpl) parent).getActivityName();
|
List<Task> tasks = taskService.createTaskQuery().activityName(activityName).list();
|
for (Task t : tasks) {
|
if (t.getExecutionId().equals(parent.getId())) {
|
task = t;
|
break;
|
}
|
}
|
Map<String, Object> v = new HashMap<String, Object>();
|
v.put(Sign.VAR_SIGN, outcome);
|
taskService.setVariables(joinTask.getId(), v);
|
Sign sign = new Sign(task.getId(), joinTask, outcome, userEntityInfo.userName, deploymentId);
|
// Sign sign = new Sign(task.getId(), joinTask, outcome, getUserEntity().getUserName(), deploymentId);
|
taskService.setVariables(task.getId(), v);
|
|
Boolean execute = processEngine.execute(sign);
|
String[] trainNames = new ProcessTemplateService().getTrainName(deploymentId, task.getActivityName(),
|
outcome);
|
nextTaskName = trainNames[0];
|
if (execute) {
|
String counterOutCome = (String) taskService.getVariable(task.getId(), Sign.VAR_SIGN_RESULT);
|
if (StringUtils.isBlank(counterOutCome)) {
|
counterOutCome = outcome;
|
}
|
Map<String, Object> map = new HashMap<String, Object>();
|
map.put("OUTCOME", counterOutCome);
|
// map.put("plflowapproveopinion", plflowapproveopinion);
|
map.put("approvalNote", approvalNote);
|
taskId = task.getId();
|
if (taskService.getSubTasks(taskId).size() != 0) {
|
taskService.takeTask(taskId, userEntityInfo.userName);
|
// taskService.takeTask(taskId, getUserEntity().getUserName());
|
}
|
// if (nextTaskName != null && !"".equals(nextTaskName)) {
|
// new ProcessTemplateService()
|
// .completeTaskByCreateTransiton(taskService,
|
// task, nextTaskName, nextTaskName, map);
|
// removeTransition(processEngine,task.getExecutionId(),task.getName(),nextTaskName);
|
// taskService.completeTask(taskId, nextTaskName, map);
|
// } else {
|
// for(Task s : taskService.getSubTasks(taskId)){
|
// deleteForkTask(s.getExecutionId());
|
// }
|
taskService.completeTask(taskId, counterOutCome, map);
|
// }
|
}
|
|
plflowapproveopinion.setPlapproveopinion(outcome);
|
flag = execute;
|
}
|
|
new PlflowapproveopinionDaoImpl().save(plflowapproveopinion);
|
if (flag) {
|
// String userName = "";
|
TaskService taskServices = processEngine.getTaskService();
|
String[] execIDs = task.getExecutionId().replace(".", ",").split(",");
|
String excutionid = "";
|
if (execIDs.length > 2) {
|
excutionid = execIDs[0] + "." + execIDs[1];
|
} else {
|
excutionid = task.getExecutionId();
|
}
|
|
List<Task> listTask = getCurrentTask(taskService, processEngine, excutionid);
|
if (listTask.size() == 0 && superTaskImpl != null) {
|
listTask = taskService.createTaskQuery().processInstanceId(superTaskImpl.getId()).list();
|
}
|
if (listTask != null) {
|
// String[] execIDs = task.getExecutionId().replace(".",
|
// ",").split(",");
|
// String activityName = getNextTaskName(deploymentId, null,
|
// task.getActivityName(), outcome);
|
// List<Task> listTask = taskService.createTaskQuery()
|
// .processInstanceId(execIDs[0]+"."+execIDs[1])
|
// .list();
|
List<String> userList = new ArrayList<String>();
|
for (int i = 0; i < listTask.size(); i++) {
|
userList = new ArrayList<String>();
|
Task task2 = listTask.get(i);
|
String sql = "select a.username from JBPM4_TASKANDUSERCONFIGEX a where a.PROCESSINSTANSID = '"
|
+ curProcessExcutionId + "' and a.taskname = '" + task2.getName() + "'";
|
//无意义代码
|
// HibernateSessionFactory.getSession().createSQLQuery(sql)
|
// .executeUpdate();
|
List<?> list = HibernateSessionFactory.getSession().createSQLQuery(sql).list();
|
if (list != null && list.size() > 0) {
|
String valueOf = String.valueOf(list.get(0));
|
String[] split = valueOf.split(",");
|
// 解析任务上定义的负责人
|
// 如果配置了用户选择插件,则执行以下操作
|
String userServiceImplClass = WorkflowProperties.getStringProperty("workflow.userService");
|
if (userServiceImplClass != null && !"".equals(userServiceImplClass)) {
|
IWorkflowUserService puService = (IWorkflowUserService) (Class
|
.forName(userServiceImplClass).newInstance());
|
ServerWithLog4j.logger.debug(
|
"=========com.vci.rmip.workflow.server.template.ProcessTemplateService.completeTaskByPlatform_v1(String, String, String, String, String[], String[], String[][]).userServiceImplClass=========username:"
|
+ getUserEntity().getUserName());
|
String[] userNameList = puService.getAllUsers2Task(split, userEntityInfo.modules);
|
// String[] userNameList = puService.getAllUsers2Task(split, getUserEntity().getModule());
|
for (String un : userNameList) {
|
if (!userList.contains(un)) {
|
userList.add(un);
|
}
|
}
|
}
|
taskAndUesrMap.put(task2.getActivityName(), userList);
|
}
|
}
|
// 如果分支中的任务跳出分支,则执行删除分支中的任务
|
boolean forkFlag = false;
|
String[] forkTaskNames = getForkTaskNames(deploymentId);
|
String[] curtTaskNames = new String[listTask.size()];
|
String custTask = "";
|
String[] custTaskIds = new String[listTask.size()];
|
String custTaskId = "";
|
for (int i = 0; i < listTask.size(); i++) {
|
curtTaskNames[i] = listTask.get(i).getActivityName();
|
custTaskIds[i] = listTask.get(i).getId();
|
}
|
if (!Arrays.equals(forkTaskNames, curtTaskNames)) {
|
if (curtTaskNames.length == 1) {
|
for (int i = 0; i < forkTaskNames.length; i++) {
|
if (curtTaskNames[0].equals(forkTaskNames[i])) {
|
forkFlag = false;
|
break;
|
} else {
|
forkFlag = true;
|
custTask = curtTaskNames[0];
|
custTaskId = custTaskIds[0];
|
}
|
}
|
} else {
|
for (int i = 0; i < curtTaskNames.length; i++) {
|
for (int j = 0; j < forkTaskNames.length; j++) {
|
if (!curtTaskNames[i].equals(forkTaskNames[j])) {
|
custTask = curtTaskNames[i];
|
custTaskId = custTaskIds[i];
|
}
|
}
|
}
|
forkFlag = true;
|
}
|
}
|
// 如果分支中的任务跳出分支,则执行删除分支中的任务
|
if (forkFlag) {
|
String sqlDelExecution = "delete from jbpm4_execution where id_ like '" + excutionid
|
+ "%' and parent_ is not null";
|
HibernateSessionFactory.getSession().createSQLQuery(sqlDelExecution).executeUpdate();
|
for (String forkTask : forkTaskNames) {
|
String sqldelParticipation = "delete jbpm4_participation where task_ =(select dbid_ from jbpm4_task where execution_id_ like '"
|
+ excutionid + "%' and name_ = '" + forkTask + "' )";
|
HibernateSessionFactory.getSession().createSQLQuery(sqldelParticipation).executeUpdate();
|
String sqlDelTask = "delete from jbpm4_task where execution_id_ like '" + excutionid
|
+ "%' and name_ = '" + forkTask + "' ";
|
HibernateSessionFactory.getSession().createSQLQuery(sqlDelTask).executeUpdate();
|
|
}
|
|
deleteForkTask(excutionid);
|
// 由于多次对同一张表操作,无法再同一事务中完成。只能使用多个事务处理。
|
// HibernateSessionFactory.getSession().getTransaction().commit();
|
// HibernateSessionFactory.getSession().getTransaction().begin();
|
if (curtTaskNames != null) {
|
String sqlUpdata = "update jbpm4_execution b set b.activityname_ = '" + custTask
|
+ "' , b.state_ ='active-root' where b.id_ = '" + excutionid + "'";
|
HibernateSessionFactory.getSession().createSQLQuery(sqlUpdata).executeUpdate();
|
String sqlSelectExecution = "select dbid_ from jbpm4_execution where activityname_ = '"
|
+ custTask + "' and id_ = '" + excutionid + "'";
|
String sqlUpdataTask = "update jbpm4_task b set b.execution_id_ = '" + excutionid
|
+ "',b.execution_ =(" + sqlSelectExecution + ") where b.name_ = '" + custTask
|
+ "' and b.dbid_ = '" + custTaskId + "'";
|
HibernateSessionFactory.getSession().createSQLQuery(sqlUpdataTask).executeUpdate();
|
}
|
}
|
String sql = "select t.pltablename,t.pldesc,t.processname from PLFLOWINSTANCE t where t.plexecutionid ='"
|
+ curProcessExcutionId + "'";
|
SQLQuery createSQLQuery = HibernateSessionFactory.getSession().createSQLQuery(sql);
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List list = createSQLQuery.list();
|
String btmType = "";
|
String btmDesc = "";
|
String processName = "";
|
for (int i = 0; i < list.size(); i++) {
|
Object[] object = (Object[]) list.get(i);
|
btmType = String.valueOf(object[0]);
|
btmDesc = (String) object[1] == null ? "" : (String) object[1];
|
processName = (String) object[2];
|
}
|
Date date = new Date();
|
long time = date.getTime();
|
Timestamp excutionTimen = new Timestamp(time);
|
// 获取是否批量发起流程的flag
|
boolean batchExecuteTaskFlag = getBatchExecuteTaskFlag();
|
// 暂时不用
|
// saveWorkItemHist(taskId, approvalNote, boDelegate,
|
// bofBoDelegate, loDelegate, task, ObjectOids,
|
// btmType, btmDesc, excutionTimen, processName);
|
for (int j = 0; j < listTask.size(); j++) {
|
// Task newTask = taskService.createTaskQuery()
|
// .processInstanceId(excutionid).uniqueResult();
|
Task newTask = listTask.get(j);
|
if (newTask == null) {
|
return true;
|
}
|
List<Task> subTasks = taskService.getSubTasks(newTask.getId());
|
if (subTasks.size() > 0) {
|
for (int i = 0; i < subTasks.size(); i++) {
|
Task subTask = subTasks.get(i);
|
String nextTaskId = subTask.getId();
|
if (userNames == null || (userNames != null && userNames.length == 0)) {
|
userNames = taskAndUesrMap.get(newTask.getActivityName()).toArray(new String[] {});
|
} else {
|
String userServiceImplClass = WorkflowProperties
|
.getStringProperty("workflow.userService");
|
if (userServiceImplClass != null && !"".equals(userServiceImplClass)) {
|
IWorkflowUserService puService = (IWorkflowUserService) (Class
|
.forName(userServiceImplClass).newInstance());
|
String[] userNameList = puService.getAllUsers2Task(userNames,
|
userEntityInfo.modules);
|
// String[] userNameList = puService.getAllUsers2Task(userNames, getUserEntity().getModule());
|
userNames = userNameList;
|
}
|
}
|
|
// 出差设置的候选人
|
List<String> taskassignList = new ArrayList<String>();
|
for (int k = 0; k < userNames.length; k++) {
|
TasksAssigned tasksAssignedByUserName = getTasksAssignedByUserName(userNames[k]);
|
String taskassign = tasksAssignedByUserName.getTasksName();
|
if (taskassign == null || "".equals(taskassign)) {
|
taskassign = userNames[k];
|
}
|
String[] split = taskassign.split(",");
|
for (String s : split) {
|
if (!taskassignList.contains(s)) {
|
taskassignList.add(s);
|
}
|
}
|
}
|
if (taskassignList != null && taskassignList.size() > 0) {
|
userNames = taskassignList.toArray(new String[0]);
|
}
|
|
// add by xhcao 2014.06.24 begin
|
for (int m = 0; m < userNames.length; m++) {
|
// List<Participation> taskParticipations = taskService
|
// .getTaskParticipations(nextTaskId);
|
// for (Participation participation : taskParticipations) {
|
// taskService
|
// .removeTaskParticipatingUser(
|
// nextTaskId,
|
// participation
|
// .getUserId(),
|
// Participation.CANDIDATE);
|
// }
|
String subAssign = subTask.getAssignee();
|
String parsSubAssign = subAssign.substring(subAssign.indexOf(":") + 1,
|
subAssign.length());
|
if (parsSubAssign.equals(userNames[m])) {
|
// edit by changmk start 20170628 如果批量执行流程,则对全部数据添加审批意见记录
|
// WorkFlowService.getInstance().saveForComplete_v1(userNames, ObjectOids, subTask, btmType, btmDesc,
|
// processName, nextTaskId, m, objectProperty, objectPropertyValues);
|
if (batchExecuteTaskFlag) {
|
WorkFlowService.getInstance().saveForCompleteAndSaveOpinion_v1(userNames,
|
objectOids, subTask, btmType, btmDesc, processName, nextTaskId, m,
|
objectProperty, allObjectPropertyValues, outcome, approvalNote,
|
getSelectedOidSet(allObjectPropertyValues));
|
} else {
|
WorkFlowService.getInstance().saveForCompleteAndSaveOpinion_v1(userNames,
|
objectOids, subTask, btmType, btmDesc, processName, nextTaskId, m,
|
objectProperty, allObjectPropertyValues, outcome, approvalNote,
|
getSelectedOidSet(objectPropertyValues));
|
}
|
// edit by changmk end
|
}
|
// taskService.addTaskParticipatingUser(
|
// nextTaskId, userNames[m],
|
// Participation.CANDIDATE);
|
}
|
// add by xchao 2014.06.24 end
|
|
setCustomUserForAssgin(taskServices, taskDescList, nextTaskId);
|
userNames = null;
|
}
|
} else {
|
|
String nextTaskId = newTask.getId();
|
if (userNames == null || (userNames != null && userNames.length == 0)) {
|
userNames = taskAndUesrMap.get(newTask.getActivityName()).toArray(new String[] {});
|
} else {
|
String userServiceImplClass = WorkflowProperties
|
.getStringProperty("workflow.userService");
|
if (userServiceImplClass != null && !"".equals(userServiceImplClass)) {
|
IWorkflowUserService puService = (IWorkflowUserService) (Class
|
.forName(userServiceImplClass).newInstance());
|
String[] userNameList = puService.getAllUsers2Task(userNames,
|
userEntityInfo.modules);
|
// String[] userNameList = puService.getAllUsers2Task(userNames, getUserEntity().getModule());
|
ServerWithLog4j.logger.debug(
|
"=============com.vci.rmip.workflow.server.template.ProcessTemplateService.completeTaskByPlatform_v1(String, String, String, String, String[], String[], String[][]).userServiceImplClass==========username:"
|
+ getUserEntity().getUserName());
|
userNames = userNameList;
|
}
|
}
|
// 出差设置的候选人
|
List<String> taskassignList = new ArrayList<String>();
|
for (int k = 0; k < userNames.length; k++) {
|
TasksAssigned tasksAssignedByUserName = getTasksAssignedByUserName(userNames[k]);
|
String taskassign = tasksAssignedByUserName.getTasksName();
|
if (taskassign == null || "".equals(taskassign)) {
|
taskassign = userNames[k];
|
}
|
String[] split = taskassign.split(",");
|
for (String s : split) {
|
if (!taskassignList.contains(s)) {
|
taskassignList.add(s);
|
}
|
}
|
}
|
if (taskassignList != null && taskassignList.size() > 0) {
|
userNames = taskassignList.toArray(new String[0]);
|
}
|
|
// add by xhcao 2014.06.24 begin
|
for (int m = 0; m < userNames.length; m++) {
|
// edit by changmk start 20170628 如果批量执行流程,则对全部数据添加审批意见记录
|
// WorkFlowService.getInstance().saveForComplete_v1(userNames, ObjectOids, newTask, btmType, btmDesc,
|
// processName, nextTaskId, m, objectProperty, objectPropertyValues);
|
if (batchExecuteTaskFlag) {
|
WorkFlowService.getInstance().saveForCompleteAndSaveOpinion_v1(userNames,
|
objectOids, newTask, btmType, btmDesc, processName, nextTaskId, m,
|
objectProperty, allObjectPropertyValues, outcome, approvalNote,
|
getSelectedOidSet(allObjectPropertyValues));
|
} else {
|
WorkFlowService.getInstance().saveForCompleteAndSaveOpinion_v1(userNames,
|
objectOids, newTask, btmType, btmDesc, processName, nextTaskId, m,
|
objectProperty, allObjectPropertyValues, outcome, approvalNote,
|
getSelectedOidSet(objectPropertyValues));
|
}
|
// edit by changmk end
|
List<Participation> taskParticipations = taskService.getTaskParticipations(nextTaskId);
|
if (m == 0) {
|
for (Participation participation : taskParticipations) {
|
taskService.removeTaskParticipatingUser(nextTaskId, participation.getUserId(),
|
Participation.CANDIDATE);
|
}
|
}
|
taskService.addTaskParticipatingUser(nextTaskId, userNames[m], Participation.CANDIDATE);
|
}
|
// add by xchao 2014.06.24 end
|
|
setCustomUserForAssgin(taskServices, taskDescList, nextTaskId);
|
|
}
|
}
|
|
}
|
|
} else {
|
return true;
|
}
|
|
Execution executedProcessInstance = processEngine.getExecutionService()
|
.findExecutionById(task.getExecutionId());
|
if (isWorkFlowInstanceExist() && executedProcessInstance == null) {
|
completeWorkflowInstance(task.getExecutionId());
|
}
|
long endTime = System.currentTimeMillis();
|
ServerWithLog4j.logger.debug("结束时间:" + (endTime / 1000));
|
ServerWithLog4j.logger.debug("耗时:" + ((endTime - startTime) / 1000));
|
return flag;
|
} catch (VCIError ve) {
|
// ve.printStackTrace();
|
ServerWithLog4j.logger.error("completeTaskByPlatform_v1-1", ve);
|
throw ve;
|
} catch (Exception e) {
|
ServerWithLog4j.logger.error("completeTaskByPlatform_v1-2", e);
|
// e.printStackTrace();
|
if (e.getCause() != null && e.getCause() instanceof VCIError) {
|
throw (VCIError) e.getCause();
|
}
|
if (e.getCause() != null && e.getCause() instanceof InvocationTargetException) {
|
Throwable t = ((InvocationTargetException) e.getCause()).getTargetException();
|
if (t instanceof VCIError) {
|
throw (VCIError) t;
|
}
|
}
|
throw ServerErrorTool.getVCIError("执行流程过程中出现错误!" + e.getMessage(), e);
|
}
|
}
|
|
/**
|
* 判断workflowInstance业务对象是否存在
|
*
|
* @return
|
*/
|
private boolean isWorkFlowInstanceExist() {
|
String isWFInstanceExist = WorkflowProperties.getStringProperty("workflow.plmworkflowInstance.isExist");
|
if (isWFInstanceExist.equalsIgnoreCase("y")) {
|
return true;
|
} else {
|
return false;
|
}
|
}
|
|
/**
|
* 终止流程时,更改workflowInstance的状态为Completed
|
*
|
* @param processInstanceId
|
* @throws VCIError
|
*/
|
private void completeWorkflowInstance(String processInstanceId) throws VCIError {
|
|
String sql = String.format("UPDATE PLATFORMBTM_WORKFLOWINSTANCE SET %s='%s' WHERE EXECUTIONID='%s'",
|
BusinessConstants.SELECT_LCSTATUS, "Completed", processInstanceId);
|
|
SQLQuery sqlQuery = HibernateSessionFactory.getSession().createSQLQuery(sql);
|
sqlQuery.executeUpdate();
|
}
|
|
private void saveForComplete(String[] userNames, String[] objectOids, Task task, String btmType, String btmDesc,
|
String processName, String nextTaskId, int m)
|
throws VCIError, ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException,
|
IllegalAccessException, InvocationTargetException, InstantiationException {
|
if (workitemClass != null && !"".equals(workitemClass)) {
|
String userName = userNames[m];
|
// PLMWorkItemInterface pwService = (PLMWorkItemInterface)
|
// (Class.forName(workitemClass).newInstance());
|
if (_pwiService != null) {
|
_pwiService.saveForComplete(userName, objectOids, task, btmType, btmDesc, processName, nextTaskId,
|
owner);
|
ServerWithLog4j.logger.debug(owner);
|
}
|
}
|
}
|
|
private void deleteForkTask(String excutionid)
|
throws VCIError, IllegalArgumentException, IllegalAccessException, InvocationTargetException,
|
SecurityException, NoSuchMethodException, ClassNotFoundException, InstantiationException {
|
if (workitemClass != null && !"".equals(workitemClass)) {
|
// PLMWorkItemInterface pwService = (PLMWorkItemInterface)
|
// (Class.forName(workitemClass).newInstance());
|
if (_pwiService != null) {
|
_pwiService.deleteForkTask(excutionid);
|
}
|
|
// Class<?> c = Class.forName(workitemClass);
|
// Method m = c.getDeclaredMethod("deleteForkTask", new Class[]{String.class});
|
// m.invoke(c.newInstance(), new Object[]{excutionid});
|
}
|
}
|
|
/**
|
* 保存历史数据
|
*
|
* @param taskId
|
* @param approvalNote
|
* @param boDelegate
|
* @param bofBoDelegate
|
* @param loDelegate
|
* @param task
|
* @param ObjectOids
|
* @param btmType
|
* @param btmDesc
|
* @param excutionTimen
|
* @param processName
|
* @param histcloList
|
* @param histcboList
|
* @throws VCIError
|
* @throws PLMError
|
*/
|
// private void saveWorkItemHist(String taskId, String approvalNote,
|
// BOFactoryServerDelegate boDelegate,
|
// BOFactoryServerBODelegate bofBoDelegate,
|
// LOFacotryServerLODelegate loDelegate, Task task,
|
// String[] ObjectOids, String btmType, String btmDesc,
|
// Timestamp excutionTimen, String processName) throws VCIError {
|
// BusinessObject histCbo;
|
// histCbo = bofBoDelegate.initBusinessObject("WorkItemHistory"
|
// .toLowerCase());
|
// histCbo.id = ObjectUtility.getNewObjectID36();
|
// histCbo.name = processName+"-"+task.getActivityName();
|
// histCbo.description = approvalNote;
|
// ObjectTool.setBOAttributeValue(histCbo, "Executor".toLowerCase(),
|
// getUserEntity().getUserName());
|
// ObjectTool.setBOAttributeValue(histCbo, "ExecuteDate".toLowerCase(),
|
// excutionTimen.toString());
|
// ObjectTool
|
// .setBOAttributeValue(histCbo, "TaskOID".toLowerCase(), taskId);
|
// ObjectTool.setBOAttributeValue(histCbo, "executionid".toLowerCase(),
|
// task.getExecutionId());
|
// LinkObject clo;
|
//
|
// List<BusinessObject> histcboList = new ArrayList<BusinessObject>();
|
// histcboList.add(histCbo);
|
// List<LinkObject> histcloList = new ArrayList<LinkObject>();
|
// for (int k = 0; k < ObjectOids.length; k++) {
|
// clo = loDelegate.initLinkObject("input".toLowerCase());
|
// BusinessObject toBO = boDelegate.getInfoBusinessObject(
|
// ObjectOids[k], btmType);
|
// ObjectTool.setLOAttributeValue(clo,
|
// "linkdescription".toLowerCase(), btmDesc);
|
// ObjectTool.setLOFromBO(clo, histCbo);
|
// ObjectTool.setLOToBO(clo, toBO);
|
// histcloList.add(clo);
|
// }
|
// boDelegate.batchCreateBusinessObjectWithLink(
|
// histcboList.toArray(new BusinessObject[0]),
|
// histcloList.toArray(new LinkObject[0]));
|
//
|
// }
|
|
/**
|
* 流程申请人
|
*/
|
private String owner = "";
|
|
/**
|
* 删除业务对象中非当前人执行的任务(对应控制策略-任意人完成任务)
|
*
|
* @param taskId
|
* @param operation
|
* @return
|
* @throws PLMError
|
* @throws VCIError
|
* @throws NoSuchMethodException
|
* @throws SecurityException
|
* @throws ClassNotFoundException
|
* @throws InvocationTargetException
|
* @throws IllegalAccessException
|
* @throws IllegalArgumentException
|
* @throws InstantiationException
|
*/
|
private String[] updataWorkItem(String taskId, String executId, UserEntityInfo userEntityInfo)
|
throws VCIError, ClassNotFoundException, InstantiationException, IllegalAccessException {
|
String[] objectOids = null;
|
if (workitemClass != null && !"".equals(workitemClass)) {
|
// PLMWorkItemInterface pwService = (PLMWorkItemInterface)
|
// (Class.forName(workitemClass).newInstance());
|
if (_pwiService != null) {
|
if (userEntityInfo != null) {
|
objectOids = _pwiService.updataWorkItem(taskId, executId, userEntityInfo.userName, owner,
|
linkDataMap);
|
owner = _pwiService.getUser(userEntityInfo.userName, executId);
|
} else {
|
objectOids = _pwiService.updataWorkItem(taskId, executId, getUserEntity().getUserName(), owner,
|
linkDataMap);
|
owner = _pwiService.getUser(getUserEntity().getUserName(), executId);
|
}
|
}
|
// ServerWithLog4j.logger.debug("===============com.vci.rmip.workflow.server.template.ProcessTemplateService.updataWorkItem(String,
|
// String)===========username:" + getUserEntity().getUserName());
|
|
// Class<?> c = Class.forName(workitemClass);
|
// Method m = c.getDeclaredMethod("updataWorkItem", new Class[]{String.class,String.class,String.class,String.class,Map.class});
|
// objectOids = (String[]) m.invoke(c.newInstance(), new Object[]{taskId,executId,getUserEntity().getUserName(),owner,linkDataMap});
|
// Method m1 = c.getDeclaredMethod("getUser", new Class[]{String.class,String.class});
|
// owner = (String) m1.invoke(c.newInstance(), new Object[]{getUserEntity().getUserName(),executId});
|
// ServerWithLog4j.logger.debug("----ProcessTemplateService.updataWorkItem--获取owner:"
|
// + owner);
|
}
|
return objectOids;
|
}
|
|
/**
|
* 获取已选择数据在全部数据集合中的补集
|
*
|
* @param objectPropertyValues
|
* @return
|
* @author changmk
|
*/
|
private Set<String> getSelectedOidSet(String[][] objectPropertyValues) {
|
Set<String> set = new HashSet<String>();
|
if (objectPropertyValues != null) {// weidy添加判断
|
for (int i = 0; i < objectPropertyValues.length; i++) {
|
set.add(objectPropertyValues[i][0]);
|
}
|
}
|
return set;
|
}
|
|
/**
|
* 任务完成
|
*
|
* @param taskId
|
* @param outcome
|
* @param nextTaskName
|
* @param approvalNote
|
* @param userNames
|
* @return
|
* @throws VCIError
|
*/
|
public boolean completeTask(String taskId, String outcome, String nextTaskName, String approvalNote,
|
String[] userNames) throws VCIError {
|
try {
|
boolean flag = false;
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
Plflowapproveopinion plflowapproveopinion = new Plflowapproveopinion();
|
String ploid = ObjectUtility.getNewObjectID36();
|
plflowapproveopinion.setPloid(ploid);
|
plflowapproveopinion.setPltaskid(taskId);
|
plflowapproveopinion.setPlapprovenote(approvalNote);
|
// 记录执行者
|
plflowapproveopinion.setPlassgin(getUserEntity().getUserName());
|
|
TaskService taskService = processEngine.getTaskService();
|
Task task = taskService.getTask(taskId);
|
taskService.assignTask(taskId, getUserEntity().getUserName());
|
String processinstansid = processEngine.getExecutionService().findExecutionById(task.getExecutionId())
|
.getProcessInstance().getId();
|
|
if (userNames != null && userNames.length != 0) {
|
// configTaskAndUserWithComplate(userNames, processinstansid,
|
// nextTaskName);
|
{
|
HibernateSessionFactory.getSession().flush();
|
String user = Arrays.toString(userNames);
|
user = user.substring(1, user.length() - 1);
|
String sql = "update jbpm4_taskanduserconfigex set username = '" + user
|
+ "' where processinstansid = '" + processinstansid + "' and taskname = '" + nextTaskName
|
+ "'";
|
HibernateSessionFactory.getSession().createSQLQuery(sql).executeUpdate();
|
|
}
|
}
|
|
// 获取deploymentID
|
String deploymentId = getDeploymentIdByExecutionId(task.getExecutionId());
|
List<?> taskDescList = this.getTaskDescList(task.getActivityName(), deploymentId);
|
int pltreatment = 0;
|
if (taskDescList != null && taskDescList.size() > 0) {
|
pltreatment = ((TaskDescSObject) taskDescList.get(0)).getPltreatment();
|
}
|
// boolean endnodeFlag = false;
|
List<String> pariticipants = new ArrayList<String>();
|
if (userNames == null || userNames.length == 0) {
|
HibernateSessionFactory.getSession().flush();
|
String sql = "select a.username from JBPM4_TASKANDUSERCONFIGEX a where a.PROCESSINSTANSID = '"
|
+ processinstansid + "' and a.taskname = '" + nextTaskName + "'";
|
//无意义代码
|
// HibernateSessionFactory.getSession().createSQLQuery(sql)
|
// .executeUpdate();
|
List<?> list = HibernateSessionFactory.getSession().createSQLQuery(sql).list();
|
if (list != null && list.size() > 0) {
|
String valueOf = String.valueOf(list.get(0));
|
String[] split = valueOf.split(",");
|
for (int i = 0; i < split.length; i++) {
|
pariticipants.add(split[i].trim());
|
}
|
}
|
}
|
for (int k = 0; k < userNames.length; k++) {
|
pariticipants.add(userNames[k]);
|
}
|
|
Map<String, Object> variables = new HashMap<String, Object>();
|
variables.put("content", nextTaskName);
|
variables.put("OUTCOME", outcome);
|
variables.put("participants", pariticipants);
|
variables.put("userName", getUserEntity().getModule());
|
|
// variables.put("processEngine", processEngine);
|
// variables.put("plflowapproveopinion", plflowapproveopinion);
|
variables.put("approvalNote", approvalNote);
|
|
processEngine.getTaskService().setVariables(taskId, variables);
|
// 获取流程实例
|
ExecutionService executionService = processEngine.getExecutionService();
|
Execution execution = executionService.findExecutionById(task.getExecutionId());
|
// Execution processInstance = execution.getProcessInstance();
|
|
// 如果是1,则说明是会签,不对任务重新设置候选人
|
if (pltreatment == 0) {
|
if ("".equals(outcome)) {
|
processEngine.getTaskService().completeTask(taskId);
|
plflowapproveopinion.setPlapproveopinion("提交任务");
|
} else {
|
processEngine.getTaskService().completeTask(taskId, outcome, variables);
|
plflowapproveopinion.setPlapproveopinion(outcome);
|
|
}
|
flag = true;
|
// Task nextTask =
|
// taskService.createTaskQuery().processInstanceId(task.getExecutionId()).uniqueResult();
|
// if(nextTask!=null){
|
// String jbpmDeploymentId =
|
// getDeploymentIdByExecutionId(nextTask
|
// .getExecutionId());
|
// try {
|
// endnodeFlag = getEndNode(jbpmDeploymentId,
|
// nextTask.getActivityName());
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// }
|
// if (!endnodeFlag) {
|
// taskDescList =
|
// this.getTaskDescList(nextTask.getActivityName(),
|
// deploymentId);
|
// pltreatment = ((TaskDescSObject) taskDescList.get(0))
|
// .getPltreatment();
|
// }
|
// }else{
|
// endnodeFlag = true;
|
// }
|
|
} else {
|
List<Task> joinTasks = taskService.findPersonalTasks(getUserEntity().getUserName());
|
// boolean executeFlag = false;
|
List<Task> subTasks = taskService.getSubTasks(task.getId());
|
Task joinTask = null;
|
for (int j = 0; j < joinTasks.size(); j++) {
|
for (int i = 0; i < subTasks.size(); i++) {
|
if ((subTasks.get(i).getName().equals(joinTasks.get(j).getName()))
|
&& (subTasks.get(i).getId().equals(joinTasks.get(j).getId()))) {
|
joinTask = joinTasks.get(j);
|
// executeFlag = true;
|
break;
|
}
|
}
|
}
|
|
Map<String, Object> v = new HashMap<String, Object>();
|
v.put(Sign.VAR_SIGN, outcome);
|
taskService.setVariables(joinTask.getId(), v);
|
Sign sign = new Sign(task.getId(), joinTask, outcome, getUserEntity().getUserName(), deploymentId);
|
|
Boolean execute = processEngine.execute(sign);
|
String[] trainNames = new ProcessTemplateService().getTrainName(deploymentId, task.getActivityName(),
|
outcome);
|
nextTaskName = trainNames[0];
|
if (execute) {
|
Map<String, Object> map = new HashMap<String, Object>();
|
map.put("OUTCOME", outcome);
|
// map.put("plflowapproveopinion", plflowapproveopinion);
|
map.put("approvalNote", approvalNote);
|
if (taskService.getSubTasks(taskId).size() != 0) {
|
taskService.takeTask(taskId, getUserEntity().getUserName());
|
}
|
if (nextTaskName != null && !"".equals(nextTaskName)) {
|
new ProcessTemplateService().completeTaskByCreateTransiton(taskService, task, nextTaskName,
|
nextTaskName, map);
|
taskService.completeTask(taskId, nextTaskName, map);
|
} else {
|
taskService.completeTask(taskId, outcome, map);
|
}
|
}
|
|
plflowapproveopinion.setPlapproveopinion(outcome);
|
flag = execute;
|
}
|
|
new PlflowapproveopinionDaoImpl().save(plflowapproveopinion);
|
if (flag) {
|
String userName = "";
|
TaskService taskServices = processEngine.getTaskService();
|
String[] execIDs = task.getExecutionId().replace(".", ",").split(",");
|
String excutionid = "";
|
if (execIDs.length > 2) {
|
excutionid = execIDs[0] + "." + execIDs[1];
|
} else {
|
excutionid = task.getExecutionId();
|
}
|
|
List<Task> listTask = taskService.createTaskQuery().processInstanceId(excutionid).list();
|
if (listTask != null) {
|
// String[] execIDs = task.getExecutionId().replace(".",
|
// ",").split(",");
|
// String activityName = getNextTaskName(deploymentId, null,
|
// task.getActivityName(), outcome);
|
// List<Task> listTask = taskService.createTaskQuery()
|
// .processInstanceId(execIDs[0]+"."+execIDs[1])
|
// .list();
|
// 如果分支中的任务跳出分支,则执行删除分支中的任务
|
boolean forkFlag = false;
|
String[] forkTaskNames = getForkTaskNames(deploymentId);
|
String[] curtTaskNames = new String[listTask.size()];
|
String custTask = "";
|
String[] custTaskIds = new String[listTask.size()];
|
String custTaskId = "";
|
for (int i = 0; i < listTask.size(); i++) {
|
curtTaskNames[i] = listTask.get(i).getActivityName();
|
custTaskIds[i] = listTask.get(i).getId();
|
}
|
if (!Arrays.equals(forkTaskNames, curtTaskNames)) {
|
if (curtTaskNames.length == 1) {
|
for (int i = 0; i < forkTaskNames.length; i++) {
|
if (curtTaskNames[0].equals(forkTaskNames[i])) {
|
forkFlag = false;
|
break;
|
} else {
|
forkFlag = true;
|
custTask = curtTaskNames[0];
|
custTaskId = custTaskIds[0];
|
}
|
}
|
} else {
|
for (int i = 0; i < curtTaskNames.length; i++) {
|
for (int j = 0; j < forkTaskNames.length; j++) {
|
if (!curtTaskNames[i].equals(forkTaskNames[j])) {
|
custTask = curtTaskNames[i];
|
custTaskId = custTaskIds[i];
|
}
|
}
|
}
|
forkFlag = true;
|
}
|
}
|
// 如果分支中的任务跳出分支,则执行删除分支中的任务
|
if (forkFlag) {
|
HibernateSessionFactory.getSession().flush();
|
String sqlDelExecution = "delete from jbpm4_execution where id_ like '" + excutionid
|
+ "%' and parent_ is not null";
|
HibernateSessionFactory.getSession().createSQLQuery(sqlDelExecution).executeUpdate();
|
for (String forkTask : forkTaskNames) {
|
String sqldelParticipation = "delete jbpm4_participation where task_ =(select dbid_ from jbpm4_task where execution_id_ like '"
|
+ excutionid + "%' and name_ = '" + forkTask + "' )";
|
HibernateSessionFactory.getSession().createSQLQuery(sqldelParticipation).executeUpdate();
|
String sqlDelTask = "delete from jbpm4_task where execution_id_ like '" + excutionid
|
+ "%' and name_ = '" + forkTask + "' ";
|
HibernateSessionFactory.getSession().createSQLQuery(sqlDelTask).executeUpdate();
|
}
|
// 由于多次对同一张表操作,无法再同一事务中完成。只能使用多个事务处理。
|
HibernateSessionFactory.getSession().getTransaction().commit();
|
HibernateSessionFactory.getSession().getTransaction().begin();
|
if (curtTaskNames != null) {
|
HibernateSessionFactory.getSession().flush();
|
String sqlUpdata = "update jbpm4_execution b set b.activityname_ = '" + custTask
|
+ "' , b.state_ ='active-root' where b.id_ = '" + excutionid + "'";
|
HibernateSessionFactory.getSession().createSQLQuery(sqlUpdata).executeUpdate();
|
String sqlSelectExecution = "select dbid_ from jbpm4_execution where activityname_ = '"
|
+ custTask + "' and id_ = '" + excutionid + "'";
|
String sqlUpdataTask = "update jbpm4_task b set b.execution_id_ = '" + excutionid
|
+ "',b.execution_ =(" + sqlSelectExecution + ") where b.name_ = '" + custTask
|
+ "' and b.dbid_ = '" + custTaskId + "'";
|
HibernateSessionFactory.getSession().createSQLQuery(sqlUpdataTask).executeUpdate();
|
}
|
}
|
for (int i = 0; i < listTask.size(); i++) {
|
String nextTaskId = listTask.get(i).getId();
|
for (int j = 0; j < userNames.length; j++) {
|
userName += "," + userNames[j];
|
if (userNames.length > 0) {
|
|
List<Participation> taskParticipations = taskService.getTaskParticipations(nextTaskId);
|
// 先删除原来的任务候选人
|
if (j == 0) {
|
ServerWithLog4j.logger.debug("删除原有候选人");
|
// taskService.assignTask(nextTaskId, null);
|
for (Participation participation : taskParticipations) {
|
taskService.removeTaskParticipatingUser(nextTaskId, participation.getUserId(),
|
Participation.CANDIDATE);
|
}
|
}
|
ServerWithLog4j.logger.debug("设置候选人" + userNames[j]);
|
taskService.addTaskParticipatingUser(nextTaskId, userNames[j], Participation.CANDIDATE);
|
|
}
|
}
|
setCustomUserForAssgin(taskServices, taskDescList, nextTaskId);
|
}
|
|
}
|
|
// if(nextTask!=null){
|
// if(!getEndNode(deploymentId,nextTask.getActivityName())){
|
}
|
// }
|
// }
|
|
return flag;
|
} catch (Exception e) {
|
// exception.printStackTrace();
|
ServerWithLog4j.logger.error("completeTask", e);
|
throw new VCIError();
|
}
|
|
}
|
|
/**
|
* 任务完成
|
*
|
* @param taskId
|
* @param outcome
|
* @param nextTaskName
|
* @param approvalNote
|
* @param userNames
|
* @param keys 设置流程参数key
|
* @param values 设置流程参数value
|
* @return
|
* @throws VCIError
|
*/
|
public boolean completeTask(String taskId, String outcome, String nextTaskName, String approvalNote,
|
String[] userNames, String[] keys, String[] values) throws VCIError {
|
long startTime = System.currentTimeMillis();
|
ServerWithLog4j.logger.debug("开始时间:" + (startTime / 1000));
|
try {
|
boolean flag = false;
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
Plflowapproveopinion plflowapproveopinion = new Plflowapproveopinion();
|
String ploid = ObjectUtility.getNewObjectID36();
|
plflowapproveopinion.setPloid(ploid);
|
plflowapproveopinion.setPltaskid(taskId);
|
plflowapproveopinion.setPlapprovenote(approvalNote);
|
// 记录执行者
|
plflowapproveopinion.setPlassgin(getUserEntity().getUserName());
|
|
TaskService taskService = processEngine.getTaskService();
|
Task task = taskService.getTask(taskId);
|
if (task == null) {
|
throw new VCIError("任务已经完成!", new String[] {});
|
}
|
// taskService.assignTask(taskId, getUserEntity().getUserName());
|
String processinstansid = processEngine.getExecutionService().findExecutionById(task.getExecutionId())
|
.getProcessInstance().getId();
|
|
if (userNames != null && userNames.length != 0) {
|
// configTaskAndUserWithComplate(userNames, processinstansid,
|
// nextTaskName);
|
{
|
// HibernateSessionFactory.getSession().flush();
|
// String user = Arrays.toString(userNames);
|
// user = user.substring(1, user.length() - 1);
|
// String sql = "update jbpm4_taskanduserconfigex set username = '"
|
// + user
|
// + "' where processinstansid = '"
|
// + processinstansid
|
// + "' and taskname = '"
|
// + nextTaskName + "'";
|
// HibernateSessionFactory.getSession().createSQLQuery(sql)
|
// .executeUpdate();
|
// TODO test mul user
|
setMulNextTaskUser(processinstansid, nextTaskName, userNames);
|
|
}
|
}
|
|
// 获取deploymentID
|
String deploymentId = getDeploymentIdByExecutionId(task.getExecutionId());
|
List<?> taskDescList = this.getTaskDescList(task.getActivityName(), deploymentId);
|
int pltreatment = 0;
|
if (taskDescList != null && taskDescList.size() > 0) {
|
pltreatment = ((TaskDescSObject) taskDescList.get(0)).getPltreatment();
|
}
|
// boolean endnodeFlag = false;
|
List<String> pariticipants = new ArrayList<String>();
|
if (userNames == null || userNames.length == 0) {
|
HibernateSessionFactory.getSession().flush();
|
String sql = "select a.username from JBPM4_TASKANDUSERCONFIGEX a where a.PROCESSINSTANSID = '"
|
+ processinstansid + "' and a.taskname = '" + nextTaskName + "'";
|
//无意义代码
|
// HibernateSessionFactory.getSession().createSQLQuery(sql)
|
// .executeUpdate();
|
List<?> list = HibernateSessionFactory.getSession().createSQLQuery(sql).list();
|
if (list != null && list.size() > 0) {
|
String valueOf = String.valueOf(list.get(0));
|
String[] split = valueOf.split(",");
|
for (int i = 0; i < split.length; i++) {
|
pariticipants.add(split[i].trim());
|
}
|
}
|
}
|
for (int k = 0; k < userNames.length; k++) {
|
pariticipants.add(userNames[k]);
|
}
|
|
Map<String, Object> variables = new HashMap<String, Object>();
|
variables.put("content", nextTaskName);
|
variables.put("OUTCOME", outcome);
|
variables.put("participants", pariticipants);
|
variables.put("userName", getUserEntity().getModule());
|
variables.put("currentSelectuserName", userNames);
|
|
// variables.put("processEngine", processEngine);
|
// variables.put("plflowapproveopinion", plflowapproveopinion);
|
variables.put("approvalNote", approvalNote);
|
|
if (keys != null) {
|
for (int i = 0; i < keys.length; i++) {
|
variables.put(keys[i], values[i]);
|
}
|
}
|
processEngine.getTaskService().setVariables(taskId, variables);
|
// 获取流程实例
|
ExecutionService executionService = processEngine.getExecutionService();
|
Execution execution = executionService.findExecutionById(task.getExecutionId());
|
// Execution processInstance = execution.getProcessInstance();
|
|
TaskService taskServices = processEngine.getTaskService();
|
String[] execIDs = task.getExecutionId().replace(".", ",").split(",");
|
String excutionid = "";
|
if (execIDs.length > 2) {
|
excutionid = execIDs[0] + "." + execIDs[1];
|
} else {
|
excutionid = task.getExecutionId();
|
}
|
List<Task> histlistTask = taskService.createTaskQuery().processInstanceId(excutionid).list();
|
|
// 如果是1,则说明是会签,不对任务重新设置候选人
|
if (pltreatment == 0) {
|
if ("".equals(outcome)) {
|
processEngine.getTaskService().completeTask(taskId);
|
plflowapproveopinion.setPlapproveopinion("提交任务");
|
} else {
|
processEngine.getTaskService().completeTask(taskId, outcome, variables);
|
plflowapproveopinion.setPlapproveopinion(outcome);
|
|
}
|
flag = true;
|
// Task nextTask =
|
// taskService.createTaskQuery().processInstanceId(task.getExecutionId()).uniqueResult();
|
// if(nextTask!=null){
|
// String jbpmDeploymentId =
|
// getDeploymentIdByExecutionId(nextTask
|
// .getExecutionId());
|
// try {
|
// endnodeFlag = getEndNode(jbpmDeploymentId,
|
// nextTask.getActivityName());
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// }
|
// if (!endnodeFlag) {
|
// taskDescList =
|
// this.getTaskDescList(nextTask.getActivityName(),
|
// deploymentId);
|
// pltreatment = ((TaskDescSObject) taskDescList.get(0))
|
// .getPltreatment();
|
// }
|
// }else{
|
// endnodeFlag = true;
|
// }
|
|
} else {
|
List<Task> joinTasks = taskService.findPersonalTasks(getUserEntity().getUserName());
|
// boolean executeFlag = false;
|
List<Task> subTasks = taskService.getSubTasks(task.getId());
|
Task joinTask = null;
|
for (int j = 0; j < joinTasks.size(); j++) {
|
for (int i = 0; i < subTasks.size(); i++) {
|
if ((subTasks.get(i).getName().equals(joinTasks.get(j).getName()))
|
&& (subTasks.get(i).getId().equals(joinTasks.get(j).getId()))) {
|
joinTask = joinTasks.get(j);
|
// executeFlag = true;
|
break;
|
}
|
}
|
}
|
|
Map<String, Object> v = new HashMap<String, Object>();
|
v.put(Sign.VAR_SIGN, outcome);
|
taskService.setVariables(joinTask.getId(), v);
|
Sign sign = new Sign(task.getId(), joinTask, outcome, getUserEntity().getUserName(), deploymentId);
|
|
Boolean execute = processEngine.execute(sign);
|
String[] trainNames = new ProcessTemplateService().getTrainName(deploymentId, task.getActivityName(),
|
outcome);
|
nextTaskName = trainNames[0];
|
if (execute) {
|
Map<String, Object> map = new HashMap<String, Object>();
|
map.put("OUTCOME", outcome);
|
// map.put("plflowapproveopinion", plflowapproveopinion);
|
map.put("approvalNote", approvalNote);
|
if (taskService.getSubTasks(taskId).size() != 0) {
|
taskService.takeTask(taskId, getUserEntity().getUserName());
|
}
|
if (nextTaskName != null && !"".equals(nextTaskName)) {
|
new ProcessTemplateService().completeTaskByCreateTransiton(taskService, task, nextTaskName,
|
nextTaskName, map);
|
taskService.completeTask(taskId, nextTaskName, map);
|
} else {
|
taskService.completeTask(taskId, outcome, map);
|
}
|
}
|
|
plflowapproveopinion.setPlapproveopinion(outcome);
|
flag = execute;
|
}
|
|
new PlflowapproveopinionDaoImpl().save(plflowapproveopinion);
|
if (flag) {
|
// String userName = "";
|
List<Task> listTask = taskService.createTaskQuery().processInstanceId(excutionid).list();
|
List<Task> currentTaskList = new ArrayList<Task>();
|
currentTaskList.addAll(listTask);
|
for (Task cTask : listTask) {
|
for (Task bTask : histlistTask) {
|
if (cTask.getName().equals(bTask.getName())) {
|
currentTaskList.remove(cTask);
|
break;
|
}
|
}
|
}
|
listTask = currentTaskList;
|
if (listTask != null && listTask.size() > 0) {
|
// String[] execIDs = task.getExecutionId().replace(".",
|
// ",").split(",");
|
// String activityName = getNextTaskName(deploymentId, null,
|
// task.getActivityName(), outcome);
|
// List<Task> listTask = taskService.createTaskQuery()
|
// .processInstanceId(execIDs[0]+"."+execIDs[1])
|
// .list();
|
// 如果分支中的任务跳出分支,则执行删除分支中的任务
|
boolean forkFlag = false;
|
String[] forkTaskNames = getForkTaskNames(deploymentId);
|
String[] curtTaskNames = new String[listTask.size()];
|
String custTask = "";
|
String[] custTaskIds = new String[listTask.size()];
|
String custTaskId = "";
|
for (int i = 0; i < listTask.size(); i++) {
|
curtTaskNames[i] = listTask.get(i).getActivityName();
|
custTaskIds[i] = listTask.get(i).getId();
|
}
|
if (!Arrays.equals(forkTaskNames, curtTaskNames)) {
|
if (curtTaskNames.length == 1) {
|
for (int i = 0; i < forkTaskNames.length; i++) {
|
if (curtTaskNames[0].equals(forkTaskNames[i])) {
|
forkFlag = false;
|
break;
|
} else {
|
forkFlag = true;
|
custTask = curtTaskNames[0];
|
custTaskId = custTaskIds[0];
|
}
|
}
|
} else {
|
for (int i = 0; i < curtTaskNames.length; i++) {
|
for (int j = 0; j < forkTaskNames.length; j++) {
|
if (!curtTaskNames[i].equals(forkTaskNames[j])) {
|
custTask = curtTaskNames[i];
|
custTaskId = custTaskIds[i];
|
}
|
}
|
}
|
forkFlag = true;
|
}
|
}
|
// 如果分支中的任务跳出分支,则执行删除分支中的任务
|
if (forkFlag) {
|
HibernateSessionFactory.getSession().flush();
|
String sqlDelExecution = "delete from jbpm4_execution where id_ like '" + excutionid
|
+ "%' and parent_ is not null";
|
HibernateSessionFactory.getSession().createSQLQuery(sqlDelExecution).executeUpdate();
|
for (String forkTask : forkTaskNames) {
|
String sqldelParticipation = "delete jbpm4_participation where task_ =(select dbid_ from jbpm4_task where execution_id_ like '"
|
+ excutionid + "%' and name_ = '" + forkTask + "' )";
|
HibernateSessionFactory.getSession().createSQLQuery(sqldelParticipation).executeUpdate();
|
String sqlDelTask = "delete from jbpm4_task where execution_id_ like '" + excutionid
|
+ "%' and name_ = '" + forkTask + "' ";
|
HibernateSessionFactory.getSession().createSQLQuery(sqlDelTask).executeUpdate();
|
}
|
// 由于多次对同一张表操作,无法再同一事务中完成。只能使用多个事务处理。
|
HibernateSessionFactory.getSession().getTransaction().commit();
|
HibernateSessionFactory.getSession().getTransaction().begin();
|
if (curtTaskNames != null) {
|
HibernateSessionFactory.getSession().flush();
|
String sqlUpdata = "update jbpm4_execution b set b.activityname_ = '" + custTask
|
+ "' , b.state_ ='active-root' where b.id_ = '" + excutionid + "'";
|
HibernateSessionFactory.getSession().createSQLQuery(sqlUpdata).executeUpdate();
|
String sqlSelectExecution = "select dbid_ from jbpm4_execution where activityname_ = '"
|
+ custTask + "' and id_ = '" + excutionid + "'";
|
String sqlUpdataTask = "update jbpm4_task b set b.execution_id_ = '" + excutionid
|
+ "',b.execution_ =(" + sqlSelectExecution + ") where b.name_ = '" + custTask
|
+ "' and b.dbid_ = '" + custTaskId + "'";
|
HibernateSessionFactory.getSession().createSQLQuery(sqlUpdataTask).executeUpdate();
|
}
|
}
|
for (int i = 0; i < listTask.size(); i++) {
|
String nextTaskId = listTask.get(i).getId();
|
String cUserName = this.getNextTaskAssigner(excutionid, listTask.get(i).getName());
|
userNames = cUserName.split(",");
|
for (int j = 0; j < userNames.length; j++) {
|
userNames[j] = userNames[j].trim();
|
// userName += "," + userNames[j];
|
if (userNames.length > 0) {
|
|
List<Participation> taskParticipations = taskService.getTaskParticipations(nextTaskId);
|
// 先删除原来的任务候选人
|
if (j == 0) {
|
ServerWithLog4j.logger.debug("删除原有候选人");
|
// taskService.assignTask(nextTaskId, null);
|
for (Participation participation : taskParticipations) {
|
taskService.removeTaskParticipatingUser(nextTaskId, participation.getUserId(),
|
Participation.CANDIDATE);
|
}
|
}
|
ServerWithLog4j.logger.debug("设置候选人" + userNames[j]);
|
taskService.addTaskParticipatingUser(nextTaskId, userNames[j], Participation.CANDIDATE);
|
|
}
|
}
|
setCustomUserForAssgin(taskServices, taskDescList, nextTaskId);
|
}
|
|
}
|
|
// if(nextTask!=null){
|
// if(!getEndNode(deploymentId,nextTask.getActivityName())){
|
}
|
// }
|
// }
|
long endTime = System.currentTimeMillis();
|
ServerWithLog4j.logger.debug("结束时间:" + (endTime / 1000));
|
ServerWithLog4j.logger.debug("耗时:" + ((endTime - startTime) / 1000));
|
return flag;
|
} catch (Exception e) {
|
// exception.printStackTrace();
|
ServerWithLog4j.logger.error("completeTask", e);
|
throw new VCIError();
|
}
|
|
}
|
|
private void setMulNextTaskUser(String processinstansid, String nextTaskName, String[] userNames) {
|
HibernateSessionFactory.getSession().flush();
|
if (nextTaskName.indexOf(",") > 0) {
|
String[] nextTaskNames = nextTaskName.split(",");
|
for (int i = 0; i < nextTaskNames.length; i++) {
|
String sql = "update jbpm4_taskanduserconfigex set username = '" + userNames[i]
|
+ "' where processinstansid = '" + processinstansid + "' and taskname = '"
|
+ nextTaskNames[i].trim() + "'";
|
HibernateSessionFactory.getSession().createSQLQuery(sql).executeUpdate();
|
}
|
} else {
|
String user = Arrays.toString(userNames);
|
user = user.substring(1, user.length() - 1);
|
String sql = "update jbpm4_taskanduserconfigex set username = '" + user + "' where processinstansid = '"
|
+ processinstansid + "' and taskname = '" + nextTaskName + "'";
|
HibernateSessionFactory.getSession().createSQLQuery(sql).executeUpdate();
|
}
|
}
|
|
/**
|
* 判断任务是否有子任务
|
*
|
* @param taskid
|
* @return
|
*/
|
public List<Task> getsubTasks(String taskid) {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
List<Task> subTasks = processEngine.getTaskService().getSubTasks(taskid);
|
if (subTasks == null || subTasks.size() == 0) {
|
return new ArrayList<Task>();
|
}
|
return subTasks;
|
}
|
|
/**
|
* 编码资源专用
|
*
|
* @param taskId
|
* @param outcome
|
* @param approvalNote
|
* @param userNames
|
* @throws VCIError
|
*/
|
public void completeTask(final String taskId, final String outcome, final String approvalNote, String[] userNames)
|
throws VCIError {
|
// 完成任务
|
boolean flag = false;
|
Plflowapproveopinion plflowapproveopinion = new Plflowapproveopinion();
|
String ploid = ObjectUtility.getNewObjectID36();
|
plflowapproveopinion.setPloid(ploid);
|
plflowapproveopinion.setPltaskid(taskId);
|
plflowapproveopinion.setPlapprovenote(approvalNote);
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
Task task = processEngine.getTaskService().getTask(taskId);
|
// 获取流程实例
|
ProcessInstance processInstance = processEngine.getExecutionService()
|
.findProcessInstanceById(processEngine.getTaskService().getTask(taskId).getExecutionId());
|
FlowInstanceDaoImpl impl = new FlowInstanceDaoImpl();
|
String hql = "from FlowInstance t where t.executionid = ?";
|
FlowInstance flowInstance = (FlowInstance) impl.findEntity(hql, new Object[] { task.getExecutionId() });
|
|
// 流程数据对象
|
List<PLFlowObject> flowObjects = getFlowObjectByExecutionId(task.getExecutionId());
|
// 获取deploymentID
|
String deploymentId = getDeploymentIdByExecutionId(task.getExecutionId());
|
List<?> list = this.getTaskDescList(task.getActivityName(), deploymentId);
|
int pltreatment = 0;
|
if (list != null && list.size() > 0) {
|
pltreatment = ((TaskDescSObject) list.get(0)).getPltreatment();
|
}
|
// boolean endnodeFlag = false;
|
List<String> pariticipants = new ArrayList<String>();
|
for (int k = 0; k < userNames.length; k++) {
|
pariticipants.add(userNames[k]);
|
}
|
// 如果是1,则说明是会签,不对任务重新设置候选人
|
if (pltreatment == 0) {
|
if (task.getAssignee() == null) {
|
processEngine.getTaskService().takeTask(taskId, getUserEntity().getUserName());
|
}
|
try {
|
if ("".equals(outcome)) {
|
Map<String, Object> variables = new HashMap<String, Object>();
|
variables.put("userName", getUserEntity().getUserName());
|
variables.put("userIP", getUserEntity().getIp());
|
variables.put("userModule", getUserEntity().getModule());
|
// variables.put("content", nextTaskName);
|
variables.put("OUTCOME", outcome);
|
variables.put("participants", pariticipants);
|
variables.put("userNameNext", userNames);
|
|
variables.put("processEngine", processEngine);
|
variables.put("processInstance", processInstance);
|
variables.put("flowInstance", flowInstance);
|
variables.put("flowObjects", flowObjects);
|
variables.put("plflowapproveopinion", plflowapproveopinion);
|
|
// add by xchao 2013.05.19 begin
|
// 标识流程流程是否启动完成,以便利用该值在判断第一个任务的初始事件是否需要执行相关事件处理
|
variables.put("ProcessStarted", "true");
|
// add by xchao 2013.05.19 end
|
|
processEngine.getTaskService().setVariables(taskId, variables);
|
processEngine.getTaskService().completeTask(taskId);
|
plflowapproveopinion.setPlapproveopinion("提交任务");
|
} else {
|
Map<String, Object> map = new HashMap<String, Object>();
|
// map.put("content", nextTaskName);
|
map.put("OUTCOME", outcome);
|
map.put("participants", pariticipants);
|
map.put("userNameNext", userNames);
|
|
map.put("processEngine", processEngine);
|
map.put("processInstance", processInstance);
|
map.put("flowInstance", flowInstance);
|
map.put("flowObjects", flowObjects);
|
map.put("plflowapproveopinion", plflowapproveopinion);
|
|
// add by xchao 2013.05.19 begin
|
// 标识流程流程是否启动完成,以便利用该值在判断第一个任务的初始事件是否需要执行相关事件处理
|
map.put("ProcessStarted", "true");
|
// add by xchao 2013.05.19 end
|
|
processEngine.getTaskService().setVariables(taskId, map);
|
processEngine.getTaskService().completeTask(taskId, outcome, map);
|
plflowapproveopinion.setPlapproveopinion(outcome);
|
}
|
flag = true;
|
} catch (Exception e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("completeTask-1", e);
|
// flag = true;
|
// 异常信息处理
|
if (e.getCause() instanceof VCIError) {
|
throw new VCIError(((VCIError) e.getCause()).code, ((VCIError) e.getCause()).messages);
|
} else {
|
// e.printStackTrace();
|
// ServerWithLog4j.logger.error("completeTask-2", e);
|
}
|
}
|
} else {
|
|
Task joinTask = processEngine.getTaskService().findPersonalTasks(getUserEntity().getUserName()).get(0);
|
|
boolean executeFlag = false;
|
List<Task> subTasks = processEngine.getTaskService().getSubTasks(task.getId());
|
for (int i = 0; i < subTasks.size(); i++) {
|
if (subTasks.get(i).getName().equals(joinTask.getName())) {
|
executeFlag = true;
|
}
|
}
|
if (!executeFlag) {
|
// throw new Error("该任务已经处理,请等待其他用户处理!");
|
throw new VCIError("410125", new String[] {});
|
|
}
|
|
Map<String, Object> v = new HashMap<String, Object>();
|
v.put(Sign.VAR_SIGN, outcome);
|
processEngine.getTaskService().setVariables(joinTask.getId(), v);
|
Sign sign = new Sign(task.getId(), joinTask, outcome, getUserEntity().getUserName(), deploymentId);
|
|
Boolean execute = processEngine.execute(sign);
|
if (execute) {
|
Map<String, Object> map = new HashMap<String, Object>();
|
map.put("OUTCOME", outcome);
|
map.put("userNameNext", userNames);
|
|
map.put("processEngine", processEngine);
|
map.put("processInstance", processInstance);
|
map.put("flowInstance", flowInstance);
|
map.put("flowObjects", flowObjects);
|
map.put("plflowapproveopinion", plflowapproveopinion);
|
|
// add by xchao 2013.05.19 begin
|
// 标识流程流程是否启动完成,以便利用该值在判断第一个任务的初始事件是否需要执行相关事件处理
|
map.put("ProcessStarted", "true");
|
// add by xchao 2013.05.19 end
|
|
if (processEngine.getTaskService().getSubTasks(taskId).size() != 0) {
|
processEngine.getTaskService().takeTask(taskId, getUserEntity().getUserName());
|
}
|
processEngine.getTaskService().completeTask(taskId, outcome, map);
|
}
|
plflowapproveopinion.setPlapproveopinion(outcome);
|
flag = execute;
|
}
|
|
// 完成任务后,如果未出现错误,则处理下一个任务的候选人数据
|
// if(flag) return;
|
String sb = " insert into PLFLOWAPPROVEOPINION values(?,?,?,?,?) ";
|
Session session = HibernateSessionFactory.getSession();
|
|
try {
|
Query query = session.createQuery(sb);
|
|
query.setString(1, plflowapproveopinion.getPloid());
|
query.setString(2, plflowapproveopinion.getPltaskid());
|
query.setString(3, plflowapproveopinion.getPlapproveopinion());
|
query.setString(4, plflowapproveopinion.getPlapprovenote());
|
query.executeUpdate();
|
|
TaskService taskService = processEngine.getTaskService();
|
Task nextTask = taskService.createTaskQuery().processInstanceId(task.getExecutionId()).uniqueResult();
|
if (nextTask == null) {
|
return;
|
}
|
String nextTaskId = nextTask.getId();
|
String activityName = nextTask.getActivityName();
|
|
String[] customUsers = new String[0];
|
String[] userNamesNew = new String[0];
|
|
if (flag) {
|
// add by xchao 2013.05.19 bgien
|
/**
|
* 解决的问题:'清空当前任务自定义候选人处理类计算出的候选人’ 由于完善当前任务节点时,会执行一个的任务的‘自定义候选人事件’(如果定义了)及其‘初始事件’
|
* 而在‘自定义候选人事件’中会注入CustomUserNames值,即自定义候选人, 而如果当前节点定义了自定义候选人事件,而一个节点未定义,
|
* 此时在CustomUserNames是在当前节点上计算出的值,是能处理当前节点的候选人 因此在完成当前节点时,如果下一个节点未定义自定义候选人处理类,
|
* 则需要清空CustomUserNames的值,以还原数据状态
|
*
|
* 在此处执行是因为,执行到这里,对于当前任务已经执行的‘完成任务’, 同时一个任务的初始事件而且已经执行完成,
|
* 后面的代码段通过通过API接口修改一个任务的处理人 为了解决‘当前任务自定义候选人对一个任务的感染’, 因此在本段尝试执行清空动作,以清除可能在感染。
|
*/
|
List<TaskDescSObject> taskDescList = this.getTaskDescList(activityName, deploymentId);
|
if (taskDescList != null) {
|
for (int i = 0; i < taskDescList.size(); i++) {
|
TaskDescSObject taskDescSObject = taskDescList.get(i);
|
String customclass = taskDescSObject.getPlcustomclassname();
|
String param = taskDescSObject.getPlcustomparam();
|
if (customclass != null && !"".equals(customclass)) {
|
// 对于解决 '清空当前任务自定义候选人处理类计算出的候选人’
|
// 此条件中不需要执行任何逻辑
|
} else {
|
// 对于解决'清空当前任务自定义候选人处理类计算出的候选人’
|
// 根据 nextTaskId 查出的 activityName 节点未定义‘自定义候选人’
|
// 因此,需要清空在当前任务节点中计算出的
|
HashMap<String, Object> map = new HashMap<String, Object>();
|
map.put("CustomUserNames", new String[] {});
|
taskService.setVariables(nextTaskId, map);
|
}
|
}
|
}
|
// add by xchao 2013.05.19 end
|
|
Object variable = taskService.getVariable(nextTaskId, "CustomUserNames");
|
if (variable instanceof String[]) {
|
String[] v = (String[]) variable;
|
if (v != null) {
|
customUsers = v;
|
}
|
}
|
|
if (customUsers != null) {
|
userNamesNew = new String[customUsers.length];
|
}
|
if (userNames != null) {
|
userNamesNew = new String[customUsers.length + userNames.length];
|
}
|
System.arraycopy(customUsers, 0, userNamesNew, 0, customUsers.length);
|
System.arraycopy(userNames, 0, userNamesNew, customUsers.length, userNames.length);
|
userNames = userNamesNew;
|
|
for (int i = 0; i < userNames.length; i++) {
|
String userName = userNames[i];
|
if (userName.trim().length() > 0) {
|
|
List<Participation> taskParticipations = taskService.getTaskParticipations(nextTaskId);
|
// 先删除原来的任务候选人
|
if (i == 0) {
|
// 放回任务
|
taskService.assignTask(nextTaskId, null);
|
for (Participation participation : taskParticipations) {
|
taskService.removeTaskParticipatingUser(nextTaskId, participation.getUserId(),
|
Participation.CANDIDATE);
|
}
|
}
|
taskService.addTaskParticipatingUser(nextTaskId, userName, Participation.CANDIDATE);
|
}
|
}
|
}
|
} catch (Exception e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("completeTask-2", e);
|
} finally {
|
}
|
}
|
|
/**
|
* 获取分支下任务节点名称
|
*
|
* @param jbpmDeploymentId
|
* @return
|
*/
|
public String[] getForkTaskNames(String jbpmDeploymentId) {
|
byte[] processXml;
|
try {
|
processXml = getProcessResource(jbpmDeploymentId, ".xml");
|
InputStream in = new ByteArrayInputStream(processXml);
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
|
|
SAXReader saxr = new SAXReader();
|
Document doc = saxr.read(reader);
|
Element root = doc.getRootElement();
|
List<String> taskNames = new ArrayList<String>();
|
// String nextTaskName = getNextTaskName(jbpmDeploymentId, root,
|
// curtentTaskName, outcome);
|
// String tokenNodeType = tokenNodeType(jbpmDeploymentId,
|
// nextTaskName, root);
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
String cellType = element.getName();
|
// if(cellType.equals(tokenNodeType)){
|
if (FlowConstants.XMLFORK.equals(cellType)) {
|
for (Iterator<?> elementIterator = element.elementIterator("transition"); elementIterator
|
.hasNext();) {
|
Element transitionEl = (Element) elementIterator.next();
|
Attribute transitionAtt = transitionEl.attribute("to");
|
String transitionVal = transitionAtt.getValue();
|
String taskName = getNameByTrainsition(transitionVal, root);
|
taskNames.add(taskName);
|
}
|
|
}
|
// }
|
}
|
return (String[]) taskNames.toArray(new String[taskNames.size()]);
|
} catch (Exception e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("getForkTaskNames-1", e);
|
}
|
return new String[0];
|
}
|
|
private String tokenNodeType(String jbpmDeploymentId, String tokenNode, Element root) {
|
if (root == null) {
|
byte[] processXml;
|
try {
|
processXml = getProcessResource(jbpmDeploymentId, ".xml");
|
InputStream in = new ByteArrayInputStream(processXml);
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
|
|
SAXReader saxr = new SAXReader();
|
Document doc = saxr.read(reader);
|
root = doc.getRootElement();
|
} catch (Exception e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("tokenNodeType-1", e);
|
}
|
}
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
String cellType = element.getName();
|
String cellName = element.attributeValue(FlowConstants.XMLNAME) == null ? ""
|
: element.attributeValue(FlowConstants.XMLNAME);
|
if (cellName.equals(tokenNode)) {// 任务节点
|
return cellType;
|
}
|
}
|
return "";
|
}
|
|
/**
|
* 获取流程中的数据ID
|
*
|
* @param executionid
|
* @return
|
*/
|
public String[] getDataId(String executionid) {
|
FlowInstanceDaoImpl impl = new FlowInstanceDaoImpl();
|
String hql = "from FlowInstance t where t.executionid = ?";
|
FlowInstance flowInstance = impl.findEntity(hql, new Object[] { executionid });
|
// String tableName = flowInstance.getTableName();
|
|
List<String> list = new ArrayList<String>();
|
List<PLFlowObject> flowObjects = new ProcessTemplateService().getFlowObjectByExecutionId(executionid);
|
for (PLFlowObject flowObject : flowObjects) {
|
list.add(flowObject.getPlobjectid());
|
}
|
return list.toArray(new String[0]);
|
}
|
|
/**
|
* 撤销功能
|
*
|
* @param taskName
|
* @param destActivityName
|
* @param executionId
|
* @return
|
*/
|
public boolean revokeTask(String taskName, String destActivityName, String executionId) {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
TaskService taskService = processEngine.getTaskService();
|
String taskId = getTaskId(taskName, executionId);
|
Map map = new HashMap();
|
map.put("revoke", "revoke");
|
String outcome = "to" + destActivityName;
|
boolean flag = completeTaskByCreateTransitonForRevoke(processEngine, destActivityName, outcome, map,
|
executionId);
|
// removeTransition(processEngine,executionId,outcome,destActivityName);
|
if (flag) {
|
taskService.completeTask(taskId, outcome, map);
|
}
|
return flag;
|
}
|
|
/**
|
* 获取任务ID
|
*
|
* @param currActivityName
|
* @param executionId
|
* @return
|
*/
|
public String getTaskId(String currActivityName, String executionId) {
|
String[] executionIds = executionId.replace(".", ",").split(",");
|
if (executionIds.length >= 3) {
|
executionId = executionIds[0] + "." + executionIds[1];
|
}
|
String deploymentIdSql = "select taskimpl0_.DBID_ from JBPM4_TASK taskimpl0_ cross join JBPM4_EXECUTION executioni1_ where taskimpl0_.EXECUTION_ = executioni1_.DBID_"
|
+ " and executioni1_.ACTIVITYNAME_ = '" + currActivityName + "' and taskimpl0_.EXECUTION_ID_ like '"
|
+ executionId + "%' ";
|
String taskId = "";
|
|
try {
|
SQLQuery sqlQuery = HibernateSessionFactory.getSession().createSQLQuery(deploymentIdSql);
|
int length = sqlQuery.list().size();
|
if (length > 0) {
|
taskId = sqlQuery.list().get(0).toString();
|
}
|
} catch (Exception e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("getTaskId", e);
|
}
|
return taskId;
|
}
|
|
/**
|
* 移除路由
|
*
|
* @param processEngine
|
* @param executionId
|
* @param sourceName
|
* @param destName
|
*/
|
public void removeTransition(ProcessEngine processEngine, String executionId, String sourceName, String destName) {
|
ExecutionService executionService = processEngine.getExecutionService();
|
// 这里不会影响事物
|
// EnvironmentImpl envImpl = ((EnvironmentFactory) processEngine).openEnvironment();
|
|
ExecutionImpl e = (ExecutionImpl) executionService.findExecutionById(executionId);
|
ActivityImpl currentActivityImpl = e.getActivity();
|
|
ProcessDefinitionImpl processDefinitionImpl = currentActivityImpl.getProcessDefinition();
|
|
ActivityImpl sourceActivity = processDefinitionImpl.findActivity(sourceName);
|
List<? extends Transition> outgoingTransitions = sourceActivity.getOutgoingTransitions();
|
for (Transition ts : outgoingTransitions) {
|
if (destName.equals(ts.getDestination().getName())) {
|
outgoingTransitions.remove(ts);
|
break;
|
}
|
}
|
}
|
|
/**
|
* 动态创建流向
|
*
|
* @param taskService
|
* @param task
|
* @param destActivityName
|
* @param createTransitionName
|
* @param map
|
*/
|
public boolean completeTaskByCreateTransitonForRevoke(ProcessEngine processEngine, String destActivityName,
|
String createTransitionName, Map map, String executionId) {
|
|
ExecutionService executionService = processEngine.getExecutionService();
|
// 这里不会影响事物
|
EnvironmentImpl envImpl = ((EnvironmentFactory) processEngine).openEnvironment();
|
try {
|
|
// 动态回退
|
ExecutionImpl e = (ExecutionImpl) executionService.findExecutionById(executionId);
|
ActivityImpl currentActivityImpl = e.getActivity();
|
|
ProcessDefinitionImpl processDefinitionImpl = currentActivityImpl.getProcessDefinition();
|
|
// 生成一个transition
|
ActivityImpl destActivityImpl = processDefinitionImpl.findActivity(destActivityName);
|
TransitionImpl toApply = currentActivityImpl.createOutgoingTransition();
|
toApply.setSource(currentActivityImpl);
|
toApply.setDestination(destActivityImpl);
|
toApply.setName(createTransitionName);
|
EventImpl createEvent = toApply.createEvent();
|
createEvent.setObservableElement(toApply);
|
String deploymentId = this.getDeploymentIdByExecutionId(executionId);
|
List<TaskRevokeSObject> taskRevokeList = this.getTaskRevokeList(destActivityName, deploymentId);
|
for (int i = 0; i < taskRevokeList.size(); i++) {
|
TaskRevokeSObject taskRevokeSObject = taskRevokeList.get(i);
|
String plclassname = taskRevokeSObject.getPlclassname();
|
Class<?> cls;
|
cls = Class.forName(plclassname);
|
EventListener testTrasionEvent = (EventListener) cls.getConstructor(null).newInstance(null);
|
createEvent.createEventListenerReference(testTrasionEvent);
|
}
|
|
} catch (Exception e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("completeTaskByCreateTransitonForRevoke", e);
|
return false;
|
} finally {
|
envImpl.close();
|
}
|
return true;
|
}
|
|
/**
|
* 获取策略列表
|
*
|
* @param taskName
|
* @param deploymentId
|
* @return
|
*/
|
public List<TaskRevokeSObject> getTaskRevokeList(final String taskName, final String deploymentId) {
|
return (List<TaskRevokeSObject>) new HibernateTemplate().run(new HibernateCallback() {
|
|
public Object execute() throws HibernateException {
|
TaskRevokeDaoImpl taskDescDaoImpl = new TaskRevokeDaoImpl();
|
String hsql = " from TaskRevokeSObject t where t.pltask = '" + taskName
|
+ "' and t.pljbpmdeploymentid = '" + deploymentId + "'";
|
return taskDescDaoImpl.findEntities(hsql);
|
}
|
});
|
}
|
|
public void completeTaskByCreateTransiton(TaskService taskService, Task task, String destActivityName,
|
String createTransitionName, Map map) {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
ExecutionService executionService = processEngine.getExecutionService();
|
// 这里不会影响事物
|
EnvironmentImpl envImpl = ((EnvironmentFactory) processEngine).openEnvironment();
|
try {
|
|
// 动态回退
|
ExecutionImpl e = (ExecutionImpl) executionService.findExecutionById(task.getExecutionId());
|
ActivityImpl currentActivityImpl = e.getActivity();
|
|
ProcessDefinitionImpl processDefinitionImpl = currentActivityImpl.getProcessDefinition();
|
|
// 生成一个transition
|
ActivityImpl destActivityImpl = processDefinitionImpl.findActivity(destActivityName);
|
TransitionImpl toApply = currentActivityImpl.createOutgoingTransition();
|
toApply.setSource(currentActivityImpl);
|
toApply.setDestination(destActivityImpl);
|
toApply.setName(createTransitionName);
|
EventImpl createEvent = toApply.createEvent();
|
createEvent.setObservableElement(toApply);
|
String[] classNames = fetchEventForTrainstion(task.getExecutionId(), task.getName(), destActivityName);
|
for (int i = 0; i < classNames.length; i++) {
|
String plclassname = classNames[i];
|
Class<?> cls;
|
cls = Class.forName(plclassname);
|
// 加入事件
|
EventListener testTrasionEvent = (EventListener) cls.getConstructor(null).newInstance(null);
|
createEvent.createEventListenerReference(testTrasionEvent);
|
}
|
} catch (Exception e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("completeTaskByCreateTransiton", e);
|
} finally {
|
envImpl.close();
|
}
|
}
|
|
private String[] fetchEventForTrainstion(String executionId, String taskname, String nexttaskName) {
|
List<String> classNameList = new ArrayList<String>();
|
String jbpmDeploymentId = getDeploymentIdByExecutionId(executionId);
|
byte[] processXml;
|
try {
|
processXml = getProcessResource(jbpmDeploymentId, ".xml");
|
InputStream in = new ByteArrayInputStream(processXml);
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
|
|
SAXReader saxr = new SAXReader();
|
Document doc = saxr.read(reader);
|
Element root = doc.getRootElement();
|
// List<Element> transitions = new ArrayList<Element>();
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
String cellType = element.getName();
|
String cellName = element.attributeValue(FlowConstants.XMLNAME);
|
if (FlowConstants.XMLTASK.equals(cellType) && cellName.equals(taskname)) {// 任务节点
|
for (Iterator<?> b = element.elementIterator(); b.hasNext();) {
|
Element next = (Element) b.next();
|
if (next.getName().equals(FlowConstants.TRANSITION)) {
|
String trainstionName = next.attribute(FlowConstants.XMLTARGET).getValue();
|
if (trainstionName.equals(nexttaskName)) {
|
for (Iterator<?> c = next.elementIterator(); c.hasNext();) {
|
Element eventListener = (Element) c.next();
|
String className = eventListener.attribute(FlowConstants.ELEMENT_CLASS).getValue();
|
classNameList.add(className);
|
}
|
}
|
}
|
}
|
}
|
}
|
} catch (Exception e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("fetchEventForTrainstion", e);
|
}
|
return classNameList.toArray(new String[] {});
|
}
|
|
public boolean setProcessHide(String jbpmdeplotmentId, int status) {
|
int id = Integer.parseInt(jbpmdeplotmentId);
|
String sql = "";
|
if (status == 0) {// 停用
|
sql = "update PLPROCESSTEMPLATE set plstatus = 0 where PLJBPMDEPLOYMENTID = " + id;
|
} else
|
// 启用
|
sql = "update PLPROCESSTEMPLATE set plstatus = 1 where PLJBPMDEPLOYMENTID = " + id;
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
session.createSQLQuery(sql.toString()).executeUpdate();
|
} catch (Exception e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("setProcessHide", e);
|
return false;
|
}
|
return true;
|
}
|
|
/**
|
* 任务指派
|
*
|
* @param currActivityName
|
* @param tagActivityName
|
* @param classNames
|
* @param executionId
|
* @param userNames
|
* @return
|
*/
|
public boolean appointTask(String currActivityName, String tagActivityName, String[] classNames, String executionId,
|
String[] userNames) {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
TaskService taskService = processEngine.getTaskService();
|
Map map = new HashMap();
|
String outcome = "to" + tagActivityName;
|
String taskId = getTaskId(currActivityName, executionId);
|
boolean flag = createTransition(processEngine, tagActivityName, outcome, map, classNames, executionId);
|
if (flag) {
|
taskService.completeTask(taskId, outcome, map);
|
}
|
|
// 取出下一步任务
|
Task nextTask = taskService.createTaskQuery().processInstanceId(executionId).uniqueResult();
|
// 取出下一步任务ID
|
String nextTaskId = nextTask.getId();
|
|
// 自定义用户类的用户和指派的用户合并
|
String[] customUsers = new String[0];
|
String[] userNamesNew = new String[0];
|
Object variable = taskService.getVariable(nextTaskId, "CustomUserNames");
|
if (variable instanceof String[]) {
|
String[] v = (String[]) variable;
|
if (v != null) {
|
customUsers = v;
|
}
|
}
|
if (customUsers != null) {
|
userNamesNew = new String[customUsers.length];
|
}
|
if (userNames != null) {
|
userNamesNew = new String[customUsers.length + userNames.length];
|
}
|
System.arraycopy(customUsers, 0, userNamesNew, 0, customUsers.length);
|
System.arraycopy(userNames, 0, userNamesNew, customUsers.length, userNames.length);
|
userNames = userNamesNew;
|
|
// 重新指派候选人
|
for (int k = 0; k < userNames.length; k++) {
|
String userName = userNames[k];
|
if (userName.trim().length() > 0) {
|
List<Participation> taskParticipations = taskService.getTaskParticipations(nextTaskId);
|
// 先删除原来的任务候选人
|
if (k == 0) {
|
// 放回任务
|
taskService.assignTask(nextTaskId, null);
|
|
for (Participation participation : taskParticipations) {
|
taskService.removeTaskParticipatingUser(nextTaskId, participation.getUserId(),
|
Participation.CANDIDATE);
|
}
|
}
|
|
taskService.addTaskParticipatingUser(nextTaskId, userName, Participation.CANDIDATE);
|
}
|
}
|
return flag;
|
}
|
|
/**
|
* 任务指派
|
*
|
* @param currActivityName
|
* @param tagActivityName
|
* @param classNames
|
* @param executionId
|
* @param userNames
|
* @return
|
*/
|
public boolean appointTask2(String currActivityName, String tagActivityName, String[] classNames,
|
String executionId, String[] userNames, UserEntityInfo userEntity) {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
TaskService taskService = processEngine.getTaskService();
|
// ClientLinkObjectOperation loperation = new ClientLinkObjectOperation();
|
Map map = new HashMap();
|
String outcome = "to" + tagActivityName;
|
String taskId = getTaskId(currActivityName, executionId);
|
// update
|
String[] objectOids = new String[0];
|
boolean flag = false;
|
try {
|
|
objectOids = updateWorkItem2(taskId, executionId, userEntity);
|
|
List<Task> histlistTask = taskService.createTaskQuery().processInstanceId(executionId).list();
|
|
flag = createTransition(processEngine, tagActivityName, outcome, map, classNames, executionId);
|
String hisTaskId = taskId;
|
if (flag) {
|
taskService.completeTask(taskId, outcome, map);
|
}
|
|
// List<Task> newlistTask = taskService.createTaskQuery().processInstanceId(executionId).list();
|
|
// 取出下一步任务
|
Task nextTask = taskService.createTaskQuery().processInstanceId(executionId).uniqueResult();
|
if (userNames.length == 0) {
|
userNames = new String[1];
|
}
|
userNames[0] = nextTask.getAssignee();
|
// 取出下一步任务ID
|
String nextTaskId = nextTask.getId();
|
// create
|
// 获取页面元素值btmType btmDesc processName
|
String sql = "select t.pltablename,t.pldesc,t.processname from PLFLOWINSTANCE t where t.plexecutionid ='"
|
+ executionId + "'";
|
SQLQuery createSQLQuery = HibernateSessionFactory.getSession().createSQLQuery(sql);
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List<?> list = createSQLQuery.list();
|
String btmType = "";
|
String btmDesc = "";
|
String processName = "";
|
for (int i = 0; i < list.size(); i++) {
|
Object[] object = (Object[]) list.get(i);
|
btmType = String.valueOf(object[0]);
|
btmDesc = (String) object[1] == null ? "" : (String) object[1];
|
processName = (String) object[2];
|
}
|
String objectProperty[] = new String[] { "Oid", "RevisionOid", "NameOid", "BTMName" };
|
String[][] objectPropertyValues = null;
|
Map<String, String> pMap = new HashMap<String, String>();
|
pMap.put("executionid", executionId);
|
pMap.put("TASKOID", hisTaskId);
|
|
BusinessObject[] findBTMObjects1;
|
|
findBTMObjects1 = getBusinessObjectByQueryTemplate("workitem", pMap);
|
for (BusinessObject businessObject2 : findBTMObjects1) {
|
// ClientBusinessObject clientBusinessObject2 = new ClientBusinessObject();
|
// clientBusinessObject2.setBusinessObject(businessObject2);
|
// ClientLinkObject[] readLinkObjectByFromBO =
|
// loperation.readLinkObjectByFromBO(clientBusinessObject2, "input");
|
LinkObject[] los = ServerServiceProvider.getBOFService().readLinkObjectByFromBO(businessObject2,
|
"input");// , true);
|
objectPropertyValues = new String[los.length][4];
|
for (int i = 0; i < los.length; i++) {
|
LinkObject lo = los[i];
|
objectPropertyValues[i] = new String[] { lo.toOid, lo.toRevOid, lo.toNameOid, lo.toBTName };
|
// 创建新的workflow
|
if (userNames.length == 0) {
|
WorkFlowService.getInstance().saveForComplete_v1(userNames, objectOids, nextTask, btmType,
|
btmDesc, processName, nextTaskId, 0, objectProperty, objectPropertyValues);
|
} else {
|
for (int m = 0; m < userNames.length; m++) {
|
WorkFlowService.getInstance().saveForComplete_v1(userNames, objectOids, nextTask, btmType,
|
btmDesc, processName, nextTaskId, m, objectProperty, objectPropertyValues);
|
}
|
}
|
}
|
}
|
// 自定义用户类的用户和指派的用户合并
|
String[] customUsers = new String[0];
|
String[] userNamesNew = new String[0];
|
Object variable = taskService.getVariable(nextTaskId, "CustomUserNames");
|
if (variable instanceof String[]) {
|
String[] v = (String[]) variable;
|
if (v != null) {
|
customUsers = v;
|
}
|
}
|
if (customUsers != null) {
|
userNamesNew = new String[customUsers.length];
|
}
|
if (userNames != null) {
|
userNamesNew = new String[customUsers.length + userNames.length];
|
}
|
System.arraycopy(customUsers, 0, userNamesNew, 0, customUsers.length);
|
System.arraycopy(userNames, 0, userNamesNew, customUsers.length, userNames.length);
|
userNames = userNamesNew;
|
|
// 重新指派候选人
|
for (int k = 0; k < userNames.length; k++) {
|
String userName = userNames[k];
|
if (userName.trim().length() > 0) {
|
List<Participation> taskParticipations = taskService.getTaskParticipations(nextTaskId);
|
// 先删除原来的任务候选人
|
if (k == 0) {
|
// 放回任务
|
taskService.assignTask(nextTaskId, null);
|
|
for (Participation participation : taskParticipations) {
|
taskService.removeTaskParticipatingUser(nextTaskId, participation.getUserId(),
|
Participation.CANDIDATE);
|
}
|
}
|
|
taskService.addTaskParticipatingUser(nextTaskId, userName, Participation.CANDIDATE);
|
}
|
}
|
} catch (VCIError e) {
|
// TODO Auto-generated catch block
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("appointTask2-1", e);
|
} catch (InstantiationException e) {
|
// TODO Auto-generated catch block
|
ServerWithLog4j.logger.error("appointTask2-2", e);
|
// e.printStackTrace();
|
} catch (IllegalAccessException e) {
|
// TODO Auto-generated catch block
|
ServerWithLog4j.logger.error("appointTask2-3", e);
|
// e.printStackTrace();
|
} catch (ClassNotFoundException e) {
|
// TODO Auto-generated catch block
|
ServerWithLog4j.logger.error("appointTask2-4", e);
|
// e.printStackTrace();
|
} catch (SecurityException e) {
|
// TODO Auto-generated catch block
|
ServerWithLog4j.logger.error("appointTask2-5", e);
|
// e.printStackTrace();
|
} catch (IllegalArgumentException e) {
|
// TODO Auto-generated catch block
|
ServerWithLog4j.logger.error("appointTask2-6", e);
|
// e.printStackTrace();
|
} catch (Throwable e) {
|
ServerWithLog4j.logger.error("appointTask2-7", e);
|
// e.printStackTrace();
|
String[] error = new String[1];
|
error[0] = e.getMessage();
|
}
|
// workitem
|
// update workitem
|
// create
|
return flag;
|
}
|
|
private String[] updateWorkItem2(String taskId, String executId, UserEntityInfo userEntity)
|
throws VCIError, ClassNotFoundException, InstantiationException, IllegalAccessException {
|
String[] objectOids = null;
|
if (workitemClass != null && !"".equals(workitemClass)) {
|
// PLMWorkItemInterface pwService = (PLMWorkItemInterface)
|
// (Class.forName(workitemClass).newInstance());
|
if (_pwiService != null) {
|
objectOids = _pwiService.updataWorkItem(taskId, executId, userEntity.userName, owner, linkDataMap);
|
owner = _pwiService.getUser(getUserEntity().getUserName(), executId);
|
ServerWithLog4j.logger.debug(owner);
|
}
|
|
}
|
return objectOids;
|
}
|
|
/**
|
* 查询方法
|
*
|
* @param btmType
|
* @param map
|
* @return
|
* @throws VCIError
|
*/
|
private BusinessObject[] getBusinessObjectByQueryTemplate(String btmType, Map<String, String> map) throws VCIError {
|
QueryTemplate qt = new QueryTemplate();
|
qt.setId("queryBtm");
|
qt.setType(QTConstants.TYPE_BTM);
|
qt.setBtmType(btmType);
|
List<String> clauseList = new ArrayList<String>();
|
clauseList.add("*");
|
qt.setClauseList(clauseList);
|
|
Condition condition = OQueryHelper.getCondition(map);
|
qt.setCondition(condition);
|
// BusinessObject[] findBTMObjects = QTClient.getService().findBTMObjects(qt.getId(), Tool.getQTTextByQT(qt));
|
|
// BusinessObject[] findBTMObjects =
|
// UIFUtilsForServer.getInstance().getBusinessObject(qt, map);
|
BusinessObject[] findBTMObjects = ServerServiceProvider.getOQService().findBTMObjects(qt.getId(),
|
OQueryHelper.getQTTextByQT(qt));
|
return findBTMObjects;
|
}
|
|
/**
|
* 获取关联bo
|
*
|
* @param btmName
|
* @param queryCondition
|
* @return
|
* @throws VCIError
|
* @author changmk
|
*/
|
// private BusinessObject[] getRefBos(String btmName, Map<String, String> queryCondition) throws VCIError {
|
// QueryTemplate qt = new QueryTemplate();
|
// qt = UIFUtilsForServer.getInstance().getBtmQueryTemplate(btmName);
|
// BusinessObject[] bos = UIFUtilsForServer.getInstance().getBusinessObject(qt, queryCondition);
|
// return bos;
|
// }
|
|
/**
|
* 得到链接类型查询模板
|
*
|
* @param linkTypeName
|
* @return
|
* @author changmk
|
*/
|
private QueryTemplate getLinkQueryTemplate(String linkTypeName) {
|
QueryTemplate qt = new QueryTemplate();
|
qt.setId("qt");
|
qt.setType("link");
|
qt.setLinkType(linkTypeName);
|
qt.setBtmType("*");
|
qt.setClauseList(Arrays.asList(new String[] { "*" }));
|
// 忽略对象的数据权限检查
|
qt.setRightFlag(false);
|
qt.setQueryChildrenFlag(true);
|
return qt;
|
}
|
|
/**
|
* 获取链接类型
|
*
|
* @param qt
|
* @param conditionMap
|
* @return
|
* @throws VCIError
|
* @author changmk
|
*/
|
// private LinkObject[] getLinkObject(QueryTemplate qt, Map<String, String> conditionMap) throws VCIError {
|
// qt.setCondition(Tool.getCondition(conditionMap));
|
// return getQTService().findLTObjects(qt.getId(), Tool.qtTOXMl(qt).asXML());
|
// }
|
//
|
// private QTServiceOperations getQTService() throws VCIError {
|
// return (QTServiceOperations) new QTServiceImpl();
|
// }
|
|
/**
|
* 创建路由
|
*
|
* @param taskService
|
* @param task
|
* @param tagActivityName
|
* @param createTransitionName
|
* @param map
|
*/
|
// public boolean createTransition(ProcessEngine processEngine,
|
// String tagActivityName, String createTransitionName, Map map,
|
// String[] classNames, String excutionID) {
|
//
|
// ExecutionService executionService = processEngine.getExecutionService();
|
// // 这里不会影响事物
|
// EnvironmentImpl envImpl = ((EnvironmentFactory) processEngine)
|
// .openEnvironment();
|
// try {
|
//
|
// ExecutionImpl e = (ExecutionImpl) executionService
|
// .findExecutionById(excutionID);
|
// ActivityImpl currentActivityImpl = e.getActivity();
|
//
|
// ProcessDefinitionImpl processDefinitionImpl = currentActivityImpl
|
// .getProcessDefinition();
|
//
|
// // 生成一个transition
|
// ActivityImpl tagActivityImpl = processDefinitionImpl
|
// .findActivity(tagActivityName);
|
// TransitionImpl toApply = currentActivityImpl
|
// .createOutgoingTransition();
|
// toApply.setSource(currentActivityImpl);
|
// toApply.setDestination(tagActivityImpl);
|
// toApply.setName(createTransitionName);
|
// EventImpl createEvent = toApply.createEvent();
|
// createEvent.setObservableElement(toApply);
|
// for (int i = 0; i < classNames.length; i++) {
|
// String plclassname = classNames[i];
|
// Class<?> cls;
|
// cls = Class.forName(plclassname);
|
// // 加入事件
|
// EventListener testTrasionEvent = (EventListener) cls
|
// .getConstructor(null).newInstance(null);
|
// createEvent.createEventListenerReference(testTrasionEvent);
|
// }
|
//
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// return false;
|
// } finally {
|
// envImpl.close();
|
// }
|
// return true;
|
// }
|
private synchronized boolean createTransition(final ProcessEngine processEngine, final String tagActivityName,
|
final String createTransitionName, final Map map, final String[] classNames, final String excutionID) {
|
@SuppressWarnings("serial")
|
Boolean res = processEngine.execute(new Command<Boolean>() {
|
public Boolean execute(Environment environment) throws Exception {
|
try {
|
ExecutionService executionService = processEngine.getExecutionService();
|
ExecutionImpl e = (ExecutionImpl) executionService.findExecutionById(excutionID);
|
ProcessDefinitionImpl processDefinitionImpl = e.getProcessDefinition();
|
ActivityImpl currentActivityImpl = processDefinitionImpl.getActivity(e.getActivityName());
|
// 生成一个transition
|
ActivityImpl tagActivityImpl = processDefinitionImpl.findActivity(tagActivityName);
|
TransitionImpl toApply = currentActivityImpl.createOutgoingTransition();
|
toApply.setSource(currentActivityImpl);
|
toApply.setDestination(tagActivityImpl);
|
toApply.setName(createTransitionName);
|
EventImpl createEvent = toApply.createEvent();
|
createEvent.setObservableElement(toApply);
|
for (int i = 0; i < classNames.length; i++) {
|
String plclassname = classNames[i];
|
Class<?> cls;
|
cls = Class.forName(plclassname);
|
// 加入事件
|
EventListener testTrasionEvent = (EventListener) cls.getConstructor(null).newInstance(null);
|
createEvent.createEventListenerReference(testTrasionEvent);
|
}
|
} catch (Exception e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("createTransition", e);
|
return false;
|
}
|
return true;
|
}
|
|
});
|
return res;
|
}
|
|
public ProcessTaskInfo findTaskPropertyById(final String jbpmDeploymentId, final String name) {
|
try {
|
ProcessTaskInfo object = (ProcessTaskInfo) new HibernateTemplate().run(new HibernateCallback() {
|
public Object execute() throws HibernateException {
|
ProcessTaskDaoImpl impl = new ProcessTaskDaoImpl();
|
String hql = "from ProcessTask t where t.deploymentId = ? and t.taskName = ?";
|
ProcessTask processTask = impl.findEntity(hql, new Object[] { jbpmDeploymentId, name });
|
if (processTask != null) {
|
ProcessTaskPropertyDaoImpl propertyImpl = new ProcessTaskPropertyDaoImpl();
|
String phql = "from ProcessTaskProperty t where t.taskPropertyId = ?";
|
List<ProcessTaskProperty> typeProperties = propertyImpl.findEntites(phql,
|
new Object[] { processTask.getTaskTypePropertyId() });
|
|
return convertToInfo(processTask, typeProperties);
|
} else {
|
ProcessTaskInfo processTaskInfo = new ProcessTaskInfo();
|
processTaskInfo.taskTypeProperties = new PropertyInfo[0];
|
return processTaskInfo;
|
}
|
}
|
|
private ProcessTaskInfo convertToInfo(ProcessTask processTask,
|
List<ProcessTaskProperty> typeProperties) {
|
ProcessTaskInfo info = new ProcessTaskInfo();
|
info.id = processTask.getId() == null ? "" : processTask.getId();
|
info.deploymentId = processTask.getDeploymentId() == null ? "" : processTask.getDeploymentId();
|
info.taskName = processTask.getTaskName() == null ? "" : processTask.getTaskName();
|
info.taskType = processTask.getTaskType() == null ? "" : processTask.getTaskType();
|
info.taskTypeProperties = getPropertyInfos(typeProperties);
|
// info.taskCCInfos = new TaskCCInfo[0];
|
info.customUserInfos = new CustomInfo[0];
|
info.revokeInfos = new PropertyInfo[0];
|
return info;
|
}
|
|
private PropertyInfo[] getPropertyInfos(List<ProcessTaskProperty> typeProperties) {
|
if (typeProperties != null && typeProperties.size() > 0) {
|
PropertyInfo[] result = new PropertyInfo[typeProperties.size()];
|
for (int i = 0; i < typeProperties.size(); i++) {
|
ProcessTaskProperty property = typeProperties.get(i);
|
result[i] = new PropertyInfo();
|
result[i].property = property.getProperty();
|
result[i].value = property.getValue();
|
}
|
return result;
|
} else {
|
return new PropertyInfo[0];
|
}
|
}
|
});
|
return object;
|
} catch (Throwable e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("findTaskPropertyById", e);
|
}
|
return null;
|
}
|
|
/**
|
* 通过执行ID获得发起人
|
*
|
* @param conn
|
* @param executionId
|
* @return
|
*/
|
public List<FlowApproveHistory> getHistoryActivityByExcetionID(Session session, final String executionId) {
|
List<FlowApproveHistory> flowApproveHistories = new ArrayList<FlowApproveHistory>();
|
StringBuilder sql = new StringBuilder();
|
|
sql.append(
|
"select ha.ACTIVITY_NAME_, DECODE(op.plassgin, null,ht.ASSIGNEE_, op.plassgin ) assgin, op.PLAPPROVEOPINION, op.PLAPPROVENOTE, ht.CREATE_, ht.END_, ht.DBID_");
|
sql.append(
|
" FROM JBPM4_HIST_TASK ht left join JBPM4_HIST_ACTINST ha on ht.DBID_=ha.HTASK_ left join PLFLOWAPPROVEOPINION op on ht.DBID_=op.PLTASKID");
|
sql.append(" where ht.EXECUTION_ = ? order by ht.create_");
|
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
createSQLQuery.setString(0, executionId);
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List<?> list = createSQLQuery.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] object = (Object[]) list.get(i);
|
FlowApproveHistory flowApproveHistory = new FlowApproveHistory();
|
String taskName = String.valueOf(object[0]);
|
String assignee = (String) object[1];
|
String opinion = (String) object[2];
|
String note = (String) object[3];
|
Timestamp createTime = (Timestamp) object[4];
|
Timestamp endTime = (Timestamp) object[5];
|
BigDecimal taskId = (BigDecimal) object[6];
|
|
if (assignee == null || "".equals(assignee)) {
|
|
StringBuilder userSql = new StringBuilder();
|
userSql.append(
|
"select p.USERID_ from JBPM4_PARTICIPATION p where p.TYPE_='candidate' and p.TASK_=?");
|
|
SQLQuery createSQLQuery1 = session.createSQLQuery(userSql.toString());
|
createSQLQuery1.setBigDecimal(0, taskId);
|
//无意义代码
|
// createSQLQuery1.executeUpdate();
|
|
StringBuilder user = new StringBuilder();
|
List<?> list2 = createSQLQuery1.list();
|
for (int j = 0; j < list2.size(); j++) {
|
String assign = String.valueOf(list2.get(j));
|
if (user.length() > 0) {
|
user.append(", ");
|
}
|
user.append(assign);
|
}
|
assignee = user.toString();
|
}
|
|
flowApproveHistory.setTaskName(taskName);
|
flowApproveHistory.setAssignee(assignee);
|
flowApproveHistory.setOpinion(opinion);
|
flowApproveHistory.setNote(note);
|
flowApproveHistory.setCreateTime(createTime);
|
flowApproveHistory.setEndTime(endTime);
|
|
flowApproveHistories.add(flowApproveHistory);
|
}
|
} catch (Exception ex) {
|
// ex.printStackTrace();
|
ServerWithLog4j.logger.error("getHistoryActivityByExcetionID", ex);
|
} finally {
|
}
|
return flowApproveHistories;
|
}
|
|
public List<FlowApproveHistory> getHistoryActivityByProInsId(final String executionId) {
|
List<FlowApproveHistory> flowApproveHistories = new ArrayList<FlowApproveHistory>();
|
StringBuilder sql = new StringBuilder();
|
String newExecutionId = executionId.replace(".", ",");
|
String[] split = newExecutionId.split(",");
|
String exeId = "";
|
if (split.length > 2) {
|
exeId = split[0] + "." + split[1];
|
} else {
|
exeId = executionId;
|
}
|
sql.append("select ha.ACTIVITY_NAME_, DECODE(op.plassgin, null,ht.ASSIGNEE_, op.plassgin ) assgin,");
|
sql.append(
|
" op.PLAPPROVEOPINION, op.PLAPPROVENOTE, ht.CREATE_, ht.END_, ht.DBID_, ht.EXECUTION_, ht.SUPERTASK_");
|
sql.append(
|
" FROM JBPM4_HIST_TASK ht left join JBPM4_HIST_ACTINST ha on ht.DBID_=ha.HTASK_ left join PLFLOWAPPROVEOPINION op on ht.DBID_=op.PLTASKID");
|
sql.append(" where ht.EXECUTION_ like ? order by ht.create_");
|
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
createSQLQuery.setString(0, exeId + "%");
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List<?> list = createSQLQuery.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] obj = (Object[]) list.get(i);
|
FlowApproveHistory flowApproveHistory = new FlowApproveHistory();
|
String taskName = (String) obj[0];
|
String assignee = (String) obj[1];
|
String opinion = (String) obj[2];
|
String note = (String) obj[3];
|
Timestamp createTime = (Timestamp) obj[4];
|
Timestamp endTime = (Timestamp) obj[5];
|
BigDecimal taskId = (BigDecimal) obj[6];
|
String taskExecId = (String) obj[7];
|
String parentTaskId = "";
|
if (obj[8] != null)
|
parentTaskId = ((BigDecimal) obj[8]).toString();
|
|
StringBuilder userSql = new StringBuilder();
|
userSql.append("select p.USERID_ from JBPM4_PARTICIPATION p where p.TYPE_='candidate' and p.TASK_=?");
|
|
SQLQuery createSQLQuery1 = session.createSQLQuery(userSql.toString());
|
createSQLQuery1.setBigDecimal(0, taskId);
|
//无意义代码
|
// createSQLQuery1.executeUpdate();
|
|
StringBuilder user = new StringBuilder();
|
List<?> list2 = createSQLQuery1.list();
|
if (list2 != null && list2.size() > 0) {
|
for (int j = 0; j < list2.size(); j++) {
|
|
String assign = String.valueOf(list2.get(j));
|
if (user.length() > 0) {
|
user.append(", ");
|
}
|
user.append(assign);
|
}
|
assignee = user.toString();
|
}
|
|
if (assignee != null && !"".equals(assignee)) {
|
flowApproveHistory.setTaskName(taskName);
|
flowApproveHistory.setAssignee(assignee);
|
flowApproveHistory.setOpinion(opinion);
|
flowApproveHistory.setNote(note);
|
flowApproveHistory.setCreateTime(createTime);
|
flowApproveHistory.setEndTime(endTime);
|
flowApproveHistory.setExecutionId(taskExecId);
|
flowApproveHistory.setTaskId(taskId.toString());
|
flowApproveHistory.setParentTaskId(parentTaskId);
|
|
flowApproveHistories.add(flowApproveHistory);
|
}
|
|
}
|
} catch (Exception ex) {
|
// ex.printStackTrace();
|
ServerWithLog4j.logger.error("getHistoryActivityByProInsId", ex);
|
} finally {
|
|
}
|
return flowApproveHistories;
|
}
|
|
public List<FlowApproveHistory> getHistoryActivityByProInsIdbyPLM(final String executionId) {
|
List<FlowApproveHistory> flowApproveHistories = new ArrayList<FlowApproveHistory>();
|
StringBuilder sql = new StringBuilder();
|
String newExecutionId = executionId.replace(".", ",");
|
String[] split = newExecutionId.split(",");
|
String exeId = "";
|
boolean subTaskFlag = true;
|
if (split.length > 2) {
|
exeId = split[0] + "." + split[1];
|
subTaskFlag = false;
|
} else {
|
exeId = executionId;
|
}
|
// ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
// HistoryService historyService = processEngine.getHistoryService();
|
// List histList = historyService.createHistoryTaskQuery().executionId(exeId).list();
|
sql.append("select ha.ACTIVITY_NAME_, DECODE(op.plassgin, null,ht.ASSIGNEE_, op.plassgin ) assgin, ");
|
sql.append(
|
" op.PLAPPROVEOPINION, op.PLAPPROVENOTE, ht.CREATE_, ht.END_, ht.DBID_, ht.EXECUTION_, ht.SUPERTASK_");
|
sql.append(
|
" FROM JBPM4_HIST_TASK ht left join JBPM4_HIST_ACTINST ha on ht.DBID_=ha.HTASK_ left join PLFLOWAPPROVEOPINION op on ht.DBID_=op.PLTASKID");
|
sql.append(
|
" where ht.EXECUTION_ like ? order by to_char(ht.create_,'yyyy-MM-dd HH:mi:ss') asc,to_char(ht.END_,'yyyy-MM-dd HH:mi:ss') asc");
|
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
StringBuilder userSql = new StringBuilder();
|
userSql.append("select p.USERID_ from JBPM4_PARTICIPATION p where p.TYPE_='candidate' and p.TASK_=?");
|
SQLQuery queryAssignee = session.createSQLQuery(userSql.toString());
|
|
SQLQuery queryHTask = session.createSQLQuery(sql.toString());
|
queryHTask.setString(0, exeId + "%");
|
// createSQLQuery.setString(0, exeId );
|
// createSQLQuery.executeUpdate();
|
List<?> list = queryHTask.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] obj = (Object[]) list.get(i);
|
FlowApproveHistory flowApproveHistory = new FlowApproveHistory();
|
String taskName = (String) obj[0];
|
String assignee = (String) obj[1];
|
String opinion = (String) obj[2];
|
String note = (String) obj[3];
|
Timestamp createTime = (Timestamp) obj[4];
|
Timestamp endTime = (Timestamp) obj[5];
|
BigDecimal taskId = (BigDecimal) obj[6];
|
String taskExecId = (String) obj[7];
|
|
String parentTaskId = "";
|
if (obj[8] != null)
|
parentTaskId = ((BigDecimal) obj[8]).toString();
|
|
//无意义代码
|
// createSQLQuery1.executeUpdate();
|
|
if (subTaskFlag) {
|
queryAssignee.setBigDecimal(0, taskId);
|
StringBuilder user = new StringBuilder();
|
List<?> listUser = queryAssignee.list();
|
if (listUser != null && listUser.size() > 0) {
|
for (int j = 0; j < listUser.size(); j++) {
|
|
String assign = String.valueOf(listUser.get(j));
|
if (user.length() > 0) {
|
user.append(", ");
|
}
|
user.append(assign);
|
}
|
assignee = user.toString();
|
}
|
}
|
|
if (assignee != null && !"".equals(assignee)) {
|
if ((endTime != null && opinion != null) || (endTime == null && opinion == null)) {
|
flowApproveHistory.setTaskName(taskName);
|
flowApproveHistory.setAssignee(assignee);
|
flowApproveHistory.setOpinion(opinion);
|
flowApproveHistory.setNote(note);
|
flowApproveHistory.setCreateTime(createTime);
|
flowApproveHistory.setEndTime(endTime);
|
flowApproveHistory.setExecutionId(taskExecId);
|
flowApproveHistory.setTaskId(taskId.toString());
|
flowApproveHistory.setParentTaskId(parentTaskId);
|
flowApproveHistories.add(flowApproveHistory);
|
}
|
}
|
|
}
|
} catch (Exception ex) {
|
// ex.printStackTrace();
|
ServerWithLog4j.logger.error("getHistoryActivityByProInsIdbyPLM", ex);
|
} finally {
|
|
}
|
return flowApproveHistories;
|
}
|
|
/**
|
* 通过执行ID跟踪流程
|
*
|
* @param executionId
|
* @return
|
* @throws IOException
|
*/
|
public byte[] getExecutionImage(String executionId) throws IOException {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
ExecutionService executionService = processEngine.getExecutionService();
|
RepositoryService repositoryService = processEngine.getRepositoryService();
|
String[] executionIdS = executionId.replace(".", ",").split(",");
|
if (executionIdS.length >= 3) {
|
executionId = executionIdS[0] + "." + executionIdS[1];
|
}
|
ProcessInstance uniqueResult = executionService.createProcessInstanceQuery().processInstanceId(executionId)
|
.uniqueResult();
|
String processDefinitionId = uniqueResult.getProcessInstance().getProcessDefinitionId();
|
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
|
.processDefinitionId(processDefinitionId).uniqueResult();
|
|
// ServerWithLog4j.logger.debug("processInstance
|
// ============================================="+uniqueResult+"!");
|
InputStream io = null;
|
BufferedImage bi = null;
|
io = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(),
|
processDefinition.getImageResourceName());
|
|
bi = ImageIO.read(io);
|
|
Set<String> findActiveActivityNames = uniqueResult.findActiveActivityNames();
|
ActivityCoordinates activityCoordinates = repositoryService.getActivityCoordinates(processDefinitionId,
|
findActiveActivityNames.iterator().next());
|
// 获取图形上下文
|
Graphics2D g = (Graphics2D) bi.getGraphics();
|
g.setStroke(new BasicStroke(2));
|
g.setColor(Color.red);
|
// 根据coordinates画一个矩形来表示高亮
|
int width = activityCoordinates.getWidth();
|
int height = activityCoordinates.getHeight();
|
int x = activityCoordinates.getX();
|
int y = activityCoordinates.getY();
|
// 画2个方框, 以加粗显示
|
g.drawRect(x, y, width, height);
|
// 图象生效
|
g.dispose();
|
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
try {
|
ImageIO.write(bi, "png", os);
|
} catch (IOException e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("getExecutionImage", e);
|
}
|
InputStream is = new ByteArrayInputStream(os.toByteArray());
|
byte[] result = InputStreamToByte(is);
|
return result;
|
|
}
|
|
public byte[] getExecutionImageByExecutionId(String executionId, String taskName) throws IOException {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
ExecutionService executionService = processEngine.getExecutionService();
|
String[] executionIdS = executionId.replace(".", ",").split(",");
|
// TODO GE
|
if (executionIdS.length >= 3) {
|
executionId = executionIdS[0] + "." + executionIdS[1];
|
}
|
ProcessInstance uniqueResult = executionService.createProcessInstanceQuery().processInstanceId(executionId)
|
.uniqueResult();
|
InputStream io = null;
|
BufferedImage bi = null;
|
RepositoryService repositoryService = processEngine.getRepositoryService();
|
String processDefinitionId = uniqueResult.getProcessInstance().getProcessDefinitionId();
|
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
|
.processDefinitionId(processDefinitionId).uniqueResult();
|
|
io = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(),
|
processDefinition.getImageResourceName());
|
|
bi = ImageIO.read(io);
|
|
if (!"".equals(taskName) && taskName != null) {
|
ActivityCoordinates coordinates = repositoryService.getActivityCoordinates(processDefinitionId, taskName);
|
|
// 获取图形上下文
|
Graphics2D g = (Graphics2D) bi.getGraphics();
|
g.setStroke(new BasicStroke(2));
|
g.setColor(Color.red);
|
// 根据coordinates画一个矩形来表示高亮
|
int width = coordinates.getWidth();
|
int height = coordinates.getHeight();
|
int x = coordinates.getX();
|
int y = coordinates.getY();
|
// 画2个方框, 以加粗显示
|
g.drawRect(x, y, width, height);
|
// 图象生效
|
g.dispose();
|
}
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
try {
|
ImageIO.write(bi, "png", os);
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
InputStream is = new ByteArrayInputStream(os.toByteArray());
|
byte[] result = InputStreamToByte(is);
|
return result;
|
}
|
|
/**
|
* 通过流程定义ID显示流程图片
|
*
|
* @param processDefinitionId 流程定义ID
|
* @param taskName 任务名称
|
* @return
|
* @throws IOException
|
*/
|
public byte[] getExecutionImageByProcessDefinitionId(String processDefinitionId, String taskName)
|
throws IOException {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
|
InputStream io = null;
|
BufferedImage bi = null;
|
RepositoryService repositoryService = processEngine.getRepositoryService();
|
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
|
.processDefinitionId(processDefinitionId).uniqueResult();
|
|
io = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(),
|
processDefinition.getImageResourceName());
|
|
bi = ImageIO.read(io);
|
|
if (!"".equals(taskName) && taskName != null) {
|
ActivityCoordinates coordinates = repositoryService.getActivityCoordinates(processDefinitionId, taskName);
|
|
// 获取图形上下文
|
Graphics2D g = (Graphics2D) bi.getGraphics();
|
g.setStroke(new BasicStroke(2));
|
g.setColor(Color.red);
|
// 根据coordinates画一个矩形来表示高亮
|
int width = coordinates.getWidth();
|
int height = coordinates.getHeight();
|
int x = coordinates.getX();
|
int y = coordinates.getY();
|
// 画2个方框, 以加粗显示
|
g.drawRect(x, y, width, height);
|
// 图象生效
|
g.dispose();
|
}
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
try {
|
ImageIO.write(bi, "png", os);
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
InputStream is = new ByteArrayInputStream(os.toByteArray());
|
byte[] result = InputStreamToByte(is);
|
return result;
|
}
|
|
@SuppressWarnings("unchecked")
|
public List<PLFlowObject> getFlowObjectByExecutionId(final String executionId) {
|
return (List<PLFlowObject>) new HibernateTemplate().run(new HibernateCallback() {
|
public Object execute() throws HibernateException {
|
PLFlowObjectDaoImpl impl = new PLFlowObjectDaoImpl();
|
String hql = "from PLFlowObject t where t.plexecutionid = :plexecutionid ";
|
return impl.findEntities(hql, "plexecutionid", executionId);
|
}
|
});
|
}
|
|
/**
|
* 获取抄送者的任务信息
|
*
|
* @param pluseroid
|
* @param first
|
* @param pageSize
|
* @return
|
*/
|
public FlowTaskInfo[] getCCTaskByUserId(String pluseroid, int first, int pageSize) {
|
List<String> assignerList = getAssigner(pluseroid);
|
StringBuffer sb = new StringBuffer();
|
for (int i = 0; i < assignerList.size(); i++) {
|
sb.append("'");
|
sb.append(assignerList.get(i));
|
if (i == assignerList.size() - 1) {
|
sb.append("'");
|
} else {
|
sb.append("',");
|
}
|
}
|
List<FlowTaskInfo> flowTaskInfos = new ArrayList<FlowTaskInfo>();
|
|
StringBuilder sql = new StringBuilder();
|
sql.append("select DBID_, NAME_, createTime, EXECUTION_ID_, PLDESC,plprocesstype ,plclsfoid");
|
sql.append(" from( ");
|
sql.append("select rownum rn, DBID_, NAME_,createTime, EXECUTION_ID_, PLDESC,plprocesstype,plclsfoid ");
|
sql.append(" from( ");
|
|
sql.append(
|
"(select t1.DBID_, t1.NAME_, t1.CREATE_ as createTime, t1.EXECUTION_ID_, i.PLDESC,i.plprocesstype,i.plclsfoid");
|
sql.append(" from JBPM4_TASK t1 left join PLFLOWINSTANCE i on t1.EXECUTION_ID_=i.PLEXECUTIONID");
|
sql.append(" where t1.ASSIGNEE_ in ?");
|
sql.append(" )union(");
|
|
sql.append(
|
" select t.DBID_, t.NAME_, t.CREATE_ as createTime, t.EXECUTION_ID_, i.PLDESC,i.plprocesstype,i.plclsfoid");
|
sql.append(
|
" from JBPM4_TASK t cross join JBPM4_PARTICIPATION participat1_ left join PLFLOWINSTANCE i on t.EXECUTION_ID_=i.PLEXECUTIONID");
|
sql.append(" where participat1_.TASK_=t.DBID_ and participat1_.TYPE_='viewer' and participat1_.USERID_ in ? ");
|
|
sql.append(" and (t.ASSIGNEE_ is null) )");
|
|
sql.append(" order by createTime desc");
|
sql.append(" ) ");
|
sql.append(" where 1=1 ");
|
sql.append(" and rownum <= " + first * pageSize);
|
sql.append(" and execution_id_ is not null ");
|
sql.append(" order by createTime desc");// and PLDESC is not null
|
sql.append(")");
|
sql.append(" where rn >" + (first - 1) * pageSize);
|
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
createSQLQuery.setString(0, sb.toString());
|
createSQLQuery.setString(1, sb.toString());
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
List<?> list = createSQLQuery.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] object = (Object[]) list.get(i);
|
FlowTaskInfo flowHistoryTaskInfo = new FlowTaskInfo();
|
String taskId = String.valueOf(object[0]);
|
String taskName = (String) object[1];
|
Timestamp createTime = (Timestamp) object[2];
|
String executionId = (String) object[3];
|
String desc = (String) object[4];
|
String processType = (String) object[5];
|
String plclsfoid = (String) object[6];
|
// 获得发起人名称
|
List<FlowApproveHistory> historyActivityByProInsId = this.getHistoryActivityByExcetionID(session,
|
executionId);
|
if (historyActivityByProInsId != null && historyActivityByProInsId.size() > 0) {
|
String assignee = historyActivityByProInsId.get(0).getAssignee();
|
flowHistoryTaskInfo.plAssgin = assignee == null ? "" : assignee;
|
}
|
|
flowHistoryTaskInfo.id = taskId == null ? "" : taskId;
|
flowHistoryTaskInfo.name = taskName == null ? "" : taskName;
|
flowHistoryTaskInfo.createTime = createTime.getTime();
|
flowHistoryTaskInfo.executionId = executionId == null ? "" : executionId;
|
flowHistoryTaskInfo.desc = desc == null ? "" : desc;
|
flowHistoryTaskInfo.processType = processType == null ? "" : processType;
|
flowHistoryTaskInfo.plclsfoid = plclsfoid == null ? "" : plclsfoid;
|
flowTaskInfos.add(flowHistoryTaskInfo);
|
}
|
} catch (Exception ex) {
|
// ex.printStackTrace();
|
ServerWithLog4j.logger.error("getCCTaskByUserId", ex);
|
} finally {
|
|
}
|
return flowTaskInfos.toArray(new FlowTaskInfo[0]);
|
}
|
|
/**
|
* 抄送人信息总数
|
*
|
* @param pluseroid
|
* @return
|
*/
|
public int queryCCTaskCount(String pluseroid) {
|
List<String> assignerList = getAssigner(pluseroid);
|
StringBuffer sb = new StringBuffer();
|
for (int i = 0; i < assignerList.size(); i++) {
|
sb.append("'");
|
sb.append(assignerList.get(i));
|
if (i == assignerList.size() - 1) {
|
sb.append("'");
|
} else {
|
sb.append("',");
|
}
|
}
|
StringBuilder sql = new StringBuilder();
|
int res = 0;
|
|
sql.append("select count(*) from (");
|
sql.append(
|
"(select t1.DBID_, t1.NAME_, t1.CREATE_ as createTime, t1.EXECUTION_ID_, i.PLDESC, i.plprocesstype, i.plclsfoid from JBPM4_TASK t1 left join PLFLOWINSTANCE i on t1.EXECUTION_ID_ = i.PLEXECUTIONID where t1.ASSIGNEE_ in ?)");
|
sql.append(" union ");
|
sql.append(
|
"(select t.DBID_, t.NAME_, t.CREATE_ as createTime, t.EXECUTION_ID_, i.PLDESC, i.plprocesstype, i.plclsfoid from JBPM4_TASK t cross join JBPM4_PARTICIPATION participat1_ left join PLFLOWINSTANCE i on t.EXECUTION_ID_ = i.PLEXECUTIONID where participat1_.TASK_ = t.DBID_ and participat1_.TYPE_ = 'candidate' and participat1_.USERID_ in ? and (t.ASSIGNEE_ is null))");
|
sql.append(" order by createTime desc) where execution_id_ is not null order by createTime desc");
|
ServerWithLog4j.logger.debug("sql = " + sql.toString());
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
createSQLQuery.setString(0, pluseroid);
|
createSQLQuery.setString(1, pluseroid);
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List<?> list = createSQLQuery.list();
|
if (list != null && list.size() > 0) {
|
res = Integer.parseInt(String.valueOf(list.get(0)));
|
}
|
|
} catch (Exception ex) {
|
// ex.printStackTrace();
|
ServerWithLog4j.logger.error("queryCCTaskCount", ex);
|
} finally {
|
|
}
|
return res;
|
}
|
|
/**
|
* 通过抄送人获取对应的候选人
|
*
|
* @param executionId
|
* @param taskName
|
* @param userName
|
* @return
|
*/
|
private List<String> getAssigner(String userName) {
|
TaskCCService service = new TaskCCService();
|
List<TaskCCSObject> taskCCInfosByUserName = service.getTaskCCInfosByUserName(userName);
|
List<String> userList = new ArrayList<String>();
|
for (int i = 0; i < taskCCInfosByUserName.size(); i++) {
|
TaskCCSObject taskCCSObject = taskCCInfosByUserName.get(i);
|
userList.add(taskCCSObject.getAssigner());
|
}
|
return userList;
|
}
|
|
public String getDeploymentIdByExecutionId(String executionId) {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
String[] executionIdS = executionId.replace(".", ",").split(",");
|
if (executionIdS.length >= 3) {
|
executionId = executionIdS[0] + "." + executionIdS[1];
|
}
|
Execution findExecutionById = processEngine.getExecutionService().findExecutionById(executionId);
|
if (findExecutionById == null) {
|
return "";
|
}
|
ProcessDefinition uniqueResult = processEngine.getRepositoryService().createProcessDefinitionQuery()
|
.processDefinitionId(findExecutionById.getProcessDefinitionId()).uniqueResult();
|
return uniqueResult.getDeploymentId();
|
}
|
|
private static void close(Statement stmt) {
|
if (stmt != null) {
|
try {
|
stmt.close();
|
} catch (SQLException e) {
|
ServerWithLog4j.logger.error("close-1", e);
|
}
|
}
|
}
|
|
private static void close(ResultSet rs) {
|
if (rs != null) {
|
try {
|
rs.close();
|
} catch (SQLException e) {
|
ServerWithLog4j.logger.error("close-2", e);
|
}
|
}
|
}
|
|
public void endProcessInstance(String processInstanceId) throws VCIError {
|
Session session = HibernateSessionFactory.getSession();
|
session.beginTransaction();
|
String user = getUserEntity().getUserName();
|
String oid = ObjectUtility.getNewObjectID36();
|
String execution_ = "";
|
String priority_ = "";
|
String v_assignee_ = "";
|
String v_activity_name_ = "";
|
Timestamp v_create_ = new Timestamp(0);
|
Timestamp v_end_ = new Timestamp(0);
|
BigDecimal procinst_ = new BigDecimal(0);
|
StringBuilder sql = new StringBuilder();
|
|
sql.append(
|
"select assignee_, create_, execution_id_ , PROCINST_, ACTIVITY_NAME_ from jbpm4_task where execution_id_ = '"
|
+ processInstanceId + "'");
|
SQLQuery createSQLQuery1 = session.createSQLQuery(sql.toString());
|
//无意义代码
|
// createSQLQuery1.executeUpdate();
|
List<?> list1 = createSQLQuery1.list();
|
for (int i = 0; i < list1.size(); i++) {
|
Object[] object = (Object[]) list1.get(i);
|
v_assignee_ = (String) object[0];
|
v_create_ = (Timestamp) object[1];
|
execution_ = (String) object[2];
|
procinst_ = (BigDecimal) object[3];
|
v_activity_name_ = (String) object[4];
|
}
|
|
Date date = new Date();
|
long time = date.getTime();
|
// v_create_ = new Timestamp(time);
|
v_end_ = new Timestamp(time);
|
StringBuilder insertJbpm4HistTask = new StringBuilder();
|
insertJbpm4HistTask.append("insert into jbpm4_hist_task");
|
insertJbpm4HistTask.append(
|
" (dbid_, dbversion_, execution_, outcome_, assignee_, priority_, state_, create_,end_, duration_, nextidx_) ");
|
insertJbpm4HistTask.append(" values ");
|
insertJbpm4HistTask
|
.append(" (" + time + ", 1, '" + processInstanceId + "', 'jbpm_no_task_outcome_specified_jbpm', '"
|
+ v_assignee_ + "', '0', 'completed', ?, ?, '0', '1') ");
|
SQLQuery createSQLQuery2 = session.createSQLQuery(insertJbpm4HistTask.toString());
|
createSQLQuery2.setTimestamp(0, v_end_);
|
createSQLQuery2.setTimestamp(1, v_end_);
|
createSQLQuery2.executeUpdate();
|
|
StringBuilder insertPlflowapproveopinion = new StringBuilder();
|
insertPlflowapproveopinion.append("insert into plflowapproveopinion");
|
insertPlflowapproveopinion.append(" (ploid, pltaskid, plapproveopinion, plapprovenote, plassgin) ");
|
insertPlflowapproveopinion.append(" values ");
|
insertPlflowapproveopinion.append(" ('" + oid + "', '" + time + "', '流程终止', '流程终止', '" + user + "') ");
|
session.createSQLQuery(insertPlflowapproveopinion.toString()).executeUpdate();
|
// session.getTransaction().commit();
|
|
// session.beginTransaction();
|
StringBuilder insertJbpm4HistActinst = new StringBuilder();
|
insertJbpm4HistActinst.append("insert into jbpm4_hist_actinst");
|
insertJbpm4HistActinst.append(
|
" (dbid_, class_, dbversion_, hproci_, type_, execution_, start_, duration_, transition_, nextidx_, htask_,ACTIVITY_NAME_) ");
|
insertJbpm4HistActinst.append(" values ");
|
insertJbpm4HistActinst.append(" (" + time + ", 'task', '0', " + procinst_ + ", 'task', '" + execution_
|
+ "', ?, '0', 'jbpm_no_task_outcome_specified_jbpm', '1', " + time + ",?) ");
|
SQLQuery createSQLQuery3 = session.createSQLQuery(insertJbpm4HistActinst.toString());
|
createSQLQuery3.setTimestamp(0, v_create_);
|
createSQLQuery3.setString(1, v_activity_name_);
|
createSQLQuery3.executeUpdate();
|
// session.getTransaction().commit();
|
|
// session.beginTransaction();
|
|
// 结束流程
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
ExecutionService executionService = processEngine.getExecutionService();
|
StringBuffer sb = new StringBuffer();
|
// 如果是分支流程,先查到分支的父节点,然后将父节点的挂起状态更改掉,再去终止流程
|
sb.append(" select dbid_,id_ from jbpm4_execution b where b.dbid_= ")
|
.append(" (select a.parent_ from jbpm4_execution a where a.id_='" + processInstanceId + "') ");
|
String parentDBId = "";
|
String parentID = "";
|
StringBuffer upDataSql = new StringBuffer();
|
upDataSql.append("update jbpm4_execution c set c.state_ = 'active-root' where c.dbid_= ? ");
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sb.toString());
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List<?> list = createSQLQuery.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] object = (Object[]) list.get(i);
|
parentDBId = String.valueOf(object[0]);
|
parentID = String.valueOf(object[1]);
|
}
|
if (parentID != null && !"".equals(parentID)) {
|
processInstanceId = parentID;
|
}
|
|
SQLQuery updateSQLQuery = session.createSQLQuery(upDataSql.toString());
|
updateSQLQuery.setString(0, parentDBId);
|
updateSQLQuery.executeUpdate();
|
|
} catch (Exception e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("endProcessInstance", e);
|
}
|
// session.getTransaction().commit();
|
// session.getTransaction().begin();
|
// 设置标记用来区分是正常流程结束,还是中断流程。
|
executionService.setVariable(processInstanceId, "intermit", "true");
|
executionService.endProcessInstance(processInstanceId, ProcessInstance.STATE_ENDED);
|
}
|
|
/**
|
* 流程终止
|
*
|
* @param processInstanceId
|
* @throws VCIError
|
*/
|
public void endProcessInstanceByplatform(String processInstanceId) throws VCIError {
|
ServerWithLog4j.logger.debug("开始终止流程:" + processInstanceId);
|
Session session = HibernateSessionFactory.getSession();
|
// session.beginTransaction();
|
String user = getUserEntity().getUserName();
|
String oid = ObjectUtility.getNewObjectID36();
|
String execution_ = "";
|
String priority_ = "";
|
String v_assignee_ = "";
|
String v_activity_name_ = "";
|
Timestamp v_create_ = new Timestamp(0);
|
Timestamp v_end_ = new Timestamp(0);
|
BigDecimal procinst_ = new BigDecimal(0);
|
StringBuilder sql = new StringBuilder();
|
|
String newExecutionId = processInstanceId.replace(".", ",");
|
String[] split = newExecutionId.split(",");
|
String exeId = "";
|
boolean subTaskFlag = true;
|
if (split.length > 2) {
|
exeId = split[0] + "." + split[1];
|
} else {
|
exeId = processInstanceId;
|
}
|
|
sql.append(
|
"select assignee_, create_, execution_id_ , PROCINST_, ACTIVITY_NAME_ from jbpm4_task where execution_id_ = '"
|
+ exeId + "'");
|
SQLQuery createSQLQuery1 = session.createSQLQuery(sql.toString());
|
|
//无意义代码
|
// createSQLQuery1.executeUpdate();
|
List<?> list1 = createSQLQuery1.list();
|
for (int i = 0; i < list1.size(); i++) {
|
Object[] object = (Object[]) list1.get(i);
|
v_assignee_ = (String) object[0];
|
v_create_ = (Timestamp) object[1];
|
execution_ = (String) object[2];
|
procinst_ = (BigDecimal) object[3];
|
v_activity_name_ = (String) object[4];
|
}
|
|
Date date = new Date();
|
long time = date.getTime();
|
// // v_create_ = new Timestamp(time);
|
v_end_ = new Timestamp(time);
|
StringBuilder insertJbpm4HistTask = new StringBuilder();
|
insertJbpm4HistTask.append("insert into jbpm4_hist_task");
|
insertJbpm4HistTask.append(
|
" (dbid_, dbversion_, execution_, outcome_, assignee_, priority_, state_, create_,end_, duration_, nextidx_) ");
|
insertJbpm4HistTask.append(" values ");
|
insertJbpm4HistTask
|
.append(" (" + time + ", 1, '" + processInstanceId + "', 'jbpm_no_task_outcome_specified_jbpm', '"
|
+ v_assignee_ + "', '0', 'completed', ?,?, '0', '1') ");
|
SQLQuery createSQLQuery2 = session.createSQLQuery(insertJbpm4HistTask.toString());
|
createSQLQuery2.setTimestamp(0, v_end_);
|
createSQLQuery2.setTimestamp(1, v_end_);
|
createSQLQuery2.executeUpdate();
|
|
StringBuilder insertPlflowapproveopinion = new StringBuilder();
|
insertPlflowapproveopinion.append("insert into plflowapproveopinion");
|
insertPlflowapproveopinion.append(" (ploid, pltaskid, plapproveopinion, plapprovenote, plassgin) ");
|
insertPlflowapproveopinion.append(" values ");
|
insertPlflowapproveopinion.append(" ('" + oid + "', '" + time + "', '流程中止', '流程中止', '" + user + "') ");
|
session.createSQLQuery(insertPlflowapproveopinion.toString()).executeUpdate();
|
// session.getTransaction().commit();
|
|
// session.beginTransaction();
|
StringBuilder insertJbpm4HistActinst = new StringBuilder();
|
insertJbpm4HistActinst.append("insert into jbpm4_hist_actinst");
|
insertJbpm4HistActinst.append(
|
" (dbid_, class_, dbversion_, hproci_, type_, execution_, start_, duration_, transition_, nextidx_, htask_,ACTIVITY_NAME_) ");
|
insertJbpm4HistActinst.append(" values ");
|
insertJbpm4HistActinst.append(" (" + time + ", 'task', '0', " + procinst_ + ", 'task', '" + execution_
|
+ "', ?, '0', 'jbpm_no_task_outcome_specified_jbpm', '1', " + time + ",?) ");
|
|
ServerWithLog4j.logger.debug("插入历史活动:" + insertJbpm4HistActinst.toString());
|
|
final SQLQuery createSQLQuery3 = session.createSQLQuery(insertJbpm4HistActinst.toString());
|
createSQLQuery3.setTimestamp(0, v_create_);
|
createSQLQuery3.setString(1, v_activity_name_);
|
new HibernateTemplate().run(new HibernateCallback() {
|
|
public Object execute() throws HibernateException, SQLException, VCIError {
|
createSQLQuery3.executeUpdate();
|
return null;
|
}
|
});
|
// session.getTransaction().commit();
|
|
// session.beginTransaction();
|
|
// 结束流程
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
ExecutionService executionService = processEngine.getExecutionService();
|
StringBuffer sb = new StringBuffer();
|
// 如果是分支流程,先查到分支的父节点,然后将父节点的挂起状态更改掉,再去终止流程
|
sb.append(" select dbid_,id_ from jbpm4_execution b where b.dbid_= ")
|
.append(" (select a.parent_ from jbpm4_execution a where a.id_='" + processInstanceId + "') ");
|
String parentDBId = "";
|
String parentID = "";
|
StringBuffer upDataSql = new StringBuffer();
|
upDataSql.append("update jbpm4_execution c set c.state_ = 'active-root' where c.dbid_= ? ");
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sb.toString());
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List<?> list = createSQLQuery.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] object = (Object[]) list.get(i);
|
parentDBId = String.valueOf(object[0]);
|
parentID = String.valueOf(object[1]);
|
}
|
if (parentID != null && !"".equals(parentID)) {
|
processInstanceId = parentID;
|
}
|
|
SQLQuery updateSQLQuery = session.createSQLQuery(upDataSql.toString());
|
updateSQLQuery.setString(0, parentDBId);
|
updateSQLQuery.executeUpdate();
|
|
} catch (Exception e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("endProcessInstanceByplatform-1", e);
|
}
|
|
// 删除workitem和input
|
try {
|
endProcess(processInstanceId);
|
} catch (SecurityException e) {
|
ServerWithLog4j.logger.error("endProcessInstanceByplatform-2", e);
|
// e.printStackTrace();
|
} catch (IllegalArgumentException e) {
|
ServerWithLog4j.logger.error("endProcessInstanceByplatform-3", e);
|
// e.printStackTrace();
|
} catch (ClassNotFoundException e) {
|
ServerWithLog4j.logger.error("endProcessInstanceByplatform-4", e);
|
// e.printStackTrace();
|
} catch (NoSuchMethodException e) {
|
ServerWithLog4j.logger.error("endProcessInstanceByplatform-5", e);
|
// e.printStackTrace();
|
} catch (IllegalAccessException e) {
|
ServerWithLog4j.logger.error("endProcessInstanceByplatform-6", e);
|
// e.printStackTrace();
|
} catch (InvocationTargetException e) {
|
ServerWithLog4j.logger.error("endProcessInstanceByplatform-7", e);
|
// e.printStackTrace();
|
} catch (InstantiationException e) {
|
ServerWithLog4j.logger.error("endProcessInstanceByplatform-8", e);
|
// e.printStackTrace();
|
}
|
|
// session.getTransaction().commit();
|
// session.getTransaction().begin();
|
// 设置标记用来区分是正常流程结束,还是中断流程。
|
executionService.setVariable(processInstanceId, "intermit", "true");
|
executionService.endProcessInstance(processInstanceId, ProcessInstance.STATE_ENDED);
|
ServerWithLog4j.logger.debug("完成终止流程:" + processInstanceId);
|
}
|
|
private void endProcess(String processInstanceId)
|
throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException,
|
IllegalAccessException, InvocationTargetException, InstantiationException, VCIError {
|
if (workitemClass != null && !"".equals(workitemClass)) {
|
// PLMWorkItemInterface pwService = (PLMWorkItemInterface)
|
// (Class.forName(workitemClass).newInstance());
|
if (_pwiService != null) {
|
_pwiService.endProcess(processInstanceId);
|
}
|
// Class<?> c = Class.forName(workitemClass);
|
// Method m = c.getDeclaredMethod("endProcess", new Class[]{String.class});
|
// m.invoke(c.newInstance(), new Object[]{processInstanceId});
|
}
|
}
|
|
public List<ProcessDefinition> getProcessDefinitionByType(final String processType) {
|
RMTemplateProcess object = (RMTemplateProcess) new HibernateTemplate().run(new HibernateCallback() {
|
public Object execute() throws HibernateException {
|
RMTemplateProcessDaoImpl impl = new RMTemplateProcessDaoImpl();
|
String hql = "from RMTemplateProcess t where t.processType = ?";
|
return impl.findEntity(hql, new Object[] { processType });
|
}
|
});
|
if (object != null) {
|
String jbpmDeploymentId = object.getJbpmDeploymentId();
|
|
RepositoryService repositoryService = JbpmEngine.getProcessEngine().getRepositoryService();
|
List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery()
|
.deploymentId(jbpmDeploymentId).list();
|
return list;
|
} else {
|
return new ArrayList<ProcessDefinition>();
|
}
|
}
|
|
/**
|
* 查询流程定义列表
|
*
|
* @return
|
*/
|
public List<ProcessDefinition> getProcessDefinitionAll() {
|
Session session = HibernateSessionFactory.getSession();
|
String sql = "select * from JBPM4_DEPLOYPROP t where t.key_ = 'pdid'";
|
String jbpmDeploymentId = "";
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List<?> list = createSQLQuery.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] obj = (Object[]) list.get(i);
|
jbpmDeploymentId = String.valueOf(obj[0]);
|
}
|
} catch (Exception ex) {
|
// ex.printStackTrace();
|
ServerWithLog4j.logger.error("getProcessDefinitionAll", ex);
|
} finally {
|
|
}
|
if (jbpmDeploymentId != null && !"".equals(jbpmDeploymentId)) {
|
|
RepositoryService repositoryService = JbpmEngine.getProcessEngine().getRepositoryService();
|
List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery()
|
.deploymentId(jbpmDeploymentId).list();
|
return list;
|
} else {
|
return new ArrayList<ProcessDefinition>();
|
}
|
}
|
|
/**
|
* 查询流程结束后的部署ID
|
*
|
* @param executionId
|
* @return
|
*/
|
public String getDepolymentID(String executionId) {
|
StringBuilder sql = new StringBuilder();
|
String newExecutionId = executionId.replace(".", ",");
|
String[] split = newExecutionId.split(",");
|
if (split.length > 2) {
|
executionId = split[0] + "." + split[1];
|
}
|
sql.append(
|
"select t.deployment_ from jbpm4_deployprop t where t.stringval_=(select t.procdefid_ from jbpm4_hist_procinst t where t.id_='"
|
+ executionId + "')");
|
String deployID = "";
|
try {
|
Query createQuery = HibernateSessionFactory.getSession().createSQLQuery(sql.toString());
|
List<BigDecimal> list = createQuery.list();
|
if (list != null && list.size() > 0) {
|
deployID = String.valueOf(list.get(0));
|
}
|
} catch (Exception ex) {
|
// ex.printStackTrace();
|
ServerWithLog4j.logger.error("getDepolymentID", ex);
|
}
|
return deployID;
|
}
|
|
/**
|
* 当整个流程结束后显示流程图
|
*
|
* @param deployID
|
* @return
|
* @throws IOException
|
*/
|
public byte[] getFlowImageByDeployID(String executionId) throws IOException {
|
// 取得父节点的id。如果包含子节点id。则重新组装执行id。
|
String[] executionIds = executionId.replace(".", ",").split(",");
|
if (executionIds.length >= 3) {
|
executionId = executionIds[0] + "." + executionIds[1];
|
}
|
InputStream io = null;
|
BufferedImage bi = null;
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
RepositoryService repositoryService = processEngine.getRepositoryService();
|
StringBuilder sql = new StringBuilder();
|
sql.append("select t.procdefid_ from jbpm4_hist_procinst t where t.id_='" + executionId + "'");
|
String processDefinitionId = "";
|
try {
|
Query createQuery = HibernateSessionFactory.getSession().createSQLQuery(sql.toString());
|
List<BigDecimal> list = createQuery.list();
|
if (list != null && list.size() > 0) {
|
processDefinitionId = String.valueOf(list.get(0));
|
}
|
} catch (Exception ex) {
|
// ex.printStackTrace();
|
ServerWithLog4j.logger.error("getFlowImageByDeployID", ex);
|
}
|
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
|
.processDefinitionId(processDefinitionId).uniqueResult();
|
|
io = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(),
|
processDefinition.getImageResourceName());
|
|
bi = ImageIO.read(io);
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
try {
|
ImageIO.write(bi, "png", os);
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
InputStream is = new ByteArrayInputStream(os.toByteArray());
|
byte[] result = InputStreamToByte(is);
|
return result;
|
}
|
|
/**
|
* 已办任务
|
*
|
* @param pluseroid
|
* @param first
|
* @param pageSize
|
* @param tasktype
|
* @param querySQL
|
* @return
|
*/
|
public FlowTaskInfo[] getDoneTaskByUserId(String pluseroid, int first, int pageSize, String tasktype,
|
String querySQL) {
|
// ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
|
List<FlowTaskInfo> flowTaskInfos = new ArrayList<FlowTaskInfo>();
|
StringBuilder sql = new StringBuilder();
|
sql.append(
|
" select DBID_, taskName, createTime, END_, EXECUTION_, PLDESC, pltemplatename,createUser ,plprocesstype ,processname");
|
sql.append(" from( ");
|
sql.append(
|
" select rownum rn,DBID_, taskName, createTime, END_, EXECUTION_, PLDESC ,pltemplatename,createUser,plprocesstype ,processname");
|
sql.append(" from( ");
|
sql.append(
|
"select ht.DBID_, ha.ACTIVITY_NAME_ as taskName, ht.CREATE_ as createTime, ht.END_, ht.EXECUTION_, i.PLDESC, i.pltemplatename,i.plcreator as createUser,i.pltasktype,i.plprocesstype as plprocesstype,i.processname as processname");
|
sql.append(
|
" FROM JBPM4_HIST_TASK ht left join JBPM4_HIST_ACTINST ha on ht.DBID_=ha.HTASK_ left join PLFLOWINSTANCE i on ht.EXECUTION_ like (i.PLEXECUTIONID||'%')");
|
sql.append(" left join JBPM4_HIST_PROCINST hp on ht.EXECUTION_ = hp.ID_");
|
String[] taskTypes = null;
|
String sqldept = "";
|
try {
|
// 2011.12.08 ligang查询指定日期范围的已办任务数据
|
int datePeriod = Integer.parseInt(WorkflowProperties.getStringProperty("done.task.date.period"));
|
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
|
long period = 1000L * 24 * 60 * 60 * datePeriod;
|
String startDate = sd.format(
|
new Date(sd.parse(new SimpleDateFormat("yyyy-MM-dd").format(new Date())).getTime() - period));
|
String endDate = sd.format(new Date());
|
sql.append(" where ht.END_ is not null and ht.ASSIGNEE_ = ? ");
|
sql.append(" order by ht.END_ desc");
|
// 分页
|
sql.append(")");
|
sql.append(" where 1=1 ");
|
if (tasktype != null && !"".equals(tasktype)) {
|
taskTypes = tasktype.split(",");
|
sql.append(" and pltasktype in ( ");
|
|
for (int i = 0; i < taskTypes.length; i++) {
|
sql.append("?");
|
if (i < taskTypes.length - 1) {
|
sql.append(",");
|
}
|
}
|
sql.append(" )");
|
}
|
if (querySQL != "") {
|
sql.append(querySQL);
|
}
|
sql.append("and rownum <= " + first * pageSize);
|
sql.append(" )");
|
sql.append(" where rn >" + (first - 1) * pageSize);
|
} catch (ParseException e1) {
|
// e1.printStackTrace();
|
ServerWithLog4j.logger.error("getDoneTaskByUserId", e1);
|
}
|
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
createSQLQuery.setString(0, pluseroid);
|
if (tasktype != null && !"".equals(tasktype)) {
|
for (int i = 0; i < taskTypes.length; i++) {
|
createSQLQuery.setString(1 + i, taskTypes[i]);
|
}
|
}
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
List<?> list = createSQLQuery.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] object = (Object[]) list.get(i);
|
FlowTaskInfo flowHistoryTaskInfo = new FlowTaskInfo();
|
String taskId = String.valueOf(object[0]);
|
String taskName = (String) object[1];
|
Timestamp createTime = (Timestamp) object[2];
|
Timestamp endTime = (Timestamp) object[3];
|
String executionId = (String) object[4];
|
String desc = (String) object[5];
|
String templateName = (String) object[6];
|
String createUser = (String) object[7];
|
String processType = (String) object[8];
|
String processName = (String) object[9];
|
flowHistoryTaskInfo.id = taskId == null ? "" : taskId;
|
flowHistoryTaskInfo.name = taskName == null ? "" : taskName;
|
flowHistoryTaskInfo.createTime = createTime.getTime();
|
flowHistoryTaskInfo.endTime = endTime.getTime();
|
flowHistoryTaskInfo.executionId = executionId == null ? "" : executionId;
|
flowHistoryTaskInfo.desc = desc == null ? "" : desc;
|
flowHistoryTaskInfo.templateName = templateName == null ? "" : templateName;
|
flowHistoryTaskInfo.applyPerson = createUser == null ? "" : createUser;
|
flowHistoryTaskInfo.processType = processType == null ? "" : processType;
|
flowHistoryTaskInfo.processName = processName == null ? "" : processName;
|
flowTaskInfos.add(flowHistoryTaskInfo);
|
}
|
} catch (Exception ex) {
|
// ex.printStackTrace();
|
ServerWithLog4j.logger.error("getDoneTaskByUserId", ex);
|
} finally {
|
|
}
|
return flowTaskInfos.toArray(new FlowTaskInfo[0]);
|
}
|
|
/**
|
* 已办任务(可排序)
|
*
|
* @param pluseroid
|
* @param first
|
* @param pageSize
|
* @param tasktype
|
* @param querySQL
|
* @param orderStr 排序字段,以order by开头
|
* @return
|
*/
|
public FlowTaskInfo[] getDoneTaskCompositorByUserId(String pluseroid, int first, int pageSize, String tasktype,
|
String querySQL, String orderStr) {
|
// ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
|
List<FlowTaskInfo> flowTaskInfos = new ArrayList<FlowTaskInfo>();
|
StringBuilder sql = new StringBuilder();
|
sql.append(
|
" select DBID_, taskName, createTime, END_, EXECUTION_, PLDESC, pltemplatename,createUser ,plprocesstype ,processname");
|
sql.append(" from( ");
|
sql.append(
|
" select rownum rn,DBID_, taskName, createTime, END_, EXECUTION_, PLDESC ,pltemplatename,createUser,plprocesstype ,processname");
|
sql.append(" from( ");
|
sql.append(
|
"select ht.DBID_, ha.ACTIVITY_NAME_ as taskName, ht.CREATE_ as createTime, ht.END_, ht.EXECUTION_, i.PLDESC, i.pltemplatename,i.plcreator as createUser,i.pltasktype,i.plprocesstype as plprocesstype,i.processname as processname");
|
sql.append(
|
" FROM JBPM4_HIST_TASK ht left join JBPM4_HIST_ACTINST ha on ht.DBID_=ha.HTASK_ left join PLFLOWINSTANCE i on ht.EXECUTION_ like (i.PLEXECUTIONID||'%')");
|
sql.append(" left join JBPM4_HIST_PROCINST hp on ht.EXECUTION_ = hp.ID_");
|
String[] taskTypes = null;
|
String sqldept = "";
|
try {
|
// 2011.12.08 ligang查询指定日期范围的已办任务数据
|
int datePeriod = Integer.parseInt(WorkflowProperties.getStringProperty("done.task.date.period"));
|
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
|
long period = 1000L * 24 * 60 * 60 * datePeriod;
|
String startDate = sd.format(
|
new Date(sd.parse(new SimpleDateFormat("yyyy-MM-dd").format(new Date())).getTime() - period));
|
String endDate = sd.format(new Date());
|
sql.append(" where ht.END_ is not null and ht.ASSIGNEE_ = ? ");
|
// 排序
|
String orderBy = " order by ht.END_ desc";
|
if (orderStr != null && !"".equals(orderStr)) {
|
orderBy = " " + orderStr + " ";
|
}
|
sql.append(orderBy);
|
// 分页
|
sql.append(")");
|
sql.append(" where 1=1 ");
|
if (tasktype != null && !"".equals(tasktype)) {
|
taskTypes = tasktype.split(",");
|
sql.append(" and pltasktype in ( ");
|
|
for (int i = 0; i < taskTypes.length; i++) {
|
sql.append("?");
|
if (i < taskTypes.length - 1) {
|
sql.append(",");
|
}
|
}
|
sql.append(" )");
|
}
|
if (querySQL != "") {
|
sql.append(querySQL);
|
}
|
sql.append("and rownum <= " + first * pageSize);
|
sql.append(" )");
|
sql.append(" where rn >" + (first - 1) * pageSize);
|
} catch (ParseException e1) {
|
// e1.printStackTrace();
|
ServerWithLog4j.logger.error("getDoneTaskCompositorByUserId", e1);
|
}
|
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
createSQLQuery.setString(0, pluseroid);
|
if (tasktype != null && !"".equals(tasktype)) {
|
for (int i = 0; i < taskTypes.length; i++) {
|
createSQLQuery.setString(1 + i, taskTypes[i]);
|
}
|
}
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
List<?> list = createSQLQuery.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] object = (Object[]) list.get(i);
|
FlowTaskInfo flowHistoryTaskInfo = new FlowTaskInfo();
|
String taskId = String.valueOf(object[0]);
|
String taskName = (String) object[1];
|
Timestamp createTime = (Timestamp) object[2];
|
Timestamp endTime = (Timestamp) object[3];
|
String executionId = (String) object[4];
|
String desc = (String) object[5];
|
String templateName = (String) object[6];
|
String createUser = (String) object[7];
|
String processType = (String) object[8];
|
String processName = (String) object[9];
|
flowHistoryTaskInfo.id = taskId == null ? "" : taskId;
|
flowHistoryTaskInfo.name = taskName == null ? "" : taskName;
|
flowHistoryTaskInfo.createTime = createTime.getTime();
|
flowHistoryTaskInfo.endTime = endTime.getTime();
|
flowHistoryTaskInfo.executionId = executionId == null ? "" : executionId;
|
flowHistoryTaskInfo.desc = desc == null ? "" : desc;
|
flowHistoryTaskInfo.templateName = templateName == null ? "" : templateName;
|
flowHistoryTaskInfo.applyPerson = createUser == null ? "" : createUser;
|
flowHistoryTaskInfo.processType = processType == null ? "" : processType;
|
flowHistoryTaskInfo.processName = processName == null ? "" : processName;
|
flowTaskInfos.add(flowHistoryTaskInfo);
|
}
|
} catch (Exception ex) {
|
// ex.printStackTrace();
|
ServerWithLog4j.logger.error("getDoneTaskCompositorByUserId-2", ex);
|
} finally {
|
|
}
|
return flowTaskInfos.toArray(new FlowTaskInfo[0]);
|
}
|
|
/**
|
* 已办任务总数
|
*
|
* @param pluseroid
|
* @param expandSql
|
* @return
|
*/
|
public int queryDoneTaskCount(String pluseroid, String expandSql) {
|
// 查询已办任务总条数
|
int res = 0;
|
List<FlowTaskInfo> flowTaskInfos = new ArrayList<FlowTaskInfo>();
|
StringBuilder sql = new StringBuilder();
|
sql.append(" select COUNT(*) ");
|
sql.append(" from( ");
|
sql.append(
|
"select ht.DBID_, ha.ACTIVITY_NAME_ as taskName, ht.CREATE_ as createTime, ht.END_, ht.EXECUTION_, i.PLDESC, i.pltemplatename,i.plcreator as createUser,i.plprocesstype as plprocesstype,i.processname as processname");
|
sql.append(
|
" FROM JBPM4_HIST_TASK ht left join JBPM4_HIST_ACTINST ha on ht.DBID_=ha.HTASK_ left join PLFLOWINSTANCE i on ht.EXECUTION_ like (i.PLEXECUTIONID||'%')");
|
sql.append(" left join JBPM4_HIST_PROCINST hp on ht.EXECUTION_ = hp.ID_");
|
|
try {
|
int datePeriod = Integer.parseInt(WorkflowProperties.getStringProperty("done.task.date.period"));
|
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
|
long period = 1000L * 24 * 60 * 60 * datePeriod;
|
String startDate = sd.format(
|
new Date(sd.parse(new SimpleDateFormat("yyyy-MM-dd").format(new Date())).getTime() - period));
|
String endDate = sd.format(new Date());
|
|
sql.append(" where ht.END_ is not null and ht.ASSIGNEE_ = ? ");
|
sql.append(" )where 1=1 ");
|
if (expandSql != null && !"".equals(expandSql)) {
|
sql.append(expandSql);
|
}
|
} catch (ParseException e1) {
|
// e1.printStackTrace();
|
ServerWithLog4j.logger.error("queryDoneTaskCount", e1);
|
}
|
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
createSQLQuery.setString(0, pluseroid);
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List<?> list = createSQLQuery.list();
|
if (list != null && list.size() > 0) {
|
res = Integer.parseInt(String.valueOf(list.get(0)));
|
}
|
|
} catch (Exception ex) {
|
// ex.printStackTrace();
|
ServerWithLog4j.logger.error("queryDoneTaskCount", ex);
|
} finally {
|
|
}
|
return res;
|
}
|
|
/**
|
* 判断key重复
|
*
|
* @param name
|
* @param keyValue
|
* @return
|
*/
|
private boolean keyFlag = false;
|
private boolean NameFlag = false;
|
private boolean resFlag = false;
|
|
public boolean checkKey(final String name, final String keyValue) {
|
new HibernateTemplate().runSql(new Work() {
|
public void execute(Connection connection) throws SQLException {
|
PreparedStatement pstmt = null;
|
ResultSet rs = null;
|
String sqlName = "select objname_ from JBPM4_DEPLOYPROP a where a.stringval_ like '" + keyValue + "%'";
|
String sqlKey = "select stringval_ from JBPM4_DEPLOYPROP a where a.objname_ = '" + name
|
+ "' and a.stringval_ is not null";
|
pstmt = connection.prepareStatement(sqlName);
|
rs = pstmt.executeQuery();
|
while (rs.next()) {
|
if (!rs.getString("objname_").equals(name)) {
|
NameFlag = true;
|
}
|
}
|
pstmt = connection.prepareStatement(sqlKey);
|
rs = pstmt.executeQuery();
|
while (rs.next()) {
|
if (!rs.getString("stringval_").equals(keyValue)) {
|
keyFlag = true;
|
}
|
}
|
if (NameFlag || keyFlag) {
|
resFlag = true;
|
}
|
}
|
});
|
return resFlag;
|
}
|
|
public String[] getDeployId(String taskId) {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
Task task = processEngine.getTaskService().getTask(taskId);
|
String executionId = task.getExecutionId();
|
Execution findExecutionById = processEngine.getExecutionService().findExecutionById(executionId);
|
if (findExecutionById == null) {
|
return new String[0];
|
}
|
ProcessDefinition uniqueResult = processEngine.getRepositoryService().createProcessDefinitionQuery()
|
.processDefinitionId(findExecutionById.getProcessDefinitionId()).uniqueResult();
|
String deploymentId = uniqueResult.getDeploymentId();
|
String[] result = new String[2];
|
result[0] = deploymentId;
|
result[1] = task.getName();
|
return result;
|
}
|
|
/**
|
* 通过流程定义ID获取部署ID
|
*
|
* @param processDifId
|
* @return
|
*/
|
public String getDeployIdByProcessDefintionId(String processDifId) {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
ProcessDefinition uniqueResult = processEngine.getRepositoryService().createProcessDefinitionQuery()
|
.processDefinitionId(processDifId).uniqueResult();
|
String deploymentId = uniqueResult.getDeploymentId();
|
return deploymentId;
|
}
|
|
/**
|
* 获取任务的流向
|
*
|
* @param jbpmDeploymentId
|
* @param taskName
|
* @return
|
* @throws Exception
|
*/
|
public boolean getProcessTaskByTaskName(final String taskId, String taskName, String outcome) throws Exception {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
TaskService taskService = processEngine.getTaskService();
|
ProcessInstance processInstance = processEngine.getExecutionService()
|
.findProcessInstanceById(taskService.getTask(taskId).getExecutionId());
|
final String processDefinitionId = processInstance.getProcessDefinitionId();
|
String jbpmDeploymentId = (String) new HibernateTemplate().run(new HibernateCallback() {
|
public Object execute() throws HibernateException {
|
ProcessTaskDaoImpl impl = new ProcessTaskDaoImpl();
|
String sql = " select t.deployment_ from JBPM4_DEPLOYPROP t where t.stringval_ = '"
|
+ processDefinitionId + "'";
|
List<?> createQueryList = impl.findEntitesBySQL(sql, new String[0], new HashMap());
|
String id = "";
|
for (int i = 0; i < createQueryList.size(); i++) {
|
id = createQueryList.get(i).toString();
|
}
|
return id;
|
}
|
});
|
LinkedList<String> transTos = new LinkedList<String>();
|
byte[] jpdlXml = getProcessResource(jbpmDeploymentId, ".xml");
|
ByteArrayInputStream bais = new ByteArrayInputStream(jpdlXml);
|
BufferedReader reader = new BufferedReader(new InputStreamReader(bais, "utf-8"));
|
SAXReader saxReader = new SAXReader();
|
Document doc = saxReader.read(reader);
|
Element root = doc.getRootElement();
|
Iterator<?> itor = root.elementIterator();
|
String elementTaskName = "";
|
boolean itorBreak = false;
|
while (itor.hasNext()) {
|
Element e = (Element) itor.next();
|
if (e.getName().trim().toLowerCase().equals("task")) {
|
elementTaskName = e.attributeValue("name");
|
if (taskName.equals(elementTaskName)) {
|
Iterator<?> itorChild = e.elementIterator();
|
while (itorChild.hasNext()) {
|
Element eChild = (Element) itorChild.next();
|
if (eChild.getName().toLowerCase().equals("transition")) {
|
elementTaskName = eChild.attributeValue("name");
|
String endTaskName = eChild.attributeValue("to");
|
// 存储taskName全部的trasn
|
transTos.add(endTaskName);
|
}
|
}
|
break;
|
}
|
}
|
}
|
boolean nextTaskIsEnd = false;
|
bais.close();
|
reader.close();
|
// 检查transTo中是否存在着end
|
bais = new ByteArrayInputStream(jpdlXml);
|
reader = new BufferedReader(new InputStreamReader(bais, "utf-8"));
|
saxReader = new SAXReader();
|
doc = saxReader.read(reader);
|
root = doc.getRootElement();
|
itor = root.elementIterator();
|
while (itor.hasNext()) {
|
Element e = (Element) itor.next();
|
if (e.getName().trim().toLowerCase().equals("end")) {
|
for (String to : transTos) {
|
if (e.attributeValue("name").equals(to)) {
|
nextTaskIsEnd = true;
|
break;
|
}
|
}
|
}
|
if (nextTaskIsEnd) {
|
break;
|
}
|
}
|
bais.close();
|
reader.close();
|
return nextTaskIsEnd;
|
}
|
|
/**
|
* 获取元素的结束节点
|
*
|
* @param jbpmDeploymentId
|
* @param taskName
|
* @return
|
* @throws Exception
|
*/
|
public boolean getEndNode(String jbpmDeploymentId, String endTaskName) {
|
byte[] jpdlXml;
|
boolean itorBreak = false;
|
try {
|
ServerWithLog4j.logger.debug("jbpmDeploymentId===" + jbpmDeploymentId);
|
jpdlXml = getProcessResource(jbpmDeploymentId, ".xml");
|
ByteArrayInputStream bais = new ByteArrayInputStream(jpdlXml);
|
BufferedReader reader = new BufferedReader(new InputStreamReader(bais, "utf-8"));
|
SAXReader saxReader = new SAXReader();
|
Document doc = saxReader.read(reader);
|
Element root = doc.getRootElement();
|
Iterator<?> itor = root.elementIterator();
|
String elementTaskName = "";
|
while (itor.hasNext()) {
|
Element e = (Element) itor.next();
|
if (e.getName().trim().toLowerCase().equals("end")) {
|
elementTaskName = e.attributeValue("name");
|
if (endTaskName.equals(elementTaskName)) {
|
itorBreak = true;
|
break;
|
}
|
}
|
if (itorBreak) {
|
break;
|
}
|
}
|
} catch (Exception e1) {
|
// e1.printStackTrace();
|
ServerWithLog4j.logger.error("getEndNode", e1);
|
}
|
return itorBreak;
|
}
|
|
/**
|
* 获取当前任务的所有路由
|
*
|
* @param taskID 任务ID
|
* @return
|
*/
|
public String[] getAllOutComes(String taskID) {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
TaskService taskService = processEngine.getTaskService();
|
Task task = taskService.getTask(taskID);
|
String[] execIDs = task.getExecutionId().replace(".", ",").split(",");
|
String excutionid = "";
|
if (execIDs.length > 2) {
|
excutionid = execIDs[0] + "." + execIDs[1];
|
} else {
|
excutionid = task.getExecutionId();
|
}
|
|
int treatment = 0;
|
try {
|
Task parTask = taskService.createTaskQuery().processInstanceId(excutionid).uniqueResult();
|
if (parTask != null) {
|
taskID = parTask.getId();
|
|
String idJbpm = this.getDeploymentIdByExecutionId(excutionid);
|
List<TaskDescSObject> lstTaskDesc = getTaskDescList(parTask.getName(), idJbpm);
|
if (lstTaskDesc != null && lstTaskDesc.size() > 0) {
|
treatment = lstTaskDesc.get(0).getPltreatment();
|
}
|
}
|
} catch (Throwable e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("getAllOutComes", e);
|
}
|
|
String[] outcomeArr;
|
if (treatment == 1) {
|
outcomeArr = new String[2];
|
outcomeArr[0] = "同意";
|
outcomeArr[1] = "不同意";
|
} else {
|
Set<String> outcomes = taskService.getOutcomes(taskID);
|
if (outcomes.contains(null)) {
|
outcomes.remove(null);
|
outcomes.add("");
|
}
|
outcomeArr = new String[outcomes.size()];
|
int i = 0;
|
for (Object o : outcomes) {
|
String outcome = (String) o;
|
outcomeArr[i] = outcome;
|
i++;
|
}
|
}
|
return outcomeArr;
|
}
|
|
/**
|
* 根据分页参数 返回 TasksAssigned 对象
|
* <p>
|
* Description:
|
* </p>
|
*
|
* @param queryParam 查询参数
|
* @return 查询结果对象
|
* @throws VCIError
|
*/
|
@SuppressWarnings("unchecked")
|
public QueryResult<TasksAssigned> getTasksAssignedByPageing(final QueryParam queryParam) {
|
return (QueryResult<TasksAssigned>) new HibernateTemplate().run(new HibernateCallback() {
|
public Object execute() throws HibernateException {
|
QueryResult<TasksAssigned> res = new QueryResult<TasksAssigned>();
|
TasksAssignedDaoImpl impl = new TasksAssignedDaoImpl();
|
List<Object> list = impl.createCriteria().setProjection(Projections.rowCount())
|
.add(Restrictions.sqlRestriction(queryParam.getCustomQueryString())).list();
|
int total = 0;
|
if (list.size() > 0 && list.get(0) instanceof Long) {
|
total = ((Long) list.get(0)).intValue();
|
}
|
res.setTotal(total);
|
res.setDatas((impl.findList((int) queryParam.getPageIndex(), (int) queryParam.getPageSize())
|
.toArray(new TasksAssigned[] {})));
|
return res;
|
}
|
});
|
}
|
|
/**
|
* 出差设置
|
*
|
* @param userName
|
* @return
|
*/
|
public TasksAssigned getTasksAssignedByUserName(String userName) {
|
TasksAssigned ta = new TasksAssigned();
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
String sql = "";
|
if (userName == "") {
|
sql = "select * from PLTASKSASSIGNED where PLFROMUSER = '" + userEntity.getUserName() + "'";
|
} else {
|
Date date = new Date(System.currentTimeMillis());
|
String now = df.format(date);
|
sql = "select * from PLTASKSASSIGNED where PLFROMUSER = '" + userName + "' AND TO_DATE('" + now
|
+ "','yyyy-mm-dd') >= TO_DATE(PLSTARTTIME,'yyyy-mm-dd') AND TO_DATE('" + now
|
+ "','yyyy-mm-dd') <= TO_DATE(PLENDTIME,'yyyy-mm-dd') AND PLISTRUE = 1";
|
}
|
Session session = HibernateSessionFactory.getSession();
|
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
|
String id = "";
|
String tasksName = "";
|
String startTime = "";
|
String endTime = "";
|
String fromUser = "";
|
BigDecimal isTrue = null;
|
List<?> list = createSQLQuery.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] obj = (Object[]) list.get(i);
|
id = String.valueOf(obj[0]);
|
userName = (String) obj[1];
|
tasksName = (String) obj[3];
|
isTrue = (BigDecimal) obj[5];
|
startTime = (String) obj[7];
|
endTime = (String) obj[8];
|
fromUser = (String) obj[6];
|
}
|
ta.setId(id);
|
ta.setUserName(userName);
|
ta.setTasksName(tasksName);
|
ta.setIsTrue((isTrue == null ? false : isTrue.intValue() != 0));
|
ta.setStartTime(df.parse(startTime));
|
ta.setEndTime(df.parse(endTime));
|
ta.setFromUser(fromUser);
|
} catch (Exception e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("getTasksAssignedByUserName", e);
|
}
|
return ta;
|
}
|
|
public TasksAssigned[] getAllTasksAssignedByUserName(String userName) {
|
List<TasksAssigned> lstTA = new ArrayList<TasksAssigned>();
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
|
String sql = "";
|
if (userName == "") {
|
sql = "select * from PLTASKSASSIGNED where PLFROMUSER = '" + userEntity.getUserName() + "'";
|
} else {
|
Date date = new Date(System.currentTimeMillis());
|
String now = df.format(date);
|
sql = "select * from PLTASKSASSIGNED where PLFROMUSER = '" + userName + "'";
|
}
|
Session session = HibernateSessionFactory.getSession();
|
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
createSQLQuery.executeUpdate();
|
|
String id = "";
|
String tasksName = "";
|
String startTime = "";
|
String endTime = "";
|
String fromUser = "";
|
BigDecimal isTrue = null;
|
List<?> list = createSQLQuery.list();
|
|
for (int i = 0; i < list.size(); i++) {
|
Object[] obj = (Object[]) list.get(i);
|
id = String.valueOf(obj[0]);
|
userName = (String) obj[1];
|
tasksName = (String) obj[3];
|
isTrue = (BigDecimal) obj[5];
|
startTime = (String) obj[7];
|
endTime = (String) obj[8];
|
fromUser = (String) obj[6];
|
|
TasksAssigned ta = new TasksAssigned();
|
|
ta.setId(id);
|
ta.setUserName(userName);
|
ta.setTasksName(tasksName);
|
ta.setIsTrue(isTrue == null ? false : isTrue.intValue() != 0);
|
ta.setStartTime(df.parse(startTime));
|
ta.setEndTime(df.parse(endTime));
|
ta.setFromUser(fromUser);
|
|
lstTA.add(ta);
|
}
|
|
} catch (Exception e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("getAllTasksAssignedByUserName", e);
|
}
|
return lstTA.toArray(new TasksAssigned[0]);
|
}
|
|
public boolean saveOrUpdateTasksAssigned(final TasksAssigned tasksAssigned) {
|
return (Boolean) new HibernateTemplate().run(new HibernateCallback() {
|
public Object execute() throws HibernateException {
|
boolean b = false;
|
int count = 0;
|
Session session = HibernateSessionFactory.getSession();
|
// String sql = "DELETE FROM PLTASKSASSIGNED WHERE PLUSERNAME = '"
|
// + tasksAssigned.getUserName() + "'";
|
|
String sql = "UPDATE PLTASKSASSIGNED SET PLISTRUE = 0, PLREVOKETIME=systimestamp WHERE PLUSERNAME = '"
|
+ tasksAssigned.getUserName() + "' AND PLISTRUE <> 0";
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sql);
|
createSQLQuery.executeUpdate();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
TasksAssignedDaoImpl impl = new TasksAssignedDaoImpl();
|
impl.saveOrUpdate(tasksAssigned);
|
return true;
|
}
|
});
|
}
|
|
public void saveSubProcess(SubprocessTemInfo[] subprocessTemInfos) {
|
Session session = HibernateSessionFactory.getSession();
|
|
for (SubprocessTemInfo info : subprocessTemInfos) {
|
String id = ObjectUtility.getNewObjectID36();
|
String sql = "insert into JBPM_SUBPROCESSTEM (id, partenttem, subprocesstem) values ('" + id + "','"
|
+ info.parentTemName + "', '" + info.subProcessName + "')";
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
createSQLQuery.executeUpdate();
|
} catch (Exception e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("saveSubProcess", e);
|
}
|
}
|
}
|
|
public int checkSubprocessQuote(String subProcess) {
|
Session session = HibernateSessionFactory.getSession();
|
int count = 0;
|
String sql = "select count(*) from JBPM_SUBPROCESSTEM where subprocesstem = ?";
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
createSQLQuery.setString(0, subProcess);
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
|
List<?> list = createSQLQuery.list();
|
if (list != null && list.size() > 0) {
|
count = Integer.parseInt(String.valueOf(list.get(0)));
|
}
|
} catch (Exception e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("checkSubprocessQuote", e);
|
}
|
return count;
|
|
}
|
|
/**
|
* 配置任务和用户信息
|
*
|
* @param processEngine
|
* @param deploymentId
|
* @param processInstansId
|
* @param dataIds
|
* @param taskAndUserMap
|
* @throws Exception
|
*/
|
private void configTaskAndUser(ProcessEngine processEngine, String deploymentId, String processInstansId,
|
String[] dataIds, Map<String, String[]> taskAndUserMap) throws Exception {
|
|
Iterator<Entry<String, String[]>> ite = taskAndUserMap.entrySet().iterator();
|
|
while (ite.hasNext()) {
|
Map.Entry<String, String[]> entry = (Entry<String, String[]>) ite.next();
|
String taskName = entry.getKey();// map中的key
|
String[] users = entry.getValue();// 上面key对应的value
|
String user = "";
|
if (users != null && users.length > 0) {
|
user = Arrays.toString(users);
|
user = user.substring(1, user.length() - 1);
|
}
|
|
// for (String dataId : dataIds) {
|
String id = ObjectUtility.getNewObjectID36();
|
String sql = "insert into JBPM4_TASKANDUSERCONFIGEX (id, deploymentid, dataid, taskname, username,PROCESSINSTANSID) values ('"
|
+ id + "','" + deploymentId + "', '" + ""
|
// + dataId
|
+ "', '" + taskName + "','" + user + "','" + processInstansId + "')";
|
HibernateSessionFactory.getSession().createSQLQuery(sql).executeUpdate();
|
// }
|
}
|
}
|
|
/**
|
* 执行时,给其他任务设置候选人
|
*
|
* @param processInstansId
|
* @param taskAndUserMap
|
*/
|
public void setTaskAndUserForComplete(String processInstansId, Map<String, String[]> taskAndUserMap) {
|
|
Iterator<Entry<String, String[]>> ite = taskAndUserMap.entrySet().iterator();
|
|
while (ite.hasNext()) {
|
Map.Entry<String, String[]> entry = (Entry<String, String[]>) ite.next();
|
String taskName = entry.getKey();// map中的key
|
String[] users = entry.getValue();// 上面key对应的value
|
String user = Arrays.toString(users);
|
user = user.substring(1, user.length() - 1);
|
String sql = "update jbpm4_taskanduserconfigex set username = '" + user + "' where processinstansid = '"
|
+ processInstansId + "' and taskname = '" + taskName + "'";
|
|
HibernateSessionFactory.getSession().createSQLQuery(sql).executeUpdate();
|
}
|
}
|
|
/**
|
* 通过流程模板、流程数据ID、流程任务名称,获取该流程任务的用户。
|
*
|
* @param processDefinitionKey
|
* @param dataId
|
* @param taskName
|
* @return
|
*/
|
public String[] userList(String deploymentId, String[] dataIds, String taskName) {
|
String[] users = null;
|
Session session = HibernateSessionFactory.getSession();
|
String dataId = "";
|
for (String s : dataIds) {
|
dataId += "'" + s + "',";
|
}
|
dataId = dataId.substring(0, dataId.length() - 1);
|
String sql = "select a.username from TASKANDUSERCONFIG a where a.DEPLOYMENTID = ? and a.dataid in (" + dataId
|
+ ") and a.taskname = ?";
|
String userName = null;
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
createSQLQuery.setString(0, deploymentId);
|
createSQLQuery.setString(1, taskName);
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List<?> list = createSQLQuery.list();
|
if (list != null && list.size() > 0) {
|
userName = String.valueOf(list.get(0));
|
}
|
if (userName == null) {
|
return null;
|
}
|
users = userName.split(",");
|
} catch (Exception e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("userList", e);
|
}
|
return users;
|
}
|
|
/**
|
* 获取全局变量
|
*
|
* @param jbpmDeploymentId
|
* @return
|
* @throws Exception
|
*/
|
private List<PropertyInfo> getGlobalParam(String jbpmDeploymentId) throws Exception {
|
List<PropertyInfo> processTypeProperties = new ArrayList<PropertyInfo>();
|
byte[] jpdlXml = getProcessResource(jbpmDeploymentId, ".xml");
|
ByteArrayInputStream bais = new ByteArrayInputStream(jpdlXml);
|
BufferedReader reader = new BufferedReader(new InputStreamReader(bais, "utf-8"));
|
SAXReader saxReader = new SAXReader();
|
Document doc = saxReader.read(reader);
|
Element root = doc.getRootElement();
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element next = (Element) a.next();
|
String cellType = next.getName();
|
if (cellType.equals(FlowConstants.GLOBAL)) {
|
for (Iterator<?> b = next.elementIterator(); b.hasNext();) {
|
Element fieldElement = (Element) b.next();// 多个field element
|
if (fieldElement.getName().equals(FlowConstants.EVENT_FIELD)) {
|
PropertyInfo propertyInfo = new PropertyInfo();
|
propertyInfo.property = fieldElement.attributeValue(FlowConstants.XMLNAME);
|
for (Iterator<?> c = fieldElement.elementIterator(); c.hasNext();) {
|
Element stringElement = (Element) c.next();
|
if (stringElement.getName().equals(FlowConstants.EVENT_STRING)) {
|
propertyInfo.value = stringElement.attributeValue(FlowConstants.EVENT_VALUE);
|
}
|
}
|
processTypeProperties.add(propertyInfo);
|
}
|
}
|
}
|
}
|
return processTypeProperties;
|
}
|
|
/**
|
* 读取下个任务的用户
|
*
|
* @param excutionId
|
* @param taskName
|
* @return
|
*/
|
public String[] nextTaskCandidateUsers(String excutionId, String taskName) {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
EnvironmentImpl envImpl = ((EnvironmentFactory) processEngine).openEnvironment();
|
Execution processInstance = processEngine.getExecutionService().findExecutionById(excutionId)
|
.getProcessInstance();
|
String proccessInstanceId = processInstance.getId();
|
ExecutionImpl execution = (ExecutionImpl) processEngine.getExecutionService()
|
.findProcessInstanceById(proccessInstanceId);
|
ActivityImpl activity = execution.getActivity();
|
ProcessDefinitionImpl processDefinitionImpl = activity.getProcessDefinition();
|
List<? extends Activity> activities = processDefinitionImpl.getActivities();
|
String[] users = null;
|
for (Activity a : activities) {
|
ActivityImpl at = (ActivityImpl) a;
|
ActivityBehaviour activityBehaviour = at.getActivityBehaviour();
|
if (activityBehaviour instanceof TaskActivity) {
|
TaskActivity ta = (TaskActivity) activityBehaviour;
|
TaskDefinitionImpl taskDefinition = ta.getTaskDefinition();
|
if (taskName.equals(taskDefinition.getName())) {
|
String assigneeExpression = taskDefinition.getAssigneeExpression();
|
String candidateUsersExpression = taskDefinition.getCandidateUsersExpression();
|
if (assigneeExpression != null && !"".equals(assigneeExpression)) {
|
users = new String[1];
|
users[0] = assigneeExpression;
|
} else if (candidateUsersExpression != null && !"".equals(candidateUsersExpression)) {
|
String[] sp = candidateUsersExpression.split(",");
|
users = new String[sp.length];
|
for (int i = 0; i < sp.length; i++) {
|
users[i] = sp[i];
|
}
|
}
|
}
|
}
|
}
|
if (users == null) {
|
return new String[0];
|
} else {
|
return users;
|
}
|
}
|
|
/**
|
* 获取任务的候选人
|
*
|
* @param executionId
|
* @param taskName
|
* @return
|
*/
|
public String getNextTaskAssigner(String executionId, String taskName) {
|
String userName = "";
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
String processInstansId = processEngine.getExecutionService().findExecutionById(executionId)
|
.getProcessInstance().getId();
|
Session session = HibernateSessionFactory.getSession();
|
String sql = "select t.username from JBPM4_TASKANDUSERCONFIGEX t where t.taskname='" + taskName
|
+ "' and t.PROCESSINSTANSID='" + processInstansId + "'";
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sql);
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List<?> list = createSQLQuery.list();
|
if (list != null && list.size() > 0) {
|
if (list.get(0) != null) {
|
userName = String.valueOf(list.get(0));
|
} else {
|
userName = null;
|
}
|
}
|
if (userName == null) {
|
return "";
|
}
|
} catch (Exception e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("getNextTaskAssigner", e);
|
}
|
return userName;
|
}
|
|
/**
|
* 根据部署ID返回流程模板对象
|
* <p>
|
* Description:
|
* </p>
|
*
|
* @author xchao
|
* @time 2012-9-25
|
* @param deployId
|
* @return
|
*/
|
public ProcessDefinitionInfo getProcessDefinitionByDeployId(final String deployId) {
|
LinkedHashMap<String, String> valuesMaps = new LinkedHashMap<String, String>();
|
valuesMaps.put("PLJBPMDEPLOYMENTID", deployId);
|
return getProcessDefinitionInfoByCustomFilter(valuesMaps).get(0);
|
}
|
|
/**
|
* 编码资源专用
|
*
|
* @param processCategoryId
|
* @return
|
*/
|
public List<ProcessDefinitionInfo> getProcessDefinitionsForRMCode(final String processCategoryId) {
|
LinkedHashMap<String, String> valuesMaps = new LinkedHashMap<String, String>();
|
valuesMaps.put("PLCATEGORYOID", processCategoryId);
|
return getProcessDefinitionInfoByCustomFilter(valuesMaps);
|
}
|
|
public List<ProcessDefinitionInfo> getProcessDefinitionsByPage(final String processCategoryId, final String name,
|
int pageSize, int pageIndex) {
|
LinkedHashMap<String, String> valuesMaps = new LinkedHashMap<String, String>();
|
// valuesMaps.put("PLCATEGORYOID", processCategoryId);
|
valuesMaps.put("OBJNAME_", name);
|
return getProcessDefinitionInfoByCustomFilterByPage(valuesMaps, processCategoryId, pageSize, pageIndex);
|
}
|
|
/**
|
* 根据名称查询
|
*
|
* @param name
|
* @return
|
*/
|
public List<ProcessDefinitionInfo> getProcessDefinitionByProcessDefinitionName(final String name,
|
String processCategoryId) {
|
LinkedHashMap<String, String> valuesMaps = new LinkedHashMap<String, String>();
|
valuesMaps.put("OBJNAME_", name);
|
return getProcessDefinitionInfoByName(valuesMaps, processCategoryId);
|
}
|
|
/**
|
* 根据名称查询
|
*
|
* @param values
|
* @return
|
*/
|
private List<ProcessDefinitionInfo> getProcessDefinitionInfoByName(LinkedHashMap<String, String> values,
|
String processCategoryId) {
|
Map<String, ProcessDefinitionInfo> pds = new HashMap<String, ProcessDefinitionInfo>();
|
List<String> deployIds = new ArrayList<String>();
|
StringBuilder sql = new StringBuilder();
|
sql.append("SELECT d.DEPLOYMENT_, d.OBJNAME_, d.KEY_, d.STRINGVAL_, d.LONGVAL_,p.PLCATEGORYOID,plstatus");
|
sql.append(" FROM JBPM4_DEPLOYPROP d left join PLPROCESSTEMPLATE p on d.DEPLOYMENT_=p.PLJBPMDEPLOYMENTID");
|
// new
|
sql.append(" where d.KEY_ <> 'langid' ");
|
Iterator<String> its = values.keySet().iterator();
|
while (its.hasNext()) {
|
String key = its.next();
|
String value = values.get(key);
|
if (!"".equals(value)) {
|
sql.append(" and d." + key + " like ? ");
|
}
|
}
|
|
if (!processCategoryId.equals("")) {// add by liujw
|
sql.append(" and p.PLCATEGORYOID" + " = '" + processCategoryId + "' ");
|
}
|
|
sql.append(" order by d.OBJNAME_, d.DEPLOYMENT_, d.KEY_");
|
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
// new
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
|
its = values.keySet().iterator();
|
int index = 0;
|
while (its.hasNext()) {
|
String key = its.next();
|
String value = values.get(key);
|
if (!"".equals(value)) {
|
createSQLQuery.setString(index++, "%" + value + "%");
|
}
|
}
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List<?> list = createSQLQuery.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] obj = (Object[]) list.get(i);
|
String deployId = String.valueOf(obj[0]) + "";
|
String name = (String) obj[1];
|
String key = (String) obj[2];
|
String stringValue = (String) obj[3];
|
String longValue = String.valueOf(obj[4]);
|
String categroyId = (String) obj[5];
|
String status = String.valueOf(obj[6]) + ""; // add by liujw
|
ProcessDefinitionInfo processDefinitionInfo = pds.get(deployId);
|
if (processDefinitionInfo == null) {
|
processDefinitionInfo = new ProcessDefinitionInfo();
|
processDefinitionInfo.jbpmDeploymentId = deployId;
|
processDefinitionInfo.name = name == null ? "" : name;
|
processDefinitionInfo.categroyId = categroyId;
|
processDefinitionInfo.status = status; // add by liujw
|
pds.put(deployId, processDefinitionInfo);
|
}
|
if (key.equals("pdid")) {
|
processDefinitionInfo.id = stringValue == null ? "" : stringValue;
|
} else if (key.equals("pdkey")) {
|
processDefinitionInfo.key = stringValue == null ? "" : stringValue;
|
} else if (key.equals("pdversion")) {
|
processDefinitionInfo.version = Integer.parseInt(longValue);
|
}
|
|
if (!deployIds.contains(deployId)) {
|
deployIds.add(deployId);
|
}
|
}
|
} catch (Exception ex) {
|
// ex.printStackTrace();
|
ServerWithLog4j.logger.error("getProcessDefinitionInfoByName", ex);
|
} finally {
|
|
}
|
|
List<ProcessDefinitionInfo> result = new ArrayList<ProcessDefinitionInfo>();
|
for (String deployId : deployIds) {
|
result.add(pds.get(deployId));
|
}
|
return result;
|
}
|
|
/**
|
* 获取任务对应的自定义类
|
*
|
* @param jbpmDeploymentId 部署ID
|
* @param taskName 任务名称
|
* @param eventType 事件类型:初始事件(start)、结束事件(end)
|
* @return
|
* @throws Exception
|
*/
|
public String getCustomClass(String executionId, String taskName, String eventType) throws Exception {
|
String jbpmDeploymentId = getDeploymentIdByExecutionId(executionId);
|
byte[] processXml = getProcessResource(jbpmDeploymentId, ".xml");
|
InputStream in = new ByteArrayInputStream(processXml);
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
|
|
SAXReader saxr = new SAXReader();
|
Document doc = saxr.read(reader);
|
Element root = doc.getRootElement();
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
String cellType = element.getName();
|
if (FlowConstants.XMLTASK.equals(cellType)) {
|
Attribute attribute = element.attribute(FlowConstants.XMLNAME);
|
String name = attribute.getValue();
|
if (name.equals(taskName)) {
|
Element elementON = element.element(FlowConstants.EVENT_ON);
|
Attribute onAttr = elementON.attribute(FlowConstants.EVENT);
|
String onValue = onAttr.getValue();
|
if (onValue.equals(eventType)) {
|
for (Iterator<?> b = elementON.elementIterator(); b.hasNext();) {
|
Element elementCustomClass = (Element) b.next();
|
String cellType2 = elementCustomClass.getName();
|
Attribute customClass = elementCustomClass.attribute(FlowConstants.CUSTOMUSERCLASS);
|
String value = customClass.getValue();
|
return value;
|
}
|
}
|
}
|
}
|
}
|
return "";
|
}
|
|
/**
|
* 转交任务 将当前任务转交给其他人处理
|
*
|
* @param fromUser
|
* @param toUserName
|
* @return
|
*/
|
public boolean assignTask(String fromUser, String toUserName) {
|
boolean flag = false;
|
try {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
TaskService taskService = processEngine.getTaskService();
|
FlowTaskInfo[] info = getTodoTaskByUserIdForAssignTask(fromUser);
|
String[] userName = toUserName.split(",");
|
for (int i = 0; i < info.length; i++) {
|
String taskId = info[i].id;
|
taskService.assignTask(taskId, null);
|
for (int j = 0; j < userName.length; j++) {
|
taskService.addTaskParticipatingUser(taskId, userName[j], Participation.CANDIDATE);
|
}
|
}
|
flag = true;
|
} catch (Exception e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("assignTask", e);
|
flag = false;
|
}
|
return flag;
|
}
|
|
public boolean assignTaskByPlatform(String fromUser, String toUserName) {
|
boolean flag = false;
|
Session session = HibernateSessionFactory.getSession();
|
String execution_ = "";
|
String priority_ = "";
|
String v_assignee_ = "";
|
String v_activity_name_ = "";
|
Timestamp v_create_ = new Timestamp(0);
|
// String v_end_ = "";
|
BigDecimal procinst_ = new BigDecimal(0);
|
Date date = new Date();
|
long time = date.getTime();
|
Timestamp v_end_ = new Timestamp(time);
|
try {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
TaskService taskService = processEngine.getTaskService();
|
FlowTaskInfo[] info = getTodoTaskByUserIdForAssignTask(fromUser);
|
String[] userName = toUserName.split(",");
|
for (int i = 0; i < info.length; i++) {
|
String taskId = info[i].id;
|
taskService.assignTask(taskId, null);
|
for (int j = 0; j < userName.length; j++) {
|
taskService.addTaskParticipatingUser(taskId, userName[j], Participation.CANDIDATE);
|
|
updataForAssign(fromUser, userName, taskId, j);
|
}
|
|
updataWorkitemForComplete(fromUser, taskId);
|
|
// session.beginTransaction();
|
String oid = ObjectUtility.getNewObjectID36();
|
|
saveTaskHist(taskId, toUserName, processEngine, fromUser, session, oid, execution_, v_activity_name_,
|
v_create_, procinst_, time, v_end_, true);
|
}
|
|
flag = true;
|
} catch (Exception e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("assignTaskByPlatform", e);
|
flag = false;
|
}
|
return flag;
|
}
|
|
private void updataWorkitemForComplete(String fromUser, String taskId)
|
throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException,
|
IllegalAccessException, InvocationTargetException, InstantiationException, VCIError {
|
if (workitemClass != null && !"".equals(workitemClass)) {
|
// PLMWorkItemInterface pwService = (PLMWorkItemInterface)
|
// (Class.forName(workitemClass).newInstance());
|
if (_pwiService != null) {
|
_pwiService.updataWorkitemForComplete(fromUser, taskId);
|
}
|
|
// Class<?> c = Class.forName(workitemClass);
|
// Method m = c.getDeclaredMethod("updataWorkitemForComplete", new Class[]{String.class,String.class});
|
// m.invoke(c.newInstance(), new Object[]{fromUser,taskId});
|
}
|
}
|
|
private void updataForAssign(String fromUser, String[] userName, String taskId, int j)
|
throws VCIError, ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException,
|
IllegalAccessException, InvocationTargetException, InstantiationException {
|
if (workitemClass != null && !"".equals(workitemClass)) {
|
// PLMWorkItemInterface pwService = (PLMWorkItemInterface)
|
// (Class.forName(workitemClass).newInstance());
|
if (_pwiService != null) {
|
_pwiService.updataForAssign(fromUser, userName, taskId, j);
|
}
|
|
// Class<?> c = Class.forName(workitemClass);
|
// Method m = c.getDeclaredMethod("updataForAssign", new Class[]{String.class,String[].class,String.class,int.class});
|
// m.invoke(c.newInstance(), new Object[]{fromUser,userName,taskId,j});
|
}
|
}
|
|
/**
|
*
|
* 任务转发(将某用户全部的(待办)任务转发给同一个人
|
*
|
* @param toUserName 任务新的处理人,格式:user:xxxx,xxx就已新责任人
|
* @return
|
* @throws VCIError
|
*/
|
public boolean transmitTaskForAll(String toUserName) throws VCIError {
|
return transmitTaskAllByFromUserName(getUserEntity().getUserName(), toUserName);
|
}
|
|
/**
|
*
|
* 任务转发(将某用户全部的(待办)任务转发给同一个人
|
*
|
* @param fromUserName 要转发的责任人,格式:xxx,xxx就是任务当前的责任人
|
* @param toUserName 任务新的处理人,格式:user:xxxx,xxx就已新责任人
|
* @return
|
* @throws VCIError
|
*/
|
public boolean transmitTaskAllByFromUserName(String fromUserName, String toUserName) throws VCIError {
|
// 先移除
|
toUserName = toUserName.replace("user:", "");
|
// 只接收一个新责任人
|
if (toUserName.indexOf(",") >= 0) {
|
toUserName = toUserName.split(",")[0];
|
}
|
if (!toUserName.startsWith("user:")) {
|
toUserName = "user:" + toUserName;
|
}
|
// 最终的新责任人 : user:xxxx
|
boolean res = true;
|
// 查出fromUserName全部执行中的任务
|
// 查出全部执行中的任务
|
List<String> allTaskIdList = getAllExecutingTaskIds(fromUserName);
|
for (String taskid : allTaskIdList) {
|
res = res && transmitTask(taskid, toUserName);
|
}
|
return res;
|
}
|
|
private List<String> getAllExecutingTaskIds(String fromUserName) throws VCIError {
|
List<String> allTaskIds = new ArrayList<String>();
|
QueryTemplate qt = new QueryTemplate();
|
List<String> list = new ArrayList();
|
list.add("*");
|
qt.setBtmType("WorkItem".toLowerCase());
|
qt.setClauseList(list);
|
qt.setId("p");
|
qt.setType("btm");
|
qt.setRightFlag(false);
|
Map map = new HashMap();
|
map.put("BusinessType".toLowerCase(), "5");
|
map.put("lcstatus".toLowerCase(), "Executing");
|
map.put("Principal".toLowerCase(), fromUserName);
|
Condition condition = OQueryHelper.getCondition(map);
|
qt.setCondition(condition);
|
|
BusinessObject bos[] = ServerServiceProvider.getOQService().findBTMObjects(qt.getId(),
|
OQueryHelper.getQTTextByQT(qt));
|
|
// BusinessObject findBTMObjects[] = QtServiceDelegate.getInstance().findBTMObjects(qt.getId(),
|
// Tool.qtTOXMl(qt).asXML());
|
// BOFactoryServerDelegate boDelegate = BOFactoryServerDelegate.getInstance();
|
for (BusinessObject businessObject : bos) {
|
String taskId = ObjectTool.getBOAttributeValue(businessObject, "TaskOID".toLowerCase());
|
allTaskIds.add(taskId);
|
}
|
return allTaskIds;
|
}
|
|
/**
|
* 任务转发
|
*
|
* @param taskid
|
* @param toUserName
|
* @return
|
*/
|
public boolean transmitTask(String taskid, String toUserName) {
|
/************************************************************
|
* add by xhcao 2018.01.19 begin 转移责任人执行逻辑说明: 0、转移是基于指定任务的转移,
|
* 如果是需要对全部任务进行转移(全部任务都转移同一个人的场景),则需要从后台查出用户全部(执行中)的任务,再依次对这些任务执行转移
|
*
|
* 1、将指定任务指定责任人进行更新,具体包含: a、同步完成对JBPM4的JBPM4_PARTICIPATION表进行更新
|
* b、将WORKITEM中指定任务、指定责任人(Principal)修改为新的责任人
|
*
|
* 2、转移责任人时,不需改更新 流程启动时对每个流程节点设置的责任人
|
*
|
* 3、转移责任人只对指定任务有影响(产生效应),不对其他任务或节点有影响
|
*
|
* add by xhcao 2018.01.19 end
|
***********************************************************/
|
boolean flag = false;
|
StringBuffer sb = new StringBuffer();
|
try {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
TaskService taskService = processEngine.getTaskService();
|
String fromUser = getUserEntity().getUserName();
|
taskService.removeTaskParticipatingUser(taskid, fromUser, Participation.CANDIDATE);
|
// toUserName 格式: user:xxx
|
String newUserName = "";
|
String[] userName = toUserName.split(",");
|
for (int j = 0; j < userName.length; j++) {
|
// update by xchao 2018.01.19 begin
|
// 不需要调用此接口
|
// OLD
|
// taskService.assignTask(taskid, userName[j]);
|
// NEW
|
// update by xchao 2018.01.19 end
|
String[] userNames = userName[j].split(":");
|
if (userNames.length >= 2) {
|
if (j == userName.length - 1) {
|
sb.append(userNames[1]);
|
} else {
|
sb.append(userNames[1] + ",");
|
}
|
newUserName = userNames[1];
|
// add by xchao 2018.01.19 begin
|
// 将新责任人关联到JBPM4的Participation(JBPM4_PARTICIPATION)
|
taskService.addTaskParticipatingUser(taskid, newUserName, Participation.CANDIDATE);
|
// add by xchao 2018.01.19 ene
|
}
|
}
|
|
Session session = HibernateSessionFactory.getSession();
|
// session.beginTransaction();
|
String oid = ObjectUtility.getNewObjectID36();
|
String execution_ = "";
|
String priority_ = "";
|
String v_assignee_ = "";
|
String v_activity_name_ = "";
|
Timestamp v_create_ = new Timestamp(0);
|
// String v_end_ = "";
|
BigDecimal procinst_ = new BigDecimal(0);
|
Date date = new Date();
|
long time = date.getTime();
|
Timestamp v_end_ = new Timestamp(time);
|
|
saveTaskHist(taskid, toUserName, processEngine, fromUser, session, oid, execution_, v_activity_name_,
|
v_create_, procinst_, time, v_end_, false);
|
|
String principal = sb.toString();
|
|
if (workitemClass != null && !"".equals(workitemClass)) {
|
// PLMWorkItemInterface pwService = (PLMWorkItemInterface)
|
// (Class.forName(workitemClass).newInstance());
|
// update by xchao 2018.01.18 begin
|
// OLD
|
// pwService.updateWorkItemPrincipal(taskid, principal);
|
// NEW
|
// 使用新接口,完成“转移责任人”(仅完成对执行中的指定任务、指定责任人进行转移)
|
if (_pwiService != null) {
|
_pwiService.updateExecutingWorkItemPrincipalToNewUserName(taskid, fromUser, newUserName);
|
}
|
// update by xchao 2018.01.18 end
|
}
|
|
flag = true;
|
} catch (Exception e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("transmitTask", e);
|
flag = false;
|
}
|
return flag;
|
}
|
|
/**
|
* 平台专用。任务转发
|
*
|
* @param taskid 任务id
|
* @param toUserName 转发到的用户名称
|
* @return
|
*/
|
public boolean transmitTaskByPlatform(String taskid, String toUserName) {
|
boolean flag = false;
|
try {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
TaskService taskService = processEngine.getTaskService();
|
String fromUser = getUserEntity().getUserName();
|
taskService.removeTaskParticipatingUser(taskid, fromUser, Participation.CANDIDATE);
|
String[] userName = toUserName.split(",");
|
// 设置用户和任务列表
|
for (int j = 0; j < userName.length; j++) {
|
Task task = taskService.getTask(taskid);
|
String sql = "update jbpm4_taskanduserconfigex set username = '" + userName[j]
|
+ "' where processinstansid = '" + task.getExecutionId() + "' and taskname = '"
|
+ task.getActivityName() + "'";
|
HibernateSessionFactory.getSession().createSQLQuery(sql).executeUpdate();
|
}
|
String userServiceImplClass = WorkflowProperties.getStringProperty("workflow.userService");
|
// 解析传入的用户
|
String[] cUserName = userName;
|
if (userServiceImplClass != null && !"".equals(userServiceImplClass)) {
|
IWorkflowUserService puService = (IWorkflowUserService) (Class.forName(userServiceImplClass)
|
.newInstance());
|
cUserName = puService.getAllUsers2Task(cUserName, getUserEntity().getModule());
|
}
|
transmitTaskByPlm(taskid, fromUser, cUserName);
|
|
Session session = HibernateSessionFactory.getSession();
|
// session.beginTransaction();
|
String oid = ObjectUtility.getNewObjectID36();
|
String execution_ = "";
|
String priority_ = "";
|
String v_assignee_ = "";
|
String v_activity_name_ = "";
|
Timestamp v_create_ = new Timestamp(0);
|
// String v_end_ = "";
|
BigDecimal procinst_ = new BigDecimal(0);
|
Date date = new Date();
|
long time = date.getTime();
|
Timestamp v_end_ = new Timestamp(time);
|
|
for (int i = 0; i < userName.length; i++) {
|
saveTaskHist(taskid, userName[i], processEngine, fromUser, session, oid, execution_, v_activity_name_,
|
v_create_, procinst_, time, v_end_, false);
|
}
|
|
flag = true;
|
} catch (Exception e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("transmitTaskByPlatform", e);
|
flag = false;
|
}
|
return flag;
|
}
|
|
private void transmitTaskByPlm(String taskid, String fromUser, String[] userName)
|
throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException,
|
IllegalAccessException, InvocationTargetException, InstantiationException, VCIError {
|
if (workitemClass != null && !"".equals(workitemClass)) {
|
// PLMWorkItemInterface pwService = (PLMWorkItemInterface)
|
// (Class.forName(workitemClass).newInstance());
|
if (_pwiService != null)
|
_pwiService.transmitTaskByPlm(taskid, fromUser, userName);
|
|
// Class<?> c = Class.forName(workitemClass);
|
// Method m = c.getDeclaredMethod("transmitTaskByPlm", new Class[]{String.class,String.class,String[].class});
|
// m.invoke(c.newInstance(), new Object[]{fromUser,taskid,userName});
|
}
|
}
|
|
private void saveTaskHist(String taskid, String toUserName, ProcessEngine processEngine, String fromUser,
|
Session session, String oid, String execution_, String v_activity_name_, Timestamp v_create_,
|
BigDecimal procinst_, long time, Timestamp v_end_, boolean set_taskanduserconfigex) throws VciException {
|
String v_assignee_;
|
// 1.查询新的任务开始时间
|
StringBuilder sql = new StringBuilder();
|
sql.append(
|
"select assignee_, create_, execution_id_ , PROCINST_, ACTIVITY_NAME_ from jbpm4_task where dbid_ = '"
|
+ taskid + "'");
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List<?> list = createSQLQuery.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] object = (Object[]) list.get(i);
|
v_assignee_ = (String) object[0];
|
v_create_ = (Timestamp) object[1];
|
execution_ = (String) object[2];
|
procinst_ = (BigDecimal) object[3];
|
v_activity_name_ = (String) object[4];
|
}
|
|
session.flush();
|
|
// 2.先更新任务时间
|
// StringBuilder updataJbpm4Task = new StringBuilder();
|
// updataJbpm4Task.append("update jbpm4_task ");
|
// updataJbpm4Task.append(" set create_ = ? ");
|
// updataJbpm4Task.append(" where dbid_ = '" + taskid + "' ");
|
// SQLQuery updataJbpm4TaskCreate = session
|
// .createSQLQuery(updataJbpm4Task.toString());
|
// updataJbpm4TaskCreate.setTimestamp(0, v_end_);
|
// updataJbpm4TaskCreate.executeUpdate();
|
|
StringBuilder insertJbpm4HistTask = new StringBuilder();
|
insertJbpm4HistTask.append("insert into jbpm4_hist_task");
|
insertJbpm4HistTask.append(
|
" (dbid_, dbversion_, execution_, outcome_, assignee_, priority_, state_, create_,end_, duration_, nextidx_, supertask_) ");
|
insertJbpm4HistTask.append(" values ");
|
insertJbpm4HistTask.append(" (" + time + ", 1, '" + execution_ + "', 'jbpm_no_task_outcome_specified_jbpm', '"
|
+ fromUser + "', '0', 'completed', ?,?, '0', '1', '') ");
|
SQLQuery createSQLQuery2 = session.createSQLQuery(insertJbpm4HistTask.toString());
|
createSQLQuery2.setTimestamp(0, v_create_);
|
createSQLQuery2.setTimestamp(1, v_end_);
|
createSQLQuery2.executeUpdate();
|
// add by changmk--start 2016.7.13
|
// 格式化转发人和接收人
|
// RightManagementClientDelegate rmcd = new RightManagementClientDelegate();
|
// UserObject userObj = rmcd.fetchUserInfoByName(fromUser);
|
// DeptObject deptObj = rmcd.fetchDeptByUserId(userObj.getId());
|
//
|
// String formatFromUser = fromUser + "(" + userObj.getTrueName() + "|"
|
// + (deptObj == null ? "无部门信息" : deptObj.getName()) + ")";
|
//
|
// String formatToUser = "";
|
// String[] userName = toUserName.split(",");
|
// for (int j = 0; j < userName.length; j++) {
|
// String[] userNames = userName[j].split(":");
|
// String toUserId = userNames[1];
|
// UserObject toUserObj = rmcd.fetchUserInfoByName(toUserId);
|
// DeptObject toDeptObj = rmcd.fetchDeptByUserId(toUserObj.getId());
|
// if (j == 0) {
|
// formatToUser = toUserId + "(" + toUserObj.getTrueName() + "|"
|
// + (toDeptObj == null ? "无部门信息" : toDeptObj.getName()) + ")";
|
// } else {
|
// String oneUser = toUserId + "(" + toUserObj.getTrueName() + "|"
|
// + (toDeptObj == null ? "无部门信息" : toDeptObj.getName()) + ")";
|
// formatToUser += "和" + oneUser;
|
// }
|
// }
|
|
// String toUserId = toUserName.substring(toUserName.indexOf(":") + 1);
|
// UserObject toUserObj = rmcd.fetchUserInfoByName(toUserId);
|
// DeptObject toDeptObj = rmcd.fetchDeptByUserId(toUserObj.getId());
|
// String formatToUser = toUserId + "(" + toUserObj.getTrueName() + "|" + (toDeptObj == null ? "无部门信息":toDeptObj.getName()) + ")";
|
// add by changmk--end 2016.7.13
|
StringBuilder insertPlflowapproveopinion = new StringBuilder();
|
insertPlflowapproveopinion.append("insert into plflowapproveopinion");
|
insertPlflowapproveopinion.append(" (ploid, pltaskid, plapproveopinion, plapprovenote, plassgin) ");
|
insertPlflowapproveopinion.append(" values ");
|
insertPlflowapproveopinion.append(" ('" + oid + "', '" + time + "', '转发', '由" + fromUser + "转发给" + toUserName
|
+ "', '" + fromUser + "') ");
|
session.createSQLQuery(insertPlflowapproveopinion.toString()).executeUpdate();
|
// session.getTransaction().commit();
|
|
// session.beginTransaction();
|
StringBuilder insertJbpm4HistActinst = new StringBuilder();
|
insertJbpm4HistActinst.append("insert into jbpm4_hist_actinst");
|
insertJbpm4HistActinst.append(
|
" (dbid_, class_, dbversion_, hproci_, type_, execution_, start_,end_, duration_, transition_, nextidx_, htask_,ACTIVITY_NAME_) ");
|
insertJbpm4HistActinst.append(" values ");
|
insertJbpm4HistActinst.append(" (" + time + ", 'task', '0', " + procinst_ + ", 'task', '" + execution_
|
+ "', ?,?, '0', 'jbpm_no_task_outcome_specified_jbpm', '1', " + time + ",?) ");
|
SQLQuery createSQLQuery3 = session.createSQLQuery(insertJbpm4HistActinst.toString());
|
createSQLQuery3.setTimestamp(0, v_create_);
|
createSQLQuery3.setTimestamp(1, v_end_);
|
createSQLQuery3.setString(2, v_activity_name_);
|
createSQLQuery3.executeUpdate();
|
// session.getTransaction().commit();
|
|
// session.beginTransaction();
|
StringBuilder insertJbpm4HistTask1 = new StringBuilder();
|
insertJbpm4HistTask1.append("update jbpm4_hist_task ");
|
insertJbpm4HistTask1.append(" set create_ = ? ");
|
insertJbpm4HistTask1.append(" where dbid_ = '" + taskid + "' ");
|
SQLQuery createSQLQuery4 = session.createSQLQuery(insertJbpm4HistTask1.toString());
|
createSQLQuery4.setTimestamp(0, v_end_);
|
createSQLQuery4.executeUpdate();
|
|
String processinstansid = processEngine.getExecutionService().findExecutionById(execution_).getProcessInstance()
|
.getId();
|
|
HibernateSessionFactory.getSession().flush();
|
if (set_taskanduserconfigex) {
|
String taskanduserconfigexSql = "update jbpm4_taskanduserconfigex set username = '" + toUserName
|
+ "' where processinstansid = '" + processinstansid + "' and taskname = '" + v_activity_name_ + "'";
|
HibernateSessionFactory.getSession().createSQLQuery(taskanduserconfigexSql).executeUpdate();
|
}
|
}
|
|
private FlowTaskInfo[] getTodoTaskByUserIdForAssignTask(String pluseroid) {
|
List<FlowTaskInfo> flowTaskInfos = new ArrayList<FlowTaskInfo>();
|
|
StringBuilder sql = new StringBuilder();
|
sql.append("select DBID_, NAME_, createTime, EXECUTION_ID_, PLDESC ,PLTEMPLATENAME,PLCREATOR");
|
sql.append(" from( ");
|
// sql.append("select rownum rn, DBID_, NAME_,createTime, EXECUTION_ID_, PLDESC ,PLTEMPLATENAME,PLCREATOR,DEPTNAME");
|
sql.append("select rownum rn, DBID_, NAME_,createTime, EXECUTION_ID_, PLDESC ,PLTEMPLATENAME,PLCREATOR");
|
sql.append(" from( ");
|
sql.append(
|
"(select t1.DBID_, t1.NAME_, t1.CREATE_ as createTime, t1.EXECUTION_ID_, i.PLDESC, i.PLTEMPLATENAME,i.pltasktype,i.plcreator");
|
sql.append(" from JBPM4_TASK t1 left join PLFLOWINSTANCE i on t1.EXECUTION_ID_=i.PLEXECUTIONID");
|
// 流程数据所在的模板表必须存在
|
sql.append(" and i.pltablename in(select rt.PLTABLENAME from plrmtemplate rt)");
|
sql.append(" where t1.ASSIGNEE_=?");
|
sql.append(" )union(");
|
sql.append(
|
" select t.DBID_, t.NAME_, t.CREATE_ as createTime, t.EXECUTION_ID_, i.PLDESC, i.PLTEMPLATENAME,i.pltasktype,i.plcreator");
|
sql.append(
|
" from JBPM4_TASK t cross join JBPM4_PARTICIPATION participat1_ left join PLFLOWINSTANCE i on t.EXECUTION_ID_=i.PLEXECUTIONID");
|
// add by xchao 2013.06.06 begin
|
// 修复由于模板删除或模板重建(表名变更了)后,从流程任务中查询流程数据时报错的问题
|
// 关键出申请人的部门
|
sql.append(
|
" where participat1_.TASK_=t.DBID_ and participat1_.TYPE_='candidate' and participat1_.USERID_=? and (t.ASSIGNEE_ is null) ");
|
// 流程数据所在的模板表必须存在
|
sql.append(")");
|
// add by xchao 2013.06.06 end
|
sql.append(" order by createTime desc");
|
sql.append(" ) ");
|
sql.append(" where 1=1 ");
|
String sqldept = "";
|
sql.append(" and PLDESC is not null order by createTime desc");
|
sql.append(")");
|
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
createSQLQuery.setString(0, pluseroid);
|
createSQLQuery.setString(1, pluseroid);
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
List<?> list = createSQLQuery.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] object = (Object[]) list.get(i);
|
FlowTaskInfo flowHistoryTaskInfo = new FlowTaskInfo();
|
String taskId = String.valueOf(object[0]);
|
String taskName = (String) object[1];
|
Timestamp createTime = (Timestamp) object[2];
|
String executionId = (String) object[3];
|
String desc = (String) object[4];
|
String applyPerson = (String) object[6];
|
flowHistoryTaskInfo.id = taskId == null ? "" : taskId;
|
flowHistoryTaskInfo.name = taskName == null ? "" : taskName;
|
flowHistoryTaskInfo.createTime = createTime.getTime();
|
flowHistoryTaskInfo.executionId = executionId == null ? "" : executionId;
|
flowHistoryTaskInfo.desc = desc == null ? "" : desc;
|
flowHistoryTaskInfo.applyPerson = applyPerson == null ? "" : applyPerson;
|
flowHistoryTaskInfo.templateName = (String) (object[5] == null ? "" : object[5]);
|
flowTaskInfos.add(flowHistoryTaskInfo);
|
}
|
} catch (Exception ex) {
|
// ex.printStackTrace();
|
ServerWithLog4j.logger.error("getTodoTaskByUserIdForAssignTask", ex);
|
} finally {
|
|
}
|
return flowTaskInfos.toArray(new FlowTaskInfo[0]);
|
}
|
|
public ProcessTaskInfo findTaskPropertyByProcessId(final String jbpmDeploymentId) {
|
ProcessTaskInfo object = (ProcessTaskInfo) new HibernateTemplate().run(new HibernateCallback() {
|
public Object execute() throws HibernateException {
|
ProcessTaskDaoImpl impl = new ProcessTaskDaoImpl();
|
String hql = "from ProcessTask t where t.deploymentId = ? ";
|
List<ProcessTask> processTask = impl.createQueryList(hql, new Object[] { jbpmDeploymentId });
|
if (processTask != null) {
|
ProcessTaskPropertyDaoImpl propertyImpl = new ProcessTaskPropertyDaoImpl();
|
String phql = "from ProcessTaskProperty t where t.taskPropertyId = ?";
|
List<ProcessTaskProperty> typeProperties = propertyImpl.findEntites(phql,
|
new Object[] { processTask.get(0).getTaskTypePropertyId() });
|
|
return convertToInfo(processTask.get(0), typeProperties);
|
} else {
|
ProcessTaskInfo processTaskInfo = new ProcessTaskInfo();
|
processTaskInfo.taskTypeProperties = new PropertyInfo[0];
|
return processTaskInfo;
|
}
|
}
|
|
private ProcessTaskInfo convertToInfo(ProcessTask processTask, List<ProcessTaskProperty> typeProperties) {
|
ProcessTaskInfo info = new ProcessTaskInfo();
|
info.id = processTask.getId() == null ? "" : processTask.getId();
|
info.deploymentId = processTask.getDeploymentId() == null ? "" : processTask.getDeploymentId();
|
info.taskName = processTask.getTaskName() == null ? "" : processTask.getTaskName();
|
info.taskType = processTask.getTaskType() == null ? "" : processTask.getTaskType();
|
info.taskTypeProperties = getPropertyInfos(typeProperties);
|
info.customUserInfos = new CustomInfo[0];
|
info.revokeInfos = new PropertyInfo[0];
|
return info;
|
}
|
|
private PropertyInfo[] getPropertyInfos(List<ProcessTaskProperty> typeProperties) {
|
if (typeProperties != null && typeProperties.size() > 0) {
|
PropertyInfo[] result = new PropertyInfo[typeProperties.size()];
|
for (int i = 0; i < typeProperties.size(); i++) {
|
ProcessTaskProperty property = typeProperties.get(i);
|
result[i] = new PropertyInfo();
|
result[i].property = property.getProperty();
|
result[i].value = property.getValue();
|
}
|
return result;
|
} else {
|
return new PropertyInfo[0];
|
}
|
}
|
});
|
return object;
|
}
|
|
/**
|
* 返回任节点上定义的候选人字符串内容
|
* <p>
|
* Description:
|
* </p>
|
*
|
* @author xchao
|
* @time 2012-11-10
|
* @param jbpmDeploymentId
|
* @param taskName
|
* @param outcome
|
* @return
|
* @throws Exception
|
*/
|
public String getNextCandidatesDefineString(String jbpmDeploymentId, String taskName, String outcome)
|
throws Exception {
|
byte[] processXml = getProcessResource(jbpmDeploymentId, ".xml");
|
InputStream in = new ByteArrayInputStream(processXml);
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
|
|
SAXReader saxr = new SAXReader();
|
Document doc = saxr.read(reader);
|
Element root = doc.getRootElement();
|
if ("".equals(taskName)) {
|
taskName = getTaskName(root);
|
}
|
|
taskName = getNextTaskName(root, taskName, outcome);
|
if (taskName.length() > 0) {
|
String result = getUsersDefineStrig(root, taskName);
|
if (result != null) {
|
return result;
|
}
|
}
|
return "";
|
}
|
|
private String getNextTaskName(Element root, String taskName, String outcome) {
|
// 选获取taskName的所有transition
|
List<Element> transitions = new ArrayList<Element>();
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
String cellType = element.getName();
|
String cellName = element.attributeValue(FlowConstants.XMLNAME);
|
if (FlowConstants.XMLTASK.equals(cellType) && cellName.equals(taskName)) {// 任务节点
|
for (Iterator<?> b = element.elementIterator(); b.hasNext();) {
|
Element next = (Element) b.next();
|
if (next.getName().equals(FlowConstants.TRANSITION)) {
|
transitions.add(next);
|
}
|
}
|
}
|
}
|
|
if (transitions.size() == 1) {// 如果只有一个transition,那么不需要判断outcome
|
return transitions.get(0).attributeValue(FlowConstants.XMLTARGET);
|
}
|
|
for (Element element : transitions) {
|
|
String attributeValue = element.attributeValue(FlowConstants.XMLTARGET);
|
String name = element.attributeValue(FlowConstants.XMLNAME);
|
if (name.equals(outcome)) {
|
return attributeValue;
|
}
|
}
|
|
return "";
|
}
|
|
private String getUsersDefineStrig(Element root, String nextTaskName) {
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
String cellName = element.attributeValue(FlowConstants.XMLNAME);
|
if (nextTaskName.equals(cellName)) {
|
// 只查询出多个候选人的用户列表
|
Attribute usersAttribute = element.attribute(FlowConstants.XMLUSERS);
|
if (usersAttribute != null) {
|
String userName = usersAttribute.getValue();
|
return userName;
|
}
|
return null;
|
}
|
}
|
return null;
|
}
|
|
/**
|
* 已完成流程
|
*
|
* @param pluseroid
|
* @param first
|
* @param pageSize
|
* @param tasktype
|
* @param querySQL
|
* @return
|
*/
|
public FlowTaskInfo[] getDoneProcessByUserId(String pluseroid, int first, int pageSize, String tasktype,
|
String querySQL) {
|
|
List<FlowTaskInfo> flowTaskInfos = new ArrayList<FlowTaskInfo>();
|
StringBuilder sql = new StringBuilder();
|
sql.append(" select distinct DBID_, CREATE_, END_, EXECUTION_, PLDESC, pltemplatename,createUser,state_ ");
|
sql.append(" from( ");
|
sql.append(" select rownum rn,DBID_, CREATE_, END_, EXECUTION_, PLDESC ,pltemplatename,createUser,state_");
|
sql.append(" from( ");
|
sql.append(
|
"select hp.DBID_, hp.start_ as CREATE_, hp.END_, ht.EXECUTION_, i.PLDESC, i.pltemplatename,i.plcreator as createUser,i.pltasktype,hp.state_");
|
sql.append(
|
" FROM JBPM4_HIST_TASK ht left join JBPM4_HIST_ACTINST ha on ht.DBID_=ha.HTASK_ left join PLFLOWINSTANCE i on ht.EXECUTION_ like (i.PLEXECUTIONID||'%')");
|
sql.append(" left join JBPM4_HIST_PROCINST hp on ht.EXECUTION_ = hp.ID_ ");
|
|
String[] taskTypes = tasktype.split(",");
|
String sqldept = "";
|
try {
|
// 2011.12.08 ligang查询指定日期范围的已办任务数据
|
int datePeriod = Integer.parseInt(WorkflowProperties.getStringProperty("done.task.date.period"));
|
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
|
long period = 1000L * 24 * 60 * 60 * datePeriod;
|
String startDate = sd.format(
|
new Date(sd.parse(new SimpleDateFormat("yyyy-MM-dd").format(new Date())).getTime() - period));
|
String endDate = sd.format(new Date());
|
sql.append(" where ht.END_ is not null and ht.ASSIGNEE_ = ? ");
|
sql.append(" order by ht.END_ desc");
|
// 分页
|
sql.append(")");
|
sql.append(" where 1=1");
|
sql.append(" and pltasktype in ( ");
|
|
for (int i = 0; i < taskTypes.length; i++) {
|
sql.append("?");
|
if (i < taskTypes.length - 1) {
|
sql.append(",");
|
}
|
}
|
sql.append(" )");
|
if (querySQL != "") {
|
if (querySQL.contains("#")) {
|
String SQL1 = querySQL.substring(0, querySQL.indexOf("#"));
|
sqldept = querySQL.substring(querySQL.indexOf("#") + 1);
|
sql.append(SQL1);
|
} else {
|
sql.append(querySQL);
|
}
|
}
|
sql.append("and rownum <= " + first * pageSize);
|
sql.append(" )");
|
sql.append(" where rn >" + (first - 1) * pageSize);
|
sql.append(" order by CREATE_ desc");
|
} catch (ParseException e1) {
|
// e1.printStackTrace();
|
ServerWithLog4j.logger.error("getDoneProcessByUserId", e1);
|
}
|
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
createSQLQuery.setString(0, pluseroid);
|
for (int i = 0; i < taskTypes.length; i++) {
|
createSQLQuery.setString(1 + i, taskTypes[i]);
|
}
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
List<?> list = createSQLQuery.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] object = (Object[]) list.get(i);
|
FlowTaskInfo flowHistoryTaskInfo = new FlowTaskInfo();
|
String taskId = String.valueOf(object[0]);
|
Timestamp createTime = (Timestamp) object[1];
|
Timestamp endTime = (Timestamp) object[2];
|
String executionId = (String) object[3];
|
String desc = (String) object[4];
|
String templateName = (String) object[5];
|
String createUser = (String) object[6];
|
flowHistoryTaskInfo.id = taskId == null ? "" : taskId;
|
flowHistoryTaskInfo.name = "" == null ? "" : "";
|
flowHistoryTaskInfo.createTime = createTime.getTime();
|
flowHistoryTaskInfo.endTime = endTime.getTime();
|
flowHistoryTaskInfo.executionId = executionId == null ? "" : executionId;
|
flowHistoryTaskInfo.desc = desc == null ? "" : desc;
|
flowHistoryTaskInfo.templateName = templateName == null ? "" : templateName;
|
flowHistoryTaskInfo.applyPerson = createUser == null ? "" : createUser;
|
flowTaskInfos.add(flowHistoryTaskInfo);
|
}
|
} catch (Exception ex) {
|
// ex.printStackTrace();
|
ServerWithLog4j.logger.error("getDoneProcessByUserId", ex);
|
} finally {
|
|
}
|
return flowTaskInfos.toArray(new FlowTaskInfo[0]);
|
}
|
|
/**
|
* 已完成流程总数
|
*
|
* @param pluseroid
|
* @param expandSql
|
* @return
|
*/
|
public int queryDoneProcessCount(String pluseroid, String expandSql) {
|
// 查询已办任务总条数
|
int res = 0;
|
List<FlowTaskInfo> flowTaskInfos = new ArrayList<FlowTaskInfo>();
|
StringBuilder sql = new StringBuilder();
|
sql.append(
|
" select count(*) from ( select distinct DBID_, CREATE_, END_, EXECUTION_, PLDESC, pltemplatename,createUser,state_ ");
|
sql.append(" from( ");
|
sql.append(" select DBID_, CREATE_, END_, EXECUTION_, PLDESC ,pltemplatename,createUser,state_");
|
sql.append(" from( ");
|
sql.append(
|
"select hp.DBID_, hp.start_ as CREATE_, hp.END_, ht.EXECUTION_, i.PLDESC, i.pltemplatename,i.plcreator as createUser,i.pltasktype,hp.state_");
|
sql.append(
|
" FROM JBPM4_HIST_TASK ht left join JBPM4_HIST_ACTINST ha on ht.DBID_=ha.HTASK_ left join PLFLOWINSTANCE i on ht.EXECUTION_ like (i.PLEXECUTIONID||'%')");
|
sql.append(" left join JBPM4_HIST_PROCINST hp on ht.EXECUTION_ = hp.ID_ ");
|
|
try {
|
// 2011.12.08 ligang查询指定日期范围的已办任务数据
|
int datePeriod = Integer.parseInt(WorkflowProperties.getStringProperty("done.task.date.period"));
|
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
|
long period = 1000L * 24 * 60 * 60 * datePeriod;
|
String startDate = sd.format(
|
new Date(sd.parse(new SimpleDateFormat("yyyy-MM-dd").format(new Date())).getTime() - period));
|
String endDate = sd.format(new Date());
|
sql.append(" where ht.END_ is not null and ht.ASSIGNEE_ = ? ");
|
sql.append(" order by ht.END_ desc");
|
// 分页
|
sql.append(")");
|
sql.append(" where 1=1");
|
if (expandSql != null && !"".equals(expandSql)) {
|
sql.append(expandSql);
|
}
|
sql.append(" )");
|
sql.append(" order by CREATE_ desc)");
|
} catch (ParseException e1) {
|
// e1.printStackTrace();
|
ServerWithLog4j.logger.error("queryDoneProcessCount", e1);
|
}
|
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
createSQLQuery.setString(0, pluseroid);
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List<?> list = createSQLQuery.list();
|
if (list != null && list.size() > 0) {
|
res = Integer.parseInt(String.valueOf(list.get(0)));
|
}
|
} catch (Exception ex) {
|
// ex.printStackTrace();
|
ServerWithLog4j.logger.error("queryDoneProcessCount", ex);
|
} finally {
|
|
}
|
return res;
|
}
|
|
/**
|
* 返回流程的第一个任务对象
|
* <p>
|
* Description:
|
* </p>
|
*
|
* @author xchao
|
* @time 2012-6-5
|
* @param jbpmDeploymentId 流程部署ID
|
* @return
|
* @throws Exception
|
*/
|
public ProcessTask getFirstProcessTask(final String jbpmDeploymentId) throws Exception {
|
ProcessTask task = null;
|
byte[] jpdlXml = getProcessResource(jbpmDeploymentId, ".xml");
|
ByteArrayInputStream bais = new ByteArrayInputStream(jpdlXml);
|
BufferedReader reader = new BufferedReader(new InputStreamReader(bais, "utf-8"));
|
SAXReader saxReader = new SAXReader();
|
Document doc = saxReader.read(reader);
|
Element root = doc.getRootElement();
|
Iterator<?> itor = root.elementIterator();
|
String firstTaskName = "";
|
boolean itorBreak = false;
|
while (itor.hasNext()) {
|
Element e = (Element) itor.next();
|
if (e.getName().trim().toLowerCase().equals("start")) {
|
Iterator<?> itorChild = e.elementIterator();
|
while (itorChild.hasNext()) {
|
Element eChild = (Element) itorChild.next();
|
if (eChild.getName().toLowerCase().equals("transition")) {
|
firstTaskName = eChild.attributeValue("to");
|
itorBreak = true;
|
break;
|
}
|
}
|
}
|
if (itorBreak) {
|
break;
|
}
|
}
|
|
final String deployId = jbpmDeploymentId;
|
final String taskName = firstTaskName;
|
task = (ProcessTask) new HibernateTemplate().run(new HibernateCallback() {
|
public Object execute() throws HibernateException {
|
ProcessTaskDaoImpl impl = new ProcessTaskDaoImpl();
|
String hsql = "from ProcessTask t where t.deploymentId = ? and t.taskName = ?";
|
return impl.findEntity(hsql, new Object[] { deployId, taskName });
|
}
|
});
|
return task == null ? new ProcessTask() : task;
|
}
|
|
/**
|
* 获取任务的流向
|
*
|
* @param jbpmDeploymentId
|
* @param taskName
|
* @return
|
* @throws Exception
|
*/
|
public String getAllNoAgreeProcessTaskByTaskName(final String taskId, String taskName, String outcome)
|
throws Exception {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
TaskService taskService = processEngine.getTaskService();
|
ProcessInstance processInstance = processEngine.getExecutionService()
|
.findProcessInstanceById(taskService.getTask(taskId).getExecutionId());
|
final String processDefinitionId = processInstance.getProcessDefinitionId();
|
String jbpmDeploymentId = (String) new HibernateTemplate().run(new HibernateCallback() {
|
public Object execute() throws HibernateException {
|
ProcessTaskDaoImpl impl = new ProcessTaskDaoImpl();
|
String sql = " select t.deployment_ from JBPM4_DEPLOYPROP t where t.stringval_ = '"
|
+ processDefinitionId + "'";
|
List<?> createQueryList = impl.findEntitesBySQL(sql, new String[0], new HashMap());
|
String id = "";
|
for (int i = 0; i < createQueryList.size(); i++) {
|
id = createQueryList.get(i).toString();
|
}
|
return id;
|
}
|
});
|
|
StringBuilder taskResult = new StringBuilder();
|
|
byte[] jpdlXml = getProcessResource(jbpmDeploymentId, ".xml");
|
ByteArrayInputStream bais = new ByteArrayInputStream(jpdlXml);
|
BufferedReader reader = new BufferedReader(new InputStreamReader(bais, "utf-8"));
|
SAXReader saxReader = new SAXReader();
|
Document doc = saxReader.read(reader);
|
Element root = doc.getRootElement();
|
Iterator<?> itor = root.elementIterator();
|
String elementTaskName = "";
|
boolean itorBreak = false;
|
while (itor.hasNext()) {
|
Element e = (Element) itor.next();
|
if (e.getName().trim().toLowerCase().equals("task")) {
|
elementTaskName = e.attributeValue("name");
|
if (taskName.equals(elementTaskName)) {
|
Iterator<?> itorChild = e.elementIterator();
|
while (itorChild.hasNext()) {
|
Element eChild = (Element) itorChild.next();
|
if (eChild.getName().toLowerCase().equals("transition")) {
|
String isAgree = eChild.attributeValue("name");
|
if (!(outcome.equals(isAgree))) {
|
String endTaskName = eChild.attributeValue("to");
|
taskResult.append(isAgree);
|
taskResult.append(",");
|
taskResult.append(endTaskName);
|
taskResult.append(";");
|
}
|
}
|
}
|
}
|
}
|
}
|
|
return taskResult.toString();
|
}
|
|
public boolean setNodeHide(final String deploymentId) {
|
return (Boolean) new HibernateTemplate().run(new HibernateCallback() {
|
public Object execute() throws HibernateException {
|
NodeHideDaoImpl impl = new NodeHideDaoImpl();
|
NodeHide nh = new NodeHide();
|
nh.setDeploymentId(deploymentId);
|
nh.setHide("1");
|
nh.setId(ObjectUtility.getNewObjectID36());
|
impl.save(nh);
|
return true;
|
}
|
});
|
}
|
|
@SuppressWarnings("unchecked")
|
public List<NodeHide> getNodeHideDeploymentId() {
|
return (List) new HibernateTemplate().run(new HibernateCallback() {
|
public Object execute() throws HibernateException {
|
NodeHideDaoImpl impl = new NodeHideDaoImpl();
|
return impl.loadAll();
|
}
|
});
|
}
|
|
public boolean deleteHideFlow(final String deployId) {
|
return (Boolean) new HibernateTemplate().run(new HibernateCallback() {
|
public Object execute() throws HibernateException {
|
NodeHideDaoImpl impl = new NodeHideDaoImpl();
|
NodeHide node = impl.findEntity(" from NodeHide n where n.deploymentId = '" + deployId + "'");
|
if (!(node == null)) {
|
impl.delete(node);
|
}
|
return true;
|
}
|
});
|
}
|
|
public FlowTaskInfo[] getTaskByCondition(String[] values, int first, int pageSize, String objectId) {
|
List<FlowTaskInfo> flowTaskInfos = new ArrayList<FlowTaskInfo>();
|
StringBuilder sql = new StringBuilder();
|
if ("".equals(objectId) || null == objectId) {
|
sql.append(" select dbid_,pltemplatename,id_,start_,end_,pldesc ,createUser ");
|
sql.append(" from( ");
|
sql.append(" select rownum rn, dbid_,pltemplatename,id_,start_,end_,pldesc ,createUser ");
|
sql.append(" from( ");
|
sql.append(
|
" select ht.dbid_,flowinstance.pltemplatename,ht.id_, ht.start_,ht.end_ ,flowinstance.pldesc ,flowinstance.plcreator as createUser ");
|
sql.append(" from JBPM4_HIST_PROCINST ht, ");
|
sql.append(" ( select * from plflowinstance f where 1=1 ");
|
// 流程发起人
|
if (!("".equals(values[0]))) {
|
sql.append(" and f.plapplicant = '" + values[0] + "' ");
|
}
|
sql.append(" and f.plexecutionid in( ");
|
sql.append(" select t.execution_ from JBPM4_HIST_TASK t where 1=1 ");
|
// 流程处理人
|
if (!("".equals(values[1]))) {
|
sql.append(" and t.assignee_ = '" + values[1] + "'");
|
}
|
sql.append(" and t.dbid_ in ");
|
sql.append(" ( ");
|
sql.append(" select k.pltaskid from PLFLOWAPPROVEOPINION k ");
|
sql.append("where 1=1 ");
|
// 流程描述
|
if (!("".equals(values[4]) || null == values[4])) {
|
sql.append(" and k.plapprovenote like '%" + values[4] + "%' ");
|
}
|
sql.append(" )");
|
sql.append(") ");
|
sql.append(") flowinstance ");
|
sql.append(" where ht.id_ in( flowinstance.plexecutionid )");
|
if (!("".equals(values[2]) || "".equals(values[2].trim()))) {
|
sql.append(" and trunc(ht.END_) >= to_date('" + values[2] + "','yyyy-mm-dd') ");
|
}
|
if (!("".equals(values[3]) || "".equals(values[3].trim()))) {
|
sql.append(" and trunc(ht.END_) <= to_date('" + values[3] + "','yyyy-mm-dd') ");
|
}
|
sql.append(" and ht.END_ IS NOT NULL ");
|
sql.append(" order by ht.END_ DESC ");
|
sql.append(" ) where rownum <= " + first * pageSize);
|
sql.append(" ) where rn >" + (first - 1) * pageSize);
|
} else {
|
sql.append(" select dbid_,pltemplatename,id_,start_,end_,pldesc ,createUser ");
|
sql.append(" from ( ");
|
sql.append(" select rownum rn,dbid_,pltemplatename,id_,start_,end_,pldesc ,createUser ");
|
sql.append(" from( ");
|
sql.append(
|
" select ht.dbid_,flowinstance.pltemplatename,ht.id_, ht.start_,ht.end_ ,flowinstance.pldesc,flowinstance.plcreator as createUser ");
|
sql.append(" from JBPM4_HIST_PROCINST ht, ");
|
sql.append(" (select * from ");
|
sql.append(" plflowinstance f where 1=1 ");
|
sql.append(" and f.plexecutionid in( ");
|
sql.append(" select t.plexecutionid from plflowobject t ");
|
sql.append(" where t.plobjectid ='" + objectId + "') ");
|
sql.append(" ) flowinstance ");
|
sql.append(" where ht.id_ in (flowinstance.plexecutionid) ");
|
sql.append(" order by ht.end_ desc ");
|
sql.append(" ) where rownum <= " + first * pageSize);
|
sql.append(" ) where rn >" + (first - 1) * pageSize);
|
|
}
|
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
List<?> list = createSQLQuery.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] obj = (Object[]) list.get(i);
|
FlowTaskInfo flowHistoryTaskInfo = new FlowTaskInfo();
|
String taskId = String.valueOf(obj[0]);
|
String templateName = (String) obj[1];
|
String executionId = (String) obj[2];
|
Timestamp createTime = (Timestamp) obj[3];
|
Timestamp endTime = (Timestamp) obj[4];
|
String desc = (String) obj[5];
|
String createUser = (String) obj[6];
|
|
flowHistoryTaskInfo.id = taskId == null ? "" : taskId;
|
flowHistoryTaskInfo.createTime = createTime == null ? 0 : createTime.getTime();
|
flowHistoryTaskInfo.endTime = endTime == null ? 0 : endTime.getTime();
|
flowHistoryTaskInfo.executionId = executionId == null ? "" : executionId;
|
flowHistoryTaskInfo.desc = desc == null ? "" : desc;
|
flowHistoryTaskInfo.templateName = templateName == null ? "" : templateName;
|
flowHistoryTaskInfo.create = createUser == null ? "" : createUser;
|
flowTaskInfos.add(flowHistoryTaskInfo);
|
}
|
} catch (Exception ex) {
|
// ex.printStackTrace();
|
ServerWithLog4j.logger.error("getTaskByCondition", ex);
|
} finally {
|
|
}
|
return flowTaskInfos.toArray(new FlowTaskInfo[0]);
|
}
|
|
public int queryFlowTaskCount(String[] values, String objectId, boolean flag) {
|
int res = 0;
|
StringBuilder sql = new StringBuilder();
|
if (flag) {
|
sql.append(" select count(*) ");
|
sql.append(" from JBPM4_HIST_PROCINST ht, ");
|
sql.append(" ( select * from plflowinstance f where 1=1 ");
|
// 流程发起人
|
if (!("".equals(values[0]))) {
|
sql.append(" and f.plapplicant = '" + values[0] + "' ");
|
}
|
sql.append(" and f.plexecutionid in( ");
|
sql.append(" select t.execution_ from JBPM4_HIST_TASK t where 1=1 ");
|
// 流程处理人
|
if (!("".equals(values[1]))) {
|
sql.append(" and t.assignee_ = '" + values[1] + "'");
|
}
|
sql.append(" and t.dbid_ in ");
|
sql.append(" ( ");
|
sql.append(" select k.pltaskid from PLFLOWAPPROVEOPINION k ");
|
sql.append("where 1=1 ");
|
// 流程描述
|
if (!("".equals(values[4]) || null == values[4])) {
|
sql.append(" and k.plapprovenote like '%" + values[4] + "%' ");
|
}
|
sql.append(" )");
|
sql.append(") ");
|
sql.append(") flowinstance ");
|
sql.append(" where ht.id_ in( flowinstance.plexecutionid )");
|
if (!("".equals(values[2]) || "".equals(values[2].trim()))) {
|
sql.append(" and trunc(ht.END_) >= to_date('" + values[2] + "','yyyy-mm-dd') ");
|
}
|
if (!("".equals(values[3]) || "".equals(values[3].trim()))) {
|
sql.append(" and trunc(ht.END_) <= to_date('" + values[3] + "','yyyy-mm-dd') ");
|
}
|
sql.append(" and ht.end_ is not null ");
|
sql.append(" order by ht.END_ DESC ");
|
} else {
|
sql.append(" select count(*) ");
|
sql.append(" from JBPM4_HIST_PROCINST ht, ");
|
sql.append(" (select * from ");
|
sql.append(" plflowinstance f where 1=1 ");
|
sql.append(" and f.plexecutionid in( ");
|
sql.append(" select t.plexecutionid from plflowobject t ");
|
sql.append(" where t.plobjectid ='" + objectId + "') ");
|
sql.append(" ) flowinstance ");
|
sql.append(" where ht.id_ in (flowinstance.plexecutionid) ");
|
}
|
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List<?> list = createSQLQuery.list();
|
if (list != null && list.size() > 0) {
|
res = Integer.parseInt(String.valueOf(list.get(0)));
|
}
|
} catch (Exception ex) {
|
// ex.printStackTrace();
|
ServerWithLog4j.logger.error("queryFlowTaskCount", ex);
|
} finally {
|
|
}
|
return res;
|
}
|
|
public String getNextTaskNameByJbpmId(String jbpmDeploymentId, String taskName, String outcome) throws Exception {
|
byte[] processXml = getProcessResource(jbpmDeploymentId, ".xml");
|
InputStream in = new ByteArrayInputStream(processXml);
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
|
|
if (taskName.indexOf("(") > 0) {
|
taskName = taskName.substring(0, taskName.indexOf("("));
|
|
}
|
|
SAXReader saxr = new SAXReader();
|
Document doc = saxr.read(reader);
|
Element root = doc.getRootElement();
|
// 选获取taskName的所有transition
|
List<Element> transitions = new ArrayList<Element>();
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
String cellType = element.getName();
|
String cellName = element.attributeValue(FlowConstants.XMLNAME);
|
if (FlowConstants.XMLTASK.equals(cellType) && cellName.equals(taskName)) {// 任务节点
|
for (Iterator<?> b = element.elementIterator(); b.hasNext();) {
|
Element next = (Element) b.next();
|
if (next.getName().equals(FlowConstants.TRANSITION)) {
|
transitions.add(next);
|
}
|
}
|
}
|
}
|
|
if (transitions.size() == 1) {// 如果只有一个transition,那么不需要判断outcome
|
return transitions.get(0).attributeValue(FlowConstants.XMLTARGET);
|
}
|
|
for (Element element : transitions) {
|
|
String attributeValue = element.attributeValue(FlowConstants.XMLTARGET);
|
String name = element.attributeValue(FlowConstants.XMLNAME);
|
if (name != null && name.equals(outcome)) {
|
return attributeValue;
|
}
|
}
|
|
return "";
|
}
|
|
/**
|
* 获取下一节点负责人,如果下一节点是子流程,直接去子流程负责人
|
*
|
* @param executionId
|
* @param taskName
|
* @param outcome
|
* @return
|
* @throws Exception
|
*/
|
public String getNextSubTaskAssigner(String executionId, String taskName, String outcome) throws Exception {
|
String jbpmDeploymentId = this.getDeploymentIdByExecutionId(executionId);
|
String superExcutionId = this.getParentExcutionId(executionId);
|
if (superExcutionId.equals(executionId)) {
|
if ("结束".equals(taskName)) {
|
return "结束";
|
}
|
String subProessId = getTaskSubProcessID(jbpmDeploymentId, taskName);
|
if (subProessId == null || subProessId.equals("")) {
|
return this.getNextTaskAssigner(executionId, taskName);
|
} else {
|
String subjbpmDeploymentId = String.valueOf(this.getDeploymentID(subProessId));
|
String subTaskName = this.getFirstProcessTask(subjbpmDeploymentId).getTaskName();
|
String formatTaskName = subTaskName + "(" + subProessId + ":" + subjbpmDeploymentId + ")";
|
return this.getNextTaskAssigner(executionId, formatTaskName);
|
}
|
} else { //
|
if ("结束".equals(taskName)) {
|
String subProcessId = this.getProcessDefinitionByDeployId(jbpmDeploymentId).id;
|
String superDeployId = this.getDeploymentIdByExecutionId(superExcutionId);
|
String superCurName = getNextSuperTaskBySubProId(superDeployId, subProcessId);
|
String superNextName[] = getNextTaskNames(superDeployId, superCurName, "同意");
|
if (superNextName != null && superNextName.length > 0) {
|
return this.getNextTaskAssigner(superExcutionId, superNextName[0]);
|
} else {
|
return "";
|
}
|
} else {
|
String subProessId = this.getProcessDefinitionByDeployId(jbpmDeploymentId).id;
|
String formatTaskName = taskName + "(" + subProessId + ":" + jbpmDeploymentId + ")";
|
return this.getNextTaskAssigner(superExcutionId, formatTaskName);
|
}
|
}
|
}
|
|
private String getNextSuperTaskBySubProId(String jbpmDeploymentId, String subProcessId) {
|
Element root = null;
|
byte[] processXml;
|
try {
|
processXml = getProcessResource(jbpmDeploymentId, ".xml");
|
InputStream in = new ByteArrayInputStream(processXml);
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
|
|
SAXReader saxr = new SAXReader();
|
Document doc = saxr.read(reader);
|
root = doc.getRootElement();
|
} catch (Exception e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("getNextSuperTaskBySubProId", e);
|
}
|
if (root == null) {
|
return "";
|
}
|
// 选获取taskName的所有transition
|
List<Element> transitions = new ArrayList<Element>();
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
String cellType = element.getName();
|
String cellName = element.attributeValue(FlowConstants.XMLNAME);
|
if (FlowConstants.SUBPROCESS.equals(cellType)
|
&& subProcessId.equals(element.attributeValue(FlowConstants.SUBPROCESSID))) {// 任务节点
|
return cellName;
|
}
|
}
|
return "";
|
}
|
|
private String getTaskSubProcessID(String jbpmDeploymentId, String taskName) throws Exception {
|
String subProcessId = "";
|
byte[] processXml = getProcessResource(jbpmDeploymentId, ".xml");
|
InputStream in = new ByteArrayInputStream(processXml);
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
|
|
SAXReader saxr = new SAXReader();
|
Document doc = saxr.read(reader);
|
Element root = doc.getRootElement();
|
List<Element> transitions = new ArrayList<Element>();
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
String cellType = element.getName();
|
String cellName = element.attributeValue(FlowConstants.XMLNAME);
|
if (FlowConstants.SUBPROCESS.equals(cellType) && cellName.equals(taskName)) {// 任务节点
|
subProcessId = element.attributeValue(FlowConstants.SUBPROCESSID);
|
break;
|
}
|
}
|
if (subProcessId == null) {
|
subProcessId = "";
|
}
|
|
return subProcessId;
|
}
|
|
public String getNextTaskTypeByJbpmId(String jbpmDeploymentId, String taskName, String outcome) throws Exception {
|
byte[] processXml = getProcessResource(jbpmDeploymentId, ".xml");
|
InputStream in = new ByteArrayInputStream(processXml);
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
|
|
SAXReader saxr = new SAXReader();
|
Document doc = saxr.read(reader);
|
Element root = doc.getRootElement();
|
// 选获取taskName的所有transition
|
for (Iterator<?> a = root.elementIterator(); a.hasNext();) {
|
Element element = (Element) a.next();
|
String cellType = element.getName();
|
String cellName = element.attributeValue(FlowConstants.XMLNAME);
|
if (FlowConstants.XMLDECISION.equals(cellType) && cellName.equals(taskName)) {// 判断节点
|
return FlowConstants.XMLDECISION;
|
}
|
}
|
|
return "";
|
}
|
|
/**
|
* 获取流程任务的发起人
|
* <p>
|
* Description:
|
* </p>
|
*
|
* @author Administrator
|
* @time 2012-12-21
|
* @param execId
|
* @return
|
*/
|
public String getProcessStartUser(String execId) {
|
Session session = HibernateSessionFactory.getSession();
|
String createUser = "";
|
try {
|
String sql = "select T.PLAPPLICANT from plflowinstance T WHERE T.PLEXECUTIONID = ?";
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sql);
|
createSQLQuery.setString(0, execId);
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List<?> list = createSQLQuery.list();
|
if (list != null && list.size() > 0) {
|
createUser = String.valueOf(list.get(0));
|
}
|
} catch (Exception e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("getProcessStartUser", e);
|
} finally {
|
|
}
|
|
return createUser;
|
}
|
|
/**
|
* 根据流程执行ID查询返回的任务ID
|
* <p>
|
* Description:
|
* </p>
|
*
|
* @time 2013-4-27
|
* @param executionId
|
* @return
|
*/
|
public String getProcessTaskId(final String executionId) {
|
String sql = "select t.DBID_ from jbpm4_task t where t.EXECUTION_ID_=?";
|
return (String) new JDBCTemplate().run(new JDBCCallback(new HibernateTemplate().getSessionConnection(), sql,
|
JDBCRunType.SQL, -1, false, false, new Object[] { executionId }) {
|
@Override
|
public Object execute(ResultSet rst) throws SQLException {
|
String res = "";
|
while (rst.next()) {
|
res = rst.getString("DBID_");
|
}
|
return res;
|
}
|
});
|
}
|
|
public boolean deleteTasksAssignedByUserName(final String[] userNames) throws SQLException, VCIError {
|
Session session = HibernateSessionFactory.getSession();
|
StringBuffer sql = new StringBuffer("DELETE FROM PLTASKSASSIGNED WHERE PLFROMUSER in( ");
|
for (int i = 0; i < userNames.length; i++) {
|
sql.append("'");
|
sql.append(userNames[i]);
|
if (i + 1 == userNames.length) {
|
sql.append("'");
|
break;
|
} else
|
sql.append("',");
|
}
|
sql.append(")");
|
try {
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
createSQLQuery.executeUpdate();
|
} catch (Exception e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("deleteTasksAssignedByUserName", e);
|
throw new VCIError();
|
} finally {
|
|
}
|
return true;
|
}
|
|
public boolean deleteTasksAssignedByIds(final String[] ids) throws SQLException, VCIError {
|
// System.out.println("===============ProcessTemplateService.deleteTasksAssignedByIds===============");
|
|
Session session = HibernateSessionFactory.getSession();
|
StringBuffer sql = new StringBuffer("DELETE FROM PLTASKSASSIGNED WHERE PLOID in( ");
|
for (int i = 0; i < ids.length; i++) {
|
sql.append("'");
|
sql.append(ids[i]);
|
if (i + 1 == ids.length) {
|
sql.append("'");
|
break;
|
} else
|
sql.append("',");
|
}
|
sql.append(")");
|
try {
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
createSQLQuery.executeUpdate();
|
} catch (Exception e) {
|
e.printStackTrace();
|
throw new VCIError();
|
} finally {
|
|
}
|
return true;
|
}
|
|
/**
|
* 下一步任务设置候选人
|
*
|
* @param nextTaskId
|
* @param userNames
|
*/
|
public void setParticipation(String nextTaskId, String[] userNames) {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
TaskService taskService = processEngine.getTaskService();
|
// 重新设置候选人
|
for (int k = 0; k < userNames.length; k++) {
|
String userName = userNames[k];
|
if (userName.trim().length() > 0) {
|
List<Participation> taskParticipations = taskService.getTaskParticipations(nextTaskId);
|
// 先删除原来的任务候选人
|
if (k == 0) {
|
// 放回任务
|
taskService.assignTask(nextTaskId, null);
|
|
for (Participation participation : taskParticipations) {
|
taskService.removeTaskParticipatingUser(nextTaskId, participation.getUserId(),
|
Participation.CANDIDATE);
|
}
|
}
|
|
taskService.addTaskParticipatingUser(nextTaskId, userName, Participation.CANDIDATE);
|
}
|
}
|
}
|
|
/**
|
* 获取下个任务的全部用户
|
*
|
* @param taskName 任务名称
|
* @param deploymentId 部署ID
|
* @return
|
*/
|
public List<String> getAllUserListForTask(String taskName, String deploymentId, String outcome, String[] varKey,
|
String[] varValue) {
|
List<String> allUserList = new ArrayList<String>();
|
Map<String, String> var = new HashMap<String, String>();
|
for (int i = 0; i < varKey.length; i++) {
|
var.put(varKey[i], varValue[i]);
|
}
|
List<TaskDescSObject> taskDescList = this.getTaskDescList(taskName, deploymentId);
|
try {
|
String curCandidates = getNextCandidatesDefineString(deploymentId, taskName, outcome);
|
allUserList.add(curCandidates);
|
} catch (Exception e1) {
|
// e1.printStackTrace();
|
ServerWithLog4j.logger.error("getAllUserListForTask", e1);
|
}
|
for (TaskDescSObject taskDescSObject : taskDescList) {
|
String plcustomclassname = taskDescSObject.getPlcustomclassname();
|
String plcustomparam = taskDescSObject.getPlcustomparam();
|
if (plcustomclassname != null && !"".equals(plcustomclassname)) {
|
Class<?> cls;
|
try {
|
cls = Class.forName(plcustomclassname);
|
CustomUserClassInterface res = (CustomUserClassInterface) cls.getConstructor().newInstance();
|
List<String> customUserList = res.getCustomUserList(plcustomparam, var);
|
for (String customUser : customUserList) {
|
allUserList.add(customUser);
|
}
|
} catch (ClassNotFoundException e) {
|
e.printStackTrace();
|
} catch (IllegalArgumentException e) {
|
e.printStackTrace();
|
} catch (SecurityException e) {
|
e.printStackTrace();
|
} catch (InstantiationException e) {
|
e.printStackTrace();
|
} catch (IllegalAccessException e) {
|
e.printStackTrace();
|
} catch (InvocationTargetException e) {
|
e.printStackTrace();
|
} catch (NoSuchMethodException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
return allUserList;
|
}
|
|
/**
|
* 返回流程执行时的参数值
|
* <p>
|
* Description:
|
* </p>
|
*
|
* @author xchao
|
* @time 2013-5-24
|
* @param executionId 流程执行ID
|
* @param varName 变量名称
|
* @return
|
*/
|
public String getProcessVariable(String executionId, String varName) {
|
String res = "";
|
int index = executionId.indexOf(".");
|
if (index >= 0) {
|
executionId = executionId.substring(index + 1);
|
}
|
String sql = "SELECT T.STRING_VALUE_ FROM JBPM4_VARIABLE T" + " WHERE T.EXECUTION_ = ? AND t.key_ = ?";
|
Object[] values = { executionId, varName };
|
res = (String) new JDBCTemplate().run(new JDBCCallback(new HibernateTemplate().getSessionConnection(), sql,
|
JDBCRunType.SQL, -1, false, false, values) {
|
@Override
|
public Object execute(ResultSet paramResultSet) throws SQLException {
|
String ress = "";
|
while (paramResultSet.next()) {
|
ress = paramResultSet.getString(1);
|
}
|
return ress;
|
}
|
});
|
return res;
|
}
|
|
@SuppressWarnings("unchecked")
|
public List<String> getTasksNameByProcessName(final String[] processNames) throws SQLException {
|
return (List<String>) new HibernateTemplate().run(new HibernateCallback() {
|
public Object execute() throws HibernateException {
|
List<String> nameList = new LinkedList<String>();
|
for (int i = 0; i < processNames.length; i++) {
|
TasksAssigned task = getTasksAssignedByUserName(processNames[i]);
|
nameList.add(processNames[i]);
|
if (task.getId() != null && task.getId() != "") {
|
String[] name = task.getTasksName().split(",");
|
for (int j = 0; j < name.length; j++) {
|
nameList.add(name[j]);
|
}
|
}
|
}
|
return nameList;
|
}
|
});
|
}
|
|
/**
|
*
|
* <p>
|
* Description: 查看已办任务的详细信息
|
* </p>
|
*
|
* @time 2013-4-11
|
* @param executionId
|
* @return
|
* @throws VCIError
|
*/
|
public String searchComplateTask(String[] params) {
|
// TODO 待处理
|
// TaskMgrControlClient client = new TaskMgrControlClient();
|
// TaskMgrControlPortType service = client.getTaskMgrControlHttpPort();
|
// String complateRes = service.completeTask(params[0], params[1],
|
// params[2]);
|
// return complateRes;
|
return "";
|
}
|
|
/**
|
* 通过流程数据获取流程实例
|
*
|
* @param dataId
|
* @param tableName
|
* @return
|
*/
|
public FlowTaskInfo[] getFlowTaskInfoByDataId(String dataId, String tableName) {
|
List<FlowTaskInfo> flowTaskInfos = new ArrayList<FlowTaskInfo>();
|
StringBuilder sql = new StringBuilder();
|
// sql.append("select k.start_ as createTime, k.id_ as EXECUTION_,PLDESC,plprocesstype, processname,k.state_ as state_,PLTEMPLATENAME from (select e.plexecutionid as EXECUTION_,e.PLDESC as PLDESC, e.plprocesstype as plprocesstype,e.processname as processname,e.PLTEMPLATENAME as PLTEMPLATENAME from plflowobject pb,plflowinstance e where pb.plexecutionid = e.plexecutionid and pb.plobjectid = ? and e.pltablename = ?) a left join jbpm4_hist_procinst k on a.EXECUTION_ = k.id_ order by createTime desc");
|
sql.append(
|
"select k.start_ as createTime, k.id_ as EXECUTION_,PLDESC,plprocesstype, processname,k.state_ as state_,PLTEMPLATENAME from (select e.plexecutionid as EXECUTION_,e.PLDESC as PLDESC, e.plprocesstype as plprocesstype,e.processname as processname,e.PLTEMPLATENAME as PLTEMPLATENAME from plflowobject pb,plflowinstance e where pb.plexecutionid = e.plexecutionid and pb.plobjectid = ? ) a left join jbpm4_hist_procinst k on a.EXECUTION_ = k.id_ order by createTime desc");
|
ServerWithLog4j.logger.debug("getFlowTaskInfoByDataId sql=" + sql);
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
createSQLQuery.setString(0, dataId);
|
// createSQLQuery.setString(1, tableName);
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
List list = createSQLQuery.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] object = (Object[]) list.get(i);
|
FlowTaskInfo flowTaskInfo = new FlowTaskInfo();
|
String taskId = "";
|
|
String taskName = "";
|
Timestamp createTime = (Timestamp) object[0];
|
String executionId = String.valueOf(object[1]);
|
String desc = (String) object[2];
|
String processType = (String) object[3];
|
String processName = (String) object[4];
|
String flowState = (String) object[5];
|
String pltemplatename = (String) object[6];
|
|
// 获得发起人名称
|
List<FlowApproveHistory> historyActivityByProInsId = this.getHistoryActivityByExcetionID(session,
|
executionId);
|
if (historyActivityByProInsId != null && historyActivityByProInsId.size() > 0) {
|
String assignee = historyActivityByProInsId.get(0).getAssignee();
|
flowTaskInfo.plAssgin = assignee == null ? "" : assignee;
|
}
|
|
flowTaskInfo.id = taskId == null ? "" : taskId;
|
flowTaskInfo.name = taskName == null ? "" : taskName;
|
flowTaskInfo.createTime = createTime.getTime();
|
flowTaskInfo.executionId = executionId == null ? "" : executionId;
|
flowTaskInfo.desc = desc == null ? "" : desc;
|
flowTaskInfo.processType = processType == null ? "" : processType;
|
flowTaskInfo.flowState = flowState == null ? "" : flowState;
|
flowTaskInfo.processName = processName == null ? "" : processName;
|
flowTaskInfo.templateName = pltemplatename == null ? "" : pltemplatename;
|
flowTaskInfos.add(flowTaskInfo);
|
}
|
} catch (Exception ex) {
|
// ex.printStackTrace();
|
ServerWithLog4j.logger.error("getFlowTaskInfoByDataId", ex);
|
} finally {
|
|
}
|
|
return flowTaskInfos.toArray(new FlowTaskInfo[0]);
|
}
|
|
public String[] getFlowTaskInfoByDataIds(String[] dataIds, String tableName) {
|
List<String> res = new ArrayList<String>();
|
try {
|
for (int d = 0; d < dataIds.length; d++) {
|
String executionId = "";
|
StringBuilder sql = new StringBuilder();
|
sql.append(
|
"select k.start_ as createTime, k.id_ as EXECUTION_,PLDESC,plprocesstype, processname,k.state_ as state_,PLTEMPLATENAME from (select e.plexecutionid as EXECUTION_,e.PLDESC as PLDESC, e.plprocesstype as plprocesstype,e.processname as processname,e.PLTEMPLATENAME as PLTEMPLATENAME from plflowobject pb,plflowinstance e where pb.plexecutionid = e.plexecutionid and pb.plobjectid = ? and e.pltablename = ?) a left join jbpm4_hist_procinst k on a.EXECUTION_ = k.id_ order by createTime desc");
|
ServerWithLog4j.logger.debug("getFlowTaskInfoByDataId sql=" + sql);
|
Session session = HibernateSessionFactory.getSession();
|
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
createSQLQuery.setString(0, dataIds[d]);
|
createSQLQuery.setString(1, tableName);
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
List list = createSQLQuery.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] object = (Object[]) list.get(i);
|
FlowTaskInfo flowTaskInfo = new FlowTaskInfo();
|
|
executionId = String.valueOf(object[1]);
|
|
}
|
res.add(executionId);
|
}
|
} catch (Exception ex) {
|
// ex.printStackTrace();
|
ServerWithLog4j.logger.error("getFlowTaskInfoByDataIds", ex);
|
} finally {
|
|
}
|
|
return res.toArray(new String[] {});
|
}
|
|
/**
|
* 给任务设置候选人,用在分支下的多个任务的候选人设置
|
*
|
* @param excutionId
|
* @param taskNames
|
* @param users
|
* @return
|
*/
|
public boolean setTasksAssignForFork(String excutionId, String[] taskNames, String[][] users) {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
EnvironmentImpl envImpl = ((EnvironmentFactory) processEngine).openEnvironment();
|
Execution processInstance = processEngine.getExecutionService().findExecutionById(excutionId)
|
.getProcessInstance();
|
String proccessInstanceId = processInstance.getId();
|
ExecutionImpl execution = (ExecutionImpl) processEngine.getExecutionService()
|
.findProcessInstanceById(proccessInstanceId);
|
TaskService taskService = processEngine.getTaskService();
|
// 根据执行id获取任务对象列表
|
List<Task> taskList = taskService.createTaskQuery().processInstanceId(execution.getId()).list();
|
for (Task task : taskList) {
|
for (int i = 0; i < taskNames.length; i++) {
|
if (taskNames[i].equals(task.getName())) {
|
for (int j = 0; j < users[i].length; j++) {
|
taskService.addTaskParticipatingUser(task.getId(), users[i][j], Participation.CANDIDATE);
|
}
|
}
|
}
|
}
|
|
return true;
|
}
|
|
/**
|
* 获取流程名称
|
*
|
* @param executionid
|
* @return
|
*/
|
public String getProcessName(String executionid) {
|
StringBuilder sql = new StringBuilder();
|
sql.append("select b.processname from plflowinstance b where b.plexecutionid = ?");
|
ServerWithLog4j.logger.debug("getFlowTaskInfoByDataId sql=" + sql);
|
Session session = HibernateSessionFactory.getSession();
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
createSQLQuery.setString(0, executionid);
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List list = createSQLQuery.list();
|
String res = "";
|
for (int i = 0; i < list.size(); i++) {
|
Object[] object = (Object[]) list.get(i);
|
String processName = (String) object[0];
|
res = processName == null ? "" : processName;
|
}
|
return res;
|
}
|
|
/**
|
* 流程任务对象
|
*
|
* @param exectionId
|
* @param taskid
|
* @return
|
*/
|
public FlowTaskInfo getFlowTaskInfo(String exectionId, String taskid) {
|
FlowTaskInfo flowTaskInfo = new FlowTaskInfo();
|
|
StringBuilder sql = new StringBuilder();
|
sql.append("select * from jbpm4_hist_task a where a.execution_ = ? and a.dbid_ = ? ");
|
|
Session session = HibernateSessionFactory.getSession();
|
try {
|
SQLQuery createSQLQuery = session.createSQLQuery(sql.toString());
|
createSQLQuery.setString(0, exectionId);
|
createSQLQuery.setString(1, taskid);
|
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
//无意义代码
|
// createSQLQuery.executeUpdate();
|
List list = createSQLQuery.list();
|
for (int i = 0; i < list.size(); i++) {
|
Object[] object = (Object[]) list.get(i);
|
flowTaskInfo = new FlowTaskInfo();
|
Timestamp endtime = (Timestamp) object[8];
|
if (endtime != null) {
|
flowTaskInfo.endTime = endtime.getTime();
|
}
|
}
|
} catch (Exception ex) {
|
// ex.printStackTrace();
|
ServerWithLog4j.logger.error("getFlowTaskInfo", ex);
|
} finally {
|
|
}
|
return flowTaskInfo;
|
}
|
|
public static void main(String[] args) {
|
// ProcessTemplateService p = new ProcessTemplateService();
|
// FlowTaskInfo[] todoTaskCompositorByUserId = p
|
// .getTodoTaskCompositorByUserId("1", 0, 0, "", "",
|
// "");
|
// System.out.println();
|
// String[] taskNames = new String[]{"任务2","任务3"};
|
// String[][] users = new String[][]{new String[]{"user1","user2"},new
|
// String[]{"user3","user4"}};
|
|
// p.setTasksAssign("测试分支.880001.880028", taskNames, users);
|
|
// p.fetchEventForTrainstion("VPM模板.850001", "会签", "编辑");
|
// BigDecimal jbpmDeploymentId = p.getDeploymentID("分支测试-1");
|
// try {
|
// String[] allTaskNames =
|
// p.getAllTaskNames(String.valueOf(jbpmDeploymentId));
|
// for(String s : allTaskNames){
|
//
|
// System.out.println("s="+s);
|
// }
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// }
|
//
|
// p.transmitTask("60009", "test4");
|
// ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
// TaskService taskService = processEngine.getTaskService();
|
// taskService.removeTaskParticipatingUser("2260004",
|
// "test1",
|
// Participation.CANDIDATE);
|
// taskService.assignTask("2260004", "test4");
|
// p.getTodoTaskByUserId("test1", 1, 100, "", "and taskName = '订货'");
|
// p.startPocessSetUser("", var, objId, userNames, outcome,
|
// taskAndUserMap);
|
// p.getForkTaskNames("130001", "审批1", "同意");
|
|
// p.transmitTask("20016", "developer");
|
// try {
|
// String[] allTaskNames = p.getNextTaskNames("260080", "判断", "");
|
//
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// }
|
// try {
|
// String[] curConstituents = p.getCurConstituents("20018", "任务", "");
|
// System.out.println();
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// }
|
// try {
|
// String[] trainsitionUrlPath = p.getTrainsitionUrlPath("200001",
|
// "任务","");
|
// } catch (Exception e) {
|
//
|
// e.printStackTrace();
|
// }
|
// String groupNames =
|
// HibernateSessionFactory.getVciSessionInfo().userName;
|
// System.out.println(groupNames);
|
|
// try {
|
// byte[] processResource = p.getProcessResource("1680001", ".xml");
|
// InputStream in = new ByteArrayInputStream(processResource);
|
// BufferedReader reader = new BufferedReader(new InputStreamReader(
|
// in, "utf-8"));
|
//
|
// SAXReader saxr = new SAXReader();
|
// Document doc = saxr.read(reader);
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// }
|
}
|
|
public String startProcessAndExecuteFirstNode(String processDefinitionKey, FlowInstanceInfo var, String[] objId,
|
UserEntityInfo userEntityInfo, String[] userNames, String outcome, Map<String, String[]> taskAndUserMap,
|
Map<String, Object> variables, String[] objectProperty, String[][] objectPropertyValues) throws VCIError {
|
String processInstanceId = "";
|
processInstanceId = startPocessByPLM_v1(processDefinitionKey, var, objId, userNames, outcome, taskAndUserMap,
|
variables, objectProperty, objectPropertyValues, userEntityInfo, true);
|
|
String jbpmDeploymentId = String.valueOf(getDeploymentID(processDefinitionKey));
|
try {
|
String[] allTasknames;
|
allTasknames = getAllTaskNames(jbpmDeploymentId);
|
String taskId = getTaskId(allTasknames[0], processInstanceId);
|
String nextTaskName = getNextTaskNameByJbpmId(jbpmDeploymentId, allTasknames[0], outcome);
|
String nextNode = getNextSubTaskAssigner(processInstanceId, nextTaskName, outcome);
|
String[] nextUser = nextNode.split(",");
|
boolean bool = completeTaskByPlatform_v1(taskId, "", nextTaskName, "同意", userEntityInfo, nextUser,
|
objectProperty, objectPropertyValues);
|
} catch (Exception e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("startProcessAndExecuteFirstNode", e);
|
if (e.getCause() != null && e.getCause() instanceof VCIError) {
|
throw (VCIError) e.getCause();
|
}
|
throw ServerErrorTool.getVCIError("发起流程后,执行第一个流程节点过程中出现错误!", e);
|
}
|
|
return processInstanceId;
|
}
|
|
public String startPocessByPLM_v1(String processDefinitionKey, FlowInstanceInfo var, String[] objId,
|
String[] userNames, String outcome, Map<String, String[]> taskAndUserMap, Map<String, Object> variables,
|
String[] objectProperty, String[][] objectPropertyValues, UserEntityInfo userEntityInfo) throws VCIError {
|
return startPocessByPLM_v1(processDefinitionKey, var, objId, userNames, outcome, taskAndUserMap, variables,
|
objectProperty, objectPropertyValues, userEntityInfo, false);
|
}
|
|
public String startPocessByPLM_v1(String processDefinitionKey, FlowInstanceInfo var, String[] objId,
|
String[] userNames, String outcome, Map<String, String[]> taskAndUserMap, Map<String, Object> variables,
|
String[] objectProperty, String[][] objectPropertyValues, UserEntityInfo userEntityInfo, boolean autoFirst)
|
throws VCIError {
|
|
// modify by weidy@2022-04-29
|
// 增加了autoFirst
|
String processInstanceId = "";
|
try {
|
ProcessEngine processEngine = JbpmEngine.getProcessEngine();
|
variables.put("process_applicant", var.applicant);
|
|
// 获取当前登录用户信息,在此处可能出现错误
|
// variables.put("userName", getUserEntity().getUserName());
|
variables.put("userName", userEntityInfo.userName);
|
variables.put("var", var);
|
|
variables.put("globalParam", var.partList == null ? "" : var.partList);
|
// List<String> participants = new ArrayList<String>();
|
// for (String participant : userNames) {
|
// participants.add(participant);
|
// }
|
// variables.put("participants", participants);
|
|
String deploymentId = getdeploymentIdBySql(processDefinitionKey);
|
|
ProcessTask ptask = getFirstProcessTask(deploymentId);
|
if (ptask == null)
|
return "";
|
|
String fTask = ptask.getTaskName();
|
List<String> participants = new ArrayList<String>();
|
if (taskAndUserMap.containsKey(fTask)) {
|
for (String participant : taskAndUserMap.get(fTask)) {
|
participants.add(participant);
|
}
|
} else {
|
for (String participant : userNames) {
|
participants.add(participant);
|
}
|
}
|
variables.put("participants", participants);
|
|
// 流程数据ID列表
|
variables.put("objId", objId);
|
variables.put("objectProperty", objectProperty);
|
variables.put("objectPropertyValues", objectPropertyValues);
|
if (objectPropertyValues != null) {
|
for (int i = 0; i < objectPropertyValues.length; i++) {
|
String oid = "";
|
Map<String, String> cMap = new HashMap<String, String>();
|
for (int j1 = 0; j1 < objectPropertyValues[i].length; j1++) {
|
cMap.put(objectProperty[j1], objectPropertyValues[i][j1]);
|
if (oid.equals("") && "Oid".equals(objectProperty[j1])) {
|
oid = objectPropertyValues[i][j1];
|
}
|
// variables .put(objectProperty[j1], new
|
// String[]{objectPropertyValues[i][j1]});
|
}
|
variables.put(oid, cMap);
|
}
|
}
|
// String deploymentId = getdeploymentIdBySql(processDefinitionKey);
|
|
ServerWithLog4j.logger.debug("startProcessInstanceById开始!");
|
ProcessInstance processInstance = processEngine.getExecutionService()
|
.startProcessInstanceById(processDefinitionKey, variables);
|
ServerWithLog4j.logger.debug("startProcessInstanceById结束!");
|
FlowInstance flowInstance = new FlowInstance();
|
String flowInstanceId = ObjectUtility.getNewObjectID36();
|
flowInstance.setId(flowInstanceId);
|
processInstanceId = processInstance.getId();
|
// 流程启动时,设置任务与候选人之间的关系。
|
configTaskAndUser(processEngine, deploymentId, processInstance.getId(), objId, taskAndUserMap);
|
|
flowInstance.setExecutionid(processInstanceId);
|
flowInstance.setApplicant(var.applicant);
|
flowInstance.setCreator(var.creator);
|
flowInstance.setTemplatePuid(var.templatePuid);
|
flowInstance.setTemplateName(var.templateName);
|
flowInstance.setClsfOid(var.clsfOid);
|
flowInstance.setTableName(var.tableName);
|
flowInstance.setDesc(var.desc);
|
String processType = var.processType;
|
flowInstance.setProcessType(processType);
|
flowInstance.setProcessName(var.processName);
|
flowInstance.setTaskType(var.taskType);
|
|
// 设置当前登录用户,由前端传递
|
UserEntity loginUserEntity = new UserEntity();
|
loginUserEntity.setUserName(userEntityInfo.userName);
|
loginUserEntity.setIp(userEntityInfo.ip);
|
loginUserEntity.setModule(userEntityInfo.modules);
|
flowInstance.setUserEntity(loginUserEntity);
|
|
// 设置当前登录用户,可能出现错误,
|
// if (getUserEntity().getUserName().equals(var.creator)) {
|
// flowInstance.setUserEntity(loginUserEntity);
|
// }
|
|
FlowInstanceDaoImpl impl = new FlowInstanceDaoImpl();
|
impl.save(flowInstance);// 保存流程实例的变量
|
|
// 插入流程数据对象表
|
// int length = objId.length;
|
// for (int i = 0; i < length; i++) {
|
// PLFlowObject flowObject = new PLFlowObject();
|
// flowObject.setPloid(ObjectUtility.getNewObjectID36());
|
// flowObject.setPlexecutionid(processInstanceId);
|
// flowObject.setPlobjectid(objId[i]);
|
// flowObject.setPlprocesstype(processType);
|
// flowObject.setInitStatus("");
|
// PLFlowObjectDaoImpl flowObjectDaoImpl = new PLFlowObjectDaoImpl();
|
// flowObjectDaoImpl.save(flowObject);
|
// }
|
//没用代码
|
PLFlowObjectDaoImpl flowObjectDaoImpl = new PLFlowObjectDaoImpl();
|
for (int j = 0; j < objectPropertyValues.length; j++) {
|
PLFlowObject flowObject = new PLFlowObject();
|
flowObject.setPloid(ObjectUtility.getNewObjectID36());
|
flowObject.setPlexecutionid(processInstanceId);
|
for (int j1 = 0; j1 < objectPropertyValues[j].length; j1++) {
|
String value = objectPropertyValues[j][j1];
|
String filed = objectProperty[j1].toLowerCase();
|
if ("Oid".toLowerCase().equals(filed)) {
|
flowObject.setPlobjectid(value);
|
} else if ("BTMName".toLowerCase().equals(filed)) {
|
flowObject.setPlprocesstype(value);
|
}
|
flowObject.setInitStatus("");
|
}
|
flowObjectDaoImpl.save(flowObject);
|
}
|
// workflowinstance业务类型目前是在workitem中保存数据的,但是如果第一个节点有多个处理人时,就会出现多条相同的数据。
|
// weidy@2018-08-22 由此修改到此处保存
|
if (isWorkFlowInstanceExist()) {
|
cunstructWorkFlowInstanceObj(processInstanceId, var.processName, var.desc, var.tableName, objId);
|
}
|
TaskService taskService = processEngine.getTaskService();
|
Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).uniqueResult();
|
List<Task> subTasks = taskService.getSubTasks(task.getId());
|
if (subTasks.size() > 0) {
|
for (int i = 0; i < subTasks.size(); i++) {
|
Task subTask = subTasks.get(i);
|
for (Entry<String, String[]> es : taskAndUserMap.entrySet()) {
|
String key = es.getKey();
|
if (key.equals(task.getName())) {
|
String taskId = subTask.getId();
|
String executionid = subTask.getExecutionId();
|
|
// 如果配置了用户选择插件,则执行以下操作
|
String userServiceImplClass = WorkflowProperties.getStringProperty("workflow.userService");
|
|
if (userServiceImplClass != null && !"".equals(userServiceImplClass)) {
|
IWorkflowUserService puService = (IWorkflowUserService) (Class
|
.forName(userServiceImplClass).newInstance());
|
String[] value = es.getValue();
|
String[] canditates = new String[value.length];
|
for (int j = 0; j < value.length; j++) {
|
canditates[j] = value[j];
|
}
|
// userNames = puService.getAllUsers2Task(canditates, getUserEntity().getModule());
|
userNames = puService.getAllUsers2Task(canditates, userEntityInfo.modules);
|
}
|
|
// 出差设置的候选人
|
List<String> taskassignList = new ArrayList<String>();
|
|
for (int k = 0; k < userNames.length; k++) {
|
String un = userNames[k];
|
String taskassign = "";
|
if (autoFirst && un.equalsIgnoreCase(userEntityInfo.userName)) {
|
// 第一节点自动提交,又是当前用户,不取代理人
|
taskassign = un;
|
} else {
|
TasksAssigned tasksAssignedByUserName = getTasksAssignedByUserName(un);
|
taskassign = tasksAssignedByUserName.getTasksName();
|
if (taskassign == null || "".equals(taskassign)) {
|
taskassign = un;
|
}
|
|
}
|
String[] split = taskassign.split(",");
|
for (String s : split) {
|
if (!taskassignList.contains(s)) {
|
taskassignList.add(s);
|
}
|
}
|
}
|
if (taskassignList != null && taskassignList.size() > 0) {
|
userNames = taskassignList.toArray(new String[0]);
|
}
|
|
for (int k = 0; k < userNames.length; k++) {
|
|
List<Participation> taskParticipations = taskService.getTaskParticipations(taskId);
|
// 先删除原来的任务候选人
|
if (k == 0) {
|
if (userNames.length == 1) {
|
subTask.setAssignee(userNames[k]);
|
}
|
for (Participation participation : taskParticipations) {
|
taskService.removeTaskParticipatingUser(taskId, participation.getUserId(),
|
Participation.CANDIDATE);
|
}
|
}
|
|
String subAssign = subTask.getAssignee();
|
String parsSubAssign = subAssign.substring(subAssign.indexOf(":") + 1,
|
subAssign.length());
|
if (parsSubAssign.equals(userNames[k])) {
|
taskService.addTaskParticipatingUser(taskId, userNames[k], Participation.CANDIDATE);
|
|
if (workitemClass != null && !"".equals(workitemClass)) {
|
|
callPLMworkitemSave_v1(var, objId, userNames, subTask, taskId, executionid, k,
|
variables, objectProperty, objectPropertyValues);
|
}
|
}
|
}
|
}
|
|
}
|
}
|
} else {
|
for (Entry<String, String[]> es : taskAndUserMap.entrySet()) {
|
String key = es.getKey();
|
if (key.equals(task.getName())) {
|
|
String taskId = task.getId();
|
String executionid = task.getExecutionId();
|
|
// 如果配置了用户选择插件,则执行以下操作
|
String userServiceImplClass = WorkflowProperties.getStringProperty("workflow.userService");
|
|
if (userServiceImplClass != null && !"".equals(userServiceImplClass)) {
|
IWorkflowUserService puService = (IWorkflowUserService) (Class.forName(userServiceImplClass)
|
.newInstance());
|
String[] value = es.getValue();
|
String[] canditates = new String[value.length];
|
for (int i = 0; i < value.length; i++) {
|
canditates[i] = value[i];
|
}
|
// userNames = puService.getAllUsers2Task(canditates, getUserEntity().getModule());
|
userNames = puService.getAllUsers2Task(canditates, userEntityInfo.modules);
|
}
|
// 出差设置的候选人
|
List<String> taskassignList = new ArrayList<String>();
|
for (int k = 0; k < userNames.length; k++) {
|
String taskassign = "";
|
String un = userNames[k];
|
if (autoFirst && un.equalsIgnoreCase(userEntityInfo.userName)) {
|
// 第一节点自动提交,又是当前用户,不取代理人
|
taskassign = un;
|
} else {
|
TasksAssigned tasksAssignedByUserName = getTasksAssignedByUserName(un);
|
taskassign = tasksAssignedByUserName.getTasksName();
|
if (taskassign == null || "".equals(taskassign)) {
|
taskassign = un;
|
}
|
}
|
String[] split = taskassign.split(",");
|
for (String s : split) {
|
if (!taskassignList.contains(s)) {
|
taskassignList.add(s);
|
}
|
}
|
}
|
if (taskassignList != null && taskassignList.size() > 0) {
|
userNames = taskassignList.toArray(new String[0]);
|
}
|
for (int k = 0; k < userNames.length; k++) {
|
|
List<Participation> taskParticipations = taskService.getTaskParticipations(taskId);
|
// 先删除原来的任务候选人
|
if (k == 0) {
|
if (userNames.length == 1) {
|
task.setAssignee(userNames[k]);
|
}
|
for (Participation participation : taskParticipations) {
|
taskService.removeTaskParticipatingUser(taskId, participation.getUserId(),
|
Participation.CANDIDATE);
|
}
|
}
|
taskService.addTaskParticipatingUser(taskId, userNames[k], Participation.CANDIDATE);
|
|
if (workitemClass != null && !"".equals(workitemClass)) {
|
|
callPLMworkitemSave_v1(var, objId, userNames, task, taskId, executionid, k, variables,
|
objectProperty, objectPropertyValues);
|
}
|
}
|
}
|
}
|
}
|
return processInstanceId;
|
} catch (VCIError e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("startPocessByPLM_v1-1", e);
|
throw e;
|
} catch (Exception e) {
|
// e.printStackTrace();
|
ServerWithLog4j.logger.error("startPocessByPLM_v1-2", e);
|
if (e.getCause() != null && e.getCause() instanceof VCIError) {
|
throw (VCIError) e.getCause();
|
}
|
throw ServerErrorTool.getVCIError("启动流程的过程中出现错误!" + e.toString(), e);
|
}
|
}
|
|
private void cunstructWorkFlowInstanceObj(String executionid, String processName, String desc, String btmType,
|
String[] oids) throws VCIError {
|
// ����workflowinstance����
|
long d = System.currentTimeMillis();
|
|
BusinessObject wfInstanceBo = ServerServiceProvider.getBOFService().initBusinessObject("workflowinstance");
|
|
// BusinessObject wfInstanceBo =
|
// bofBoDelegate.initBusinessObject("workflowinstance".toLowerCase());
|
wfInstanceBo.id = ObjectUtility.getNewObjectID36();
|
wfInstanceBo.name = processName;
|
wfInstanceBo.description = desc;
|
wfInstanceBo.lcStatus = "Executing";
|
ObjectTool.setBOAttributeValue(wfInstanceBo, "executionid".toLowerCase(), executionid);
|
|
// BOFactoryServerDelegate bofDelegate = BOFactoryServerDelegate.getInstance();
|
|
BusinessObject[] toBos = ServerServiceProvider.getBOFService().getBatchBusinessObject(oids, btmType);
|
List<LinkObject> linkObjectList = new ArrayList<LinkObject>();
|
|
// LOFacotryServerLODelegate loDelegate =
|
// LOFacotryServerLODelegate.getInstance();
|
// 每次初始化链接类型都比较耗时,所以初始化一次后,后面都执行拷贝
|
LinkObject inputLo = null;
|
for (int j = 0; j < toBos.length; j++) {
|
LinkObject clo = null;
|
clo = ServerServiceProvider.getBOFService().initLinkObject("input");
|
|
ObjectTool.setLOAttributeValue(clo, "linkdescription".toLowerCase(), desc);
|
ObjectTool.setLOFromBO(clo, wfInstanceBo);
|
ObjectTool.setLOToBO(clo, toBos[j]);
|
linkObjectList.add(clo);
|
}
|
|
BusinessObject[] bos = new BusinessObject[] { wfInstanceBo };
|
// BusinessObjectListHolder hbos = new BusinessObjectListHolder();
|
// hbos.value = new BusinessObject[] { wfInstanceBo };
|
//
|
// LinkObjectListHolder hlos = new LinkObjectListHolder();
|
// hlos.value = linkObjectList.toArray(new LinkObject[0]);
|
LinkObject[] los = linkObjectList.toArray(new LinkObject[0]);
|
|
ServerServiceProvider.getBOFService().batchCreateBusinessObjectWithLink(bos, los);
|
|
long e = System.currentTimeMillis();
|
ServerWithLog4j.logger.debug("保存流程实例和数据的链接耗时:" + (e - d));
|
}
|
|
/**
|
* 重新设置节点负责人
|
*
|
* @param executionId
|
* @param taskNames
|
* @param userNames
|
* @return
|
* @throws VCIError
|
*/
|
public boolean resetNodeUser(String executionId, String[] taskNames, String[] userNames) throws VCIError {
|
boolean bool = false;
|
if (taskNames != null && taskNames.length != 0) {
|
for (int i = 0; i < taskNames.length; i++) {
|
String formatName = taskNames[i];
|
String user = userNames[i];
|
String sql = "update jbpm4_taskanduserconfigex set username = '" + user + "' where processinstansid = '"
|
+ executionId + "' and taskname = '" + formatName + "'";
|
HibernateSessionFactory.getSession().createSQLQuery(sql).executeUpdate();
|
}
|
bool = true;
|
}
|
return bool;
|
}
|
}
|