From 4f91b953e8f0ae7c63aea01a57367b6b57639a7f Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期二, 05 八月 2025 10:58:52 +0800
Subject: [PATCH] 清除无用的显示ncprogram的内容代码
---
blade-service/blade-mdm/src/main/java/org/springblade/mdm/flow/service/FlowBusinessService.java | 387 ++++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 268 insertions(+), 119 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 0ab7275..6bdee86 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
@@ -1,56 +1,37 @@
-/**
- * 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.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.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.system.feign.IUserClient;
+import org.springblade.system.pojo.entity.User;
import org.springframework.stereotype.Service;
+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.Map;
/**
* 娴佺▼涓氬姟瀹炵幇绫�
@@ -60,57 +41,75 @@
@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 ProcessProgRefService processProgRefService;
+ private final ApproveRecordService approveRecordService;
+ private final NcProgramService ncProgramService;
+ private final FlowProgramFileService flowProgramFileService;
+ /**
+ * 鏌ヨ鎴戠殑娴佺▼(涓汉寰呭姙鍒楄〃)
+ * @param page 鍒嗛〉淇℃伅
+ * @param createTimeBegin 鍒涘缓鏃堕棿寮�濮�
+ * @param createTimeEnd 鍒涘缓鏃堕棿鎴
+ * @param keyword 鏌ヨ鍏抽敭瀛�
+ * @return
+ */
+ public IPage<FlowVO> selectTodoPage(IPage<FlowVO> page, 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(createTimeBegin)) {
+ todoQuery.taskCreatedAfter(DateUtil.toDate(createTimeBegin));
- 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();
+ ////濡傛灉鏌ヨ瀹炰緥鐨勫紑濮嬫椂闂达細鍙兘鐢ㄤ互涓嬭繖涓紝鍏堟煡鍑哄疄渚媔d鏉�
+ //todoQuery.processInstanceIdIn()
+ }
+ if (Func.isNotEmpty(createTimeEnd)) {
+ todoQuery.taskCreatedBefore(DateUtil.toDate(createTimeEnd));
+ //todoQuery.taskInProgressStartTimeBefore(DateUtil.toDate(createTimeEnd));
+ }
+ if (Func.isNotEmpty(keyword)) {
+ addKeywordCondition(todoQuery, keyword);
}
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());
+ flowList.forEach(flowVO -> {
+ if(flowVO.getVariables().containsKey("machineCode")){
+ //Machine machinemachineService.getByCode((String)flowVO.getVariables().get("machineCode"))
+ }
+ });
// 璁$畻鎬绘暟
long count = todoQuery.count();
- // 璁剧疆椤垫暟
- page.setSize(count);
+
// 璁剧疆鎬绘暟
page.setTotal(count);
// 璁剧疆鏁版嵁
page.setRecords(flowList);
return page;
+ }
+
+ void addKeywordCondition(TaskQuery todoQuery,String keyword) {
+ 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 + "%");
+
+ todoQuery.endOr();
+ }
}
/*
@Override
@@ -251,25 +250,6 @@
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;
- }
*/
/**
* 鏋勫缓娴佺▼
@@ -277,9 +257,8 @@
* @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()));
}
@@ -292,9 +271,13 @@
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());
@@ -303,20 +286,30 @@
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.setFile(getFileString(task.getProcessInstanceId()));
//flow.setProcessDefinitionKey(processDefinition.getKey());
//flow.setProcessDefinitionVersion(processDefinition.getVersion());
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());
@@ -328,12 +321,37 @@
flow.setProcessDefinitionVersion(processDefinition.getVersion());
flow.setProcessInstanceId(task.getProcessInstanceId());
//flow.setStatus(status);
- /*
- */
+
flowList.add(flow);
});
}
+ 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();
+ }
+ }
/**
* 鑾峰彇鍘嗗彶娴佺▼
*
@@ -344,42 +362,173 @@
return historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
}
- public IPage<BladeFlow> selectAllTaskPage(IPage<BladeFlow> page, String keyword) {
+ public IPage<FlowVO> selectAllTaskPage(IPage<FlowVO> page, String keyword) {
- List<BladeFlow> flowList = new LinkedList<>();
+ 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);
// 璁剧疆鏁版嵁
page.setRecords(flowList);
return page;
}
+
+ /**
+ * 瓒呮椂浠诲姟鏌ヨ
+ * @param page 鍒嗛〉淇℃伅
+ * @param keyword 鍏抽敭瀛�
+ * @return 鍒嗛〉鏁版嵁
+ */
+ public IPage<FlowVO> selectOvertimePage(IPage<FlowVO> page, LocalDate createTimeBegin, LocalDate createTimeEnd, String assigneeName, String keyword) {
+
+ 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+"%");
+ }
+
+ addKeywordCondition(todoQuery, keyword);
+
+ todoQuery.orderByTaskCreateTime().desc();
+
+ // 鏋勫缓鍒楄〃鏁版嵁
+ FlowVO bladeFlow = new FlowVO();
+ buildFlowTaskList(bladeFlow, flowList, todoQuery,page.getCurrent(),page.getSize());//FlowEngineConstant.STATUS_TODO
+
+ // 璁$畻鎬绘暟
+ long count = todoQuery.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, LocalDate createTimeBegin, LocalDate createTimeEnd,String processDefinitionKey,String keyword) {
+
+ 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);
+ }
+
+ 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 processDefinitionKey,LocalDate createTimeBegin, LocalDate createTimeEnd, String keyword) {
+ HistoricProcessInstanceQuery query = this.historyService.createHistoricProcessInstanceQuery().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;
+ }
}
--
Gitblit v1.9.3