肝了一夜,撸了一个请假工作流模块

点击▲关注 “爪哇笔记”   给公众号标星置顶

更多精彩 第一时间直达

前言

应广大网友墙裂呼吁,撸主点灯野战撸了一个简单的工作流模块,的确是简单了那么一丢丢,但是不影响体验,后面会慢慢优化,直到大家足够满意。

开肝

话不多说,先上图。

我的休假:

@Override
@Transactional(rollbackFor = Exception.class)
public Result myList(BpmLeave leave) {
    Long userId = ShiroUtils.getUserId();
    PageBean<BpmLeave> data = new PageBean<>();
    long count = historyService.createHistoricProcessInstanceQuery()
            .processDefinitionKey("leave").startedBy(userId.toString())
            .count();
    if (count > 0) {
        Integer pageSize = leave.getPageSize();
        Integer firstResult = (leave.getPageNo()) * pageSize;
        List<HistoricProcessInstance> list = historyService.createHistoricProcessInstanceQuery()
                .processDefinitionKey("leave").startedBy(userId.toString())
                .listPage(firstResult, pageSize);
        List<BpmLeave> listLeave = new ArrayList<>();
        list.forEach(instance->{
            String nativeSql = "SELECT * FROM bpm_leave WHERE process_instance_id=?";
            BpmLeave entity = dynamicQuery.nativeQuerySingleResult(BpmLeave.class,nativeSql,new Object[]{instance.getId()});
            entity.setStatus(instance.getEndTime()==null?"进行中":"已完成");
            listLeave.add(entity);
        });
        data = new PageBean(listLeave, count);
    }
    return Result.ok(data);
}

待办任务:

@Override
public Result toDoList(BpmLeave leave) {
    Long userId = ShiroUtils.getUserId();
    PageBean<BpmLeave> data = new PageBean<>();
    long count = taskService.createTaskQuery()
            .taskCandidateOrAssigned(userId.toString()).count();
    if(count>0){
        Integer pageSize = leave.getPageSize();
        Integer firstResult = (leave.getPageNo()) * pageSize;
        List<Task> tasks = taskService.createTaskQuery()
                .taskCandidateOrAssigned(userId.toString())
                .listPage(firstResult,pageSize);
        List<BpmLeave> listLeave = new ArrayList<>();
        tasks.forEach(task->{
            String processInstanceId = task.getProcessInstanceId();
            String nativeSql = "SELECT * FROM bpm_leave WHERE process_instance_id=?";
            BpmLeave entity = dynamicQuery.nativeQuerySingleResult(BpmLeave.class,nativeSql,new Object[]{processInstanceId});
            entity.setTaskId(task.getId());
            listLeave.add(entity);
        });
        data = new PageBean(listLeave, count);
    }
    return Result.ok(data);
}

已办任务:

@Override
public Result toDoList(BpmLeave leave) {
    Long userId = ShiroUtils.getUserId();
    PageBean<BpmLeave> data = new PageBean<>();
    long count = taskService.createTaskQuery()
            .taskCandidateOrAssigned(userId.toString()).count();
    if(count>0){
        Integer pageSize = leave.getPageSize();
        Integer firstResult = (leave.getPageNo()) * pageSize;
        List<Task> tasks = taskService.createTaskQuery()
                .taskCandidateOrAssigned(userId.toString())
                .listPage(firstResult,pageSize);
        List<BpmLeave> listLeave = new ArrayList<>();
        tasks.forEach(task->{
            String processInstanceId = task.getProcessInstanceId();
            String nativeSql = "SELECT * FROM bpm_leave WHERE process_instance_id=?";
            BpmLeave entity = dynamicQuery.nativeQuerySingleResult(BpmLeave.class,nativeSql,new Object[]{processInstanceId});
            entity.setTaskId(task.getId());
            listLeave.add(entity);
        });
        data = new PageBean(listLeave, count);
    }
    return Result.ok(data);
}

小结

流程做的有点仓促,无论怎样,先开源给各位小伙伴,需要请666点赞再看,如果觉得不错可以分享给身边的朋友,你们的支持是我更新最大的动力。

获取方式 

1. 识别下方二维码

2. 后台回复「666」即可获取

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值