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字符串 * bpmnModel转xml字符串
* *
* @deprecated 存在会丢失 bpmn 连线问题
* @param bpmnModel bpmnModel对象 * @param bpmnModel bpmnModel对象
* @return xml字符串 * @return xml字符串
*/ */
@Deprecated
public static String getBpmnXmlStr(BpmnModel bpmnModel) { public static String getBpmnXmlStr(BpmnModel bpmnModel) {
return StrUtil.utf8Str(getBpmnXml(bpmnModel)); return StrUtil.utf8Str(getBpmnXml(bpmnModel));
} }
@@ -40,9 +42,11 @@ public class ModelUtils {
/** /**
* bpmnModel转xml对象 * bpmnModel转xml对象
* *
* @deprecated 存在丢失 bpmn 连线问题
* @param bpmnModel bpmnModel对象 * @param bpmnModel bpmnModel对象
* @return xml * @return xml
*/ */
@Deprecated
public static byte[] getBpmnXml(BpmnModel bpmnModel) { public static byte[] getBpmnXml(BpmnModel bpmnModel) {
return bpmnXMLConverter.convertToXML(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.Deployment;
import org.flowable.engine.repository.Model; import org.flowable.engine.repository.Model;
import org.flowable.engine.repository.ModelQuery; import org.flowable.engine.repository.ModelQuery;
import org.flowable.engine.repository.ProcessDefinition;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@@ -215,17 +217,6 @@ public class WfModelServiceImpl extends FlowServiceFactory implements IWfModelSe
if (ObjectUtil.isNull(model)) { if (ObjectUtil.isNull(model)) {
throw new RuntimeException("流程模型不存在!"); 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()); model.setCategory(modelBo.getCategory());
WfMetaInfoDto metaInfoDto = JsonUtils.parseObject(model.getMetaInfo(), WfMetaInfoDto.class); WfMetaInfoDto metaInfoDto = JsonUtils.parseObject(model.getMetaInfo(), WfMetaInfoDto.class);
String metaInfo = buildMetaInfo(metaInfoDto, modelBo.getDescription()); String metaInfo = buildMetaInfo(metaInfoDto, modelBo.getDescription());
@@ -272,7 +263,8 @@ public class WfModelServiceImpl extends FlowServiceFactory implements IWfModelSe
// 保存流程模型 // 保存流程模型
repositoryService.saveModel(newModel); repositoryService.saveModel(newModel);
// 保存 BPMN XML // 保存 BPMN XML
repositoryService.addModelEditorSource(newModel.getId(), ModelUtils.getBpmnXml(bpmnModel)); byte[] bpmnXmlBytes = StringUtils.getBytes(modelBo.getBpmnXml(), StandardCharsets.UTF_8);
repositoryService.addModelEditorSource(newModel.getId(), bpmnXmlBytes);
} }
@Override @Override
@@ -283,7 +275,6 @@ public class WfModelServiceImpl extends FlowServiceFactory implements IWfModelSe
if (ObjectUtil.isNull(model)) { if (ObjectUtil.isNull(model)) {
throw new RuntimeException("流程模型不存在!"); throw new RuntimeException("流程模型不存在!");
} }
String bpmnXml = queryBpmnXmlById(modelId);
Integer latestVersion = repositoryService.createModelQuery() Integer latestVersion = repositoryService.createModelQuery()
.modelKey(model.getKey()) .modelKey(model.getKey())
.latestVersion() .latestVersion()
@@ -292,6 +283,8 @@ public class WfModelServiceImpl extends FlowServiceFactory implements IWfModelSe
if (model.getVersion().equals(latestVersion)) { if (model.getVersion().equals(latestVersion)) {
throw new RuntimeException("当前版本已是最新版!"); throw new RuntimeException("当前版本已是最新版!");
} }
// 获取 BPMN XML
byte[] bpmnBytes = repositoryService.getModelEditorSource(modelId);
Model newModel = repositoryService.newModel(); Model newModel = repositoryService.newModel();
newModel.setName(model.getName()); newModel.setName(model.getName());
newModel.setKey(model.getKey()); newModel.setKey(model.getKey());
@@ -301,7 +294,7 @@ public class WfModelServiceImpl extends FlowServiceFactory implements IWfModelSe
// 保存流程模型 // 保存流程模型
repositoryService.saveModel(newModel); repositoryService.saveModel(newModel);
// 保存 BPMN XML // 保存 BPMN XML
repositoryService.addModelEditorSource(newModel.getId(), StrUtil.utf8Bytes(bpmnXml)); repositoryService.addModelEditorSource(newModel.getId(), bpmnBytes);
} }
@Override @Override
@@ -325,16 +318,22 @@ public class WfModelServiceImpl extends FlowServiceFactory implements IWfModelSe
throw new RuntimeException("流程模型不存在!"); 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); BpmnModel bpmnModel = ModelUtils.getBpmnModel(bpmnXml);
String processName = model.getName() + ProcessConstants.SUFFIX; String processName = model.getName() + ProcessConstants.SUFFIX;
// 部署流程 // 部署流程
Deployment deployment = repositoryService.createDeployment() Deployment deployment = repositoryService.createDeployment()
.name(model.getName()) .name(model.getName())
.key(model.getKey()) .key(model.getKey())
.addBpmnModel(processName, bpmnModel)
.category(model.getCategory()) .category(model.getCategory())
.addBytes(processName, bpmnBytes)
.deploy(); .deploy();
ProcessDefinition procDef = repositoryService.createProcessDefinitionQuery()
.deploymentId(deployment.getId())
.singleResult();
// 修改流程定义的分类,便于搜索流程
repositoryService.setProcessDefinitionCategory(procDef.getId(), model.getCategory());
// 保存部署表单 // 保存部署表单
return deployFormService.saveInternalDeployForm(deployment.getId(), bpmnModel); 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.IORuntimeException;
import cn.hutool.core.io.IoUtil; import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.PageQuery; import com.ruoyi.common.core.domain.PageQuery;
@@ -626,8 +627,10 @@ public class WfProcessServiceImpl extends FlowServiceFactory implements IWfProce
detailVo.setTaskFormData(currTaskFormData(historicProcIns.getDeploymentId(), taskIns)); detailVo.setTaskFormData(currTaskFormData(historicProcIns.getDeploymentId(), taskIns));
} }
// 获取Bpmn模型信息 // 获取Bpmn模型信息
BpmnModel bpmnModel = repositoryService.getBpmnModel(historicProcIns.getProcessDefinitionId()); InputStream inputStream = repositoryService.getProcessModel(historicProcIns.getProcessDefinitionId());
detailVo.setBpmnXml(ModelUtils.getBpmnXmlStr(bpmnModel)); String bpmnXmlStr = StrUtil.utf8Str(IoUtil.readBytes(inputStream, false));
BpmnModel bpmnModel = ModelUtils.getBpmnModel(bpmnXmlStr);
detailVo.setBpmnXml(bpmnXmlStr);
detailVo.setHistoryProcNodeList(historyProcNodeList(historicProcIns)); detailVo.setHistoryProcNodeList(historyProcNodeList(historicProcIns));
detailVo.setProcessFormList(processFormList(bpmnModel, historicProcIns)); detailVo.setProcessFormList(processFormList(bpmnModel, historicProcIns));
detailVo.setFlowViewer(getFlowViewer(bpmnModel, procInsId)); detailVo.setFlowViewer(getFlowViewer(bpmnModel, procInsId));