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

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

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