Commit 8b0c6535 authored by 李家智's avatar 李家智
Browse files

flowable jump ?

parent 0a58ecc4
......@@ -9,9 +9,11 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.ibeetl.starter.workflow.event.ProcessEndEvent;
import com.ibeetl.starter.workflow.event.ProcessPauseEvent;
import com.ibeetl.starter.workflow.event.ProcessStartEvent;
import com.ibeetl.starter.workflow.event.TaskEndEvent;
import com.ibeetl.starter.workflow.event.TaskOwnerChangeEvent;
import com.ibeetl.starter.workflow.event.TaskPauseEvent;
import com.ibeetl.starter.workflow.event.TaskStartEvent;
import com.ibeetl.starter.workflow.event.TaslClaimEvent;
import com.ibeetl.starter.workflow.service.WfNotifyService;
......@@ -69,16 +71,18 @@ public class WorkflowConfig {
}
@Override
public void taskPause(String taskInsId) {
log.info("taskIns "+taskInsId+" pause");
public void taskPause(TaskPauseEvent pauseEvent) {
log.info(pauseEvent);
}
@Override
public void processPause(String processInsId) {
log.info("processInsId "+processInsId+" pause");
public void processPause(ProcessPauseEvent pauseEvent) {
log.info(pauseEvent);
}
};
......
package com.ibeetl.starter.workflow.engine.cmd;
import java.io.Serializable;
import java.util.Map;
import org.flowable.bpmn.model.FlowElement;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.common.impl.interceptor.Command;
import org.flowable.engine.common.impl.interceptor.CommandContext;
import org.flowable.engine.impl.history.HistoryManager;
import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
import org.flowable.engine.impl.persistence.entity.ExecutionEntityManager;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.engine.impl.util.ProcessDefinitionUtil;
import org.flowable.task.api.TaskInfo;
import org.flowable.task.service.TaskService;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
import org.flowable.task.service.impl.persistence.entity.TaskEntityManager;
import com.ibeetl.starter.workflow.kit.Constants;
import com.ibeetl.starter.workflow.model.WfUser;
import com.ibeetl.starter.workflow.service.WfTaskService;
public abstract class BaseManagmentCmd implements Command, Serializable{
protected ExecutionEntityManager executionManager;
protected TaskEntityManager taskEntityManager;
protected HistoryManager historyManager;
protected WfTaskService service;
protected TaskService taskService;
protected RuntimeService runtimeService;
public BaseManagmentCmd(WfTaskService service) {
this.service = service;
}
@Override
public Object execute(CommandContext commandContext) {
executionManager = CommandContextUtil.getExecutionEntityManager();
taskEntityManager = CommandContextUtil.getTaskServiceConfiguration().getTaskEntityManager();
historyManager = CommandContextUtil.getHistoryManager();
taskService = CommandContextUtil.getTaskService();
runtimeService = CommandContextUtil.getProcessEngineConfiguration().getRuntimeService();
return complete();
}
protected TaskInfo getRunningTask(String taskInsId) {
return taskService.createTaskQuery().taskId(taskInsId).includeTaskLocalVariables().singleResult();
}
protected ExecutionEntity getRunningExecutiton(String executionId) {
return executionManager.findById(executionId);
}
protected FlowElement getCurrentFlowElement(String processId,String taskKey) {
return ProcessDefinitionUtil.getBpmnModel(processId).getFlowElement(taskKey);
}
protected WfUser getHistoryUser(TaskInfo task) {
WfUser user = new WfUser();
user.setUserId(task.getAssignee());
Map<String,Object> map = task.getTaskLocalVariables();
if(map.containsKey(Constants.VAR_TASK_ORG)) {
user.setOrgId((String)map.get(Constants.VAR_TASK_ORG));
}
if(map.containsKey(Constants.VAR_TASK_ROLE)) {
user.setRoleId((String)map.get(Constants.VAR_TASK_ROLE));
}
return user;
}
protected TaskInfo createTask(ExecutionEntity taskExecution,FlowElement target) {
//创建执行人
TaskEntity task = taskEntityManager.create();
task.setExecutionId(taskExecution.getId());
task.setTaskDefinitionKey(target.getId());
task.setName(target.getName());
taskEntityManager.insert(task);
return task;
}
public abstract Object complete() ;
}
package com.ibeetl.starter.workflow.engine.cmd;
import org.flowable.bpmn.model.FlowElement;
import org.flowable.bpmn.model.Process;
import org.flowable.engine.FlowableEngineAgenda;
import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.engine.impl.util.ProcessDefinitionUtil;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
import com.ibeetl.starter.workflow.model.WfUser;
import com.ibeetl.starter.workflow.service.WfTaskService;
public class CommonTaskJumpCmd extends BaseManagmentCmd {
protected String taskInsId;
protected String target;
WfUser targetUser;
String title;
public CommonTaskJumpCmd(WfTaskService service,String taskInsId, String target, WfUser targetUser,String title) {
super(service);
this.taskInsId = taskInsId;
this.target = target;
this.targetUser = targetUser;
this.title = title;
}
@Override
public Object complete() {
TaskEntity taskEntity = taskEntityManager.findById(taskInsId);
ExecutionEntity ee = executionManager.findById(taskEntity.getExecutionId());
Process process = ProcessDefinitionUtil.getProcess(ee.getProcessDefinitionId());
FlowElement targetFlowElement = process.getFlowElement(target);
ee.setCurrentFlowElement(targetFlowElement);
FlowableEngineAgenda agenda = CommandContextUtil.getAgenda();
agenda.planContinueProcessInCompensation(ee);
taskEntityManager.delete(taskInsId);
return null;
}
}
package com.ibeetl.starter.workflow.event;
public class ProcessPauseEvent {
String processInsId;
String processKey;
String processName;
public String getProcessInsId() {
return processInsId;
}
public void setProcessInsId(String processInsId) {
this.processInsId = processInsId;
}
public String getProcessKey() {
return processKey;
}
public void setProcessKey(String processKey) {
this.processKey = processKey;
}
public String getProcessName() {
return processName;
}
public void setProcessName(String processName) {
this.processName = processName;
}
@Override
public String toString() {
return "ProcessPauseEvent [processInsId=" + processInsId + ", processKey=" + processKey + ", processName="
+ processName + "]";
}
}
......@@ -9,7 +9,9 @@ public class ProcessStartEvent {
String processInsId;
String processKey;
String processName;
String taskId;
String taskInsId;
String taskName;
WfUser user;
Map processVars;
public String getProcessInsId() {
......@@ -48,6 +50,24 @@ public class ProcessStartEvent {
public void setUser(WfUser user) {
this.user = user;
}
public String getTaskId() {
return taskId;
}
public void setTaskId(String taskId) {
this.taskId = taskId;
}
public String getTaskName() {
return taskName;
}
public void setTaskName(String taskName) {
this.taskName = taskName;
}
@Override
public String toString() {
return "ProcessStartEvent [processInsId=" + processInsId + ", processKey=" + processKey + ", processName="
+ processName + ", taskId=" + taskId + ", taskInsId=" + taskInsId + ", taskName=" + taskName + ", user="
+ user + ", processVars=" + processVars + "]";
}
......
package com.ibeetl.starter.workflow.event;
public class TaskPauseEvent {
String taskId;
String taskName;
String taskInsId;
String processKey;
String processName;
String processInsId;
public String getTaskId() {
return taskId;
}
public void setTaskId(String taskId) {
this.taskId = taskId;
}
public String getTaskName() {
return taskName;
}
public void setTaskName(String taskName) {
this.taskName = taskName;
}
public String getTaskInsId() {
return taskInsId;
}
public void setTaskInsId(String taskInsId) {
this.taskInsId = taskInsId;
}
public String getProcessKey() {
return processKey;
}
public void setProcessKey(String processKey) {
this.processKey = processKey;
}
public String getProcessName() {
return processName;
}
public void setProcessName(String processName) {
this.processName = processName;
}
public String getProcessInsId() {
return processInsId;
}
public void setProcessInsId(String processInsId) {
this.processInsId = processInsId;
}
@Override
public String toString() {
return "TaskPauseEvent [taskId=" + taskId + ", taskName=" + taskName + ", taskInsId=" + taskInsId
+ ", processKey=" + processKey + ", processName=" + processName + ", processInsId=" + processInsId
+ "]";
}
}
......@@ -6,9 +6,9 @@ public class Constants {
public static final String VAR_TASK_ROLE = "_roleId";
public static final String VAR_TASK_TITLE = "_title";
public static final String VAR_LAST_TASK_ID = "_lastTaskId";
public static final String VAR_USER_FLAG = "_userFlag";
public static final String VAR_TASK_WAIT = "_wait";
public static final String VAR_PROCESS_STATUS= "_processStatus";
public static final String VAR_BUTTON_CODE= "_buttonCode";
public static final String TYPE_COMMENT_AGREE = "comment";
public static final String TYPE_COMMENT_DELEGATE = "delegate";
......@@ -25,6 +25,9 @@ public class Constants {
//环节对应的页面
public static final String EXT_TASK_PAGE = "page";
/* 工作流支持的操作 */
//普通按钮
public static final String BUTTON_TYPE_GENERAL = "general";
//任意跳转
......@@ -34,8 +37,8 @@ public class Constants {
//回到上一个任务,有问题
public static final String BUTTON_TYPE_BACK = "back";
//自动
public static final String BUTTON_TYPE_AUTO = "auto";
//自动汇聚,用于并行或者多实例
public static final String BUTTON_TYPE_AUTO = "autoJoin";
//直接结束流程的按钮
public static final String BUTTON_TYPE_END_PROCESS = "complete";
//多实例
......@@ -45,17 +48,13 @@ public class Constants {
//等待
public static final String BUTTON_TYPE_WAIT = "wait";
//按照角色选取
public static final String USER_ROLE = "role";
/*工作流能提供的选人策略,业务侧选人策略自定义,不包含在如下列表里*/
//流程的历史执行人
public static final String USER_task_history = "task_history";
//流程的创建者
public static final String USER_PROCESS_CREATOR = "processe_creator";
//来自于某个变量,因此不必选取,暂时没有这个需求,取消
// public static final String USER_DYNAMIC_VARS = "dynamic_vars";
//业务侧按钮的渲人策略
public static final String CHOOSE_ONE = "one";
public static final String CHOOSE_RANDOM_ONE = "random_one";
public static final String CHOOSE_MUTIPLE = "mutiple";
}
package com.ibeetl.starter.workflow.service;
import com.ibeetl.starter.workflow.event.ProcessEndEvent;
import com.ibeetl.starter.workflow.event.ProcessPauseEvent;
import com.ibeetl.starter.workflow.event.ProcessStartEvent;
import com.ibeetl.starter.workflow.event.TaskEndEvent;
import com.ibeetl.starter.workflow.event.TaskOwnerChangeEvent;
import com.ibeetl.starter.workflow.event.TaskPauseEvent;
import com.ibeetl.starter.workflow.event.TaskStartEvent;
import com.ibeetl.starter.workflow.event.TaslClaimEvent;
......@@ -15,8 +17,8 @@ import com.ibeetl.starter.workflow.event.TaslClaimEvent;
public interface WfNotifyService {
public void processStart(ProcessStartEvent startEvent);
public void taskStart(TaskStartEvent startEvent);
public void taskPause(String taskInsId);
public void processPause(String processInsId);
public void taskPause(TaskPauseEvent pauseEvent);
public void processPause(ProcessPauseEvent pauseEvent);
public void taskEnd(TaskEndEvent endEvent);
public void processEnd(ProcessEndEvent endEvent);
public void taskOwnerChanged(TaskOwnerChangeEvent changeEvent);
......
package com.ibeetl.starter.workflow.service.impl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.flowable.bpmn.model.Activity;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.bpmn.model.EndEvent;
import org.flowable.bpmn.model.ExtensionElement;
import org.flowable.bpmn.model.FlowElement;
import org.flowable.bpmn.model.FlowNode;
import org.flowable.bpmn.model.ParallelGateway;
import org.flowable.bpmn.model.SequenceFlow;
import org.flowable.bpmn.model.SubProcess;
import org.flowable.bpmn.model.UserTask;
import org.flowable.engine.HistoryService;
import org.flowable.engine.IdentityService;
import org.flowable.engine.ProcessEngine;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.flowable.task.api.TaskInfo;
import org.flowable.task.api.history.HistoricTaskInstance;
import org.springframework.beans.factory.annotation.Autowired;
import com.ibeetl.starter.workflow.engine.CurrentTaskLocal;
import com.ibeetl.starter.workflow.engine.cmd.CommonTaskJumpCmd;
import com.ibeetl.starter.workflow.event.TaslClaimEvent;
import com.ibeetl.starter.workflow.exception.WfException;
import com.ibeetl.starter.workflow.kit.Constants;
import com.ibeetl.starter.workflow.model.InternalTaskStartInfo;
import com.ibeetl.starter.workflow.model.SimpleProcessProgress;
import com.ibeetl.starter.workflow.model.WfTaskButton;
import com.ibeetl.starter.workflow.model.WfTaskSpec;
import com.ibeetl.starter.workflow.model.WfUser;
import com.ibeetl.starter.workflow.model.WfUserSpec;
......@@ -65,71 +86,51 @@ public class WfTaskServiceImpl implements WfTaskService {
return firstTask.getId();
}
private void notifyProcessStart(String processKey,String processInsId,WfUser startUser,Map paras,Task firstTask) {
}
@Override
public void complete(String taskInsId, WfUser acUser, String comment, String title, String buttonCode,
public void complete(String taskInsId, WfUser wfUser, String comment, String title, String buttonCode,
WfUser[] targetAcUsers, Map<String, Object> processVars, Map<String, Object> parameters) {
InternalTaskStartInfo taskStartInfo = new InternalTaskStartInfo();
taskStartInfo.setAssigner(acUser);
taskStartInfo.setAssigner(wfUser);
taskStartInfo.setButtonCode(buttonCode);
taskStartInfo.setStartTaskInsId(taskInsId);
//保存当前信息,供后续操作使用
CurrentTaskLocal.setTaskInfo(taskStartInfo);
Task currentTask = taskService.createTaskQuery().taskId(taskInsId).includeTaskLocalVariables().singleResult();
if (currentTask == null) {
throw new WfException("taskInsId=" + taskInsId + " 已经完成或者此代办不存在");
}
// String procInsId = currentTask.getProcessInstanceId();
// FlowElement taskElement = this.getFlowElement(null, procInsId, currentTask.getTaskDefinitionKey());
// List<AcTaskButton> buttons = this.getButtonList(taskElement.getExtensionElements().get("toolbar").get(0));
// AcTaskButton button = this.findButtonByCode(buttons, buttonCode);
//
// // 设置任务点击的按钮,可以用于后面的gateway(如果有) 走向判断
// Map<String, Object> taskVar = new HashMap<String, Object>();
// taskVar.put("buttonCode", buttonCode);
// if (processVars != null && processVars.size() != 0) {
// runtimeService.setVariablesLocal(procInsId, processVars);
// }
//
// if (parameters != null && parameters.size() != 0) {
// taskService.setVariablesLocal(taskInsId, parameters);
// }
//
// taskService.addComment(taskInsId, procInsId, Constants.TYPE_COMMENT_AGREE, comment);
//
// if (Constants.BUTTON_TYPE_JUMP.equals(button.getType())) {
// // 跳转到任意节点
// this.taskJump(taskInsId, button.getTargetRef(), acUser, targetAcUsers[0], title, comment);
// return;
// } else if (Constants.BUTTON_TYPE_WAIT.equals(button.getType())) {
// // 等待,其他按钮或者外部事件来真正完成
// this.taskWait(taskInsId);
// return;
// } else if (Constants.BUTTON_TYPE_END_PROCESS.equals(button.getType())) {
// // 流程结束
// this.processEnd(taskInsId, comment, DeleteReason.PRAOCESS_CANCEL);
// return;
// } else if (Constants.BUTTON_TYPE_MUTILPLE.equals(button.getType())) {
//
// this.taskMutipleTask(currentTask, targetAcUsers, title);
//
// return;
// } else if (Constants.BUTTON_TYPE_GENERAL.equals(button.getType())) {
// taskGeneral(currentTask, targetAcUsers, title);
// } else if (Constants.BUTTON_TYPE_PARALLEL.equals(button.getType())) {
// // 并行流程
// taskParallel(currentTask, targetAcUsers, title);
//
// } else if (Constants.BUTTON_TYPE_AUTO.equals(button.getType())) {
//
// taskAuto(currentTask);
// } else {
// throw new UnsupportedOperationException("不支持的按钮类型" + button.getType());
// }
String procInsId = currentTask.getProcessInstanceId();
FlowElement taskElement = this.getFlowElement(null, procInsId, currentTask.getTaskDefinitionKey());
List<WfTaskButton> buttons = this.getButtonList(taskElement.getExtensionElements().get("toolbar").get(0));
WfTaskButton button = this.findButtonByCode(buttons, buttonCode);
if (processVars != null && processVars.size() != 0) {
runtimeService.setVariablesLocal(procInsId, processVars);
}
if (parameters != null && parameters.size() != 0) {
taskService.setVariablesLocal(taskInsId, parameters);
}
// 设置任务点击的按钮,可以用于后面的gateway(如果有) 走向判断
taskService.setVariableLocal(taskInsId, Constants.VAR_BUTTON_CODE, buttonCode);
taskService.addComment(taskInsId, procInsId, Constants.TYPE_COMMENT_AGREE, comment);
if (Constants.BUTTON_TYPE_GENERAL.equals(button.getType())) {
taskGeneral(currentTask, targetAcUsers, title);
}else if (Constants.BUTTON_TYPE_JUMP.equals(button.getType())) {
// 跳转到任意节点,如回退
this.taskJump(taskInsId, button.getTargetRef(), wfUser, targetAcUsers[0], title, comment);
return;
}
//更多流程
}
@Override
public void complete(String taskInsId, WfUser wfUser, String buttonCode, WfUser targetWfUser) {
......@@ -139,14 +140,42 @@ public class WfTaskServiceImpl implements WfTaskService {
@Override
public boolean claim(WfUser user, String taskInsId) {
// TODO Auto-generated method stub
return false;
taskService.claim(taskInsId, user.getUserId());
TaslClaimEvent claimEvent = new TaslClaimEvent();
claimEvent.setTaskInsId(taskInsId);
this.notifyService.taskClaim(claimEvent);
return true;
}
@Override
public WfTaskSpec getTaskSpec(String processKey, String processInsId, String taskId) {
// TODO Auto-generated method stub
return null;
FlowElement taskElement = this.getFlowElement(processKey, processInsId, taskId);
Map<String, List<ExtensionElement>> root = taskElement.getExtensionElements();
Map processVars = null;
if (StringUtils.isNotEmpty(processInsId)) {
processVars = this.runtimeService.getVariables(processInsId);
}
ExtensionElement toolBar = root.get("toolbar").get(0);
List<WfTaskButton> buttonList = getButtonList(toolBar, processVars);
for (WfTaskButton button : buttonList) {
String refTask = button.getTargetRef();
if (StringUtils.isEmpty(refTask)) {
// 结束按钮
continue;
} else {
// 如果按奶没有设定目标task,则自动寻找,通过outgoing
List<WfUserSpec> userSpecs = this.getOutgoingTaskUserDefine(processKey, processInsId, refTask);
button.setTargetUserSpecs(userSpecs);
}
}
WfUserSpec curretTaskSpec = getTaskUserDefine(processKey, processInsId, taskId);
WfTaskSpec taskSpec = new WfTaskSpec();
taskSpec.setButtons(buttonList);
taskSpec.setUserSpec(curretTaskSpec);
return taskSpec;
}
@Override
......@@ -156,15 +185,47 @@ public class WfTaskServiceImpl implements WfTaskService {
}
@Override
public WfUser getHistoryWfUser(String procInsId, String taskKey) {
// TODO Auto-generated method stub
return null;
public WfUser getHistoryWfUser(String procInsId, String taskId) {
List<HistoricTaskInstance> tasks = historyService.createHistoricTaskInstanceQuery().finished()
.processInstanceId(procInsId).taskDefinitionKey(taskId).orderByTaskCreateTime().desc()
.includeTaskLocalVariables().list();
if (tasks.size() == 0) {
throw new WfException("procInsId=" + procInsId + ",taskId=" + taskId + " 还未被执行");
}
HistoricTaskInstance task = tasks.get(0);
String assignee = task.getAssignee();
Map<String, Object> taskLocalVariables = task.getTaskLocalVariables();
String roleId = (String) taskLocalVariables.get(Constants.VAR_TASK_ROLE);
String orgId = (String) taskLocalVariables.get(Constants.VAR_TASK_ORG);
WfUser wfUser = new WfUser();
wfUser.setUserId(assignee);
wfUser.setRoleId(roleId);
wfUser.setOrgId(orgId);
return wfUser;
}
@Override
public WfUser getHistoryProcessOwnerWfUser(String procInsId) {
// TODO Auto-generated method stub
return null;
List<HistoricTaskInstance> list = historyService.createHistoricTaskInstanceQuery().processInstanceId(procInsId)
.orderByTaskCreateTime().asc().includeTaskLocalVariables().listPage(0, 1);
if (list.size() == 0) {
throw new WfException("procInsId=" + procInsId + " 不存在");
}
HistoricTaskInstance ins = list.get(0);
Map map = ins.getTaskLocalVariables();
String userId = (String) ins.getAssignee();
String roleId = (String) map.get(Constants.VAR_TASK_ROLE);
String orgId = (String) map.get(Constants.VAR_TASK_ORG);
WfUser wfUser = new WfUser();
wfUser.setRoleId(roleId);
wfUser.setUserId(userId);
wfUser.setOrgId(orgId);
return wfUser;
}
@Override
......@@ -187,8 +248,63 @@ public class WfTaskServiceImpl implements WfTaskService {
@Override
public SimpleProcessProgress getSimpleProgress(String processInsId) {
// TODO Auto-generated method stub
return null;
BpmnModel model = this.getBpmnMode(null, processInsId);
FlowNode currentElement = (FlowNode) model.getMainProcess().getInitialFlowElement();
List<String> names = new ArrayList<String>();
List<String> ids = new ArrayList<String>();
while (!currentElement.getOutgoingFlows().isEmpty()) {
//未考虑分支情况,TODO
if (currentElement.getOutgoingFlows().size() != 1) {
throw new WfException("不支持的流程类型 " + model.getMainProcess().getId());
}
SequenceFlow defaultFlow = currentElement.getOutgoingFlows().get(0);
FlowElement defaultElement = defaultFlow.getTargetFlowElement();
if (defaultElement instanceof UserTask) {
String taskName = defaultElement.getName();
String id = defaultElement.getId();
if (ids.contains(id)) {
throw new WfException("环节名称重复或者循环" + model.getMainProcess().getId());
}
names.add(taskName);
ids.add(id);
currentElement = (FlowNode) defaultElement;
} else if (defaultElement instanceof EndEvent) {
// 结束
break;
} else if (defaultElement instanceof SubProcess) {
// 未来考虑支持SubProcess
throw new WfException("不支持的流程类型 " + model.getMainProcess().getId());
} else {
throw new WfException(
"不支持的流程类型 " + model.getMainProcess().getId() + " nodeId=" + defaultElement.getId());
}
}
SimpleProcessProgress progress = new SimpleProcessProgress();
progress.setTaskNames(names);
progress.setTaskIds(ids);
if (StringUtils.isNotEmpty(processInsId)) {
List<Task> list = this.taskService.createTaskQuery().processInstanceId(processInsId).orderByTaskCreateTime()
.desc().listPage(0, 1);
if (list.isEmpty()) {
// 未找到,认为流程已经完成
progress.setComplete(true);
return progress;
}
Task currentTask = list.get(0);
String currentId = currentTask.getTaskDefinitionKey();
for (int i = 0; i < ids.size(); i++) {
String taskId = ids.get(i);
if (currentId.equals(taskId)) {
progress.setCurrentIndex(i);
progress.setCurrentTaskName(names.get(i));
break;
}
}
}
return progress;
}
@Override
......@@ -199,8 +315,233 @@ public class WfTaskServiceImpl implements WfTaskService {
@Override
public boolean isProcessCompleted(String taskInsId) {
// TODO Auto-generated method stub
return false;
TaskInfo taskInfo = this.historyService.createHistoricTaskInstanceQuery().taskId(taskInsId).singleResult();
String processInsId = taskInfo.getProcessInstanceId();
List<ProcessInstance> list = this.runtimeService.createProcessInstanceQuery().processInstanceId(processInsId)
.list();
return list.isEmpty();
}
/**
* 获取taskId对应的定义,如果processId为空,取最新的流程定义,否则,取流程特定版本的定义。
*
* @param processKey
* @param processId
* @param taskKey
* @return
*/
protected FlowElement getFlowElement(String processKey, String processInsId, String taskId) {
ProcessDefinition pd = null;
if (StringUtils.isEmpty(processInsId)) {
// 取定义
pd = repositoryService.createProcessDefinitionQuery().processDefinitionKey(processKey).latestVersion()
.singleResult();
} else {
String processId = this.getProcessId(processInsId);
pd = repositoryService.createProcessDefinitionQuery().processDefinitionId(processId).singleResult();
processKey = pd.getKey();
}
BpmnModel model = repositoryService.getBpmnModel(pd.getId());
FlowElement target = model.getFlowElement(taskId);
if (target == null) {
throw new WfException("环节不存在 " + processKey + " 环节 " + taskId);
}
return target;
}
protected String getProcessId(String processInsId) {
ProcessInstance processIns = this.runtimeService.createProcessInstanceQuery().processInstanceId(processInsId)
.singleResult();
String processId = null;
if (processIns != null) {
processId = processIns.getProcessDefinitionId();
} else {
HistoricProcessInstance his = this.historyService.createHistoricProcessInstanceQuery()
.processInstanceId(processInsId).singleResult();
processId = his.getProcessDefinitionId();
}
return processId;
}
/**
* 获得按钮定义
*
* @param toolBar
* @return
*/
private List<WfTaskButton> getButtonList(ExtensionElement toolBar) {
return this.getButtonList(toolBar, null, true);
}
/**
* 提供流程参数,获得按钮定义
*
* @param toolBar
* @param processVars
* @return
*/
private List<WfTaskButton> getButtonList(ExtensionElement toolBar, Map processVars) {
return this.getButtonList(toolBar, processVars, false);
}
private List<WfTaskButton> getButtonList(ExtensionElement toolBar, Map processVars, boolean skipEval) {
//TODO,目前还不具备动态获取处理信息
Map<String, List<ExtensionElement>> child = toolBar.getChildElements();
List<ExtensionElement> list = child.get("button");
List<WfTaskButton> buttonList = new ArrayList<WfTaskButton>();
for (ExtensionElement ee : list) {
String code = ee.getAttributeValue(null, "code");
String name = ee.getAttributeValue(null, "name");
String displayName = ee.getAttributeValue(null, "displayName");
String targetRef = ee.getAttributeValue(null, "targetRef");
String displayCss = ee.getAttributeValue(null, "displayCss");
String strategy = ee.getAttributeValue(null, "strategy");
String type = ee.getAttributeValue(null, "type");
List<ExtensionElement> paramList = ee.getExtensionElements().get("para");
Map<String, String> strategyParameter = new HashMap<String, String>();
if (paramList != null) {
for (ExtensionElement paramter : paramList) {
String key = paramter.getAttributeValue(null, "key");
String value = paramter.getAttributeValue(null, "value");
strategyParameter.put(key, value);
}
}
WfTaskButton button = new WfTaskButton();
button.setName(name);
button.setType(type);
button.setDisplayName(displayName);
button.setDisplayCss(displayCss);
button.setStrategy(strategy);
button.setTargetRef(targetRef);
button.setStrategyParameter(strategyParameter);
buttonList.add(button);
}
return buttonList;
}
private WfTaskButton findButtonByCode(List<WfTaskButton> buttons, String buttonCode) {
for (WfTaskButton button : buttons) {
if (button.getName().equals(buttonCode)) {
return button;
}
}
StringBuilder sb = new StringBuilder();
for (WfTaskButton button : buttons) {
sb.append(button.getName()).append(",");
}
sb.setLength(sb.length() - 1);
throw new WfException("buttonCode未发现:" + buttonCode + ",期望是 " + sb.toString());
}
protected void taskGeneral(Task currentTask, WfUser[] targetAcUsers, String title) {
// 顺序流程,或者汇聚
String taskInsId = currentTask.getId();
this.taskService.complete(taskInsId, null);
Task t = taskService.createTaskQuery().executionId(currentTask.getExecutionId())
.taskVariableValueEquals(Constants.VAR_LAST_TASK_ID, taskInsId).singleResult();
if (t == null) {
// 没有代办(或者分支汇聚)或者流程结束
return;
}
if (t.getAssignee() == null) {
//流程没有自动指定执行人,采用通常的业务侧指定
WfUser assignee = targetAcUsers[0];
this.setTaskAssignee(t, assignee, title);
}
return;
}
protected void taskJump(String currentTaskInsId, String targetTaskId, final WfUser acUser, final WfUser targetUser,
final String title, String comment) {
CommonTaskJumpCmd cmd = new CommonTaskJumpCmd(this, currentTaskInsId, targetTaskId, targetUser, title);
org.flowable.engine.ManagementService managementService = processEngine.getManagementService();
managementService.executeCommand(cmd);
}
protected String getProcessKey(String processDefineId) {
// simple-workflow:4:40007 -->simple-workflow
String[] arrays = processDefineId.split(":");
return arrays[0];
}
protected List<WfUserSpec> getOutgoingTaskUserDefine(String processKey, String processId, String refer) {
if (refer.equals(Constants.TASK_END)) {
return Collections.EMPTY_LIST;
}
FlowElement out = (FlowElement) this.getFlowElement(processKey, processId, refer);
List<WfUserSpec> list = new ArrayList<WfUserSpec>();
if (out instanceof Activity) {
WfUserSpec spec = this.getTaskUserDefine(processKey, processId, out.getId());
list.add(spec);
return list;
} else if (out instanceof SequenceFlow) {
Activity activity = (Activity) ((SequenceFlow) out).getTargetFlowElement();
WfUserSpec spec = this.getTaskUserDefine(processKey, processId, activity.getId());
list.add(spec);
return list;
} else if (out instanceof ParallelGateway) {
for (SequenceFlow flow : ((ParallelGateway) out).getOutgoingFlows()) {
Activity activity = (Activity) flow.getTargetFlowElement();
list.add(this.getTaskUserDefine(processKey, processId, activity.getId()));
}
return list;
} else {
throw new UnsupportedOperationException("不支持的类型 " + out);
}
}
protected BpmnModel getBpmnMode(String processKey, String processInsId) {
String processId = null;
if (StringUtils.isEmpty(processInsId)) {
ProcessDefinition pd = repositoryService.createProcessDefinitionQuery().processDefinitionKey(processKey)
.latestVersion().singleResult();
processId = pd.getId();
} else {
ProcessInstance processIns = this.runtimeService.createProcessInstanceQuery()
.processInstanceId(processInsId).singleResult();
if (processIns != null) {
processId = processIns.getProcessDefinitionId();
} else {
HistoricProcessInstance his = this.historyService.createHistoricProcessInstanceQuery()
.processInstanceId(processInsId).singleResult();
processId = his.getProcessDefinitionId();
}
}
BpmnModel model = repositoryService.getBpmnModel(processId);
return model;
}
private void notifyProcessStart(String processKey,String processInsId,WfUser startUser,Map paras,Task firstTask) {
}
}
Supports Markdown
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