提交 41ace484 编写于 作者: sq3536's avatar sq3536

工作流审批意见

上级 dd174a92
package cn.ibizlab.core.extensions.domain;
import cn.ibizlab.util.security.AuthenticationUser;
import org.flowable.common.engine.api.identity.AuthenticationContext;
import org.flowable.common.engine.impl.identity.Authentication;
import java.security.Principal;
public class FlowUser implements Principal {
public String getName() {
return this.user.getUserid();
}
private AuthenticationUser user;
private String token;
public AuthenticationUser getUser() {
return user;
}
public void setUser(AuthenticationUser user) {
this.user = user;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public static FlowUser getCurUser()
{
AuthenticationContext context = Authentication.getAuthenticationContext();
if(context!=null&&context.getPrincipal()!=null&&context.getPrincipal() instanceof FlowUser)
return (FlowUser)context.getPrincipal();
else
{
FlowUser user = new FlowUser();
user.setUser(AuthenticationUser.getAuthenticationUser());
return user;
}
}
}
package cn.ibizlab.core.extensions.listener; package cn.ibizlab.core.extensions.listener;
import cn.ibizlab.core.extensions.domain.FlowUser;
import cn.ibizlab.core.extensions.service.WFCoreService; import cn.ibizlab.core.extensions.service.WFCoreService;
import cn.ibizlab.core.extensions.service.WFModelService; import cn.ibizlab.core.extensions.service.WFModelService;
import cn.ibizlab.util.security.AuthTokenUtil; import cn.ibizlab.util.security.AuthTokenUtil;
...@@ -11,7 +12,9 @@ import org.flowable.bpmn.model.UserTask; ...@@ -11,7 +12,9 @@ import org.flowable.bpmn.model.UserTask;
import org.flowable.common.engine.api.delegate.event.*; import org.flowable.common.engine.api.delegate.event.*;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType; import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.common.engine.impl.event.FlowableEntityEventImpl; import org.flowable.common.engine.impl.event.FlowableEntityEventImpl;
import org.flowable.engine.TaskService;
import org.flowable.engine.delegate.event.impl.FlowableActivityEventImpl; import org.flowable.engine.delegate.event.impl.FlowableActivityEventImpl;
import org.flowable.engine.delegate.event.impl.FlowableEntityWithVariablesEventImpl;
import org.flowable.engine.delegate.event.impl.FlowableProcessStartedEventImpl; import org.flowable.engine.delegate.event.impl.FlowableProcessStartedEventImpl;
import org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl; import org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl;
import org.flowable.task.service.impl.persistence.entity.TaskEntity; import org.flowable.task.service.impl.persistence.entity.TaskEntity;
...@@ -27,11 +30,6 @@ import java.util.LinkedHashMap; ...@@ -27,11 +30,6 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
/**
* 流程实例监听器,监听流程实例启动、流转、结束状态
* 1.流程状态发生变化时,将实例信息同步到统一工作流平台
* 2.到达流程节点时,调用统一接口,查询当前节点办理人并设置到引擎中
*/
@Slf4j @Slf4j
@Component @Component
public class ProcessInstanceListener implements FlowableEventListener { public class ProcessInstanceListener implements FlowableEventListener {
...@@ -45,11 +43,37 @@ public class ProcessInstanceListener implements FlowableEventListener { ...@@ -45,11 +43,37 @@ public class ProcessInstanceListener implements FlowableEventListener {
@Lazy @Lazy
private RemoteService remoteService; private RemoteService remoteService;
@Autowired
@Lazy
private TaskService taskService;
@Override @Override
public void onEvent(FlowableEvent evt) { public void onEvent(FlowableEvent evt) {
if(evt instanceof FlowableProcessStartedEventImpl) if(evt instanceof FlowableEntityWithVariablesEventImpl)
{
FlowableEntityWithVariablesEventImpl event = (FlowableEntityWithVariablesEventImpl) evt;
if(event.getType() == FlowableEngineEventType.TASK_COMPLETED)
{
TaskEntity taskEntity = (TaskEntity)event.getEntity();
if(taskEntity.getTaskDefinitionKey().startsWith("tid-"))
{
Object data=taskEntity.getVariable("activedata");
Object link=taskEntity.getVariable("sequenceFlowName");
if(data!=null&&(data instanceof Map)&&link!=null)
{
Map activedata=(Map)data;
String wfprocdesc="";
if(activedata.get("wfprocdesc")!=null)
wfprocdesc=activedata.get("wfprocdesc").toString();
taskService.addComment(taskEntity.getId(),taskEntity.getProcessInstanceId(),link.toString(),wfprocdesc);
}
}
}
}
else if(evt instanceof FlowableProcessStartedEventImpl)
{ {
FlowableProcessStartedEventImpl event=(FlowableProcessStartedEventImpl)evt; FlowableProcessStartedEventImpl event=(FlowableProcessStartedEventImpl)evt;
if(event.getEntity() instanceof ExecutionEntityImpl){ if(event.getEntity() instanceof ExecutionEntityImpl){
...@@ -57,9 +81,9 @@ public class ProcessInstanceListener implements FlowableEventListener { ...@@ -57,9 +81,9 @@ public class ProcessInstanceListener implements FlowableEventListener {
if(executionEntity.getVariable("cloud-serviceid")==null) if(executionEntity.getVariable("cloud-serviceid")==null)
return; return;
String businessKey=(String)executionEntity.getVariable("businessKey"); String businessKey=(String)executionEntity.getVariable("businessKey");
HashMap curUser=(HashMap) executionEntity.getVariable("curuser"); //HashMap curUser=(HashMap) executionEntity.getVariable("curuser");
FlowUser curUser=FlowUser.getCurUser();
String entity=executionEntity.getVariable("entitys").toString(); String entity=executionEntity.getVariable("entitys").toString();
String cloudServiceid=executionEntity.getVariable("cloud-serviceid").toString(); String cloudServiceid=executionEntity.getVariable("cloud-serviceid").toString();
Map setting=wfModelService.getProcessGlobalSetting(executionEntity.getProcessDefinitionId()); Map setting=wfModelService.getProcessGlobalSetting(executionEntity.getProcessDefinitionId());
String wfstepfield=""; String wfstepfield="";
...@@ -103,9 +127,9 @@ public class ProcessInstanceListener implements FlowableEventListener { ...@@ -103,9 +127,9 @@ public class ProcessInstanceListener implements FlowableEventListener {
callbackArg.put(wfverfield,Integer.parseInt(executionEntity.getVariable("wfversion").toString())); callbackArg.put(wfverfield,Integer.parseInt(executionEntity.getVariable("wfversion").toString()));
if(callbackArg.size()>0) { if(callbackArg.size()>0) {
if(curUser.get("bearer-token")==null) if(StringUtils.isEmpty(curUser.getToken()))
return; return;
String token=curUser.get("bearer-token").toString(); String token=curUser.getToken();
remoteService.getClient(cloudServiceid).put(entity + "/" + businessKey, token,callbackArg); remoteService.getClient(cloudServiceid).put(entity + "/" + businessKey, token,callbackArg);
} }
} }
...@@ -113,18 +137,14 @@ public class ProcessInstanceListener implements FlowableEventListener { ...@@ -113,18 +137,14 @@ public class ProcessInstanceListener implements FlowableEventListener {
else if(evt instanceof FlowableEntityEventImpl) else if(evt instanceof FlowableEntityEventImpl)
{ {
FlowableEntityEventImpl event=((FlowableEntityEventImpl) evt); FlowableEntityEventImpl event=((FlowableEntityEventImpl) evt);
// 当前节点任务实体
// TODO 获取到了taskEntity 自己做每个节点的前置操作
FlowableEventType eventType = event.getType(); FlowableEventType eventType = event.getType();
//待办创建
if(eventType == FlowableEngineEventType.PROCESS_COMPLETED){ if(eventType == FlowableEngineEventType.PROCESS_COMPLETED){
ExecutionEntityImpl executionEntity= (ExecutionEntityImpl) event.getEntity(); ExecutionEntityImpl executionEntity= (ExecutionEntityImpl) event.getEntity();
if(executionEntity.getVariable("cloud-serviceid")==null) if(executionEntity.getVariable("cloud-serviceid")==null)
return; return;
String businessKey=(String)executionEntity.getVariable("businessKey"); String businessKey=(String)executionEntity.getVariable("businessKey");
HashMap curUser=(HashMap) executionEntity.getVariable("curuser"); //HashMap curUser=(HashMap) executionEntity.getVariable("curuser");
FlowUser curUser=FlowUser.getCurUser();
String entity=executionEntity.getVariable("entitys").toString(); String entity=executionEntity.getVariable("entitys").toString();
String cloudServiceid=executionEntity.getVariable("cloud-serviceid").toString(); String cloudServiceid=executionEntity.getVariable("cloud-serviceid").toString();
String wfstepfield = executionEntity.getVariable("wfstepfield").toString(); String wfstepfield = executionEntity.getVariable("wfstepfield").toString();
...@@ -138,23 +158,14 @@ public class ProcessInstanceListener implements FlowableEventListener { ...@@ -138,23 +158,14 @@ public class ProcessInstanceListener implements FlowableEventListener {
if(!StringUtils.isEmpty(wfstepfield)) if(!StringUtils.isEmpty(wfstepfield))
callbackArg.put(wfstepfield,""); callbackArg.put(wfstepfield,"");
if(callbackArg.size()>0) { if(callbackArg.size()>0) {
if(curUser.get("bearer-token")==null) if(StringUtils.isEmpty(curUser.getToken()))
return; return;
String token=curUser.get("bearer-token").toString(); String token=curUser.getToken();
remoteService.getClient(cloudServiceid).put(entity + "/" + businessKey, token,callbackArg); remoteService.getClient(cloudServiceid).put(entity + "/" + businessKey, token,callbackArg);
} }
System.out.println("流程结束"); System.out.println("流程结束");
} }
if(eventType == FlowableEngineEventType.PROCESS_COMPLETED_WITH_ERROR_END_EVENT){ if(eventType == FlowableEngineEventType.PROCESS_COMPLETED_WITH_ERROR_END_EVENT){
event.getEntity();
System.out.println("流程异常结束");
}
if(eventType == FlowableEngineEventType.TASK_COMPLETED){
TaskEntity taskEntity = (TaskEntity) event.getEntity();
event.getEntity(); event.getEntity();
System.out.println("流程异常结束"); System.out.println("流程异常结束");
} }
...@@ -162,15 +173,13 @@ public class ProcessInstanceListener implements FlowableEventListener { ...@@ -162,15 +173,13 @@ public class ProcessInstanceListener implements FlowableEventListener {
else if(evt instanceof FlowableActivityEventImpl) else if(evt instanceof FlowableActivityEventImpl)
{ {
FlowableActivityEventImpl event=((FlowableActivityEventImpl) evt); FlowableActivityEventImpl event=((FlowableActivityEventImpl) evt);
// 当前节点任务实体
// TODO 获取到了taskEntity 自己做每个节点的前置操作
FlowableEventType eventType = event.getType(); FlowableEventType eventType = event.getType();
if(eventType == FlowableEngineEventType.ACTIVITY_STARTED && "userTask".equals(event.getActivityType())){ if(eventType == FlowableEngineEventType.ACTIVITY_STARTED && "userTask".equals(event.getActivityType())){
if(event.getExecution().getVariable("cloud-serviceid")==null) if(event.getExecution().getVariable("cloud-serviceid")==null)
return; return;
String businessKey=(String)event.getExecution().getVariable("businessKey"); String businessKey=(String)event.getExecution().getVariable("businessKey");
HashMap curUser=(HashMap) event.getExecution().getVariable("curuser"); //HashMap curUser=(HashMap) event.getExecution().getVariable("curuser");
FlowUser curUser=FlowUser.getCurUser();
String entity=event.getExecution().getVariable("entitys").toString(); String entity=event.getExecution().getVariable("entitys").toString();
String cloudServiceid=event.getExecution().getVariable("cloud-serviceid").toString(); String cloudServiceid=event.getExecution().getVariable("cloud-serviceid").toString();
String wfstepfield = event.getExecution().getVariable("wfstepfield").toString(); String wfstepfield = event.getExecution().getVariable("wfstepfield").toString();
...@@ -178,12 +187,11 @@ public class ProcessInstanceListener implements FlowableEventListener { ...@@ -178,12 +187,11 @@ public class ProcessInstanceListener implements FlowableEventListener {
if(!StringUtils.isEmpty(wfstepfield)&&event.getActivityId().startsWith("tid-")) if(!StringUtils.isEmpty(wfstepfield)&&event.getActivityId().startsWith("tid-"))
callbackArg.put(wfstepfield,event.getActivityId().split("-")[1]); callbackArg.put(wfstepfield,event.getActivityId().split("-")[1]);
if(callbackArg.size()>0) { if(callbackArg.size()>0) {
if(curUser.get("bearer-token")==null) if(StringUtils.isEmpty(curUser.getToken()))
return; return;
String token=curUser.get("bearer-token").toString(); String token=curUser.getToken();
remoteService.getClient(cloudServiceid).put(entity + "/" + businessKey, token,callbackArg); remoteService.getClient(cloudServiceid).put(entity + "/" + businessKey, token,callbackArg);
} }
} }
} }
......
package cn.ibizlab.core.extensions.service; package cn.ibizlab.core.extensions.service;
import cn.ibizlab.core.extensions.domain.FlowUser;
import cn.ibizlab.core.workflow.domain.*; import cn.ibizlab.core.workflow.domain.*;
import cn.ibizlab.core.workflow.service.IWFGroupService; import cn.ibizlab.core.workflow.service.IWFGroupService;
import cn.ibizlab.core.workflow.service.IWFProcessDefinitionService; import cn.ibizlab.core.workflow.service.IWFProcessDefinitionService;
import cn.ibizlab.util.domain.EntityBase; import cn.ibizlab.core.workflow.service.IWFUserService;
import cn.ibizlab.util.errors.BadRequestAlertException; import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.helper.RuleUtils; import cn.ibizlab.util.helper.RuleUtils;
import cn.ibizlab.util.security.AuthTokenUtil; import cn.ibizlab.util.security.AuthTokenUtil;
import cn.ibizlab.util.security.AuthenticationUser; import cn.ibizlab.util.security.AuthenticationUser;
import cn.ibizlab.util.service.RemoteService; import cn.ibizlab.util.service.RemoteService;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.flowable.bpmn.BpmnAutoLayout; import org.flowable.bpmn.BpmnAutoLayout;
import org.flowable.bpmn.converter.BpmnXMLConverter; import org.flowable.bpmn.converter.BpmnXMLConverter;
import org.flowable.bpmn.model.*; import org.flowable.bpmn.model.*;
import org.flowable.bpmn.model.Process; import org.flowable.bpmn.model.Process;
import org.flowable.common.engine.api.history.HistoricData;
import org.flowable.common.engine.api.identity.AuthenticationContext;
import org.flowable.common.engine.impl.identity.Authentication; import org.flowable.common.engine.impl.identity.Authentication;
import org.flowable.common.engine.impl.identity.UserIdAuthenticationContext;
import org.flowable.editor.language.json.converter.BpmnJsonConverter; import org.flowable.editor.language.json.converter.BpmnJsonConverter;
import org.flowable.engine.HistoryService; import org.flowable.engine.HistoryService;
import org.flowable.engine.RepositoryService; import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService; import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService; import org.flowable.engine.TaskService;
import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.history.HistoricActivityInstance;
import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.history.ProcessInstanceHistoryLog;
import org.flowable.engine.repository.Deployment; import org.flowable.engine.repository.Deployment;
import org.flowable.engine.repository.DeploymentBuilder; import org.flowable.engine.repository.DeploymentBuilder;
import org.flowable.engine.runtime.ProcessInstance; import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.idm.engine.impl.persistence.entity.UserEntityImpl; import org.flowable.engine.task.Comment;
import org.flowable.identitylink.api.IdentityLink;
import org.flowable.task.api.Task; import org.flowable.task.api.Task;
import org.flowable.task.api.TaskQuery; import org.flowable.task.api.TaskQuery;
import org.flowable.task.service.impl.persistence.entity.HistoricTaskInstanceEntity;
import org.flowable.ui.common.security.SecurityUtils; import org.flowable.ui.common.security.SecurityUtils;
import org.flowable.ui.modeler.domain.AbstractModel; import org.flowable.ui.modeler.domain.AbstractModel;
import org.flowable.ui.modeler.domain.AppModelDefinition; import org.flowable.ui.modeler.domain.AppModelDefinition;
...@@ -37,8 +45,6 @@ import org.flowable.ui.modeler.model.AppDefinitionRepresentation; ...@@ -37,8 +45,6 @@ import org.flowable.ui.modeler.model.AppDefinitionRepresentation;
import org.flowable.ui.modeler.model.AppDefinitionSaveRepresentation; import org.flowable.ui.modeler.model.AppDefinitionSaveRepresentation;
import org.flowable.ui.modeler.model.ModelKeyRepresentation; import org.flowable.ui.modeler.model.ModelKeyRepresentation;
import org.flowable.ui.modeler.model.ModelRepresentation; import org.flowable.ui.modeler.model.ModelRepresentation;
import org.flowable.ui.modeler.repository.ModelRepository;
import org.flowable.ui.modeler.service.ModelServiceImpl;
import org.flowable.ui.modeler.serviceapi.AppDefinitionService; import org.flowable.ui.modeler.serviceapi.AppDefinitionService;
import org.flowable.ui.modeler.serviceapi.ModelService; import org.flowable.ui.modeler.serviceapi.ModelService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -51,6 +57,7 @@ import org.springframework.util.StringUtils; ...@@ -51,6 +57,7 @@ import org.springframework.util.StringUtils;
import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamReader;
import java.io.*; import java.io.*;
import java.security.Principal;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.*; import java.util.*;
...@@ -74,6 +81,10 @@ public class WFCoreService ...@@ -74,6 +81,10 @@ public class WFCoreService
@Autowired @Autowired
private ModelService modelService; private ModelService modelService;
@Autowired
private IWFUserService iwfUserService;
@Autowired @Autowired
protected AppDefinitionService appDefinitionService; protected AppDefinitionService appDefinitionService;
...@@ -86,23 +97,19 @@ public class WFCoreService ...@@ -86,23 +97,19 @@ public class WFCoreService
@Autowired @Autowired
private AuthTokenUtil jwtTokenUtil; private AuthTokenUtil jwtTokenUtil;
private HashMap getCurUser() private AuthenticationContext createAuthenticationContext()
{ {
HashMap curUser=new HashMap(); UserIdAuthenticationContext context=new UserIdAuthenticationContext();
AuthenticationUser user=AuthenticationUser.getAuthenticationUser(); AuthenticationUser user=AuthenticationUser.getAuthenticationUser();
curUser.put("userid",user.getUserid()); FlowUser principal=new FlowUser();
curUser.put("username",user.getUsername()); principal.setUser(user);
curUser.put("personname",user.getPersonname()); principal.setToken("Bearer "+jwtTokenUtil.generateToken(user));
curUser.put("orgid",user.getOrgid()); context.setPrincipal((Principal) principal);
curUser.put("mdeptid",user.getMdeptid()); return context;
curUser.put("bcode",user.getBcode());
curUser.put("orgInfo",user.getOrgInfo());
curUser.put("sessionParams",user.getSessionParams());
curUser.put("bearer-token","Bearer "+jwtTokenUtil.generateToken(user));
return curUser;
} }
public List<WFProcessDefinition> getWorkflow(String system,String appname,String entity) { public List<WFProcessDefinition> getWorkflow(String system,String appname,String entity) {
return wfModelService.getWorkflow(system,entity); return wfModelService.getWorkflow(system,entity);
} }
...@@ -138,6 +145,7 @@ public class WFCoreService ...@@ -138,6 +145,7 @@ public class WFCoreService
if(StringUtils.isEmpty(userId)) if(StringUtils.isEmpty(userId))
return wfStepCnt; return wfStepCnt;
//runtimeService.createNativeProcessInstanceQuery().
TaskQuery query=taskService.createTaskQuery().taskCandidateOrAssigned(userId); TaskQuery query=taskService.createTaskQuery().taskCandidateOrAssigned(userId);
if(!StringUtils.isEmpty(processDefinitionKey)) if(!StringUtils.isEmpty(processDefinitionKey))
query.processDefinitionKey(processDefinitionKey); query.processDefinitionKey(processDefinitionKey);
...@@ -203,7 +211,7 @@ public class WFCoreService ...@@ -203,7 +211,7 @@ public class WFCoreService
Map<String, Object> variables = new LinkedHashMap<>(); Map<String, Object> variables = new LinkedHashMap<>();
variables.put("businessKey",businessKey); variables.put("businessKey",businessKey);
variables.put("activedata",instance.get("activedata")); variables.put("activedata",instance.get("activedata"));
variables.put("curuser",getCurUser()); //variables.put("curuser",getCurUser());
variables.put("cloud-serviceid",system+"-"+appname); variables.put("cloud-serviceid",system+"-"+appname);
variables.put("system",system); variables.put("system",system);
variables.put("appname",appname); variables.put("appname",appname);
...@@ -211,6 +219,7 @@ public class WFCoreService ...@@ -211,6 +219,7 @@ public class WFCoreService
variables.put("wfversion",version); variables.put("wfversion",version);
//根据流程定义启动流程 //根据流程定义启动流程
Authentication.setAuthenticatedUserId(userId); Authentication.setAuthenticatedUserId(userId);
Authentication.setAuthenticationContext(createAuthenticationContext());
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey,processInstanceBusinessKey, variables);//流程定时标识、业务标识、变量 ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey,processInstanceBusinessKey, variables);//流程定时标识、业务标识、变量
instance.setBusinesskey(processInstanceBusinessKey); instance.setBusinesskey(processInstanceBusinessKey);
instance.setId(processInstance.getId()); instance.setId(processInstance.getId());
...@@ -344,22 +353,151 @@ public class WFCoreService ...@@ -344,22 +353,151 @@ public class WFCoreService
} }
Map<String, Object> transientVariables = new LinkedHashMap<>(); Map<String, Object> transientVariables = new LinkedHashMap<>();
transientVariables.put("activedata",activedata); transientVariables.put("activedata",activedata);
transientVariables.put("curuser",getCurUser()); //transientVariables.put("curuser",getCurUser());
//根据流程定义启动流程 //根据流程定义启动流程
Authentication.setAuthenticatedUserId(userId); Authentication.setAuthenticatedUserId(userId);
String wfprocdesc=""; Authentication.setAuthenticationContext(createAuthenticationContext());
if(activedata.get("wfprocdesc")!=null)
wfprocdesc=activedata.get("wfprocdesc").toString();
taskService.addComment(taskId,taskWay.getProcessinstanceid(),taskWay.getSequenceflowname(),wfprocdesc);
taskService.complete(taskId, variables,transientVariables); taskService.complete(taskId, variables,transientVariables);
WFProcessInstance instance = new WFProcessInstance(); WFProcessInstance instance = new WFProcessInstance();
instance.setBusinesskey(processInstanceBusinessKey); instance.setBusinesskey(processInstanceBusinessKey);
return instance; return instance;
} }
public WFProcessInstance getWFHistory(String system,String appname,
String entity,String businessKey,String processInstanceId)
{
WFProcessInstance wfProcessInstance=new WFProcessInstance();
String processInstanceBusinessKey=system+":"+entity+":k-"+businessKey;
List<String> processInstanceIds=new ArrayList<>();
if(StringUtils.isEmpty(processInstanceId))
{
List<HistoricProcessInstance> instances=historyService.createHistoricProcessInstanceQuery().processInstanceBusinessKey(processInstanceBusinessKey).orderByProcessInstanceStartTime().asc().list();
if(instances.size()==0)
return wfProcessInstance;
for(HistoricProcessInstance instance:instances)
{
processInstanceIds.add(instance.getId());
}
}
else
processInstanceIds.add(processInstanceId);
Map<String,WFProcessNode> nodes=new LinkedHashMap<>();
List<Comment> comments = new ArrayList<>();
Map<String,HistoricTaskInstanceEntity> tasks=new LinkedHashMap<>();
Set<String> waitTaskId=new LinkedHashSet<>();
Map<String,WFUser> wfUserMap = new HashMap<>();
Timestamp endTime=null;
for(String id:processInstanceIds) {
ProcessInstanceHistoryLog processInstanceHistoryLog = historyService.createProcessInstanceHistoryLogQuery(id).includeTasks().includeActivities().includeComments().singleResult();
if(!StringUtils.isEmpty(processInstanceHistoryLog.getStartUserId()))
{
WFUser user=new WFUser();
user.setId(processInstanceHistoryLog.getStartUserId());
wfUserMap.put(processInstanceHistoryLog.getStartUserId(),user);
}
if(StringUtils.isEmpty(wfProcessInstance.getId())) {
wfProcessInstance.setId(processInstanceHistoryLog.getId());
wfProcessInstance.setStarttime(new Timestamp(processInstanceHistoryLog.getStartTime().getTime()));
wfProcessInstance.setBusinesskey(processInstanceHistoryLog.getBusinessKey());
wfProcessInstance.setStartuserid(processInstanceHistoryLog.getStartUserId());
}
if(processInstanceHistoryLog.getEndTime()!=null)
{
if(endTime==null||processInstanceHistoryLog.getEndTime().getTime()>=endTime.getTime())
endTime = (new Timestamp(processInstanceHistoryLog.getEndTime().getTime()));
}
List<HistoricData> historicData = processInstanceHistoryLog.getHistoricData();
for (HistoricData data :historicData){
if (data instanceof HistoricActivityInstance){
HistoricActivityInstance hai= (HistoricActivityInstance) data;
if(!hai.getActivityType().equals("userTask"))
continue;
if(!nodes.containsKey(hai.getActivityId()))
{
WFProcessNode node=new WFProcessNode();
node.setUsertaskid(hai.getActivityId());
node.setUsertaskname(hai.getActivityName());
node.set("comments",new ArrayList<WFHistory>());
node.set("identityLinks",new ArrayList<WFUser>());
nodes.put(hai.getActivityId(),node);
}
}
else if(data instanceof Comment)
{
Comment comment=(Comment)data;
if(!StringUtils.isEmpty(comment.getUserId())){
WFUser user=new WFUser();
user.setId(comment.getUserId());
wfUserMap.put(comment.getUserId(),user);
comments.add(comment);
}
}
else if(data instanceof HistoricTaskInstanceEntity)
{
HistoricTaskInstanceEntity historicTaskInstanceEntity= (HistoricTaskInstanceEntity) data;
tasks.put(historicTaskInstanceEntity.getId(),historicTaskInstanceEntity);
if(historicTaskInstanceEntity.getEndTime()==null)
waitTaskId.add(historicTaskInstanceEntity.getId());
}
}
}
if(waitTaskId.size()>0){
for(String taskid:waitTaskId) {
List<IdentityLink> idlinks = taskService.getIdentityLinksForTask(taskid);
for(IdentityLink idlink:idlinks)
{
WFUser user=new WFUser();
user.setId(idlink.getUserId());
wfUserMap.put(idlink.getUserId(),user);
((ArrayList)nodes.get(tasks.get(taskid).getTaskDefinitionKey()).get("identityLinks")).add(user);
}
}
}
else
wfProcessInstance.setEndtime(endTime);
if(wfUserMap.size()>0)
iwfUserService.listByIds(wfUserMap.keySet()).forEach(item ->wfUserMap.get(item.getId()).setDisplayname(item.getDisplayname()));
for(Comment comment:comments)
{
if(tasks.containsKey(comment.getTaskId())&&(nodes.containsKey(tasks.get(comment.getTaskId()).getTaskDefinitionKey()))) {
if(wfUserMap.containsKey(comment.getUserId())) {
WFHistory history = new WFHistory();
history.setId(comment.getId());
history.setAuthor(comment.getUserId());
history.setAuthorname(wfUserMap.get(comment.getUserId()).getDisplayname());
history.setFullmessage(comment.getFullMessage());
history.setTime(new Timestamp(comment.getTime().getTime()));
history.setType(comment.getType());
//history.setTaskid(comment.getTaskId());
//history.setProcessinstanceid(comment.getProcessInstanceId());
//history.setProcessinstancebusinesskey(businessKey);
((ArrayList) nodes.get(tasks.get(comment.getTaskId()).getTaskDefinitionKey()).get("comments")).add(history);
}
}
}
wfProcessInstance.set("userTasks",nodes.values());
if(!StringUtils.isEmpty(wfProcessInstance.getStartuserid()))
{
wfProcessInstance.setStartusername(wfUserMap.get(wfProcessInstance.getStartuserid()).getDisplayname());
}
wfProcessInstance.setBusinesskey(businessKey);
return wfProcessInstance;
}
@Value("${ibiz.filePath:/app/file/}") @Value("${ibiz.filePath:/app/file/}")
private String fileRoot; private String fileRoot;
...@@ -619,7 +757,8 @@ public class WFCoreService ...@@ -619,7 +757,8 @@ public class WFCoreService
if(delegateExecution.getCurrentFlowElement() instanceof ServiceTask && activedata instanceof Map) if(delegateExecution.getCurrentFlowElement() instanceof ServiceTask && activedata instanceof Map)
{ {
ServiceTask task=(ServiceTask)delegateExecution.getCurrentFlowElement(); ServiceTask task=(ServiceTask)delegateExecution.getCurrentFlowElement();
HashMap curUser=(HashMap)delegateExecution.getVariable("curuser"); //HashMap curUser=(HashMap)delegateExecution.getVariable("curuser");
FlowUser curUser=FlowUser.getCurUser();
String businessKey=(String)delegateExecution.getVariable("businessKey"); String businessKey=(String)delegateExecution.getVariable("businessKey");
String cloudServiceId=(String)delegateExecution.getVariable("cloud-serviceid"); String cloudServiceId=(String)delegateExecution.getVariable("cloud-serviceid");
Map entity=(Map) activedata; Map entity=(Map) activedata;
...@@ -644,9 +783,9 @@ public class WFCoreService ...@@ -644,9 +783,9 @@ public class WFCoreService
} }
if(StringUtils.isEmpty(serviceEntity)||StringUtils.isEmpty(serviceDEAction)) if(StringUtils.isEmpty(serviceEntity)||StringUtils.isEmpty(serviceDEAction))
return; return;
if(curUser.get("bearer-token")==null) if(StringUtils.isEmpty(curUser.getToken()))
return; return;
String token=curUser.get("bearer-token").toString(); String token=curUser.getToken();
String path=serviceEntity; String path=serviceEntity;
if(serviceDEAction.equalsIgnoreCase("create")) if(serviceDEAction.equalsIgnoreCase("create"))
remoteService.getClient(cloudServiceId).post(path,token,entity); remoteService.getClient(cloudServiceId).post(path,token,entity);
......
...@@ -65,6 +65,16 @@ public class WFCoreResource ...@@ -65,6 +65,16 @@ public class WFCoreResource
return ResponseEntity.status(HttpStatus.OK).body(wfCoreService.getTaskLink(system,appname,entity,businessKey,taskId)); return ResponseEntity.status(HttpStatus.OK).body(wfCoreService.getTaskLink(system,appname,entity,businessKey,taskId));
} }
@ApiOperation(value = "getWFHistory", tags = {"getWFHistory" }, notes = "根据业务主键获取审批意见记录")
@RequestMapping(method = RequestMethod.GET, value = "/{system}-app-{appname}/{entity}/{businessKey}/process-instances/{processInstanceId}/history")
public ResponseEntity<WFProcessInstance> getWFHistory(@PathVariable("system") String system,@PathVariable("appname") String appname,
@PathVariable("entity") String entity,
@PathVariable("businessKey") String businessKey,@PathVariable("processInstanceId") String processInstanceId) {
if(StringUtils.isEmpty(processInstanceId)||"null".equals(processInstanceId)||"alls".equals(processInstanceId))
processInstanceId="";
return ResponseEntity.status(HttpStatus.OK).body(wfCoreService.getWFHistory(system,appname,entity,businessKey,processInstanceId));
}
//@PreAuthorize("hasPermission(#entity,'WFSTART',this.getEntity())") //@PreAuthorize("hasPermission(#entity,'WFSTART',this.getEntity())")
@ApiOperation(value = "wfsubmit", tags = {"WFProcessInstance" }, notes = "工作流执行步骤") @ApiOperation(value = "wfsubmit", tags = {"WFProcessInstance" }, notes = "工作流执行步骤")
@RequestMapping(method = RequestMethod.POST, value = "/{system}-app-{appname}/{entity}/{businessKey}/tasks/{taskId}") @RequestMapping(method = RequestMethod.POST, value = "/{system}-app-{appname}/{entity}/{businessKey}/tasks/{taskId}")
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册