From 7a6b24ebb7197821c71e9bb41ca31b196037022a Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期日, 10 八月 2025 12:57:08 +0800
Subject: [PATCH] 增加上一步审批用户查询接口
---
blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/FlowBusinessService.java | 253 ++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 210 insertions(+), 43 deletions(-)
diff --git a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/FlowBusinessService.java b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/FlowBusinessService.java
index 99126f6..35394e9 100644
--- a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/FlowBusinessService.java
+++ b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/FlowBusinessService.java
@@ -7,19 +7,24 @@
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.launch.constant.FlowConstant;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.*;
-import org.springblade.mdm.basesetting.machine.MachineService;
+import org.springblade.mdm.flow.constants.FlowContants;
+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.entity.ProcessProgRef;
+import org.springblade.mdm.program.service.NcProgramService;
import org.springblade.mdm.program.service.ProcessProgRefService;
import org.springblade.system.feign.IUserClient;
import org.springblade.system.pojo.entity.User;
@@ -27,11 +32,7 @@
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.stream.Collectors;
+import java.util.*;
/**
* 娴佺▼涓氬姟瀹炵幇绫�
@@ -47,13 +48,14 @@
private final IUserClient userClient;
private final ProcessProgRefService processProgRefService;
private final ApproveRecordService approveRecordService;
-
+ private final NcProgramService ncProgramService;
+ private final FlowProgramFileService flowProgramFileService;
/**
* 鏌ヨ鎴戠殑娴佺▼(涓汉寰呭姙鍒楄〃)
- * @param page
- * @param createTimeBegin
- * @param createTimeEnd
- * @param keyword
+ * @param page 鍒嗛〉淇℃伅
+ * @param createTimeBegin 鍒涘缓鏃堕棿寮�濮�
+ * @param createTimeEnd 鍒涘缓鏃堕棿鎴
+ * @param keyword 鏌ヨ鍏抽敭瀛�
* @return
*/
public IPage<FlowVO> selectTodoPage(IPage<FlowVO> page, LocalDateTime createTimeBegin, LocalDateTime createTimeEnd, String keyword) {
@@ -64,9 +66,6 @@
TaskQuery todoQuery = taskService.createTaskQuery().taskAssignee(userId).active().includeProcessVariables();
if (Func.isNotEmpty(createTimeBegin)) {
todoQuery.taskCreatedAfter(DateUtil.toDate(createTimeBegin));
-
- ////濡傛灉鏌ヨ瀹炰緥鐨勫紑濮嬫椂闂达細鍙兘鐢ㄤ互涓嬭繖涓紝鍏堟煡鍑哄疄渚媔d鏉�
- //todoQuery.processInstanceIdIn()
}
if (Func.isNotEmpty(createTimeEnd)) {
todoQuery.taskCreatedBefore(DateUtil.toDate(createTimeEnd));
@@ -80,34 +79,32 @@
// 鏋勫缓鍒楄〃鏁版嵁
FlowVO bladeFlow = new FlowVO();
- buildFlowTaskList(bladeFlow, flowList, todoQuery);//FlowEngineConstant.STATUS_TODO , "todo"
- flowList.forEach(flowVO -> {
- if(flowVO.getVariables().containsKey("machineCode")){
- //Machine machinemachineService.getByCode((String)flowVO.getVariables().get("machineCode"))
- }
- });
+ buildFlowTaskList(bladeFlow, flowList, todoQuery,page.getCurrent(),page.getSize());
+
// 璁$畻鎬绘暟
long count = todoQuery.count();
- // 璁剧疆椤垫暟
- page.setSize(count);
+
// 璁剧疆鎬绘暟
page.setTotal(count);
// 璁剧疆鏁版嵁
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();
+ 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("processNo", "%" + keyword + "%");
- todoQuery.processVariableValueLike("machineCode", "%" + keyword + "%");
- todoQuery.processVariableValueLike("machineMode", "%" + keyword + "%");
- todoQuery.processVariableValueLike("processName", "%" + keyword + "%");
- todoQuery.processVariableValueLike("processEdition", "%" + keyword + "%");
- todoQuery.processVariableValueLike("craftEdition", "%" + keyword + "%");
-
+ todoQuery.processDefinitionNameLike(likeVal);
todoQuery.endOr();
}
}
@@ -258,7 +255,7 @@
* @param flowList 娴佺▼鍒楄〃
* @param taskQuery 浠诲姟鏌ヨ绫�
*/
- private void buildFlowTaskList(FlowVO bladeFlow, List<FlowVO> flowList, TaskQuery taskQuery) {
+ private void buildFlowTaskList(FlowVO bladeFlow, List<FlowVO> flowList, TaskQuery taskQuery,Long currentPage,Long pageSize) {
if (bladeFlow.getCategory() != null) {
taskQuery.processCategoryIn(Func.toStrList(bladeFlow.getCategory()));
}
@@ -272,7 +269,10 @@
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 -> {
FlowVO flow = new FlowVO();
flow.setTaskId(task.getId());
@@ -287,6 +287,7 @@
flow.setProcessDefinitionId(task.getProcessDefinitionId());
+ flow.setFile(getFileString(task.getProcessInstanceId()));
//flow.setProcessDefinitionKey(processDefinition.getKey());
//flow.setProcessDefinitionVersion(processDefinition.getVersion());
flow.setProcessInstanceId(task.getProcessInstanceId());
@@ -371,12 +372,12 @@
// 鏋勫缓鍒楄〃鏁版嵁
FlowVO bladeFlow = new FlowVO();
- buildFlowTaskList(bladeFlow, flowList, todoQuery);//FlowEngineConstant.STATUS_TODO
+ buildFlowTaskList(bladeFlow, flowList, todoQuery,page.getCurrent(),page.getSize());//FlowEngineConstant.STATUS_TODO
// 璁$畻鎬绘暟
long count = todoQuery.count();
// 璁剧疆椤垫暟
- page.setSize(count);
+ //page.setSize(count);
// 璁剧疆鎬绘暟
page.setTotal(count);
// 璁剧疆鏁版嵁
@@ -412,12 +413,11 @@
// 鏋勫缓鍒楄〃鏁版嵁
FlowVO bladeFlow = new FlowVO();
- buildFlowTaskList(bladeFlow, flowList, todoQuery);//FlowEngineConstant.STATUS_TODO
+ buildFlowTaskList(bladeFlow, flowList, todoQuery,page.getCurrent(),page.getSize());//FlowEngineConstant.STATUS_TODO
// 璁$畻鎬绘暟
long count = todoQuery.count();
- // 璁剧疆椤垫暟
- page.setSize(count);
+
// 璁剧疆鎬绘暟
page.setTotal(count);
// 璁剧疆鏁版嵁
@@ -433,7 +433,7 @@
* @param keyword
* @return
*/
- public IPage<FlowVO> selectSearchPage(IPage<FlowVO> page, LocalDate createTimeBegin, LocalDate createTimeEnd, String keyword) {
+ public IPage<FlowVO> selectSearchPage(IPage<FlowVO> page, LocalDate createTimeBegin, LocalDate createTimeEnd,String processDefinitionKey,String keyword) {
List<FlowVO> flowList = new LinkedList<>();
Date now = new Date();
@@ -444,6 +444,9 @@
if(Func.isNotEmpty(createTimeEnd)) {
taskQuery.taskCreatedBefore(DateUtil.toDate(createTimeEnd.plusDays(1)));
}
+ if(Func.isNotEmpty(processDefinitionKey)) {
+ taskQuery.processDefinitionKey(processDefinitionKey);
+ }
addKeywordCondition(taskQuery, keyword);
@@ -451,12 +454,10 @@
// 鏋勫缓鍒楄〃鏁版嵁
FlowVO bladeFlow = new FlowVO();
- buildFlowTaskList(bladeFlow, flowList, taskQuery);//FlowEngineConstant.STATUS_TODO
+ buildFlowTaskList(bladeFlow, flowList, taskQuery,page.getCurrent(),page.getSize());//FlowEngineConstant.STATUS_TODO
// 璁$畻鎬绘暟
long count = taskQuery.count();
- // 璁剧疆椤垫暟
- page.setSize(count);
// 璁剧疆鎬绘暟
page.setTotal(count);
// 璁剧疆鏁版嵁
@@ -468,4 +469,170 @@
runtimeService.deleteProcessInstance(processInstancesId, "娴佺▼鏌ヨ-鍒犻櫎");
//TODO 鍒犻櫎鍑哄叧鑱斿瓧娈�
}
+
+ /**
+ * 宸插畬缁撶殑娴佺▼鍒嗛〉鍒楄〃
+ * @param page 鍒嗛〉淇℃伅
+ * @param createTimeBegin
+ * @param createTimeEnd
+ * @param keyword 鍏抽敭瀛�
+ * @return
+ */
+ 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);
+ }
+ if(createTimeBegin!=null) {
+ query.startedAfter(DateUtil.toDate(createTimeBegin));
+ }
+ if(createTimeEnd!=null) {
+ query.startedBefore(DateUtil.toDate(createTimeEnd));
+ }
+ 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());
+
+ 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 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;
+ }
}
--
Gitblit v1.9.3