| | |
| | | /** |
| | | * BladeX Commercial License Agreement |
| | | * Copyright (c) 2018-2099, https://bladex.cn. All rights reserved. |
| | | * <p> |
| | | * Use of this software is governed by the Commercial License Agreement |
| | | * obtained after purchasing a license from BladeX. |
| | | * <p> |
| | | * 1. This software is for development use only under a valid license |
| | | * from BladeX. |
| | | * <p> |
| | | * 2. Redistribution of this software's source code to any third party |
| | | * without a commercial license is strictly prohibited. |
| | | * <p> |
| | | * 3. Licensees may copyright their own code but cannot use segments |
| | | * from this software for such purposes. Copyright of this software |
| | | * remains with BladeX. |
| | | * <p> |
| | | * Using this software signifies agreement to this License, and the software |
| | | * must not be used for illegal purposes. |
| | | * <p> |
| | | * THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is |
| | | * not liable for any claims arising from secondary or illegal development. |
| | | * <p> |
| | | * Author: Chill Zhuang (bladejava@qq.com) |
| | | */ |
| | | |
| | | package org.springblade.mdm.flow.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import lombok.AllArgsConstructor; |
| | | import org.flowable.engine.HistoryService; |
| | | import org.flowable.engine.RuntimeService; |
| | | import org.flowable.engine.TaskService; |
| | | import org.flowable.engine.history.HistoricProcessInstance; |
| | | import org.flowable.engine.history.HistoricProcessInstanceQuery; |
| | | import org.flowable.engine.task.Comment; |
| | | import org.flowable.task.api.Task; |
| | | import org.flowable.task.api.TaskInfoQuery; |
| | | import org.flowable.task.api.TaskQuery; |
| | | import org.flowable.task.api.history.HistoricTaskInstance; |
| | | import org.flowable.task.api.history.HistoricTaskInstanceQuery; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.support.Kv; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.core.tool.utils.StringPool; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | import org.springblade.flow.core.constant.ProcessConstant; |
| | | import org.springblade.flow.core.pojo.entity.BladeFlow; |
| | | import org.springblade.flow.core.utils.TaskUtil; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.*; |
| | | |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | | import org.springblade.mdm.basesetting.machine.service.MachineService; |
| | | import org.springblade.mdm.commons.service.ParamService; |
| | | import org.springblade.mdm.flow.constants.FlowVariableConstant; |
| | | import org.springblade.mdm.flow.entity.FlowProgramFile; |
| | | import org.springblade.mdm.flow.entity.MdmFlowProcess; |
| | | import org.springblade.mdm.flow.util.MdmFlowCache; |
| | | import org.springblade.mdm.flow.vo.FlowVO; |
| | | import org.springblade.mdm.flow.vo.TodoQueryVO; |
| | | import org.springblade.system.feign.IUserClient; |
| | | import org.springblade.system.pojo.entity.User; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Date; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 流程业务实现类 |
| | | * |
| | | * @author Chill |
| | | * @author yangys |
| | | */ |
| | | @Service |
| | | @AllArgsConstructor |
| | | public class FlowBusinessService { |
| | | |
| | | private final RuntimeService runtimeService; |
| | | private final TaskService taskService; |
| | | private final HistoryService historyService; |
| | | |
| | | |
| | | public IPage<BladeFlow> selectTodoPage(IPage<BladeFlow> page, String keyword) { |
| | | private final IUserClient userClient; |
| | | private final FlowProgramFileService flowProgramFileService; |
| | | private final ParamService paramService; |
| | | private final MachineService machineService; |
| | | /** |
| | | * 查询我的流程(个人待办列表) |
| | | * @param page 分页信息 |
| | | * @param createTimeBegin 创建时间开始 |
| | | * @param createTimeEnd 创建时间截止 |
| | | * @param keyword 查询关键字 |
| | | * @return |
| | | */ |
| | | public IPage<FlowVO> selectTodoPage(IPage<FlowVO> page, TodoQueryVO queryVO) {//LocalDateTime createTimeBegin, LocalDateTime createTimeEnd, String keyword |
| | | //String taskUser = TaskUtil.getTaskUser(); |
| | | String userId = ""+AuthUtil.getUserId(); |
| | | List<BladeFlow> flowList = new LinkedList<>(); |
| | | String userId = "" + AuthUtil.getUserId(); |
| | | List<FlowVO> flowList = new LinkedList<>(); |
| | | |
| | | TaskQuery todoQuery = taskService.createTaskQuery().taskAssignee(userId).active().includeProcessVariables(); |
| | | |
| | | if(Func.isNotEmpty(keyword)){ |
| | | todoQuery.or(); |
| | | if(queryVO.getMachineSpec() != null){ |
| | | if(queryVO.getMachineSpec().length==1) {//2个为全选 |
| | | //查询车床代码集合 |
| | | String turnVal = paramService.turninngValue(); |
| | | List<Machine> machines = machineService.lambdaQuery().eq(Machine::getMachineSpec, turnVal).eq(Machine::getStatus, Machine.STATUS_ENABLE).list(); |
| | | List<String> turnMachineCodes = machines.stream().map(Machine::getCode).toList(); |
| | | |
| | | todoQuery.processVariableValueLike("processNo",keyword); |
| | | todoQuery.processVariableValueLike("machineCode",keyword); |
| | | todoQuery.processVariableValueLike("machineMode",keyword); |
| | | List<String> specs = Arrays.asList(queryVO.getMachineSpec()); |
| | | if (specs.contains("1")) { |
| | | //车床 |
| | | todoQuery.or(); |
| | | for (String mCode : turnMachineCodes) { |
| | | todoQuery.processVariableValueEquals(FlowVariableConstant.MACHINE_CODE, mCode); |
| | | } |
| | | todoQuery.endOr(); |
| | | } else { |
| | | //加工中心 |
| | | todoQuery.or(); |
| | | for (String mCode : turnMachineCodes) { |
| | | todoQuery.processVariableValueNotEquals(FlowVariableConstant.MACHINE_CODE, mCode); |
| | | } |
| | | todoQuery.endOr(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | todoQuery.processVariableValueLike("processName",keyword); |
| | | todoQuery.processVariableValueLike("processEdition",keyword); |
| | | |
| | | todoQuery.processVariableValueLike("craftEdition",keyword); |
| | | //TODO 多个字段都要匹配 |
| | | |
| | | todoQuery.endOr(); |
| | | if (Func.isNotEmpty(queryVO.getCreateTimeBegin())) { |
| | | todoQuery.taskCreatedAfter(DateUtil.toDate(queryVO.getCreateTimeBegin())); |
| | | } |
| | | if (Func.isNotEmpty(queryVO.getCreateTimeEnd())) { |
| | | todoQuery.taskCreatedBefore(DateUtil.toDate(queryVO.getCreateTimeEnd())); |
| | | } |
| | | if (Func.isNotEmpty(queryVO.getKeyword())) { |
| | | addKeywordCondition(todoQuery, queryVO.getKeyword()); |
| | | } |
| | | |
| | | todoQuery.orderByTaskCreateTime().desc(); |
| | | //List<Task> listt = todoQuery.list(); |
| | | |
| | | // 已签收的任务.caseVariableValueLike("processNo",keyword) |
| | | /* |
| | | TaskQuery todoQuery = taskService.createTaskQuery().taskAssignee(userId).active() |
| | | .includeProcessVariables().orderByTaskCreateTime().desc(); |
| | | |
| | | */ |
| | | |
| | | // 构建列表数据 |
| | | BladeFlow bladeFlow = new BladeFlow(); |
| | | buildFlowTaskList(bladeFlow, flowList, todoQuery, "todo");//FlowEngineConstant.STATUS_TODO |
| | | FlowVO bladeFlow = new FlowVO(); |
| | | buildFlowTaskList(bladeFlow, flowList, todoQuery,page.getCurrent(),page.getSize()); |
| | | |
| | | // 计算总数 |
| | | long count = todoQuery.count(); |
| | | // 设置页数 |
| | | page.setSize(count); |
| | | |
| | | // 设置总数 |
| | | page.setTotal(count); |
| | | // 设置数据 |
| | | page.setRecords(flowList); |
| | | return page; |
| | | } |
| | | /* |
| | | @Override |
| | | public IPage<BladeFlow> selectSendPage(IPage<BladeFlow> page, BladeFlow bladeFlow) { |
| | | String taskUser = TaskUtil.getTaskUser(); |
| | | List<BladeFlow> flowList = new LinkedList<>(); |
| | | //TaskInfoQuery |
| | | //void addKeywordCondition(TaskQuery todoQuery,String keyword) { |
| | | void addKeywordCondition(TaskInfoQuery todoQuery, String keyword) { |
| | | if(Func.isNotEmpty(keyword)) { |
| | | String likeVal = "%" + keyword + "%"; |
| | | todoQuery.or(); |
| | | todoQuery.processVariableValueLike(FlowVariableConstant.TITLE,likeVal); |
| | | todoQuery.processVariableValueLike(FlowVariableConstant.PROCESS_NO, likeVal); |
| | | todoQuery.processVariableValueLike(FlowVariableConstant.MACHINE_CODE, likeVal); |
| | | todoQuery.processVariableValueLike(FlowVariableConstant.MACHINE_MODE, likeVal); |
| | | todoQuery.processVariableValueLike(FlowVariableConstant.PROCESS_NAME, likeVal); |
| | | todoQuery.processVariableValueLike(FlowVariableConstant.PROCESS_EDITION, likeVal); |
| | | todoQuery.processVariableValueLike(FlowVariableConstant.CRAFT_EDITION, likeVal); |
| | | |
| | | HistoricProcessInstanceQuery historyQuery = historyService.createHistoricProcessInstanceQuery().startedBy(taskUser).orderByProcessInstanceStartTime().desc(); |
| | | |
| | | if (bladeFlow.getCategory() != null) { |
| | | historyQuery.processDefinitionCategory(bladeFlow.getCategory()); |
| | | todoQuery.processDefinitionNameLike(likeVal); |
| | | todoQuery.endOr(); |
| | | } |
| | | if (bladeFlow.getProcessDefinitionName() != null) { |
| | | historyQuery.processDefinitionName(bladeFlow.getProcessDefinitionName()); |
| | | } |
| | | if (bladeFlow.getBeginDate() != null) { |
| | | historyQuery.startedAfter(bladeFlow.getBeginDate()); |
| | | } |
| | | if (bladeFlow.getEndDate() != null) { |
| | | historyQuery.startedBefore(bladeFlow.getEndDate()); |
| | | } |
| | | |
| | | // 查询列表 |
| | | List<HistoricProcessInstance> historyList = historyQuery.listPage(Func.toInt((page.getCurrent() - 1) * page.getSize()), Func.toInt(page.getSize())); |
| | | |
| | | historyList.forEach(historicProcessInstance -> { |
| | | BladeFlow flow = new BladeFlow(); |
| | | // historicProcessInstance |
| | | flow.setCreateTime(historicProcessInstance.getStartTime()); |
| | | flow.setEndTime(historicProcessInstance.getEndTime()); |
| | | flow.setVariables(historicProcessInstance.getProcessVariables()); |
| | | String[] businessKey = Func.toStrArray(StringPool.COLON, historicProcessInstance.getBusinessKey()); |
| | | if (businessKey.length > 1) { |
| | | flow.setBusinessTable(businessKey[0]); |
| | | flow.setBusinessId(businessKey[1]); |
| | | } |
| | | flow.setHistoryActivityName(historicProcessInstance.getName()); |
| | | flow.setProcessInstanceId(historicProcessInstance.getId()); |
| | | flow.setHistoryProcessInstanceId(historicProcessInstance.getId()); |
| | | // ProcessDefinition |
| | | FlowProcess processDefinition = FlowCache.getProcessDefinition(historicProcessInstance.getProcessDefinitionId()); |
| | | flow.setProcessDefinitionId(processDefinition.getId()); |
| | | flow.setProcessDefinitionName(processDefinition.getName()); |
| | | flow.setProcessDefinitionVersion(processDefinition.getVersion()); |
| | | flow.setProcessDefinitionKey(processDefinition.getKey()); |
| | | flow.setCategory(processDefinition.getCategory()); |
| | | flow.setCategoryName(FlowCache.getCategoryName(processDefinition.getCategory())); |
| | | flow.setProcessInstanceId(historicProcessInstance.getId()); |
| | | // HistoricTaskInstance |
| | | List<HistoricTaskInstance> historyTasks = historyService.createHistoricTaskInstanceQuery().processInstanceId(historicProcessInstance.getId()).orderByHistoricTaskInstanceEndTime().desc().list(); |
| | | if (Func.isNotEmpty(historyTasks)) { |
| | | HistoricTaskInstance historyTask = historyTasks.iterator().next(); |
| | | flow.setTaskId(historyTask.getId()); |
| | | flow.setTaskName(historyTask.getName()); |
| | | flow.setTaskDefinitionKey(historyTask.getTaskDefinitionKey()); |
| | | } |
| | | // Status |
| | | if (historicProcessInstance.getEndActivityId() != null) { |
| | | flow.setProcessIsFinished(FlowEngineConstant.STATUS_FINISHED); |
| | | } else { |
| | | flow.setProcessIsFinished(FlowEngineConstant.STATUS_UNFINISHED); |
| | | } |
| | | flow.setStatus(FlowEngineConstant.STATUS_FINISH); |
| | | flowList.add(flow); |
| | | }); |
| | | |
| | | // 计算总数 |
| | | long count = historyQuery.count(); |
| | | // 设置总数 |
| | | page.setTotal(count); |
| | | page.setRecords(flowList); |
| | | return page; |
| | | } |
| | | |
| | | @Override |
| | | public IPage<BladeFlow> selectDonePage(IPage<BladeFlow> page, BladeFlow bladeFlow) { |
| | | String taskUser = TaskUtil.getTaskUser(); |
| | | List<BladeFlow> flowList = new LinkedList<>(); |
| | | |
| | | HistoricTaskInstanceQuery doneQuery = historyService.createHistoricTaskInstanceQuery().taskAssignee(taskUser).finished() |
| | | .includeProcessVariables().orderByHistoricTaskInstanceEndTime().desc(); |
| | | |
| | | if (bladeFlow.getCategory() != null) { |
| | | doneQuery.processCategoryIn(Func.toStrList(bladeFlow.getCategory())); |
| | | } |
| | | if (bladeFlow.getProcessDefinitionName() != null) { |
| | | doneQuery.processDefinitionName(bladeFlow.getProcessDefinitionName()); |
| | | } |
| | | if (bladeFlow.getBeginDate() != null) { |
| | | doneQuery.taskCompletedAfter(bladeFlow.getBeginDate()); |
| | | } |
| | | if (bladeFlow.getEndDate() != null) { |
| | | doneQuery.taskCompletedBefore(bladeFlow.getEndDate()); |
| | | } |
| | | |
| | | // 查询列表 |
| | | List<HistoricTaskInstance> doneList = doneQuery.listPage(Func.toInt((page.getCurrent() - 1) * page.getSize()), Func.toInt(page.getSize())); |
| | | doneList.forEach(historicTaskInstance -> { |
| | | BladeFlow flow = new BladeFlow(); |
| | | flow.setTaskId(historicTaskInstance.getId()); |
| | | flow.setTaskDefinitionKey(historicTaskInstance.getTaskDefinitionKey()); |
| | | flow.setTaskName(historicTaskInstance.getName()); |
| | | flow.setAssignee(historicTaskInstance.getAssignee()); |
| | | flow.setCreateTime(historicTaskInstance.getCreateTime()); |
| | | flow.setExecutionId(historicTaskInstance.getExecutionId()); |
| | | flow.setHistoryTaskEndTime(historicTaskInstance.getEndTime()); |
| | | flow.setVariables(historicTaskInstance.getProcessVariables()); |
| | | |
| | | FlowProcess processDefinition = FlowCache.getProcessDefinition(historicTaskInstance.getProcessDefinitionId()); |
| | | flow.setProcessDefinitionId(processDefinition.getId()); |
| | | flow.setProcessDefinitionName(processDefinition.getName()); |
| | | flow.setProcessDefinitionKey(processDefinition.getKey()); |
| | | flow.setProcessDefinitionVersion(processDefinition.getVersion()); |
| | | flow.setCategory(processDefinition.getCategory()); |
| | | flow.setCategoryName(FlowCache.getCategoryName(processDefinition.getCategory())); |
| | | |
| | | flow.setProcessInstanceId(historicTaskInstance.getProcessInstanceId()); |
| | | flow.setHistoryProcessInstanceId(historicTaskInstance.getProcessInstanceId()); |
| | | HistoricProcessInstance historicProcessInstance = getHistoricProcessInstance((historicTaskInstance.getProcessInstanceId())); |
| | | if (Func.isNotEmpty(historicProcessInstance)) { |
| | | String[] businessKey = Func.toStrArray(StringPool.COLON, historicProcessInstance.getBusinessKey()); |
| | | flow.setBusinessTable(businessKey[0]); |
| | | flow.setBusinessId(businessKey[1]); |
| | | if (historicProcessInstance.getEndActivityId() != null) { |
| | | flow.setProcessIsFinished(FlowEngineConstant.STATUS_FINISHED); |
| | | } else { |
| | | flow.setProcessIsFinished(FlowEngineConstant.STATUS_UNFINISHED); |
| | | } |
| | | } |
| | | flow.setStatus(FlowEngineConstant.STATUS_FINISH); |
| | | flowList.add(flow); |
| | | }); |
| | | // 计算总数 |
| | | long count = doneQuery.count(); |
| | | // 设置总数 |
| | | page.setTotal(count); |
| | | page.setRecords(flowList); |
| | | return page; |
| | | } |
| | | |
| | | @Override |
| | | public boolean completeTask(BladeFlow flow) { |
| | | String taskId = flow.getTaskId(); |
| | | String processInstanceId = flow.getProcessInstanceId(); |
| | | String comment = Func.toStr(flow.getComment(), ProcessConstant.PASS_COMMENT); |
| | | // 增加评论 |
| | | if (StringUtil.isNoneBlank(processInstanceId, comment)) { |
| | | taskService.addComment(taskId, processInstanceId, comment); |
| | | } |
| | | // 创建变量 |
| | | Map<String, Object> variables = flow.getVariables(); |
| | | if (variables == null) { |
| | | variables = Kv.create(); |
| | | } |
| | | variables.put(ProcessConstant.PASS_KEY, flow.isPass()); |
| | | // 完成任务 |
| | | taskService.complete(taskId, variables); |
| | | return true; |
| | | } |
| | | */ |
| | | /** |
| | | * 构建流程 |
| | | * |
| | | * @param bladeFlow 流程通用类 |
| | | * @param flowList 流程列表 |
| | | * @param taskQuery 任务查询类 |
| | | * @param status 状态 |
| | | */ |
| | | private void buildFlowTaskList(BladeFlow bladeFlow, List<BladeFlow> flowList, TaskQuery taskQuery, String status) { |
| | | private void buildFlowTaskList(FlowVO bladeFlow, List<FlowVO> flowList, TaskQuery taskQuery,Long currentPage,Long pageSize) { |
| | | if (bladeFlow.getCategory() != null) { |
| | | taskQuery.processCategoryIn(Func.toStrList(bladeFlow.getCategory())); |
| | | } |
| | |
| | | if (bladeFlow.getEndDate() != null) { |
| | | taskQuery.taskCreatedBefore(bladeFlow.getEndDate()); |
| | | } |
| | | List<Task> tasks = taskQuery.list(); |
| | | |
| | | //List<Task> tasks = taskQuery.list(); |
| | | long total = taskQuery.count(); |
| | | Long firstResult = (currentPage-1)*pageSize; |
| | | List<Task> tasks = taskQuery.listPage(Func.toInt(firstResult), Func.toInt(pageSize)); |
| | | tasks.forEach(task -> { |
| | | BladeFlow flow = new BladeFlow(); |
| | | FlowVO flow = new FlowVO(); |
| | | flow.setTaskId(task.getId()); |
| | | flow.setTaskDefinitionKey(task.getTaskDefinitionKey()); |
| | | flow.setTaskName(task.getName()); |
| | |
| | | flow.setClaimTime(task.getClaimTime()); |
| | | flow.setExecutionId(task.getExecutionId()); |
| | | flow.setVariables(task.getProcessVariables()); |
| | | flow.setDueDate(task.getDueDate()); |
| | | |
| | | flow.setProcessDefinitionId(task.getProcessDefinitionId()); |
| | | //flow.setProcessDefinitionName(task.getprocessd); |
| | | |
| | | //flow.setProcessDefinitionKey(processDefinition.getKey()); |
| | | //flow.setProcessDefinitionVersion(processDefinition.getVersion()); |
| | | flow.setFile(getFileString(task.getProcessInstanceId())); |
| | | flow.setProcessInstanceId(task.getProcessInstanceId()); |
| | | /* |
| | | HistoricProcessInstance historicProcessInstance = getHistoricProcessInstance(task.getProcessInstanceId()); |
| | | if (Func.isNotEmpty(historicProcessInstance)) { |
| | | String[] businessKey = Func.toStrArray(StringPool.COLON, historicProcessInstance.getBusinessKey()); |
| | | flow.setBusinessTable(businessKey[0]); |
| | | flow.setBusinessId(businessKey[1]); |
| | | }*/ |
| | | |
| | | // 查询流程实例创建时间 |
| | | HistoricProcessInstance historicProcess = historyService.createHistoricProcessInstanceQuery() |
| | | .processInstanceId(task.getProcessInstanceId()) |
| | | .singleResult(); |
| | | flow.setProcessCreateTime(historicProcess.getStartTime()); |
| | | |
| | | R<User> ru = userClient.userInfoById(Long.valueOf(historicProcess.getStartUserId())); |
| | | if(ru.isSuccess()) { |
| | | flow.setStartUserName(ru.getData().getName()); |
| | | } |
| | | List<Comment> comments = lastStepComments(task);//taskService.getTaskComments(task.getId()); |
| | | if(!comments.isEmpty()){ |
| | | flow.setComment(comments.get(0).getFullMessage()); |
| | | } |
| | | |
| | | MdmFlowProcess processDefinition = MdmFlowCache.getProcessDefinition(task.getProcessDefinitionId()); |
| | | |
| | |
| | | flow.setProcessDefinitionVersion(processDefinition.getVersion()); |
| | | flow.setProcessInstanceId(task.getProcessInstanceId()); |
| | | //flow.setStatus(status); |
| | | /* |
| | | */ |
| | | |
| | | flowList.add(flow); |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 获取历史流程 |
| | | * |
| | | * @param processInstanceId 流程实例id |
| | | * @return HistoricProcessInstance |
| | | */ |
| | | private HistoricProcessInstance getHistoricProcessInstance(String processInstanceId) { |
| | | return historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); |
| | | List<Comment> lastStepComments(Task currentTask){ |
| | | List<HistoricTaskInstance> previousTasks = historyService.createHistoricActivityInstanceQuery() |
| | | .processInstanceId(currentTask.getProcessInstanceId()) |
| | | .activityType("userTask") // 直接查询用户任务类型 |
| | | .orderByHistoricActivityInstanceEndTime() |
| | | .desc() |
| | | .list() |
| | | .stream() |
| | | .filter(activity -> !activity.getActivityId().equals(currentTask.getTaskDefinitionKey())) |
| | | .map(activity -> historyService.createHistoricTaskInstanceQuery() |
| | | .taskDefinitionKey(activity.getActivityId()) |
| | | .processInstanceId(activity.getProcessInstanceId()) |
| | | .orderByHistoricTaskInstanceEndTime() |
| | | .desc() |
| | | .list() |
| | | ) |
| | | .flatMap(List::stream) |
| | | .toList(); |
| | | List<Comment> comments; |
| | | if (!previousTasks.isEmpty()) { |
| | | return taskService.getTaskComments(previousTasks.get(0).getId()); |
| | | |
| | | }else{ |
| | | return Collections.emptyList(); |
| | | } |
| | | } |
| | | |
| | | public IPage<BladeFlow> selectAllTaskPage(IPage<BladeFlow> page, String keyword) { |
| | | |
| | | List<BladeFlow> flowList = new LinkedList<>(); |
| | | public IPage<FlowVO> selectAllTaskPage(IPage<FlowVO> page, String keyword) { |
| | | |
| | | List<FlowVO> flowList = new LinkedList<>(); |
| | | |
| | | TaskQuery todoQuery = taskService.createTaskQuery().active().includeProcessVariables(); |
| | | |
| | | if(Func.isNotEmpty(keyword)){ |
| | | todoQuery.or(); |
| | | |
| | | todoQuery.processVariableValueLike("processNo",keyword); |
| | | todoQuery.processVariableValueLike("machineCode",keyword); |
| | | todoQuery.processVariableValueLike("machineMode",keyword); |
| | | |
| | | todoQuery.processVariableValueLike("processName",keyword); |
| | | todoQuery.processVariableValueLike("processEdition",keyword); |
| | | |
| | | todoQuery.processVariableValueLike("craftEdition",keyword); |
| | | //TODO 多个字段都要匹配 |
| | | |
| | | todoQuery.endOr(); |
| | | } |
| | | addKeywordCondition(todoQuery, keyword); |
| | | |
| | | todoQuery.orderByTaskCreateTime().desc(); |
| | | |
| | | // 构建列表数据 |
| | | BladeFlow bladeFlow = new BladeFlow(); |
| | | buildFlowTaskList(bladeFlow, flowList, todoQuery, "todo");//FlowEngineConstant.STATUS_TODO |
| | | FlowVO bladeFlow = new FlowVO(); |
| | | buildFlowTaskList(bladeFlow, flowList, todoQuery,page.getCurrent(),page.getSize());//FlowEngineConstant.STATUS_TODO |
| | | |
| | | // 计算总数 |
| | | long count = todoQuery.count(); |
| | | // 设置页数 |
| | | page.setSize(count); |
| | | //page.setSize(count); |
| | | // 设置总数 |
| | | page.setTotal(count); |
| | | // 设置数据 |
| | |
| | | |
| | | /** |
| | | * 超时任务查询 |
| | | * @param page |
| | | * @param keyword |
| | | * @return |
| | | * @param page 分页信息 |
| | | * @param keyword 关键字 |
| | | * @return 分页数据 |
| | | */ |
| | | public IPage<BladeFlow> selectOvertimePage(IPage<BladeFlow> page, String assigneeName,String keyword) { |
| | | public IPage<FlowVO> selectOvertimePage(IPage<FlowVO> page, LocalDate createTimeBegin, LocalDate createTimeEnd, String assigneeName, String keyword) { |
| | | |
| | | List<BladeFlow> flowList = new LinkedList<>(); |
| | | List<FlowVO> flowList = new LinkedList<>(); |
| | | Date now = new Date(); |
| | | TaskQuery todoQuery = taskService.createTaskQuery().taskDueBefore(now).active().includeProcessVariables(); |
| | | if(Func.isNotEmpty(createTimeBegin)) { |
| | | todoQuery.taskCreatedAfter(DateUtil.toDate(createTimeBegin)); |
| | | } |
| | | if(Func.isNotEmpty(createTimeEnd)) { |
| | | todoQuery.taskCreatedBefore(DateUtil.toDate(createTimeEnd.plusDays(1))); |
| | | } |
| | | |
| | | if(Func.isNotEmpty(keyword)) { |
| | | todoQuery.taskVariableValueLike("assigneeName", "%"+assigneeName+"%"); |
| | | } |
| | | if(Func.isNotEmpty(keyword)){ |
| | | todoQuery.or(); |
| | | keyword = "%"+keyword+"%"; |
| | | todoQuery.processVariableValueLike("processNo",keyword); |
| | | todoQuery.processVariableValueLike("machineCode",keyword); |
| | | todoQuery.processVariableValueLike("machineMode",keyword); |
| | | |
| | | todoQuery.processVariableValueLike("processName",keyword); |
| | | todoQuery.processVariableValueLike("processEdition",keyword); |
| | | |
| | | todoQuery.processVariableValueLike("craftEdition",keyword); |
| | | //TODO 多个字段都要匹配 |
| | | |
| | | todoQuery.endOr(); |
| | | } |
| | | addKeywordCondition(todoQuery, keyword); |
| | | |
| | | todoQuery.orderByTaskCreateTime().desc(); |
| | | |
| | | // 构建列表数据 |
| | | BladeFlow bladeFlow = new BladeFlow(); |
| | | buildFlowTaskList(bladeFlow, flowList, todoQuery, "todo");//FlowEngineConstant.STATUS_TODO |
| | | FlowVO bladeFlow = new FlowVO(); |
| | | buildFlowTaskList(bladeFlow, flowList, todoQuery,page.getCurrent(),page.getSize());//FlowEngineConstant.STATUS_TODO |
| | | |
| | | // 计算总数 |
| | | long count = todoQuery.count(); |
| | | // 设置页数 |
| | | page.setSize(count); |
| | | |
| | | // 设置总数 |
| | | page.setTotal(count); |
| | | // 设置数据 |
| | | page.setRecords(flowList); |
| | | return page; |
| | | } |
| | | |
| | | /** |
| | | * 流程查询 功能 的分页 |
| | | * @param page |
| | | * @param createTimeBegin |
| | | * @param createTimeEnd |
| | | * @param keyword |
| | | * @return |
| | | */ |
| | | public IPage<FlowVO> selectSearchPage(IPage<FlowVO> page,String myProcessName,String keyword, LocalDate createTimeBegin, LocalDate createTimeEnd) { |
| | | |
| | | List<FlowVO> flowList = new LinkedList<>(); |
| | | TaskQuery taskQuery = taskService.createTaskQuery().active().includeProcessVariables(); |
| | | if(Func.isNotEmpty(createTimeBegin)) { |
| | | taskQuery.taskCreatedAfter(DateUtil.toDate(createTimeBegin)); |
| | | } |
| | | if(Func.isNotEmpty(createTimeEnd)) { |
| | | taskQuery.taskCreatedBefore(DateUtil.toDate(createTimeEnd.plusDays(1))); |
| | | } |
| | | if(Func.isNotEmpty(myProcessName)) { |
| | | taskQuery.processVariableValueEquals(FlowVariableConstant.MY_PROCESS_NAME, myProcessName); |
| | | } |
| | | |
| | | addKeywordCondition(taskQuery, keyword); |
| | | |
| | | taskQuery.orderByTaskCreateTime().desc(); |
| | | |
| | | // 构建列表数据 |
| | | FlowVO bladeFlow = new FlowVO(); |
| | | buildFlowTaskList(bladeFlow, flowList, taskQuery,page.getCurrent(),page.getSize());//FlowEngineConstant.STATUS_TODO |
| | | |
| | | // 计算总数 |
| | | long count = taskQuery.count(); |
| | | // 设置总数 |
| | | page.setTotal(count); |
| | | // 设置数据 |
| | | page.setRecords(flowList); |
| | | return page; |
| | | } |
| | | |
| | | public void deleteProcessInstance(String processInstancesId) { |
| | | runtimeService.deleteProcessInstance(processInstancesId, "流程查询-删除"); |
| | | //TODO 删除出关联字段 |
| | | } |
| | | |
| | | /** |
| | | * 已完结的流程分页列表 |
| | | * @param page 分页信息 |
| | | * @param createTimeBegin |
| | | * @param createTimeEnd |
| | | * @param keyword 关键字 |
| | | * @return |
| | | */ |
| | | public IPage<FlowVO> selectFinishedPage(IPage<FlowVO> page, String myProcessName, String keyword,LocalDateTime createTimeBegin, LocalDateTime createTimeEnd) { |
| | | HistoricProcessInstanceQuery query = this.historyService.createHistoricProcessInstanceQuery().finished().includeProcessVariables(); |
| | | //.finished() // 只查询已完成的流程.unfinished() // 查询未完成的流程 |
| | | if(Func.isNotEmpty(myProcessName)) { |
| | | query.variableValueEquals(FlowVariableConstant.MY_PROCESS_NAME, myProcessName); |
| | | } |
| | | if(createTimeBegin!=null) { |
| | | query.startedAfter(DateUtil.toDate(createTimeBegin)); |
| | | } |
| | | if(createTimeEnd!=null) { |
| | | query.startedBefore(DateUtil.toDate(createTimeEnd)); |
| | | } |
| | | if(Func.isNotEmpty(keyword)) { |
| | | String likeVal = "%" + keyword + "%"; |
| | | query.or(); |
| | | query.variableValueLike(FlowVariableConstant.TITLE,likeVal); |
| | | query.variableValueLike(FlowVariableConstant.PROCESS_NO, likeVal); |
| | | query.variableValueLike(FlowVariableConstant.MACHINE_CODE, likeVal); |
| | | query.variableValueLike(FlowVariableConstant.MACHINE_MODE, likeVal); |
| | | query.variableValueLike(FlowVariableConstant.PROCESS_NAME, likeVal); |
| | | query.variableValueLike(FlowVariableConstant.PROCESS_EDITION, likeVal); |
| | | query.variableValueLike(FlowVariableConstant.CRAFT_EDITION, likeVal); |
| | | |
| | | query.endOr(); |
| | | } |
| | | |
| | | |
| | | query.orderByProcessInstanceEndTime().desc(); // 按结束时间降序排列 |
| | | page.setTotal(query.count()); |
| | | |
| | | long firstResult = (page.getCurrent()-1) * page.getSize(); |
| | | List<HistoricProcessInstance> processes = query |
| | | .listPage((int)firstResult, (int)page.getSize()); |
| | | |
| | | List<FlowVO> records = new LinkedList<>(); |
| | | |
| | | for(HistoricProcessInstance processInstance : processes) { |
| | | FlowVO vo = new FlowVO(); |
| | | vo.setProcessDefinitionKey(processInstance.getProcessDefinitionKey()); |
| | | vo.setProcessInstanceId(processInstance.getId()); |
| | | vo.setProcessDefinitionName(processInstance.getProcessDefinitionName()); |
| | | vo.setVariables(processInstance.getProcessVariables()); |
| | | |
| | | vo.setProcessCreateTime(processInstance.getStartTime()); |
| | | vo.setHistoryTaskEndTime(processInstance.getEndTime()); |
| | | |
| | | R<User> ru = userClient.userInfoById(Long.valueOf(processInstance.getStartUserId())); |
| | | if(ru.isSuccess()) { |
| | | vo.setStartUserName(ru.getData().getName()); |
| | | } |
| | | |
| | | vo.setFile(getFileString(processInstance.getId())); |
| | | records.add(vo); |
| | | } |
| | | |
| | | page.setRecords(records); |
| | | |
| | | return page; |
| | | } |
| | | |
| | | /** |
| | | * 异常流程 |
| | | * @param page |
| | | * @param myProcessName |
| | | * @param keyword |
| | | * @param createTimeBegin |
| | | * @param createTimeEnd |
| | | * @return |
| | | */ |
| | | public IPage<FlowVO> selectExceptionPage(IPage<FlowVO> page, String myProcessName, String keyword,LocalDateTime createTimeBegin, LocalDateTime createTimeEnd) { |
| | | HistoricProcessInstanceQuery query = this.historyService.createHistoricProcessInstanceQuery().finished().includeProcessVariables(); |
| | | //.finished() // 只查询已完成的流程.unfinished() // 查询未完成的流程 |
| | | |
| | | query.variableValueEquals(FlowVariableConstant.EXCEPTION, "1"); |
| | | if(Func.isNotEmpty(myProcessName)) { |
| | | query.variableValueEquals(FlowVariableConstant.MY_PROCESS_NAME, myProcessName); |
| | | } |
| | | if(createTimeBegin!=null) { |
| | | query.startedAfter(DateUtil.toDate(createTimeBegin)); |
| | | } |
| | | if(createTimeEnd!=null) { |
| | | query.startedBefore(DateUtil.toDate(createTimeEnd)); |
| | | } |
| | | if(Func.isNotEmpty(keyword)) { |
| | | String likeVal = "%" + keyword + "%"; |
| | | query.or(); |
| | | query.variableValueLike(FlowVariableConstant.TITLE,likeVal); |
| | | query.variableValueLike(FlowVariableConstant.PROCESS_NO, likeVal); |
| | | query.variableValueLike(FlowVariableConstant.MACHINE_CODE, likeVal); |
| | | query.variableValueLike(FlowVariableConstant.MACHINE_MODE, likeVal); |
| | | query.variableValueLike(FlowVariableConstant.PROCESS_NAME, likeVal); |
| | | query.variableValueLike(FlowVariableConstant.PROCESS_EDITION, likeVal); |
| | | query.variableValueLike(FlowVariableConstant.CRAFT_EDITION, likeVal); |
| | | |
| | | query.endOr(); |
| | | } |
| | | |
| | | |
| | | query.orderByProcessInstanceEndTime().desc(); // 按结束时间降序排列 |
| | | page.setTotal(query.count()); |
| | | |
| | | long firstResult = (page.getCurrent()-1) * page.getSize(); |
| | | List<HistoricProcessInstance> processes = query |
| | | .listPage((int)firstResult, (int)page.getSize()); |
| | | |
| | | List<FlowVO> records = new LinkedList<>(); |
| | | |
| | | for(HistoricProcessInstance processInstance : processes) { |
| | | FlowVO vo = new FlowVO(); |
| | | vo.setProcessDefinitionKey(processInstance.getProcessDefinitionKey()); |
| | | vo.setProcessInstanceId(processInstance.getId()); |
| | | vo.setProcessDefinitionName(processInstance.getProcessDefinitionName()); |
| | | vo.setVariables(processInstance.getProcessVariables()); |
| | | |
| | | vo.setProcessCreateTime(processInstance.getStartTime()); |
| | | vo.setHistoryTaskEndTime(processInstance.getEndTime()); |
| | | R<User> ru = userClient.userInfoById(Long.valueOf(processInstance.getStartUserId())); |
| | | if(ru.isSuccess()) { |
| | | vo.setStartUserName(ru.getData().getName()); |
| | | } |
| | | vo.setFile(getFileString(processInstance.getId())); |
| | | records.add(vo); |
| | | } |
| | | |
| | | page.setRecords(records); |
| | | |
| | | return page; |
| | | } |
| | | /* |
| | | 获取列表中的文件名 |
| | | */ |
| | | String getFileString(String processInstanceId){ |
| | | String result = ""; |
| | | List<FlowProgramFile> fileList = flowProgramFileService.lambdaQuery().eq(FlowProgramFile::getProcessInstanceId, processInstanceId).list(); |
| | | |
| | | result = String.join(",",fileList.stream().map(FlowProgramFile::getName).toList()); |
| | | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 个人已办(已完成任务) |
| | | * @param page |
| | | * @param processDefinitionKey |
| | | * @param createTimeBegin |
| | | * @param createTimeEnd |
| | | * @param keyword |
| | | * @return |
| | | */ |
| | | public IPage<FlowVO> selectDonePage(IPage<FlowVO> page, String processDefinitionKey,LocalDateTime createTimeBegin, LocalDateTime createTimeEnd, String keyword) { |
| | | String userId = "" + AuthUtil.getUserId(); |
| | | HistoricTaskInstanceQuery doneTaskQuery = historyService.createHistoricTaskInstanceQuery().taskAssignee(userId).finished().includeProcessVariables(); |
| | | |
| | | //.finished() // 只查询已完成的流程.unfinished() // 查询未完成的流程 |
| | | if(Func.isNotEmpty(processDefinitionKey)) { |
| | | doneTaskQuery.processDefinitionKey(processDefinitionKey); |
| | | } |
| | | if(createTimeBegin!=null) { |
| | | Date after = DateUtil.toDate(createTimeBegin); |
| | | |
| | | doneTaskQuery.taskCreatedAfter(after); |
| | | |
| | | //doneTaskQuery.taskCreatedOn(after); |
| | | //doneTaskQuery.taskInProgressStartTimeAfter(after); |
| | | } |
| | | if(createTimeEnd!=null) { |
| | | Date before = DateUtil.toDate(createTimeEnd); |
| | | |
| | | doneTaskQuery.taskCreatedBefore(before); |
| | | |
| | | //doneTaskQuery.taskInProgressStartTimeBefore(before); |
| | | } |
| | | |
| | | if (Func.isNotEmpty(keyword)) { |
| | | addKeywordCondition(doneTaskQuery, keyword); |
| | | } |
| | | |
| | | doneTaskQuery.orderByTaskCreateTime().desc(); // 按结束时间降序排列 |
| | | page.setTotal(doneTaskQuery.count()); |
| | | |
| | | long firstResult = (page.getCurrent()-1) * page.getSize(); |
| | | |
| | | List<HistoricTaskInstance> processes = doneTaskQuery |
| | | .listPage((int)firstResult, (int)page.getSize()); |
| | | |
| | | List<FlowVO> records = new LinkedList<>(); |
| | | |
| | | Map<String,String> startUserMap = new HashMap<>();//使用userId缓存其姓名 |
| | | for(HistoricTaskInstance hisTask : processes) { |
| | | FlowVO vo = new FlowVO(); |
| | | |
| | | HistoricProcessInstance processInstance = historyService |
| | | .createHistoricProcessInstanceQuery() |
| | | .processInstanceId(hisTask.getProcessInstanceId()) |
| | | .singleResult(); |
| | | |
| | | if(startUserMap.containsKey(processInstance.getStartUserId())) { |
| | | vo.setStartUserName(startUserMap.get(processInstance.getStartUserId())); |
| | | }else { |
| | | R<User> ru = userClient.userInfoById(Long.valueOf(processInstance.getStartUserId())); |
| | | if (ru.isSuccess()) { |
| | | vo.setStartUserName(ru.getData().getName()); |
| | | startUserMap.put(processInstance.getStartUserId(),ru.getData().getName()); |
| | | } |
| | | } |
| | | vo.setProcessCreateTime(processInstance.getStartTime()); |
| | | |
| | | vo.setProcessInstanceId(hisTask.getProcessInstanceId()); |
| | | vo.setProcessDefinitionName(processInstance.getProcessDefinitionName()); |
| | | vo.setProcessDefinitionKey(processInstance.getProcessDefinitionKey()); |
| | | vo.setTaskName(hisTask.getName()); |
| | | vo.setTaskDefinitionKey(hisTask.getTaskDefinitionKey()); |
| | | vo.setCreateTime(hisTask.getCreateTime()); |
| | | vo.setEndTime(hisTask.getEndTime()); |
| | | vo.setVariables(hisTask.getProcessVariables()); |
| | | |
| | | vo.setProcessCreateTime(processInstance.getStartTime()); |
| | | vo.setHistoryTaskEndTime(hisTask.getEndTime()); |
| | | |
| | | vo.setFile(getFileString(hisTask.getProcessInstanceId())); |
| | | records.add(vo); |
| | | } |
| | | |
| | | page.setRecords(records); |
| | | |
| | | return page; |
| | | } |
| | | |
| | | } |