学习记录554@flowable候选人组机制

本文介绍了Flowable流程引擎中如何处理候选人组,通过示例展示了创建用户、用户组及两者关系,并详细解释了如何领取、完成、归还和移交任务的操作。流程图显示了一个简单的审批流程,涉及到业务人员组和风控人员组的角色分配。在实际开发中,需要将企业内部的用户、角色和部门信息同步到Flowable的相关表中,以便于流程的正确执行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

候选人比较多的时候就需要用到候选人组了,类似于实际工作中的什么角色或者部门的人审批什么节点。
需要再flowable独有的用户表、用户组表、两者的关联表中同步自己业务系统的数据。act_id_user、act_id_group、act_id_membership

流程

在这里插入图片描述

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:flowable="http://flowable.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" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.flowable.org/processdef" exporter="Flowable Open Source Modeler" exporterVersion="6.7.2">
  <process id="shenpi1" name="审批1" isExecutable="true">
    <startEvent id="startEvent1" flowable:formFieldValidation="true"></startEvent>
    <userTask id="sid-B0A762DE-D600-4998-96D6-49F7BE676159" name="创建审批单" flowable:candidateGroups="${业务人员组}" flowable:formFieldValidation="true"></userTask>
    <sequenceFlow id="sid-0129BF6A-C57C-4383-A14C-879FD48EED4E" sourceRef="startEvent1" targetRef="sid-B0A762DE-D600-4998-96D6-49F7BE676159"></sequenceFlow>
    <userTask id="sid-3808E689-1750-4D10-BFDE-18F41AAF3CB5" name="风控审批" flowable:candidateGroups="${风控人员组}" flowable:formFieldValidation="true"></userTask>
    <sequenceFlow id="sid-3349C437-5FF2-4565-B2CD-75CCA54FAF03" sourceRef="sid-B0A762DE-D600-4998-96D6-49F7BE676159" targetRef="sid-3808E689-1750-4D10-BFDE-18F41AAF3CB5"></sequenceFlow>
    <endEvent id="sid-80CB6AF8-5DD5-4AC1-A1B2-05A5569B402D"></endEvent>
    <sequenceFlow id="sid-AD80B163-B8F0-4472-80D0-C9074FB69CC4" sourceRef="sid-3808E689-1750-4D10-BFDE-18F41AAF3CB5" targetRef="sid-80CB6AF8-5DD5-4AC1-A1B2-05A5569B402D"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_shenpi1">
    <bpmndi:BPMNPlane bpmnElement="shenpi1" id="BPMNPlane_shenpi1">
      <bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1">
        <omgdc:Bounds height="30.0" width="30.0" x="100.0" y="163.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-B0A762DE-D600-4998-96D6-49F7BE676159" id="BPMNShape_sid-B0A762DE-D600-4998-96D6-49F7BE676159">
        <omgdc:Bounds height="80.0" width="100.0" x="225.0" y="135.00000216744158"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-3808E689-1750-4D10-BFDE-18F41AAF3CB5" id="BPMNShape_sid-3808E689-1750-4D10-BFDE-18F41AAF3CB5">
        <omgdc:Bounds height="80.0" width="100.00000000000006" x="423.00000899488253" y="135.00000216744158"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-80CB6AF8-5DD5-4AC1-A1B2-05A5569B402D" id="BPMNShape_sid-80CB6AF8-5DD5-4AC1-A1B2-05A5569B402D">
        <omgdc:Bounds height="28.0" width="28.0" x="568.0000089948826" y="161.00000216744158"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sid-3349C437-5FF2-4565-B2CD-75CCA54FAF03" id="BPMNEdge_sid-3349C437-5FF2-4565-B2CD-75CCA54FAF03" flowable:sourceDockerX="50.0" flowable:sourceDockerY="40.0" flowable:targetDockerX="50.000000000000036" flowable:targetDockerY="40.0">
        <omgdi:waypoint x="324.95000000000005" y="175.00000216744158"></omgdi:waypoint>
        <omgdi:waypoint x="423.00000899488253" y="175.00000216744158"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-AD80B163-B8F0-4472-80D0-C9074FB69CC4" id="BPMNEdge_sid-AD80B163-B8F0-4472-80D0-C9074FB69CC4" flowable:sourceDockerX="50.000000000000036" flowable:sourceDockerY="40.0" flowable:targetDockerX="14.0" flowable:targetDockerY="14.0">
        <omgdi:waypoint x="522.9500089948785" y="175.00000216744158"></omgdi:waypoint>
        <omgdi:waypoint x="568.0000089948826" y="175.00000216744158"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-0129BF6A-C57C-4383-A14C-879FD48EED4E" id="BPMNEdge_sid-0129BF6A-C57C-4383-A14C-879FD48EED4E" flowable:sourceDockerX="15.0" flowable:sourceDockerY="15.0" flowable:targetDockerX="50.0" flowable:targetDockerY="40.0">
        <omgdi:waypoint x="129.94742557455893" y="177.71879863507866"></omgdi:waypoint>
        <omgdi:waypoint x="225.0" y="175.9365639907934"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

在这里插入图片描述

添加用户和组,以及两者的关系

实际开发中,可将本身的用户表、角色表、部门表以及之间的关系同步到flowable的act_id_user、act_id_group、act_id_membership表中
其中角色和部门可当作组

@Transactional
    public void addGroupAndUser() {

        //实际开发中,可将本身的用户表、角色表、部门表以及之间的关系同步到flowable的act_id_user、act_id_group、act_id_membership表中
        //其中角色和部门可当作组
        User user1 = identityService.newUser("樱木花道1");
        user1.setFirstName("樱木");
        user1.setLastName("花道1");
        identityService.saveUser(user1);//注意必须这样保存

        User user2 =identityService.newUser("樱木花道2");
        user2.setFirstName("樱木");
        user2.setLastName("花道2");
        identityService.saveUser(user2);//注意必须这样保存

        User user3 =identityService.newUser("三井寿1");
        user3.setFirstName("三井");
        user3.setLastName("寿1");
        identityService.saveUser(user3);//注意必须这样保存

        User user4 =identityService.newUser("三井寿2");
        user4.setFirstName("三井");
        user4.setLastName("寿2");
        identityService.saveUser(user4);//注意必须这样保存

        Group group1 = identityService.newGroup("业务人员组");
        group1.setName("业务员");
        identityService.saveGroup(group1);//注意必须这样保存

        Group group2 = identityService.newGroup("风控人员组");
        group2.setName("风控员");
        identityService.saveGroup(group2);//注意必须这样保存

        //创建关联关系
        identityService.createMembership("樱木花道1","业务人员组");
        identityService.createMembership("樱木花道2","业务人员组");
        identityService.createMembership("三井寿1","风控人员组");
        identityService.createMembership("三井寿2","风控人员组");
    }

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

领取任务、归还任务、移交任务、完成任务

原理和候选人机制类似,底层也是改变act_ru_task表中ASSIGNEE_字段,这里就不多叙述了。

//领取任务,act_ru_task表中ASSIGNEE_字段之前为空,谁领取就变成谁。
    @Transactional
    public void claimTask() {

        //根据当前用户樱木花道1获取所在的组
        Group group = identityService.createGroupQuery().groupMember("樱木花道1").singleResult();
        //根据组查询任务
        Task task = taskService.createTaskQuery().processInstanceId("4279f082-b22e-11ec-8d53-3c9c0f202230").taskCandidateGroup(group.getId()).singleResult();
        if (task != null){
            taskService.claim(task.getId(),"樱木花道1");//领取任务
            System.out.println(task.getAssignee());
        }
    }
//    完成任务
    @Transactional
    public void completeTask() {
        Task task = taskService.createTaskQuery().processInstanceId("4279f082-b22e-11ec-8d53-3c9c0f202230").taskAssignee("樱木花道1").singleResult();
        if (task != null){
            taskService.complete(task.getId());
        }
    }
    //归还任务,act_ru_task表中ASSIGNEE_字段置为空。
    @Transactional
    public void unClaimTask() {
        Task task = taskService.createTaskQuery().processInstanceId("4279f082-b22e-11ec-8d53-3c9c0f202230").taskAssignee("樱木花道1").singleResult();
        if (task != null){
            taskService.unclaim(task.getId());
            System.out.println(task.getAssignee());
        }
    }
    //移交任务,其实就是设置处理人,act_ru_task表中ASSIGNEE_字段交给被移交的人。
    @Transactional
    public void transTask() {
        Task task = taskService.createTaskQuery().processInstanceId("9359e78a-ae72-11ec-978f-3c9c0f202230").taskAssignee("樱木花道1").singleResult();
        if (task != null){
            taskService.setAssignee(task.getId(),"樱木花道2");
            System.out.println(task.getAssignee());
        }
    }

如果不是他们拒绝接受我的生意,我永远不会停止和他们交易,那么我也就永远学不到:与在对赌行赌几个点的波动相比,股票投机游戏的内容更多。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值