项目实训—flowable开发(二)

目录

获取待办事项

flowable数据库

TodoList待办列表:

FlowMyBusinessMapper.xml:

FlowMyBusinessServiceImpl:

FlowTaskServiceImpl:

FlowTaskController:

获取已办事项

FlowMyBusinessMapper.xml:

FlowMyBusinessServiceImpl:

FlowTaskServiceImpl:

FlowTaskController:

 获取办结事项

流程状态解释

查询到办结事项

实验授课申请的办结事项

实验课任教申请的办结事项


可以在FlowTaskServiceImpl.java中设置相应的办法来处理待办事项、已办事项和办结事项,通过传递serviceKey来获取不同类型的申请

serviceKey定义:

ExcApply: 0

ExtApply: 1

Extarrangement: 2

ChangeScoresApply: 3

实验管理员需要处理多项申请,所以需要获取待办事项和已办事项

获取待办事项

为了获取待办事项,可以调用flowable的接口

TaskQuery taskQuery = taskService.createTaskQuery()
                .active()
                .includeProcessVariables()
                .taskCandidateUser(username)
                .orderByTaskCreateTime().desc();

调用这个接口来获取用户的待办列表

taskService.createTaskQuery()
                .active()
                .includeProcessVariables()
                .taskCandidateUser(username)

taskCandidateUser(username)可以获取到候选人为此用户名的任务,即为待办事项,orderByTaskCreateTime().desc()能够将查询出的task按照创建时间降序排列

但是taskQuery只能获取到task(任务)的id与name,因此需要从数据库中再查询出申请信息。

因此还需要用sql语句查询数据库,但是对于具体流程使用sql语句查询数据库需要很准确地了解flowable数据库的定义以及存储数据

flowable数据库

 flowable数据表分类:

1.ACT_GE_*:通用数据表,各种情况都使用的数据

2.ACT_RE_*:流程定义存储表,'RE'表示repository。此前缀的表存放的都是静态信息,如流程定义等。最开始用前端界面创建流程图是就把信息存储在此类表中

3.ACT_ID_*:身份信息表,'ID'表示identity。这些表中包含标识的信息,如用户、用户组等标识

4.ACT_RU_*:运行时数据库表,'RU'表示runtime,这些表存储着流程变量、用户任务、变量、指责等运行时的数据。

5.ACT_HI_*:'HI'表示history。这些表包含历史相关数据,如结束的流程实例,变量,任务等。

TodoList待办列表:

了解了数据库表格储存的信息,调用flowable的接口,获取到候选人Candidate为用户的任务记录,其id为flow_my_bussiness中的task_id

 获取到task_id,可以在flow_my_business查询到此条申请的data_id,此条申请的data_id就是exc_apply的id

理清数据库的关系,可以写各个服务的todoList()方法

FlowMyBusinessMapper.xml:

首先通过task_id得到这条数据的data_id,然后再通过data_id找到相应的申请数据库中的申请信息

//获取flow_my_business中待办的business
<select id="getTodoBusiness" resultType="org.jeecg.modules.flowable.apithird.business.entity.FlowMyBusiness">
        select *
        from flow_my_business
        where todo_users like CONCAT('%',#{todousers},'%') and process_definition_key = #{serviceKey}
    </select>
//获取相应的ExcApply
    <select id="getExcApply" resultType="org.jeecg.modules.flowable.apithird.business.entity.ExcApply">
        select *
        from exc_apply
        where id = #{dataid}
    </select>
//获取相应的ExtApply
    <select id="getExtApply" resultType="org.jeecg.modules.flowable.apithird.business.entity.ExtApply">
        select *
        from ext_apply
        where id = #{dataid}
    </select>
//获取相应的Extarrangement
    <select id="getExtarrangement" resultType="org.jeecg.modules.flowable.apithird.business.entity.Extarrangement">
        select *
        from extarrangement
        where id = #{dataid}
    </select>

//获取相应的ChangeScoresApply
    <select id="getChangeScoresApply" resultType="org.jeecg.modules.flowable.apithird.business.entity.ChangeScoresApply">
         select *
        from change_scores_apply
        where id = #{dataid}
    </select>

FlowMyBusinessMapper和IFlowMyBusinessService中只需要加个方法声明,不再赘述

FlowMyBusinessServiceImpl:

 //获取待办
    @Override
    public List<FlowMyBusiness> getTodoBusiness(String todousers,String serviceKey) {
        return this.baseMapper.getTodoBusiness(todousers,serviceKey);
    }

    //获取相应的ExcApply
    @Override
    public ExcApply getExcApply(String dataid) {
        return this.baseMapper.getExcApply(dataid);
    }

    //获取相应的ExtApply
    @Override
    public ExtApply getExtApply(String dataid) {
        return this.baseMapper.getExtApply(dataid);
    }

    //获取相应的Extarrangement
    @Override
    public Extarrangement getExtarrangement(String dataid) {
        return this.baseMapper.getExtarrangement(dataid);
    }

    //获取相应的ChangeScoresApply
    @Override
    public ChangeScoresApply getChangeScoresAply(String dataid) {
        return this.baseMapper.getChangeScoresApply(dataid);
    }

FlowTaskServiceImpl:

之前提到FlowTaskServiceImpl中主要书写了关于任务的处理方式,所以要在FlowTaskServiceImpl中新写todoList1()

@Override
    public Result todoList1(Integer pageNum, Integer pageSize, String serviceType) {
        String username = iFlowThirdService.getLoginUser().getUsername();
        //获取候选人为此用户的任务记录
        TaskQuery taskQuery = taskService.createTaskQuery()
                .active()
                .includeProcessVariables()
                .taskCandidateUser(username)
                .orderByTaskCreateTime().desc();
        List<Task> taskList = taskQuery.listPage((pageNum - 1)*pageSize, pageSize);
        List<ExcApply> excApplyList = new ArrayList<>();
        List<ExtApply> extApplyList = new ArrayList<>();
        for (Task task : taskList) {
            //通过task_id找到对应的business,再找到相应的申请记录
            FlowMyBusiness business = flowMyBusinessService.getDataId(task.getId());
            if(business.getProcessDefinitionKey().equals("ExcApply")){
                ExcApply temp = flowMyBusinessService.getExcApply(business.getDataId());
                excApplyList.add(temp);
            }else if(business.getProcessDefinitionKey().equals("ExtApply")){
                ExtApply temp = flowMyBusinessService.getExtApply(business.getDataId());
                extApplyList.add(temp);
            }

        }
        if(serviceType.equals("0")){
            //如果服务类型为ExcApply
            return Result.OK(excApplyList);
        }else if(serviceType.equals("1")){
            //如果服务类型为ExtApply
            return Result.OK(extApplyList);
        }else{
            return null;
        }

    }

但是这个接口在后续实践中,如果临时指定候选人不能完美地将候选人存入CandidateUser,存后续操作不能成功进行,因此需要直接从flow_my_business中筛选出todo_users为登录用户的流程 

修改后代码

@Override
    public Result todoList1(Integer pageNum, Integer pageSize, String serviceType) {
        String username = iFlowThirdService.getLoginUser().getUsername();
        String serviceKey = "";
        if(serviceType.equals("0")){
            //如果服务类型为ExcApply
            serviceKey = "ExcApply";
        }else if(serviceType.equals("1")){
            //如果服务类型为ExtApply
            serviceKey = "ExtApply";
        }else if(serviceType.equals("2")){
            serviceKey = "Extarrangement";
        }else if(serviceType.equals("3")){
            serviceKey = "ChangeScoresApply";
        }
        List<ExcApply> excApplyList = new ArrayList<>();
        List<ExtApply> extApplyList = new ArrayList<>();
        List<Extarrangement> arrangeConfirmList = new ArrayList<>();
        List<ChangeScoresApply> changeScoresApplyList = new ArrayList<>();
        List<FlowMyBusiness> businessList = flowMyBusinessService.getTodoBusiness(username,serviceKey);
        System.out.println("username"+username);
        System.out.println("serviceKey"+serviceKey);
        System.out.println("businessList"+businessList.size());
        for(FlowMyBusiness business: businessList){
            System.out.println("business"+business.toString());
        }
        if(serviceType.equals("0")){
            //如果服务类型为ExcApply
            for(FlowMyBusiness business:businessList){
                ExcApply excApply = flowMyBusinessService.getExcApply(business.getDataId());
                excApplyList.add(excApply);
            }
            return Result.OK(excApplyList);
        }else if(serviceType.equals("1")){
            //如果服务类型为ExtApply
            for(FlowMyBusiness business:businessList){
                ExtApply extApply = flowMyBusinessService.getExtApply(business.getDataId());
                extApplyList.add(extApply);
            }
            return Result.OK(extApplyList);
        }else if(serviceType.equals("2")){
            for(FlowMyBusiness business:businessList){
                Extarrangement extarrangement = flowMyBusinessService.getExtarrangement(business.getDataId());
                arrangeConfirmList.add(extarrangement);
            }
            return Result.OK(arrangeConfirmList);
        }else if(serviceType.equals("3")){
            for(FlowMyBusiness business:businessList){
                ChangeScoresApply changeScoresApply = flowMyBusinessService.getChangeScoresAply(business.getDataId());
                changeScoresApplyList.add(changeScoresApply);
            }
            return Result.OK(changeScoresApplyList);
        }
        else{
            return null;
        }

    }

FlowTaskController:

为了区分不同服务类型,需要传入serviceType这个参数

jeecg在url中的list需要传入参数,传参格式:

开始我将serviceType设为require=true,但是一直显示前端未传入参数 ,所以我将@RequestParams("serviceType") String serviceType改为HttpServletRequest req

再通过req.getParameter("serviceType");获取到传入的serviceType参数(注意:传入参数默认为String

@ApiOperation(value = "改进的待办列表", response = FlowTaskDto.class)
    @GetMapping(value = "/todoList1")
    public Result todoList1(@ApiParam(value = "当前页码", defaultValue = "1") @RequestParam Integer pageNum,
                           @ApiParam(value = "每页条数", defaultValue = "1") @RequestParam Integer pageSize,
                            HttpServletRequest req
    ) {
        String serviceType = req.getParameter("serviceType");
        return flowTaskService.todoList1(pageNum, pageSize,serviceType);
    }

获取已办事项

act_hi_taskinst表中的ASSIGNEE_字段保存处理此流程某一步的用户名,通过flowable API接口从历史表中获取到处理过流程的username

HistoricTaskInstanceQuery taskInstanceQuery = historyService.createHistoricTaskInstanceQuery()
                .includeProcessVariables()
                .finished()
                .taskAssignee(username)
                .orderByHistoricTaskInstanceEndTime()
                .desc();

所以可以通过

HistoricTaskInstanceQuery taskInstanceQuery = historyService.createHistoricTaskInstanceQuery() .includeProcessVariables() .finished() .taskAssignee(username)

来获取此用户处理过的申请,再调用orderByHistoricTaskInstanceEndTime() .desc()使其降序排列

 调用taskInstanceQuery.getProcessInstanceId()通过process_instance_Id获取到flow_my_business中的相应数据,这样可以获取到data_id获取到相应的ext_apply中的数据

FlowMyBusinessMapper.xml:

//从flow_my_business获取此用户办结的business
<select id="getDoneBusiness" resultType="org.jeecg.modules.flowable.apithird.business.entity.FlowMyBusiness">
        select *
        from flow_my_business
        where done_users like CONCAT('%',#{doneusers},'%') and process_definition_key = #{serviceKey}
    </select>

FlowMyBusinessServiceImpl:

 //获取已办
    @Override
    public List<FlowMyBusiness> getDoneBusiness(String doneusers,String serviceKey) {
        return this.baseMapper.getDoneBusiness(doneusers,serviceKey);
    }

FlowTaskServiceImpl:

要在FlowTaskServiceImpl中新写finishedList1()来实现已办事项的查看

/**
     * 改进已办任务列表
     *
     * @param pageNum  当前页码
     * @param pageSize 每页条数
     * @return
     */
    @Override
    public Result finishedList1(Integer pageNum, Integer pageSize,String serviceType) {
        String username = iFlowThirdService.getLoginUser().getUsername();
        HistoricTaskInstanceQuery taskInstanceQuery = historyService.createHistoricTaskInstanceQuery()
                .includeProcessVariables()
                .finished()
                .taskAssignee(username)
                .orderByHistoricTaskInstanceEndTime()
                .desc();
        List<HistoricTaskInstance> historicTaskInstanceList = taskInstanceQuery.listPage((pageNum - 1)*pageSize, pageSize);
        List<ExcApply> excApplyList = new ArrayList<>();
        List<ExtApply> extApplyList = new ArrayList<>();
        for (HistoricTaskInstance histTask : historicTaskInstanceList) {
            //通过process_instance_id找到对应的business
            FlowMyBusiness business = flowMyBusinessService.getDataIdByProId(histTask.getProcessInstanceId());
            //判断类型,通过business找到对应的申请数据并把它放在列表中
            if (business.getProcessDefinitionKey().equals("ExcApply")) {
                ExcApply temp = flowMyBusinessService.getExcApply(business.getDataId());
                excApplyList.add(temp);
            } else if (business.getProcessDefinitionKey().equals("ExtApply")) {
                ExtApply temp = flowMyBusinessService.getExtApply(business.getDataId());
                extApplyList.add(temp);
            }
        }



        if(serviceType.equals("0")){
            //如果服务类型为ExcApply
            return Result.OK(excApplyList);
        }else if(serviceType.equals("1")){
            //如果服务类型为ExtApply
            return Result.OK(extApplyList);
        }else{
            return null;
        }
    }

 已办列表finishedList1()也有同样的问题,也需要修改,修改后的代码

/**
     * 改进已办任务列表
     *
     * @param pageNum  当前页码
     * @param pageSize 每页条数
     * @param serviceType 服务类型
     * @return
     */
    @Override
    public Result finishedList1(Integer pageNum, Integer pageSize,String serviceType) {
        String username = iFlowThirdService.getLoginUser().getUsername();
        String serviceKey = "";
        if(serviceType.equals("0")){
            //如果服务类型为ExcApply
           serviceKey = "ExcApply";
        }else if(serviceType.equals("1")){
            //如果服务类型为ExtApply
            serviceKey = "ExtApply";
        }else if(serviceType.equals("2")){
            serviceKey = "Extarrangement";
        }else if(serviceType.equals("3")){
            serviceKey = "ChangeScoresApply";
        }
        List<FlowMyBusiness> businesses = flowMyBusinessService.getDoneBusiness(username,serviceKey);
        List<ExcApply> excApplyList = new ArrayList<>();
        List<ExtApply> extApplyList = new ArrayList<>();
        List<Extarrangement> extarrangementsList = new ArrayList<>();
        List<ChangeScoresApply> changeScoresApplyList = new ArrayList<>();
        if(serviceType.equals("0")){
            //如果服务类型为ExcApply
            for(FlowMyBusiness business:businesses){
                ExcApply excApply = flowMyBusinessService.getExcApply(business.getDataId());
                excApplyList.add(excApply);
            }
            return Result.OK(excApplyList);
        }else if(serviceType.equals("1")){
            //如果服务类型为ExtApply
            for(FlowMyBusiness business:businesses){
                ExtApply extApply = flowMyBusinessService.getExtApply(business.getDataId());
                extApplyList.add(extApply);
            }
            return Result.OK(extApplyList);
        }else if(serviceType.equals("2")){
            for(FlowMyBusiness business:businesses){
                Extarrangement extarrangement = flowMyBusinessService.getExtarrangement(business.getDataId());
                extarrangementsList.add(extarrangement);
            }
            return Result.OK(extarrangementsList);
        }else if(serviceType.equals("3")){
            for(FlowMyBusiness business:businesses){
                ChangeScoresApply changeScoresApply = flowMyBusinessService.getChangeScoresAply(business.getDataId());
                changeScoresApplyList.add(changeScoresApply);
            }
            return Result.OK(changeScoresApplyList);
        }
        else{
            return null;
        }
    }

FlowTaskController:

@ApiOperation(value = "改进的获取已办任务", response = FlowTaskDto.class)
    @GetMapping(value = "/finishedList1")
    public Result finishedList1(@ApiParam(value = "当前页码", required = true) @RequestParam Integer pageNum,
                               @ApiParam(value = "每页条数", required = true) @RequestParam Integer pageSize,
                                HttpServletRequest req) {
        String serviceType = req.getParameter("serviceType");
        return flowTaskService.finishedList1(pageNum, pageSize,serviceType);
    }

 获取办结事项

申请人需要查看自己的申请是否通过,所以需要有个办结事项便于用户查看

查看flow_my_business数据库可以看见每一条工作流数据会有流程状态act_status

流程状态解释

草稿:业务数据未与流程相关联或已关联定义信息但是未启动流程

启动:业务数据与流程已关联并通过了第一个节点(申请人节点start

撤回:启动的流程被销毁,业务数据与流程定义信息存在关联,可直接启动(亦可重新关联 别的流程再启动)

驳回:驳回状态的流程并未结束,流程实例依然存在,被驳回到的节点需要重新审批,业务 按钮中,退回与驳回实际上都是驳回,当驳回到申请人节点start时,请注意业务 开发中表单编辑权限需要打开,此时再度提交流程实际上是审批操作,注意页面上 的文字描述

审批中:流程正常流转中

审批通过:流程全部审批完成自动结束了

查询到办结事项

查询办结事项只要找到申请人为用户并且流程状态为"审核通过"的流程实例记录

用inner join来找到相应的申请

实验授课申请的办结事项

FlowMyBusiness.xml:

//获取相应用户已办的ExcApply
<select id="getExcDoneApply" resultType="org.jeecg.modules.flowable.apithird.business.entity.ExcApply">
        select *
        from exc_apply a inner join flow_my_business b
        on a.id = b.data_id
        where b.act_status = "审批通过" and b.create_by = #{username}
    </select>

//获取相应用户已办的ExtApply
    <select id="getExtDoneApply" resultType="org.jeecg.modules.flowable.apithird.business.entity.ExtApply">
         select *
        from ext_apply a inner join flow_my_business b
        on a.id = b.data_id
        where b.act_status = "审批通过" and b.create_by = #{username}
    </select>

//获取相应用户已办的ChangeScoresDone
    <select id="getChangeScoresDone" resultType="org.jeecg.modules.flowable.apithird.business.entity.ChangeScoresApply">
         select *
        from change_scores_apply a inner join flow_my_business b
        on a.id = b.data_id
        where b.act_status = "审批通过" and b.create_by = #{username}
    </select>


//获取相应用户已办的TeaExtDoneApply,任课老师任教的实验课申请
    <select id="getTeaExtDoneApply" resultType="org.jeecg.modules.flowable.apithird.business.entity.ExtApply">
         select *
        from ext_apply a inner join flow_my_business b
        on a.id = b.data_id
        where b.act_status = "审批通过" and b.create_by = "teaAdmin" and a.needextea = "否" and a.tid = #{username}
    </select>

FlowMyBusinessServiceImpl:

//获取相应用户办结的ExcApply
    @Override
    public List<ExcApply> getExcDoneApply(String username) {
        return this.baseMapper.getExcDoneApply(username);
    }

    //获取相应用户办结的ExtApply
    @Override
    public List<ExtApply> getExtDoneApply(String dataid) {
        return this.baseMapper.getExtDoneApply(dataid);
    }

    //获取相应用户办结的TeaExtDoneApply
    @Override
    public List<ExtApply> getTeaExtDoneApply(String username) {
        return this.baseMapper.getTeaExtDoneApply(username);
    }

    //获取相应用户办结的ChangeScoresApply
    @Override
    public List<ChangeScoresApply> getChangeScoresDone(String username) {
        return this.baseMapper.getChangeScoresDone(username);
    }

前端直接设置url中的list的接口为此接口即可,就可以获取到办结事项

实验课任教申请的办结事项

ExtApplyMapper.xml:

<select id="getMyList" resultType="org.jeecg.modules.demo.ExtApply.entity.ExtApply">
        select *
        from ext_apply a inner join flow_my_business b on a.id =b.data_id
        where a.extid = #{extid} and b.act_status != "审批通过"
    </select>

ExtApplyServiceImpl:

 @Override
    public List<ExtApply> getMyList(String extid) {
        return this.baseMapper.getMyList(extid);
    }

ExtApplyController:

@RequestMapping(value = "/getMyList",method = RequestMethod.GET)
	 public Result<?> getMyList(@RequestParam(name="extid",defaultValue="1") String extid){
		 SysUser sysUser = iFlowThirdService.getLoginUser();
		 extid = sysUser.getUsername();
		 List<ExtApply> allList = extApplyService.getMyList(extid);
		 return Result.OK(allList);
	 }

 前端直接设置url中的list的接口为此接口即可,就可以获取到办结事项

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值