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