fix: 修复 流程图回显时,网关连线缺失问题。

This commit is contained in:
konbai
2023-03-02 01:39:11 +08:00
parent a3d3f962a3
commit a170d7d4c0
3 changed files with 24 additions and 18 deletions

View File

@@ -30,9 +30,11 @@ public class ModelUtils {
/**
* bpmnModel转xml字符串
*
* @deprecated 存在会丢失 bpmn 连线问题
* @param bpmnModel bpmnModel对象
* @return xml字符串
*/
@Deprecated
public static String getBpmnXmlStr(BpmnModel bpmnModel) {
return StrUtil.utf8Str(getBpmnXml(bpmnModel));
}
@@ -40,9 +42,11 @@ public class ModelUtils {
/**
* bpmnModel转xml对象
*
* @deprecated 存在丢失 bpmn 连线问题
* @param bpmnModel bpmnModel对象
* @return xml
*/
@Deprecated
public static byte[] getBpmnXml(BpmnModel bpmnModel) {
return bpmnXMLConverter.convertToXML(bpmnModel);
}

View File

@@ -26,9 +26,11 @@ import org.flowable.bpmn.model.StartEvent;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.repository.Model;
import org.flowable.engine.repository.ModelQuery;
import org.flowable.engine.repository.ProcessDefinition;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -215,17 +217,6 @@ public class WfModelServiceImpl extends FlowServiceFactory implements IWfModelSe
if (ObjectUtil.isNull(model)) {
throw new RuntimeException("流程模型不存在!");
}
// 修改模型分类信息
if (ObjectUtil.notEqual(model.getCategory(), modelBo.getCategory())) {
byte[] bpmnBytes = repositoryService.getModelEditorSource(model.getId());
if (ObjectUtil.isNotEmpty(bpmnBytes)) {
BpmnModel bpmnModel = ModelUtils.getBpmnModel(StrUtil.utf8Str(bpmnBytes));
// 设置最新流程分类编码
bpmnModel.setTargetNamespace(model.getCategory());
// 保存 BPMN XML
repositoryService.addModelEditorSource(model.getId(), ModelUtils.getBpmnXml(bpmnModel));
}
}
model.setCategory(modelBo.getCategory());
WfMetaInfoDto metaInfoDto = JsonUtils.parseObject(model.getMetaInfo(), WfMetaInfoDto.class);
String metaInfo = buildMetaInfo(metaInfoDto, modelBo.getDescription());
@@ -272,7 +263,8 @@ public class WfModelServiceImpl extends FlowServiceFactory implements IWfModelSe
// 保存流程模型
repositoryService.saveModel(newModel);
// 保存 BPMN XML
repositoryService.addModelEditorSource(newModel.getId(), ModelUtils.getBpmnXml(bpmnModel));
byte[] bpmnXmlBytes = StringUtils.getBytes(modelBo.getBpmnXml(), StandardCharsets.UTF_8);
repositoryService.addModelEditorSource(newModel.getId(), bpmnXmlBytes);
}
@Override
@@ -283,7 +275,6 @@ public class WfModelServiceImpl extends FlowServiceFactory implements IWfModelSe
if (ObjectUtil.isNull(model)) {
throw new RuntimeException("流程模型不存在!");
}
String bpmnXml = queryBpmnXmlById(modelId);
Integer latestVersion = repositoryService.createModelQuery()
.modelKey(model.getKey())
.latestVersion()
@@ -292,6 +283,8 @@ public class WfModelServiceImpl extends FlowServiceFactory implements IWfModelSe
if (model.getVersion().equals(latestVersion)) {
throw new RuntimeException("当前版本已是最新版!");
}
// 获取 BPMN XML
byte[] bpmnBytes = repositoryService.getModelEditorSource(modelId);
Model newModel = repositoryService.newModel();
newModel.setName(model.getName());
newModel.setKey(model.getKey());
@@ -301,7 +294,7 @@ public class WfModelServiceImpl extends FlowServiceFactory implements IWfModelSe
// 保存流程模型
repositoryService.saveModel(newModel);
// 保存 BPMN XML
repositoryService.addModelEditorSource(newModel.getId(), StrUtil.utf8Bytes(bpmnXml));
repositoryService.addModelEditorSource(newModel.getId(), bpmnBytes);
}
@Override
@@ -325,16 +318,22 @@ public class WfModelServiceImpl extends FlowServiceFactory implements IWfModelSe
throw new RuntimeException("流程模型不存在!");
}
// 获取流程图
String bpmnXml = queryBpmnXmlById(modelId);
byte[] bpmnBytes = repositoryService.getModelEditorSource(modelId);
String bpmnXml = StringUtils.toEncodedString(bpmnBytes, StandardCharsets.UTF_8);
BpmnModel bpmnModel = ModelUtils.getBpmnModel(bpmnXml);
String processName = model.getName() + ProcessConstants.SUFFIX;
// 部署流程
Deployment deployment = repositoryService.createDeployment()
.name(model.getName())
.key(model.getKey())
.addBpmnModel(processName, bpmnModel)
.category(model.getCategory())
.addBytes(processName, bpmnBytes)
.deploy();
ProcessDefinition procDef = repositoryService.createProcessDefinitionQuery()
.deploymentId(deployment.getId())
.singleResult();
// 修改流程定义的分类,便于搜索流程
repositoryService.setProcessDefinitionCategory(procDef.getId(), model.getCategory());
// 保存部署表单
return deployFormService.saveInternalDeployForm(deployment.getId(), bpmnModel);
}

View File

@@ -7,6 +7,7 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.PageQuery;
@@ -626,8 +627,10 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
detailVo.setTaskFormData(currTaskFormData(historicProcIns.getDeploymentId(), taskIns));
}
// 获取Bpmn模型信息
BpmnModel bpmnModel = repositoryService.getBpmnModel(historicProcIns.getProcessDefinitionId());
detailVo.setBpmnXml(ModelUtils.getBpmnXmlStr(bpmnModel));
InputStream inputStream = repositoryService.getProcessModel(historicProcIns.getProcessDefinitionId());
String bpmnXmlStr = StrUtil.utf8Str(IoUtil.readBytes(inputStream, false));
BpmnModel bpmnModel = ModelUtils.getBpmnModel(bpmnXmlStr);
detailVo.setBpmnXml(bpmnXmlStr);
detailVo.setHistoryProcNodeList(historyProcNodeList(historicProcIns));
detailVo.setProcessFormList(processFormList(bpmnModel, historicProcIns));
detailVo.setFlowViewer(getFlowViewer(bpmnModel, procInsId));