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

新增了 流程中调用Api的函数构建方法

上级 063c4de7
......@@ -18,6 +18,9 @@ public class Parameter {
@ApiModelProperty(value = "类名")
private String className;
@ApiModelProperty("流程表达式")
private String exp;
/**
* Map形式的实例对象
* key为字段名 value为字段值
......
......@@ -3,7 +3,9 @@ package com.tykj.workflowcore.workflow_editer.controller;
import com.tykj.workflowcore.base.result.ResultUtil;
import com.tykj.workflowcore.workflow_editer.entity.FlowsInfo;
import com.tykj.workflowcore.workflow_editer.entity.NodePage;
import com.tykj.workflowcore.workflow_editer.entity.VariableStorage;
import com.tykj.workflowcore.workflow_editer.entity.WorkFlowUser;
import com.tykj.workflowcore.workflow_editer.entity.vo.VariableStorageVo;
import com.tykj.workflowcore.workflow_editer.service.*;
import com.tykj.workflowcore.workflow_editer.vo.DeployedVo;
import com.tykj.workflowcore.workflow_editer.vo.FlowsInfoVo;
......@@ -80,13 +82,6 @@ public class FlowsInfoController {
return deployedVos;
}
// @PostMapping("/saveXml")
// @ApiOperation("保存xml")
// public String saveXml(@RequestParam("file") MultipartFile file){
// String xml = workFlowService.saveXml(file);
// return xml;
// }
@GetMapping("/deploy")
@ApiOperation(value = "部署流程",notes = "0 部署成功")
public Integer deploy(Long id) throws FileNotFoundException {
......@@ -128,6 +123,13 @@ public class FlowsInfoController {
return workFlowService.createFlow(flowsInfovo.toEntity());
}
@PostMapping("/saveVariableStorage")
@ApiModelProperty("保存函数调用配置")
public ResponseEntity saveVariableStorage(@RequestBody VariableStorageVo variableStorageVo){
VariableStorage variableStorage = variableStorageService.saveVariableStorageService(variableStorageVo.toEntity());
return ResultUtil.success(variableStorage,"保存成功");
}
@PostMapping("/test")
public WorkFlowUser test(){
return userService.getCurrentUser();
......
......@@ -4,7 +4,6 @@ import com.tykj.workflowcore.api.entity.InvokeRequest;
import com.tykj.workflowcore.workflow_editer.entity.FlowsInfo;
import com.tykj.workflowcore.workflow_editer.service.FlowInfoService;
import com.tykj.workflowcore.workflow_editer.service.WorkFlowService;
import com.tykj.workflowcore.workflow_editer.util.PageUtil;
import com.tykj.workflowcore.workflow_editer.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
......@@ -76,12 +75,6 @@ public class WorkFlowController {
workFlowService.completeTask(taskVo);
}
@PostMapping("/getVariable")
@ApiOperation("获取变量池")
public void getVariable(){
// workFlowService.setVariables()
}
@PostMapping("/isTransferTask")
@ApiOperation("是否转交任务")
public void isTransferTask(@RequestBody TransferTask transferTask){
......@@ -110,9 +103,4 @@ public class WorkFlowController {
workFlowService.flowProgress(flowProcessVo.getResponse(),flowProcessVo.getProcessInstanceId());
}
@PostMapping("getInvokeRequest")
@ApiOperation("调用服务接口")
public InvokeRequest getInvokeRequest(@RequestBody InvokeRequestVo invokeRequestVo) throws IOException {
return workFlowService.saveInvokeRequest(invokeRequestVo);
}
}
package com.tykj.workflowcore.workflow_editer.entity;
import org.flowable.common.engine.api.delegate.Expression;
import org.flowable.common.engine.impl.interceptor.Command;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
import org.flowable.engine.impl.persistence.entity.ExecutionEntityManager;
import org.flowable.engine.impl.util.CommandContextUtil;
/**
* @author HuangXiahao
* @version V1.0
* @class Test
* @packageName com.example.flowable.expense.controller
**/
public class CommandGetValue implements Command<Object> {
private String processInstanceId;
private Expression expression;
public CommandGetValue(String processInstanceId, Expression expression) {
this.processInstanceId = processInstanceId;
this.expression = expression;
}
@Override
public Object execute(CommandContext commandContext) {
ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager();
ExecutionEntity executionEntity = executionEntityManager.findChildExecutionsByProcessInstanceId(processInstanceId).get(0);
return expression.getValue(executionEntity);
}
}
......@@ -34,8 +34,13 @@ public class VariableStorage {
@ApiModelProperty("流程主键")
private String flowKey;
@ApiModelProperty("变量池")
private String variable;
@ApiModelProperty("调用类名")
private String className;
@ApiModelProperty("调用方法")
private String method;
@ApiModelProperty("详情json")
private String variableInfo;
}
package com.tykj.workflowcore.workflow_editer.entity;
package com.tykj.workflowcore.workflow_editer.entity.vo;
import com.tykj.workflowcore.model_layer.annotatiion.WorkFlowCoreNoScan;
import lombok.AllArgsConstructor;
......
package com.tykj.workflowcore.workflow_editer.entity.vo;
import com.tykj.workflowcore.workflow_editer.entity.VariableStorage;
import com.tykj.workflowcore.workflow_editer.vo.OutFormPageVo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
/**
* @author HuangXiahao
* @version V1.0
* @class VariableStorageVo
* @packageName com.tykj.workflowcore.workflow_editer.entity.vo
**/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class VariableStorageVo {
private Long id;
private String flowKey;
private String className;
private String method;
private String variableInfo;
public VariableStorage toEntity(){
VariableStorage variableStorage = new VariableStorage();
BeanUtils.copyProperties(this,variableStorage);
return variableStorage;
}
}
......@@ -4,6 +4,8 @@ import com.tykj.workflowcore.workflow_editer.entity.VariableStorage;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.util.List;
/**
* ClassName: VariableStorageMapper
* Package: com.tykj.mapper
......@@ -19,5 +21,5 @@ public interface VariableStorageMapper extends JpaRepository<VariableStorage,Lon
* @param flowKey 流程主键
* @return
*/
VariableStorage findByFlowKey(String flowKey);
List<VariableStorage> findAllByFlowKey(String flowKey);
}
......@@ -32,6 +32,8 @@ public interface UserService {
* 获取当前系统中的用户以及用户分组
* @return
*/
List<WorkFlowRole> getAllRole();
List<WorkFlowRole> getAllRole(String roleType);
List<String> getRoleType();
}
......@@ -3,6 +3,8 @@ package com.tykj.workflowcore.workflow_editer.service;
import com.tykj.workflowcore.workflow_editer.entity.VariableStorage;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
/**
* ClassName: VariableStorageService
* Package: com.tykj.service
......@@ -17,12 +19,12 @@ public interface VariableStorageService {
* 保存变量池
* @param variableStorage 变量池
*/
void saveVariableStorageService(@RequestBody VariableStorage variableStorage);
VariableStorage saveVariableStorageService(@RequestBody VariableStorage variableStorage);
/**
* 查询变量池
* @param flowKey 流程主键
* @return VariableStorage 变量池
*/
VariableStorage findByFlowKey(String flowKey);
List<VariableStorage> findByFlowKey(String flowKey);
}
......@@ -125,11 +125,6 @@ public interface WorkFlowService {
*/
void flowProgress (HttpServletResponse httpServletResponse, String processId) throws IOException;
/**
* 调用服务接口vo
* @param invokeRequestVo 调用服务接口vo
* @return 调用服务接口实体
*/
InvokeRequest saveInvokeRequest(InvokeRequestVo invokeRequestVo);
}
......@@ -7,6 +7,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
/**
* ClassName: VariableStorageServiceImpl
* Package: com.tykj.service.impl
......@@ -21,13 +23,15 @@ public class VariableStorageServiceImpl implements VariableStorageService {
private VariableStorageMapper variableStorageMapper;
@Override
public void saveVariableStorageService(@RequestBody VariableStorage variableStorage) {
variableStorageMapper.save(variableStorage);
public VariableStorage saveVariableStorageService(@RequestBody VariableStorage variableStorage) {
return variableStorageMapper.save(variableStorage);
}
@Override
public VariableStorage findByFlowKey(String flowKey) {
VariableStorage variableStorage = variableStorageMapper.findByFlowKey(flowKey);
return variableStorage;
public List<VariableStorage> findByFlowKey(String flowKey) {
List<VariableStorage> allByFlowKey = variableStorageMapper.findAllByFlowKey(flowKey);
return allByFlowKey;
}
}
package com.tykj.workflowcore.workflow_editer.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.tykj.workflowcore.api.entity.InvokeRequest;
import com.tykj.workflowcore.api.entity.Parameter;
import com.tykj.workflowcore.workflow_editer.entity.CommandGetValue;
import com.tykj.workflowcore.workflow_editer.entity.FlowsInfo;
import com.tykj.workflowcore.workflow_editer.entity.VariablesMap;
import com.tykj.workflowcore.workflow_editer.entity.WorkFlowUser;
......@@ -30,6 +33,7 @@ import org.flowable.task.api.history.HistoricTaskInstance;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
......@@ -292,7 +296,9 @@ public class WorkFlowServiceImpl implements WorkFlowService {
}
if (taskVo.getTaskId() == null){
//流程结束了
//保存调用接口
}
}
......@@ -371,42 +377,42 @@ public class WorkFlowServiceImpl implements WorkFlowService {
}
@Override
public InvokeRequest saveInvokeRequest(InvokeRequestVo invokeRequestVo) {
//取出变量池的值
Expression expression = processEngineConfiguration.getExpressionManager().createExpression(invokeRequestVo.getExp());
ManagementService managementService = processEngine.getManagementService();
VariablesMap variablesMap = new VariablesMap(invokeRequestVo.getProcessInstanceId(),expression);
Object o = managementService.executeCommand(variablesMap);
Map<String, Object> map = new HashMap<>();
if (o instanceof Map){
//如果是对象
map = (Map<String, Object>) o;
/**
* 获取调用Api用的参数
* @param invokeRequestVo 调用服务接口vo
* @return 调用服务接口实体
*/
public InvokeRequest getApiInvokeParam(InvokeRequestVo invokeRequestVo) {
//拿出taskId
String processInstanceId = invokeRequestVo.getProcessInstanceId();
List<Parameter> parameterList = invokeRequestVo.getParameterList();
List<Parameter> newParameterList = new ArrayList<>();
for (int i = 0; i < parameterList.size(); i++) {
Parameter parameter = parameterList.get(i);
if (!StringUtils.isEmpty(parameter.getExp())){
parameter.setInstance((Map<String, Object>) getProcessValue(processInstanceId,parameter.getExp()));
}else {
//如果是字段
map.put("o",o);
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(processInstanceId, (String) instance.get(key)));
}
parameter.setInstance(newInstance);
}
newParameterList.add(i,parameter);
}
invokeRequestVo.setParameterList(newParameterList);
return JSONObject.parseObject(JSONObject.toJSONString(invokeRequestVo),InvokeRequest.class) ;
}
//构建InvokeRequest
InvokeRequest invokeRequest = new InvokeRequest();
// invokeRequest.setClassName("com.tykj.www");
// invokeRequest.setName("add");
invokeRequest.setClassName(invokeRequestVo.getClassName());
invokeRequest.setName(invokeRequestVo.getName());
// Parameter parameter = new Parameter();
// parameter.setClassName("expense");
List<Parameter> parameterList = invokeRequestVo.getParameterList();
Parameter parameter = new Parameter();
parameter.setInstance(map);
parameterList.add(parameter);
invokeRequest.setParams(parameterList);
return invokeRequest;
public Object getProcessValue(String processInstanceId, String exp) {
Expression expression = processEngineConfiguration.getExpressionManager().createExpression(exp);
ManagementService managementService = processEngine.getManagementService();
CommandGetValue test = new CommandGetValue(processInstanceId,expression);
Object o = managementService.executeCommand(test);
return o ;
}
@Override
......
......@@ -23,10 +23,11 @@ import java.util.List;
@Data
@Api(tags = "调用服务接口vo")
public class InvokeRequestVo {
@ApiModelProperty("流程实例id")
private String processInstanceId;
@ApiModelProperty("流程表达式")
private String exp;
@ApiModelProperty("类名")
private String className;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论