增加flowable模块
This commit is contained in:
parent
92fac2b3f7
commit
b4e03795d4
|
@ -140,3 +140,20 @@ flowable:
|
|||
async-executor-activate: false
|
||||
# 将databaseSchemaUpdate设置为true。当Flowable发现库与数据库表结构不一致时,会自动将数据库表结构升级至新版本。
|
||||
database-schema-update: true
|
||||
log4j:
|
||||
rootLogger: ERROR, CA
|
||||
|
||||
# ConsoleAppender
|
||||
appender:
|
||||
CA: org.apache.log4j.ConsoleAppender
|
||||
|
||||
|
||||
#custom
|
||||
logger:
|
||||
org:
|
||||
flowable:
|
||||
task:
|
||||
service:
|
||||
impl:
|
||||
persistence:
|
||||
entity: DEBUG
|
|
@ -26,10 +26,13 @@ public class DeploymentTests extends JunitTestApplication {
|
|||
|
||||
@Test
|
||||
public void createClassDeployment() throws Exception{
|
||||
InputStream in = new BufferedInputStream(new FileInputStream("D:\\请假流程.bpmn20.xml"));
|
||||
InputStream in = new BufferedInputStream(new FileInputStream("D:\\ChromeCoreDownloads\\snow_leave.bpmn20.xml"));
|
||||
DeploymentDTO classDeploymentDTO=new DeploymentDTO();
|
||||
classDeploymentDTO.setKey("snow_leave");
|
||||
// classDeploymentDTO.setKey("snow_leave");
|
||||
classDeploymentDTO.setName("请假流程");
|
||||
// classDeploymentDTO.setCategory("snow");
|
||||
classDeploymentDTO.setResourceName("请假流程");
|
||||
// classDeploymentDTO.setTenantId("snow");
|
||||
// classDeploymentDTO.setClassPathResource("D:\\flowable\\leave.bpmn20.xml");
|
||||
Deployment classDeployment = flowAblePublishService.createInputStreamDeployment(classDeploymentDTO,in);
|
||||
log.info("发布结果:{}",JSON.toJSONString(classDeployment));
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package com.snow.flowable;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.snow.JunitTestApplication;
|
||||
import com.snow.flowable.domain.StartProcessDTO;
|
||||
import com.snow.flowable.service.FlowableService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.flowable.engine.runtime.ProcessInstance;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author qimingjin
|
||||
* @Title:
|
||||
* @Description:
|
||||
* @date 2020/11/20 16:05
|
||||
*/
|
||||
@Slf4j
|
||||
public class FlowableServiceTests extends JunitTestApplication {
|
||||
@Autowired
|
||||
private FlowableService flowableService;
|
||||
|
||||
@Test
|
||||
public void startProcessInstanceByKey(){
|
||||
StartProcessDTO startProcessDTO=new StartProcessDTO();
|
||||
startProcessDTO.setStartUserId("1");
|
||||
startProcessDTO.setProcessDefinitionKey("snow_leave");
|
||||
startProcessDTO.setBusinessKey("QJ000001");
|
||||
Map<String,Object> map=Maps.newHashMap();
|
||||
map.put("manager","2");
|
||||
startProcessDTO.setVariables(map);
|
||||
ProcessInstance processInstance = flowableService.startProcessInstanceByKey(startProcessDTO);
|
||||
log.info("发布结果:{}",JSON.toJSONString(processInstance));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.snow.flowable.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author qimingjin
|
||||
* @Title:
|
||||
* @Description:
|
||||
* @date 2020/11/20 14:10
|
||||
*/
|
||||
@Data
|
||||
public class CompleteTaskDTO implements Serializable {
|
||||
/**
|
||||
* 任务ID
|
||||
*/
|
||||
private String taskId;
|
||||
/**
|
||||
* 完成任务人
|
||||
*/
|
||||
private String userId;
|
||||
/**
|
||||
* 是否通过
|
||||
*/
|
||||
private Boolean isPass;
|
||||
|
||||
/**
|
||||
* 审批意见
|
||||
*/
|
||||
private String comment;
|
||||
/**
|
||||
* 审批节点的相关文件(只在审批节点展示)
|
||||
*/
|
||||
|
||||
private List<FileEntry> files;
|
||||
/**
|
||||
* 流程级别的相关文件(跟具体业务相关需要回写到业务库)
|
||||
*/
|
||||
private List<FileGroup> flowFiles;
|
||||
/**
|
||||
* 特殊事项
|
||||
*/
|
||||
private List<String> specialItems;
|
||||
/**
|
||||
* 参数map
|
||||
*/
|
||||
private Map<String,Object> paramMap;
|
||||
|
||||
public final static String IS_PASS="isPass";
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.snow.flowable.domain;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class FileEntry implements Serializable {
|
||||
|
||||
|
||||
private String key;
|
||||
|
||||
|
||||
private String name;
|
||||
|
||||
private String url;
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.snow.flowable.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class FileGroup implements Serializable {
|
||||
@NotEmpty
|
||||
private final String category;
|
||||
@NotNull
|
||||
private final List<FileEntry> files;
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.snow.flowable.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author qimingjin
|
||||
* @Title:
|
||||
* @Description:
|
||||
* @date 2020/11/20 16:16
|
||||
*/
|
||||
@Data
|
||||
public class StartProcessDTO implements Serializable {
|
||||
|
||||
private String startUserId;
|
||||
|
||||
private String processDefinitionKey;
|
||||
|
||||
private String businessKey;
|
||||
|
||||
private Map<String, Object> variables;
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.snow.flowable.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author qimingjin
|
||||
* @Title:
|
||||
* @Description:
|
||||
* @date 2020/11/20 13:43
|
||||
*/
|
||||
@Data
|
||||
public class TaskBaseDTO implements Serializable {
|
||||
|
||||
private String processInstanceId;
|
||||
|
||||
private String definitionKey;
|
||||
|
||||
private String taskId;
|
||||
|
||||
private String businessKey;
|
||||
/**
|
||||
* 初始页
|
||||
*/
|
||||
private int firstResult=0;
|
||||
/**
|
||||
* 每页数
|
||||
*/
|
||||
private int maxResults=10;
|
||||
|
||||
}
|
|
@ -1,7 +1,10 @@
|
|||
package com.snow.flowable.service;
|
||||
|
||||
import com.snow.flowable.domain.CompleteTaskDTO;
|
||||
import com.snow.flowable.domain.StartProcessDTO;
|
||||
import com.snow.flowable.domain.TaskBaseDTO;
|
||||
import org.flowable.engine.runtime.ProcessInstance;
|
||||
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
|
||||
import org.flowable.task.api.Task;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -15,27 +18,27 @@ import java.util.Map;
|
|||
public interface FlowableService {
|
||||
/**
|
||||
* 通过processDefinitionKey开始流程
|
||||
* @param processDefinitionKey
|
||||
* @param startProcessDTO
|
||||
* @return
|
||||
*/
|
||||
ProcessInstance startProcessInstanceByKey(String processDefinitionKey);
|
||||
ProcessInstance startProcessInstanceByKey(StartProcessDTO startProcessDTO);
|
||||
|
||||
ProcessInstance startProcessInstanceByKey(String processDefinitionKey, String businessKey);
|
||||
|
||||
ProcessInstance startProcessInstanceByKey(String processDefinitionKey, Map<String, Object> variables);
|
||||
|
||||
ProcessInstance startProcessInstanceByKey(String processDefinitionKey, String businessKey, Map<String, Object> variables);
|
||||
|
||||
ProcessInstance startProcessInstanceByKeyAndTenantId(String processDefinitionKey, String tenantId);
|
||||
|
||||
/**
|
||||
* 根据流程实例查询任务
|
||||
* @param processInstanceId
|
||||
* 根据任务ID获取代办
|
||||
* @param taskId
|
||||
* @return
|
||||
*/
|
||||
List<TaskEntity> findTasksByProcessInstanceId(String processInstanceId);
|
||||
Task getTask(String taskId);
|
||||
|
||||
TaskEntity getTask(String id);
|
||||
/**
|
||||
* 获取代办
|
||||
* @param userId
|
||||
* @param taskBaseDTO
|
||||
* @return
|
||||
*/
|
||||
List<Task> findTasksByUserId(String userId,TaskBaseDTO taskBaseDTO);
|
||||
|
||||
List<TaskEntity> findTasksByUserId(String userId);
|
||||
void completeTask(CompleteTaskDTO completeTaskDTO);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.snow.flowable.service.impl;
|
||||
|
||||
import com.snow.common.utils.StringUtils;
|
||||
import com.snow.flowable.domain.ClassDeploymentDTO;
|
||||
import com.snow.flowable.domain.DeploymentDTO;
|
||||
import com.snow.flowable.service.FlowablePublishService;
|
||||
|
@ -7,6 +8,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.flowable.common.engine.impl.util.IoUtil;
|
||||
import org.flowable.engine.RepositoryService;
|
||||
import org.flowable.engine.repository.Deployment;
|
||||
import org.flowable.engine.repository.DeploymentBuilder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -68,11 +70,17 @@ public class FlowablePublishServiceImpl implements FlowablePublishService {
|
|||
|
||||
@Override
|
||||
public Deployment createInputStreamDeployment(DeploymentDTO deploymentDTO, InputStream inputStream) {
|
||||
Deployment deploy = repositoryService.createDeployment()
|
||||
.tenantId(deploymentDTO.getTenantId())
|
||||
.category(deploymentDTO.getCategory())
|
||||
.name(deploymentDTO.getName())
|
||||
.key(deploymentDTO.getKey())
|
||||
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
|
||||
if(StringUtils.isNotNull(deploymentDTO.getTenantId())){
|
||||
deploymentBuilder.tenantId(deploymentDTO.getTenantId());
|
||||
}
|
||||
if(StringUtils.isNotNull(deploymentDTO.getCategory())){
|
||||
deploymentBuilder.category(deploymentDTO.getCategory());
|
||||
}
|
||||
if(StringUtils.isNotNull(deploymentDTO.getKey())){
|
||||
deploymentBuilder.key(deploymentDTO.getKey());
|
||||
}
|
||||
Deployment deploy = deploymentBuilder.name(deploymentDTO.getName())
|
||||
.addInputStream(deploymentDTO.getResourceName(), inputStream)
|
||||
.deploy();
|
||||
return deploy;
|
||||
|
|
|
@ -1,20 +1,31 @@
|
|||
package com.snow.flowable.service.impl;
|
||||
|
||||
import com.snow.common.exception.BusinessException;
|
||||
import com.snow.flowable.domain.CompleteTaskDTO;
|
||||
import com.snow.flowable.domain.FileEntry;
|
||||
import com.snow.flowable.domain.StartProcessDTO;
|
||||
import com.snow.flowable.domain.TaskBaseDTO;
|
||||
import com.snow.flowable.service.FlowableService;
|
||||
import com.snow.system.domain.SysRole;
|
||||
import com.snow.system.service.ISysRoleService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.flowable.engine.IdentityService;
|
||||
import org.flowable.engine.RepositoryService;
|
||||
import org.flowable.engine.RuntimeService;
|
||||
import org.flowable.engine.TaskService;
|
||||
import org.flowable.engine.runtime.ProcessInstance;
|
||||
import org.flowable.task.api.Task;
|
||||
import org.flowable.task.api.TaskQuery;
|
||||
import org.flowable.task.service.impl.TaskQueryProperty;
|
||||
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
@ -26,6 +37,9 @@ import java.util.stream.Collectors;
|
|||
@Slf4j
|
||||
@Service
|
||||
public class FlowableServiceImpl implements FlowableService {
|
||||
@Autowired
|
||||
private IdentityService identityService;
|
||||
|
||||
@Autowired
|
||||
private RuntimeService runtimeService;
|
||||
|
||||
|
@ -35,53 +49,90 @@ public class FlowableServiceImpl implements FlowableService {
|
|||
@Autowired
|
||||
private ISysRoleService roleService;
|
||||
|
||||
@Autowired
|
||||
private RepositoryService repositoryService;
|
||||
|
||||
@Override
|
||||
public ProcessInstance startProcessInstanceByKey(String processDefinitionKey) {
|
||||
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey);
|
||||
public ProcessInstance startProcessInstanceByKey(StartProcessDTO startProcessDTO) {
|
||||
ProcessInstance processInstance=null;
|
||||
if(!StringUtils.isEmpty(startProcessDTO.getStartUserId())){
|
||||
identityService.setAuthenticatedUserId(startProcessDTO.getStartUserId());
|
||||
}
|
||||
Map<String, Object> paramMap = startProcessDTO.getVariables();
|
||||
|
||||
if(!CollectionUtils.isEmpty(paramMap)){
|
||||
processInstance = runtimeService.startProcessInstanceByKey(startProcessDTO.getProcessDefinitionKey(),startProcessDTO.getBusinessKey(),paramMap);
|
||||
}else {
|
||||
processInstance = runtimeService.startProcessInstanceByKey(startProcessDTO.getProcessDefinitionKey(),startProcessDTO.getBusinessKey());
|
||||
}
|
||||
return processInstance;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public ProcessInstance startProcessInstanceByKey(String processDefinitionKey, String businessKey) {
|
||||
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey, businessKey);
|
||||
return processInstance;
|
||||
public Task getTask(String taskId) {
|
||||
Task task = taskService.createTaskQuery()
|
||||
.taskId(taskId)
|
||||
.singleResult();
|
||||
return task;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProcessInstance startProcessInstanceByKey(String processDefinitionKey, Map<String, Object> variables) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProcessInstance startProcessInstanceByKey(String processDefinitionKey, String businessKey, Map<String, Object> variables) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProcessInstance startProcessInstanceByKeyAndTenantId(String processDefinitionKey, String tenantId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TaskEntity> findTasksByProcessInstanceId(String processInstanceId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskEntity getTask(String id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TaskEntity> findTasksByUserId(String userId) {
|
||||
public List<Task> findTasksByUserId(String userId, TaskBaseDTO taskBaseDTO) {
|
||||
//根据用户ID获取角色
|
||||
List<SysRole> sysRoles = roleService.selectRolesByUserId(Long.parseLong(userId));
|
||||
List<Task> tasks = taskService.createTaskQuery()
|
||||
.or().taskCandidateOrAssigned(userId)
|
||||
.or().taskCandidateGroupIn(sysRoles.stream().map(SysRole::getRoleKey).collect(Collectors.toList()))
|
||||
.endOr()
|
||||
.listPage(1, 10);
|
||||
|
||||
TaskQuery taskQuery = taskService.createTaskQuery()
|
||||
.or()
|
||||
.taskCandidateOrAssigned(userId);
|
||||
if(!CollectionUtils.isEmpty(sysRoles)) {
|
||||
taskQuery.or()
|
||||
.taskCandidateGroupIn(sysRoles.stream().map(SysRole::getRoleKey).collect(Collectors.toList()));
|
||||
}
|
||||
if(!StringUtils.isEmpty(taskBaseDTO.getProcessInstanceId())){
|
||||
taskQuery.processInstanceId(taskBaseDTO.getProcessInstanceId());
|
||||
}
|
||||
if(!StringUtils.isEmpty(taskBaseDTO.getTaskId())){
|
||||
taskQuery.taskId(taskBaseDTO.getTaskId());
|
||||
}
|
||||
if(!StringUtils.isEmpty(taskBaseDTO.getBusinessKey())){
|
||||
taskQuery.processInstanceBusinessKey(taskBaseDTO.getBusinessKey());
|
||||
}
|
||||
if(StringUtils.isEmpty(taskBaseDTO.getDefinitionKey())){
|
||||
taskQuery.processDefinitionKey(taskBaseDTO.getDefinitionKey());
|
||||
}
|
||||
return taskQuery.endOr()
|
||||
.orderBy(TaskQueryProperty.CREATE_TIME)
|
||||
.listPage(taskBaseDTO.getFirstResult(),taskBaseDTO.getMaxResults());
|
||||
}
|
||||
|
||||
return null;
|
||||
@Override
|
||||
public void completeTask(CompleteTaskDTO completeTaskDTO) {
|
||||
Task task = this.getTask(completeTaskDTO.getTaskId());
|
||||
if(StringUtils.isEmpty(task)){
|
||||
log.info("完成任务时,该任务ID:%不存在",completeTaskDTO.getTaskId());
|
||||
throw new BusinessException(String.format("该任务ID:%不存在",completeTaskDTO.getTaskId()));
|
||||
}
|
||||
if(StringUtils.isEmpty(completeTaskDTO.getComment())){
|
||||
taskService.addComment(task.getId(),task.getProcessInstanceId(),completeTaskDTO.getComment());
|
||||
}
|
||||
List<FileEntry> files = completeTaskDTO.getFiles();
|
||||
if(!CollectionUtils.isEmpty(files)){
|
||||
files.stream().forEach(t->
|
||||
taskService.createAttachment("",task.getId(),task.getProcessInstanceId(),t.getKey(),t.getName(),t.getUrl())
|
||||
);
|
||||
}
|
||||
runtimeService.setVariable(task.getExecutionId(),CompleteTaskDTO.IS_PASS,completeTaskDTO.getIsPass());
|
||||
Map<String, Object> paramMap = completeTaskDTO.getParamMap();
|
||||
if(!CollectionUtils.isEmpty(paramMap)){
|
||||
Set<Map.Entry<String, Object>> entries = paramMap.entrySet();
|
||||
entries.stream().forEach(t->
|
||||
runtimeService.setVariable(task.getExecutionId(),t.getKey(),t.getValue())
|
||||
);
|
||||
}
|
||||
paramMap.put(CompleteTaskDTO.IS_PASS,completeTaskDTO.getIsPass());
|
||||
taskService.complete(task.getId(),paramMap,true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public class FlowableUserServiceImpl implements FlowableUserService {
|
|||
@Override
|
||||
public void getFlowableUserList() {
|
||||
SysUser sysUser=new SysUser();
|
||||
iSysUserService.selectAllocatedList(sysUser)
|
||||
iSysUserService.selectAllocatedList(sysUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue