Search in sources :

Example 1 with WfTaskVo

use of com.ruoyi.workflow.domain.vo.WfTaskVo in project RuoYi-Flowable-Plus by KonBAI-Q.

the class WfTaskServiceImpl method flowRecord.

/**
 * 流程历史流转记录
 *
 * @param procInsId 流程实例Id
 * @return
 */
@Override
public Map<String, Object> flowRecord(String procInsId, String deployId) {
    Map<String, Object> map = new HashMap<>();
    if (StringUtils.isNotBlank(procInsId)) {
        List<HistoricActivityInstance> list = historyService.createHistoricActivityInstanceQuery().processInstanceId(procInsId).orderByHistoricActivityInstanceStartTime().desc().list();
        List<WfTaskVo> hisFlowList = new ArrayList<>();
        for (HistoricActivityInstance histIns : list) {
            if (StringUtils.isNotBlank(histIns.getTaskId())) {
                WfTaskVo flowTask = new WfTaskVo();
                flowTask.setProcDefId(histIns.getProcessDefinitionId());
                flowTask.setTaskId(histIns.getTaskId());
                flowTask.setTaskName(histIns.getActivityName());
                flowTask.setCreateTime(histIns.getStartTime());
                flowTask.setFinishTime(histIns.getEndTime());
                if (StringUtils.isNotBlank(histIns.getAssignee())) {
                    SysUser sysUser = sysUserService.selectUserById(Long.parseLong(histIns.getAssignee()));
                    flowTask.setAssigneeId(sysUser.getUserId());
                    flowTask.setAssigneeName(sysUser.getNickName());
                    flowTask.setDeptName(sysUser.getDept().getDeptName());
                }
                // 展示审批人员
                List<HistoricIdentityLink> linksForTask = historyService.getHistoricIdentityLinksForTask(histIns.getTaskId());
                StringBuilder stringBuilder = new StringBuilder();
                for (HistoricIdentityLink identityLink : linksForTask) {
                    if ("candidate".equals(identityLink.getType())) {
                        if (StringUtils.isNotBlank(identityLink.getUserId())) {
                            SysUser sysUser = sysUserService.selectUserById(Long.parseLong(identityLink.getUserId()));
                            stringBuilder.append(sysUser.getNickName()).append(",");
                        }
                        if (StringUtils.isNotBlank(identityLink.getGroupId())) {
                            SysRole sysRole = sysRoleService.selectRoleById(Long.parseLong(identityLink.getGroupId()));
                            stringBuilder.append(sysRole.getRoleName()).append(",");
                        }
                    }
                }
                if (StringUtils.isNotBlank(stringBuilder)) {
                    flowTask.setCandidate(stringBuilder.substring(0, stringBuilder.length() - 1));
                }
                flowTask.setDuration(histIns.getDurationInMillis() == null || histIns.getDurationInMillis() == 0 ? null : getDate(histIns.getDurationInMillis()));
                // 获取意见评论内容
                List<Comment> commentList = taskService.getProcessInstanceComments(histIns.getProcessInstanceId());
                commentList.forEach(comment -> {
                    if (histIns.getTaskId().equals(comment.getTaskId())) {
                        flowTask.setComment(WfCommentDto.builder().type(comment.getType()).comment(comment.getFullMessage()).build());
                    }
                });
                hisFlowList.add(flowTask);
            }
        }
        map.put("flowList", hisFlowList);
    // // 查询当前任务是否完成
    // List<Task> taskList = taskService.createTaskQuery().processInstanceId(procInsId).list();
    // if (CollectionUtils.isNotEmpty(taskList)) {
    // map.put("finished", true);
    // } else {
    // map.put("finished", false);
    // }
    }
    // 第一次申请获取初始化表单
    if (StringUtils.isNotBlank(deployId)) {
        WfFormVo formVo = deployFormService.selectDeployFormByDeployId(deployId);
        if (Objects.isNull(formVo)) {
            throw new ServiceException("请先配置流程表单");
        }
        map.put("formData", JsonUtils.parseObject(formVo.getContent(), Map.class));
    }
    return map;
}
Also used : Comment(org.flowable.engine.task.Comment) FlowComment(com.ruoyi.flowable.common.enums.FlowComment) HistoricIdentityLink(org.flowable.identitylink.api.history.HistoricIdentityLink) SysUser(com.ruoyi.common.core.domain.entity.SysUser) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) WfTaskVo(com.ruoyi.workflow.domain.vo.WfTaskVo) WfFormVo(com.ruoyi.workflow.domain.vo.WfFormVo) ServiceException(com.ruoyi.common.exception.ServiceException) SysRole(com.ruoyi.common.core.domain.entity.SysRole) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HistoricActivityInstance(org.flowable.engine.history.HistoricActivityInstance)

Example 2 with WfTaskVo

use of com.ruoyi.workflow.domain.vo.WfTaskVo in project RuoYi-Flowable-Plus by KonBAI-Q.

the class WfTaskServiceImpl method todoList.

/**
 * 代办任务列表
 *
 * @return
 */
@Override
public TableDataInfo<WfTaskVo> todoList(PageQuery pageQuery) {
    Page<WfTaskVo> page = new Page<>();
    Long userId = LoginHelper.getUserId();
    TaskQuery taskQuery = taskService.createTaskQuery().active().includeProcessVariables().taskCandidateOrAssigned(userId.toString()).orderByTaskCreateTime().desc();
    page.setTotal(taskQuery.count());
    int offset = pageQuery.getPageSize() * (pageQuery.getPageNum() - 1);
    List<Task> taskList = taskQuery.listPage(offset, pageQuery.getPageSize());
    List<WfTaskVo> flowList = new ArrayList<>();
    for (Task task : taskList) {
        WfTaskVo flowTask = new WfTaskVo();
        // 当前流程信息
        flowTask.setTaskId(task.getId());
        flowTask.setTaskDefKey(task.getTaskDefinitionKey());
        flowTask.setCreateTime(task.getCreateTime());
        flowTask.setProcDefId(task.getProcessDefinitionId());
        flowTask.setTaskName(task.getName());
        // 流程定义信息
        ProcessDefinition pd = repositoryService.createProcessDefinitionQuery().processDefinitionId(task.getProcessDefinitionId()).singleResult();
        flowTask.setDeployId(pd.getDeploymentId());
        flowTask.setProcDefName(pd.getName());
        flowTask.setProcDefVersion(pd.getVersion());
        flowTask.setProcInsId(task.getProcessInstanceId());
        // 流程发起人信息
        HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult();
        SysUser startUser = sysUserService.selectUserById(Long.parseLong(historicProcessInstance.getStartUserId()));
        // SysUser startUser = sysUserService.selectUserById(Long.parseLong(task.getAssignee()));
        flowTask.setStartUserId(startUser.getNickName());
        flowTask.setStartUserName(startUser.getNickName());
        flowTask.setStartDeptName(startUser.getDept().getDeptName());
        flowList.add(flowTask);
    }
    page.setRecords(flowList);
    return TableDataInfo.build(page);
}
Also used : Task(org.flowable.task.api.Task) SysUser(com.ruoyi.common.core.domain.entity.SysUser) HistoricProcessInstance(org.flowable.engine.history.HistoricProcessInstance) WfTaskVo(com.ruoyi.workflow.domain.vo.WfTaskVo) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) TaskQuery(org.flowable.task.api.TaskQuery)

Example 3 with WfTaskVo

use of com.ruoyi.workflow.domain.vo.WfTaskVo in project RuoYi-Flowable-Plus by KonBAI-Q.

the class WfTaskServiceImpl method myProcess.

/**
 * 我发起的流程
 *
 * @return
 */
@Override
public TableDataInfo<WfTaskVo> myProcess(PageQuery pageQuery) {
    Page<WfTaskVo> page = new Page<>();
    Long userId = LoginHelper.getUserId();
    HistoricProcessInstanceQuery historicProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery().startedBy(userId.toString()).orderByProcessInstanceStartTime().desc();
    int offset = pageQuery.getPageSize() * (pageQuery.getPageNum() - 1);
    List<HistoricProcessInstance> historicProcessInstances = historicProcessInstanceQuery.listPage(offset, pageQuery.getPageSize());
    page.setTotal(historicProcessInstanceQuery.count());
    List<WfTaskVo> taskVoList = new ArrayList<>();
    for (HistoricProcessInstance hisIns : historicProcessInstances) {
        WfTaskVo taskVo = new WfTaskVo();
        taskVo.setCreateTime(hisIns.getStartTime());
        taskVo.setFinishTime(hisIns.getEndTime());
        taskVo.setProcInsId(hisIns.getId());
        // 计算耗时
        if (Objects.nonNull(hisIns.getEndTime())) {
            long time = hisIns.getEndTime().getTime() - hisIns.getStartTime().getTime();
            taskVo.setDuration(getDate(time));
        } else {
            long time = System.currentTimeMillis() - hisIns.getStartTime().getTime();
            taskVo.setDuration(getDate(time));
        }
        // 流程部署实例信息
        Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(hisIns.getDeploymentId()).singleResult();
        taskVo.setDeployId(hisIns.getDeploymentId());
        taskVo.setProcDefId(hisIns.getProcessDefinitionId());
        taskVo.setProcDefName(hisIns.getProcessDefinitionName());
        taskVo.setProcDefVersion(hisIns.getProcessDefinitionVersion());
        taskVo.setCategory(deployment.getCategory());
        // 当前所处流程 todo: 本地启动放开以下注释
        // List<Task> taskList = taskService.createTaskQuery().processInstanceId(hisIns.getId()).list();
        // if (CollectionUtils.isNotEmpty(taskList)) {
        // flowTask.setTaskId(taskList.get(0).getId());
        // } else {
        // List<HistoricTaskInstance> historicTaskInstance = historyService.createHistoricTaskInstanceQuery().processInstanceId(hisIns.getId()).orderByHistoricTaskInstanceEndTime().desc().list();
        // flowTask.setTaskId(historicTaskInstance.get(0).getId());
        // }
        taskVoList.add(taskVo);
    }
    page.setRecords(taskVoList);
    return TableDataInfo.build(page);
}
Also used : HistoricProcessInstanceQuery(org.flowable.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstance(org.flowable.engine.history.HistoricProcessInstance) WfTaskVo(com.ruoyi.workflow.domain.vo.WfTaskVo) Deployment(org.flowable.engine.repository.Deployment) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page)

Example 4 with WfTaskVo

use of com.ruoyi.workflow.domain.vo.WfTaskVo in project RuoYi-Flowable-Plus by KonBAI-Q.

the class WfTaskServiceImpl method finishedList.

/**
 * 已办任务列表
 *
 * @return
 */
@Override
public TableDataInfo<WfTaskVo> finishedList(PageQuery pageQuery) {
    Page<WfTaskVo> page = new Page<>();
    Long userId = LoginHelper.getUserId();
    HistoricTaskInstanceQuery taskInstanceQuery = historyService.createHistoricTaskInstanceQuery().includeProcessVariables().finished().taskAssignee(userId.toString()).orderByHistoricTaskInstanceEndTime().desc();
    int offset = pageQuery.getPageSize() * (pageQuery.getPageNum() - 1);
    List<HistoricTaskInstance> historicTaskInstanceList = taskInstanceQuery.listPage(offset, pageQuery.getPageSize());
    List<WfTaskVo> hisTaskList = Lists.newArrayList();
    for (HistoricTaskInstance histTask : historicTaskInstanceList) {
        WfTaskVo flowTask = new WfTaskVo();
        // 当前流程信息
        flowTask.setTaskId(histTask.getId());
        // 审批人员信息
        flowTask.setCreateTime(histTask.getCreateTime());
        flowTask.setFinishTime(histTask.getEndTime());
        flowTask.setDuration(getDate(histTask.getDurationInMillis()));
        flowTask.setProcDefId(histTask.getProcessDefinitionId());
        flowTask.setTaskDefKey(histTask.getTaskDefinitionKey());
        flowTask.setTaskName(histTask.getName());
        // 流程定义信息
        ProcessDefinition pd = repositoryService.createProcessDefinitionQuery().processDefinitionId(histTask.getProcessDefinitionId()).singleResult();
        flowTask.setDeployId(pd.getDeploymentId());
        flowTask.setProcDefName(pd.getName());
        flowTask.setProcDefVersion(pd.getVersion());
        flowTask.setProcInsId(histTask.getProcessInstanceId());
        flowTask.setHisProcInsId(histTask.getProcessInstanceId());
        // 流程发起人信息
        HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(histTask.getProcessInstanceId()).singleResult();
        SysUser startUser = sysUserService.selectUserById(Long.parseLong(historicProcessInstance.getStartUserId()));
        flowTask.setStartUserId(startUser.getNickName());
        flowTask.setStartUserName(startUser.getNickName());
        flowTask.setStartDeptName(startUser.getDept().getDeptName());
        hisTaskList.add(flowTask);
    }
    page.setTotal(taskInstanceQuery.count());
    page.setRecords(hisTaskList);
    // result.put("finished",true);
    return TableDataInfo.build(page);
}
Also used : HistoricTaskInstance(org.flowable.task.api.history.HistoricTaskInstance) SysUser(com.ruoyi.common.core.domain.entity.SysUser) HistoricProcessInstance(org.flowable.engine.history.HistoricProcessInstance) WfTaskVo(com.ruoyi.workflow.domain.vo.WfTaskVo) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) HistoricTaskInstanceQuery(org.flowable.task.api.history.HistoricTaskInstanceQuery)

Aggregations

WfTaskVo (com.ruoyi.workflow.domain.vo.WfTaskVo)4 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)3 SysUser (com.ruoyi.common.core.domain.entity.SysUser)3 HistoricProcessInstance (org.flowable.engine.history.HistoricProcessInstance)3 ProcessDefinition (org.flowable.engine.repository.ProcessDefinition)2 SysRole (com.ruoyi.common.core.domain.entity.SysRole)1 ServiceException (com.ruoyi.common.exception.ServiceException)1 FlowComment (com.ruoyi.flowable.common.enums.FlowComment)1 WfFormVo (com.ruoyi.workflow.domain.vo.WfFormVo)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 HistoricActivityInstance (org.flowable.engine.history.HistoricActivityInstance)1 HistoricProcessInstanceQuery (org.flowable.engine.history.HistoricProcessInstanceQuery)1 Deployment (org.flowable.engine.repository.Deployment)1 Comment (org.flowable.engine.task.Comment)1 HistoricIdentityLink (org.flowable.identitylink.api.history.HistoricIdentityLink)1 Task (org.flowable.task.api.Task)1 TaskQuery (org.flowable.task.api.TaskQuery)1 HistoricTaskInstance (org.flowable.task.api.history.HistoricTaskInstance)1 HistoricTaskInstanceQuery (org.flowable.task.api.history.HistoricTaskInstanceQuery)1