提交 656b4923 authored 作者: 黄夏豪's avatar 黄夏豪

[数据模型] 更新了流程结束的触发器

上级 da15f32d
......@@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonGetter;
import com.tykj.workflowcore.base.entity.BaseEntity;
import com.tykj.workflowcore.model_layer.annotations.WorkFlowCoreNoScan;
import com.tykj.workflowcore.workflow_editer.entity.vo.InvokeRequestVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
......@@ -27,11 +28,12 @@ import javax.persistence.Entity;
@Data
public class VariableStorage extends BaseEntity {
@ApiModelProperty("流程主键")
private String flowKey;
@ApiModelProperty("流程主键")
private String activityId;
@ApiModelProperty("调用类名")
private String className;
......@@ -41,6 +43,7 @@ public class VariableStorage extends BaseEntity {
@ApiModelProperty("详情json")
private String invokeRequest;
@JsonGetter
public InvokeRequestVo getInvokeRequest() {
return JSON.parseObject(invokeRequest,InvokeRequestVo.class);
......
......@@ -7,6 +7,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.runtime.ProcessInstance;
import java.util.List;
......@@ -26,7 +27,7 @@ import java.util.List;
public class InvokeRequestVo {
@ApiModelProperty("流程实例")
private ProcessInstance processInstance;
private DelegateExecution processInstance;
@ApiModelProperty("流程实例id")
private String processInstanceId;
......
......@@ -21,7 +21,10 @@ public class SearchVariableStorageVo extends JpaCustomPage {
private String flowKey;
public SearchVariableStorageVo(String flowKey) {
private String activityId;
public SearchVariableStorageVo(String flowKey,String activityId) {
this.flowKey = flowKey;
this.activityId = activityId;
}
}
......@@ -3,6 +3,7 @@ package com.tykj.workflowcore.workflow_editer.entity.vo;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonParser;
import com.tykj.workflowcore.workflow_editer.entity.VariableStorage;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
......@@ -20,12 +21,19 @@ import springfox.documentation.spring.web.json.Json;
@NoArgsConstructor
public class VariableStorageVo {
@ApiModelProperty("主键")
private Integer id;
@ApiModelProperty("流程主键")
private String flowKey;
@ApiModelProperty("节点Id")
private String activityId;
@ApiModelProperty("调用类名")
private String className;
@ApiModelProperty("调用方法名")
private String method;
private InvokeRequestVo invokeRequest;
......
......@@ -9,11 +9,15 @@ import com.tykj.workflowcore.workflow_editer.entity.VariableStorage;
import com.tykj.workflowcore.workflow_editer.entity.vo.InvokeRequestVo;
import com.tykj.workflowcore.workflow_editer.entity.vo.SearchVariableStorageVo;
import com.tykj.workflowcore.workflow_editer.service.VariableStorageService;
import org.flowable.bpmn.model.EndEvent;
import org.flowable.common.engine.api.delegate.Expression;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent;
import org.flowable.common.engine.api.delegate.event.FlowableEvent;
import org.flowable.engine.*;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.event.AbstractFlowableEngineEventListener;
import org.flowable.engine.delegate.event.FlowableActivityEvent;
import org.flowable.engine.delegate.event.impl.FlowableActivityEventImpl;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
import org.flowable.engine.runtime.ProcessInstance;
......@@ -51,26 +55,28 @@ public class ProcessEndListener extends AbstractFlowableEngineEventListener {
@Autowired
ApiController apiController;
@Override
protected void processCompleted(FlowableEngineEntityEvent event) {
//流程结束了
if (event.getEntity() instanceof ProcessInstance){
ProcessInstance processInstance = (ProcessInstance) event.getEntity();
String processDefinitionId = processInstance.getProcessDefinitionId();
String flowKey = processDefinitionId;
if (processDefinitionId.indexOf(":")>=0){
flowKey = processDefinitionId.substring(0,processDefinitionId.indexOf(":"));
}
List<VariableStorage> variableStorageList = variableStorageService.searchVariableStorageList(new SearchVariableStorageVo(flowKey));
for (VariableStorage variableStorage : variableStorageList) {
InvokeRequestVo variableInfo = variableStorage.getInvokeRequest();
variableInfo.setProcessInstance(processInstance);
//调用服务接口
//1. 获取调用的具体数值
apiController.invoke(getApiInvokeParam(variableInfo));
}
}
// if (event.getEntity() instanceof ProcessInstance){
// ProcessInstance processInstance = (ProcessInstance) event.getEntity();
// String processDefinitionId = processInstance.getProcessDefinitionId();
// String flowKey = processDefinitionId;
// if (processDefinitionId.indexOf(":")>=0){
// flowKey = processDefinitionId.substring(0,processDefinitionId.indexOf(":"));
// }
// List<VariableStorage> variableStorageList = variableStorageService.searchVariableStorageList(new SearchVariableStorageVo(flowKey));
// for (VariableStorage variableStorage : variableStorageList) {
// InvokeRequestVo variableInfo = variableStorage.getInvokeRequest();
// variableInfo.setProcessInstance(processInstance);
// //调用服务接口
//
// //1. 获取调用的具体数值
// apiController.invoke(getApiInvokeParam(variableInfo));
// }
// }
// throw new ApiException("强行报错");
}
......@@ -81,10 +87,32 @@ public class ProcessEndListener extends AbstractFlowableEngineEventListener {
@Override
public void onEvent(FlowableEvent flowableEvent) {
System.out.println(flowableEvent.getType());
super.onEvent(flowableEvent);
}
@Override
protected void activityCompleted(FlowableActivityEvent event) {
super.activityCompleted(event);
if (event instanceof FlowableActivityEventImpl){
DelegateExecution execution = ((FlowableActivityEventImpl) event).getExecution();
if (execution.getCurrentFlowElement() instanceof EndEvent){
System.out.println("流程结束了");
String processDefinitionId = execution.getProcessDefinitionId();
String flowKey = processDefinitionId;
if (processDefinitionId.indexOf(":")>=0){
flowKey = processDefinitionId.substring(0,processDefinitionId.indexOf(":"));
}
List<VariableStorage> variableStorageList = variableStorageService.searchVariableStorageList(new SearchVariableStorageVo(flowKey,execution.getCurrentActivityId()));
for (VariableStorage variableStorage : variableStorageList) {
InvokeRequestVo variableInfo = variableStorage.getInvokeRequest();
variableInfo.setProcessInstance(execution);
//调用服务接口
apiController.invoke(getApiInvokeParam(variableInfo));
}
}
}
}
/**
* 获取调用Api用的参数
*
......@@ -93,21 +121,21 @@ public class ProcessEndListener extends AbstractFlowableEngineEventListener {
*/
public InvokeRequest getApiInvokeParam(InvokeRequestVo invokeRequestVo) {
//拿出taskId
ProcessInstance processInstance = invokeRequestVo.getProcessInstance();
DelegateExecution execution = invokeRequestVo.getProcessInstance();
List<Parameter> parameterList = invokeRequestVo.getParams();
List<Parameter> newParameterList = new ArrayList<>();
for (int i = 0; i < parameterList.size(); i++) {
Parameter parameter = parameterList.get(i);
if (!StringUtils.isEmpty(parameter.getExp())) {
//如果是表示式 如:${people}
parameter.setInstance((Map<String, Object>) getProcessValue(processInstance, parameter.getExp()));
parameter.setInstance((Map<String, Object>) getProcessValue(execution, parameter.getExp()));
} else {
Map<String, Object> instance = parameter.getInstance();
JSONObject newInstance = new JSONObject();
//遍历param的key
Set<String> oldInstanceKey = instance.keySet();
for (String key : oldInstanceKey) {
newInstance.put(key, getProcessValue(processInstance, (String) instance.get(key)));
newInstance.put(key, getProcessValue(execution, (String) instance.get(key)));
}
parameter.setInstance(newInstance);
}
......@@ -117,10 +145,10 @@ public class ProcessEndListener extends AbstractFlowableEngineEventListener {
return JSONObject.parseObject(JSONObject.toJSONString(invokeRequestVo), InvokeRequest.class);
}
public Object getProcessValue(ProcessInstance processInstance, String exp) {
public Object getProcessValue(DelegateExecution execution, String exp) {
// processInstance -> ExecutionEntity
Expression expression = processEngineConfiguration.getExpressionManager().createExpression(exp);
return expression.getValue((ExecutionEntity)processInstance);
return expression.getValue(execution);
}
}
......@@ -7,6 +7,8 @@ import com.tykj.workflowcore.workflow_editer.dao.VariableStorageMapper;
import com.tykj.workflowcore.workflow_editer.entity.vo.SearchVariableStorageVo;
import com.tykj.workflowcore.workflow_editer.service.VariableStorageService;
import liquibase.pro.packaged.B;
import liquibase.util.StreamUtil;
import liquibase.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
......@@ -47,7 +49,8 @@ public class VariableStorageServiceImpl implements VariableStorageService {
PredicateBuilder predicateBuilder = Specifications.and();
if (searchVariableStorageVo!=null){
predicateBuilder.eq(searchVariableStorageVo.getId()!=null,"id",searchVariableStorageVo.getId());
predicateBuilder.eq(searchVariableStorageVo.getFlowKey()!=null,"flowKey",searchVariableStorageVo.getFlowKey());
predicateBuilder.eq(StringUtils.isEmpty(searchVariableStorageVo.getFlowKey()),"flowKey",searchVariableStorageVo.getFlowKey());
predicateBuilder.eq(StringUtils.isEmpty(searchVariableStorageVo.getActivityId()),"activityId",searchVariableStorageVo.getActivityId());
}
return variableStorageMapper.findAll(predicateBuilder.build(),searchVariableStorageVo.getPageable());
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论