add -- 添加“新建流程”页面,发起流程操作从“我的流程”页面分离。

This commit is contained in:
hewenqiang
2022-03-25 20:18:00 +08:00
parent 7005f04314
commit 581a6d8f02
11 changed files with 570 additions and 1 deletions

View File

@@ -122,7 +122,7 @@ public class WfDefinitionController extends BaseController {
return R.ok("导入成功");
}
@Deprecated
@ApiOperation(value = "根据流程定义id启动流程实例")
@SaCheckPermission("workflow:definition:start")
@PostMapping("/start/{procDefId}")

View File

@@ -0,0 +1,48 @@
package com.ruoyi.web.controller.workflow;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.JsonUtils;
import com.ruoyi.workflow.domain.vo.WfFormVo;
import com.ruoyi.workflow.service.IWfDeployFormService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
import java.util.Objects;
/**
* @author KonBAI
* @createTime 2022/3/24 20:57
*/
@Slf4j
@Api(tags = "流程部署")
@RequiredArgsConstructor
@RestController
@RequestMapping("/workflow/deploy")
public class WfDeployController extends BaseController {
private final IWfDeployFormService deployFormService;
/**
*
* @param deployId
* @return
*/
@ApiOperation(value = "查询流程部署关联表单信息")
@GetMapping("/form/{deployId}")
public R<?> start(@ApiParam(value = "流程部署id") @PathVariable(value = "deployId") String deployId) {
WfFormVo formVo = deployFormService.selectSysDeployFormByDeployId(deployId);
if (Objects.isNull(formVo)) {
return R.fail("请先配置流程表单");
}
return R.ok(JsonUtils.parseObject(formVo.getContent(), Map.class));
}
}

View File

@@ -0,0 +1,50 @@
package com.ruoyi.web.controller.workflow;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.workflow.domain.vo.WfDefinitionVo;
import com.ruoyi.workflow.service.IWfProcessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
* 工作流流程管理
*
* @author KonBAI
* @createTime 2022/3/24 18:54
*/
@Slf4j
@Api(tags = "工作流流程管理")
@RequiredArgsConstructor
@RestController
@RequestMapping("/workflow/process")
public class WfProcessController extends BaseController {
private final IWfProcessService processService;
@GetMapping(value = "/list")
@SaCheckPermission("workflow:process:startList")
@ApiOperation(value = "查询可发起流程列表", response = WfDefinitionVo.class)
public TableDataInfo<WfDefinitionVo> list(PageQuery pageQuery) {
return processService.processList(pageQuery);
}
@ApiOperation(value = "根据流程定义id启动流程实例")
@SaCheckPermission("workflow:process:start")
@PostMapping("/start/{processDefId}")
public R<Void> start(@ApiParam(value = "流程定义id") @PathVariable(value = "processDefId") String processDefId,
@ApiParam(value = "变量集合,json对象") @RequestBody Map<String, Object> variables) {
processService.startProcess(processDefId, variables);
return R.ok("流程启动成功");
}
}

View File

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

View File

@@ -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) {

View File

@@ -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("流程启动错误");
}
}
}

View File

@@ -0,0 +1,9 @@
import request from '@/utils/request'
// 查询流程部署关联表单信息
export function getFormByDeployId(deployId) {
return request({
url: '/workflow/deploy/form/' + deployId,
method: 'get',
})
}

View File

@@ -1,5 +1,24 @@
import request from '@/utils/request'
// 查询流程列表
export function listProcess(query) {
return request({
url: '/workflow/process/list',
method: 'get',
params: query
})
}
// 部署流程实例
export function startProcess(processDefId, data) {
return request({
url: '/workflow/process/start/' + processDefId,
method: 'post',
data: data
})
}
// 我的发起的流程
export function myProcessList(query) {
return request({

View File

@@ -87,11 +87,30 @@ export const constantRoutes = [
}
]
},
{
path: '/process',
component: Layout,
hidden: true,
children: [
{
path: 'start',
component: () => import('@/views/workflow/process/start'),
name: 'StartProcess',
meta: { title: '发起流程', icon: '' }
}
]
},
{
path: '/task',
component: Layout,
hidden: true,
children: [
{
path: 'process/index',
component: () => import('@/views/workflow/task/process/index'),
name: 'Record',
meta: { title: '我的流程', icon: '' }
},
{
path: 'record/index',
component: () => import('@/views/workflow/task/record/index'),

View File

@@ -0,0 +1,178 @@
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="名称" prop="name">
<el-input
v-model="queryParams.name"
placeholder="请输入名称"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="开始时间" prop="deployTime">
<el-date-picker clearable size="small"
v-model="queryParams.deployTime"
type="date"
value-format="yyyy-MM-dd"
placeholder="选择时间">
</el-date-picker>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" fit :data="processList">
<el-table-column label="序号" type="index" width="50"></el-table-column>
<el-table-column label="流程标识" align="center" prop="processKey" :show-overflow-tooltip="true" />
<el-table-column label="流程名称" align="center" :show-overflow-tooltip="true">
<template slot-scope="scope">
<el-button type="text" @click="handleProcessView(scope.row)">
<span>{{ scope.row.processName }}</span>
</el-button>
</template>
</el-table-column>
<el-table-column label="流程分类" align="center" prop="categoryName">
<template slot-scope="scope">
<span>{{ categoryOptions.find(k => k.code === scope.row.category).categoryName }}</span>
</template>
</el-table-column>
<el-table-column label="流程版本" align="center">
<template slot-scope="scope">
<el-tag size="medium" >v{{ scope.row.version }}</el-tag>
</template>
</el-table-column>
<el-table-column label="状态" align="center">
<template slot-scope="scope">
<el-tag type="success" v-if="!scope.row.suspended">激活</el-tag>
<el-tag type="warning" v-if="scope.row.suspended">挂起</el-tag>
</template>
</el-table-column>
<el-table-column label="部署时间" align="center" prop="deploymentTime" width="180"/>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
type="text"
size="mini"
icon="el-icon-video-play"
@click="handleStart(scope.row)"
v-hasPermi="['workflow:definition:designer']"
>发起</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total > 0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 流程图 -->
<el-dialog :title="processView.title" :visible.sync="processView.open" width="70%" append-to-body>
<process-viewer :key="`designer-${processView.index}`" :xml="processView.xmlData" :style="{height: '400px'}" />
</el-dialog>
</div>
</template>
<script>
import { listProcess } from "@/api/workflow/process";
import { listCategory } from '@/api/workflow/category'
import { readXml } from '@/api/workflow/definition'
import ProcessViewer from '@/components/ProcessViewer'
export default {
name: 'Process',
components: {
ProcessViewer
},
data() {
return {
// 遮罩层
loading: true,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
},
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
filterCategoryText: '',
categoryOptions: [],
categoryProps: {
label: 'categoryName',
value: 'code'
},
// 流程定义表格数据
processList: [],
processView: {
title: '',
open: false,
index: undefined,
xmlData:"",
}
}
},
created() {
this.getTreeselect();
this.getList();
},
methods: {
/** 查询流程分类列表 */
getTreeselect() {
listCategory().then(response => {
this.categoryOptions = response.rows;
})
},
/** 查询流程定义列表 */
getList() {
listProcess(this.queryParams).then(response => {
this.processList = response.rows;
this.total = response.total;
this.loading = false
})
},
// 搜索按钮操作
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
// 重置按钮操作
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
/** 查看流程图 */
handleProcessView(row) {
let definitionId = row.definitionId;
this.processView.title = "流程图";
this.processView.index = definitionId;
// 发送请求获取xml
readXml(definitionId).then(res => {
this.processView.xmlData = res.data;
this.processView.open = true;
})
},
handleStart(row) {
this.$router.push({
path: '/process/start',
query: {
definitionId: row.definitionId,
deployId: row.deploymentId,
}
})
}
}
}
</script>
<style scoped>
</style>

View File

@@ -0,0 +1,98 @@
<template>
<div class="app-container">
<el-card class="box-card">
<div slot="header" class="clearfix">
<span>发起流程</span>
<!-- <el-button style="float: right; padding: 3px 0" type="text">关闭</el-button>-->
</div>
<el-col :span="18" :offset="3">
<div class="form-conf" v-if="formOpen">
<parser :key="new Date().getTime()" :form-conf="formData" @submit="submit" ref="parser" @getData="getData"/>
</div>
</el-col>
</el-card>
</div>
</template>
<script>
import { getFormByDeployId } from '@/api/workflow/deploy'
import { startProcess } from '@/api/workflow/process'
import Parser from '@/utils/generator/parser'
export default {
name: 'StartProcess',
components: {
Parser
},
data() {
return {
formOpen: false,
formData: {}
}
},
created() {
this.definitionId = this.$route.query && this.$route.query.definitionId;
this.deployId = this.$route.query && this.$route.query.deployId;
this.getFormData(this.deployId);
},
methods: {
/** 流程流转记录 */
getFormData(deployId) {
getFormByDeployId(deployId).then(res => {
if (res.data) {
this.formData = res.data;
this.formOpen = true
}
})
},
/** 接收子组件传的值 */
getData(data) {
if (data) {
const variables = [];
data.fields.forEach(item => {
let variableData = {};
variableData.label = item.__config__.label
// 表单值为多个选项时
if (item.__config__.defaultValue instanceof Array) {
const array = [];
item.__config__.defaultValue.forEach(val => {
array.push(val)
})
variableData.val = array;
} else {
variableData.val = item.__config__.defaultValue
}
variables.push(variableData)
})
this.variables = variables;
}
},
submit(data) {
if (data) {
const variables = data.valData;
const formData = data.formData;
formData.disabled = true;
formData.formBtns = false;
if (this.definitionId) {
variables.variables = formData;
// 启动流程并将表单数据加入流程变量
startProcess(this.definitionId, JSON.stringify(variables)).then(res => {
this.$modal.msgSuccess(res.msg);
this.$router.push({
path: '/task/process/index'
})
})
}
}
}
}
}
</script>
<style lang="scss" scoped>
.form-conf {
margin: 15px auto;
width: 80%;
padding: 15px;
}
</style>