Search in sources :

Example 1 with HistoricTaskInstanceQuery

use of org.flowable.task.api.history.HistoricTaskInstanceQuery in project petals-se-flowable by petalslink.

the class Assert method assertUserTaskEnded.

/**
 * Assertion to check that a user task was completed by the given user.
 *
 * @param processInstanceId
 *            The process instance identifier
 * @param taskDefinitionKey
 *            The process definition key
 * @param user
 *            The task has been completed by the given user
 * @param historyService
 *            The Flowable's history service used to request the Flowable engine about historic process instances.
 */
public static void assertUserTaskEnded(final String processInstanceId, final String taskDefinitionKey, final String user, final HistoryService historyService) {
    final HistoricTaskInstanceQuery taskQuery = historyService.createHistoricTaskInstanceQuery();
    final HistoricTaskInstance nextTask = taskQuery.processInstanceId(processInstanceId).taskDefinitionKey(taskDefinitionKey).singleResult();
    assertNotNull(nextTask);
    assertEquals(user, nextTask.getAssignee());
}
Also used : HistoricTaskInstance(org.flowable.task.api.history.HistoricTaskInstance) HistoricTaskInstanceQuery(org.flowable.task.api.history.HistoricTaskInstanceQuery)

Example 2 with HistoricTaskInstanceQuery

use of org.flowable.task.api.history.HistoricTaskInstanceQuery in project plumdo-work by wengwh.

the class TaskDoneResource method getTasks.

@GetMapping(value = "/tasks/done", name = "已办任务查询")
public PageResponse getTasks(@RequestParam Map<String, String> requestParams) {
    HistoricTaskInstanceQuery query = historyService.createHistoricTaskInstanceQuery();
    if (ObjectUtils.isNotEmpty(requestParams.get("processInstanceId"))) {
        query.processInstanceId(requestParams.get("processInstanceId"));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("processInstanceBusinessKey"))) {
        query.processInstanceBusinessKeyLike(ObjectUtils.convertToLike(requestParams.get("processInstanceBusinessKey")));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("processDefinitionKey"))) {
        query.processDefinitionKeyLike(ObjectUtils.convertToLike(requestParams.get("processDefinitionKey")));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("processDefinitionId"))) {
        query.processDefinitionId(requestParams.get("processDefinitionId"));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("processDefinitionName"))) {
        query.processDefinitionNameLike(ObjectUtils.convertToLike(requestParams.get("processDefinitionName")));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("taskCreatedBefore"))) {
        query.taskCreatedBefore(ObjectUtils.convertToDatetime(requestParams.get("taskCreatedBefore")));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("taskCreatedAfter"))) {
        query.taskCreatedAfter(ObjectUtils.convertToDatetime(requestParams.get("taskCreatedAfter")));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("taskCompletedBefore"))) {
        query.taskCompletedBefore(ObjectUtils.convertToDatetime(requestParams.get("taskCompletedBefore")));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("taskCompletedAfter"))) {
        query.taskCompletedAfter(ObjectUtils.convertToDatetime(requestParams.get("taskCompletedAfter")));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("processFinished"))) {
        boolean isProcessFinished = ObjectUtils.convertToBoolean(requestParams.get("processFinished"));
        if (isProcessFinished) {
            query.processFinished();
        } else {
            query.processUnfinished();
        }
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("tenantId"))) {
        query.taskTenantId(requestParams.get("tenantId"));
    }
    query.finished().or().taskAssignee(Authentication.getUserId()).taskOwner(Authentication.getUserId()).endOr();
    return new TaskPaginateList(restResponseFactory).paginateList(getPageable(requestParams), query, allowedSortProperties);
}
Also used : TaskPaginateList(com.plumdo.flow.rest.task.TaskPaginateList) HistoricTaskInstanceQuery(org.flowable.task.api.history.HistoricTaskInstanceQuery) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 3 with HistoricTaskInstanceQuery

use of org.flowable.task.api.history.HistoricTaskInstanceQuery in project plumdo-work by wengwh.

the class TaskResource method getTasks.

@GetMapping(value = "/tasks", name = "任务查询")
public PageResponse getTasks(@RequestParam Map<String, String> requestParams) {
    HistoricTaskInstanceQuery query = historyService.createHistoricTaskInstanceQuery();
    if (ObjectUtils.isNotEmpty(requestParams.get("taskId"))) {
        query.taskId(requestParams.get("taskId"));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("processInstanceId"))) {
        query.processInstanceId(requestParams.get("processInstanceId"));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("processInstanceBusinessKey"))) {
        query.processInstanceBusinessKeyLike(ObjectUtils.convertToLike(requestParams.get("processInstanceBusinessKey")));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("processDefinitionKey"))) {
        query.processDefinitionKeyLike(ObjectUtils.convertToLike(requestParams.get("processDefinitionKey")));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("processDefinitionId"))) {
        query.processDefinitionId(requestParams.get("processDefinitionId"));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("processDefinitionName"))) {
        query.processDefinitionNameLike(ObjectUtils.convertToLike(requestParams.get("processDefinitionName")));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("executionId"))) {
        query.executionId(requestParams.get("executionId"));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("taskName"))) {
        query.taskNameLike(ObjectUtils.convertToLike(requestParams.get("taskName")));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("taskDescription"))) {
        query.taskDescriptionLike(ObjectUtils.convertToLike(requestParams.get("taskDescription")));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("taskDefinitionKey"))) {
        query.taskDefinitionKeyLike(ObjectUtils.convertToLike(requestParams.get("taskDefinitionKey")));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("taskAssignee"))) {
        query.taskAssignee(requestParams.get("taskAssignee"));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("taskOwner"))) {
        query.taskOwner(requestParams.get("taskOwner"));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("taskInvolvedUser"))) {
        query.taskInvolvedUser(requestParams.get("taskInvolvedUser"));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("taskPriority"))) {
        query.taskPriority(ObjectUtils.convertToInteger(requestParams.get("taskPriority")));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("finished"))) {
        boolean isFinished = ObjectUtils.convertToBoolean(requestParams.get("finished"));
        if (isFinished) {
            query.finished();
        } else {
            query.unfinished();
        }
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("processFinished"))) {
        boolean isProcessFinished = ObjectUtils.convertToBoolean(requestParams.get("processFinished"));
        if (isProcessFinished) {
            query.processFinished();
        } else {
            query.processUnfinished();
        }
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("parentTaskId"))) {
        query.taskParentTaskId(requestParams.get("parentTaskId"));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("dueDateAfter"))) {
        query.taskDueAfter(ObjectUtils.convertToDatetime(requestParams.get("dueDateAfter")));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("dueDateBefore"))) {
        query.taskDueBefore(ObjectUtils.convertToDatetime(requestParams.get("dueDateBefore")));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("taskCreatedBefore"))) {
        query.taskCreatedBefore(ObjectUtils.convertToDatetime(requestParams.get("taskCreatedBefore")));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("taskCreatedAfter"))) {
        query.taskCreatedAfter(ObjectUtils.convertToDatetime(requestParams.get("taskCreatedAfter")));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("taskCompletedBefore"))) {
        query.taskCompletedBefore(ObjectUtils.convertToDatetime(requestParams.get("taskCompletedBefore")));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("taskCompletedAfter"))) {
        query.taskCompletedAfter(ObjectUtils.convertToDatetime(requestParams.get("taskCompletedAfter")));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("tenantId"))) {
        query.taskTenantId(requestParams.get("tenantId"));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("taskCandidateUser"))) {
        query.taskCandidateUser(requestParams.get("taskCandidateUser"));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("taskCandidateGroup"))) {
        query.taskCandidateGroup(requestParams.get("taskCandidateGroup"));
    }
    if (ObjectUtils.isNotEmpty(requestParams.get("taskCandidateGroups"))) {
        String[] candidateGroups = requestParams.get("taskCandidateGroups").split(",");
        query.taskCandidateGroupIn(Arrays.asList(candidateGroups));
    }
    return new TaskPaginateList(restResponseFactory).paginateList(getPageable(requestParams), query, allowedSortProperties);
}
Also used : TaskPaginateList(com.plumdo.flow.rest.task.TaskPaginateList) HistoricTaskInstanceQuery(org.flowable.task.api.history.HistoricTaskInstanceQuery) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 4 with HistoricTaskInstanceQuery

use of org.flowable.task.api.history.HistoricTaskInstanceQuery in project ruoyi-vue-pro by YunaiV.

the class BpmTaskServiceImpl method getDoneTaskPage.

@Override
public PageResult<BpmTaskDonePageItemRespVO> getDoneTaskPage(Long userId, BpmTaskDonePageReqVO pageVO) {
    // 查询已办任务
    HistoricTaskInstanceQuery taskQuery = historyService.createHistoricTaskInstanceQuery().finished().taskAssignee(// 分配给自己
    String.valueOf(userId)).orderByHistoricTaskInstanceEndTime().desc();
    if (StrUtil.isNotBlank(pageVO.getName())) {
        taskQuery.taskNameLike("%" + pageVO.getName() + "%");
    }
    if (pageVO.getBeginCreateTime() != null) {
        taskQuery.taskCreatedAfter(pageVO.getBeginCreateTime());
    }
    if (pageVO.getEndCreateTime() != null) {
        taskQuery.taskCreatedBefore(pageVO.getEndCreateTime());
    }
    // 执行查询
    List<HistoricTaskInstance> tasks = taskQuery.listPage(PageUtils.getStart(pageVO), pageVO.getPageSize());
    if (CollUtil.isEmpty(tasks)) {
        return PageResult.empty(taskQuery.count());
    }
    // 获得 TaskExtDO Map
    List<BpmTaskExtDO> bpmTaskExtDOs = taskExtMapper.selectListByTaskIds(convertSet(tasks, HistoricTaskInstance::getId));
    Map<String, BpmTaskExtDO> bpmTaskExtDOMap = convertMap(bpmTaskExtDOs, BpmTaskExtDO::getTaskId);
    // 获得 ProcessInstance Map
    Map<String, HistoricProcessInstance> historicProcessInstanceMap = processInstanceService.getHistoricProcessInstanceMap(convertSet(tasks, HistoricTaskInstance::getProcessInstanceId));
    // 获得 User Map
    Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertSet(historicProcessInstanceMap.values(), instance -> Long.valueOf(instance.getStartUserId())));
    // 拼接结果
    return new PageResult<>(BpmTaskConvert.INSTANCE.convertList2(tasks, bpmTaskExtDOMap, historicProcessInstanceMap, userMap), taskQuery.count());
}
Also used : java.util(java.util) AdminUserApi(cn.iocoder.yudao.module.system.api.user.AdminUserApi) TaskService(org.flowable.engine.TaskService) ServiceExceptionUtil.exception(cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception) BpmTaskConvert(cn.iocoder.yudao.module.bpm.convert.task.BpmTaskConvert) TaskQuery(org.flowable.task.api.TaskQuery) DeptApi(cn.iocoder.yudao.module.system.api.dept.DeptApi) ErrorCodeConstants(cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants) PageResult(cn.iocoder.yudao.framework.common.pojo.PageResult) ProcessInstance(org.flowable.engine.runtime.ProcessInstance) HistoricProcessInstance(org.flowable.engine.history.HistoricProcessInstance) TransactionSynchronizationManager(org.springframework.transaction.support.TransactionSynchronizationManager) Valid(javax.validation.Valid) BpmTaskExtDO(cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmTaskExtDO) Service(org.springframework.stereotype.Service) CollectionUtils.convertMap(cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap) CollectionUtils.convertSet(cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet) AdminUserRespDTO(cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO) Resource(javax.annotation.Resource) BpmMessageService(cn.iocoder.yudao.module.bpm.service.message.BpmMessageService) BpmTaskExtMapper(cn.iocoder.yudao.module.bpm.dal.mysql.task.BpmTaskExtMapper) Task(org.flowable.task.api.Task) BpmProcessInstanceResultEnum(cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum) CollUtil(cn.hutool.core.collection.CollUtil) StrUtil(cn.hutool.core.util.StrUtil) Slf4j(lombok.extern.slf4j.Slf4j) TransactionSynchronization(org.springframework.transaction.support.TransactionSynchronization) DeptRespDTO(cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO) HistoryService(org.flowable.engine.HistoryService) PageUtils(cn.iocoder.yudao.framework.common.util.object.PageUtils) HistoricTaskInstanceQuery(org.flowable.task.api.history.HistoricTaskInstanceQuery) NumberUtils(cn.iocoder.yudao.framework.common.util.number.NumberUtils) cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task(cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task) HistoricTaskInstance(org.flowable.task.api.history.HistoricTaskInstance) Transactional(org.springframework.transaction.annotation.Transactional) AdminUserRespDTO(cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO) HistoricTaskInstance(org.flowable.task.api.history.HistoricTaskInstance) BpmTaskExtDO(cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmTaskExtDO) HistoricProcessInstance(org.flowable.engine.history.HistoricProcessInstance) HistoricTaskInstanceQuery(org.flowable.task.api.history.HistoricTaskInstanceQuery) PageResult(cn.iocoder.yudao.framework.common.pojo.PageResult)

Example 5 with HistoricTaskInstanceQuery

use of org.flowable.task.api.history.HistoricTaskInstanceQuery 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

HistoricTaskInstanceQuery (org.flowable.task.api.history.HistoricTaskInstanceQuery)6 HistoricTaskInstance (org.flowable.task.api.history.HistoricTaskInstance)4 HistoricProcessInstance (org.flowable.engine.history.HistoricProcessInstance)3 TaskPaginateList (com.plumdo.flow.rest.task.TaskPaginateList)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 CollUtil (cn.hutool.core.collection.CollUtil)1 StrUtil (cn.hutool.core.util.StrUtil)1 ServiceExceptionUtil.exception (cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception)1 PageResult (cn.iocoder.yudao.framework.common.pojo.PageResult)1 CollectionUtils.convertMap (cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap)1 CollectionUtils.convertSet (cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet)1 NumberUtils (cn.iocoder.yudao.framework.common.util.number.NumberUtils)1 PageUtils (cn.iocoder.yudao.framework.common.util.object.PageUtils)1 cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task (cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task)1 BpmTaskConvert (cn.iocoder.yudao.module.bpm.convert.task.BpmTaskConvert)1 BpmTaskExtDO (cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmTaskExtDO)1 BpmTaskExtMapper (cn.iocoder.yudao.module.bpm.dal.mysql.task.BpmTaskExtMapper)1 ErrorCodeConstants (cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants)1 BpmProcessInstanceResultEnum (cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum)1 BpmMessageService (cn.iocoder.yudao.module.bpm.service.message.BpmMessageService)1