act_id_xxx相关表存储了所有用户和组的数据。

一、维护用户信息

    @Autowired
    private IdentityService identityService;

    /**
     * 维护用户
     */
    @Test
    void createUser() {
        User user = identityService.newUser("zhangsan");
        user.setEmail("zhangsan@qq.com");
        user.setFirstName("zhang");
        user.setLastName("san");
        identityService.saveUser(user);
    }

        在act_id_user表中查看创建的用户信息,这里添加了两条用户信息。

springboot与flowable(9):候选人组插图

二、维护用户组

        创建用户组

    /**
     * 维护用户组
     */
    @Test
    void createGroup() {
        Group group = identityService.newGroup("xsb");
        group.setName("销售部");
        group.setType("type1");
        identityService.saveGroup(group);
    }

        在act_id_group表中查看信息,这里添加了两条用户组。

springboot与flowable(9):候选人组插图(1)

三、维护用户与组的关系

    /**
     * 维护用户和用户组的关系
     */
    @Test
    void createMemberShip() {
        // 通过id获取组信息
        Group group = identityService.createGroupQuery().groupId("xsb").singleResult();
        // 获取所有用户信息
        List list = identityService.createUserQuery().list();
        for (User user : list) {
            // 用户和组的绑定
            identityService.createMembership(user.getId(), group.getId());
        }
    }

        在act_id_membership表中查看结果。

springboot与flowable(9):候选人组插图(2)

四、候选人组案例

        创建HolidayDemo2流程案例,绘制如下流程。

springboot与flowable(9):候选人组插图(3)

        给人事审批和经理审批分配用户,都在在候选组中添加xsb(销售部)。

springboot与flowable(9):候选人组插图(4)

        保存并导出该流程图,复制到当前项目中。

springboot与flowable(9):候选人组插图(5)

        部署流程定义

 @Test
    void contextLoads() {
        DeploymentBuilder deployment = repositoryService.createDeployment();
        deployment.addClasspathResource("process01/HolidayDemo2.bpmn20.xml");
        deployment.name("候选人组案例");
        Deployment deploy = deployment.deploy();
        System.out.println("deploy.getId() = " + deploy.getId());
    }

springboot与flowable(9):候选人组插图(6)

        发起流程

    /**
     * 发起流程
     */
    @Test
    public void startProcess() {
        String id = "HolidayDemo2:1:595e0359-2b0c-11ef-9f3e-644ed7087863";
        // 根据流程定义ID启动流程
        ProcessInstance processInstance = runtimeService.startProcessInstanceById(id);
    }

        查看待办事项表,审批人为null。 

springboot与flowable(9):候选人组插图(7)

        查看act_ru_identitylink(运行时用户关系表),可以看到候选人组是xsb。

springboot与flowable(9):候选人组插图(8)

        候选人组审批,流程结束。

   /**
     * 候选任务查询
     */
    @Test
    void findCandidateTask() {
        // 根据当前登录用户查询所属的组
        Group group = identityService.createGroupQuery().groupMember("zhangsan").singleResult();
        // 根据候选人组查询待办信息
        List list = taskService.createTaskQuery().taskCandidateGroup(group.getId()).list();
        for (Task task : list) {
            // 当前用户拾取待办任务 候选人 -> 审批人
            taskService.claim(task.getId(), "zhangsan");
            // 审批任务
            taskService.complete(task.getId());
        }
    }
本站无任何商业行为
个人在线分享 » springboot与flowable(9):候选人组
E-->