From 688e4a78f9a7ce37913af682d575ec5e928dc29f Mon Sep 17 00:00:00 2001 From: smallchill Date: Thu, 31 Mar 2022 11:38:10 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8DProcessDefinition?= =?UTF-8?q?=E5=9C=A8redis=E7=BC=93=E5=AD=98json=E6=A8=A1=E5=BC=8F=E4=B8=8B?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/FlowBusinessServiceImpl.java | 8 +++--- .../flow/engine/entity/FlowProcess.java | 26 +++++++++++-------- .../service/impl/FlowEngineServiceImpl.java | 2 +- .../flow/engine/utils/FlowCache.java | 11 ++++++-- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/blade-ops/blade-flow/src/main/java/org/springblade/flow/business/service/impl/FlowBusinessServiceImpl.java b/blade-ops/blade-flow/src/main/java/org/springblade/flow/business/service/impl/FlowBusinessServiceImpl.java index b96e2926..0db6bba8 100644 --- a/blade-ops/blade-flow/src/main/java/org/springblade/flow/business/service/impl/FlowBusinessServiceImpl.java +++ b/blade-ops/blade-flow/src/main/java/org/springblade/flow/business/service/impl/FlowBusinessServiceImpl.java @@ -22,7 +22,6 @@ import org.flowable.engine.HistoryService; import org.flowable.engine.TaskService; import org.flowable.engine.history.HistoricProcessInstance; import org.flowable.engine.history.HistoricProcessInstanceQuery; -import org.flowable.engine.repository.ProcessDefinition; import org.flowable.task.api.TaskQuery; import org.flowable.task.api.history.HistoricTaskInstance; import org.flowable.task.api.history.HistoricTaskInstanceQuery; @@ -36,6 +35,7 @@ import org.springblade.flow.core.constant.ProcessConstant; import org.springblade.flow.core.entity.BladeFlow; import org.springblade.flow.core.utils.TaskUtil; import org.springblade.flow.engine.constant.FlowEngineConstant; +import org.springblade.flow.engine.entity.FlowProcess; import org.springblade.flow.engine.utils.FlowCache; import org.springframework.stereotype.Service; @@ -148,7 +148,7 @@ public class FlowBusinessServiceImpl implements FlowBusinessService { flow.setProcessInstanceId(historicProcessInstance.getId()); flow.setHistoryProcessInstanceId(historicProcessInstance.getId()); // ProcessDefinition - ProcessDefinition processDefinition = FlowCache.getProcessDefinition(historicProcessInstance.getProcessDefinitionId()); + FlowProcess processDefinition = FlowCache.getProcessDefinition(historicProcessInstance.getProcessDefinitionId()); flow.setProcessDefinitionId(processDefinition.getId()); flow.setProcessDefinitionName(processDefinition.getName()); flow.setProcessDefinitionVersion(processDefinition.getVersion()); @@ -216,7 +216,7 @@ public class FlowBusinessServiceImpl implements FlowBusinessService { flow.setHistoryTaskEndTime(historicTaskInstance.getEndTime()); flow.setVariables(historicTaskInstance.getProcessVariables()); - ProcessDefinition processDefinition = FlowCache.getProcessDefinition(historicTaskInstance.getProcessDefinitionId()); + FlowProcess processDefinition = FlowCache.getProcessDefinition(historicTaskInstance.getProcessDefinitionId()); flow.setProcessDefinitionId(processDefinition.getId()); flow.setProcessDefinitionName(processDefinition.getName()); flow.setProcessDefinitionKey(processDefinition.getKey()); @@ -307,7 +307,7 @@ public class FlowBusinessServiceImpl implements FlowBusinessService { flow.setBusinessId(businessKey[1]); } - ProcessDefinition processDefinition = FlowCache.getProcessDefinition(task.getProcessDefinitionId()); + FlowProcess processDefinition = FlowCache.getProcessDefinition(task.getProcessDefinitionId()); flow.setCategory(processDefinition.getCategory()); flow.setCategoryName(FlowCache.getCategoryName(processDefinition.getCategory())); flow.setProcessDefinitionId(processDefinition.getId()); diff --git a/blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/entity/FlowProcess.java b/blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/entity/FlowProcess.java index 9fd24006..f9df6d91 100644 --- a/blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/entity/FlowProcess.java +++ b/blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/entity/FlowProcess.java @@ -17,6 +17,7 @@ package org.springblade.flow.engine.entity; import lombok.Data; +import lombok.NoArgsConstructor; import org.flowable.engine.impl.persistence.entity.ProcessDefinitionEntityImpl; import org.springblade.flow.engine.utils.FlowCache; @@ -29,6 +30,7 @@ import java.util.Date; * @author Chill */ @Data +@NoArgsConstructor public class FlowProcess implements Serializable { private String id; @@ -45,17 +47,19 @@ public class FlowProcess implements Serializable { private Date deploymentTime; public FlowProcess(ProcessDefinitionEntityImpl entity) { - this.id = entity.getId(); - this.tenantId = entity.getTenantId(); - this.name = entity.getName(); - this.key = entity.getKey(); - this.category = entity.getCategory(); - this.categoryName = FlowCache.getCategoryName(entity.getCategory()); - this.version = entity.getVersion(); - this.deploymentId = entity.getDeploymentId(); - this.resourceName = entity.getResourceName(); - this.diagramResourceName = entity.getDiagramResourceName(); - this.suspensionState = entity.getSuspensionState(); + if (entity != null) { + this.id = entity.getId(); + this.tenantId = entity.getTenantId(); + this.name = entity.getName(); + this.key = entity.getKey(); + this.category = entity.getCategory(); + this.categoryName = FlowCache.getCategoryName(entity.getCategory()); + this.version = entity.getVersion(); + this.deploymentId = entity.getDeploymentId(); + this.resourceName = entity.getResourceName(); + this.diagramResourceName = entity.getDiagramResourceName(); + this.suspensionState = entity.getSuspensionState(); + } } } diff --git a/blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/service/impl/FlowEngineServiceImpl.java b/blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/service/impl/FlowEngineServiceImpl.java index cfc15766..d8b61a92 100644 --- a/blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/service/impl/FlowEngineServiceImpl.java +++ b/blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/service/impl/FlowEngineServiceImpl.java @@ -151,7 +151,7 @@ public class FlowEngineServiceImpl extends ServiceImpl im flowExecution.setProcessDefinitionId(execution.getProcessDefinitionId()); flowExecution.setProcessDefinitionKey(execution.getProcessDefinitionKey()); flowExecution.setSuspensionState(execution.getSuspensionState()); - ProcessDefinition processDefinition = FlowCache.getProcessDefinition(execution.getProcessDefinitionId()); + FlowProcess processDefinition = FlowCache.getProcessDefinition(execution.getProcessDefinitionId()); flowExecution.setCategory(processDefinition.getCategory()); flowExecution.setCategoryName(FlowCache.getCategoryName(processDefinition.getCategory())); flowList.add(flowExecution); diff --git a/blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/utils/FlowCache.java b/blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/utils/FlowCache.java index 8cc797ba..a8d0745e 100644 --- a/blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/utils/FlowCache.java +++ b/blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/utils/FlowCache.java @@ -17,11 +17,14 @@ package org.springblade.flow.engine.utils; import org.flowable.engine.RepositoryService; +import org.flowable.engine.impl.persistence.entity.ProcessDefinitionEntityImpl; import org.flowable.engine.repository.ProcessDefinition; import org.springblade.core.cache.utils.CacheUtil; +import org.springblade.core.tool.utils.BeanUtil; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.SpringUtil; import org.springblade.core.tool.utils.StringPool; +import org.springblade.flow.engine.entity.FlowProcess; import org.springblade.system.cache.DictCache; import static org.springblade.core.cache.constant.CacheConstant.FLOW_CACHE; @@ -49,8 +52,12 @@ public class FlowCache { * @param processDefinitionId 流程对象id * @return */ - public static ProcessDefinition getProcessDefinition(String processDefinitionId) { - return CacheUtil.get(FLOW_CACHE, FLOW_DEFINITION_ID , processDefinitionId, () -> getRepositoryService().createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult()); + public static FlowProcess getProcessDefinition(String processDefinitionId) { + return CacheUtil.get(FLOW_CACHE, FLOW_DEFINITION_ID, processDefinitionId, () -> { + ProcessDefinition processDefinition = getRepositoryService().createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult(); + ProcessDefinitionEntityImpl processDefinitionEntity = BeanUtil.copy(processDefinition, ProcessDefinitionEntityImpl.class); + return new FlowProcess(processDefinitionEntity); + }); } /**