Spring管理流程部署——Activiti
pom.xml
<!-- activit jar 包 -->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
<version>5.19.0.2</version>
</dependency> <dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring</artifactId>
<version>5.19.0.2</version>
</dependency> <dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-bpmn-model</artifactId>
<version>5.19.0.2</version>
</dependency>
<!-- spring整合activiti插件 -->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring</artifactId>
<version>5.19.0.3</version>
</dependency>
----------
spring 管理activiti
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.1.xsd"> <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"> <!-- 连接数据库的配置 -->
<property name="jdbcDriver" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="jdbcUrl" value="jdbc:oracle:thin:@10.2.13.100:1521:orcl"></property>
<property name="jdbcUsername" value="cyqq"></property>
<property name="jdbcPassword" value="1"></property> <!-- 没有表创建表 -->
<property name="databaseSchemaUpdate" value="true"></property>
</bean> <!-- 创建流程引擎对象 -->
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration" ref="processEngineConfiguration" />
</bean> <!-- 由流程引擎对象,提供的方法,创建项目中使用的Activiti工作流的Service -->
<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
<bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
<bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
<bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
<bean id="formService" factory-bean="processEngine" factory-method="getFormService" /> <!-- 将Activiti工作流的Service注入WrokflowService中 -->
<bean id="changeWorkflowService" class="com.chen.workflowservice.impl.ChangeWorkFlowService">
<property name="repositoryService" ref="repositoryService"></property>
<property name="runtimeService" ref="runtimeService"></property>
<property name="taskService" ref="taskService"></property>
<property name="formService" ref="formService"></property>
<property name="historyService" ref="historyService"></property>
</bean>
</beans>
ChangeWorkFlowService
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipInputStream; import javax.servlet.http.HttpServletResponse; import org.activiti.engine.FormService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.impl.RepositoryServiceImpl;
import org.activiti.engine.impl.bpmn.behavior.UserTaskActivityBehavior;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity;
import org.activiti.engine.impl.pvm.PvmActivity;
import org.activiti.engine.impl.pvm.PvmTransition;
import org.activiti.engine.impl.pvm.process.ActivityImpl;
import org.activiti.engine.impl.task.TaskDefinition;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.Execution;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task; import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.tcinc.cyqq.model.other.TP_BUSINESS;
import com.tcinc.cyqq.workflowservice.IWorkflowService; public class ChangeWorkFlowService implements IWorkflowService {
/** 创建工作流Service */
public RepositoryService repositoryService;// 流程定义
public RuntimeService runtimeService;// 运行时
public TaskService taskService;// 任务
public FormService formService;// 任务表单
public HistoryService historyService;// 历史 public void setRepositoryService(RepositoryService repositoryService) {
this.repositoryService = repositoryService;
} public void setRuntimeService(RuntimeService runtimeService) {
this.runtimeService = runtimeService;
} public void setTaskService(TaskService taskService) {
this.taskService = taskService;
} public void setFormService(FormService formService) {
this.formService = formService;
} public void setHistoryService(HistoryService historyService) {
this.historyService = historyService;
} /*-------------------------------------方法实现------------------------------------*/ /*----------------------------------------- 接口实现 ----------------------------------------*/ @Override
public void deploy(String deployBpmn, String deployPng, String deployName) {
try {
repositoryService.createDeployment()
// 创建部署对象
.name(deployName).addClasspathResource(deployBpmn)
.addClasspathResource(deployPng).deploy();// 完成部署
} catch (Exception ex) {
ex.printStackTrace();
}
} @Override
public void deploy(File file, String deployName) {
try {
ZipInputStream zipInputStream = new ZipInputStream(
new FileInputStream(file));
repositoryService.createDeployment().name(deployName)
.addZipInputStream(zipInputStream).deploy();
} catch (Exception ex) {
ex.printStackTrace();
}
} @Override
public void delDeployGeneral(String deployId) {
try {
// 普通删除,如果当前规则下有正在执行的流程,则抛异常
repositoryService.deleteDeployment(deployId);
} catch (Exception ex) {
ex.printStackTrace();
}
} @Override
public void delDeployCascade(String deployId) {
try {
// 级联删除,会删除和当前规则相关的所有信息,包括历史
repositoryService.deleteDeployment(deployId, true);
} catch (Exception ex) {
ex.printStackTrace();
}
} @Override
public List<Deployment> findDeploymentList() {
List<Deployment> list = null;
try {
list = repositoryService.createDeploymentQuery()
.orderByDeploymenTime().asc().list();
} catch (Exception ex) {
ex.printStackTrace();
}
return list;
} @Override
public List<Deployment> findDeploymentList(String deployName) {
List<Deployment> list = null;
try {
list = repositoryService.createDeploymentQuery()
.deploymentName(deployName).orderByDeploymenTime().asc()
.list();
} catch (Exception ex) {
ex.printStackTrace();
}
return list;
} @Override
public Deployment findDeployment(String deployName) {
Deployment deployment = null;
try {
deployment = repositoryService.createDeploymentQuery()
.deploymentName(deployName).orderByDeploymenTime().desc()
.singleResult();
} catch (Exception ex) {
ex.printStackTrace();
}
return deployment;
} @Override
public List<ProcessDefinition> findProcessDefinitionList() {
List<ProcessDefinition> list = null;
try {
list = repositoryService.createProcessDefinitionQuery()
.orderByProcessDefinitionVersion().asc().list();
} catch (Exception ex) {
ex.printStackTrace();
}
return list;
} @Override
public ProcessDefinition findProcessDefinition(String deployId) {
ProcessDefinition processDefinition = null;
try {
processDefinition = repositoryService
.createProcessDefinitionQuery().deploymentId(deployId)
.orderByProcessDefinitionVersion().desc().singleResult();
} catch (Exception ex) {
ex.printStackTrace();
}
return processDefinition;
} @Override
public String findProcessKey(String deployName) {
Deployment deployment = findDeployment(deployName);
ProcessDefinition pd = findProcessDefinition(deployment.getId()); return pd.getKey();
} @Override
public ActivityImpl findTaskNode(String processInstanceId) {
ExecutionEntity execution = null;
ProcessDefinitionEntity processDefinitionEntity = null;
ActivityImpl activity = null;
try {
// 获取流程发布Id信息
String definitionId = getDefinitionId(processInstanceId); processDefinitionEntity = getProcessDefinitionEntity(definitionId); execution = getExecutionEntity(processInstanceId); // 获取流程所有节点信息
List<ActivityImpl> activitiList = processDefinitionEntity
.getActivities(); // 遍历所有节点信息
for (ActivityImpl activityImpl : activitiList) {
// 找到当前节点信息
if (execution.getActivityId().equals(activityImpl.getId())) {
activity = activityImpl;
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
return activity;
} @Override
public ProcessDefinition findProcessDefinitionByPid(String processInstanceId) {
ProcessDefinitionEntity processDefinitionEntity = null;
ProcessDefinition processDefinition = null;
try {
// 获取流程发布Id信息
String definitionId = getDefinitionId(processInstanceId); processDefinitionEntity = getProcessDefinitionEntity(definitionId); String deploymentId = processDefinitionEntity.getDeploymentId(); processDefinition = getProcessDefinition(deploymentId); } catch (Exception ex) {
ex.printStackTrace();
}
return processDefinition;
} @Override
public ProcessDefinition findProcessDefinitionByHistory(
String processInstanceId) {
ProcessDefinitionEntity processDefinitionEntity = null;
ProcessDefinition processDefinition = null;
try {
// 获取流程发布Id信息
String definitionId = getDefinitionIdByHistory(processInstanceId); processDefinitionEntity = getProcessDefinitionEntity(definitionId); String deploymentId = processDefinitionEntity.getDeploymentId(); processDefinition = getProcessDefinition(deploymentId); } catch (Exception ex) {
ex.printStackTrace();
}
return processDefinition;
} @Override
public List<Task> findTaskListByRole(String roleId) {
List<Task> list = taskService.createTaskQuery()
.taskCandidateUser(roleId).orderByTaskCreateTime().asc().list(); return list;
} @Override
public String findCompleteTaskByUser(String userId, String chartId) {
List<HistoricTaskInstance> list = historyService
.createHistoricTaskInstanceQuery().taskAssignee(userId).list();
HistoricProcessInstance hi = null;
ProcessDefinition pd = null; StringBuilder businessIds = new StringBuilder();
String str = "";
for (HistoricTaskInstance ti : list) {
hi = getHistoricProcessInstance(ti.getProcessInstanceId().trim());
pd = getProcessDefinitionByDe(hi.getProcessDefinitionId().trim()); if (!pd.getKey().trim().equals(chartId))
continue; str = "'"
+ hi.getBusinessKey().trim()
.replace(pd.getKey().trim() + ".", "") + "',";
if (!businessIds.toString().contains(str)) {
businessIds.append(str);
}
} str = businessIds.toString().trim();
if (!"".equals(str) && str.endsWith(",")) {
str = str.substring(0, str.length() - 1);
} return str;
} @Override
public InputStream findImageInputStream(String deploymentId,
String imageName) {
return repositoryService.getResourceAsStream(deploymentId, imageName);
} @Override
public Page<TP_BUSINESS> findBusiness(int pageNumber, int pageSize,
String roleId) {
return null;
} @Override
public ProcessInstance startProcess(String key) {
System.out.println("key...................................");
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(key);
System.out.println(processInstance);
// 获取任务对象
return processInstance;
} @Override
public Map<String, Object> findCoording(String processInstanceId) {
// 存放坐标
Map<String, Object> map = new HashMap<String, Object>();
// 使用任务ID,查询任务对象
Task task = getTask(processInstanceId); // 获取流程定义的ID
String processDefinitionId = task.getProcessDefinitionId();
// 获取流程定义的实体对象,(对应.bpmn文件中的数据)
ProcessDefinitionEntity processDefinitionEntity = getProcessDefinitionEntity(processDefinitionId); // 使用流程实例ID,查询正在执行的对象表,获取当前活动对应的流程实例对象
ProcessInstance pi = getProcessInstance(processInstanceId); // 获取当前活动的ID
String activityId = pi.getActivityId();
// 获取当前活动对象
ActivityImpl activityImpl = processDefinitionEntity
.findActivity(activityId);
// 获取坐标
map.put("x", activityImpl.getX());
map.put("y", activityImpl.getY());
map.put("width", activityImpl.getWidth());
map.put("height", activityImpl.getHeight());
return map;
} @Override
public List<Map<String, Object>> findCoordings(String deploymentId) {
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> map = null;
ProcessDefinition pd = getProcessDefinition(deploymentId);
ProcessDefinitionEntity processDefinition = getProcessDefinitionEntity(pd
.getId());
List<ActivityImpl> activitiList = processDefinition.getActivities(); for (ActivityImpl activity : activitiList) {
map = new HashMap<String, Object>();
map.put("x", activity.getX());
map.put("y", activity.getY());
map.put("width", activity.getWidth());
map.put("height", activity.getHeight());
map.put("taskId", activity.getId());
map.put("taskName", activity.getProperty("name"));
map.put("processKey", pd.getKey()); list.add(map);
} return list;
} @Override
public boolean finishTask(String processInstanceId, String lineName,
String userId) {
String taskId = "";
Map<String, Object> variables = new HashMap<String, Object>(); // 使用任务ID,查询任务对象
Task task = getTask(processInstanceId); taskId = task.getId().trim(); // 拾取办理人
taskService.claim(taskId, userId); // 设置连线名称
variables.put("msg", lineName); // 完成任务
taskService.complete(taskId, variables); // 判断流程是否结束
ProcessInstance pi = getProcessInstance(processInstanceId); if (pi == null) {
return true;
} return false;
} @Override
public TaskDefinition getNextTaskDefinition(String processInstanceId,
String msg) { String activityId = ""; String definitionId = getDefinitionId(processInstanceId); ProcessDefinitionEntity processDefinitionEntity = getProcessDefinitionEntity(definitionId); ExecutionEntity execution = getExecutionEntity(processInstanceId); activityId = execution.getActivityId(); ActivityImpl activityImpl = processDefinitionEntity
.findActivity(activityId);// 当前节点 // 获取当前节点连线所有集合
List<PvmTransition> pvmTransitions = activityImpl
.getOutgoingTransitions(); for (PvmTransition pvmTransition : pvmTransitions) {
PvmActivity pa = pvmTransition.getDestination();// 获取所有的终点节点 if ("userTask".equals(pa.getProperty("type"))) {
return ((UserTaskActivityBehavior) ((ActivityImpl) pa)
.getActivityBehavior()).getTaskDefinition();
}
} return null;
} @Override
public Map<String, String> isEndTask(String processInstanceId, String msg) { Map<String, String> map = new HashMap<String, String>();
map.put("isEnd", "false"); String activityId = ""; String definitionId = getDefinitionId(processInstanceId); ProcessDefinitionEntity processDefinitionEntity = getProcessDefinitionEntity(definitionId); ExecutionEntity execution = getExecutionEntity(processInstanceId); activityId = execution.getActivityId(); ActivityImpl activityImpl = processDefinitionEntity
.findActivity(activityId);// 当前节点 // 获取当前节点连线所有集合
List<PvmTransition> pvmTransitions = activityImpl
.getOutgoingTransitions(); for (PvmTransition pvmTransition : pvmTransitions) {
PvmActivity pa = pvmTransition.getDestination();// 获取所有的终点节点
// 获取连线名
String condition = pvmTransition.getProperty("conditionText")
.toString().trim().replace("${msg==", "").replace("}", "")
.replace("'", ""); if (msg.equals(condition)) {
if ("endEvent".equals(pa.getProperty("type"))) {
map.put("isEnd", "true");
map.put("node", pa.getId().trim());
return map;
}
}
} return map;
} /*---------------------------------------------------常用方法-----------------------------------------------*/ /**
* 根据流程实例 ID,获取流程定义ID
*
* @param processInstanceId
* 流程实例ID
* @return
*/
public String getDefinitionId(String processInstanceId) {
String definitionId = "";
ProcessInstance pi = runtimeService.createProcessInstanceQuery()
.processInstanceId(processInstanceId).singleResult();
definitionId = pi.getProcessDefinitionId().trim(); return definitionId;
} /**
* 根据流程实例ID,获取流程定义ID(历史表)
*
* @param processInstanceId
* @return
*/
public String getDefinitionIdByHistory(String processInstanceId) {
String definitionId = "";
HistoricProcessInstance pi = historyService
.createHistoricProcessInstanceQuery()
.processInstanceId(processInstanceId).singleResult();
definitionId = pi.getProcessDefinitionId().trim();
return definitionId;
} /**
* 根据流程定义ID,获取流程定义对象实体
*
* @param definitionId
* 流程定义ID
* @return
*/
public ProcessDefinitionEntity getProcessDefinitionEntity(
String definitionId) {
ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)
.getDeployedProcessDefinition(definitionId); return processDefinitionEntity;
} /**
* 根据流程部署ID,获取流程定义对象实体
*
* @param deploymentId
* 流程部署ID
* @return
*/
public ProcessDefinition getProcessDefinition(String deploymentId) {
ProcessDefinition processDefinition = repositoryService
.createProcessDefinitionQuery().deploymentId(deploymentId)
.singleResult(); return processDefinition;
} /**
* 根据流程定义ID,获取流程定义对象实体
*
* @param deploymentId
* 流程定义ID
* @return
*/
public ProcessDefinition getProcessDefinitionByDe(String processDefinitionId) {
ProcessDefinition processDefinition = repositoryService
.createProcessDefinitionQuery()
.processDefinitionId(processDefinitionId).singleResult(); return processDefinition;
} /**
* 根据流程实例ID,获取任务
*
* @param processInstanceId
* 流程实例ID
* @return
*/
public Task getTask(String processInstanceId) {
Task task = taskService.createTaskQuery()
.processInstanceId(processInstanceId).singleResult(); return task;
} /**
* 根据流程实例ID,获取运行时对象实体
*
* @param processInstanceId
* 流程实例ID
* @return
*/
public ExecutionEntity getExecutionEntity(String processInstanceId) {
ExecutionEntity execution = (ExecutionEntity) runtimeService
.createProcessInstanceQuery()
.processInstanceId(processInstanceId).singleResult(); return execution;
} /**
* 使用流程实例ID,查询正在执行的对象表,获取当前活动对应的流程实例对象
*
* @param processInstanceId
* 流程实例ID
* @return
*/
public ProcessInstance getProcessInstance(String processInstanceId) {
ProcessInstance processInstance = runtimeService
.createProcessInstanceQuery()
.processInstanceId(processInstanceId).singleResult(); return processInstance;
} /**
* 使用流程实例ID,查询历史流程实例
*
* @param processInstanceId
* @return
*/
public HistoricProcessInstance getHistoricProcessInstance(
String processInstanceId) {
HistoricProcessInstance historicProcessInstance = historyService
.createHistoricProcessInstanceQuery()
.processInstanceId(processInstanceId).singleResult();
return historicProcessInstance;
} /**
* 通过流程定义的key,级联删除流程
*
* @param processKey
* 流程定义key
*/
public void deleteDeploy(String processKey) {
List<ProcessDefinition> pdList = repositoryService// 获取Service
.createProcessDefinitionQuery()// 创建流程定义查询
.processDefinitionKey(processKey)// 通过key查询
.list();// 返回一个集合
for (ProcessDefinition pd : pdList) {
repositoryService// 获取Service
.deleteDeployment(pd.getDeploymentId(), true);
} } /**
* 根据流程实例id,得到当前任务
* @param processInstanceId 流程实例id
* @return
*/
public Task findTask(String processInstanceId) {
return taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
} /**
* 根据流程实例id,得到上一个已完成节点
* @param processInstanceId
* @return
*/
public HistoricActivityInstance findLastTask(String processInstanceId) {
//得到以完成的上一任务节点
List<HistoricActivityInstance> haList=historyService.createHistoricActivityInstanceQuery().processInstanceId(processInstanceId).finished().orderByHistoricActivityInstanceEndTime().desc().list();
//已完成的上一任务
HistoricActivityInstance ha = haList.get(0);
return ha;
} @Override
public Execution getExecution(String processInstanceId) {
return runtimeService.createExecutionQuery()
.processInstanceId(processInstanceId)
.singleResult();
} @Override
public HistoricTaskInstance findLastHistTask(String processInstanceId) {
List<HistoricTaskInstance> list = historyService.createHistoricTaskInstanceQuery()
.processInstanceId(processInstanceId)
.orderByHistoricTaskInstanceEndTime()
.desc()
.list();
return list.get(0);
}
/**
* 通过流程定义key,得到所有节点数量和节点字符串
* @param processKey 流程定义key
* @return
* @throws Exception
*/
public Object[] getNodeId(String processKey){
// 得到流程部署实例(得到部署最新的那一个流程)
Deployment deployment =repositoryService.createDeploymentQuery().processDefinitionKey(processKey).orderByDeploymenTime().desc().list().get(0);
// 得到流程定义实例
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
//得到流程定义实体
ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService)
.getDeployedProcessDefinition(processDefinition.getId());
List<ActivityImpl> activitiList = processDefinitionEntity.getActivities();
// 初始化节点集合
List<String> nodeList = new ArrayList<String>();
for (ActivityImpl activity : activitiList) {
nodeList.add(activity.getId());
}
StringBuffer nodeId = new StringBuffer();
for (String node : nodeList) {
nodeId.append("'").append(node).append("',");
}
Object[] obj = new Object[]{nodeList.size(),nodeId.substring(0, nodeId.length() - 1)};
return obj;
} @Override
public List<TP_BUSINESS> getApplyList(List<TP_BUSINESS> list, String currentUserId, String currentUserName) {
if (list != null && list.size() > 0) {
for (int i = 0; i < list.size(); i++) {
// 获取流程实例Id
String processInstanceId = list.get(i).get("PI_ID");
// 设置办理人为当前登录用户
list.get(i).set("CURRENTUSER", currentUserName);
// 判断流程是否结束,如果结束则标志为完成
// 通过流程实例id查找正在执行的对象
Execution execution = runtimeService.createExecutionQuery().processInstanceId(processInstanceId)
.singleResult();
String status = "";
if (execution != null) {
status = "在办";
} else {
status = "完成";
}
list.get(i).set("AUDIT_STATUS", status);
}
}
return list;
} @Override
public String getActId(String processInstanceId) {
String actId = "";
// 通过流程实例id获取流程实例对象
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
.processInstanceId(processInstanceId).singleResult();
if (processInstance != null) {
actId = processInstance.getActivityId();
}
return actId;
} @Override
public List<TP_BUSINESS> getWaitList(List<TP_BUSINESS> list, String currentUserId, String currentUserName) {
if(list != null && list.size() > 0) {
for(int i=0; i<list.size(); i++) {
//流程实例id
String pi_id = list.get(i).get("pi_id");
//设置当前办理人名称
list.get(i).set("CURRENTUSER", currentUserName);
//查询当前流程的历史任务
List<HistoricTaskInstance> hisList = historyService.createHistoricTaskInstanceQuery()
.processInstanceId(pi_id)
.orderByHistoricTaskInstanceEndTime()
.desc()
.list();
if(hisList != null && hisList.size() > 0) {
//设置上一个环节名称
list.get(i).set("LAST_LINK", hisList.get(0).getName());
//设置上个环节提交时间
list.get(i).set("LAST_LINK_DATE", hisList.get(0).getEndTime());
//得到上个办理人id
String lastAsseId = hisList.get(0).getAssignee();
List<Record> userList = Db.find("SELECT REAL_NAME FROM SYS_USER WHERE ID='"+lastAsseId+"'");
if(userList != null && userList.size() > 0) {
//设置上个办理人名称
list.get(i).set("LAST_LINK_APPLICANT", userList.get(0).get("real_name"));
} }
if(list.get(i).get("AUDIT_STATUS").equals("1")) {
list.get(i).set("AUDIT_STATUS", "在办");
}else {
list.get(i).set("AUDIT_STATUS", "完结");
}
}
}
return list;
} @Override
public InputStream viewImg(String processInstanceId) {
InputStream in = null;
// 获取流程实例对象
HistoricProcessInstance processinstance = historyService.createHistoricProcessInstanceQuery()
.processInstanceId(processInstanceId)
.singleResult();
if (processinstance != null) {
// 获取流程定义id
String processDefinitionId = processinstance.getProcessDefinitionId();
// 获取流程定义对象
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
.processDefinitionId(processDefinitionId).singleResult();
// 部署id
String deployId = processDefinition.getDeploymentId();
// 文件名称
String imgName = processDefinition.getDiagramResourceName();
// 获取输入流
in = repositoryService.getResourceAsStream(deployId, imgName);
}
return in;
} @Override
public Execution getCurrentExecution(String processInstanceId) {
Execution execution = runtimeService.createExecutionQuery()
.processInstanceId(processInstanceId)
.singleResult();
return execution;
}
@Override
public boolean completeProcess(String processInstanceId,String status,String currentUserId) {
boolean result = false;
String elString="${message=='完成'}";
Map<String,Object> variables = new HashMap<String, Object>();
Task task = taskService.createTaskQuery()
.processInstanceId(processInstanceId)
.singleResult();
if(task != null) {
//获取任务id
String taskId = task.getId();
//拾取任务
if(task.getAssignee() == null) {
//采用当前要用户拾取任务
taskService.claim(taskId, currentUserId);
}
//得到下一个节点id
String nextActId = this.viewNextAct(processInstanceId, elString);
//如果下一个节点id是endevent1(结束节点),则根据status判断是同意还是拒绝用于最后是否保存数据
if(nextActId.toString().trim().equals("endevent1")) {
variables.put("message", "完成");
}else {
variables.put("message", status);
}
taskService.complete(taskId,variables);
result = true;
}
return result;
} @Override
public String viewNextAct(String processInstanceId, String elString) {
String nextActId = "";
//获取流程实例对象
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
.processInstanceId(processInstanceId)
.singleResult(); if(processInstance != null) {
//获取当前节点id
String activityId = processInstance.getActivityId();
//获取流程定义id
String processDefinitionId = processInstance.getProcessDefinitionId();
//获取流程定义实体对象
ProcessDefinitionEntity processDefinitionEntity= (ProcessDefinitionEntity)repositoryService.getProcessDefinition(processDefinitionId);
if(processDefinitionEntity != null) {
//获取当前节点对象
ActivityImpl activityImpl = processDefinitionEntity.findActivity(activityId);
if(activityImpl != null) {
//得到当前节点所有出线信息
List<PvmTransition> pvmList = activityImpl.getOutgoingTransitions();
if(pvmList != null && pvmList.size() > 1) {
for(PvmTransition pvm:pvmList) {
//得到连线的表达式
String conditionText = (String)pvm.getProperty("conditionText");
//看得到的连线名称和传递过来的名称是否匹配
if(elString.equals(conditionText)) {
ActivityImpl a = (ActivityImpl)pvm.getDestination();
//获取下一个节点的id
nextActId = a.getId();
}
}
}
}
}
}
return nextActId;
} @Override
public boolean revoke(String processInstanceId) {
// 根据流程实例id获取任务对象
Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
String taskId = task.getId();
// 结束流程时设置流程变量
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("message", "撤销");
taskService.complete(taskId, variables);
// 查看流程是否结束(execution为空则结束)
Execution execution = runtimeService.createExecutionQuery().processInstanceId(processInstanceId).singleResult();
if (execution == null) {
return true;
} else {
return false;
}
}
/**
* 查看流程图的当前活动节点
* @param taskId 任务id
* @return [0]x、[1]y、[2]width、[3]height、[4]流程部署id、[5]资源图片路径
* @throws Exception
*/
public Object[] showCurrentView(String processInstanceId) throws Exception{
//无论流程是否走完,得到的都是最后一条记录(ACT_HI_TASKINST)
HistoricTaskInstance h = historyService.createHistoricTaskInstanceQuery().processInstanceId(processInstanceId).list().get(0);
String processDefinitionId = h.getProcessDefinitionId();//得到流程定义id
//流程定义实体
ProcessDefinitionEntity pdm = (ProcessDefinitionEntity) repositoryService.getProcessDefinition(processDefinitionId);
ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); /*因为activiti框架的缓存会话机制,所以我在这个位置将“流程部署id和支援图片路径取出来”*/
ProcessDefinition pd = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId.trim()).singleResult();
String deploymentId = pd.getDeploymentId(); //流程部署id
String diagramResourceName = pd.getDiagramResourceName(); //流程资源图片路径
/*因为activiti框架的缓存会话机制,所以我在这个位置将“流程部署id和支援图片路径取出来”*/ Object[] view = new Object[6];
view[4] = deploymentId;
view[5] = diagramResourceName;
//因为有可能流程已经走完,所有还是判断哈,免得空指针异常
if(pi != null){
ActivityImpl ai = pdm.findActivity(pi.getActivityId());
//根据活动ID 获取活动实例
ActivityImpl activityImpl = pdm.findActivity(pi.getActivityId());
view[0] = activityImpl.getX();
view[1] = activityImpl.getY();
view[2] = activityImpl.getWidth(); //宽度
view[3] = activityImpl.getHeight(); //高度
} return view;
}
/**
* 查看流程图
* @param deploymentId 流程部署id
* @param diagramResourceName 资源图片名称
* @param response 将数据向页面输出
* @throws IOException
*/
public void showView(String deploymentId,String diagramResourceName,HttpServletResponse response) throws Exception{
//调用接口得到流程图
InputStream inputStream = repositoryService.getResourceAsStream(deploymentId, diagramResourceName);
OutputStream out = response.getOutputStream();
for(int b = -1;(b=inputStream.read())!=-1;){
out.write(b);
}
out.close();
inputStream.close();
}
}
web.xml
<!-- 加载Spring容器配置 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- 设置Spring容器加载所有的配置文件的路径 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:activiti-context.xml</param-value>
</context-param>
Spring管理流程部署——Activiti的更多相关文章
- Activiti第二篇【管理流程定义、执行任务和流程实例、流程变量】
上篇Activiti只是一个快速入门案例,这篇就讲定义.部署.查看任务等等的一些细节[涉及到的数据库表.对象等等]- 管理流程定义 管理流程定义主要涉及到以下的4张表: -- 流程部署相关的表 SEL ...
- Activiti 流程部署方式 activi 动态部署(高级源码篇)
Activiti的流程 部署方式有很多种方式,我们可以根据activit工作流引擎提供的ap方式进行部署. 当然了实际需求决定你要使用哪一种api操作,后面的总结详细介绍了使用场景. 下面看一下部署方 ...
- Activiti 流程部署方式 activi 动态部署(高级源代码篇)
Activiti的流程 部署方式有非常多种方式,我们能够依据activit工作流引擎提供的ap方式进行部署. 当然了实际需求决定你要使用哪一种api操作,后面的总结具体介绍了使用场景. 以下看一下部署 ...
- activiti 流程部署的各种方式
流程资源可以是各种类型的文件,在启动流程或流程实例运行过程中会被读取.下面介绍常用的流程资源. 一.流程资源 流程定义文件:扩展名为bpmn20.xml和bpmn; 流程定义的图片:用BPMN2.0规 ...
- activiti 流程部署 保存流程图到数据库 保存二进制图片 存储失败
activiti 流程部署 保存流程图到数据库 保存二进制图片 存储失败 具体错误如下 具体 junit测试 结果 :提示如下: 解决方法: 数据库版本不同 无法保存二进制文件到数据库表中!5.5. ...
- Flowable实战(三)流程部署管理
一.流程定义的版本 当部署流程定义时,数据库中的流程定义会是这个样子: id key name version myProcess:1:676 myProcess My important pro ...
- Activiti系列:带有serviceTask的或者定时启动任务的流程部署失败的原因分析
在将两个带有serviceTask任务的流程部署到数据库的时候发现无法导入,最终分析出如下问题: 1)流程1是打算让定时启动事件可以每小时触发一次 由于原来是用 R/2015-11-01T01:00: ...
- 流程开发Activiti 与SpringMVC整合实例
流程(Activiti) 流程是完成一系列有序动作的概述.每一个节点动作的结果将对后面的具体操作步骤产生影响.信息化系统中流程的功能完全等同于纸上办公的层级审批,尤其在oa系统中各类电子流提现较为明显 ...
- Spring 管理数据源
Spring 管理数据源 不管通过何种持久化技术,都必须通过数据连接访问数据库,在Spring中,数据连接是通过数据源获得的.在以往的应用中,数据源一般是Web应用服务器提供的.在Spring中,你不 ...
随机推荐
- Objective-C学习笔记(二十二)——初始化方法init的重写与自己定义
初学OC.对init这种方法不是非常了解.我们如今来分别对init方法进行重写以及自己定义,来加深对他的了解. 本样例也是用Person类来进行測试. (一)重写init方法. (1)在Person. ...
- rsync与cwRsync
以下这个链接是windows之间的csRsync和csRsyncServer同步教程: http://www.cnblogs.com/wwufengg/p/rsync-config.html !Att ...
- 微信企业号开发:UserAgent
userAgent 属性是一个仅仅读的字符串,声明了浏览器用于 HTTP 请求的用户代理头 的值.微信企业号的打开网页的userAgent又包括那些信息呢? 使用userAgent能够推断用户訪问的浏 ...
- PHP独立操作符
& 与 ^ 位逻辑异或 $ # ! 逻辑或 ~ 按位取反
- POJ1151 Atlantis 扫描线算法
题目大意 给出几个矩形对角端点坐标,求这些矩形整体覆盖的面积. 扫描线算法 整个平面被每个矩形的水平边所在直线(以后简称“水平线”)分成了几个部分,而整体覆盖面积则为每相邻的两个水平线间夹的长度(以后 ...
- Linux安装sshfs挂载远程目录到本地及卸载
挂载远程目录的方式很多,这里把sshfs记录一下备忘.Linux用sshfs挂载远程目录到本地 安装sshfs 在Ubuntu下,只需要使用 $ sudo apt-get install sshfs ...
- HttpServletRequest对象小结
当客户端通过HTTP协议访问服务器时,请求所有信息都封装在HttpServletRequest对象中,可通过它获取到请求的所有信息,其常用方法如下: getRequestURL方法返回客户端发出请求时 ...
- 922. 按奇偶排序数组 II
给定一个非负整数数组 A, A 中一半整数是奇数,一半整数是偶数. 对数组进行排序,以便当 A[i] 为奇数时,i 也是奇数:当 A[i] 为偶数时, i 也是偶数. 你可以返回任何满足上述条件的数组 ...
- SwiftUI 官方教程(七)
7. 给子 View 传递数据 LandmarkDetail 现在依然使用硬编码的数据来显示地标.像 LandmarkRow 一样,LandmarkDetail 类型和它组合的其他 view 都需要一 ...
- TYVJ 1941 BZOJ3038 上帝造题的七分钟2 并查集+树状数组
背景 XLk觉得<上帝造题的七分钟>不太过瘾,于是有了第二部. 描述 "第一分钟,X说,要有数列,于是便给定了一个正整数数列. 第二分钟,L说,要能修改,于是便有了对一段数中每个 ...