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

[工作流模块] 优化了一些代码结构

上级 3746b342
# 工作流项目核心
## 项目简介
1. 通过可视化的方式进行流程的定制
2. 提供流程相关页面的定制
3. 提供流程相关 的接口
### 环境要求
- Maven3+
......@@ -56,7 +60,8 @@
│ └─frame --核心逻辑所在位置
```
## 使用方式
### 安装
### 后端安装
#### maven
```
<dependency>
......@@ -69,7 +74,7 @@
1. 获取 workflow-core-0.0.1-SNAPSHOT.jar
2. 在你自己项目的根目录下创建lib文件夹 并将 jar 包放入
3. pom 添加 如下
```
<dependency>
<groupId>com.tykj</groupId>
......@@ -79,7 +84,11 @@
<systemPath>${basedir}/lib/workflow-core-0.0.1-SNAPSHOT.jar</systemPath>
</dependency>
```
### 调用
### 前端安装
```
npm install workflow-form
```
### 配置
1. 在springboot 启动类上添加注解 @EnableWorkFlowCore
```
@EnableWorkFlowCore
......@@ -92,8 +101,52 @@ public class DemoApplication {
}
```
2. 如需要使用工作流的审批人功能请实现 UserService
例如:
### 使用
1. 工作流部分
1. 建立数据模型
```
在项目启动时 工作流核心 会对带有 @Entity 注解的实体进行扫描 扫描的实体会被记录到
```
如果需要建立一个流程需要先为该流程建立 数据模型,就像是平时开发过程中的建表操作
例如:新建一个新增用户的流程,需要先新建一个用户对象
![image-20210315130344008](images\image-20210315130344008.png)
2. 建立流程
根据业务自行建立流程图
![image-20210315131641756](images\image-20210315131641756.png)
3. 为节点配置页面
![image-20210315131723560](images\image-20210315131723560.png)
![image-20210315132632917](images\image-20210315132632917.png)
4. 配置节点的执行人
```
如下图所示,配置了节点的执行为 为 hxh_admin
```
![image-20210316100902054](C:\Users\admin\AppData\Roaming\Typora\typora-user-images\image-20210316100902054.png)
如需要使用工作流的执行人功能请实现 UserService
例如:
```
@Service
@Primary
......@@ -145,5 +198,106 @@ public class FlowUserServiceImpl implements UserService {
}
```
5. 配置流程结束后的回调函数
```
回调函数 需要提前写好
例如: 新增人员流程 需要 提前写好 新增人员的接口
当流程结束后 工作流引擎会自动对接口进行调用
```
![image-20210316104207047](C:\Users\admin\AppData\Roaming\Typora\typora-user-images\image-20210316104207047.png)
2. 宿主系统部分
1. 查询可发起流程
```
接口返回值示例
{
"message": "查询成功",
"data": {
"content": [
{
"id": 2,
"createdTime": "2021-03-15T03:00:48.028+00:00",
"updatedTime": "2021-03-15T03:10:33.009+00:00",
"deleted": 0,
"userId": null,
"userName": null,
"flowName": "测试1",
"resourceName": "processId_2850e08d-0e3d-4925-93f6-adce8a9e2246bpmn20.xml",
"flowKey": "processId_2850e08d-0e3d-4925-93f6-adce8a9e2246",
//前端组件需要使用该数据
"state": 0,
"filePath": "\\xml\\processId_2850e08d-0e3d-4925-93f6-adce8a9e2246bpmn20.xml",
"flowDescribe": "测试2",
"startId": null,
"startPageId": 1, //前端组件需要使用该数据
"processInstanceId": null,
"deployId": "a4c408b0-853a-11eb-81c9-d2c637ad090d"
},
{
"id": 3,
"createdTime": "2021-03-15T03:17:30.914+00:00",
"updatedTime": "2021-03-15T03:17:31.850+00:00",
"deleted": 0,
"userId": null,
"userName": null,
"flowName": "测试流程1",
"resourceName": "processId_560c6b5c-8be5-40b8-852f-8e174346e9c8bpmn20.xml",
"flowKey": "processId_560c6b5c-8be5-40b8-852f-8e174346e9c8",
"state": 0,
"filePath": "\\xml\\processId_560c6b5c-8be5-40b8-852f-8e174346e9c8bpmn20.xml",
"flowDescribe": "测试流程描述1",
"startId": null,
"startPageId": null,
"processInstanceId": null,
"deployId": "fa83de4c-853c-11eb-81c9-d2c637ad090d"
}
],
"pageable": {
"sort": {
"sorted": false,
"unsorted": true,
"empty": true
},
"offset": 0,
"pageSize": 15,
"pageNumber": 0,
"paged": true,
"unpaged": false
},
"totalElements": 2,
"last": true,
"totalPages": 1,
"number": 0,
"size": 15,
"sort": {
"sorted": false,
"unsorted": true,
"empty": true
},
"numberOfElements": 2,
"first": true,
"empty": false
}
}
```
2. 渲染页面
```
fromUtil.creatFrom(pageId,flowKey)
```
(渲染出来的表单页面中的逻辑由工作流控制,用户完成表单所有操作后页面会自动关闭)
3. 模拟效果
![image-20210315132852126](images\image-20210315132852126.png)
![image-20210315132859363](images\image-20210315132859363.png)
package com.tykj.workflowcore.base.util;
import java.io.*;
/**
* @author HuangXiahao
* @version V1.0
* @class FileUtil
* @packageName com.tykj.workflowcore.base.util
**/
public class FileUtil {
public static File createFileByString(String filePath,String fileString){
File f = null;
try {
f = new File(filePath);
// 判断文件是否存在
if(!f.exists()){
f.createNewFile();
}
} catch (Exception e) {
e.printStackTrace();
}
BufferedReader bufferedReader = null;
BufferedWriter bufferedWriter = null;
try {
bufferedReader = new BufferedReader(new StringReader(fileString));
bufferedWriter = new BufferedWriter(new FileWriter(f));
//字符缓冲区
char buf[] = new char[1024];
int len;
while ((len = bufferedReader.read(buf)) != -1) {
bufferedWriter.write(buf, 0, len);
}
bufferedWriter.flush();
bufferedReader.close();
bufferedWriter.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return f;
}
}
......@@ -20,4 +20,6 @@ public class SearchTableInfoVo extends JpaCustomPage {
private String tableName;
private String tableCnName;
private Integer modelType;
}
......@@ -82,6 +82,7 @@ public class ModelImpl implements ModelService {
PredicateBuilder<TableInfo> and = Specifications.and();
and.like(searchTableInfoVo.getTableName() != null, "name", "%" + searchTableInfoVo.getTableName() + "%");
and.like(searchTableInfoVo.getTableCnName() != null, "cnName", "%" + searchTableInfoVo.getTableCnName() + "%");
and.eq(searchTableInfoVo.getModelType()!=null,"modelType",searchTableInfoVo.getModelType());
return tableInfoDao.findAll(and.build(), searchTableInfoVo.getPageable());
}
......
......@@ -4,6 +4,7 @@ import com.tykj.workflowcore.base.result.ResultUtil;
import com.tykj.workflowcore.workflow_editer.entity.FlowsInfo;
import com.tykj.workflowcore.workflow_editer.entity.VariableStorage;
import com.tykj.workflowcore.workflow_editer.entity.vo.SearchFlowInfoVo;
import com.tykj.workflowcore.workflow_editer.entity.vo.SearchVariableStorageVo;
import com.tykj.workflowcore.workflow_editer.entity.vo.VariableStorageVo;
import com.tykj.workflowcore.workflow_editer.service.*;
import com.tykj.workflowcore.workflow_editer.entity.vo.FlowsInfoVo;
......@@ -92,7 +93,13 @@ public class FlowsInfoController {
@ApiModelProperty("保存函数调用配置")
public ResponseEntity saveVariableStorage(@RequestBody VariableStorageVo variableStorageVo){
VariableStorage variableStorage = variableStorageService.saveVariableStorageService(variableStorageVo.toEntity());
return ResultUtil.success(variableStorage,"调用接口成功");
return ResultUtil.success(variableStorage,"保存接口调用配置成功");
}
@PostMapping("/searchVariableStorage")
@ApiModelProperty("查找函数调用配置")
public ResponseEntity searchVariableStorage(@RequestBody SearchVariableStorageVo searchVariableStorageVo){
return ResultUtil.success( variableStorageService.searchVariableStoragePage(searchVariableStorageVo),"查询接口调用配置成功");
}
}
......@@ -42,7 +42,6 @@ public class WorkFlowController {
@ApiOperation("任务个人待办列表")
public List<Map<String,Object>> findUserTask(@RequestBody NextTaskVo nextTaskVo){
return workFlowService.findTaskByUserId(nextTaskVo);
}
@PostMapping("/findTaskDetail")
......@@ -91,4 +90,6 @@ public class WorkFlowController {
return workFlowService.findHistoryTask(userId);
}
}
......@@ -51,6 +51,9 @@ public class FlowsInfo extends BaseEntity {
@ApiModelProperty("文件路径")
private String filePath;
@ApiModelProperty("自定义格式XML路径")
private String fileCustomPath;
@ApiModelProperty("流程描述")
private String flowDescribe;
......
......@@ -34,7 +34,6 @@ import java.util.Date;
public class FormPage extends BaseEntity {
@ApiModelProperty("页面名称")
private String pageName;
......
package com.tykj.workflowcore.workflow_editer.entity;
import com.alibaba.fastjson.JSON;
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.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
......@@ -17,11 +20,11 @@ import javax.persistence.Entity;
*
* @Author: zsp
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@WorkFlowCoreNoScan
@Data
public class VariableStorage extends BaseEntity {
......@@ -36,6 +39,11 @@ public class VariableStorage extends BaseEntity {
private String method;
@ApiModelProperty("详情json")
private String variableInfo;
private String invokeRequest;
@JsonGetter
public InvokeRequestVo getInvokeRequest() {
return JSON.parseObject(invokeRequest,InvokeRequestVo.class);
}
}
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 lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;
import springfox.documentation.spring.web.json.Json;
/**
* @author HuangXiahao
......@@ -25,11 +28,12 @@ public class VariableStorageVo {
private String method;
private String variableInfo;
private InvokeRequestVo invokeRequest;
public VariableStorage toEntity(){
VariableStorage variableStorage = new VariableStorage();
BeanUtils.copyProperties(this,variableStorage);
variableStorage.setInvokeRequest(JSON.toJSONString(invokeRequest));
return variableStorage;
}
}
package com.tykj.workflowcore.workflow_editer.service;
import com.tykj.workflowcore.workflow_editer.entity.VariableStorage;
import com.tykj.workflowcore.workflow_editer.entity.vo.SearchVariableStorageVo;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
......@@ -16,15 +18,22 @@ import java.util.List;
public interface VariableStorageService {
/**
* 保存变量池
* 保存接口调用配置
* @param variableStorage 变量池
*/
VariableStorage saveVariableStorageService(@RequestBody VariableStorage variableStorage);
/**
* 查询变量池
* @param flowKey 流程主键
* 根据流程主键查询
* @param searchVariableStorageVo 流程主键
* @return VariableStorage 变量池
*/
List<VariableStorage> findByFlowKey(String flowKey);
List<VariableStorage> searchVariableStorageList(SearchVariableStorageVo searchVariableStorageVo);
/**
* 多条件查询接口配置
* @param searchVariableStorageVo
* @return
*/
Page<VariableStorage> searchVariableStoragePage(SearchVariableStorageVo searchVariableStorageVo);
}
package com.tykj.workflowcore.workflow_editer.service.impl;
import com.github.wenhao.jpa.PredicateBuilder;
import com.github.wenhao.jpa.Specifications;
import com.tykj.workflowcore.workflow_editer.entity.VariableStorage;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -28,10 +33,25 @@ public class VariableStorageServiceImpl implements VariableStorageService {
}
@Override
public List<VariableStorage> findByFlowKey(String flowKey) {
List<VariableStorage> allByFlowKey = variableStorageMapper.findAllByFlowKey(flowKey);
return allByFlowKey;
public List<VariableStorage> searchVariableStorageList(SearchVariableStorageVo searchVariableStorageVo) {
PredicateBuilder predicateBuilder = Specifications.and();
if (searchVariableStorageVo!=null){
predicateBuilder.eq(searchVariableStorageVo.getId()!=null,"id",searchVariableStorageVo.getId());
predicateBuilder.eq(searchVariableStorageVo.getFlowKey()!=null,"flowKey",searchVariableStorageVo.getFlowKey());
}
return variableStorageMapper.findAll(predicateBuilder.build());
}
@Override
public Page<VariableStorage> searchVariableStoragePage(SearchVariableStorageVo searchVariableStorageVo) {
PredicateBuilder predicateBuilder = Specifications.and();
if (searchVariableStorageVo!=null){
predicateBuilder.eq(searchVariableStorageVo.getId()!=null,"id",searchVariableStorageVo.getId());
predicateBuilder.eq(searchVariableStorageVo.getFlowKey()!=null,"flowKey",searchVariableStorageVo.getFlowKey());
}
return variableStorageMapper.findAll(predicateBuilder.build(),searchVariableStorageVo.getPageable());
}
}
......@@ -5,9 +5,11 @@ import com.tykj.workflowcore.api.entity.InvokeRequest;
import com.tykj.workflowcore.api.entity.Parameter;
import com.tykj.workflowcore.api.service.SpringBeanService;
import com.tykj.workflowcore.base.result.ApiException;
import com.tykj.workflowcore.base.util.FileUtil;
import com.tykj.workflowcore.workflow_editer.entity.*;
import com.tykj.workflowcore.workflow_editer.dao.FlowsInfoMapper;
import com.tykj.workflowcore.workflow_editer.entity.vo.*;
import com.tykj.workflowcore.workflow_editer.service.NodeInfoService;
import com.tykj.workflowcore.workflow_editer.service.UserService;
import com.tykj.workflowcore.workflow_editer.service.VariableStorageService;
import com.tykj.workflowcore.workflow_editer.service.WorkFlowService;
......@@ -17,11 +19,12 @@ import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.bpmn.model.*;
import org.flowable.common.engine.api.delegate.Expression;
import org.flowable.common.engine.impl.identity.Authentication;
import org.flowable.engine.*;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.runtime.Execution;
import org.flowable.engine.runtime.ProcessInstance;
......@@ -30,6 +33,7 @@ import org.flowable.task.api.Task;
import org.flowable.task.api.TaskQuery;
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;
......@@ -39,6 +43,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.*;
import java.util.regex.Pattern;
/**
* ClassName: FlowableServiceImpl
......@@ -65,7 +70,10 @@ public class WorkFlowServiceImpl implements WorkFlowService {
final
ClassLoader classLoader;
public WorkFlowServiceImpl(SpringBeanService springBeanService,HistoryService historyService, RepositoryService repositoryService, RuntimeService runtimeService, TaskService taskService, FlowsInfoMapper flowsInfoMapper, ProcessEngineConfigurationImpl processEngineConfiguration, ProcessEngine processEngine, VariableStorageService variableStorageService, ClassLoader classLoader) {
@Autowired
NodeInfoService nodeInfoService;
public WorkFlowServiceImpl(SpringBeanService springBeanService, HistoryService historyService, RepositoryService repositoryService, RuntimeService runtimeService, TaskService taskService, FlowsInfoMapper flowsInfoMapper, ProcessEngineConfigurationImpl processEngineConfiguration, ProcessEngine processEngine, VariableStorageService variableStorageService, ClassLoader classLoader) {
this.historyService = historyService;
this.repositoryService = repositoryService;
this.runtimeService = runtimeService;
......@@ -76,7 +84,7 @@ public class WorkFlowServiceImpl implements WorkFlowService {
this.processEngine = processEngine;
this.variableStorageService = variableStorageService;
this.classLoader = classLoader;
System.out.println(userService!=null?"成功":"失败");
System.out.println(userService != null ? "成功" : "失败");
}
@Override
......@@ -94,7 +102,7 @@ public class WorkFlowServiceImpl implements WorkFlowService {
System.out.println(fileName);
//指定本地存入路径
File fileNew = new File(classLoader.getResource("").getPath() + fileName);
realPath = classLoader.getResource("").getPath()+fileName;
realPath = classLoader.getResource("").getPath() + fileName;
try {
file.transferTo(fileNew);
} catch (IOException e) {
......@@ -120,13 +128,13 @@ public class WorkFlowServiceImpl implements WorkFlowService {
List<Attribute> attributes = stu.attributes();
System.out.println("======获取属性值======");
for (Attribute attribute : attributes) {
if ("id".equals(attribute.getName())){
if ("id".equals(attribute.getName())) {
processId = attribute.getValue();
System.out.println("processId的值是:"+processId);
System.out.println("processId的值是:" + processId);
}
if ("name".equals(attribute.getName())){
if ("name".equals(attribute.getName())) {
processName = attribute.getValue();
System.out.println("processName的值是:"+processName);
System.out.println("processName的值是:" + processName);
}
}
//保存processId和processName 到数据库里面
......@@ -144,53 +152,20 @@ public class WorkFlowServiceImpl implements WorkFlowService {
@Override
public void flowXml(@RequestBody FlowsInfoVo flowsInfoVo) {
String basePath = System.getProperty("user.dir") + "\\xml\\";
Integer id = flowsInfoVo.getId();
String flowKey = flowsInfoVo.getFlowKey();
String fileXml = flowsInfoVo.getFileXml();
//生成xml文件
File f = null;
try {
f = new File(System.getProperty("user.dir")+"\\xml\\"+flowKey+"bpmn20.xml");
// 判断文件是否存在
if(!f.exists()){
f.createNewFile();
}
System.out.println("生成"+flowKey+".xml成功");
} catch (Exception e) {
e.printStackTrace();
System.out.println("生成"+flowKey+".xml失败");
}
BufferedReader bufferedReader = null;
BufferedWriter bufferedWriter = null;
try {
bufferedReader = new BufferedReader(new StringReader(fileXml));
bufferedWriter = new BufferedWriter(new FileWriter(f));
//字符缓冲区
char buf[] = new char[1024];
int len;
while ((len = bufferedReader.read(buf)) != -1) {
bufferedWriter.write(buf, 0, len);
}
bufferedWriter.flush();
bufferedReader.close();
bufferedWriter.close();
} catch (IOException e) {
e.printStackTrace();
FileUtil.createFileByString(basePath + flowKey + "bpmn20.xml", flowsInfoVo.getFileXml().replaceAll("\\[\\?\\?[^\\]]+\\?\\?\\]", ""));
FileUtil.createFileByString(basePath + flowKey + "bpmnCustom20.xml", flowsInfoVo.getFileXml());
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
FlowsInfo flowsInfo = new FlowsInfo();
BeanUtils.copyProperties(flowsInfoVo,flowsInfo);
flowsInfo.setResourceName(flowKey+"bpmn20.xml");
flowsInfo.setFilePath("\\xml\\"+flowKey+"bpmn20.xml");
BeanUtils.copyProperties(flowsInfoVo, flowsInfo);
flowsInfo.setResourceName(flowKey + "bpmn20.xml");
flowsInfo.setFilePath("\\xml\\" + flowKey + "bpmn20.xml");
flowsInfo.setFileCustomPath("\\xml\\" + flowKey + "bpmnCustom20.xml");
flowsInfo.setId(id);
//更新并保存
FlowsInfo save = flowsInfoMapper.save(flowsInfo);
......@@ -198,8 +173,9 @@ public class WorkFlowServiceImpl implements WorkFlowService {
deployXml(save);
}
@Override
public Integer createFlow(FlowsInfo flowsInfo ) {
public Integer createFlow(FlowsInfo flowsInfo) {
FlowsInfo flowsInfo1 = flowsInfoMapper.save(flowsInfo);
return flowsInfo1.getId();
}
......@@ -209,8 +185,8 @@ public class WorkFlowServiceImpl implements WorkFlowService {
public void deployXml(FlowsInfo flowsInfo) {
Deployment deploy = null;
try {
deploy = repositoryService.createDeployment().addInputStream(System.getProperty("user.dir")+flowsInfo.getResourceName(),
new FileInputStream(System.getProperty("user.dir") +flowsInfo.getFilePath())).deploy();
deploy = repositoryService.createDeployment().addInputStream(System.getProperty("user.dir") + flowsInfo.getResourceName(),
new FileInputStream(System.getProperty("user.dir") + flowsInfo.getFilePath())).deploy();
} catch (FileNotFoundException e) {
e.printStackTrace();
......@@ -228,7 +204,7 @@ public class WorkFlowServiceImpl implements WorkFlowService {
//设置流程发起人
WorkFlowUser currentUser = userService.getCurrentUser();
Authentication.setAuthenticatedUserId(currentUser.getId()+"");
Authentication.setAuthenticatedUserId(currentUser.getId() + "");
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(startFlowVo.getFlowKey(),
startFlowVo.getMap());
......@@ -241,26 +217,36 @@ public class WorkFlowServiceImpl implements WorkFlowService {
@Override
public List<Map<String,Object>> findTaskByUserId(NextTaskVo nextTaskVo) {
public List<Map<String, Object>> findTaskByUserId(NextTaskVo nextTaskVo) {
List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
TaskQuery taskQuery = taskService.createTaskQuery().or();
if (nextTaskVo.getUserId()!=null){
taskQuery.taskCandidateUser(nextTaskVo.getUserId()).orderByTaskCreateTime().desc();
}
if (nextTaskVo.getRoleId()!=null&&nextTaskVo.getRoleId().size()>0){
taskQuery.taskCandidateGroupIn(nextTaskVo.getRoleId()).orderByTaskCreateTime().desc();
TaskQuery taskQuery = taskService.createTaskQuery();
if (nextTaskVo.getRoleId() != null || nextTaskVo.getUserId() != null) {
taskQuery.or();
if (nextTaskVo.getUserId() != null) {
taskQuery.taskCandidateUser(nextTaskVo.getUserId()).orderByTaskCreateTime().desc();
}
if (nextTaskVo.getRoleId() != null && nextTaskVo.getRoleId().size() > 0) {
taskQuery.taskCandidateGroupIn(nextTaskVo.getRoleId()).orderByTaskCreateTime().desc();
}
taskQuery.endOr();
}
List<Task> listTask = taskQuery.endOr().listPage(1,5);
List<Task> listTask = taskQuery.list();
for (Task task : listTask) {
Map<String, Object> map = new HashMap<>();
ProcessInstance processInstance =
runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult();
map.put("taskName",task.getName());
map.put("taskDesc",task.getDescription());
map.put("createTime",task.getCreateTime());
map.put("promoter",processInstance.getStartUserId());
map.put("processInstanceId",processInstance.getId());
//节点id
String taskDefinitionKey = task.getTaskDefinitionKey();
//通过节点id查询出pageId
Integer currentPageId = nodeInfoService.findByNodeId(taskDefinitionKey);
map.put("taskId", task.getId());
map.put("processKey", processInstance.getProcessDefinitionKey());
map.put("taskName", task.getName());
map.put("taskDesc", task.getDescription());
map.put("createTime", task.getCreateTime());
map.put("promoter", processInstance.getStartUserId());
map.put("processInstanceId", processInstance.getId());
map.put("currentPageId", currentPageId);
listMap.add(map);
}
return listMap;
......@@ -271,14 +257,14 @@ public class WorkFlowServiceImpl implements WorkFlowService {
public Map<String, Object> findTaskDetail(String taskId) {
Map<String, Object> variables = new HashMap<>();
//流程还在运行
if (taskId != null){
if (taskId != null) {
variables = taskService.getVariables(taskId);
}else {
} else {
//流程已经结束
//从历史中查询
HistoricTaskInstance historicTaskInstance =
historyService.createHistoricTaskInstanceQuery().taskId(taskId).finished().singleResult();
variables.put("historicTaskInstance",historicTaskInstance);
variables.put("historicTaskInstance", historicTaskInstance);
}
return variables;
}
......@@ -287,47 +273,64 @@ public class WorkFlowServiceImpl implements WorkFlowService {
public void completeTask(@RequestBody TaskVo taskVo) {
Map<String, Object> map = new HashMap<>();
setVariables(taskVo.getMap());
if (taskVo.getMap() != null) {
setVariables(taskVo.getMap());
}
Task task = taskService.createTaskQuery().taskId(taskVo.getTaskId()).singleResult();
String processInstanceId = task.getProcessInstanceId();
taskService.addComment(task.getId(),processInstanceId,taskVo.getComments());
//如果 存在任务评论的话 向任务中添加任务评论
if (taskVo.getComments() != null) {
taskService.addComment(task.getId(), processInstanceId, taskVo.getComments());
}
//先判断是不是表达式
if (taskVo.getConditionalExpression()!= null){
claimTask(task.getId(),userService.getCurrentUser().getId());
if (taskVo.getConditionalExpression() != null) {
claimTask(task.getId(), userService.getCurrentUser().getId());
taskService.complete(task.getId());
}else {
map.put("handlingOpinion",taskVo.getHandlingOpinion());
claimTask(task.getId(),userService.getCurrentUser().getId());
taskService.complete(task.getId(),map);
}
if (taskVo.getTaskId() == null){
//流程结束了
//通过processInstanceId查询出flowKey
FlowsInfo flowsInfo = flowsInfoMapper.findByProcessInstanceId(processInstanceId);
List<VariableStorage> variableStorageList = variableStorageService.findByFlowKey(flowsInfo.getFlowKey());
for (VariableStorage variableStorage : variableStorageList) {
String variableInfo = variableStorage.getVariableInfo();
//调用服务接口
InvokeRequestVo invokeRequestVo = (InvokeRequestVo) JSONObject.parse(variableInfo);
getApiInvokeParam(invokeRequestVo);
}
} else {
map.put("handlingOpinion", taskVo.getHandlingOpinion());
claimTask(task.getId(), userService.getCurrentUser().getId());
taskService.complete(task.getId(), map);
}
//查询是否为最后一个节点
// ExecutionEntity ee = (ExecutionEntity) processEngine.getRuntimeService().createExecutionQuery()
// .executionId(task.getExecutionId()).singleResult();
// BpmnModel bpmnModel = processEngine.getRepositoryService().getBpmnModel(task.getProcessDefinitionId());
// FlowNode flowNode = (FlowNode) bpmnModel.getFlowElement(ee.getActivityId());
// List<SequenceFlow> outFlows = flowNode.getOutgoingFlows();
// for (SequenceFlow sequenceFlow : outFlows) {
// FlowElement targetFlow = sequenceFlow.getTargetFlowElement();
// // 如果下个审批节点为结束节点
// if (targetFlow instanceof EndEvent) {
// System.out.println("下一节点为结束节点:id=" + targetFlow.getId() + ",name=" + targetFlow.getName());
// }
// }
// if (taskVo.getTaskId() == null){
// //流程结束了
// //通过processInstanceId查询出flowKey
// FlowsInfo flowsInfo = flowsInfoMapper.findByProcessInstanceId(processInstanceId);
// //查询调用接口的配置
// List<VariableStorage> variableStorageList = variableStorageService.searchVariableStorageList(new SearchVariableStorageVo(flowsInfo.getFlowKey()));
// for (VariableStorage variableStorage : variableStorageList) {
// InvokeRequestVo variableInfo = variableStorage.getInvokeRequest();
// //调用服务接口
// getApiInvokeParam(variableInfo);
// }
// }
}
@Override
public void claimTask(String taskId, Integer userId) {
//当前登录人的Id
taskService.claim(taskId,Integer.toString(userId));
taskService.claim(taskId, Integer.toString(userId));
}
@Override
public void transferTask(TransferTask transferTask) {
taskService.setAssignee(transferTask.getTaskId(),transferTask.getUserId());
taskService.setAssignee(transferTask.getTaskId(), transferTask.getUserId());
}
......@@ -337,17 +340,17 @@ public class WorkFlowServiceImpl implements WorkFlowService {
FlowsInfo flowsInfo = flowsInfoMapper.findById(id).get();
String flowKey = flowsInfo.getFlowKey();
List<Deployment> list = repositoryService.createDeploymentQuery().processDefinitionKey(flowKey).list();
if (list!=null&&list.size()>0){
if (flowsInfo.getState() == 0){
if (list != null && list.size() > 0) {
if (flowsInfo.getState() == 0) {
//挂起
repositoryService.suspendProcessDefinitionByKey(flowKey, true, new Date());
flowsInfo.setState(1);
}else {
} else {
//激活
repositoryService.activateProcessDefinitionByKey(flowKey,true, new Date());
repositoryService.activateProcessDefinitionByKey(flowKey, true, new Date());
flowsInfo.setState(0);
}
}else {
} else {
throw new ApiException("该流程未编辑流程图无法被启用");
}
......@@ -359,12 +362,12 @@ public class WorkFlowServiceImpl implements WorkFlowService {
public void deleteFlow(Integer id) {
//通过流程id查询出flowsInfo
Optional<FlowsInfo> flowsInfoMapperById = flowsInfoMapper.findById(id);
if (flowsInfoMapperById.isPresent()){
if (flowsInfoMapperById.isPresent()) {
FlowsInfo flowsInfo = flowsInfoMapperById.get();
if(flowsInfo.getState() == 0){
if (flowsInfo.getState() == 0) {
flowsInfoMapper.deleteById(id);
}
}else {
} else {
throw new ApiException("流程不存在");
}
......@@ -398,7 +401,7 @@ public class WorkFlowServiceImpl implements WorkFlowService {
BpmnModel bpmnModel = repositoryService.getBpmnModel(pi.getProcessDefinitionId());
ProcessEngineConfiguration engconf = processEngine.getProcessEngineConfiguration();
ProcessDiagramGenerator diagramGenerator = engconf.getProcessDiagramGenerator();
InputStream in = diagramGenerator.generateDiagram(bpmnModel, "png", activityIds, flows, engconf.getActivityFontName(), engconf.getLabelFontName(),engconf.getAnnotationFontName(),engconf.getClassLoader(),1.0,true);
InputStream in = diagramGenerator.generateDiagram(bpmnModel, "png", activityIds, flows, engconf.getActivityFontName(), engconf.getLabelFontName(), engconf.getAnnotationFontName(), engconf.getClassLoader(), 1.0, true);
OutputStream out = null;
byte[] buf = new byte[1024];
int legth = 0;
......@@ -429,6 +432,7 @@ public class WorkFlowServiceImpl implements WorkFlowService {
/**
* 获取调用Api用的参数
*
* @param invokeRequestVo 调用服务接口vo
* @return 调用服务接口实体
*/
......@@ -439,38 +443,39 @@ public class WorkFlowServiceImpl implements WorkFlowService {
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 {
if (!StringUtils.isEmpty(parameter.getExp())) {
parameter.setInstance((Map<String, Object>) getProcessValue(processInstanceId, 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(processInstanceId, (String) instance.get(key)));
newInstance.put(key, getProcessValue(processInstanceId, (String) instance.get(key)));
}
parameter.setInstance(newInstance);
}
newParameterList.add(i,parameter);
newParameterList.add(i, parameter);
}
invokeRequestVo.setParameterList(newParameterList);
return JSONObject.parseObject(JSONObject.toJSONString(invokeRequestVo),InvokeRequest.class) ;
return JSONObject.parseObject(JSONObject.toJSONString(invokeRequestVo), InvokeRequest.class);
}
public Object getProcessValue(String processInstanceId, String exp) {
Expression expression = processEngineConfiguration.getExpressionManager().createExpression(exp);
ManagementService managementService = processEngine.getManagementService();
CommandGetValue test = new CommandGetValue(processInstanceId,expression);
CommandGetValue test = new CommandGetValue(processInstanceId, expression);
Object o = managementService.executeCommand(test);
return o ;
return o;
}
@Override
public Map<String,Object> setVariables(@RequestBody Map<String,Object> maxMap) {
public Map<String, Object> setVariables(@RequestBody Map<String, Object> maxMap) {
Map<String, Object> map = new HashMap<>();
map.putAll(maxMap);
return map;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论