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

callback

上级 00a34fb1
package cn.ibizlab.core.extensions.listener;
import cn.ibizlab.core.extensions.service.WFCoreService;
import cn.ibizlab.core.extensions.service.WFModelService;
import cn.ibizlab.util.security.AuthTokenUtil;
import cn.ibizlab.util.security.AuthenticationUser;
import cn.ibizlab.util.service.RemoteService;
import lombok.extern.slf4j.Slf4j;
import org.flowable.bpmn.model.UserTask;
import org.flowable.common.engine.api.delegate.event.*;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.common.engine.impl.event.FlowableEntityEventImpl;
import org.flowable.engine.delegate.event.impl.FlowableActivityEventImpl;
import org.flowable.engine.delegate.event.impl.FlowableProcessStartedEventImpl;
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.TaskEntityImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* 流程实例监听器,监听流程实例启动、流转、结束状态
......@@ -23,10 +36,74 @@ import java.util.List;
@Component
public class ProcessInstanceListener implements FlowableEventListener {
@Autowired
@Lazy
private WFCoreService wfCoreService;
@Autowired
@Lazy
private WFModelService wfModelService;
@Autowired
@Lazy
private RemoteService remoteService;
@Autowired
private AuthTokenUtil jwtTokenUtil;
@Override
public void onEvent(FlowableEvent evt) {
if(evt instanceof FlowableEntityEventImpl)
if(evt instanceof FlowableProcessStartedEventImpl)
{
FlowableProcessStartedEventImpl event=(FlowableProcessStartedEventImpl)evt;
if(event.getEntity() instanceof ExecutionEntityImpl){
ExecutionEntityImpl executionEntity= (ExecutionEntityImpl) event.getEntity();
if(executionEntity.getVariable("cloud-serviceid")==null)
return;
String businessKey=(String)executionEntity.getVariable("businessKey");
AuthenticationUser curUser=(AuthenticationUser)executionEntity.getVariable("curuser");
String entity=executionEntity.getVariable("entitys").toString();
String cloudServiceid=executionEntity.getVariable("cloud-serviceid").toString();
Map setting=wfModelService.getProcessGlobalSetting(executionEntity.getProcessDefinitionId());
String wfstepfield="";
if(setting.containsKey("wfstepfield"+"_"+entity))
wfstepfield=setting.get("wfstepfield"+"_"+entity).toString();
String wfinstfield="";
if(setting.containsKey("wfinstfield"+"_"+entity))
wfinstfield=setting.get("wfinstfield"+"_"+entity).toString();
String udstatefield="";
if(setting.containsKey("udstatefield"+"_"+entity))
udstatefield=setting.get("udstatefield"+"_"+entity).toString();
String wfstate="";
if(setting.containsKey("wfstate"+"_"+entity))
wfstate=setting.get("wfstate"+"_"+entity).toString();
String wfverfield="";
if(setting.containsKey("wfverfield"+"_"+entity))
wfverfield=setting.get("wfverfield"+"_"+entity).toString();
executionEntity.setVariable("wfstepfield",wfstepfield);
executionEntity.setVariable("wfinstfield",wfinstfield);
executionEntity.setVariable("udstatefield",udstatefield);
executionEntity.setVariable("wfstate",wfstate);
executionEntity.setVariable("wfverfield",wfverfield);
Map callbackArg=new LinkedHashMap();
if(!StringUtils.isEmpty(wfinstfield))
callbackArg.put(wfinstfield,executionEntity.getProcessInstanceId());
if(!StringUtils.isEmpty(wfstate))
callbackArg.put(wfstate,1);
if(!StringUtils.isEmpty(udstatefield))
callbackArg.put(udstatefield,"20");
if((!StringUtils.isEmpty(wfverfield))&&(executionEntity.getVariable("wfversion")!=null))
callbackArg.put(wfverfield,Integer.parseInt(executionEntity.getVariable("wfversion").toString()));
if(callbackArg.size()>0) {
String token="Bearer "+jwtTokenUtil.generateToken(curUser);
remoteService.getClient(cloudServiceid).put(entity + "/" + businessKey, token,callbackArg);
}
}
}
else if(evt instanceof FlowableEntityEventImpl)
{
FlowableEntityEventImpl event=((FlowableEntityEventImpl) evt);
// 当前节点任务实体
......@@ -34,9 +111,41 @@ public class ProcessInstanceListener implements FlowableEventListener {
// TODO 获取到了taskEntity 自己做每个节点的前置操作
FlowableEventType eventType = event.getType();
//待办创建
if(eventType == FlowableEngineEventType.TASK_CREATED){
if(eventType == FlowableEngineEventType.PROCESS_COMPLETED){
ExecutionEntityImpl executionEntity= (ExecutionEntityImpl) event.getEntity();
if(executionEntity.getVariable("cloud-serviceid")==null)
return;
String businessKey=(String)executionEntity.getVariable("businessKey");
AuthenticationUser curUser=(AuthenticationUser)executionEntity.getVariable("curuser");
String entity=executionEntity.getVariable("entitys").toString();
String cloudServiceid=executionEntity.getVariable("cloud-serviceid").toString();
String wfstepfield = executionEntity.getVariable("wfstepfield").toString();
String udstatefield = executionEntity.getVariable("udstatefield").toString();
String wfstate = executionEntity.getVariable("wfstate").toString();
Map callbackArg=new LinkedHashMap();
if(!StringUtils.isEmpty(wfstate))
callbackArg.put(wfstate,2);
if(!StringUtils.isEmpty(udstatefield))
callbackArg.put(udstatefield,"30");
if(!StringUtils.isEmpty(wfstepfield))
callbackArg.put(wfstepfield,"");
if(callbackArg.size()>0) {
String token="Bearer "+jwtTokenUtil.generateToken(curUser);
remoteService.getClient(cloudServiceid).put(entity + "/" + businessKey, token,callbackArg);
}
System.out.println("流程结束");
}
if(eventType == FlowableEngineEventType.PROCESS_COMPLETED_WITH_ERROR_END_EVENT){
event.getEntity();
System.out.println("流程异常结束");
}
//待办分配
else if(eventType == FlowableEngineEventType.TASK_CREATED){
TaskEntity taskEntity = (TaskEntity) event.getEntity();
System.out.println("创建任务");
System.out.println("分配任务");
}
//待办分配
else if(eventType == FlowableEngineEventType.TASK_ASSIGNED){
......@@ -49,6 +158,31 @@ public class ProcessInstanceListener implements FlowableEventListener {
System.out.println("完成任务");
}
}
else if(evt instanceof FlowableActivityEventImpl)
{
FlowableActivityEventImpl event=((FlowableActivityEventImpl) evt);
// 当前节点任务实体
// TODO 获取到了taskEntity 自己做每个节点的前置操作
FlowableEventType eventType = event.getType();
if(eventType == FlowableEngineEventType.ACTIVITY_STARTED && "userTask".equals(event.getActivityType())){
if(event.getExecution().getVariable("cloud-serviceid")==null)
return;
String businessKey=(String)event.getExecution().getVariable("businessKey");
AuthenticationUser curUser=(AuthenticationUser)event.getExecution().getVariable("curuser");
String entity=event.getExecution().getVariable("entitys").toString();
String cloudServiceid=event.getExecution().getVariable("cloud-serviceid").toString();
String wfstepfield = event.getExecution().getVariable("wfstepfield").toString();
Map callbackArg=new LinkedHashMap();
if(!StringUtils.isEmpty(wfstepfield)&&event.getActivityId().startsWith("tid-"))
callbackArg.put(wfstepfield,event.getActivityId().split("-")[1]);
if(callbackArg.size()>0) {
String token="Bearer "+jwtTokenUtil.generateToken(curUser);
remoteService.getClient(cloudServiceid).put(entity + "/" + businessKey, token,callbackArg);
}
}
}
}
......
......@@ -5,7 +5,10 @@ import cn.ibizlab.core.workflow.service.IWFGroupService;
import cn.ibizlab.core.workflow.service.IWFProcessDefinitionService;
import cn.ibizlab.util.domain.EntityBase;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.security.AuthTokenUtil;
import cn.ibizlab.util.security.AuthenticationUser;
import cn.ibizlab.util.service.RemoteService;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.flowable.bpmn.converter.BpmnXMLConverter;
import org.flowable.bpmn.model.*;
......@@ -135,12 +138,20 @@ public class WFCoreService
String userId=AuthenticationUser.getAuthenticationUser().getUserid();
if(StringUtils.isEmpty(userId))
throw new BadRequestAlertException("未传入当前用户",entity,businessKey);
Integer version=1;
String processDefinitionKey=instance.getProcessdefinitionkey();
if(StringUtils.isEmpty(processDefinitionKey)){
List<String> definitionKeys=this.getWorkflowKey(system,appname,entity);
if(definitionKeys.size()==0)
List<WFProcessDefinition> definitions=this.getWorkflow(system,appname,entity);
if(definitions.size()==0)
throw new BadRequestAlertException("未找到对应的工作流配置",entity,businessKey);
processDefinitionKey=definitionKeys.get(0);
processDefinitionKey=definitions.get(0).getDefinitionkey();
version=definitions.get(0).getModelversion();
}
else {
WFProcessDefinition definition = iwfProcessDefinitionService.getById(processDefinitionKey);
if(definition==null)
throw new BadRequestAlertException("未找到对应的工作流配置",entity,businessKey);
version=definition.getModelversion();
}
String processInstanceBusinessKey=system+":"+entity+":k-"+businessKey;
......@@ -152,7 +163,10 @@ public class WFCoreService
variables.put("activedata",instance.get("activedata"));
variables.put("curuser",AuthenticationUser.getAuthenticationUser());
variables.put("cloud-serviceid",system+"-app-"+appname);
variables.put("system",system);
variables.put("appname",appname);
variables.put("entitys",entity);
variables.put("wfversion",version);
//根据流程定义启动流程
Authentication.setAuthenticatedUserId(userId);
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey,processInstanceBusinessKey, variables);//流程定时标识、业务标识、变量
......@@ -273,10 +287,8 @@ public class WFCoreService
}
String processInstanceBusinessKey=system+":"+entity+":k-"+businessKey;
Map<String, Object> variables = new LinkedHashMap<>();
variables.put("businessKey",businessKey);
variables.put("sequenceFlowId",taskWay.getSequenceflowid());
variables.put("cloud-serviceid",system+"-app-"+appname);
variables.put("entitys",entity);
Map<String, Object> transientVariables = new LinkedHashMap<>();
transientVariables.put("activedata",taskWay.get("activedata"));
......@@ -290,6 +302,7 @@ public class WFCoreService
return instance;
}
@Value("${ibiz.filePath:/app/file/}")
private String fileRoot;
......@@ -461,9 +474,64 @@ public class WFCoreService
}
@Autowired
private RemoteService remoteService;
@Autowired
private AuthTokenUtil jwtTokenUtil;
public void execute(DelegateExecution delegateExecution,Object activedata) throws Exception {
//String entity = (String)delegateExecution.getVariable("pass");
if(delegateExecution.getCurrentFlowElement() instanceof ServiceTask && activedata instanceof Map)
{
ServiceTask task=(ServiceTask)delegateExecution.getCurrentFlowElement();
AuthenticationUser curUser=(AuthenticationUser)delegateExecution.getVariable("curuser");
String businessKey=(String)delegateExecution.getVariable("businessKey");
String cloudServiceId=(String)delegateExecution.getVariable("cloud-serviceid");
Map entity=(Map) activedata;
String serviceEntity="";
String serviceDEAction="";
for(FieldExtension fieldExtension : task.getFieldExtensions())
{
if("service-entity".equals(fieldExtension.getFieldName()))
{
serviceEntity=fieldExtension.getStringValue();
}
else if("service-deaction".equals(fieldExtension.getFieldName()))
{
serviceDEAction=fieldExtension.getStringValue();
}
else if(fieldExtension.getFieldName().startsWith("params-"))
{
String key=fieldExtension.getFieldName().split("-")[1];
entity.put(key,fieldExtension.getStringValue());
}
}
if(StringUtils.isEmpty(serviceEntity)||StringUtils.isEmpty(serviceDEAction))
return;
String token="Bearer "+jwtTokenUtil.generateToken(curUser);
String path=serviceEntity;
//cloudServiceId="support5";
if(serviceDEAction.equalsIgnoreCase("create"))
remoteService.getClient(cloudServiceId).post(path,token,entity);
else if(serviceDEAction.equalsIgnoreCase("update"))
remoteService.getClient(cloudServiceId).put(path+"/"+businessKey,token,entity);
else if(serviceDEAction.equalsIgnoreCase("remove"))
remoteService.getClient(cloudServiceId).delete(path+"/"+businessKey,token);
else if(serviceDEAction.equalsIgnoreCase("save"))
remoteService.getClient(cloudServiceId).post(path+"/save",token,entity);
else if(serviceDEAction.equalsIgnoreCase("get"))
remoteService.getClient(cloudServiceId).get(path+"/"+businessKey,token);
else if(serviceDEAction.equalsIgnoreCase("getdraft")){}
else if(serviceDEAction.equalsIgnoreCase("checkkey")){}
else
remoteService.getClient(cloudServiceId).post(path+"/"+businessKey+"/"+serviceDEAction,token,entity);
}
System.out.println("test");
// Boolean val = (Boolean) pass.getValue(delegateExecution);
//logger.info("=ProductFactoryNewProductTask=>business:{} prossId:{} pass:{}",delegateExecution.getProcessInstanceBusinessKey(),delegateExecution.getProcessInstanceId(),val.toString());
......
......@@ -4,7 +4,9 @@ import cn.ibizlab.core.workflow.domain.WFProcessDefinition;
import cn.ibizlab.core.workflow.domain.WFProcessNode;
import cn.ibizlab.core.workflow.service.IWFProcessDefinitionService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.flowable.bpmn.model.ExtensionElement;
import org.flowable.bpmn.model.FlowElement;
import org.flowable.bpmn.model.Process;
import org.flowable.bpmn.model.UserTask;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.repository.ProcessDefinition;
......@@ -76,4 +78,15 @@ public class WFModelService
}
return userTasks;
}
public Map<String,Object> getProcessGlobalSetting(String definitionid)
{
LinkedHashMap<String,Object> setting = new LinkedHashMap();
Process process=repositoryService.getBpmnModel(definitionid).getMainProcess();
for(ExtensionElement field:repositoryService.getBpmnModel(definitionid).getMainProcess().getExtensionElements().get("field")) {
if((!StringUtils.isEmpty(field.getAttributes().get("name").get(0).getValue()))&&(!StringUtils.isEmpty(field.getChildElements().get("string").get(0).getElementText())))
setting.put(field.getAttributes().get("name").get(0).getValue(),field.getChildElements().get("string").get(0).getElementText());
}
return setting;
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册