Activiti6---用户与用户组

1. 说明

Activiti中内置了一套用户、用户组关系,以及对它们的操作API。关于用户和用户组表工业四张,如下图:

表名含义
act_id_user身份信息-用户信息
act_id_group身份信息-组信息
act_id_info身份信息-用户扩展信息表
act_id_membership身份信息-用户和组关系的中间表

2. 用户与用户组表的介绍

1、ACT_ID_USER(用户信息表)
在这里插入图片描述
2、ACT_ID_INFO(用户扩展信息表)
在这里插入图片描述
3、ACT_ID_GROUP(用户组信息表)
在这里插入图片描述
4、ACT_ID_MEMBERSHIP(用户与用户组关系信息表)
在这里插入图片描述

3. 项目中用户和角色与Activiti中的用户、用户组整合

通常来说在项目中都已经是有了用户和角色权限功能。比如我创建了一个springboot项目,已经创建了用户表和角色表,那么如何将项目本身的用户和角色与activiti的用户、用户组整合在一起啦。

我的思路:在项目中创建了用户时,同时也需要将用户与Activiti的用户关联起来,直接通过id关联即可。

3.1 整合

	/**
     * 把自定义用户同步到activiti用户
     */
    @Test
    public void addUser(){
        List<com.yb.domain.User> all = userDao.findAll();
        for (com.yb.domain.User user : all) {
            User user1 = identityService.newUser(user.getUid()+"");
            user1.setFirstName(user.getUsername());
            user1.setPassword(user.getPassword());
            identityService.saveUser(user1);
        }

    }

    /**
     * 查询用户信息
     */
    @Test
    public void queryUser(){
        User user = identityService.createUserQuery()
                .userId("1")
                .singleResult();
        System.out.println(user.getFirstName());
    }

    /**
     * 创建activiti用户组
     */
    @Test
    public void addGroup(){
        Group group1 = identityService.newGroup("group1");
        group1.setName("主管组");
        group1.setType("主管组");
        identityService.saveGroup(group1);

        Group group2 = identityService.newGroup("group2");
        group2.setName("总监组");
        group2.setType("总监组");
        identityService.saveGroup(group2);

        Group group3 = identityService.newGroup("group3");
        group3.setName("项目经理组");
        group3.setType("项目经理组");
        identityService.saveGroup(group3);


        Group group4 = identityService.newGroup("group4");
        group4.setName("员工组");
        group4.setType("员工组");
        identityService.saveGroup(group4);

        Group group5 = identityService.newGroup("group5");
        group5.setName("人力资源组");
        group5.setType("人力资源组");
        identityService.saveGroup(group5);

    }

    /**
     * 查询用户组
     */
    @Test
    public void queryGroup( ){
        Group group = identityService.createGroupQuery()
                .groupId("group1")
                .singleResult();
        System.out.println(group.getId());
        System.out.println(group.getName());
        System.out.println(group.getType());

    }

    /**
     * 创建用户-用户组之间的关系
     */
    @Test
    public void addMembership( ){
        identityService.createMembership("1", "group4");
        identityService.createMembership("3", "group3");
        identityService.createMembership("4", "group3");
        identityService.createMembership("5", "group3");
        identityService.createMembership("6", "group5");
    }

    /**
     * 查询属于用户组group3的用户
     */
    @Test
    public void queryUserListByGroup( ){

        //查询属于组group1的用户
        List<User> usersInGroup = identityService.createUserQuery()
                .memberOfGroup("group3")
                .list();
        for (User user : usersInGroup) {
            System.out.println(user.getFirstName());
        }

    }

数据库:
用户表
在这里插入图片描述
中间表
在这里插入图片描述
用户组表
在这里插入图片描述

3.2 测试

流程图
在这里插入图片描述
Bpmn文件
可以看到设置项目经理审批节点的组为’group3’,也就是项目经理组,属于这个组的人员都可以进行审批

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" xmlns:tns="http://www.activiti.org/test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" expressionLanguage="http://www.w3.org/1999/XPath" id="m1597729482723" name="" targetNamespace="http://www.activiti.org/test" typeLanguage="http://www.w3.org/2001/XMLSchema">
  <process id="parallel" isClosed="false" isExecutable="true" processType="None">
    <startEvent id="_2" name="开始"/>
    <userTask activiti:candidateGroups="group3" activiti:exclusive="true" id="_3" name="项目经理审批"/>
    <parallelGateway gatewayDirection="Unspecified" id="_4" name="ParallelGateway"/>
    <userTask activiti:assignee="user2" activiti:exclusive="true" id="_5" name="上级领导审批"/>
    <userTask activiti:assignee="user3" activiti:exclusive="true" id="_6" name="董事长审批"/>
    <userTask activiti:assignee="user4" activiti:exclusive="true" id="_7" name="主管审批"/>
    <userTask activiti:assignee="user5" activiti:exclusive="true" id="_8" name="总监审批"/>
    <parallelGateway gatewayDirection="Unspecified" id="_9" name="ParallelGateway"/>
    <endEvent id="_10" name="结束"/>
    <sequenceFlow id="_11" sourceRef="_2" targetRef="_3"/>
    <sequenceFlow id="_12" sourceRef="_3" targetRef="_4"/>
    <sequenceFlow id="_13" sourceRef="_4" targetRef="_5"/>
    <sequenceFlow id="_14" sourceRef="_4" targetRef="_7"/>
    <sequenceFlow id="_15" sourceRef="_5" targetRef="_6"/>
    <sequenceFlow id="_16" sourceRef="_7" targetRef="_8"/>
    <sequenceFlow id="_17" sourceRef="_6" targetRef="_9"/>
    <sequenceFlow id="_18" sourceRef="_8" targetRef="_9"/>
    <sequenceFlow id="_19" sourceRef="_9" targetRef="_10"/>
  </process>
  <bpmndi:BPMNDiagram documentation="background=#000000;count=1;horizontalcount=1;orientation=0;width=842.4;height=1195.2;imageableWidth=832.4;imageableHeight=1185.2;imageableX=5.0;imageableY=5.0" id="Diagram-_1" name="New Diagram">
    <bpmndi:BPMNPlane bpmnElement="parallel">
      <bpmndi:BPMNShape bpmnElement="_2" id="Shape-_2">
        <omgdc:Bounds height="32.0" width="32.0" x="285.0" y="-10.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_3" id="Shape-_3">
        <omgdc:Bounds height="55.0" width="85.0" x="260.0" y="60.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_4" id="Shape-_4">
        <omgdc:Bounds height="32.0" width="32.0" x="285.0" y="145.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_5" id="Shape-_5">
        <omgdc:Bounds height="55.0" width="85.0" x="190.0" y="265.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_6" id="Shape-_6">
        <omgdc:Bounds height="55.0" width="85.0" x="190.0" y="405.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_7" id="Shape-_7">
        <omgdc:Bounds height="55.0" width="85.0" x="335.0" y="265.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_8" id="Shape-_8">
        <omgdc:Bounds height="55.0" width="85.0" x="335.0" y="405.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_9" id="Shape-_9">
        <omgdc:Bounds height="32.0" width="32.0" x="290.0" y="530.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_10" id="Shape-_10">
        <omgdc:Bounds height="32.0" width="32.0" x="290.0" y="645.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="_13" id="BPMNEdge__13" sourceElement="_4" targetElement="_5">
        <omgdi:waypoint x="285.0" y="161.0"/>
        <omgdi:waypoint x="235.0" y="230.0"/>
        <omgdi:waypoint x="235.0" y="265.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_12" id="BPMNEdge__12" sourceElement="_3" targetElement="_4">
        <omgdi:waypoint x="301.0" y="115.0"/>
        <omgdi:waypoint x="301.0" y="145.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_15" id="BPMNEdge__15" sourceElement="_5" targetElement="_6">
        <omgdi:waypoint x="232.5" y="320.0"/>
        <omgdi:waypoint x="232.5" y="405.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_14" id="BPMNEdge__14" sourceElement="_4" targetElement="_7">
        <omgdi:waypoint x="317.0" y="161.0"/>
        <omgdi:waypoint x="375.0" y="225.0"/>
        <omgdi:waypoint x="375.0" y="265.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_17" id="BPMNEdge__17" sourceElement="_6" targetElement="_9">
        <omgdi:waypoint x="235.0" y="460.0"/>
        <omgdi:waypoint x="235.0" y="490.0"/>
        <omgdi:waypoint x="290.0" y="546.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_16" id="BPMNEdge__16" sourceElement="_7" targetElement="_8">
        <omgdi:waypoint x="377.5" y="320.0"/>
        <omgdi:waypoint x="377.5" y="405.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_19" id="BPMNEdge__19" sourceElement="_9" targetElement="_10">
        <omgdi:waypoint x="306.0" y="562.0"/>
        <omgdi:waypoint x="306.0" y="645.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_18" id="BPMNEdge__18" sourceElement="_8" targetElement="_9">
        <omgdi:waypoint x="380.0" y="460.0"/>
        <omgdi:waypoint x="380.0" y="490.0"/>
        <omgdi:waypoint x="322.0" y="546.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_11" id="BPMNEdge__11" sourceElement="_2" targetElement="_3">
        <omgdi:waypoint x="301.0" y="22.0"/>
        <omgdi:waypoint x="301.0" y="60.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

测试类

/**
     * 部署流程,测试用户组审批
     */
    @Test
    public void repositoryDeploy(){
        Deployment deploy = repositoryService.createDeployment()
                .addClasspathResource("processes/activiti_ParallelFallback.bpmn")
                .addClasspathResource("processes/activiti_ParallelFallback.png")
                .name("测试用户组审批-1")
                .deploy();
        System.out.println("部署ID:"+deploy.getId());
        System.out.println("部署名称"+deploy.getName());
    }

    /**
     * 发布流程
     */
    @Test
    public void runtimeRelease(){

        ProcessInstance pi = runtimeService.startProcessInstanceByKey("parallel");
        System.out.println("流程实例ID:"+pi.getId());
        System.out.println("流程定义ID:"+pi.getProcessDefinitionId());
    }

    /**
     * 查询及完成任务
     */
    @Test
    public void taskQueryComplete(){
        List<Task> list = taskService.createTaskQuery()
                .taskName("项目经理审批")
                .list();
        for (Task task : list) {
            System.out.println("--------------------------------------------");
            System.out.println("任务ID:" + task.getId());
            System.out.println("任务名称:" + task.getName());
            System.out.println("任务创建时间:" + task.getCreateTime());
            System.out.println("任务委派人:" + task.getAssignee());
            System.out.println("流程实例ID:" + task.getProcessInstanceId());
            System.out.println("--------------------------------------------");
//            taskService.complete(task.getId());
            List<IdentityLink> identityLinksForTask = taskService.getIdentityLinksForTask(task.getId());
            for (IdentityLink identityLink : identityLinksForTask) {
                System.out.println(identityLink.getGroupId());
                //查询属于组group3(项目经理子)的用户
                List<User> usersInGroup = identityService.createUserQuery()
                        .memberOfGroup(identityLink.getGroupId())
                        .list();
                for (User user : usersInGroup) {
                    System.out.println(user.getFirstName());
//                    这一步可根据当前登录的用户判断是否属于项目经理组,属于,就可以为此分配任务
                    if(user.getFirstName().equals("王二")){

                        taskService.claim(task.getId(),user.getFirstName());
                    }

                }
            }

        }


    }

    /**
     * 拾取任务还可以回退给用户组
     */
    @Test
    public void test01(){
        //此方式如果有审批人拾取到任务不想审批,可以回退给用户组,让其他人审批
        Task task = taskService.createTaskQuery()
                .taskName("项目经理审批")
                .singleResult();
        taskService.setAssignee(task.getId(),null);
    }

    /**
     * 完成任务
     */
    @Test
    public void test02(){
        Task task = taskService.createTaskQuery()
                .taskAssignee("王二")
                .singleResult();
        taskService.complete(task.getId());
    }

效果:

所有属于项目经理组的人员都可以看到项目经理审批任务,只需一个人审批通过即可完成该任务,下图是任务完成后走向了并行流程。
在这里插入图片描述

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: ruoyi-activiti是一个流程引擎平台,是ruoyi框架中的一个模块。它基于Activiti 6.x版本开发,是一个轻量级、易用性强的工作流引擎。它在ruoyi框架中担任着流程管理和流程任务分配的角色,帮助企业或机构简化了日常业务流程,提高了工作效率。 ruoyi-activiti提供了丰富的功能。其中包括:流程设计器、流程监控、用户任务管理、流程部署、流程挂起、历史流程查询等功能。用户可以通过流程设计器设计出符合企业实际业务的流程,也可以通过流程监控及时了解流程运行状态。用户任务管理功能可以帮助管理员快速分配任务,监管任务进度。流程部署功能可以将设计好的流程部署到服务器中。流程挂起则可以帮助管理员停止不需要执行的流程。历史流程查询功能可以让用户查看已完成的流程,方便以后的参考和分析。 总之,ruoyi-activiti是一个高效便捷的流程引擎平台,它的出现对于企业或机构的业务流程管理有着非常大的帮助,未来也会在业界中有着更广泛的应用。 ### 回答2: Ruoyi-activiti是一款基于Ruoyi框架的工作流管理系统。它集成了Activiti工作流引擎,提供了流程设计、流程部署、流程运行监控、流程催办、任务分配、流程驳回、任务委派等功能。 Ruoyi-activiti可以帮助企业更好地管理和优化业务流程,提高流程处理效率和管理水平。它可以通过流程图形化设计工具快速创建复杂流程,并且可以使用流程设计器实时预览和调试流程。在流程运行期间,用户可以根据实际情况对流程进行调整和修改,从而保证流程的灵活性和适应性。另外,Ruoyi-activiti还提供了丰富的统计报表和数据分析功能,方便用户进行数据的分析和管理。 总之,Ruoyi-activiti是一款功能强大、易于使用、性能优秀的工作流管理系统。它的使用可以帮助企业更好地管理流程,提高管理效率和管理质量,让企业更加高效地运转。 ### 回答3: ruoyi-activiti是一款基于Activiti引擎的业务流程管理系统,它是ruoyi-admin的衍生项目。用户可以在ruoyi-activiti中方便地定义和管理工作流程、任务、用户用户组、角色、表单等元素,同时支持动态设计、部署和启动业务流程。此外,ruoyi-activiti还提供了丰富的报表和数据统计功能,用户可以直观地了解工作流程的运行情况,从而对流程进行优化和改进。此外,ruoyi-activiti还支持消息提醒和审核日志等功能,提高了工作效率和透明度。总之,ruoyi-activiti是一个功能强大、易于使用和可扩展的业务流程管理系统,具有广泛的应用前景。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值