10 changed files with 151 additions and 15 deletions
@ -0,0 +1,50 @@ |
|||
package com.qs.serve.modules.bpm.service; |
|||
|
|||
import com.qs.serve.modules.bpm.entity.dto.FlowProcDefDto; |
|||
|
|||
import java.util.Map; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 流程定义服务 |
|||
* @author YenHex |
|||
* @since 2022/8/22 |
|||
*/ |
|||
public interface IFlowDefinitionService { |
|||
|
|||
/** |
|||
* 流程定义列表 |
|||
* @param procDefName |
|||
* @return |
|||
*/ |
|||
List<FlowProcDefDto> list(String procDefName); |
|||
|
|||
/** |
|||
* 检查流程实例是否存在 |
|||
* @param processDefinitionKey |
|||
* @return |
|||
*/ |
|||
boolean exist(String processDefinitionKey); |
|||
|
|||
/** |
|||
* 根据流程定义ID启动流程实例 |
|||
* @param procDefId |
|||
* @param variables |
|||
* @return |
|||
*/ |
|||
void startProcessInstanceById(String procDefId, Map<String, Object> variables); |
|||
|
|||
/** |
|||
* 激活或挂起流程定义 |
|||
* @param state 状态: 1=激活 ;2=挂起 |
|||
* @param deployId 流程部署ID |
|||
*/ |
|||
void updateState(Integer state, String deployId); |
|||
|
|||
/** |
|||
* 删除流程定义 |
|||
* @param deployId 流程部署ID act_ge_bytearray 表中 deployment_id值 |
|||
*/ |
|||
void delete(String deployId); |
|||
|
|||
} |
@ -0,0 +1,84 @@ |
|||
package com.qs.serve.modules.bpm.service.impl; |
|||
|
|||
import com.qs.serve.common.util.Assert; |
|||
import com.qs.serve.modules.bpm.common.consts.ProcessConstants; |
|||
import com.qs.serve.modules.bpm.common.enums.FlowComment; |
|||
import com.qs.serve.modules.bpm.conf.FlowServiceFactory; |
|||
import com.qs.serve.modules.bpm.entity.dto.FlowProcDefDto; |
|||
import com.qs.serve.modules.bpm.mapper.FlowDeployMapper; |
|||
import com.qs.serve.modules.bpm.service.IFlowDefinitionService; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.flowable.engine.repository.ProcessDefinition; |
|||
import org.flowable.engine.repository.ProcessDefinitionQuery; |
|||
import org.flowable.engine.runtime.ProcessInstance; |
|||
import org.flowable.task.api.Task; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.Objects; |
|||
|
|||
/** |
|||
* @author YenHex |
|||
* @since 2022/8/22 |
|||
*/ |
|||
@Slf4j |
|||
@Service |
|||
@AllArgsConstructor |
|||
public class IFlowDefinitionServiceImpl extends FlowServiceFactory implements IFlowDefinitionService { |
|||
|
|||
private final FlowDeployMapper flowDeployMapper; |
|||
|
|||
@Override |
|||
public List<FlowProcDefDto> list(String procDefName) { |
|||
return flowDeployMapper.selectDeployList(procDefName); |
|||
} |
|||
|
|||
@Override |
|||
public boolean exist(String processDefinitionKey) { |
|||
ProcessDefinitionQuery processDefinitionQuery |
|||
= repositoryService.createProcessDefinitionQuery().processDefinitionKey(processDefinitionKey); |
|||
long count = processDefinitionQuery.count(); |
|||
return count > 0; |
|||
} |
|||
|
|||
@Override |
|||
public void startProcessInstanceById(String procDefId, Map<String, Object> variables) { |
|||
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(procDefId) |
|||
.latestVersion().singleResult(); |
|||
if (Objects.nonNull(processDefinition) && processDefinition.isSuspended()) { |
|||
Assert.throwEx("流程已被挂起,请先激活流程"); |
|||
} |
|||
// variables.put("skip", true);
|
|||
// variables.put(ProcessConstants.FLOWABLE_SKIP_EXPRESSION_ENABLED, true);
|
|||
// 设置流程发起人Id到流程中
|
|||
identityService.setAuthenticatedUserId("TODO"); |
|||
variables.put(ProcessConstants.PROCESS_INITIATOR, ""); |
|||
ProcessInstance processInstance = runtimeService.startProcessInstanceById(procDefId, variables); |
|||
// 给第一步申请人节点设置任务执行人和意见 todo:第一个节点不设置为申请人节点有点问题?
|
|||
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getProcessInstanceId()).singleResult(); |
|||
if (Objects.nonNull(task)) { |
|||
taskService.addComment(task.getId(), processInstance.getProcessInstanceId(), FlowComment.NORMAL.getType(), "sysUser.getNickName()发起流程申请"); |
|||
// taskService.setAssignee(task.getId(), sysUser.getUserId().toString());
|
|||
taskService.complete(task.getId(), variables); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void updateState(Integer state, String deployId) { |
|||
ProcessDefinition procDef = repositoryService.createProcessDefinitionQuery().deploymentId(deployId).singleResult(); |
|||
if (state == 1) { |
|||
repositoryService.activateProcessDefinitionById(procDef.getId(), true, null); |
|||
} |
|||
if (state == 2) { |
|||
repositoryService.suspendProcessDefinitionById(procDef.getId(), true, null); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void delete(String deployId) { |
|||
// true 允许级联删除 ,不设置会导致数据库外键关联异常
|
|||
repositoryService.deleteDeployment(deployId, true); |
|||
} |
|||
} |
Loading…
Reference in new issue