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);
}
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;
}
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);
}
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;
}
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);
}
Aggregations