Search in sources :

Example 1 with TaskQuery

use of org.flowable.task.api.TaskQuery 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 2 with TaskQuery

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

the class Assert method assertCurrentUserTask.

/**
 * <p>
 * Assertion to check that a single user task can be completed by the given user.
 * </p>
 * <p>
 * The requested user can be the task assignee, or a member of a candidate group, or a candidate user.
 * </p>
 *
 * @param processInstanceId
 *            The process instance identifier
 * @param taskDefinitionKey
 *            The process definition key
 * @param user
 *            The task can be completed by the given user
 * @param taskService
 *            The Flowable's task service used to request the Flowable engine about task instances.
 * @return The task to complete
 */
public static Task assertCurrentUserTask(final String processInstanceId, final String taskDefinitionKey, final String user, final TaskService taskService) {
    final TaskQuery taskQuery = taskService.createTaskQuery();
    final Task nextTask = taskQuery.processInstanceId(processInstanceId).taskCandidateOrAssigned(user).singleResult();
    assertNotNull(nextTask);
    assertEquals(processInstanceId, nextTask.getProcessInstanceId());
    assertEquals(taskDefinitionKey, nextTask.getTaskDefinitionKey());
    return nextTask;
}
Also used : Task(org.flowable.task.api.Task) TaskQuery(org.flowable.task.api.TaskQuery)

Example 3 with TaskQuery

use of org.flowable.task.api.TaskQuery in project syncope by apache.

the class FlowableUserRequestHandler method getForms.

protected Pair<Integer, List<UserRequestForm>> getForms(final TaskQuery query, final int page, final int size, final List<OrderByClause> orderByClauses) {
    for (OrderByClause clause : orderByClauses) {
        boolean sorted = true;
        switch(clause.getField().trim()) {
            case "bpmnProcess":
                query.orderByProcessDefinitionId();
                break;
            case "executionId":
                query.orderByExecutionId();
                break;
            case "taskId":
                query.orderByTaskId();
                break;
            case "createTime":
                query.orderByTaskCreateTime();
                break;
            case "dueDate":
                query.orderByTaskDueDate();
                break;
            case "assignee":
                query.orderByTaskAssignee();
                break;
            default:
                LOG.warn("Form sort request by {}: unsupported, ignoring", clause.getField().trim());
                sorted = false;
        }
        if (sorted) {
            if (clause.getDirection() == OrderByClause.Direction.ASC) {
                query.asc();
            } else {
                query.desc();
            }
        }
    }
    List<UserRequestForm> result = query.listPage(size * (page <= 0 ? 0 : page - 1), size).stream().map(task -> task instanceof HistoricTaskInstance ? FlowableUserRequestHandler.this.getForm((HistoricTaskInstance) task) : FlowableUserRequestHandler.this.getForm(task)).collect(Collectors.toList());
    return Pair.of((int) query.count(), result);
}
Also used : UserUR(org.apache.syncope.common.lib.request.UserUR) WorkflowException(org.apache.syncope.core.workflow.api.WorkflowException) LoggerFactory(org.slf4j.LoggerFactory) ResourceOperation(org.apache.syncope.common.lib.types.ResourceOperation) StringUtils(org.apache.commons.lang3.StringUtils) UserRequestFormPropertyType(org.apache.syncope.common.lib.types.UserRequestFormPropertyType) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) WorkflowTaskExecInput(org.apache.syncope.common.lib.to.WorkflowTaskExecInput) UserDataBinder(org.apache.syncope.core.provisioning.api.data.UserDataBinder) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) SyncDeltaType(org.identityconnectors.framework.common.objects.SyncDeltaType) AnyLifecycleEvent(org.apache.syncope.core.provisioning.api.event.AnyLifecycleEvent) FormType(org.flowable.engine.form.FormType) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) UserWorkflowResult(org.apache.syncope.core.provisioning.api.UserWorkflowResult) Set(java.util.Set) DomainProcessEngine(org.apache.syncope.core.flowable.support.DomainProcessEngine) Task(org.flowable.task.api.Task) Collectors(java.util.stream.Collectors) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) UserRequestHandler(org.apache.syncope.core.flowable.api.UserRequestHandler) Objects(java.util.Objects) EntityFactory(org.apache.syncope.core.persistence.api.entity.EntityFactory) List(java.util.List) UserRequestFormPropertyValue(org.apache.syncope.common.lib.to.UserRequestFormPropertyValue) Optional(java.util.Optional) UserRequest(org.apache.syncope.common.lib.to.UserRequest) FormProperty(org.flowable.engine.form.FormProperty) BeanUtils(org.springframework.beans.BeanUtils) TaskFormData(org.flowable.engine.form.TaskFormData) PasswordPatch(org.apache.syncope.common.lib.request.PasswordPatch) TaskQuery(org.flowable.task.api.TaskQuery) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) HashMap(java.util.HashMap) ExecutionEntity(org.flowable.engine.impl.persistence.entity.ExecutionEntity) ProcessInstance(org.flowable.engine.runtime.ProcessInstance) FlowableException(org.flowable.common.engine.api.FlowableException) HashSet(java.util.HashSet) IdentityLinkType(org.flowable.identitylink.api.IdentityLinkType) UserRequestFormProperty(org.apache.syncope.common.lib.to.UserRequestFormProperty) HistoricVariableInstance(org.flowable.variable.api.history.HistoricVariableInstance) Propagation(org.springframework.transaction.annotation.Propagation) FlowableIllegalArgumentException(org.flowable.common.engine.api.FlowableIllegalArgumentException) HistoricActivityInstance(org.flowable.engine.history.HistoricActivityInstance) Logger(org.slf4j.Logger) User(org.apache.syncope.core.persistence.api.entity.user.User) DropdownValueProvider(org.apache.syncope.core.flowable.api.DropdownValueProvider) UserTO(org.apache.syncope.common.lib.to.UserTO) ApplicationContextProvider(org.apache.syncope.core.spring.ApplicationContextProvider) HistoricTaskInstance(org.flowable.task.api.history.HistoricTaskInstance) Collections(java.util.Collections) Any(org.apache.syncope.core.persistence.api.entity.Any) UserRequestForm(org.apache.syncope.common.lib.to.UserRequestForm) HistoricFormPropertyEntity(org.flowable.engine.impl.persistence.entity.HistoricFormPropertyEntity) Transactional(org.springframework.transaction.annotation.Transactional) UserRequestForm(org.apache.syncope.common.lib.to.UserRequestForm) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) HistoricTaskInstance(org.flowable.task.api.history.HistoricTaskInstance)

Example 4 with TaskQuery

use of org.flowable.task.api.TaskQuery in project SurveyKing by javahuang.

the class FlowServiceImpl method statics.

@Override
public FlowStaticsView statics() {
    FlowStaticsView statics = new FlowStaticsView();
    // 获取我的待办
    TaskQuery taskQuery = taskService.createTaskQuery().active();
    String userId = SecurityContextUtils.getUserId();
    taskQuery.or().taskCandidateUser(userId).taskAssignee(userId).endOr().orderByTaskCreateTime().desc();
    statics.setTodo(taskQuery.count());
    // 获取我的已办
    statics.setFinished(flowOperationService.count(Wrappers.<FlowOperation>lambdaQuery().eq(FlowOperation::getTaskType, FlowTaskType.userTask).ne(FlowOperation::getApprovalType, FlowApprovalType.SAVE)));
    // 获取我能发起的,任务在审批中的
    statics.setSelfCreated(flowInstanceService.count(Wrappers.<FlowInstance>lambdaQuery().eq(FlowInstance::getCreateBy, SecurityContextUtils.getUserId()).eq(FlowInstance::getStatus, FlowInstanceStatus.APPROVING)));
    // 获取抄送给我的
    return statics;
}
Also used : TaskQuery(org.flowable.task.api.TaskQuery)

Example 5 with TaskQuery

use of org.flowable.task.api.TaskQuery in project SurveyKing by javahuang.

the class FlowServiceImpl method getTodo.

private PaginationResponse<FlowTaskView> getTodo(FlowTaskQuery query) {
    TaskQuery taskQuery = taskService.createTaskQuery().active();
    String userId = SecurityContextUtils.getUserId();
    // https://forum.flowable.org/t/sql-exception-with-task-query-after-upgrade-to-6-7-0/8334
    taskQuery.processDefinitionKey(query.getProjectId()).or().taskCandidateUser(userId).taskAssignee(userId).endOr().includeProcessVariables().orderByTaskCreateTime().desc();
    int firstResult = (query.getCurrent() - 1) * query.getPageSize();
    List<Task> taskList = taskQuery.listPage(firstResult, query.getPageSize());
    long totalCount = taskQuery.count();
    List<FlowTaskView> viewList = taskList.stream().map(task -> {
        FlowTaskView taskView = new FlowTaskView();
        taskView.setId(task.getId());
        taskView.setCreateAt(task.getCreateTime());
        taskView.setProjectId(query.getProjectId());
        String answerId = (String) task.getProcessVariables().get(FlowConstant.VARIABLE_ANSWER_KEY);
        taskView.setAnswerId(answerId);
        taskView.setActivityId(task.getTaskDefinitionKey());
        taskView.setProcessInstanceId(task.getProcessInstanceId());
        return taskView;
    }).collect(Collectors.toList());
    return new PaginationResponse<>(totalCount, viewList);
}
Also used : java.util(java.util) TaskService(org.flowable.engine.TaskService) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) FlowEntryElementModelMapper(cn.surveyking.server.flow.domain.mapper.FlowEntryElementModelMapper) XMLInputFactory(javax.xml.stream.XMLInputFactory) RequiredArgsConstructor(lombok.RequiredArgsConstructor) BpmnXMLConverter(org.flowable.bpmn.converter.BpmnXMLConverter) TaskQuery(org.flowable.task.api.TaskQuery) Cleanup(lombok.Cleanup) cn.surveyking.server.flow.domain.model(cn.surveyking.server.flow.domain.model) ContextHelper(cn.surveyking.server.core.uitls.ContextHelper) UserService(cn.surveyking.server.service.UserService) cn.surveyking.server.flow.service(cn.surveyking.server.flow.service) Execution(org.flowable.engine.runtime.Execution) PaginationResponse(cn.surveyking.server.core.common.PaginationResponse) ProjectService(cn.surveyking.server.service.ProjectService) SchemaParser(cn.surveyking.server.core.uitls.SchemaParser) ByteArrayInputStream(java.io.ByteArrayInputStream) XMLStreamReader(javax.xml.stream.XMLStreamReader) Service(org.springframework.stereotype.Service) BpmnModel(org.flowable.bpmn.model.BpmnModel) RuntimeService(org.flowable.engine.RuntimeService) Wrappers(com.baomidou.mybatisplus.core.toolkit.Wrappers) FlowableRuntimeException(cn.surveyking.server.flow.exception.FlowableRuntimeException) FlowEntryModelMapper(cn.surveyking.server.flow.domain.mapper.FlowEntryModelMapper) RevertTaskHandler(cn.surveyking.server.flow.service.impl.taskHandler.RevertTaskHandler) SecurityContextUtils(cn.surveyking.server.core.uitls.SecurityContextUtils) TaskHandler(cn.surveyking.server.flow.service.impl.taskHandler.TaskHandler) Deployment(org.flowable.engine.repository.Deployment) Task(org.flowable.task.api.Task) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) cn.surveyking.server.domain.dto(cn.surveyking.server.domain.dto) cn.surveyking.server.flow.domain.dto(cn.surveyking.server.flow.domain.dto) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) cn.surveyking.server.flow.constant(cn.surveyking.server.flow.constant) FlowOperationModelMapper(cn.surveyking.server.flow.domain.mapper.FlowOperationModelMapper) RepositoryService(org.flowable.engine.RepositoryService) AnswerService(cn.surveyking.server.service.AnswerService) Transactional(org.springframework.transaction.annotation.Transactional) StringUtils(org.springframework.util.StringUtils) InputStream(java.io.InputStream) Task(org.flowable.task.api.Task) TaskQuery(org.flowable.task.api.TaskQuery) PaginationResponse(cn.surveyking.server.core.common.PaginationResponse)

Aggregations

TaskQuery (org.flowable.task.api.TaskQuery)11 Task (org.flowable.task.api.Task)7 Transactional (org.springframework.transaction.annotation.Transactional)5 java.util (java.util)3 ProcessDefinition (org.flowable.engine.repository.ProcessDefinition)3 CollUtil (cn.hutool.core.collection.CollUtil)2 StrUtil (cn.hutool.core.util.StrUtil)2 ServiceExceptionUtil.exception (cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception)2 PageResult (cn.iocoder.yudao.framework.common.pojo.PageResult)2 CollectionUtils.convertMap (cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap)2 CollectionUtils.convertSet (cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet)2 NumberUtils (cn.iocoder.yudao.framework.common.util.number.NumberUtils)2 PageUtils (cn.iocoder.yudao.framework.common.util.object.PageUtils)2 cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task (cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task)2 BpmTaskConvert (cn.iocoder.yudao.module.bpm.convert.task.BpmTaskConvert)2 BpmTaskExtDO (cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmTaskExtDO)2 BpmTaskExtMapper (cn.iocoder.yudao.module.bpm.dal.mysql.task.BpmTaskExtMapper)2 ErrorCodeConstants (cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants)2 BpmProcessInstanceResultEnum (cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum)2 BpmMessageService (cn.iocoder.yudao.module.bpm.service.message.BpmMessageService)2