提交 8220af95 authored 作者: 黄夏豪's avatar 黄夏豪

[流程模块] 修改了回调函数时会发生类型错误的Bug

上级 f0d4f878
...@@ -13,6 +13,8 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; ...@@ -13,6 +13,8 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
public class WorkflowCoreApplication { public class WorkflowCoreApplication {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(WorkflowCoreApplication.class, args); SpringApplication.run(WorkflowCoreApplication.class, args);
System.out.println( System.out.println(
"█▀▀▀▀▀▀▀█▀▀▀█▀▀▀█▀▀▀█▀█▀▀▀▀▀▀▀█\n" + "█▀▀▀▀▀▀▀█▀▀▀█▀▀▀█▀▀▀█▀█▀▀▀▀▀▀▀█\n" +
......
...@@ -23,6 +23,6 @@ public class Parameter { ...@@ -23,6 +23,6 @@ public class Parameter {
* key为字段名 value为字段值 * key为字段名 value为字段值
*/ */
@ApiModelProperty(value = "实例对象") @ApiModelProperty(value = "实例对象")
private Map<String,Object> instance; private Object instance;
} }
...@@ -161,8 +161,8 @@ public class ApiService { ...@@ -161,8 +161,8 @@ public class ApiService {
/** /**
* 把map转成指定类型的JavaBean对象 * 把map转成指定类型的JavaBean对象
*/ */
public static <T> T toBean(Map<String, Object> map, Class<T> clazz) { public static <T> T toBean(Object o, Class<T> clazz) {
return JSON.parseObject(JSON.toJSONString(map), clazz); return JSON.parseObject(JSON.toJSONString(o), clazz);
} }
} }
\ No newline at end of file
...@@ -16,7 +16,7 @@ public class ApiException extends RuntimeException { ...@@ -16,7 +16,7 @@ public class ApiException extends RuntimeException {
} }
public ApiException(String message) { public ApiException(String message) {
this.responseEntity = ResponseEntity.status(500).body(new ResultObj(message)); this.responseEntity = ResponseEntity.status(500).body(new ResultObj("",message));
} }
public ApiException( Object data,String message) { public ApiException( Object data,String message) {
......
...@@ -25,5 +25,5 @@ public class SearchTableInfoVo extends JpaCustomPage { ...@@ -25,5 +25,5 @@ public class SearchTableInfoVo extends JpaCustomPage {
private String modelTitle; private String modelTitle;
private List<Integer> modelType; private Integer[] modelType;
} }
...@@ -95,7 +95,7 @@ public class ModelImpl implements ModelService { ...@@ -95,7 +95,7 @@ public class ModelImpl implements ModelService {
PredicateBuilder<TableInfo> and = Specifications.and(); PredicateBuilder<TableInfo> and = Specifications.and();
and.like(searchTableInfoVo.getModelName() != null && StringUtils.isNotEmpty(searchTableInfoVo.getModelName()), "modelName", "%" + searchTableInfoVo.getModelName() + "%"); and.like(searchTableInfoVo.getModelName() != null && StringUtils.isNotEmpty(searchTableInfoVo.getModelName()), "modelName", "%" + searchTableInfoVo.getModelName() + "%");
and.like(searchTableInfoVo.getModelTitle() != null && StringUtils.isNotEmpty(searchTableInfoVo.getModelTitle()), "modelTitle", "%" + searchTableInfoVo.getModelTitle() + "%"); and.like(searchTableInfoVo.getModelTitle() != null && StringUtils.isNotEmpty(searchTableInfoVo.getModelTitle()), "modelTitle", "%" + searchTableInfoVo.getModelTitle() + "%");
and.in(searchTableInfoVo.getModelType() != null&&searchTableInfoVo.getModelType().size()>0, "modelType", searchTableInfoVo.getModelType()); and.in(searchTableInfoVo.getModelType() != null&&searchTableInfoVo.getModelType().length>0, "modelType", searchTableInfoVo.getModelType());
return tableInfoDao.findAll(and.build(), searchTableInfoVo.getPageable()); return tableInfoDao.findAll(and.build(), searchTableInfoVo.getPageable());
} }
......
...@@ -97,26 +97,26 @@ public class FlowsInfoController { ...@@ -97,26 +97,26 @@ public class FlowsInfoController {
} }
@PostMapping("/createFlow") @PostMapping("/createFlow")
@ApiModelProperty("创建流程") @ApiOperation("创建流程")
public ResponseEntity createFlow(@RequestBody FlowsInfoVo flowsInfovo){ public ResponseEntity createFlow(@RequestBody FlowsInfoVo flowsInfovo){
return ResultUtil.success(workFlowService.createFlow(flowsInfovo.toEntity()),"流程创建成功"); return ResultUtil.success(workFlowService.createFlow(flowsInfovo.toEntity()),"流程创建成功");
} }
@PostMapping("/saveVariableStorage") @PostMapping("/saveVariableStorage")
@ApiModelProperty("保存函数调用配置") @ApiOperation("保存函数调用配置")
public ResponseEntity saveVariableStorage(@RequestBody VariableStorageVo variableStorageVo){ public ResponseEntity saveVariableStorage(@RequestBody VariableStorageVo variableStorageVo){
VariableStorage variableStorage = variableStorageService.saveVariableStorageService(variableStorageVo.toEntity()); VariableStorage variableStorage = variableStorageService.saveVariableStorageService(variableStorageVo.toEntity());
return ResultUtil.success(variableStorage,"保存接口调用配置成功"); return ResultUtil.success(variableStorage,"保存接口调用配置成功");
} }
@PostMapping("/searchVariableStorage") @PostMapping("/searchVariableStorage")
@ApiModelProperty("查找函数调用配置") @ApiOperation("查找函数调用配置")
public ResponseEntity searchVariableStorage(@RequestBody SearchVariableStorageVo searchVariableStorageVo){ public ResponseEntity searchVariableStorage(@RequestBody SearchVariableStorageVo searchVariableStorageVo){
return ResultUtil.success( variableStorageService.searchVariableStoragePage(searchVariableStorageVo),"查询接口调用配置成功"); return ResultUtil.success( variableStorageService.searchVariableStoragePage(searchVariableStorageVo),"查询接口调用配置成功");
} }
@GetMapping("/searchVariableStorage") @GetMapping("/searchVariableStorage")
@ApiModelProperty("根据ID查找函数调用配置") @ApiOperation("根据ID查找函数调用配置")
public ResponseEntity searchVariableStorageById(Integer id){ public ResponseEntity searchVariableStorageById(Integer id){
return ResultUtil.success( variableStorageService.searchVariableById(id),"查询接口调用配置成功"); return ResultUtil.success( variableStorageService.searchVariableById(id),"查询接口调用配置成功");
} }
......
...@@ -14,6 +14,7 @@ import lombok.Data; ...@@ -14,6 +14,7 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Lob;
import java.util.List; import java.util.List;
/** /**
...@@ -41,14 +42,16 @@ public class VariableStorage extends BaseEntity { ...@@ -41,14 +42,16 @@ public class VariableStorage extends BaseEntity {
private String className; private String className;
@ApiModelProperty("调用方法") @ApiModelProperty("调用方法")
private String method; private String name;
@ApiModelProperty("方法描述")
private String description;
@Lob
@ApiModelProperty("详情json") @ApiModelProperty("详情json")
private String parameterInfo; private String params;
@JsonGetter public List<ParameterVo> getParams() {
public List<ParameterVo> getParameterInfo() { return JSON.parseObject(params,new TypeReference<List<ParameterVo>>(){});
return JSON.parseObject(parameterInfo,new TypeReference<List<ParameterVo>>(){});
} }
} }
...@@ -24,6 +24,6 @@ public class ParameterVo { ...@@ -24,6 +24,6 @@ public class ParameterVo {
private String name; private String name;
private List<ParameterVo> params; private List<ParameterVo> fields;
} }
...@@ -38,12 +38,15 @@ public class VariableStorageVo { ...@@ -38,12 +38,15 @@ public class VariableStorageVo {
@ApiModelProperty("调用方法名") @ApiModelProperty("调用方法名")
private String name; private String name;
@ApiModelProperty("方法描述")
private String description;
private List<ParameterVo> params; private List<ParameterVo> params;
public VariableStorage toEntity(){ public VariableStorage toEntity(){
VariableStorage variableStorage = new VariableStorage(); VariableStorage variableStorage = new VariableStorage();
BeanUtils.copyProperties(this,variableStorage); BeanUtils.copyProperties(this,variableStorage);
variableStorage.setParameterInfo(JSON.toJSONString(params)); variableStorage.setParams(JSON.toJSONString(params));
return variableStorage; return variableStorage;
} }
} }
...@@ -6,14 +6,17 @@ import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer; ...@@ -6,14 +6,17 @@ import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import com.tykj.workflowcore.api.controller.ApiController; import com.tykj.workflowcore.api.controller.ApiController;
import com.tykj.workflowcore.api.entity.InvokeRequest; import com.tykj.workflowcore.api.entity.InvokeRequest;
import com.tykj.workflowcore.api.entity.Parameter; import com.tykj.workflowcore.api.entity.Parameter;
import com.tykj.workflowcore.base.result.ApiException;
import com.tykj.workflowcore.workflow_editer.entity.CommandGetValue; import com.tykj.workflowcore.workflow_editer.entity.CommandGetValue;
import com.tykj.workflowcore.workflow_editer.entity.DataHistory; import com.tykj.workflowcore.workflow_editer.entity.DataHistory;
import com.tykj.workflowcore.workflow_editer.entity.JavaTypeEnum;
import com.tykj.workflowcore.workflow_editer.entity.VariableStorage; 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.ParameterVo; import com.tykj.workflowcore.workflow_editer.entity.vo.ParameterVo;
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.DataHistoryService; import com.tykj.workflowcore.workflow_editer.service.DataHistoryService;
import com.tykj.workflowcore.workflow_editer.service.VariableStorageService; import com.tykj.workflowcore.workflow_editer.service.VariableStorageService;
import io.swagger.annotations.Api;
import org.flowable.bpmn.model.*; import org.flowable.bpmn.model.*;
import liquibase.pro.packaged.I; import liquibase.pro.packaged.I;
import org.flowable.bpmn.model.EndEvent; import org.flowable.bpmn.model.EndEvent;
...@@ -26,11 +29,6 @@ import org.flowable.engine.delegate.event.AbstractFlowableEngineEventListener; ...@@ -26,11 +29,6 @@ import org.flowable.engine.delegate.event.AbstractFlowableEngineEventListener;
import org.flowable.engine.delegate.event.FlowableActivityEvent; import org.flowable.engine.delegate.event.FlowableActivityEvent;
import org.flowable.engine.delegate.event.impl.FlowableActivityEventImpl; 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.repository.ProcessDefinition;
import org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
...@@ -73,25 +71,6 @@ public class ProcessEndListener extends AbstractFlowableEngineEventListener { ...@@ -73,25 +71,6 @@ public class ProcessEndListener extends AbstractFlowableEngineEventListener {
@Override @Override
protected void processCompleted(FlowableEngineEntityEvent event) { 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));
// }
// }
// throw new ApiException("强行报错");
} }
@Override @Override
...@@ -111,55 +90,54 @@ public class ProcessEndListener extends AbstractFlowableEngineEventListener { ...@@ -111,55 +90,54 @@ public class ProcessEndListener extends AbstractFlowableEngineEventListener {
DelegateExecution execution = ((FlowableActivityEventImpl) event).getExecution(); DelegateExecution execution = ((FlowableActivityEventImpl) event).getExecution();
if (execution.getCurrentFlowElement() instanceof EndEvent){ if (execution.getCurrentFlowElement() instanceof EndEvent){
System.out.println("流程结束了"); System.out.println("流程结束了");
String processDefinitionId = ((ExecutionEntityImpl) execution).getProcessDefinitionKey(); //拿到流程定义ID
String flowKey = processDefinitionId; String processDefinitionId = execution.getProcessDefinitionId();
if (processDefinitionId.indexOf(":")>=0){ //通过定义Id取到flowKey
flowKey = processDefinitionId.substring(0,processDefinitionId.indexOf(":")); String flowKey = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).list().get(0).getKey();
}
List<VariableStorage> variableStorageList = variableStorageService.searchVariableStorageList(new SearchVariableStorageVo(flowKey,execution.getCurrentActivityId())); List<VariableStorage> variableStorageList = variableStorageService.searchVariableStorageList(new SearchVariableStorageVo(flowKey,execution.getCurrentActivityId()));
for (VariableStorage variableStorage : variableStorageList) { for (VariableStorage variableStorage : variableStorageList) {
List<ParameterVo> parameterVoList = variableStorage.getParameterInfo(); List<ParameterVo> parameterVoList = variableStorage.getParams();
InvokeRequest invokeRequest = new InvokeRequest(); InvokeRequest invokeRequest = new InvokeRequest();
invokeRequest.setClassName(variableStorage.getClassName()); invokeRequest.setClassName(variableStorage.getClassName());
invokeRequest.setName(variableStorage.getMethod()); invokeRequest.setName(variableStorage.getName());
invokeRequest.setParams(getApiInvokeParam(parameterVoList,execution)); invokeRequest.setParams(getApiInvokeParam(parameterVoList,execution));
//调用服务接口 //调用服务接口
apiController.invoke(invokeRequest); apiController.invoke(invokeRequest);
} }
} }
//开始节点 // //开始节点
if (execution.getCurrentFlowElement() instanceof StartEvent){ // if (execution.getCurrentFlowElement() instanceof StartEvent){
DataHistory dataHistory = new DataHistory(); // DataHistory dataHistory = new DataHistory();
StartEvent startEvent = (StartEvent) execution.getCurrentFlowElement(); // StartEvent startEvent = (StartEvent) execution.getCurrentFlowElement();
//流程id 实例id pageId datas userId // //流程id 实例id pageId datas userId
String processInstanceBusinessKey = execution.getProcessInstanceBusinessKey(); // String processInstanceBusinessKey = execution.getProcessInstanceBusinessKey();
dataHistory.setFlowKey(processInstanceBusinessKey); // dataHistory.setFlowKey(processInstanceBusinessKey);
dataHistory.setProcessInstanceId(execution.getProcessInstanceId()); // dataHistory.setProcessInstanceId(execution.getProcessInstanceId());
dataHistory.setPageId(startEvent.getFormKey()); // dataHistory.setPageId(startEvent.getFormKey());
// dataHistory.setUserId(); //// dataHistory.setUserId();
// dataHistory.setDatas(); //// dataHistory.setDatas();
System.out.println(processInstanceBusinessKey); // System.out.println(processInstanceBusinessKey);
//
String formKey = startEvent.getFormKey(); // String formKey = startEvent.getFormKey();
//通过formKey查询出页面 // //通过formKey查询出页面
//
} // }
if (execution.getCurrentFlowElement() instanceof UserTask){ // if (execution.getCurrentFlowElement() instanceof UserTask){
//查询任务 // //查询任务
Task task = taskService.createTaskQuery().singleResult(); // Task task = taskService.createTaskQuery().singleResult();
Map<String, Object> variables = taskService.getVariables(task.getId()); // Map<String, Object> variables = taskService.getVariables(task.getId());
DataHistory dataHistory = new DataHistory(); // DataHistory dataHistory = new DataHistory();
String datas = JSON.toJSONString(variables); // String datas = JSON.toJSONString(variables);
//流程实例id // //流程实例id
String processInstanceId = task.getProcessInstanceId(); // String processInstanceId = task.getProcessInstanceId();
//当前节点id // //当前节点id
String processInstanceBusinessKey = execution.getProcessInstanceBusinessKey(); // String processInstanceBusinessKey = execution.getProcessInstanceBusinessKey();
//
// dataHistory.setTaskId(taskId); //// dataHistory.setTaskId(taskId);
dataHistory.setDatas(datas); // dataHistory.setDatas(datas);
dataHistory.setProcessInstanceId(processInstanceId); // dataHistory.setProcessInstanceId(processInstanceId);
dataHistoryService.saveData(dataHistory); // dataHistoryService.saveData(dataHistory);
} // }
} }
} }
...@@ -178,23 +156,47 @@ public class ProcessEndListener extends AbstractFlowableEngineEventListener { ...@@ -178,23 +156,47 @@ public class ProcessEndListener extends AbstractFlowableEngineEventListener {
parameter.setClassName(parameterVo.getClassName()); parameter.setClassName(parameterVo.getClassName());
Map<String, Object> instance = new HashMap<>(); Map<String, Object> instance = new HashMap<>();
FillParameter(instance,parameterVoList.get(i),execution); FillParameter(instance,parameterVoList.get(i),execution);
parameter.setInstance((Map<String, Object>) instance.get(parameterVo.getName())); parameter.setInstance(instance.get(parameterVo.getName()));
parameterList.add(parameter); parameterList.add(parameter);
} }
return parameterList; return parameterList;
} }
public Map<String, Object> FillParameter(Map<String, Object> instance,ParameterVo parameterVo,DelegateExecution execution){ public Map<String, Object> FillParameter(Map<String, Object> instance,ParameterVo parameterVo,DelegateExecution execution) {
if (!StringUtils.isEmpty(parameterVo.getExp())) { if (!StringUtils.isEmpty(parameterVo.getExp())) {
//如果是表示式 如:${people} //如果是表示式 如:${people}
instance.put(parameterVo.getName(),getProcessValue(execution, parameterVo.getExp())); instance.put(parameterVo.getName(),getProcessValue(execution, parameterVo.getExp()));
}else { }else {
instance.put(parameterVo.getName(),""); if (instance.get(parameterVo.getName())==null){
//判断基础类型 为基础类型
Class<?> aClass = null;
try {
aClass = Class.forName(parameterVo.getClassName());
}catch (ClassNotFoundException e){
throw new ApiException("填充参数时类型转换失败,className:"+parameterVo.getClassName());
}
if (checkIn(parameterVo.getClassName())){
instance.put(parameterVo.getName(),null);
}else
if (Collection.class.isAssignableFrom(aClass)){
try {
instance.put(parameterVo.getName(),aClass.newInstance());
} catch (InstantiationException e) {
throw new ApiException("目标类型无法被实例化,className:"+parameterVo.getClassName());
} catch (IllegalAccessException e) {
throw new ApiException("无法访问目标类型,className:"+parameterVo.getClassName());
}
}else {
instance.put(parameterVo.getName(),new HashMap<>());
}
}
} }
List<ParameterVo> parameterVoList = parameterVo.getParams(); List<ParameterVo> parameterVoList = parameterVo.getFields();
if (parameterVoList!=null&&parameterVoList.size()>0){ if (parameterVoList!=null&&parameterVoList.size()>0){
for (int i = 0; i < parameterVoList.size() ; i++) { for (int i = 0; i < parameterVoList.size() ; i++) {
FillParameter(instance,parameterVoList.get(i),execution); if (instance.get(parameterVo.getName()) instanceof Map){
FillParameter((Map<String, Object>) instance.get(parameterVo.getName()),parameterVoList.get(i),execution);
}
} }
} }
return instance; return instance;
...@@ -206,4 +208,21 @@ public class ProcessEndListener extends AbstractFlowableEngineEventListener { ...@@ -206,4 +208,21 @@ public class ProcessEndListener extends AbstractFlowableEngineEventListener {
return expression.getValue(execution); return expression.getValue(execution);
} }
public Boolean checkIn(String className){
JavaTypeEnum[] values = JavaTypeEnum.values();
for (int i = 0; i < values.length ; i++) {
if (className.equals(values[i].getName())){
return true;
};
}
return false;
}
public static void main(String[] args) throws ClassNotFoundException {
Class<?> aClass = Class.forName(ArrayList.class.getName());
if (Collection.class.isAssignableFrom(aClass)){
System.out.println("1");
}
}
} }
...@@ -56,8 +56,8 @@ public class VariableStorageServiceImpl implements VariableStorageService { ...@@ -56,8 +56,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(StringUtils.isEmpty(searchVariableStorageVo.getFlowKey()),"flowKey",searchVariableStorageVo.getFlowKey()); predicateBuilder.eq(!StringUtils.isEmpty(searchVariableStorageVo.getFlowKey()),"flowKey",searchVariableStorageVo.getFlowKey());
predicateBuilder.eq(StringUtils.isEmpty(searchVariableStorageVo.getActivityId()),"activityId",searchVariableStorageVo.getActivityId()); 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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论