Excel导入流程图位置重叠位置问题修复

This commit is contained in:
anhc 2022-09-16 15:33:30 +08:00
parent f50640681d
commit a1d74c2c33
3 changed files with 788 additions and 47 deletions

View File

@ -133,7 +133,10 @@ public class ImportShapeExcel1 {
//常规图形绘制
LogUtil.appendLog(BatchConst.LOG_DESC + "[执行阶段][绘制常规分支图形]", simpleLogFile, fullLogFile);
Map<String, Map<String, Map<String, List<CellObject>>>> branchData = fileDataMap.get(repositoryId);
double maxRight = this.drawBranchShape(repositoryId, branchData, offsetX, nodeMap, relationList);
JSONObject drawBranchShape = this.drawBranchShape(repositoryId, branchData, offsetX, nodeMap, relationList);
double maxRight = drawBranchShape.getDouble("rightMaxLine");
int maxLevel = drawBranchShape.getInteger("maxLevel");
rightMaxLine = Math.max(rightMaxLine,maxRight);
offsetX = rightMaxLine + 150;
@ -145,6 +148,7 @@ public class ImportShapeExcel1 {
if (specicalCell == null || specicalCell.isEmpty()){
continue;
}
for (int i = 0; i < specicalCell.size(); i++) {
CellObject node = specicalCell.get(i);
@ -152,7 +156,9 @@ public class ImportShapeExcel1 {
List<JSONObject> shapes = new ArrayList<>();
//节点画图,
JSONObject shape = this.drawShape(node, 0, offsetX, i, i);
JSONObject shape =this.drawShape(node, 0, offsetX, i, i);
//计算最右边界
rightMaxLine = this.getrightMaxLine(shape,rightMaxLine);
shapes.add(shape);
nodeMap.put(this.getCellObjectUUID(node),shapes);
@ -160,38 +166,49 @@ public class ImportShapeExcel1 {
//文件操作
LogUtil.appendLog(BatchConst.LOG_END + "[执行阶段][保存模型阶段]", simpleLogFile, fullLogFile);
this.saveDefine(repositoryId,nodeMap);
this.saveDefine(repositoryId,nodeMap,rightMaxLine,maxLevel);
// 更新其他自定义属性
LogUtil.appendLog(BatchConst.LOG_START + "完善模型内形状自定义属性配置", simpleLogFile, fullLogFile);
PALRepositoryAPIManager.getInstance().updateRepositoryProperty(repositoryId);
LogUtil.appendLog(BatchConst.LOG_END + "完善模型内形状自定义属性配置", simpleLogFile, fullLogFile);
}
LogUtil.appendLog(BatchConst.LOG_END + "[执行结束][Excel导入完成]", simpleLogFile, fullLogFile);
}
private double drawBranchShape(String repositoryId,Map<String, Map<String, Map<String, List<CellObject>>>> branchData,double originOffsetX,Map<String,List<JSONObject>> nodeMap,List<DesignerShapeRelationModel> relationList){
private JSONObject drawBranchShape(String repositoryId,Map<String, Map<String, Map<String, List<CellObject>>>> branchData,double originOffsetX,Map<String,List<JSONObject>> nodeMap,
List<DesignerShapeRelationModel> relationList){
JSONObject res = new JSONObject();
res.put("rightMaxLine",0);
res.put("maxLevel",0);
if (branchData==null || branchData.isEmpty()){
return 0;
return res;
}
double rightMaxLine = 0;
double offsetX = originOffsetX;
int maxLevelNum = 0;
for (Map.Entry<String, Map<String, Map<String, List<CellObject>>>> branch : branchData.entrySet()) {
//int offsetX = offsetX + rightMaxLine;
// <层级同级别map>
Map<String, Map<String, List<CellObject>>> levelMap = branch.getValue();
//获取最大层级
int maxLevel = levelMap.keySet().size();
maxLevelNum = Math.max(maxLevel,maxLevelNum);
//遍历层级产出图+连线
for (int level = 0; level < maxLevel; level++) {
//同层级多分支节点信息, <序号同序号listNode>
Map<String, List<CellObject>> numList = levelMap.get("" + level);
//计算同层级索引
int levelNodeIndex = 0;
for (int i = 0; i < numList.keySet().size()+1; i++) {
// double offset = startNodeOffset;
//构建同层级的分支序号
String levelNo = this.getLevelNo(level, i);
@ -201,11 +218,6 @@ public class ImportShapeExcel1 {
continue;
}
// if (levelNo.equals("5.2")){
// Object o = new Object();
// }
//找到上级节点可跨级
JSONObject upNodes = this.findUpLevelNode(levelNo, levelMap, nodeMap);
JSONArray upList = upNodes.getJSONArray("upList");
@ -225,27 +237,29 @@ public class ImportShapeExcel1 {
size = numList.keySet().size();
}
}else{
//多个父级节点计算偏移量
Double minX = null;
Double maxX = null;
for (int upIndex = 0; upIndex < upList.size(); upIndex++) {
JSONObject upNode = upList.getJSONObject(upIndex);
JSONObject props = (JSONObject)upNode.get("props");
if (minX == null && maxX == null){
minX = props.getDouble("x");
maxX = minX;
if (levelNo.contains(".")){
//当前节点是分支下节点
//多个父级节点计算偏移量
Double minX = null;
Double maxX = null;
for (int upIndex = 0; upIndex < upList.size(); upIndex++) {
JSONObject upNode = upList.getJSONObject(upIndex);
JSONObject props = (JSONObject)upNode.get("props");
if (minX == null && maxX == null){
minX = props.getDouble("x");
maxX = minX;
}
maxX = Math.max(props.getDouble("x"), maxX);
minX = Math.min(props.getDouble("x"), minX);
}
maxX = Math.max(props.getDouble("x"), maxX);
minX = Math.min(props.getDouble("x"), minX);
levelOffset =((maxX - minX) * 0.5 ) + minX;
}
levelOffset =((maxX - minX) * 0.5 ) + minX;
}
}
//同级别节点是一分二分节点节点计算offset
//同级别节点是一分二分节点三分节点计算offset
double offset = this.getLevelStartNodeOffset(size,levelOffset);
for (int nodeIndex = 0; nodeIndex < nodes.size(); nodeIndex++,levelNodeIndex++) {
CellObject node = nodes.get(nodeIndex);
@ -258,23 +272,10 @@ public class ImportShapeExcel1 {
//计算最右边边界
rightMaxLine = this.getrightMaxLine(shape, rightMaxLine);
//图形拓展属性处理
JSONArray attributesJsonArray = new JSONArray();
JSONArray expandArr = node.getExpandArr();
this.handleExpandAttr(repositoryId,shape,expandArr,attributesJsonArray,relationList);
if (attributesJsonArray.size() > 0) {
JSONArray dataAttributes = shape.getJSONArray("dataAttributes");
if (!dataAttributes.isEmpty() && dataAttributes.size() > 0) {
for (Object attribute : dataAttributes) {
JSONObject obj = (JSONObject) attribute;
if (obj.containsKey("attributesJsonArray")) {
obj.put("attributesJsonArray", attributesJsonArray);
break;
}
}
}
}
this.handleExpandAttr(repositoryId,shape,expandArr,relationList);
shapes.add(shape);
if (upNodes.getBooleanValue("isUp")){
@ -295,10 +296,675 @@ public class ImportShapeExcel1 {
}
}
}
//位置重叠偏移计算
//左边界
double leftMinLine = offsetX - ShapeConst.SHAPE_BRANCH_INTERVAL;
JSONObject object = this.changeShapePosition(levelMap, nodeMap, offsetX, rightMaxLine, leftMinLine);
Double changeLeftMinLine = object.getDouble("leftMinLine");
Double changeRightMaxLine = object.getDouble("rightMaxLine");
rightMaxLine = Math.max(changeRightMaxLine,rightMaxLine);
// leftMinLine = Math.min(leftMinLine,changeLeftMinLine);
//比较返回左边界<leftMinLine 则需要将分支整体向右调整offset = leftMinLine - 左边界
if (changeLeftMinLine <= leftMinLine){
//整体调整分支偏移量
//计算偏移
double offset = leftMinLine - changeLeftMinLine + 100;
double moveToRightOffset = this.branchMoveToRight(levelMap, nodeMap, offset, rightMaxLine);
rightMaxLine = Math.max(moveToRightOffset,rightMaxLine);
}
offsetX = rightMaxLine + ShapeConst.SHAPE_BRANCH_INTERVAL;
}
return rightMaxLine;
res.put("rightMaxLine",rightMaxLine);
res.put("maxLevel",maxLevelNum);
return res;
}
private double branchMoveToRight(Map<String, Map<String, List<CellObject>>> levelMap,Map<String,List<JSONObject>> nodeMap,double offset,double rightMaxLine){
double rightLine = rightMaxLine;
//获取最大层级
int maxLevel = levelMap.keySet().size();
for (int level = 0; level < maxLevel; level++) {
//同层级多分支节点信息, <序号同序号listNode>
Map<String, List<CellObject>> numList = levelMap.get("" + level);
for (int i = 0; i < numList.keySet().size()+1; i++) {
//构建同层级的分支序号
String levelNo = this.getLevelNo(level, i);
//当前分支的最终节点同序号节点list
List<CellObject> nodes = numList.get(levelNo);
if (null == nodes){
continue;
}
for (CellObject node : nodes) {
//图形+连线
List<JSONObject> shapes = nodeMap.get(this.getCellObjectUUID(node));
for (JSONObject shape : shapes) {
if (shape.getString("name").equals("linker")){
//调整连线调整to的xpointer的size-1对象的x
JSONObject from = shape.getJSONObject("from");
Double fromx = from.getDouble("x");
from.put("x",(double)fromx + offset);
JSONObject to = shape.getJSONObject("to");
Double tox = to.getDouble("x");
to.put("x",(double)tox + offset);
JSONArray points = shape.getJSONArray("points");
for (int i1 = 0; i1 < points.size(); i1++) {
JSONObject point = points.getJSONObject(i1);
Double x = point.getDouble("x");
point.put("x",(double)x + offset);
}
}else{
//调整图形的x坐标比较x与leftLine 的min
JSONObject props = shape.getJSONObject("props");
Double x = props.getDouble("x");
props.put("x",(double) x + offset);
//计算最右边界
rightLine = this.getrightMaxLine(shape,rightLine);
}
}
}
}
}
return Math.max(rightLine,rightMaxLine);
}
private JSONObject changeShapePosition(Map<String, Map<String, List<CellObject>>> levelMap,Map<String,List<JSONObject>> nodeMap,double offsetX,double rightMaxLine,double leftMinLine){
JSONObject res = new JSONObject();
res.put("rightMaxLine",rightMaxLine);
res.put("leftMinLine",leftMinLine);
int maxLevel = levelMap.keySet().size();
int branchMax = 0;
int startLevel = 0;
//计算分支数量
for (int level = 0; level < maxLevel; level++) {
//同层级多分支节点信息, <序号同序号listNode>
Map<String, List<CellObject>> numList = levelMap.get("" + level);
if (numList.keySet().size()<=1){
//只调整分支节点
continue;
}
//找到一个出现分支的层级
branchMax = numList.keySet().size();
startLevel = level;
break;
}
//计算当前分支是奇数还是偶数项,branchMax 为0 说明没有分支不需要计算
if (branchMax == 0){
return res;
}
double medianBranch = (branchMax + 1) * 0.5;
if (branchMax % 2 == 1 ){
//奇数分支
JSONObject object = this.oddBranchChange(levelMap, nodeMap, maxLevel, startLevel, medianBranch, rightMaxLine, leftMinLine);
res.put("rightMaxLine",object.getDouble("rightMaxLine"));
res.put("leftMinLine",object.getDouble("leftMinLine"));
}else {
//偶数分支
JSONObject object = this.evenBranchChange(levelMap, nodeMap, maxLevel, startLevel, medianBranch, offsetX, rightMaxLine, leftMinLine);
res.put("rightMaxLine",object.getDouble("rightMaxLine"));
res.put("leftMinLine",object.getDouble("leftMinLine"));
}
return res;
}
//奇数分支处理
private JSONObject oddBranchChange(Map<String, Map<String, List<CellObject>>> levelMap,Map<String,List<JSONObject>> nodeMap,int maxLevel,int startLevel,double medianBranch,double rightMaxLine,double leftMinLine){
JSONObject res = new JSONObject();
res.put("rightMaxLine",rightMaxLine);
res.put("leftMinLine",leftMinLine);
for (int level = maxLevel-1; level>=startLevel; level--){
//同层级多分支节点信息
Map<String, List<CellObject>> numList = levelMap.get("" + level);
// if (numList.keySet().size()<=1 && !numList.keySet().contains(".")){
// //只调整分支节点
// continue;
// }
//奇数左半部分支调整,逆序
int branchMedian = (int) medianBranch;
for (int i = branchMedian-1; i >=1; i--) {
//构建同层级的分支序号
String leftLevelNo = this.getLevelNo(level, i);
String rightLevelNo = this.getLevelNo(level,i+1);
//同分支序号多节点list
List<CellObject> leftNodes = numList.get(leftLevelNo);
List<CellObject> rightNodes = numList.get(rightLevelNo);
if (null == leftNodes || leftNodes.isEmpty() ){
continue;
}
if (leftLevelNo.equals("4.1")){
Object o = new Object();
}
if (rightNodes == null || rightNodes.isEmpty()){
//递归向上找分支结点
rightNodes = this.findUpBranchNode(levelMap,rightLevelNo);
if (rightNodes.isEmpty()){
continue;
}
}
double leftShapeX = this.getNumListLeftShapeX(leftNodes, nodeMap);
double rightShapeX = this.getNumListRightShapeX(rightNodes, nodeMap);
if (leftShapeX + 15 > rightShapeX){
//需要调整,向左边移动
double offset = leftShapeX - (rightShapeX - ShapeConst.SHAPE_NODE_INTERVAL - ShapeConst.SHAPE_NODE_WIDTH );
double leftOffset = this.leftOffsetNode(leftNodes, levelMap, nodeMap, offset, leftMinLine);
res.put("leftMinLine",Math.min(leftOffset,leftMinLine));
}
}
//奇数右半部调整
for (int i = branchMedian; i < numList.keySet().size();i++){
//构建同层级的分支序号
String leftLevelNo = this.getLevelNo(level, i);
String rightLevelNo = this.getLevelNo(level,i+1);
//同分支序号多节点list
List<CellObject> leftNodes = numList.get(leftLevelNo);
List<CellObject> rightNodes = numList.get(rightLevelNo);
if (rightNodes == null || rightNodes.isEmpty()){
continue;
}
if (null == leftNodes || leftNodes.isEmpty()){
//递归找到左边的上级节点list
leftNodes = this.findUpBranchNode(levelMap,leftLevelNo);
if (leftNodes.isEmpty()){
continue;
}
}
double leftShapeX = this.getNumListLeftShapeX(leftNodes, nodeMap);
double rightShapeX = this.getNumListRightShapeX(rightNodes, nodeMap);
if (leftShapeX + 15 > rightShapeX){
//需要调整向右边移动
double offset = leftShapeX + ShapeConst.SHAPE_NODE_INTERVAL + ShapeConst.SHAPE_NODE_WIDTH;
double rightOffset = this.rightOffsetNode(rightNodes, levelMap, nodeMap, offset, rightMaxLine);
res.put("rightMaxLine",Math.max(rightMaxLine,rightOffset));
}
}
}
return res;
}
//偶数项调整
private JSONObject evenBranchChange(Map<String, Map<String, List<CellObject>>> levelMap,Map<String,List<JSONObject>> nodeMap,int maxLevel,int startLevel,double medianBranch,double offsetX,double rightMaxLine,double leftMinLine){
JSONObject res = new JSONObject();
res.put("rightMaxLine",rightMaxLine);
res.put("leftMinLine",leftMinLine);
for (int level = maxLevel-1; level>=startLevel; level--){
//同层级多分支节点信息
Map<String, List<CellObject>> numList = levelMap.get("" + level);
if (numList.keySet().size()<=1){
//只调整分支节点
continue;
}
//偶数左半部分支调整,逆序
int branchMedian = (int) Math.ceil(medianBranch);
for (int i = branchMedian-1; i >=1; i--){
//构建同层级的分支序号
String leftLevelNo = this.getLevelNo(level, i);
String rightLevelNo = "-1";
if (i+1 < medianBranch){
rightLevelNo = this.getLevelNo(level,i+1);
}
if (leftLevelNo.equals("4.1")){
Object o = new Object();
}
//同分支序号多节点list
List<CellObject> leftNodes = numList.get(leftLevelNo);
List<CellObject> rightNodes = numList.get(rightLevelNo);
if (null == leftNodes || leftNodes.isEmpty()){
continue;
}
double leftShapeX = this.getNumListLeftShapeX(leftNodes, nodeMap);
double rightShapeX = this.getNumListRightShapeX(rightNodes, nodeMap);
if (rightShapeX == 0){
rightShapeX = offsetX;
}
if (leftShapeX + 15 > rightShapeX){
//需要调整,向左边移动
double offset = leftShapeX - (rightShapeX - ShapeConst.SHAPE_NODE_INTERVAL - ShapeConst.SHAPE_NODE_WIDTH );
double leftOffset = this.leftOffsetNode(leftNodes, levelMap, nodeMap, offset, leftMinLine);
res.put("leftMinLine",Math.min(leftMinLine,leftOffset));
}
}
//偶数右半部调整
branchMedian = (int) Math.floor(medianBranch);
for (int i = branchMedian; i < numList.keySet().size();i++){
//构建同层级的分支序号
String leftLevelNo = "-1";
String rightLevelNo = this.getLevelNo(level,i+1);
if (i > medianBranch){
leftLevelNo = this.getLevelNo(level, i);
}
//同分支序号多节点list
List<CellObject> leftNodes = numList.get(leftLevelNo);
List<CellObject> rightNodes = numList.get(rightLevelNo);
if (rightNodes == null || rightNodes.isEmpty()){
continue;
}
double leftShapeX = this.getNumListLeftShapeX(leftNodes, nodeMap);
double rightShapeX = this.getNumListRightShapeX(rightNodes, nodeMap);
if (leftShapeX == 0){
leftShapeX = offsetX;
}
if (leftShapeX + 15 > rightShapeX){
//需要调整向右边移动
double offset = leftShapeX + ShapeConst.SHAPE_NODE_INTERVAL + ShapeConst.SHAPE_NODE_WIDTH;
double rightOffset = this.rightOffsetNode(rightNodes, levelMap, nodeMap, offset, rightMaxLine);
res.put("rightMaxLine",Math.max(rightMaxLine,rightOffset));
}
}
}
return res;
}
private double leftOffsetNode(List<CellObject> nodes,Map<String, Map<String, List<CellObject>>> levelMap,Map<String,List<JSONObject>> nodeMap,double offset,double leftMinLine){
double leftLine = leftMinLine;
//递归处理父级所有图形+连线的x的偏移量
double upLeftLine = this.changeUpLeftOffset(nodes.get(0), levelMap, nodeMap, offset, leftLine);
leftLine = Math.min(leftLine,upLeftLine);
//处理当前nodes的偏移x
double moveLeftLine = this.moveLeftNode(nodes, nodeMap, offset, leftLine,true,true);
leftLine = Math.min(leftLine,moveLeftLine);
//递归处理子级所有图形+连线x的偏移量
double subLeftLine = this.changeSubLeftOffset(nodes.get(0), levelMap, nodeMap, offset, leftLine);
leftLine = Math.min(leftLine,subLeftLine);
return Math.min(leftLine,leftMinLine);
}
private double changeUpLeftOffset(CellObject node,Map<String, Map<String, List<CellObject>>> levelMap,Map<String,List<JSONObject>> nodeMap,double offset,double leftMinLine){
double leftLine = leftMinLine;
String shapeNum = node.getShapeNum();
if (!shapeNum.contains(".")){
return leftLine;
}
//小数
String[] split = shapeNum.split("\\.");
String level = ""+ (Integer.parseInt(split[0])-1);
String branch = split[1];
Map<String, List<CellObject>> numList = levelMap.get(level);
List<CellObject> upList = numList.get(level + "." + branch);
if (upList == null || upList.isEmpty()){
return leftLine;
}
double upLeftLine = this.changeUpLeftOffset(upList.get(0), levelMap, nodeMap, offset, leftLine);
leftLine = Math.min(leftLine,upLeftLine);
//移动父级节点
double moveLeftLine = this.moveLeftNode(upList, nodeMap, offset, leftLine,true,false);
leftLine = Math.min(leftLine,moveLeftLine);
return Math.min(leftLine,leftMinLine);
}
private double moveLeftNode(List<CellObject> nodes,Map<String,List<JSONObject>> nodeMap,double offset,double leftMinLine,boolean isUp,boolean isSub){
double leftLine = leftMinLine;
if (nodes==null || nodes.isEmpty()){
return leftLine;
}
for (CellObject node : nodes) {
//图形+连线
List<JSONObject> shapes = nodeMap.get(this.getCellObjectUUID(node));
for (JSONObject shape : shapes) {
if (shape.getString("name").equals("linker")){
//调整连线调整to的xpointer的size-1对象的x
if (isUp){
JSONObject to = shape.getJSONObject("to");
Double x = to.getDouble("x");
to.put("x",(double)x-offset);
JSONArray points = shape.getJSONArray("points");
JSONObject point = points.getJSONObject(points.size() - 1);
Double x1 = point.getDouble("x");
point.put("x",(double)x1-offset);
}
if (isSub){
JSONObject from = shape.getJSONObject("from");
Double x = from.getDouble("x");
from.put("x",(double)x-offset);
JSONArray points = shape.getJSONArray("points");
JSONObject point = points.getJSONObject(0);
Double x1 = point.getDouble("x");
point.put("x",(double)x1-offset);
}
}else{
//调整图形的x坐标比较x与leftLine 的min
JSONObject props = shape.getJSONObject("props");
Double x = props.getDouble("x");
props.put("x",(double)x-offset);
//计算最左边界
leftLine = this.getLeftMinLine(shape,leftLine);
}
}
}
return leftLine;
}
private double changeSubLeftOffset(CellObject node,Map<String, Map<String, List<CellObject>>> levelMap,Map<String,List<JSONObject>> nodeMap,double offset,double leftMinLine){
double leftLine = leftMinLine;
String shapeNum = node.getShapeNum();
if (!shapeNum.contains(".")){
return leftLine;
}
//小数
String[] split = shapeNum.split("\\.");
String level = ""+ (Integer.parseInt(split[0])+1);
String branch = split[1];
Map<String, List<CellObject>> numList = levelMap.get(level);
List<CellObject> subList = numList.get(level + "." + branch);
if (subList == null || subList.isEmpty()){
subList = numList.get(level);
if (subList != null){
//直接特殊处理下一个整数节点连线调整
for (CellObject cellObject : subList) {
String upLevelno = Integer.parseInt(level) - 1 + "." + branch;
//图形+连线
List<JSONObject> shapes = nodeMap.get(this.getCellObjectUUID(cellObject));
for (JSONObject shape : shapes) {
//只调整连线的from点位
if (shape.getString("name").equals("linker")){
//只调整与上一次递归分支的连线调整to的xpointer的0对象的x
JSONObject from = shape.getJSONObject("from");
if (from.getString("shapeNum").equals(upLevelno)){
Double x = from.getDouble("x");
from.put("x",(double)x-offset);
JSONArray points = shape.getJSONArray("points");
JSONObject point = points.getJSONObject(0);
Double x1 = point.getDouble("x");
point.put("x",(double)x1-offset);
}
}
}
}
}
return leftLine;
}
double subLeftOffset = this.changeSubLeftOffset(subList.get(0), levelMap, nodeMap, offset, leftLine);
leftLine = Math.min(leftLine,subLeftOffset);
//移动子级节点
double moveLeftLine = this.moveLeftNode(subList, nodeMap, offset, leftLine,true,true);
leftLine = Math.min(leftLine,moveLeftLine);
return Math.min(leftLine,leftMinLine);
}
private double rightOffsetNode(List<CellObject> nodes,Map<String, Map<String, List<CellObject>>> levelMap,Map<String,List<JSONObject>> nodeMap,double offset,double rightMaxLine){
double rightLine = rightMaxLine;
//递归处理父级所有图形+连线的x的偏移量
double upRightOffset = this.changeUpRightOffset(nodes.get(0), levelMap, nodeMap, offset, rightLine);
rightLine = Math.max(rightLine,upRightOffset);
//处理当前nodes的偏移x
double moveRightOffset = this.moveRightNode(nodes, nodeMap, offset, rightLine, true, true);
rightLine = Math.max(rightLine,moveRightOffset);
//递归处理子级所有图形+连线x的偏移量
double subRightOffset = this.changeSubRightOffset(nodes.get(0), levelMap, nodeMap, offset, rightLine);
rightLine = Math.max(subRightOffset,rightLine);
return Math.max(rightLine,rightMaxLine);
}
private double changeUpRightOffset(CellObject node,Map<String, Map<String, List<CellObject>>> levelMap,Map<String,List<JSONObject>> nodeMap,double offset,double rightMaxLine){
double rightLine = rightMaxLine;
String shapeNum = node.getShapeNum();
if (!shapeNum.contains(".")){
return rightLine;
}
//小数,取上级节点数据
String[] split = shapeNum.split("\\.");
String level = ""+ (Integer.parseInt(split[0])-1);
String branch = split[1];
Map<String, List<CellObject>> numList = levelMap.get(level);
List<CellObject> upList = numList.get(level + "." + branch);
if (upList == null || upList.isEmpty()){
return rightLine;
}
double upRightOffset = this.changeUpRightOffset(upList.get(0), levelMap, nodeMap, offset, rightLine);
rightLine = Math.max(rightLine,upRightOffset);
//移动父节点x的偏移量
double moveRightOffset = this.moveRightNode(upList, nodeMap, offset, rightLine, true, false);
rightLine = Math.max(moveRightOffset,rightLine);
return Math.max(rightLine,rightMaxLine);
}
private double moveRightNode(List<CellObject> nodes,Map<String,List<JSONObject>> nodeMap,double offset,double rightMaxLine,boolean isUp,boolean isSub){
double rightLine = rightMaxLine;
if (nodes==null || nodes.isEmpty()){
return rightLine;
}
for (CellObject node : nodes) {
//图形+连线
List<JSONObject> shapes = nodeMap.get(this.getCellObjectUUID(node));
for (JSONObject shape : shapes) {
if (shape.getString("name").equals("linker")){
//调整连线调整to的xpointer的size-1对象的x
if (isUp){
JSONObject to = shape.getJSONObject("to");
Double x = to.getDouble("x");
to.put("x",(double)x+offset);
JSONArray points = shape.getJSONArray("points");
JSONObject point = points.getJSONObject(points.size() - 1);
Double x1 = point.getDouble("x");
point.put("x",(double)x1+offset);
}
if (isSub){
JSONObject from = shape.getJSONObject("from");
Double x = from.getDouble("x");
from.put("x",(double)x+offset);
JSONArray points = shape.getJSONArray("points");
JSONObject point = points.getJSONObject(0);
Double x1 = point.getDouble("x");
point.put("x",(double)x1+offset);
}
}else{
//调整图形的x坐标比较x与leftLine 的min
JSONObject props = shape.getJSONObject("props");
Double x = props.getDouble("x");
props.put("x",(double)x+offset);
//计算最左边界
rightLine = this.getLeftMinLine(shape,rightMaxLine);
}
}
}
return rightLine;
}
private double changeSubRightOffset(CellObject node,Map<String, Map<String, List<CellObject>>> levelMap,Map<String,List<JSONObject>> nodeMap,double offset,double rightMaxLine){
double rightLine = rightMaxLine;
String shapeNum = node.getShapeNum();
if (!shapeNum.contains(".")){
return rightLine;
}
//小数
String[] split = shapeNum.split("\\.");
String level = ""+ (Integer.parseInt(split[0])+1);
String branch = split[1];
Map<String, List<CellObject>> numList = levelMap.get(level);
List<CellObject> subList = numList.get(level + "." + branch);
if (subList == null || subList.isEmpty()){
subList = numList.get(level);
if (subList != null){
//直接特殊处理下一个整数节点连线调整
for (CellObject cellObject : subList) {
String upLevelno = Integer.parseInt(level) - 1 + "." + branch;
//图形+连线
List<JSONObject> shapes = nodeMap.get(this.getCellObjectUUID(cellObject));
for (JSONObject shape : shapes) {
//只调整连线的from点位
if (shape.getString("name").equals("linker")){
//只调整与上一次递归分支的连线调整to的xpointer的0对象的x
JSONObject from = shape.getJSONObject("from");
if (from.getString("shapeNum").equals(upLevelno)){
Double x = from.getDouble("x");
from.put("x",(double)x-offset);
JSONArray points = shape.getJSONArray("points");
JSONObject point = points.getJSONObject(0);
Double x1 = point.getDouble("x");
point.put("x",(double)x1-offset);
}
}
}
}
}
return rightLine;
}
double subRightOffset = this.changeSubRightOffset(subList.get(0), levelMap, nodeMap, offset, rightLine);
rightLine = Math.max(rightLine,subRightOffset);
//移动子级节点
double moveRightOffset = this.moveRightNode(subList, nodeMap, offset, rightLine, true, true);
rightLine = Math.max(rightLine,moveRightOffset);
return Math.max(rightLine,rightMaxLine);
}
private double getNumListLeftShapeX(List<CellObject> leftNodes,Map<String,List<JSONObject>> nodeMap){
JSONObject shape = this.getNumListLeftShape(leftNodes, nodeMap);
if (shape == null){
return 0;
}
JSONObject props = shape.getJSONObject("props");
return props.getDouble("x");
}
private double getNumListRightShapeX(List<CellObject> rightNodes,Map<String,List<JSONObject>> nodeMap){
JSONObject shape = this.getNumListRightShape(rightNodes, nodeMap);
if (shape == null){
return 0;
}
JSONObject props = shape.getJSONObject("props");
return props.getDouble("x");
}
private JSONObject getNumListLeftShape(List<CellObject> leftNodes,Map<String,List<JSONObject>> nodeMap){
if (null == leftNodes || leftNodes.isEmpty()){
return null;
}
CellObject cellObject = leftNodes.get(leftNodes.size()-1);
List<JSONObject> jsonObjects = nodeMap.get(this.getCellObjectUUID(cellObject));
return jsonObjects == null || jsonObjects.isEmpty() ? null:jsonObjects.get(0);
}
private JSONObject getNumListRightShape(List<CellObject> rightNodes,Map<String,List<JSONObject>> nodeMap){
if (null == rightNodes || rightNodes.isEmpty()){
return null;
}
CellObject cellObject = rightNodes.get(0);
List<JSONObject> jsonObjects = nodeMap.get(this.getCellObjectUUID(cellObject));
return jsonObjects == null || jsonObjects.isEmpty() ? null:jsonObjects.get(0);
}
private double getrightMaxLine(JSONObject shape,double rightMaxLine){
@ -312,7 +978,19 @@ public class ImportShapeExcel1 {
return Math.max(shapeRight,rightMaxLine);
}
private void handleExpandAttr(String repositoryId,JSONObject shape,JSONArray expandArr,JSONArray attributesJsonArray,List<DesignerShapeRelationModel> relationList){
private double getLeftMinLine(JSONObject shape,double leftMaxLine){
if (null == shape){
return 0;
}
JSONObject props = shape.getJSONObject("props");
Double x = props.getDouble("x");
return Math.min(x,leftMaxLine);
}
private void handleExpandAttr(String repositoryId,JSONObject shape,JSONArray expandArr,List<DesignerShapeRelationModel> relationList){
JSONArray attributesJsonArray = new JSONArray();
String shapeTitle = shape.getString("title");
String shapeId = shape.getString("id");
String shapeText = shape.getString("text");
@ -503,10 +1181,24 @@ public class ImportShapeExcel1 {
attributesJsonArray.add(object2);
}
}
if (attributesJsonArray.size() > 0) {
JSONArray dataAttributes = shape.getJSONArray("dataAttributes");
if (!dataAttributes.isEmpty() && dataAttributes.size() > 0) {
for (Object attribute : dataAttributes) {
JSONObject obj = (JSONObject) attribute;
if (obj.containsKey("attributesJsonArray")) {
obj.put("attributesJsonArray", attributesJsonArray);
break;
}
}
}
}
}
private void saveDefine(String repositoryId,Map<String,List<JSONObject>> nodeMap){
private void saveDefine(String repositoryId,Map<String,List<JSONObject>> nodeMap,double rightMaxLine,int maxLevel){
PALRepositoryModel palModel = PALRepositoryCache.getCache().get(repositoryId);
BaseModel defineModel = CoeDesignerAPIManager.getInstance().getDefinition(palModel.getId(), 0);
if (defineModel == null) {
@ -515,8 +1207,23 @@ public class ImportShapeExcel1 {
}
defineModel.setUpdateTime(new SimpleDateFormat(CoeDesignerConstant.DATE_TIME_STYLE_YYYY_MM_DD_HH_MM_SS).format(new Date()));
String define = defineModel.getDefinition();
// System.out.println("@@@:"+define);
JSONObject definition = JSON.parseObject(define);
//计算画布宽度
JSONObject page = definition.getJSONObject("page");
Double width = page.getDouble("width");
Double height = page.getDouble("height");
int bottomMaxLine = (ShapeConst.SHAPE_NODE_HEIGHT + ShapeConst.SHAPE_HEIGHT_INTERVAL) * maxLevel;
if (width < rightMaxLine){
page.put("width",rightMaxLine + 500);
}
if (height < bottomMaxLine + 150){
page.put("height",bottomMaxLine + 500);
}
JSONObject element = new JSONObject();
for (List<JSONObject> nodeValue : nodeMap.values()) {
for (JSONObject node : nodeValue) {
@ -524,6 +1231,7 @@ public class ImportShapeExcel1 {
}
}
definition.put("elements",element);
defineModel.setDefinition(definition.toString());
// 保存文件
CoeDesignerAPIManager.getInstance().storeDefinition(defineModel);// dao操作
@ -564,10 +1272,12 @@ public class ImportShapeExcel1 {
JSONObject from = this.getShapeBottomPoint(fromNode);
from.put("id", fromNode.getString("id"));
from.put("shapeNum",fromNode.getString("shapeNum"));
from.put("angle",4.71238898038469 );
JSONObject to = this.getShapTopPoint(toNode);
to.put("id", toNode.getString("id"));
to.put("shapeNum",toNode.getString("shapeNum"));
to.put("angle",1.5707963267948968 );
//设置linker的point
@ -752,6 +1462,37 @@ public class ImportShapeExcel1 {
return ""+level+"."+index;
}
private List<CellObject> findUpBranchNode(Map<String, Map<String, List<CellObject>>> levelMap,String levelNo){
List<CellObject> list = new ArrayList<>();
if (!levelNo.contains(".")){
return list;
}
//小数
String[] split = levelNo.split("\\.");
String level = ""+ (Integer.parseInt(split[0])-1);
String branch = split[1];
if (Integer.parseInt(level)<0){
return list;
}
Map<String, List<CellObject>> numList = levelMap.get(level);
List<CellObject> cellObjects = numList.get(level + "." + branch);
if (cellObjects==null){
return list;
}
list.addAll(cellObjects);
if (cellObjects.isEmpty()){
List<CellObject> upBranchNode = this.findUpBranchNode(levelMap, level + "." + branch);
list.addAll(upBranchNode);
}
return list;
}
/**
* 找到已经画好的上级节点 改为递归
* @param no

View File

@ -17,7 +17,7 @@ public class ShapeConst {
public final static String TABLE_REPOSITORY_TYPE = "模型类型";
public final static String TABLE_SHAPE_NAME = "形状名称";
public final static String TABLE_SHAPE_TYPE = "形状类型";
public final static String TABLE_SHAPE_BRANCH = "形状分支";
public final static String TABLE_SHAPE_BRANCH = "流程分支";
public final static String TABLE_SHAPE_NUM = "形状编号";
public final static String TABLE_EXTAND_EXAMPLE = "扩展<xxx>";
public final static String TABLE_EXTAND_EXAMPLE2 = "...";
@ -27,7 +27,7 @@ public class ShapeConst {
public final static String SHAPE_BASE_TITLE_ROW = "模型名称、模型类型、形状名称、形状类型";
public final static String [] SHAPE_TITLE_ROW_IMPORT = new String [] {TABLE_REPOSITORY_NAME, TABLE_REPOSITORY_TYPE, TABLE_SHAPE_NAME, TABLE_SHAPE_TYPE,TABLE_SHAPE_BRANCH,TABLE_SHAPE_NUM};
public final static String SHAPE_BASE_TITLE_ROW_IMPORT = "模型名称、模型类型、形状名称、形状类型、形状分支、形状编号";
public final static String SHAPE_BASE_TITLE_ROW_IMPORT = "模型名称、模型类型、形状名称、形状类型、流程分支、形状编号";
public final static Integer SHAPE_NODE_WIDTH = 200;