Commit 9bc06c27 by 罗绍泽

流程引擎简单回退功能实现

parent 32302264
......@@ -15,22 +15,30 @@ $(function(){
field : 'ACTIVITY_NAME',
title : '环节名称',
width : 200,
align : 'center',
align : 'center'
}, {
field : 'ASSIGNEE',
title : '办理人',
width : 200,
align : 'center',
align : 'center'
// }, {
// field : 'IS_BACK',
// title : '特殊',
// width : 250,
// align : 'center',
// formatter:function(value,row,index){
// return value==1?"回退":"正常";
// }
}, {
field : 'START_TIME',
title : '开始时间',
width : 250,
align : 'center',
align : 'center'
}, {
field : 'END_TIME',
title : '结束时间',
width : 250,
align : 'center',
align : 'center'
} ] ],
onLoadSuccess : function() {
if(is_opetipmenuwidth==null){
......
......@@ -178,6 +178,13 @@ function updateDataToNext(is_entity){
return v_result;
}
//退回按钮执行事件
function backProc(is_entity){
v_result = proctaskModule.act.back(is_entity);
$('#list').datagrid('reload');
return v_result;
}
/****/
/**
......
package com.gaowj.activiti.cmd;
import java.util.Iterator;
import java.util.Map;
import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.activiti.engine.impl.persistence.entity.ExecutionEntityManager;
import org.activiti.engine.impl.persistence.entity.TaskEntity;
import org.activiti.engine.impl.pvm.process.ActivityImpl;
public class NodeJumpTaskCmd implements Command<Void> {
protected String executionId;// 执行ID
protected ActivityImpl desActivity; // 目标引擎对象
protected Map<String, Object> paramvar;// 变量
protected ActivityImpl currentActivity;// 当前引擎对象
protected String deleteReason = "completed";
/**
* 构造参数 可以根据自己的业务需要添加更多的字段
*
* @param executionId
* @param desActivity
* @param paramvar
* @param currentActivity
*/
public NodeJumpTaskCmd(String executionId, ActivityImpl desActivity, Map<String, Object> paramvar, ActivityImpl currentActivity) {
this.executionId = executionId;
this.desActivity = desActivity;
this.paramvar = paramvar;
this.currentActivity = currentActivity;
}
public NodeJumpTaskCmd(String executionId, ActivityImpl desActivity, Map<String, Object> paramvar, ActivityImpl currentActivity, String deleteReason) {
this.executionId = executionId;
this.desActivity = desActivity;
this.paramvar = paramvar;
this.currentActivity = currentActivity;
this.deleteReason = deleteReason;
}
/**
* 获取执行实体管理 获取当前的任务执行对象 设置对应的值 获取当前的任务 删除 执行目标工作流
*/
@Override
public Void execute(CommandContext commandContext) {
// 获取执行实体管理
ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
// 根据ExecutionID 查找执行实体 获取当前流程的executionId,因为在并发的情况下executionId是唯一的。
ExecutionEntity executionEntity = executionEntityManager.findExecutionById(executionId);
executionEntity.setVariables(paramvar);
executionEntity.setEventSource(this.currentActivity);
executionEntity.setActivity(this.currentActivity);
// 获取当前ExecutionID的任务 根据executionId 获取Task
Iterator<TaskEntity> localIterator = commandContext.getTaskEntityManager().findTasksByExecutionId(this.executionId).iterator();
while (localIterator.hasNext()) {
TaskEntity taskEntity = (TaskEntity) localIterator.next();
// 触发任务监听
taskEntity.fireEvent("complete");
// 删除任务的原因
commandContext.getTaskEntityManager().deleteTask(taskEntity, this.deleteReason, false);
}
executionEntity.executeActivity(this.desActivity);
System.out.println();
return null;
}
}
......@@ -9,13 +9,11 @@ import org.activiti.engine.HistoryService;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.task.IdentityLink;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.gaowj.business.ProcdefiChooseUserBusiness;
import com.gaowj.business.ProcinstanceBusiness;
import com.gaowj.business.comp.BusinessManager;
import com.gaowj.business.util.SessionUtil;
/**
......
......@@ -20,6 +20,7 @@ import org.activiti.engine.TaskService;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.task.Task;
import org.activiti.image.impl.DefaultProcessDiagramGenerator;
import org.apache.ibatis.session.RowBounds;
......@@ -32,6 +33,7 @@ import com.gaowj.business.system.SystemBackDAO;
import com.gaowj.business.util.Page;
import com.gaowj.business.util.SessionUtil;
import com.gaowj.business.utils.ActivitiTools;
import com.gaowj.business.utils.model.ActivitiOptEnum;
import com.gaowj.business.utils.model.ActivitiResultEnum;
public class ProcinstanceBusinessImpl implements ProcinstanceBusiness {
......@@ -157,7 +159,7 @@ public class ProcinstanceBusinessImpl implements ProcinstanceBusiness {
@Override
public Map<String, Object> update_proc_instance(Map<String, Object> entity) throws ActivitiException,BusinessException {
ActivitiResultEnum activitiResultEnum = ActivitiTools.save(entity, false);
ActivitiResultEnum activitiResultEnum = ActivitiTools.save(entity, ActivitiOptEnum.SAVE);
switch (activitiResultEnum) {
case OK:
break;
......@@ -169,7 +171,7 @@ public class ProcinstanceBusinessImpl implements ProcinstanceBusiness {
@Override
public Map<String, Object> update_proc_instance_next(Map<String, Object> entity) throws ActivitiException,BusinessException {
ActivitiResultEnum activitiResultEnum = ActivitiTools.save(entity, true);
ActivitiResultEnum activitiResultEnum = ActivitiTools.save(entity, ActivitiOptEnum.SAVE_AND_NEXT);
switch (activitiResultEnum) {
case OK:
break;
......@@ -289,13 +291,7 @@ public class ProcinstanceBusinessImpl implements ProcinstanceBusiness {
// 只显示userTask类型
continue;
}
/*
* if(hai.getActivityName()==null){ continue; }
*/
/*
* if(hai.getAssignee()==null&&hai.getEndTime()!=null){
* //如果没有办理人,但是有结束时间,任务该环节是开始环节,默认剔除 continue; }
*/
if (hai.getAssignee() != null) {
listAssignee.add(hai.getAssignee());
}
......
......@@ -32,6 +32,7 @@ import com.gaowj.business.procinstance.procinstanceDAO;
import com.gaowj.business.util.Page;
import com.gaowj.business.util.SessionUtil;
import com.gaowj.business.utils.ActivitiTools;
import com.gaowj.business.utils.model.ActivitiOptEnum;
import com.gaowj.business.utils.model.ActivitiResultEnum;
public class ProctaskBusinessImpl implements ProctaskBusiness {
......@@ -232,7 +233,7 @@ public class ProctaskBusinessImpl implements ProctaskBusiness {
@Override
public Map<String, Object> update(Map<String, Object> entity) throws ActivitiException, BusinessException {
ActivitiResultEnum activitiResultEnum = ActivitiTools.save(entity, false);
ActivitiResultEnum activitiResultEnum = ActivitiTools.save(entity, ActivitiOptEnum.SAVE);
switch (activitiResultEnum) {
case OK:
break;
......@@ -244,7 +245,7 @@ public class ProctaskBusinessImpl implements ProctaskBusiness {
@Override
public Map<String, Object> updateToNext(Map<String, Object> entity) throws ActivitiException, BusinessException {
ActivitiResultEnum activitiResultEnum = ActivitiTools.save(entity, true);
ActivitiResultEnum activitiResultEnum = ActivitiTools.save(entity, ActivitiOptEnum.SAVE_AND_NEXT);
switch (activitiResultEnum) {
case OK:
break;
......@@ -256,147 +257,15 @@ public class ProctaskBusinessImpl implements ProctaskBusiness {
@Override
public Map<String, Object> back(Map<String, Object> entity) throws BusinessException {
// 存储自定义表单的业务数据
update_custom_business(entity.get("TABLE_ID_SYSTEM").toString(), entity);
// 通过任务id获取流程id
String taskId = entity.get("TASK_ID_SYSTEM").toString();
// 退回当前任务
taskRollBack(taskId);
return entity;
}
private void update_proc_instance(Map<String, Object> entity) {
Map<String, Object> entity2 = new HashMap<String, Object>();
entity2.put("UUID", entity.get("UUID"));
if (entity.keySet() != null) {
List<Map<String, Object>> info = new ArrayList<Map<String, Object>>();
entity2.put("info", info);
Set<String> key = entity.keySet();
for (String str : key) {
if ("UUID".equals(str)) {
continue;
}
Map<String, Object> colum = new HashMap<String, Object>();
colum.put("key", str);
colum.put("value", entity.get(str));
info.add(colum);
}
}
procinstanceDAO.update_proc_instance(entity2);
}
private String update_custom_business(String tableId, Map<String, Object> entity) {
entity.remove("TABLE_ID_SYSTEM");
if (entity.get("UUID") == null) {
entity.put("UUID", java.util.UUID.randomUUID().toString());
}
if (entity.get("CREATE_TIME") == null) {
entity.put("CREATE_TIME", new Date());
}
if (entity.get("CREATE_ID") == null) {
entity.put("CREATE_ID", SessionUtil.getCode());
}
if (entity.get("UPDATE_ID") == null) {
entity.put("UPDATE_ID", SessionUtil.getCode());
}
if (entity.get("UPDATE_TIME") == null) {
entity.put("UPDATE_TIME", new Date());
ActivitiResultEnum activitiResultEnum = ActivitiTools.save(entity, ActivitiOptEnum.SAVE_AND_RALLBACK);
switch (activitiResultEnum) {
case OK:
break;
default:
throw new ActivitiException(activitiResultEnum.getMsg());
}
Map<String, Object> query = new HashMap<String, Object>();
query.put("UUID", tableId);
// 动态传值插入
List<Map<String, Object>> infoList = new ArrayList<Map<String, Object>>();
// List<String> infoListKey = new ArrayList<String>();
if (entity.keySet() != null) {
Set<String> key = entity.keySet();
// 将map集合中的key和value 取出来分别放到list集合里
for (String str : key) {
// UUID不需要加进去
if ("UUID".equals(str)) {
continue;
}
Map<String, Object> kv = new HashMap<String, Object>();
kv.put("value", entity.get(str));
kv.put("key", str);
infoList.add(kv);
}
entity.put("infoList", infoList);
}
/*
* List<Object> infoList = new ArrayList<Object>(); if (entity.keySet()
* != null) { Set<String> key = entity.keySet(); // 将map集合中的key和value
* 取出来分别放到list集合里 for (String str : key) {
* infoList.add(entity.get(str)); infoListKey.add(str); }
* entity.put("infoListKey", infoListKey); entity.put("infoList",
* infoList); }
*/
// 设置表名
String tableName = formtableDAO.list_form_table(query).get(0).get("TABLE_NAME").toString();
entity.put("tableName", tableName);
entity.put("uuid", entity.get("UUID"));
procdefinitionDAO.update_custom_business(entity);
return entity.get("UUID").toString();
return entity;
}
private void taskRollBack(String taskId) {
try {
Map<String, Object> variables;
// 取得当前任务
HistoricTaskInstance currTask = historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult();
// 取得流程实例
ProcessInstance instance = runtimeService.createProcessInstanceQuery().processInstanceId(currTask.getProcessInstanceId()).singleResult();
if (instance == null) {
// 流程结束
}
variables = instance.getProcessVariables();
// 取得流程定义
ProcessDefinitionEntity definition = (ProcessDefinitionEntity) (repositoryService.getProcessDefinition(currTask.getProcessDefinitionId()));
if (definition == null) {
// log.error("流程定义未找到");
return;
}
// 取得上一步活动
ActivityImpl currActivity = ((ProcessDefinitionImpl) definition).findActivity(currTask.getTaskDefinitionKey());
List<PvmTransition> nextTransitionList = currActivity.getIncomingTransitions();
// 清除当前活动的出口
List<PvmTransition> oriPvmTransitionList = new ArrayList<PvmTransition>();
List<PvmTransition> pvmTransitionList = currActivity.getOutgoingTransitions();
for (PvmTransition pvmTransition : pvmTransitionList) {
oriPvmTransitionList.add(pvmTransition);
}
pvmTransitionList.clear();
// 建立新出口
List<TransitionImpl> newTransitions = new ArrayList<TransitionImpl>();
for (PvmTransition nextTransition : nextTransitionList) {
PvmActivity nextActivity = nextTransition.getSource();
ActivityImpl nextActivityImpl = ((ProcessDefinitionImpl) definition).findActivity(nextActivity.getId());
TransitionImpl newTransition = currActivity.createOutgoingTransition();
newTransition.setDestination(nextActivityImpl);
newTransitions.add(newTransition);
}
// 完成任务
List<Task> tasks = taskService.createTaskQuery().processInstanceId(instance.getId()).taskDefinitionKey(currTask.getTaskDefinitionKey()).list();
for (Task task : tasks) {
taskService.complete(task.getId(), variables);
historyService.deleteHistoricTaskInstance(task.getId());
}
// 恢复方向
for (TransitionImpl transitionImpl : newTransitions) {
currActivity.getOutgoingTransitions().remove(transitionImpl);
}
for (PvmTransition pvmTransition : oriPvmTransitionList) {
pvmTransitionList.add(pvmTransition);
}
return;
} catch (Exception e) {
return;
}
}
}
......@@ -8,17 +8,32 @@ import java.util.Map;
import java.util.Set;
import org.activiti.engine.HistoryService;
import org.activiti.engine.ManagementService;
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.HistoricIdentityLink;
import org.activiti.engine.history.HistoricTaskInstance;
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.pvm.process.ProcessDefinitionImpl;
import org.activiti.engine.impl.pvm.process.TransitionImpl;
import org.activiti.engine.runtime.Execution;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.ContextLoaderListener;
import com.gaowj.activiti.cmd.NodeJumpTaskCmd;
import com.gaowj.business.ProcdefiChooseUserBusiness;
import com.gaowj.business.formtable.formtableDAO;
import com.gaowj.business.procdefinition.procdefinitionDAO;
import com.gaowj.business.procinstance.procinstanceDAO;
import com.gaowj.business.util.SessionUtil;
import com.gaowj.business.utils.model.ActivitiOptEnum;
import com.gaowj.business.utils.model.ActivitiResultEnum;
/**
......@@ -31,18 +46,24 @@ public class ActivitiTools {
private static HistoryService historyService;
private static TaskService taskService;
private static RuntimeService runtimeService;
private static RepositoryService repositoryService;
private static ManagementService managementService;
private static procdefinitionDAO procdefinitionDAO;
private static formtableDAO formtableDAO;
private static procinstanceDAO procinstanceDAO;
private static ProcdefiChooseUserBusiness procdefiChooseUserBusiness;
static {
ApplicationContext context = ContextLoaderListener.getCurrentWebApplicationContext();
historyService = (HistoryService) context.getBean("historyService");
taskService = (TaskService) context.getBean("taskService");
runtimeService = (RuntimeService) context.getBean("runtimeService");
repositoryService = (RepositoryService) context.getBean("repositoryService");
managementService = (ManagementService) context.getBean("managementService");
procdefinitionDAO = (procdefinitionDAO) context.getBean("procdefinitionDAO");
formtableDAO = (formtableDAO) context.getBean("formtableDAO");
procinstanceDAO = (procinstanceDAO) context.getBean("procinstanceDAO");
procdefiChooseUserBusiness = (ProcdefiChooseUserBusiness) context.getBean("ProcdefiChooseUserBusiness");
}
/**
......@@ -132,23 +153,33 @@ public class ActivitiTools {
}
/**
* 保存
*
* @param entity
* @param isNext
* 业务数据
* @param opt
* 具体执行的操作(保存,下一步,回退等)
* @return
*/
public static ActivitiResultEnum save(Map<String, Object> entity, boolean isNext) {
public static ActivitiResultEnum save(Map<String, Object> entity, ActivitiOptEnum opt) {
// 去除不必要属性
entity.remove("OPETYPE");
Map<String, Object> procInstance = findProcInstanceByBusinessId(entity.get("UUID").toString());
// 验证是否有权限修改
if (!checkPowerByInstance(procInstance)) {
return ActivitiResultEnum.NO_POWER;
}
// 更新业务数据
if (opt.isSave()) {
String procDefId = procInstance.get("PROC_DEFINITION_ID").toString();
String tableId = findProcdeFinitionByUuid(procDefId).get("TABLE_ID").toString();
updateCustomBusiness(tableId, entity);
}
if (isNext) {
// 执行下一步
if (opt.isNext()) {
if (procInstance.get("INSTANCE_ID") == null || "".equals(procInstance.get("INSTANCE_ID"))) {
// 如果未启动,则通过流程定义id启动流程
String deploymentKey = findProcdeFinitionByUuid(procInstance.get("PROC_DEFINITION_ID").toString()).get("DEPLOYMENT_KEY").toString();
......@@ -161,14 +192,291 @@ public class ActivitiTools {
updateProcInstanceData(procInstanceUpdate);
}
// 完成当前登录人任务
Task task = taskService.createTaskQuery().processInstanceId(procInstance.get("INSTANCE_ID").toString()).taskCandidateUser(SessionUtil.getCode()).singleResult();
List<Task> listTask = taskService.createTaskQuery().processInstanceId(procInstance.get("INSTANCE_ID").toString()).taskCandidateUser(SessionUtil.getCode()).list();
for(Task task:listTask){
taskService.complete(task.getId());
}
}
// 执行回退
if (opt.isRallback()) {
Task task = taskService.createTaskQuery().processInstanceId(procInstance.get("INSTANCE_ID").toString()).taskCandidateUser(SessionUtil.getCode()).singleResult();
try {
rollBackByTaskId(task.getId());
} catch (Exception e) {
return ActivitiResultEnum.ROLLBACK_ERROR;
}
}
return ActivitiResultEnum.OK;
}
/**
* 回退
*
* @param executionId
* 执行id
* @param currentActivity
* 当前节点
* @param destinationActivity
* 目标节点
* @param vars
* 参数
*/
private static void rollBack(String executionId, ActivityImpl currentActivity, ActivityImpl destinationActivity, Map<String, Object> vars) {
managementService.executeCommand(new NodeJumpTaskCmd(executionId, destinationActivity, vars, currentActivity));
}
private static void rollBack(String executionId, ActivityImpl currentActivity, ActivityImpl destinationActivity) {
managementService.executeCommand(new NodeJumpTaskCmd(executionId, destinationActivity, new HashMap<String, Object>(), currentActivity));
}
/**
* 根据任务id进行退回操作
*
* @param taskId
* 任务id
* @throws Exception
*/
private static void rollBackByTaskId(String taskId) throws Exception {
HistoricTaskInstance currTask = null;
ActivityImpl currActivity = null;
List<TransitionImpl> newTransitions = null;
List<PvmTransition> oriPvmTransitionList = null;
List<PvmTransition> pvmTransitionList = null;
try {
// 取得当前任务
currTask = historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult();
// 取得流程实例
ProcessInstance instance = runtimeService.createProcessInstanceQuery().processInstanceId(currTask.getProcessInstanceId()).singleResult();
if (instance == null) {
// 流程结束
}
// 获取该流程实例,当前所有的任务
List<Task> listNowAllTask = taskService.createTaskQuery().processInstanceId(instance.getId()).list();
// 取得流程定义
ProcessDefinitionEntity definition = (ProcessDefinitionEntity) (repositoryService.getProcessDefinition(currTask.getProcessDefinitionId()));
if (definition == null) {
// log.error("流程定义未找到");
return;
}
// 取得上一步活动
currActivity = ((ProcessDefinitionImpl) definition).findActivity(currTask.getTaskDefinitionKey());
List<PvmTransition> nextTransitionList = findIncomingTransitionsWithoutGateway(definition, instance.getId(), currActivity);
// 是否使用修改流程定义的方式进行回退
boolean useChangeProcessDefinition = true;
if (!useChangeProcessDefinition) {
if (nextTransitionList.size() > 0) {
// 如果有多个源头,只获取第一个
PvmTransition nextTransition = nextTransitionList.get(0);
PvmActivity nextActivity = nextTransition.getSource();
ActivityImpl nextActivityImpl = ((ProcessDefinitionImpl) definition).findActivity(nextActivity.getId());
rollBack(currTask.getExecutionId(), currActivity, nextActivityImpl);
}
} else {
// 清除当前活动的出口
oriPvmTransitionList = new ArrayList<PvmTransition>();
pvmTransitionList = currActivity.getOutgoingTransitions();
for (PvmTransition pvmTransition : pvmTransitionList) {
oriPvmTransitionList.add(pvmTransition);
}
pvmTransitionList.clear();
// 建立新出口
newTransitions = new ArrayList<TransitionImpl>();
for (PvmTransition nextTransition : nextTransitionList) {
PvmActivity nextActivity = nextTransition.getSource();
ActivityImpl nextActivityImpl = ((ProcessDefinitionImpl) definition).findActivity(nextActivity.getId());
TransitionImpl newTransition = currActivity.createOutgoingTransition();
newTransition.setDestination(nextActivityImpl);
newTransitions.add(newTransition);
}
// 完成任务
List<Task> tasks = taskService.createTaskQuery().processInstanceId(instance.getId()).taskDefinitionKey(currTask.getTaskDefinitionKey()).list();
for (Task task : tasks) {
taskService.complete(task.getId());
}
}
// 获取新的当前任务
List<Task> listNewTask = taskService.createTaskQuery().processInstanceId(instance.getId()).list();
// 为当前任务添加对应的环节人员
outer: for (Task newTask : listNewTask) {
for (Task nowTask : listNowAllTask) {
if (newTask.getId().equals(nowTask.getId())) {
// 如果是回退前就有的任务不进行处理
continue outer;
}
}
if (checkTaskIsFirst(newTask)) {
// 如果是第一个环节,则插入该实例创建人
taskService.addCandidateUser(newTask.getId(), findCreateUserByInstanceId(instance.getId()));
} else {
List<Map<String, Object>> listUsers = findUsersByTaskDefinitionKey(newTask.getTaskDefinitionKey());
for (Map<String, Object> u : listUsers) {
taskService.addCandidateUser(newTask.getId(), u.get("CODE").toString());
}
}
}
return;
} catch (Exception e) {
throw e;
} finally {
// 恢复方向
if (newTransitions != null) {
for (TransitionImpl transitionImpl : newTransitions) {
currActivity.getOutgoingTransitions().remove(transitionImpl);
}
}
if (oriPvmTransitionList != null) {
for (PvmTransition pvmTransition : oriPvmTransitionList) {
pvmTransitionList.add(pvmTransition);
}
}
}
}
/**
* 获取来源任务(除去网关)
*
* @param currActivity
* 任务对象
* @return
*/
private static List<PvmTransition> findIncomingTransitionsWithoutGateway(List<HistoricActivityInstance> listGateway, ProcessDefinitionImpl definition, String instanceId, ActivityImpl currActivity) {
List<PvmTransition> listResult = new ArrayList<PvmTransition>();
List<PvmTransition> list = currActivity.getIncomingTransitions();
for (PvmTransition p : list) {
PvmActivity prevActivity = p.getSource();
ActivityImpl prevActivityImpl = definition.findActivity(prevActivity.getId());
boolean isGateway = false;
for (HistoricActivityInstance gateway : listGateway) {
if (prevActivityImpl.getId().equals(gateway.getActivityId())) {
isGateway = true;
break;
}
}
if (isGateway) {
// 如果当前环节是网关,则需要继续向前查询环节
listResult.addAll(findIncomingTransitionsWithoutGateway(listGateway, definition, instanceId, prevActivityImpl));
} else {
listResult.add(p);
}
}
return listResult;
}
/**
* 获取来源任务(除去网关)
*
* @param definition
* 流程定义对象
* @param instanceId
* 流程实例id
* @param currActivity
* 任务对象
* @return
*/
private static List<PvmTransition> findIncomingTransitionsWithoutGateway(ProcessDefinitionImpl definition, String instanceId, ActivityImpl currActivity) {
// 获取该流程实例所有的网关
List<HistoricActivityInstance> listGateway = getHistoricActivityInstance(instanceId, "parallelGateway");
return findIncomingTransitionsWithoutGateway(listGateway, definition, instanceId, currActivity);
}
/**
* 根据流程实例id获取该实例的新建人
*
* @param instanceId
* 流程实例id
* @return 新建人UUID
*/
private static String findCreateUserByInstanceId(String instanceId) {
Map<String, Object> query = new HashMap<String, Object>();
query.put("INSTANCE_ID", instanceId);
return procinstanceDAO.list_proc_instance_all(query).get(0).get("CREATE_ID").toString();
}
/**
* 获取某一类型的任务
*
* @param instanceId
* 实例id
* @param type
* 类型字符串
* @return 任务列表
*/
private static List<HistoricActivityInstance> getHistoricActivityInstance(String instanceId, String type) {
List<HistoricActivityInstance> listHistoricActivityInstance = historyService // 历史相关Service
.createHistoricActivityInstanceQuery() // 创建历史活动实例查询
.processInstanceId(instanceId) // 执行流程实例id
.finished().list();
List<HistoricActivityInstance> listResult = new ArrayList<HistoricActivityInstance>();
for (HistoricActivityInstance hai : listHistoricActivityInstance) {
if (type.equals(hai.getActivityType())) {
listResult.add(hai);
}
}
return listResult;
}
/**
* 验证任务环节是否为第一个环节
*
* @param task
* 任务实例
* @return true:是第一个环节;false:不是第一个环节
*/
private static boolean checkTaskIsFirst(Task task) {
// 获取开始节点的TaskDefinitionKey
String startEventTaskDefinitionKey = null;
List<HistoricActivityInstance> listHistoricActivityInstance = historyService // 历史相关Service
.createHistoricActivityInstanceQuery() // 创建历史活动实例查询
.processInstanceId(task.getProcessInstanceId()) // 执行流程实例id
.finished().list();
for (HistoricActivityInstance hai : listHistoricActivityInstance) {
if ("startEvent".equals(hai.getActivityType())) {
startEventTaskDefinitionKey = hai.getActivityId();
break;
}
}
// 取得流程定义
ProcessDefinitionEntity definition = (ProcessDefinitionEntity) (repositoryService.getProcessDefinition(task.getProcessDefinitionId()));
ActivityImpl currActivity = ((ProcessDefinitionImpl) definition).findActivity(task.getTaskDefinitionKey());
List<PvmTransition> nextTransitionList = currActivity.getIncomingTransitions();
for (PvmTransition pvmTransition : nextTransitionList) {
String sourceStr = pvmTransition.getSource().toString();
if (sourceStr.indexOf(startEventTaskDefinitionKey) != -1) {
// 如果存在开始节点的TaskDefinitionKey,表示是第一个环节
return true;
}
}
return false;
}
public static List<Map<String, Object>> findUsersByTaskDefinitionKey(String taskDefinitionKey) {
Map<String, Object> query = new HashMap<String, Object>();
query.put("LINK_KEY", taskDefinitionKey);
return procdefiChooseUserBusiness.list_procdefi_chooseUser(query);
}
/**
* 根据主键id修改流程实例表
*
* @param entity
* 流程实例表对象
*/
private static void updateProcInstanceData(Map<String, Object> entity) {
procinstanceDAO.update_proc_instance(machiningUpdateEntity(entity, "UUID"));
......
package com.gaowj.business.utils.model;
/**
* activiti操作枚举类
*
* @author luosz
*
*/
public enum ActivitiOptEnum {
/**
* 保存
*/
SAVE(true, false, false),
/**
* 保存并且下一步
*/
SAVE_AND_NEXT(true, true, false),
/**
* 下一步
*/
NEXT(false, true, false),
/**
* 回退
*/
RALLBACK(false, false, true),
/**
* 保存并回退
*/
SAVE_AND_RALLBACK(true, false, true);
private boolean isNextSign = false;
private boolean isSaveSign = false;
private boolean isRallbackSign = false;
/**
* 操作规则制定
*
* @param isSaveSign
* 是否执行保存
* @param isNextSign
* 是否执行下一步
* @param isRallbackSign
* 是否执行回退
*/
private ActivitiOptEnum(boolean isSaveSign, boolean isNextSign, boolean isRallbackSign) {
this.isSaveSign = isSaveSign;
this.isNextSign = isNextSign;
this.isRallbackSign = isRallbackSign;
}
/**
* 是否执行下一步
*
* @return
*/
public boolean isNext() {
return isNextSign;
}
/**
* 是否执行保存
*
* @return
*/
public boolean isSave() {
return isSaveSign;
}
/**
* 是否执行回退
*
* @return
*/
public boolean isRallback() {
return isRallbackSign;
}
}
......@@ -14,7 +14,11 @@ public enum ActivitiResultEnum {
/**
* 无权限
*/
NO_POWER(-1, "您不是当前环节操作人,无权限修改该内容!");
NO_POWER(-1, "您不是当前环节操作人,无权限修改该内容!"),
/**
* 退回异常
*/
ROLLBACK_ERROR(-2, "回退异常!");
private ActivitiResult activitiResult;
private ActivitiResultEnum(int code, String msg) {
......
......@@ -62,12 +62,12 @@ public class dataAction extends BasicAction{
Map<String, Object> query = RequestUtils.getUpdateFieldMap(request,RequestUtils.UPDATEDATAFIELDPREFIX);
try {
query = QueryParamUtil.StringToDate(query);
Page<Map<String, Object>> pageRows = business.list_proc_instance(pageNo,pageSize, query);
setPageCount((pageRows.getCount() - 1) / pageSize + 1);
Page<Map<String, Object>> pageRows = business.list_proc_instance(page,rows, query);
setPageCount((pageRows.getCount() - 1) / rows + 1);
Map<String, Object> data = new HashMap<String, Object>();
data.put("rowSet", QueryParamUtil.DateTimeToString(pageRows.getItems()));
data.put("pageNo", pageNo);
data.put("pageSize", pageSize);
data.put("pageNo", page);
data.put("pageSize", rows);
data.put("pageCount", pageCount);
data.put("rows", data.get("rowSet"));
data.put("total", pageRows.getCount());
......
......@@ -92,8 +92,16 @@ public class actAction extends BasicAction {
jsonObject = new JSONObject();
try {
entity = QueryParamUtil.StringToDate(entity);
// business.list_proc_task(pageNo, pageSize, query)
Map<String, Object> procinstance = business.back(entity);
// 操作日志
SystemOpeBusiness sysbusiness = BusinessManager.getBusiness(SystemOpeBusiness.class);
sysbusiness.insert_logBusiness("backInfo", "" + procinstance, "回退流程实例数据", (String) entity.get("UUID"), (String) entity.get("CONTENT"), "procinstance");
jsonObject.putAll(Status.getStatusSuccessMessage("保存成功"));
} catch (ActivitiException e) {
jsonObject.putAll(Status.getStatusErrorMessage(e.getMessage()));
e.printStackTrace();
} catch (Exception e) {
jsonObject.putAll(Status.getStatusErrorMessage(e.getMessage()));
e.printStackTrace();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment