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

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

上级 3746b342
# 工作流项目核心 # 工作流项目核心
## 项目简介 ## 项目简介
1. 通过可视化的方式进行流程的定制
2. 提供流程相关页面的定制
3. 提供流程相关 的接口
### 环境要求 ### 环境要求
- Maven3+ - Maven3+
...@@ -56,7 +60,8 @@ ...@@ -56,7 +60,8 @@
│ └─frame --核心逻辑所在位置 │ └─frame --核心逻辑所在位置
``` ```
## 使用方式 ## 使用方式
### 安装 ### 后端安装
#### maven #### maven
``` ```
<dependency> <dependency>
...@@ -79,7 +84,11 @@ ...@@ -79,7 +84,11 @@
<systemPath>${basedir}/lib/workflow-core-0.0.1-SNAPSHOT.jar</systemPath> <systemPath>${basedir}/lib/workflow-core-0.0.1-SNAPSHOT.jar</systemPath>
</dependency> </dependency>
``` ```
### 调用 ### 前端安装
```
npm install workflow-form
```
### 配置
1. 在springboot 启动类上添加注解 @EnableWorkFlowCore 1. 在springboot 启动类上添加注解 @EnableWorkFlowCore
``` ```
@EnableWorkFlowCore @EnableWorkFlowCore
...@@ -92,8 +101,52 @@ public class DemoApplication { ...@@ -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 @Service
@Primary @Primary
...@@ -145,5 +198,106 @@ public class FlowUserServiceImpl implements UserService { ...@@ -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 { ...@@ -20,4 +20,6 @@ public class SearchTableInfoVo extends JpaCustomPage {
private String tableName; private String tableName;
private String tableCnName; private String tableCnName;
private Integer modelType;
} }
...@@ -82,6 +82,7 @@ public class ModelImpl implements ModelService { ...@@ -82,6 +82,7 @@ public class ModelImpl implements ModelService {
PredicateBuilder<TableInfo> and = Specifications.and(); PredicateBuilder<TableInfo> and = Specifications.and();
and.like(searchTableInfoVo.getTableName() != null, "name", "%" + searchTableInfoVo.getTableName() + "%"); and.like(searchTableInfoVo.getTableName() != null, "name", "%" + searchTableInfoVo.getTableName() + "%");
and.like(searchTableInfoVo.getTableCnName() != null, "cnName", "%" + searchTableInfoVo.getTableCnName() + "%"); and.like(searchTableInfoVo.getTableCnName() != null, "cnName", "%" + searchTableInfoVo.getTableCnName() + "%");
and.eq(searchTableInfoVo.getModelType()!=null,"modelType",searchTableInfoVo.getModelType());
return tableInfoDao.findAll(and.build(), searchTableInfoVo.getPageable()); return tableInfoDao.findAll(and.build(), searchTableInfoVo.getPageable());
} }
......
...@@ -4,6 +4,7 @@ import com.tykj.workflowcore.base.result.ResultUtil; ...@@ -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.FlowsInfo;
import com.tykj.workflowcore.workflow_editer.entity.VariableStorage; 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.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.entity.vo.VariableStorageVo;
import com.tykj.workflowcore.workflow_editer.service.*; import com.tykj.workflowcore.workflow_editer.service.*;
import com.tykj.workflowcore.workflow_editer.entity.vo.FlowsInfoVo; import com.tykj.workflowcore.workflow_editer.entity.vo.FlowsInfoVo;
...@@ -92,7 +93,13 @@ public class FlowsInfoController { ...@@ -92,7 +93,13 @@ public class FlowsInfoController {
@ApiModelProperty("保存函数调用配置") @ApiModelProperty("保存函数调用配置")
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")
@ApiModelProperty("查找函数调用配置")
public ResponseEntity searchVariableStorage(@RequestBody SearchVariableStorageVo searchVariableStorageVo){
return ResultUtil.success( variableStorageService.searchVariableStoragePage(searchVariableStorageVo),"查询接口调用配置成功");
} }
} }
...@@ -42,7 +42,6 @@ public class WorkFlowController { ...@@ -42,7 +42,6 @@ public class WorkFlowController {
@ApiOperation("任务个人待办列表") @ApiOperation("任务个人待办列表")
public List<Map<String,Object>> findUserTask(@RequestBody NextTaskVo nextTaskVo){ public List<Map<String,Object>> findUserTask(@RequestBody NextTaskVo nextTaskVo){
return workFlowService.findTaskByUserId(nextTaskVo); return workFlowService.findTaskByUserId(nextTaskVo);
} }
@PostMapping("/findTaskDetail") @PostMapping("/findTaskDetail")
...@@ -91,4 +90,6 @@ public class WorkFlowController { ...@@ -91,4 +90,6 @@ public class WorkFlowController {
return workFlowService.findHistoryTask(userId); return workFlowService.findHistoryTask(userId);
} }
} }
...@@ -51,6 +51,9 @@ public class FlowsInfo extends BaseEntity { ...@@ -51,6 +51,9 @@ public class FlowsInfo extends BaseEntity {
@ApiModelProperty("文件路径") @ApiModelProperty("文件路径")
private String filePath; private String filePath;
@ApiModelProperty("自定义格式XML路径")
private String fileCustomPath;
@ApiModelProperty("流程描述") @ApiModelProperty("流程描述")
private String flowDescribe; private String flowDescribe;
......
...@@ -34,7 +34,6 @@ import java.util.Date; ...@@ -34,7 +34,6 @@ import java.util.Date;
public class FormPage extends BaseEntity { public class FormPage extends BaseEntity {
@ApiModelProperty("页面名称") @ApiModelProperty("页面名称")
private String pageName; private String pageName;
......
package com.tykj.workflowcore.workflow_editer.entity; 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.base.entity.BaseEntity;
import com.tykj.workflowcore.model_layer.annotations.WorkFlowCoreNoScan; import com.tykj.workflowcore.model_layer.annotations.WorkFlowCoreNoScan;
import com.tykj.workflowcore.workflow_editer.entity.vo.InvokeRequestVo;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
...@@ -17,11 +20,11 @@ import javax.persistence.Entity; ...@@ -17,11 +20,11 @@ import javax.persistence.Entity;
* *
* @Author: zsp * @Author: zsp
*/ */
@Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@Entity @Entity
@WorkFlowCoreNoScan @WorkFlowCoreNoScan
@Data
public class VariableStorage extends BaseEntity { public class VariableStorage extends BaseEntity {
...@@ -36,6 +39,11 @@ public class VariableStorage extends BaseEntity { ...@@ -36,6 +39,11 @@ public class VariableStorage extends BaseEntity {
private String method; private String method;
@ApiModelProperty("详情json") @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; 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 com.tykj.workflowcore.workflow_editer.entity.VariableStorage;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import springfox.documentation.spring.web.json.Json;
/** /**
* @author HuangXiahao * @author HuangXiahao
...@@ -25,11 +28,12 @@ public class VariableStorageVo { ...@@ -25,11 +28,12 @@ public class VariableStorageVo {
private String method; private String method;
private String variableInfo; private InvokeRequestVo invokeRequest;
public VariableStorage toEntity(){ public VariableStorage toEntity(){
VariableStorage variableStorage = new VariableStorage(); VariableStorage variableStorage = new VariableStorage();
BeanUtils.copyProperties(this,variableStorage); BeanUtils.copyProperties(this,variableStorage);
variableStorage.setInvokeRequest(JSON.toJSONString(invokeRequest));
return variableStorage; return variableStorage;
} }
} }
package com.tykj.workflowcore.workflow_editer.service; package com.tykj.workflowcore.workflow_editer.service;
import com.tykj.workflowcore.workflow_editer.entity.VariableStorage; 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 org.springframework.web.bind.annotation.RequestBody;
import java.util.List; import java.util.List;
...@@ -16,15 +18,22 @@ import java.util.List; ...@@ -16,15 +18,22 @@ import java.util.List;
public interface VariableStorageService { public interface VariableStorageService {
/** /**
* 保存变量池 * 保存接口调用配置
* @param variableStorage 变量池 * @param variableStorage 变量池
*/ */
VariableStorage saveVariableStorageService(@RequestBody VariableStorage variableStorage); VariableStorage saveVariableStorageService(@RequestBody VariableStorage variableStorage);
/** /**
* 查询变量池 * 根据流程主键查询
* @param flowKey 流程主键 * @param searchVariableStorageVo 流程主键
* @return VariableStorage 变量池 * @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; 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.entity.VariableStorage;
import com.tykj.workflowcore.workflow_editer.dao.VariableStorageMapper; 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 com.tykj.workflowcore.workflow_editer.service.VariableStorageService;
import liquibase.pro.packaged.B;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
...@@ -28,10 +33,25 @@ public class VariableStorageServiceImpl implements VariableStorageService { ...@@ -28,10 +33,25 @@ public class VariableStorageServiceImpl implements VariableStorageService {
} }
@Override @Override
public List<VariableStorage> findByFlowKey(String flowKey) { public List<VariableStorage> searchVariableStorageList(SearchVariableStorageVo searchVariableStorageVo) {
List<VariableStorage> allByFlowKey = variableStorageMapper.findAllByFlowKey(flowKey); PredicateBuilder predicateBuilder = Specifications.and();
return allByFlowKey; 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; ...@@ -5,9 +5,11 @@ 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.api.service.SpringBeanService; import com.tykj.workflowcore.api.service.SpringBeanService;
import com.tykj.workflowcore.base.result.ApiException; 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.entity.*;
import com.tykj.workflowcore.workflow_editer.dao.FlowsInfoMapper; import com.tykj.workflowcore.workflow_editer.dao.FlowsInfoMapper;
import com.tykj.workflowcore.workflow_editer.entity.vo.*; 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.UserService;
import com.tykj.workflowcore.workflow_editer.service.VariableStorageService; import com.tykj.workflowcore.workflow_editer.service.VariableStorageService;
import com.tykj.workflowcore.workflow_editer.service.WorkFlowService; import com.tykj.workflowcore.workflow_editer.service.WorkFlowService;
...@@ -17,11 +19,12 @@ import org.dom4j.Document; ...@@ -17,11 +19,12 @@ import org.dom4j.Document;
import org.dom4j.DocumentException; import org.dom4j.DocumentException;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.io.SAXReader; 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.api.delegate.Expression;
import org.flowable.common.engine.impl.identity.Authentication; import org.flowable.common.engine.impl.identity.Authentication;
import org.flowable.engine.*; import org.flowable.engine.*;
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.Deployment; import org.flowable.engine.repository.Deployment;
import org.flowable.engine.runtime.Execution; import org.flowable.engine.runtime.Execution;
import org.flowable.engine.runtime.ProcessInstance; import org.flowable.engine.runtime.ProcessInstance;
...@@ -30,6 +33,7 @@ import org.flowable.task.api.Task; ...@@ -30,6 +33,7 @@ import org.flowable.task.api.Task;
import org.flowable.task.api.TaskQuery; import org.flowable.task.api.TaskQuery;
import org.flowable.task.api.history.HistoricTaskInstance; 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.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
...@@ -39,6 +43,7 @@ import org.springframework.web.multipart.MultipartFile; ...@@ -39,6 +43,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
import java.util.regex.Pattern;
/** /**
* ClassName: FlowableServiceImpl * ClassName: FlowableServiceImpl
...@@ -65,7 +70,10 @@ public class WorkFlowServiceImpl implements WorkFlowService { ...@@ -65,7 +70,10 @@ public class WorkFlowServiceImpl implements WorkFlowService {
final final
ClassLoader classLoader; 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.historyService = historyService;
this.repositoryService = repositoryService; this.repositoryService = repositoryService;
this.runtimeService = runtimeService; this.runtimeService = runtimeService;
...@@ -76,7 +84,7 @@ public class WorkFlowServiceImpl implements WorkFlowService { ...@@ -76,7 +84,7 @@ public class WorkFlowServiceImpl implements WorkFlowService {
this.processEngine = processEngine; this.processEngine = processEngine;
this.variableStorageService = variableStorageService; this.variableStorageService = variableStorageService;
this.classLoader = classLoader; this.classLoader = classLoader;
System.out.println(userService!=null?"成功":"失败"); System.out.println(userService != null ? "成功" : "失败");
} }
@Override @Override
...@@ -94,7 +102,7 @@ public class WorkFlowServiceImpl implements WorkFlowService { ...@@ -94,7 +102,7 @@ public class WorkFlowServiceImpl implements WorkFlowService {
System.out.println(fileName); System.out.println(fileName);
//指定本地存入路径 //指定本地存入路径
File fileNew = new File(classLoader.getResource("").getPath() + fileName); File fileNew = new File(classLoader.getResource("").getPath() + fileName);
realPath = classLoader.getResource("").getPath()+fileName; realPath = classLoader.getResource("").getPath() + fileName;
try { try {
file.transferTo(fileNew); file.transferTo(fileNew);
} catch (IOException e) { } catch (IOException e) {
...@@ -120,13 +128,13 @@ public class WorkFlowServiceImpl implements WorkFlowService { ...@@ -120,13 +128,13 @@ public class WorkFlowServiceImpl implements WorkFlowService {
List<Attribute> attributes = stu.attributes(); List<Attribute> attributes = stu.attributes();
System.out.println("======获取属性值======"); System.out.println("======获取属性值======");
for (Attribute attribute : attributes) { for (Attribute attribute : attributes) {
if ("id".equals(attribute.getName())){ if ("id".equals(attribute.getName())) {
processId = attribute.getValue(); 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(); processName = attribute.getValue();
System.out.println("processName的值是:"+processName); System.out.println("processName的值是:" + processName);
} }
} }
//保存processId和processName 到数据库里面 //保存processId和processName 到数据库里面
...@@ -144,53 +152,20 @@ public class WorkFlowServiceImpl implements WorkFlowService { ...@@ -144,53 +152,20 @@ public class WorkFlowServiceImpl implements WorkFlowService {
@Override @Override
public void flowXml(@RequestBody FlowsInfoVo flowsInfoVo) { public void flowXml(@RequestBody FlowsInfoVo flowsInfoVo) {
String basePath = System.getProperty("user.dir") + "\\xml\\";
Integer id = flowsInfoVo.getId(); Integer id = flowsInfoVo.getId();
String flowKey = flowsInfoVo.getFlowKey(); String flowKey = flowsInfoVo.getFlowKey();
String fileXml = flowsInfoVo.getFileXml(); String fileXml = flowsInfoVo.getFileXml();
//生成xml文件 //生成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; FileUtil.createFileByString(basePath + flowKey + "bpmn20.xml", flowsInfoVo.getFileXml().replaceAll("\\[\\?\\?[^\\]]+\\?\\?\\]", ""));
BufferedWriter bufferedWriter = null; FileUtil.createFileByString(basePath + flowKey + "bpmnCustom20.xml", flowsInfoVo.getFileXml());
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();
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
FlowsInfo flowsInfo = new FlowsInfo(); FlowsInfo flowsInfo = new FlowsInfo();
BeanUtils.copyProperties(flowsInfoVo,flowsInfo); BeanUtils.copyProperties(flowsInfoVo, flowsInfo);
flowsInfo.setResourceName(flowKey+"bpmn20.xml"); flowsInfo.setResourceName(flowKey + "bpmn20.xml");
flowsInfo.setFilePath("\\xml\\"+flowKey+"bpmn20.xml"); flowsInfo.setFilePath("\\xml\\" + flowKey + "bpmn20.xml");
flowsInfo.setFileCustomPath("\\xml\\" + flowKey + "bpmnCustom20.xml");
flowsInfo.setId(id); flowsInfo.setId(id);
//更新并保存 //更新并保存
FlowsInfo save = flowsInfoMapper.save(flowsInfo); FlowsInfo save = flowsInfoMapper.save(flowsInfo);
...@@ -198,8 +173,9 @@ public class WorkFlowServiceImpl implements WorkFlowService { ...@@ -198,8 +173,9 @@ public class WorkFlowServiceImpl implements WorkFlowService {
deployXml(save); deployXml(save);
} }
@Override @Override
public Integer createFlow(FlowsInfo flowsInfo ) { public Integer createFlow(FlowsInfo flowsInfo) {
FlowsInfo flowsInfo1 = flowsInfoMapper.save(flowsInfo); FlowsInfo flowsInfo1 = flowsInfoMapper.save(flowsInfo);
return flowsInfo1.getId(); return flowsInfo1.getId();
} }
...@@ -209,8 +185,8 @@ public class WorkFlowServiceImpl implements WorkFlowService { ...@@ -209,8 +185,8 @@ public class WorkFlowServiceImpl implements WorkFlowService {
public void deployXml(FlowsInfo flowsInfo) { public void deployXml(FlowsInfo flowsInfo) {
Deployment deploy = null; Deployment deploy = null;
try { try {
deploy = repositoryService.createDeployment().addInputStream(System.getProperty("user.dir")+flowsInfo.getResourceName(), deploy = repositoryService.createDeployment().addInputStream(System.getProperty("user.dir") + flowsInfo.getResourceName(),
new FileInputStream(System.getProperty("user.dir") +flowsInfo.getFilePath())).deploy(); new FileInputStream(System.getProperty("user.dir") + flowsInfo.getFilePath())).deploy();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
...@@ -228,7 +204,7 @@ public class WorkFlowServiceImpl implements WorkFlowService { ...@@ -228,7 +204,7 @@ public class WorkFlowServiceImpl implements WorkFlowService {
//设置流程发起人 //设置流程发起人
WorkFlowUser currentUser = userService.getCurrentUser(); WorkFlowUser currentUser = userService.getCurrentUser();
Authentication.setAuthenticatedUserId(currentUser.getId()+""); Authentication.setAuthenticatedUserId(currentUser.getId() + "");
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(startFlowVo.getFlowKey(), ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(startFlowVo.getFlowKey(),
startFlowVo.getMap()); startFlowVo.getMap());
...@@ -241,26 +217,36 @@ public class WorkFlowServiceImpl implements WorkFlowService { ...@@ -241,26 +217,36 @@ public class WorkFlowServiceImpl implements WorkFlowService {
@Override @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>>(); List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
TaskQuery taskQuery = taskService.createTaskQuery().or(); TaskQuery taskQuery = taskService.createTaskQuery();
if (nextTaskVo.getUserId()!=null){ if (nextTaskVo.getRoleId() != null || nextTaskVo.getUserId() != null) {
taskQuery.or();
if (nextTaskVo.getUserId() != null) {
taskQuery.taskCandidateUser(nextTaskVo.getUserId()).orderByTaskCreateTime().desc(); taskQuery.taskCandidateUser(nextTaskVo.getUserId()).orderByTaskCreateTime().desc();
} }
if (nextTaskVo.getRoleId()!=null&&nextTaskVo.getRoleId().size()>0){ if (nextTaskVo.getRoleId() != null && nextTaskVo.getRoleId().size() > 0) {
taskQuery.taskCandidateGroupIn(nextTaskVo.getRoleId()).orderByTaskCreateTime().desc(); taskQuery.taskCandidateGroupIn(nextTaskVo.getRoleId()).orderByTaskCreateTime().desc();
} }
List<Task> listTask = taskQuery.endOr().listPage(1,5); taskQuery.endOr();
}
List<Task> listTask = taskQuery.list();
for (Task task : listTask) { for (Task task : listTask) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
ProcessInstance processInstance = ProcessInstance processInstance =
runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult(); runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult();
map.put("taskName",task.getName()); //节点id
map.put("taskDesc",task.getDescription()); String taskDefinitionKey = task.getTaskDefinitionKey();
map.put("createTime",task.getCreateTime()); //通过节点id查询出pageId
map.put("promoter",processInstance.getStartUserId()); Integer currentPageId = nodeInfoService.findByNodeId(taskDefinitionKey);
map.put("processInstanceId",processInstance.getId()); 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); listMap.add(map);
} }
return listMap; return listMap;
...@@ -271,14 +257,14 @@ public class WorkFlowServiceImpl implements WorkFlowService { ...@@ -271,14 +257,14 @@ public class WorkFlowServiceImpl implements WorkFlowService {
public Map<String, Object> findTaskDetail(String taskId) { public Map<String, Object> findTaskDetail(String taskId) {
Map<String, Object> variables = new HashMap<>(); Map<String, Object> variables = new HashMap<>();
//流程还在运行 //流程还在运行
if (taskId != null){ if (taskId != null) {
variables = taskService.getVariables(taskId); variables = taskService.getVariables(taskId);
}else { } else {
//流程已经结束 //流程已经结束
//从历史中查询 //从历史中查询
HistoricTaskInstance historicTaskInstance = HistoricTaskInstance historicTaskInstance =
historyService.createHistoricTaskInstanceQuery().taskId(taskId).finished().singleResult(); historyService.createHistoricTaskInstanceQuery().taskId(taskId).finished().singleResult();
variables.put("historicTaskInstance",historicTaskInstance); variables.put("historicTaskInstance", historicTaskInstance);
} }
return variables; return variables;
} }
...@@ -287,47 +273,64 @@ public class WorkFlowServiceImpl implements WorkFlowService { ...@@ -287,47 +273,64 @@ public class WorkFlowServiceImpl implements WorkFlowService {
public void completeTask(@RequestBody TaskVo taskVo) { public void completeTask(@RequestBody TaskVo taskVo) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
if (taskVo.getMap() != null) {
setVariables(taskVo.getMap()); setVariables(taskVo.getMap());
}
Task task = taskService.createTaskQuery().taskId(taskVo.getTaskId()).singleResult(); Task task = taskService.createTaskQuery().taskId(taskVo.getTaskId()).singleResult();
String processInstanceId = task.getProcessInstanceId(); 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){ if (taskVo.getConditionalExpression() != null) {
claimTask(task.getId(),userService.getCurrentUser().getId()); claimTask(task.getId(), userService.getCurrentUser().getId());
taskService.complete(task.getId()); taskService.complete(task.getId());
}else { } else {
map.put("handlingOpinion",taskVo.getHandlingOpinion()); map.put("handlingOpinion", taskVo.getHandlingOpinion());
claimTask(task.getId(),userService.getCurrentUser().getId()); claimTask(task.getId(), userService.getCurrentUser().getId());
taskService.complete(task.getId(),map); taskService.complete(task.getId(), map);
} }
if (taskVo.getTaskId() == null){ //查询是否为最后一个节点
//流程结束了 // ExecutionEntity ee = (ExecutionEntity) processEngine.getRuntimeService().createExecutionQuery()
//通过processInstanceId查询出flowKey // .executionId(task.getExecutionId()).singleResult();
FlowsInfo flowsInfo = flowsInfoMapper.findByProcessInstanceId(processInstanceId); // BpmnModel bpmnModel = processEngine.getRepositoryService().getBpmnModel(task.getProcessDefinitionId());
List<VariableStorage> variableStorageList = variableStorageService.findByFlowKey(flowsInfo.getFlowKey()); // FlowNode flowNode = (FlowNode) bpmnModel.getFlowElement(ee.getActivityId());
for (VariableStorage variableStorage : variableStorageList) { // List<SequenceFlow> outFlows = flowNode.getOutgoingFlows();
String variableInfo = variableStorage.getVariableInfo(); // for (SequenceFlow sequenceFlow : outFlows) {
//调用服务接口 // FlowElement targetFlow = sequenceFlow.getTargetFlowElement();
InvokeRequestVo invokeRequestVo = (InvokeRequestVo) JSONObject.parse(variableInfo); // // 如果下个审批节点为结束节点
getApiInvokeParam(invokeRequestVo); // 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 @Override
public void claimTask(String taskId, Integer userId) { public void claimTask(String taskId, Integer userId) {
//当前登录人的Id //当前登录人的Id
taskService.claim(taskId,Integer.toString(userId)); taskService.claim(taskId, Integer.toString(userId));
} }
@Override @Override
public void transferTask(TransferTask transferTask) { 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 { ...@@ -337,17 +340,17 @@ public class WorkFlowServiceImpl implements WorkFlowService {
FlowsInfo flowsInfo = flowsInfoMapper.findById(id).get(); FlowsInfo flowsInfo = flowsInfoMapper.findById(id).get();
String flowKey = flowsInfo.getFlowKey(); String flowKey = flowsInfo.getFlowKey();
List<Deployment> list = repositoryService.createDeploymentQuery().processDefinitionKey(flowKey).list(); List<Deployment> list = repositoryService.createDeploymentQuery().processDefinitionKey(flowKey).list();
if (list!=null&&list.size()>0){ if (list != null && list.size() > 0) {
if (flowsInfo.getState() == 0){ if (flowsInfo.getState() == 0) {
//挂起 //挂起
repositoryService.suspendProcessDefinitionByKey(flowKey, true, new Date()); repositoryService.suspendProcessDefinitionByKey(flowKey, true, new Date());
flowsInfo.setState(1); flowsInfo.setState(1);
}else { } else {
//激活 //激活
repositoryService.activateProcessDefinitionByKey(flowKey,true, new Date()); repositoryService.activateProcessDefinitionByKey(flowKey, true, new Date());
flowsInfo.setState(0); flowsInfo.setState(0);
} }
}else { } else {
throw new ApiException("该流程未编辑流程图无法被启用"); throw new ApiException("该流程未编辑流程图无法被启用");
} }
...@@ -359,12 +362,12 @@ public class WorkFlowServiceImpl implements WorkFlowService { ...@@ -359,12 +362,12 @@ public class WorkFlowServiceImpl implements WorkFlowService {
public void deleteFlow(Integer id) { public void deleteFlow(Integer id) {
//通过流程id查询出flowsInfo //通过流程id查询出flowsInfo
Optional<FlowsInfo> flowsInfoMapperById = flowsInfoMapper.findById(id); Optional<FlowsInfo> flowsInfoMapperById = flowsInfoMapper.findById(id);
if (flowsInfoMapperById.isPresent()){ if (flowsInfoMapperById.isPresent()) {
FlowsInfo flowsInfo = flowsInfoMapperById.get(); FlowsInfo flowsInfo = flowsInfoMapperById.get();
if(flowsInfo.getState() == 0){ if (flowsInfo.getState() == 0) {
flowsInfoMapper.deleteById(id); flowsInfoMapper.deleteById(id);
} }
}else { } else {
throw new ApiException("流程不存在"); throw new ApiException("流程不存在");
} }
...@@ -398,7 +401,7 @@ public class WorkFlowServiceImpl implements WorkFlowService { ...@@ -398,7 +401,7 @@ public class WorkFlowServiceImpl implements WorkFlowService {
BpmnModel bpmnModel = repositoryService.getBpmnModel(pi.getProcessDefinitionId()); BpmnModel bpmnModel = repositoryService.getBpmnModel(pi.getProcessDefinitionId());
ProcessEngineConfiguration engconf = processEngine.getProcessEngineConfiguration(); ProcessEngineConfiguration engconf = processEngine.getProcessEngineConfiguration();
ProcessDiagramGenerator diagramGenerator = engconf.getProcessDiagramGenerator(); 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; OutputStream out = null;
byte[] buf = new byte[1024]; byte[] buf = new byte[1024];
int legth = 0; int legth = 0;
...@@ -429,6 +432,7 @@ public class WorkFlowServiceImpl implements WorkFlowService { ...@@ -429,6 +432,7 @@ public class WorkFlowServiceImpl implements WorkFlowService {
/** /**
* 获取调用Api用的参数 * 获取调用Api用的参数
*
* @param invokeRequestVo 调用服务接口vo * @param invokeRequestVo 调用服务接口vo
* @return 调用服务接口实体 * @return 调用服务接口实体
*/ */
...@@ -439,38 +443,39 @@ public class WorkFlowServiceImpl implements WorkFlowService { ...@@ -439,38 +443,39 @@ public class WorkFlowServiceImpl implements WorkFlowService {
List<Parameter> newParameterList = new ArrayList<>(); List<Parameter> newParameterList = new ArrayList<>();
for (int i = 0; i < parameterList.size(); i++) { for (int i = 0; i < parameterList.size(); i++) {
Parameter parameter = parameterList.get(i); Parameter parameter = parameterList.get(i);
if (!StringUtils.isEmpty(parameter.getExp())){ if (!StringUtils.isEmpty(parameter.getExp())) {
parameter.setInstance((Map<String, Object>) getProcessValue(processInstanceId,parameter.getExp())); parameter.setInstance((Map<String, Object>) getProcessValue(processInstanceId, parameter.getExp()));
}else { } else {
Map<String, Object> instance = parameter.getInstance(); Map<String, Object> instance = parameter.getInstance();
JSONObject newInstance = new JSONObject(); JSONObject newInstance = new JSONObject();
//遍历param的key //遍历param的key
Set<String> oldInstanceKey = instance.keySet(); Set<String> oldInstanceKey = instance.keySet();
for (String key : oldInstanceKey) { 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); parameter.setInstance(newInstance);
} }
newParameterList.add(i,parameter); newParameterList.add(i, parameter);
} }
invokeRequestVo.setParameterList(newParameterList); 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) { public Object getProcessValue(String processInstanceId, String exp) {
Expression expression = processEngineConfiguration.getExpressionManager().createExpression(exp); Expression expression = processEngineConfiguration.getExpressionManager().createExpression(exp);
ManagementService managementService = processEngine.getManagementService(); ManagementService managementService = processEngine.getManagementService();
CommandGetValue test = new CommandGetValue(processInstanceId,expression); CommandGetValue test = new CommandGetValue(processInstanceId, expression);
Object o = managementService.executeCommand(test); Object o = managementService.executeCommand(test);
return o ; return o;
} }
@Override @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<String, Object> map = new HashMap<>();
map.putAll(maxMap); map.putAll(maxMap);
return map; return map;
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论