From 586019ba7ccb6088ae8bc5f4bfa78cdede1e3e7e Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Fri, 12 May 2023 15:03:35 +0800
Subject: [PATCH] 巡检添加已办事务

---
 skjcmanager/skjcmanager-ops/skjcmanager-flow/src/main/java/cn/gistack/flow/business/service/impl/FlowBusinessServiceImpl.java |  114 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 114 insertions(+), 0 deletions(-)

diff --git a/skjcmanager/skjcmanager-ops/skjcmanager-flow/src/main/java/cn/gistack/flow/business/service/impl/FlowBusinessServiceImpl.java b/skjcmanager/skjcmanager-ops/skjcmanager-flow/src/main/java/cn/gistack/flow/business/service/impl/FlowBusinessServiceImpl.java
index 2fcaecb..2930179 100644
--- a/skjcmanager/skjcmanager-ops/skjcmanager-flow/src/main/java/cn/gistack/flow/business/service/impl/FlowBusinessServiceImpl.java
+++ b/skjcmanager/skjcmanager-ops/skjcmanager-flow/src/main/java/cn/gistack/flow/business/service/impl/FlowBusinessServiceImpl.java
@@ -20,6 +20,7 @@
 import cn.gistack.flow.core.constant.ProcessConstant;
 import cn.gistack.flow.core.entity.BladeFlow;
 import cn.gistack.flow.core.utils.TaskUtil;
+import cn.gistack.flow.core.vo.BladeFlowVO;
 import cn.gistack.flow.engine.constant.FlowEngineConstant;
 import cn.gistack.flow.engine.entity.FlowProcess;
 import cn.gistack.flow.engine.utils.FlowCache;
@@ -32,6 +33,7 @@
 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.BladeUser;
 import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.tool.support.Kv;
 import org.springblade.core.tool.utils.Func;
@@ -42,6 +44,8 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+
+import static org.springblade.core.launch.constant.FlowConstant.TASK_USR_PREFIX;
 
 /**
  * 流程业务实现类
@@ -90,6 +94,29 @@
 	@Override
 	public IPage<BladeFlow> selectTodoPage(IPage<BladeFlow> page, BladeFlow bladeFlow) {
 		String taskUser = TaskUtil.getTaskUser();
+		List<BladeFlow> flowList = new LinkedList<>();
+
+		// 已签收的任务
+		TaskQuery todoQuery = taskService.createTaskQuery().taskAssignee(taskUser).active()
+			.includeProcessVariables().orderByTaskCreateTime().desc();
+
+		// 构建列表数据
+		buildFlowTaskList(bladeFlow, flowList, todoQuery, FlowEngineConstant.STATUS_TODO);
+
+		// 计算总数
+		long count = todoQuery.count();
+		// 设置页数
+		page.setSize(count);
+		// 设置总数
+		page.setTotal(count);
+		// 设置数据
+		page.setRecords(flowList);
+		return page;
+	}
+
+	@Override
+	public IPage<BladeFlow> selectTodoPage(IPage<BladeFlow> page, BladeFlow bladeFlow,String currentUserId) {
+		String taskUser = StringUtil.format("{}{}", TASK_USR_PREFIX, currentUserId);
 		List<BladeFlow> flowList = new LinkedList<>();
 
 		// 已签收的任务
@@ -249,6 +276,72 @@
 	}
 
 	@Override
+	public IPage<BladeFlowVO> selectDonePage(IPage<BladeFlowVO> page, BladeFlow bladeFlow,String currentUserId) {
+		String taskUser = StringUtil.format("{}{}", TASK_USR_PREFIX, currentUserId);
+		List<BladeFlowVO> 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 -> {
+			BladeFlowVO flow = new BladeFlowVO();
+			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();
@@ -268,6 +361,27 @@
 		return true;
 	}
 
+	@Override
+	public BladeFlow getBladeFlowByBusinessId(String businessId,String target) {
+		String taskUser = StringUtil.format("{}{}", TASK_USR_PREFIX, target);
+		List<BladeFlow> flowList = new LinkedList<>();
+
+		// 已签收的任务
+		TaskQuery todoQuery = taskService.createTaskQuery().taskAssignee(taskUser).active()
+			.includeProcessVariables().orderByTaskCreateTime().desc();
+		BladeFlow bladeFlow = new BladeFlow();
+		// 构建列表数据
+		buildFlowTaskList(bladeFlow, flowList, todoQuery, FlowEngineConstant.STATUS_TODO);
+		BladeFlow flow = new BladeFlow();
+		flowList.forEach(e->{
+			if (Func.equals(e.getBusinessId(),businessId)){
+				flow.setTaskId(e.getTaskId());
+			}
+		});
+
+		return flow;
+	}
+
 	/**
 	 * 构建流程
 	 *

--
Gitblit v1.9.3