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

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

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