| | |
| | | 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.launch.constant.FlowConstant; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.api.R; |
| | |
| | | |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.util.Collections; |
| | | import java.util.Date; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 流程业务实现类 |
| | |
| | | page.setRecords(flowList); |
| | | return page; |
| | | } |
| | | |
| | | void addKeywordCondition(TaskQuery todoQuery,String keyword) { |
| | | //TaskInfoQuery |
| | | //void addKeywordCondition(TaskQuery todoQuery,String keyword) { |
| | | void addKeywordCondition(TaskInfoQuery todoQuery, String keyword) { |
| | | if(Func.isNotEmpty(keyword)) { |
| | | String likeVal = "%" + keyword + "%"; |
| | | todoQuery.or(); |
| | |
| | | * @param keyword 关键字 |
| | | * @return |
| | | */ |
| | | public IPage<FlowVO> selectFinishedPage(IPage<FlowVO> page, String processDefinitionKey,LocalDate createTimeBegin, LocalDate createTimeEnd, String keyword) { |
| | | HistoricProcessInstanceQuery query = this.historyService.createHistoricProcessInstanceQuery().includeProcessVariables(); |
| | | public IPage<FlowVO> selectFinishedPage(IPage<FlowVO> page, String processDefinitionKey,LocalDateTime createTimeBegin, LocalDateTime createTimeEnd, String keyword) { |
| | | HistoricProcessInstanceQuery query = this.historyService.createHistoricProcessInstanceQuery().finished().includeProcessVariables(); |
| | | //.finished() // 只查询已完成的流程.unfinished() // 查询未完成的流程 |
| | | if(Func.isNotEmpty(processDefinitionKey)) { |
| | | query.processDefinitionKey(processDefinitionKey); |
| | |
| | | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 查询已办任务分页数据 |
| | | * @param page |
| | | * @param createTimeBegin |
| | | * @param createTimeEnd |
| | | * @param keyword |
| | | * @return |
| | | */ |
| | | /* |
| | | public IPage<FlowVO> selectDonePage(IPage<FlowVO> page, LocalDateTime createTimeBegin, LocalDateTime createTimeEnd, String keyword) { |
| | | String userId = "" + AuthUtil.getUserId(); |
| | | List<FlowVO> flowList = new LinkedList<>(); |
| | | |
| | | HistoricTaskInstanceQuery doneTaskQuery = historyService.createHistoricTaskInstanceQuery().taskAssignee(userId).finished().includeProcessVariables(); |
| | | //TaskQuery todoQuery = historyService.createHistoricTaskInstanceQuery().taskAssignee(userId).finished().includeProcessVariables() |
| | | if (Func.isNotEmpty(createTimeBegin)) { |
| | | doneTaskQuery.taskCreatedAfter(DateUtil.toDate(createTimeBegin)); |
| | | } |
| | | if (Func.isNotEmpty(createTimeEnd)) { |
| | | doneTaskQuery.taskCreatedBefore(DateUtil.toDate(createTimeEnd)); |
| | | //todoQuery.taskInProgressStartTimeBefore(DateUtil.toDate(createTimeEnd)); |
| | | } |
| | | if (Func.isNotEmpty(keyword)) { |
| | | addKeywordCondition(doneTaskQuery, keyword); |
| | | } |
| | | |
| | | todoQuery.orderByTaskCreateTime().desc(); |
| | | |
| | | // 构建列表数据 |
| | | FlowVO bladeFlow = new FlowVO(); |
| | | buildFlowTaskList(bladeFlow, flowList, todoQuery,page.getCurrent(),page.getSize()); |
| | | |
| | | // 计算总数 |
| | | long count = todoQuery.count(); |
| | | |
| | | // 设置总数 |
| | | page.setTotal(count); |
| | | // 设置数据 |
| | | page.setRecords(flowList); |
| | | return page; |
| | | }*/ |
| | | public IPage<FlowVO> selectDonePage(IPage<FlowVO> page, String processDefinitionKey,LocalDateTime completeTimeBegin, 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(completeTimeBegin!=null) { |
| | | doneTaskQuery.taskCompletedAfter(DateUtil.toDate(completeTimeBegin)); |
| | | } |
| | | if(createTimeEnd!=null) { |
| | | doneTaskQuery.taskCompletedBefore(DateUtil.toDate(createTimeEnd)); |
| | | } |
| | | //QueryProperty |
| | | 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> processDefKeyMap = new HashMap<>();//使用TaskDefinitionKey缓存ProcessDefinitionKey |
| | | //Map<String,String> processDefNameMap = new HashMap<>();//使用TaskDefinitionKey缓存ProcessDefinitionName |
| | | 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.setTaskName(hisTask.getName()); |
| | | 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; |
| | | } |
| | | } |