增加flowable模块

This commit is contained in:
jinqiming 2020-11-20 18:03:14 +08:00
parent 92fac2b3f7
commit b4e03795d4
12 changed files with 329 additions and 61 deletions

View File

@ -140,3 +140,20 @@ flowable:
async-executor-activate: false async-executor-activate: false
# 将databaseSchemaUpdate设置为true。当Flowable发现库与数据库表结构不一致时会自动将数据库表结构升级至新版本。 # 将databaseSchemaUpdate设置为true。当Flowable发现库与数据库表结构不一致时会自动将数据库表结构升级至新版本。
database-schema-update: true 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

View File

@ -26,10 +26,13 @@ public class DeploymentTests extends JunitTestApplication {
@Test @Test
public void createClassDeployment() throws Exception{ 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(); DeploymentDTO classDeploymentDTO=new DeploymentDTO();
classDeploymentDTO.setKey("snow_leave"); // classDeploymentDTO.setKey("snow_leave");
classDeploymentDTO.setName("请假流程"); classDeploymentDTO.setName("请假流程");
// classDeploymentDTO.setCategory("snow");
classDeploymentDTO.setResourceName("请假流程");
// classDeploymentDTO.setTenantId("snow");
// classDeploymentDTO.setClassPathResource("D:\\flowable\\leave.bpmn20.xml"); // classDeploymentDTO.setClassPathResource("D:\\flowable\\leave.bpmn20.xml");
Deployment classDeployment = flowAblePublishService.createInputStreamDeployment(classDeploymentDTO,in); Deployment classDeployment = flowAblePublishService.createInputStreamDeployment(classDeploymentDTO,in);
log.info("发布结果:{}",JSON.toJSONString(classDeployment)); log.info("发布结果:{}",JSON.toJSONString(classDeployment));

View File

@ -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));
}
}

View File

@ -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";
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -1,7 +1,10 @@
package com.snow.flowable.service; 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.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.List;
import java.util.Map; import java.util.Map;
@ -15,27 +18,27 @@ import java.util.Map;
public interface FlowableService { public interface FlowableService {
/** /**
* 通过processDefinitionKey开始流程 * 通过processDefinitionKey开始流程
* @param processDefinitionKey * @param startProcessDTO
* @return * @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);
/** /**
* 根据流程实例查询任务 * 根据任务ID获取代办
* @param processInstanceId * @param taskId
* @return * @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);
} }

View File

@ -1,5 +1,6 @@
package com.snow.flowable.service.impl; package com.snow.flowable.service.impl;
import com.snow.common.utils.StringUtils;
import com.snow.flowable.domain.ClassDeploymentDTO; import com.snow.flowable.domain.ClassDeploymentDTO;
import com.snow.flowable.domain.DeploymentDTO; import com.snow.flowable.domain.DeploymentDTO;
import com.snow.flowable.service.FlowablePublishService; 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.common.engine.impl.util.IoUtil;
import org.flowable.engine.RepositoryService; import org.flowable.engine.RepositoryService;
import org.flowable.engine.repository.Deployment; import org.flowable.engine.repository.Deployment;
import org.flowable.engine.repository.DeploymentBuilder;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -68,12 +70,18 @@ public class FlowablePublishServiceImpl implements FlowablePublishService {
@Override @Override
public Deployment createInputStreamDeployment(DeploymentDTO deploymentDTO, InputStream inputStream) { public Deployment createInputStreamDeployment(DeploymentDTO deploymentDTO, InputStream inputStream) {
Deployment deploy = repositoryService.createDeployment() DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
.tenantId(deploymentDTO.getTenantId()) if(StringUtils.isNotNull(deploymentDTO.getTenantId())){
.category(deploymentDTO.getCategory()) deploymentBuilder.tenantId(deploymentDTO.getTenantId());
.name(deploymentDTO.getName()) }
.key(deploymentDTO.getKey()) if(StringUtils.isNotNull(deploymentDTO.getCategory())){
.addInputStream(deploymentDTO.getResourceName(),inputStream) deploymentBuilder.category(deploymentDTO.getCategory());
}
if(StringUtils.isNotNull(deploymentDTO.getKey())){
deploymentBuilder.key(deploymentDTO.getKey());
}
Deployment deploy = deploymentBuilder.name(deploymentDTO.getName())
.addInputStream(deploymentDTO.getResourceName(), inputStream)
.deploy(); .deploy();
return deploy; return deploy;
} }

View File

@ -1,20 +1,31 @@
package com.snow.flowable.service.impl; 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.flowable.service.FlowableService;
import com.snow.system.domain.SysRole; import com.snow.system.domain.SysRole;
import com.snow.system.service.ISysRoleService; import com.snow.system.service.ISysRoleService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.IdentityService;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService; import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService; import org.flowable.engine.TaskService;
import org.flowable.engine.runtime.ProcessInstance; import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task; 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.flowable.task.service.impl.persistence.entity.TaskEntity;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -26,6 +37,9 @@ import java.util.stream.Collectors;
@Slf4j @Slf4j
@Service @Service
public class FlowableServiceImpl implements FlowableService { public class FlowableServiceImpl implements FlowableService {
@Autowired
private IdentityService identityService;
@Autowired @Autowired
private RuntimeService runtimeService; private RuntimeService runtimeService;
@ -35,53 +49,90 @@ public class FlowableServiceImpl implements FlowableService {
@Autowired @Autowired
private ISysRoleService roleService; private ISysRoleService roleService;
@Autowired
private RepositoryService repositoryService;
@Override @Override
public ProcessInstance startProcessInstanceByKey(String processDefinitionKey) { public ProcessInstance startProcessInstanceByKey(StartProcessDTO startProcessDTO) {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey); 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; return processInstance;
} }
@Override @Override
public ProcessInstance startProcessInstanceByKey(String processDefinitionKey, String businessKey) { public Task getTask(String taskId) {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey, businessKey); Task task = taskService.createTaskQuery()
return processInstance; .taskId(taskId)
.singleResult();
return task;
} }
@Override @Override
public ProcessInstance startProcessInstanceByKey(String processDefinitionKey, Map<String, Object> variables) { public List<Task> findTasksByUserId(String userId, TaskBaseDTO taskBaseDTO) {
return null; //根据用户ID获取角色
}
@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) {
List<SysRole> sysRoles = roleService.selectRolesByUserId(Long.parseLong(userId)); 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);
} }
} }

View File

@ -50,7 +50,7 @@ public class FlowableUserServiceImpl implements FlowableUserService {
@Override @Override
public void getFlowableUserList() { public void getFlowableUserList() {
SysUser sysUser=new SysUser(); SysUser sysUser=new SysUser();
iSysUserService.selectAllocatedList(sysUser) iSysUserService.selectAllocatedList(sysUser);
} }
@Override @Override