提交 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());
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论