模型转换 EPC转BPMN 路径绘制中 全局引用ref未替换导致报错问题解决

This commit is contained in:
qinoy 2023-11-13 15:14:52 +08:00
parent b120ff61bb
commit cd7c725d43
3 changed files with 155 additions and 2 deletions

View File

@ -17,7 +17,9 @@ import com.actionsoft.apps.coe.pal.pal.repository.dao.CoeProcessLevelDaoFacotory
import com.actionsoft.apps.coe.pal.pal.repository.dao.PALRepository;
import com.actionsoft.apps.coe.pal.pal.repository.dao.PALRepositoryAttributeDao;
import com.actionsoft.apps.coe.pal.pal.repository.dao.PALRepositoryShapeAttributeDao;
import com.actionsoft.apps.coe.pal.pal.repository.designer.CoeDesignerShapeAPIManager;
import com.actionsoft.apps.coe.pal.pal.repository.designer.manage.CoeDesignerAPIManager;
import com.actionsoft.apps.coe.pal.pal.repository.designer.model.BPMNModel;
import com.actionsoft.apps.coe.pal.pal.repository.designer.model.BaseModel;
import com.actionsoft.apps.coe.pal.pal.repository.designer.util.CoeDesignerUtil;
import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryAttributeModel;
@ -219,11 +221,17 @@ public class EpcToBPMN implements ModelConvertStrategy {
}
});
bpmnElements.keySet().forEach(key -> {
JSONObject eleObj = bpmnElements.getJSONObject(key);
this.handleDefaultDataAttribute(eleObj);
});
// 2.根据处理好的数据生成BPMN模型
BaseModel model = CoeDesignerAPIManager.getInstance().getDefinition(bpmnModelId, 0);
BPMNModel model = CoeDesignerAPIManager.getInstance().getDefinitionOfBpmn(bpmnModelId, 0);
if (model == null) {
model = CoeDesignerUtil.createModel(bpmnModelId, 0);
model = CoeDesignerUtil.createBPMNModel(bpmnModelId, 0);
}
String bpmnDefinition = model.getDefinition();
JSONObject bpmnDefineObj = JSONObject.parseObject(bpmnDefinition);
bpmnDefineObj.put("elements",bpmnElements);
@ -240,6 +248,16 @@ public class EpcToBPMN implements ModelConvertStrategy {
define = define.replace(key,ConvertUtil.getSchemaShapeMapping().get(key));
}
CoeDesignerShapeAPIManager manager = CoeDesignerShapeAPIManager.getInstance();
//获取流程定义和排序
JSONObject object = manager.getBpmnDefinitionAndSort(define, "6f4e292c-1b90-4dd2-8c20-7da159cb20a5", targetMethod);
define = object.getString("define");
List<String> sortList = (List<String>) object.get("sort");
//处理流程节点形状的通用配置
JSONObject obj = manager.getCoeProcessShapeConfig(define, "6f4e292c-1b90-4dd2-8c20-7da159cb20a5", targetMethod, bpmnModelId);
define = obj.getString("define");
model.setDefinition(define);
CoeDesignerAPIManager.getInstance().storeDefinition(model);
}
@ -514,6 +532,41 @@ public class EpcToBPMN implements ModelConvertStrategy {
}
}
private void handleDefaultDataAttribute(JSONObject shapeDefinition){
String eleName = shapeDefinition.getString("name");
if ("linker".equals(eleName)) return; // 根据新建的结果看 连线先不做处理
if (shapeDefinition.containsKey("dataAttributes")){
JSONArray dataAttributes = shapeDefinition.getJSONArray("dataAttributes");
dataAttributes.forEach(item -> {
JSONObject obj = (JSONObject) item;
obj.put("id", UUIDGener.getObjectId());
});
JSONArray array = JSONArray.parseArray(ConvertUtil.bpmnDataAttrbuiteDefault);
for (int i = 0; i < array.size(); i++) {
JSONObject item = array.getJSONObject(i);
item.put("id", UUIDGener.getObjectId());
dataAttributes.add(i, item);
}
}
// 处理全局引用问题
if (shapeDefinition.containsKey("path")) {
JSONArray shapePath = shapeDefinition.getJSONArray("path");
for (int i = 0; i < shapePath.size(); i++) {
JSONObject object = shapePath.getJSONObject(i);
if (object.containsKey("actions")) {
Object actions = object.get("actions");
if (actions.toString().startsWith("{")) {
JSONObject object2 = JSONObject.parseObject(actions.toString());
if (object2.containsKey("ref") && ConvertUtil.globalCommandMapping.containsKey(object2.getString("ref"))) {
object.put("actions", JSONArray.parseArray(ConvertUtil.globalCommandMapping.get(object2.getString("ref"))));
}
}
}
}
}
}
// 处理图形转换
private void handleShapeConvert(JSONObject elements,JSONObject bpmnElements,Map<String,Integer> zIndexMap,int epcPageWidth,String targetMethod){
elements.keySet().stream().forEach(key -> {