端到端功能 节点闭合代码优化
This commit is contained in:
parent
f7f93e1f9f
commit
ea80535d27
Binary file not shown.
@ -31,15 +31,11 @@ public class GraphNodeCloseHandle {
|
||||
private String shapeId; // 总图中当前要关闭的子流程图形ID
|
||||
private CoeDesignerAPIManager apiManager;
|
||||
private String relationFileId; // 当前要关闭的子流程图形所标识模型文件ID
|
||||
private JSONObject childProcessDefine; // 要关闭的子流程模型信息
|
||||
private JSONObject endToEndProcessDefine; // 总图的模型信息
|
||||
private JSONObject scopeLimitationShape; // 范围标注框
|
||||
private AbstractDefinitionHandle definitionHandle;
|
||||
private AbstractDefinitionHandle subProcessNodeDefineHandle;
|
||||
private AbstractDefinitionHandle definitionHandle; // 当前总图 define 处理器
|
||||
private AbstractDefinitionHandle subProcessNodeDefineHandle; // 子流程节点 define 处理器
|
||||
|
||||
private final ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
public GraphNodeCloseHandle(String repositoryId, String shapeId, String endToEndProcessDefineStr) {
|
||||
public GraphNodeCloseHandle(String repositoryId, String shapeId, String endToEndProcessDefineStr) throws AWSException{
|
||||
this.repositoryId = repositoryId;
|
||||
this.shapeId = shapeId;
|
||||
|
||||
@ -53,46 +49,13 @@ public class GraphNodeCloseHandle {
|
||||
|
||||
subProcessNodeDefineHandle = new DefinitionThreadUnSafe(SubProcessNodeDefineUtil.readSubProcessNodeDefine(repositoryId, shapeId));
|
||||
|
||||
readChildProcessDefine();
|
||||
readCurrentProcessDefine(endToEndProcessDefineStr);
|
||||
scopeLimitationShape = definitionHandle.getShapeByKey(shapeId);
|
||||
|
||||
} catch (AWSException e) {
|
||||
throw new AWSException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取子流程节点的存储信息
|
||||
* @throws AWSException
|
||||
*/
|
||||
private void readChildProcessDefine() throws AWSException{
|
||||
List<DesignerShapeRelationModel> childProcessModelList = DesignerShapeRelationCache.getListByAttrId(repositoryId, shapeId, SubProcessConst.CHILD_PROCESS);
|
||||
DesignerShapeRelationModel relationModel = childProcessModelList.stream().findFirst().orElse(null);
|
||||
if (relationModel == null)
|
||||
throw new AWSException("未找到当前节点所标识的子流程文件信息");
|
||||
relationFileId = relationModel.getRelationFileId();
|
||||
// 先去与总图存储的同级目录下读取 如果为空说明是初次读取
|
||||
String childProcessDefineStr = apiManager.getChildProcessDefine(repositoryId, 0, relationFileId);
|
||||
if (UtilString.isEmpty(childProcessDefineStr)){ // 初次读取 去源文件目录读取
|
||||
BaseModel childProcessBaseModel = apiManager.getDefinition(relationFileId, 0);
|
||||
if (childProcessBaseModel == null)
|
||||
throw new AWSException("当前子流程节点内部可能没有图形元素,可以去添加后展开");
|
||||
childProcessDefineStr = childProcessBaseModel.getDefinition();
|
||||
}
|
||||
childProcessDefine = JSONObject.parseObject(childProcessDefineStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取当前总图的存储信息
|
||||
* @throws AWSException
|
||||
*/
|
||||
private void readCurrentProcessDefine(String endToEndProcessDefineStr) throws AWSException{
|
||||
if (UtilString.isEmpty(endToEndProcessDefineStr))
|
||||
throw new AWSException("参数异常,模型存储信息未传");
|
||||
endToEndProcessDefine = JSONObject.parseObject(endToEndProcessDefineStr);
|
||||
|
||||
scopeLimitationShape= endToEndProcessDefine.getJSONObject("elements").getJSONObject(shapeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理节点关闭
|
||||
* @return
|
||||
@ -102,28 +65,27 @@ public class GraphNodeCloseHandle {
|
||||
|
||||
|
||||
// 1、处理范围选择框及其内部节点
|
||||
handleRelationModelNodePosition();
|
||||
removeScopeShapeAndInRangeEle();
|
||||
|
||||
// 2、处理总图中的节点与连线
|
||||
handleEndToEndGraphNodeAndLinker();
|
||||
|
||||
return endToEndProcessDefine.toJSONString();
|
||||
return definitionHandle.getDefine().toJSONString();
|
||||
}
|
||||
|
||||
private void handleEndToEndGraphNodeAndLinker(){
|
||||
// 1、创建对应子流程节点
|
||||
JSONObject subProcessNode = buildSubProcessNode(shapeId, scopeLimitationShape);
|
||||
addEndToEndGraphElements(subProcessNode);
|
||||
definitionHandle.addEle(shapeId, subProcessNode);
|
||||
// 2、根据现有连线关系创建邻接矩阵
|
||||
NodeCloseAdjMatrix closeAdjMatrix = buildEndToEndGraphAdjMatrix();
|
||||
closeAdjMatrix.buildAdjMatrix();
|
||||
|
||||
JSONObject elements = readEndToEndGraphElements();
|
||||
JSONObject elements = definitionHandle.getElements();
|
||||
// 更新因节点展开后 坐标发生变化的节点坐标
|
||||
String direction = definitionHandle.getProcessProperties().getString("direction");
|
||||
graphPartNodePoiRenderAgain(elements, direction, subProcessNode);
|
||||
// 3、收集现有元素坐标
|
||||
|
||||
double[][] vertexPosition = closeAdjMatrix.getVertexPosition(elements);
|
||||
// 4、删除现有连线
|
||||
removeEndToEndGraphOldLinker();
|
||||
@ -132,7 +94,7 @@ public class GraphNodeCloseHandle {
|
||||
JSONArray linkers = linkerRender.toAssembleLinker(direction, shapeId);
|
||||
for (Object o : linkers) {
|
||||
JSONObject linker = (JSONObject) o;
|
||||
addEndToEndGraphElements(linker);
|
||||
definitionHandle.addEle(linker.getString("id"), linker);
|
||||
}
|
||||
|
||||
// 6、更新画布的大小
|
||||
@ -140,17 +102,11 @@ public class GraphNodeCloseHandle {
|
||||
double w = Arrays.stream(vertexPosition).mapToDouble(position -> position[0]).max().orElse(0.0);
|
||||
double h = Arrays.stream(vertexPosition).mapToDouble(position -> position[1]).max().orElse(0.0);
|
||||
|
||||
JSONObject page = endToEndProcessDefine.getJSONObject("page");
|
||||
JSONObject page = definitionHandle.getPage();
|
||||
page.put("width", w + 300);
|
||||
page.put("height", h + 300);
|
||||
}
|
||||
|
||||
private void handleRelationModelNodePosition(){
|
||||
removeScopeShapeAndInRangeEle();
|
||||
removeEndToEndGraphElements(shapeId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 节点闭合 部分节点坐标再次更新
|
||||
*/
|
||||
@ -197,7 +153,7 @@ public class GraphNodeCloseHandle {
|
||||
* 删除总图中节点展开前的连线
|
||||
*/
|
||||
private void removeEndToEndGraphOldLinker(){
|
||||
JSONObject elements = endToEndProcessDefine.getJSONObject("elements");
|
||||
JSONObject elements = definitionHandle.getElements();
|
||||
Set<String> eleKeys = new HashSet<>();
|
||||
for (String key : elements.keySet()) {
|
||||
JSONObject ele = elements.getJSONObject(key);
|
||||
@ -206,7 +162,7 @@ public class GraphNodeCloseHandle {
|
||||
}
|
||||
}
|
||||
for (String eleKey : eleKeys) {
|
||||
removeEndToEndGraphElements(eleKey);
|
||||
definitionHandle.removeShape(eleKey);
|
||||
}
|
||||
}
|
||||
|
||||
@ -219,7 +175,7 @@ public class GraphNodeCloseHandle {
|
||||
|
||||
List<String> nodeIdList = new ArrayList<>();
|
||||
List<JSONObject> linkerList = new ArrayList<>();
|
||||
JSONObject endToEndProcessElements = endToEndProcessDefine.getJSONObject("elements");
|
||||
JSONObject endToEndProcessElements = definitionHandle.getElements();
|
||||
for (String key : endToEndProcessElements.keySet()) {
|
||||
JSONObject ele = endToEndProcessElements.getJSONObject(key);
|
||||
if ("linker".equals(ele.getString("name"))) {
|
||||
@ -255,55 +211,13 @@ public class GraphNodeCloseHandle {
|
||||
* 删除总图中范围选择框以及 框内元素
|
||||
*/
|
||||
private void removeScopeShapeAndInRangeEle(){
|
||||
JSONObject childProcessElements = childProcessDefine.getJSONObject("elements");
|
||||
for (String key : childProcessElements.keySet()) {
|
||||
removeEndToEndGraphElements(key);
|
||||
|
||||
Set<String> keys = SubProcessNodeDefineUtil.getInScopeLimitationRangeEles(shapeId, definitionHandle, subProcessNodeDefineHandle);
|
||||
for (String key : keys) {
|
||||
definitionHandle.removeShape(key);
|
||||
}
|
||||
|
||||
removeEndToEndGraphElements(shapeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取总图中的elements
|
||||
* @return elements
|
||||
*/
|
||||
private JSONObject readEndToEndGraphElements(){
|
||||
lock.lock();
|
||||
try {
|
||||
JSONObject elements = endToEndProcessDefine.getJSONObject("elements");
|
||||
return elements;
|
||||
}finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 总图中添加元素
|
||||
* @param ele
|
||||
*/
|
||||
private void addEndToEndGraphElements(JSONObject ele){
|
||||
lock.lock();
|
||||
try{
|
||||
JSONObject elements = readEndToEndGraphElements();
|
||||
String id = ele.getString("id");
|
||||
elements.put(id, ele);
|
||||
}finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 总图中删除元素
|
||||
* @param key
|
||||
*/
|
||||
private void removeEndToEndGraphElements(String key){
|
||||
lock.lock();
|
||||
try{
|
||||
JSONObject elements = readEndToEndGraphElements();
|
||||
elements.remove(key);
|
||||
}finally {
|
||||
lock.unlock();
|
||||
}
|
||||
definitionHandle.removeShape(shapeId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -9,17 +9,22 @@ import com.alibaba.fastjson.JSONObject;
|
||||
*/
|
||||
public abstract class AbstractDefinitionHandle {
|
||||
|
||||
private final String definition;
|
||||
private final JSONObject definition;
|
||||
|
||||
public AbstractDefinitionHandle(String definition) {
|
||||
this.definition = definition;
|
||||
this.definition = JSONObject.parseObject(definition);
|
||||
}
|
||||
|
||||
protected JSONObject getDefine(){
|
||||
JSONObject define = JSONObject.parseObject(definition);
|
||||
return define;
|
||||
public JSONObject getDefine(){
|
||||
return definition;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 page 属性
|
||||
* @return
|
||||
*/
|
||||
public abstract JSONObject getPage();
|
||||
|
||||
/**
|
||||
* 获取 elements 属性
|
||||
* @return
|
||||
@ -44,4 +49,21 @@ public abstract class AbstractDefinitionHandle {
|
||||
* @param ele
|
||||
*/
|
||||
public abstract void addEle(String key, JSONObject ele);
|
||||
|
||||
/**
|
||||
* 根据key获取elements中指定的图形
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public abstract JSONObject getShapeByKey(String key);
|
||||
|
||||
/**
|
||||
* 获取ele元素 中的props属性
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public abstract JSONObject getShapeByProps(String key);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -18,6 +18,16 @@ public class DefinitionThreadSafe extends AbstractDefinitionHandle {
|
||||
super(definition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getPage() {
|
||||
lock.lock();
|
||||
try {
|
||||
return getDefine().getJSONObject("page");
|
||||
}finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public JSONObject getElements(){
|
||||
lock.lock();
|
||||
try {
|
||||
@ -53,4 +63,24 @@ public class DefinitionThreadSafe extends AbstractDefinitionHandle {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getShapeByKey(String key) {
|
||||
lock.lock();
|
||||
try {
|
||||
return getElements().getJSONObject(key);
|
||||
}finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getShapeByProps(String key) {
|
||||
lock.lock();
|
||||
try{
|
||||
return getShapeByKey(key).getJSONObject("props");
|
||||
}finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,6 +14,11 @@ public class DefinitionThreadUnSafe extends AbstractDefinitionHandle {
|
||||
super(definition);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getPage() {
|
||||
return getDefine().getJSONObject("page");
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getElements() {
|
||||
return getDefine().getJSONObject("elements");
|
||||
@ -33,4 +38,14 @@ public class DefinitionThreadUnSafe extends AbstractDefinitionHandle {
|
||||
public void addEle(String key, JSONObject ele) {
|
||||
getElements().put(key, ele);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getShapeByKey(String key) {
|
||||
return getElements().getJSONObject(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject getShapeByProps(String key) {
|
||||
return getShapeByKey(key).getJSONObject("props");
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,7 +10,9 @@ import com.actionsoft.bpms.util.UtilString;
|
||||
import com.actionsoft.exception.AWSException;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author oYang
|
||||
@ -87,4 +89,39 @@ public class SubProcessNodeDefineUtil {
|
||||
double scopeShapeH = childProcessEleMaxY.getDoubleValue("y") + childProcessEleMaxY.getDoubleValue("h") - childProcessEleMinY.getDoubleValue("y") + SubProcessConst.SCOPE_SHAPE_PADDING;
|
||||
return new double[]{scopeShapeW, scopeShapeH};
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取在范围标识框内的元素
|
||||
* @param shapeId 当前范围标识框的图形ID
|
||||
* @param endToEndDefineHandle 总图 define 处理器
|
||||
* @param subProcessDefineHandle 子流程节点的 define 处理器
|
||||
* @return
|
||||
*/
|
||||
public static Set<String> getInScopeLimitationRangeEles(String shapeId, AbstractDefinitionHandle endToEndDefineHandle, AbstractDefinitionHandle subProcessDefineHandle){
|
||||
double[] widthAndHeight = calculateSubProcessNodeExpandScope(subProcessDefineHandle); // 获取当前子流程节点展开后的范围标识框 宽度与高度
|
||||
double scopeW = widthAndHeight[0], scopeH = widthAndHeight[1];
|
||||
double scopeX = endToEndDefineHandle.getShapeByProps(shapeId).getDoubleValue("x");
|
||||
double scopeY = endToEndDefineHandle.getShapeByProps(shapeId).getDoubleValue("y");
|
||||
// 判断当前元素是否在范围选择框的范围内
|
||||
Set<String> inRangeEleKeySet = new HashSet<>();
|
||||
for (String key : endToEndDefineHandle.getElements().keySet()) {
|
||||
if (key.equals(shapeId)) continue;
|
||||
JSONObject shape = endToEndDefineHandle.getShapeByKey(key);
|
||||
if ("linker".equals(shape.getString("name"))){ // 连线
|
||||
JSONObject from = shape.getJSONObject("from");
|
||||
JSONObject to = shape.getJSONObject("to");
|
||||
double fromX = from.getDoubleValue("x"), fromY = from.getDoubleValue("y"), toX = to.getDoubleValue("x"), toY = to.getDoubleValue("y");
|
||||
if ((scopeX < fromX && fromX < scopeX + scopeW && scopeY < fromY && fromY < scopeY + scopeH) || (scopeX < toX && toX < scopeX + scopeW && scopeY < toY && toY < scopeY + scopeH)){
|
||||
inRangeEleKeySet.add(key);
|
||||
}
|
||||
}else {
|
||||
double x = endToEndDefineHandle.getShapeByProps(key).getDoubleValue("x");
|
||||
double y = endToEndDefineHandle.getShapeByProps(key).getDoubleValue("y");
|
||||
if (scopeX <= x && x < scopeX + scopeW && scopeY <= y && y < scopeY + scopeH){
|
||||
inRangeEleKeySet.add(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
return inRangeEleKeySet;
|
||||
}
|
||||
}
|
||||
|
||||
@ -308,9 +308,10 @@ public class SubProcessWeb extends ActionWeb {
|
||||
|
||||
/**
|
||||
* 节点展开操作
|
||||
* @param repositoryId 当前总图ID
|
||||
* @param shapeId 待展开的子流程节点ID
|
||||
* @param direction 布局方向
|
||||
* @param repositoryId 当前端到端总图ID
|
||||
* @param shapeId 当前展开的子流程节点ID 如果为空 说明是一键展开操作
|
||||
* @param endToEndProcessDefineStr 模型define
|
||||
* @return 模型define
|
||||
*/
|
||||
public String shapeNodeExpand(String repositoryId, String shapeId, String endToEndProcessDefineStr){
|
||||
try {
|
||||
@ -324,6 +325,13 @@ public class SubProcessWeb extends ActionWeb {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 节点关闭操作
|
||||
* @param repositoryId 当前端到端总图ID
|
||||
* @param shapeId 当前闭合的子流程节点ID 如果为空 说明是一键闭合操作
|
||||
* @param endToEndProcessDefineStr 模型define
|
||||
* @return 模型define
|
||||
*/
|
||||
public String shapeNodeClose(String repositoryId, String shapeId, String endToEndProcessDefineStr){
|
||||
try {
|
||||
GraphNodeCloseHandle closeHandle = new GraphNodeCloseHandle(repositoryId, shapeId, endToEndProcessDefineStr);
|
||||
|
||||
@ -166,7 +166,6 @@ class SubProcess {
|
||||
window.subProcess.fileModifiedTip();
|
||||
},
|
||||
err: function(r){
|
||||
$.simpleAlert(r.msg);
|
||||
}
|
||||
});
|
||||
// 3、刷新当前画布
|
||||
|
||||
Loading…
Reference in New Issue
Block a user