| | |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.*; |
| | | |
| | | import org.springblade.mdm.flow.constants.FlowContants; |
| | | 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.program.service.NcProgramService; |
| | | import org.springblade.mdm.program.service.ProcessProgRefService; |
| | | 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; |
| | |
| | | /** |
| | | * 流程业务实现类 |
| | | * |
| | | * @author Chill |
| | | * @author yangys |
| | | */ |
| | | @Service |
| | | @AllArgsConstructor |
| | |
| | | private final HistoryService historyService; |
| | | private final IUserClient userClient; |
| | | private final FlowProgramFileService flowProgramFileService; |
| | | private final ParamService paramService; |
| | | private final MachineService machineService; |
| | | /** |
| | | * 查询我的流程(个人待办列表) |
| | | * @param page 分页信息 |
| | |
| | | * @param keyword 查询关键字 |
| | | * @return |
| | | */ |
| | | public IPage<FlowVO> selectTodoPage(IPage<FlowVO> page, LocalDateTime createTimeBegin, LocalDateTime createTimeEnd, String keyword) { |
| | | public IPage<FlowVO> selectTodoPage(IPage<FlowVO> page, TodoQueryVO queryVO) {//LocalDateTime createTimeBegin, LocalDateTime createTimeEnd, String keyword |
| | | //String taskUser = TaskUtil.getTaskUser(); |
| | | String userId = "" + AuthUtil.getUserId(); |
| | | List<FlowVO> flowList = new LinkedList<>(); |
| | | |
| | | TaskQuery todoQuery = taskService.createTaskQuery().taskAssignee(userId).active().includeProcessVariables(); |
| | | if (Func.isNotEmpty(createTimeBegin)) { |
| | | todoQuery.taskCreatedAfter(DateUtil.toDate(createTimeBegin)); |
| | | |
| | | 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(); |
| | | |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | | if (Func.isNotEmpty(createTimeEnd)) { |
| | | todoQuery.taskCreatedBefore(DateUtil.toDate(createTimeEnd)); |
| | | //todoQuery.taskInProgressStartTimeBefore(DateUtil.toDate(createTimeEnd)); |
| | | |
| | | if (Func.isNotEmpty(queryVO.getCreateTimeBegin())) { |
| | | todoQuery.taskCreatedAfter(DateUtil.toDate(queryVO.getCreateTimeBegin())); |
| | | } |
| | | if (Func.isNotEmpty(keyword)) { |
| | | addKeywordCondition(todoQuery, keyword); |
| | | if (Func.isNotEmpty(queryVO.getCreateTimeEnd())) { |
| | | todoQuery.taskCreatedBefore(DateUtil.toDate(queryVO.getCreateTimeEnd())); |
| | | } |
| | | if (Func.isNotEmpty(queryVO.getKeyword())) { |
| | | addKeywordCondition(todoQuery, queryVO.getKeyword()); |
| | | } |
| | | |
| | | todoQuery.orderByTaskCreateTime().desc(); |
| | |
| | | if(Func.isNotEmpty(keyword)) { |
| | | String likeVal = "%" + keyword + "%"; |
| | | todoQuery.or(); |
| | | todoQuery.processVariableValueLike(FlowContants.TITLE,likeVal); |
| | | todoQuery.processVariableValueLike(FlowContants.PROCESS_NO, likeVal); |
| | | todoQuery.processVariableValueLike(FlowContants.MACHINE_CODE, likeVal); |
| | | todoQuery.processVariableValueLike(FlowContants.MACHINE_MODE, likeVal); |
| | | todoQuery.processVariableValueLike(FlowContants.PROCESS_NAME, likeVal); |
| | | todoQuery.processVariableValueLike(FlowContants.PROCESS_EDITION, likeVal); |
| | | todoQuery.processVariableValueLike(FlowContants.CRAFT_EDITION, likeVal); |
| | | 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); |
| | | |
| | | todoQuery.processDefinitionNameLike(likeVal); |
| | | todoQuery.endOr(); |
| | |
| | | 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()); |
| | |
| | | return Collections.emptyList(); |
| | | } |
| | | } |
| | | /** |
| | | * 获取历史流程 |
| | | * |
| | | * @param processInstanceId 流程实例id |
| | | * @return HistoricProcessInstance |
| | | */ |
| | | private HistoricProcessInstance getHistoricProcessInstance(String processInstanceId) { |
| | | return historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); |
| | | } |
| | | |
| | | |
| | | public IPage<FlowVO> selectAllTaskPage(IPage<FlowVO> page, String keyword) { |
| | | |
| | |
| | | * @param keyword |
| | | * @return |
| | | */ |
| | | public IPage<FlowVO> selectSearchPage(IPage<FlowVO> page, LocalDate createTimeBegin, LocalDate createTimeEnd,String processDefinitionKey,String keyword) { |
| | | public IPage<FlowVO> selectSearchPage(IPage<FlowVO> page,String myProcessName,String keyword, LocalDate createTimeBegin, LocalDate createTimeEnd) { |
| | | |
| | | List<FlowVO> flowList = new LinkedList<>(); |
| | | Date now = new Date(); |
| | | 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(processDefinitionKey)) { |
| | | taskQuery.processDefinitionKey(processDefinitionKey); |
| | | if(Func.isNotEmpty(myProcessName)) { |
| | | taskQuery.processVariableValueEquals(FlowVariableConstant.MY_PROCESS_NAME, myProcessName); |
| | | } |
| | | |
| | | addKeywordCondition(taskQuery, keyword); |
| | |
| | | * @param keyword 关键字 |
| | | * @return |
| | | */ |
| | | public IPage<FlowVO> selectFinishedPage(IPage<FlowVO> page, String processDefinitionKey,LocalDateTime createTimeBegin, LocalDateTime createTimeEnd, String keyword) { |
| | | 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(processDefinitionKey)) { |
| | | query.processDefinitionKey(processDefinitionKey); |
| | | 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()); |
| | | |
| | |
| | | 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); |
| | | } |
| | |
| | | |
| | | return page; |
| | | } |
| | | |
| | | } |