在ruoyi-flowable-plus-0.8.X-vform审批流程中动态设置审批人为发起人的部门经理

本文介绍了如何在RuoyiUI中修改审批人设置,新增自定义监听器功能,如DeptLeaderTaskListener,通过Java代码实现在流程实例中根据发起人自动设置部门经理为审批人。开发者还展示了如何在流程中选择并配置监听器来实现多人审批机制。
摘要由CSDN通过智能技术生成

我摸索后测试这样是可行的

1、修改前端“审批人设置”,新增自定义,如下图

文件路径:ruoyi-ui/src/plugins/package/penal/task/task-components/UserTask.vue

1、
        <el-radio label="LISTENER">监听器指定</el-radio>


2、
        else if (val === 'LISTENER') {
        // userTaskForm.assignee = "${assignee}"; //设置单个审批人
        userTaskForm.candidateUsers = "${candidateUsers}"; //可以指定多个审批人
        userTaskForm.text = "监听器指定";
      }

2、配置测试监听器DeptLeaderTaskListener,我将监听器放在了system模块,因为要调用一些类。

package com.ruoyi.workflow.listener;


import cn.hutool.extra.spring.SpringUtil;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.mapper.SysUserMapper;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 动态指定部门经理审批监听器
 */
@Component
public class DeptLeaderTaskListener implements ExecutionListener {

    @Override
    public void notify(DelegateExecution execution) {
//        获取发起人id
        ProcessInstance processInstance = SpringUtil.getBean(RuntimeService.class)
            .createProcessInstanceQuery()
            .processInstanceId(execution.getProcessInstanceId())
            .singleResult();
        String startUserId = processInstance.getStartUserId();

//    根据具体情况修改
        SysUserMapper userMapper = SpringUtil.getBean(SysUserMapper.class);
//        根据发起人id查询本部门的经理id
        List<SysUser> leaders = userMapper.getLeaderById(Long.valueOf(startUserId));


        List<String> ids = leaders.stream()
            .map(SysUser::getUserId) // 提取 SysUser 对象的 id 属性
            .map(String::valueOf) // 将 id 转换为字符串
            .collect(Collectors.toList()); // 将结果收集到 List<String> 中

        execution.setVariable("candidateUsers", ids); // 将计算得到的审批人设置为流程变量,多人审批只需一人通过就可以进行下一节点的审批流程
// 也可以使用assignee
        System.out.println("动态指定部门经理审批监听器执行完成");
    }

}

3、创建流程

选择要使用监听器的节点,选择自定义的审批人设置,点击添加监听器,如下图

  • 5
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 11
    评论
首先需要确保你的Vue项目已经创建完成并且可以正常运行。 接下来,你可以按照以下步骤将RuoYi-Flowable-Plus项目的工作流引入到你的Vue项目: 1. 打开RuoYi-Flowable-Plus项目并进入到`ruoyi-flowable-web`模块,使用Maven编译并打包生成`ruoyi-flowable-web.jar`文件。 2. 将`ruoyi-flowable-web.jar`文件拷贝到你的Vue项目的`src/main/resources/lib`目录下。 3. 在你的Vue项目的`package.json`文件添加如下依赖: ```json "dependencies": { "axios": "^0.19.2", "element-ui": "^2.13.2", "vue": "^2.6.11", "vue-router": "^3.1.6", "vuex": "^3.1.3", "vue-cli-plugin-ruby": "^0.1.3", "ruoyi-flowable-web": "file:./src/main/resources/lib/ruoyi-flowable-web.jar" }, ``` 注意:`ruoyi-flowable-web`的版本号需要根据你的实际情况进行修改。 4. 在你的Vue项目的`vue.config.js`文件添加如下配置: ```javascript module.exports = { configureWebpack: { resolve: { alias: { 'ruoyi-flowable-web': 'ruoyi-flowable-web' } }, module: { rules: [ { test: /\.jar$/, loader: 'jar-loader' } ] } } } ``` 5. 在你的Vue项目的`main.js`文件引入`ruoyi-flowable-web`: ```javascript import 'ruoyi-flowable-web' ``` 6. 在你的Vue项目的某个组件使用工作流组件: ```vue <template> <div> <h1>工作流组件</h1> <ruoyi-flowable></ruoyi-flowable> </div> </template> <script> export default { name: 'WorkflowComponent' } </script> ``` 通过以上步骤,你就可以在你的Vue项目使用RuoYi-Flowable-Plus项目的工作流组件了。当然,具体的使用方法还需要根据实际情况进行调整。
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值