add -- 添加“新建流程”页面,发起流程操作从“我的流程”页面分离。
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package com.ruoyi.workflow.service;
|
||||
|
||||
import com.ruoyi.common.core.domain.PageQuery;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.workflow.domain.vo.WfDefinitionVo;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author KonBAI
|
||||
* @createTime 2022/3/24 18:57
|
||||
*/
|
||||
public interface IWfProcessService {
|
||||
|
||||
/**
|
||||
* 查询可发起流程列表
|
||||
* @param pageQuery 分页参数
|
||||
* @return
|
||||
*/
|
||||
TableDataInfo<WfDefinitionVo> processList(PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 启动流程实例
|
||||
* @param procDefId 流程定义ID
|
||||
* @param variables 扩展参数
|
||||
*/
|
||||
void startProcess(String procDefId, Map<String, Object> variables);
|
||||
}
|
||||
@@ -203,6 +203,7 @@ public class WfDefinitionServiceImpl extends FlowServiceFactory implements IWfDe
|
||||
* @param variables 流程变量
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void startProcessInstanceById(String procDefId, Map<String, Object> variables) {
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
package com.ruoyi.workflow.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.ruoyi.common.core.domain.PageQuery;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.helper.LoginHelper;
|
||||
import com.ruoyi.flowable.common.constant.ProcessConstants;
|
||||
import com.ruoyi.flowable.common.enums.FlowComment;
|
||||
import com.ruoyi.flowable.factory.FlowServiceFactory;
|
||||
import com.ruoyi.workflow.domain.vo.WfDefinitionVo;
|
||||
import com.ruoyi.workflow.service.IWfProcessService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.flowable.engine.repository.Deployment;
|
||||
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 org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author KonBAI
|
||||
* @createTime 2022/3/24 18:57
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProcessService {
|
||||
|
||||
/**
|
||||
* 流程定义列表
|
||||
*
|
||||
* @param pageQuery 分页参数
|
||||
* @return 流程定义分页列表数据
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<WfDefinitionVo> processList(PageQuery pageQuery) {
|
||||
Page<WfDefinitionVo> page = new Page<>();
|
||||
// 流程定义列表数据查询
|
||||
ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery()
|
||||
.latestVersion()
|
||||
.active()
|
||||
.orderByProcessDefinitionKey()
|
||||
.asc();
|
||||
long pageTotal = processDefinitionQuery.count();
|
||||
if (pageTotal <= 0) {
|
||||
return TableDataInfo.build();
|
||||
}
|
||||
int offset = pageQuery.getPageSize() * (pageQuery.getPageNum() - 1);
|
||||
List<ProcessDefinition> definitionList = processDefinitionQuery.listPage(offset, pageQuery.getPageSize());
|
||||
|
||||
List<WfDefinitionVo> definitionVoList = new ArrayList<>();
|
||||
for (ProcessDefinition processDefinition : definitionList) {
|
||||
String deploymentId = processDefinition.getDeploymentId();
|
||||
Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult();
|
||||
WfDefinitionVo vo = new WfDefinitionVo();
|
||||
vo.setDefinitionId(processDefinition.getId());
|
||||
vo.setProcessKey(processDefinition.getKey());
|
||||
vo.setProcessName(processDefinition.getName());
|
||||
vo.setVersion(processDefinition.getVersion());
|
||||
vo.setCategory(processDefinition.getCategory());
|
||||
vo.setDeploymentId(processDefinition.getDeploymentId());
|
||||
vo.setSuspended(processDefinition.isSuspended());
|
||||
// 流程定义时间
|
||||
vo.setCategory(deployment.getCategory());
|
||||
vo.setDeploymentTime(deployment.getDeploymentTime());
|
||||
definitionVoList.add(vo);
|
||||
}
|
||||
page.setRecords(definitionVoList);
|
||||
page.setTotal(pageTotal);
|
||||
return TableDataInfo.build(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据流程定义ID启动流程实例
|
||||
*
|
||||
* @param procDefId 流程定义Id
|
||||
* @param variables 流程变量
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void startProcess(String procDefId, Map<String, Object> variables) {
|
||||
try {
|
||||
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
|
||||
.processDefinitionId(procDefId).singleResult();
|
||||
if (Objects.nonNull(processDefinition) && processDefinition.isSuspended()) {
|
||||
throw new ServiceException("流程已被挂起,请先激活流程");
|
||||
}
|
||||
// variables.put("skip", true);
|
||||
// variables.put(ProcessConstants.FLOWABLE_SKIP_EXPRESSION_ENABLED, true);
|
||||
// 设置流程发起人Id到流程中
|
||||
String userIdStr = LoginHelper.getUserId().toString();
|
||||
identityService.setAuthenticatedUserId(userIdStr);
|
||||
variables.put(ProcessConstants.PROCESS_INITIATOR, userIdStr);
|
||||
ProcessInstance processInstance = runtimeService.startProcessInstanceById(procDefId, variables);
|
||||
// 给第一步申请人节点设置任务执行人和意见 todo:第一个节点不设置为申请人节点有点问题?
|
||||
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getProcessInstanceId()).singleResult();
|
||||
if (Objects.nonNull(task)) {
|
||||
if (!StrUtil.equalsAny(task.getAssignee(), userIdStr)) {
|
||||
throw new ServiceException("数据验证失败,该工作流第一个用户任务的指派人并非当前用户,不能执行该操作!");
|
||||
}
|
||||
taskService.addComment(task.getId(), processInstance.getProcessInstanceId(), FlowComment.NORMAL.getType(), LoginHelper.getNickName() + "发起流程申请");
|
||||
// taskService.setAssignee(task.getId(), userIdStr);
|
||||
taskService.complete(task.getId(), variables);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ServiceException("流程启动错误");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user