package com.example.server.progressTrack.service; import cn.hutool.core.convert.Convert; import cn.hutool.core.date.DateUtil; import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject;; import cn.hutool.json.XML; import com.example.client.service.BaseService; import com.example.client.utils.UUIDUtil; import com.example.server.progressTrack.Dto.*; import com.example.server.progressTrack.dao.ProjectNetworkDiagramDao; import com.example.server.utils.JsonUtils2; import com.example.server.utils.TimeUtils; import com.mxgraph.util.mxConstants; import com.mxgraph.view.mxGraph; import com.mxgraph.view.mxStylesheet; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.awt.*; import java.awt.font.FontRenderContext; import java.awt.geom.AffineTransform; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * DJ_WX_PROJECT * * @author zt generator * @since 1.0.0 2020-07-20 */ @Service public class NetWorkDiagramService extends BaseService { /* @Autowired ProjectListInspectionService projectListInspectionService; @Autowired NetworkDiagramPhaseService networkDiagramPhaseService; @Autowired NetworkDiagramJInspectionService networkDiagramJInspectionService;*/ @Autowired NetWorkDiagramService projectNetWorkDiagramService; /* @Autowired private SysMajorService sysMajorService; @Autowired private ISysDeptService iSysDeptService;*/ @Value("${zt.oss.local-path}") private String path; @Value("${data.line-nodes}") private int lineNodes; @Value("${data.area-width}") private int areaWidth; String diagramParams = "{\"diagramWidth\":\"5000\",\"lineNodeNum\":\"10\",\"majorFontsize\":\"14\",\"dateFontsize\":\"20\",\"beginDate\":\"\"}"; String edge = "{\"shape\":\"edge\",\"attrs\":{\"line\":{\"stroke\":\"#A2B1C3\"}},\"id\":\"9f8f91cd-228e-49eb-b22c-b268c5bee0cc\",\"zIndex\":0,\"source\":{\"cell\":\"1e2b6675-e9ab-46e0-8dca-89de2725d0f4\",\"port\":\"ffd5aa1c-1b1e-4506-ad33-315dbccf9ae8\"},\"target\":{\"cell\":\"f4a369dd-e8a9-487e-8567-aa78ba1ac018\",\"port\":\"496ca160-5342-4b61-a435-3743e4aacb45\"},\"connector\":{\"name\":\"smooth\"},\"labels\":[{\"attrs\":{\"text\":{\"text\":\"\"}},\"position\":{\"distance\":0.1}}]}"; String edge2 = "{\"shape\":\"edge\",\"attrs\":{\"line\":{\"stroke\":\"#A2B1C3\"}},\"id\":\"9f8f91cd-228e-49eb-b22c-b268c5bee0cc\",\"zIndex\":0,\"source\":{\"cell\":\"1e2b6675-e9ab-46e0-8dca-89de2725d0f4\",\"port\":\"ffd5aa1c-1b1e-4506-ad33-315dbccf9ae8\"},\"target\":{\"cell\":\"f4a369dd-e8a9-487e-8567-aa78ba1ac018\",\"port\":\"496ca160-5342-4b61-a435-3743e4aacb45\"},\"connector\":{\"name\":\"smooth\"},\"labels\":[{\"attrs\":{\"text\":{\"text\":\"\"}},\"position\":{\"distance\":0.1}}]}"; String rect = "{\"position\":{\"x\":-460,\"y\":-180},\"size\":{\"width\":86,\"height\":56},\"attrs\":{\"text\":{\"fontSize\":15,\"fill\":\"#C41414\",\"refX\":\"0\",\"refY\":-0.5,\"text\":\"过程\",\"refY2\":-10},\"body\":{\"fill\":\"#179C65\",\"stroke\":\"#5F95FF\",\"strokeWidth\":1},\"image\":{\"event\":\"node:delete\",\"xlinkHref\":\"trash.png\",\"width\":20,\"height\":20},\"title\":{\"text\":\"1970-01-01\",\"fontSize\":15,\"fill\":\"#C41414\",\"refX\":\"0\",\"refY\":0.5,\"refY2\":-10,\"textAnchor\":\"middle\",\"textVerticalAnchor\":\"middle\"}},\"visible\":true,\"shape\":\"text-block\",\"id\":\"f4a369dd-e8a9-487e-8567-aa78ba1ac018\",\"data\":{\"projectId\":\"1550367211193708545\",\"date\":\"2022-08-31\"},\"markup\":[{\"tagName\":\"rect\",\"selector\":\"body\"},{\"tagName\":\"text\",\"selector\":\"title\"},{\"tagName\":\"text\",\"selector\":\"text\"}],\"ports\":{\"groups\":{\"top\":{\"position\":\"top\",\"attrs\":{\"circle\":{\"r\":8,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"right\":{\"position\":\"right\",\"attrs\":{\"circle\":{\"r\":8,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"bottom\":{\"position\":\"bottom\",\"attrs\":{\"circle\":{\"r\":8,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"left\":{\"position\":\"left\",\"attrs\":{\"circle\":{\"r\":8,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}}},\"items\":[{\"group\":\"top\",\"id\":\"9e51974d-1f6b-412c-bab2-abb3306347c8\"},{\"group\":\"right\",\"id\":\"4fb643f3-33f5-443b-8e91-e10c1989bec1\"},{\"group\":\"bottom\",\"id\":\"0c0b39e1-89ae-4afb-921d-bef610322ade\"},{\"group\":\"left\",\"id\":\"496ca160-5342-4b61-a435-3743e4aacb45\"}]},\"zIndex\":1,\"tools\":{\"items\":[{\"name\":\"button-remove\",\"args\":{\"x\":15,\"y\":15}}],\"name\":null}}"; String rect2 = "{\"position\":{\"x\":-460,\"y\":-180},\"size\":{\"width\":86,\"height\":56},\"attrs\":{\"text\":{\"fontSize\":15,\"fill\":\"#C41414\",\"refX\":\"0\",\"refY\":-0.5,\"text\":\"过程\",\"refY2\":-10},\"body\":{\"fill\":\"#179C65\",\"stroke\":\"#5F95FF\",\"strokeWidth\":1},\"image\":{\"event\":\"node:delete\",\"xlinkHref\":\"trash.png\",\"width\":20,\"height\":20},\"title\":{\"text\":\"1970-01-01\",\"fontSize\":15,\"fill\":\"#C41414\",\"refX\":\"0\",\"refY\":0.5,\"refY2\":-10,\"textAnchor\":\"middle\",\"textVerticalAnchor\":\"middle\"}},\"visible\":true,\"shape\":\"text-block\",\"id\":\"f4a369dd-e8a9-487e-8567-aa78ba1ac018\",\"data\":{\"projectId\":\"1550367211193708545\",\"date\":\"2022-08-31\"},\"markup\":[{\"tagName\":\"rect\",\"selector\":\"body\"},{\"tagName\":\"text\",\"selector\":\"title\"},{\"tagName\":\"text\",\"selector\":\"text\"}],\"ports\":{\"groups\":{\"top\":{\"position\":\"top\",\"attrs\":{\"circle\":{\"r\":8,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"right\":{\"position\":\"right\",\"attrs\":{\"circle\":{\"r\":8,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"bottom\":{\"position\":\"bottom\",\"attrs\":{\"circle\":{\"r\":8,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"left\":{\"position\":\"left\",\"attrs\":{\"circle\":{\"r\":8,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}}},\"items\":[{\"group\":\"top\",\"id\":\"9e51974d-1f6b-412c-bab2-abb3306347c8\"},{\"group\":\"right\",\"id\":\"4fb643f3-33f5-443b-8e91-e10c1989bec1\"},{\"group\":\"bottom\",\"id\":\"0c0b39e1-89ae-4afb-921d-bef610322ade\"},{\"group\":\"left\",\"id\":\"496ca160-5342-4b61-a435-3743e4aacb45\"}]},\"zIndex\":1,\"tools\":{\"items\":[{\"name\":\"button-remove\",\"args\":{\"x\":15,\"y\":15}}],\"name\":null}}"; String circle = "{\"position\":{\"x\":-734,\"y\":-310},\"size\":{\"width\":86,\"height\":56},\"attrs\":{\"text\":{\"fill\":\"#A21919\",\"text\":\"阶段\"},\"body\":{\"fill\":\"#1C7C11\"},\"title\":{\"text\":\"2022-08-31\",\"fill\":\"#A21919\"}},\"visible\":true,\"shape\":\"custom-circle\",\"data\":{\"projectId\":\"1550367211193708545\",\"date\":\"2022-08-31\"},\"ports\":{\"groups\":{\"top\":{\"position\":\"top\",\"attrs\":{\"circle\":{\"r\":8,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"right\":{\"position\":\"right\",\"attrs\":{\"circle\":{\"r\":8,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"bottom\":{\"position\":\"bottom\",\"attrs\":{\"circle\":{\"r\":8,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"left\":{\"position\":\"left\",\"attrs\":{\"circle\":{\"r\":8,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}}},\"items\":[{\"group\":\"top\",\"id\":\"5b75c432-0399-4bf5-8699-68cfaa68f617\"},{\"group\":\"right\",\"id\":\"ffd5aa1c-1b1e-4506-ad33-315dbccf9ae8\"},{\"group\":\"bottom\",\"id\":\"6c3204f6-3bf7-40a0-939f-befd9469a71b\"},{\"group\":\"left\",\"id\":\"8a63602f-ee81-439b-9511-987a0f5b7e48\"}]},\"id\":\"1e2b6675-e9ab-46e0-8dca-89de2725d0f4\",\"zIndex\":2,\"tools\":{\"items\":[{\"name\":\"button-remove\",\"args\":{\"x\":15,\"y\":15}},{\"name\":\"button-remove\",\"args\":{\"x\":15,\"y\":15}}],\"name\":null}}"; String circle2 = "{\"position\":{\"x\":-734,\"y\":-310},\"size\":{\"width\":86,\"height\":56},\"attrs\":{\"text\":{\"fill\":\"#A21919\",\"text\":\"阶段\"},\"body\":{\"fill\":\"#1C7C11\"},\"title\":{\"text\":\"2022-08-31\",\"fill\":\"#A21919\"}},\"visible\":true,\"shape\":\"custom-circle\",\"data\":{\"projectId\":\"1550367211193708545\",\"date\":\"2022-08-31\"},\"ports\":{\"groups\":{\"top\":{\"position\":\"top\",\"attrs\":{\"circle\":{\"r\":8,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"right\":{\"position\":\"right\",\"attrs\":{\"circle\":{\"r\":8,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"bottom\":{\"position\":\"bottom\",\"attrs\":{\"circle\":{\"r\":8,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"left\":{\"position\":\"left\",\"attrs\":{\"circle\":{\"r\":8,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}}},\"items\":[{\"group\":\"top\",\"id\":\"5b75c432-0399-4bf5-8699-68cfaa68f617\"},{\"group\":\"right\",\"id\":\"ffd5aa1c-1b1e-4506-ad33-315dbccf9ae8\"},{\"group\":\"bottom\",\"id\":\"6c3204f6-3bf7-40a0-939f-befd9469a71b\"},{\"group\":\"left\",\"id\":\"8a63602f-ee81-439b-9511-987a0f5b7e48\"}]},\"id\":\"1e2b6675-e9ab-46e0-8dca-89de2725d0f4\",\"zIndex\":2,\"tools\":{\"items\":[{\"name\":\"button-remove\",\"args\":{\"x\":15,\"y\":15}},{\"name\":\"button-remove\",\"args\":{\"x\":15,\"y\":15}}],\"name\":null}}"; String textBox = "{\"position\":{\"x\":-734,\"y\":-310},\"size\":{\"width\":86,\"height\":56},\"attrs\":{\"text\":{\"fill\":\"#A21919\",\"text\":\"阶段\"},\"body\":{\"fill\":\"#1C7C11\"},\"title\":{\"text\":\"2022-08-31\",\"fill\":\"#A21919\"}},\"visible\":true,\"shape\":\"custom-circle\",\"data\":{\"projectId\":\"1550367211193708545\",\"date\":\"2022-08-31\"},\"ports\":{\"groups\":{\"top\":{\"position\":\"top\",\"attrs\":{\"circle\":{\"r\":8,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"right\":{\"position\":\"right\",\"attrs\":{\"circle\":{\"r\":8,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"bottom\":{\"position\":\"bottom\",\"attrs\":{\"circle\":{\"r\":8,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}},\"left\":{\"position\":\"left\",\"attrs\":{\"circle\":{\"r\":8,\"magnet\":true,\"stroke\":\"#5F95FF\",\"strokeWidth\":1,\"fill\":\"#fff\",\"style\":{\"visibility\":\"hidden\"}}}}},\"items\":[{\"group\":\"top\",\"id\":\"5b75c432-0399-4bf5-8699-68cfaa68f617\"},{\"group\":\"right\",\"id\":\"ffd5aa1c-1b1e-4506-ad33-315dbccf9ae8\"},{\"group\":\"bottom\",\"id\":\"6c3204f6-3bf7-40a0-939f-befd9469a71b\"},{\"group\":\"left\",\"id\":\"8a63602f-ee81-439b-9511-987a0f5b7e48\"}]},\"id\":\"1e2b6675-e9ab-46e0-8dca-89de2725d0f4\",\"zIndex\":2,\"tools\":{\"items\":[{\"name\":\"button-remove\",\"args\":{\"x\":15,\"y\":15}},{\"name\":\"button-remove\",\"args\":{\"x\":15,\"y\":15}}],\"name\":null}}"; //状态分为:专业、已启动/进行中(浅灰)、临期(黄色)、已逾期(红色)、已完成(浅绿色)、超期完成(深绿色) enum StatusEnum {zy, jxz, lq, yq, zcwc, cqwc} String[] fillColorArr = {"#e5e5e5", "#3498DB", "#F1C40F", "#E74C3C", "#2ECC71", "#006400"}; String[] fontColorArr = {"#e5e5e5", "#3498DB", "#F1C40F", "#E74C3C", "#2ECC71", "#006400"}; InitParamDto initParamDto = new InitParamDto(); ResultDataDto resultDataDto = new ResultDataDto(); NetworkDiagramPetsDto networkDiagramPetsDto = new NetworkDiagramPetsDto(); public String getStatusDiagram(String dialgramJsonStr, Integer yuqiDetermineDays, List nodeStatusDtos) { if (yuqiDetermineDays == null) yuqiDetermineDays = 7; Map statusMap = new HashMap<>(); Date today = new Date(); for (NetworkNodeStatusDto node : nodeStatusDtos) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date requiredCompletionDate = null; Date actualCompletionDate = null; try { if (StringUtils.isNotBlank(node.getRequiredCompletionTime())) { requiredCompletionDate = sdf.parse(node.getRequiredCompletionTime()); } if (StringUtils.isNotBlank(node.getActualCompletion())) { actualCompletionDate = sdf.parse(node.getActualCompletion()); } } catch (ParseException e) { e.printStackTrace(); } if (node.getCurrentStatus() == null || node.getCurrentStatus() == 0) { if (today.after(requiredCompletionDate)) { statusMap.put(node.getId(), StatusEnum.yq); } else if ((requiredCompletionDate.getTime() - today.getTime()) / (1000 * 60 * 60 * 24) < yuqiDetermineDays) { statusMap.put(node.getId(), StatusEnum.lq); } else { statusMap.put(node.getId(), StatusEnum.jxz); } } else if (node.getCurrentStatus() == 1) { // 已完成 if (node.getActualCompletion() != null && actualCompletionDate.after(requiredCompletionDate)) { statusMap.put(node.getId(), StatusEnum.cqwc); } else { statusMap.put(node.getId(), StatusEnum.zcwc); } } } int showStatus = 1; JSONObject dialgramJson = new JSONObject(dialgramJsonStr); JSONArray dialgramJsonArray = dialgramJson.getJSONArray("cells"); this.getPetsInfo(); StatusEnum maintainStatus = StatusEnum.jxz; Date lastActualFinishDate = null; if (dialgramJsonArray != null) { for (int i = 0; i < dialgramJsonArray.size(); i++ ) { JSONObject jsonObject = dialgramJsonArray.getJSONObject(i); String shape = jsonObject.get("shape").toString(); StatusEnum status = StatusEnum.jxz;//StatusEnum.wqd; if (shape.equals("custom-text")) { JsonUtils2.setJsonValueByPath(jsonObject, "attrs/body/fill".split("/"), fillColorArr[StatusEnum.zy.ordinal()]); JsonUtils2.setJsonValueByPath(jsonObject, "attrs/text/fill".split("/"), fontColorArr[StatusEnum.zy.ordinal()]); } else if (shape.equals("custom-circle1")) { Object dataIdStr = JsonUtils2.getJsonValueByPath(jsonObject, "data/dataId".split("/")); Long dataId = dataIdStr == null || "".equals(dataIdStr) ? 0L : Convert.toLong(JsonUtils2.getJsonValueByPath(jsonObject, "data/dataId".split("/")).toString()); if (dataId > 0) { /* InspectStatusDto check = StatusMap.get(dataId); if (check != null) { if (check.getRequireFinishDate() != null) JsonUtils2.setJsonValueByPath(jsonObject, "attrs/text/text".split("/"), DateUtils.format(check.getRequireFinishDate(), "yyyy-MM-dd")); else { // 时间搞没了 } }*/ } } else if (shape.equals("custom-circle")) { Object dataIdStr = JsonUtils2.getJsonValueByPath(jsonObject, "data/dataId".split("/")); Long dataId = dataIdStr == null || "".equals(dataIdStr) ? 0L : Convert.toLong(JsonUtils2.getJsonValueByPath(jsonObject, "data/dataId".split("/")).toString()); //String requireFinishDateStr = JsonUtils2.getJsonValueByPath(jsonObject, "data/finishDate".split("/")) == null ? "" : JsonUtils2.getJsonValueByPath(jsonObject, "data/finishDate".split("/")).toString(); if (dataId == 0L) { continue; } // Date today = new Date(); if (dataId > 0) { // NetworkDiagramPhase networkDiagramPhase = networkDiagramPhaseService.get(dataId); // if (networkDiagramPhase != null) { // Date requireFinishDate = networkDiagramPhase.getRequiredCompletion(); // if (requireFinishDate != null) { // Date actualFinishDate = networkDiagramPhase.getActualCompletion(); // // JsonUtils2.setJsonValueByPath(jsonObject, "attrs/title/text".split("/"), DateUtils.format(requireFinishDate, "yyyy-MM-dd")); // if (networkDiagramPhase.getActualCompletion() != null) { // actualFinishDate = networkDiagramPhase.getActualCompletion(); // } // int dbStatus = 0; // if (networkDiagramPhase.getCurrentStatus() != null) { // dbStatus = networkDiagramPhase.getCurrentStatus(); // } // if (dbStatus == 2) { // if (actualFinishDate != null && actualFinishDate.after(requireFinishDate)) // status = StatusEnum.cqwc; // else // status = StatusEnum.zcwc; // } else if (dbStatus > 0) { // if (today.after(requireFinishDate)) // status = StatusEnum.yq; // else if ((requireFinishDate.getTime() - today.getTime()) / (1000 * 60 * 60 * 24) < 7) // status = StatusEnum.lq; // else // status = StatusEnum.jxz; // } status = statusMap.get(dataId); JsonUtils2.setJsonValueByPath(jsonObject, "attrs/body/fill".split("/"), fillColorArr[status.ordinal()]); JsonUtils2.setJsonValueByPath(jsonObject, "attrs/text/fill".split("/"), fontColorArr[status.ordinal()]); JsonUtils2.setJsonValueByPath(jsonObject, "attrs/title/fill".split("/"), fontColorArr[status.ordinal()]); // } // } else { // //status = 节点没有定义需要完成时间 // } } else { //status = 节点已经不存在了 } } else if (shape.equals("custom-rect")) { Object dataIdStr = JsonUtils2.getJsonValueByPath(jsonObject, "data/dataId".split("/")); Long dataId = dataIdStr == null || "".equals(dataIdStr) ? 0L : Convert.toLong(JsonUtils2.getJsonValueByPath(jsonObject, "data/dataId".split("/")).toString()); if (dataId > 0) { /*InspectStatusDto check = StatusMap.get(dataId); if (check != null) { status = StatusEnum.jxz; Date requireFinishDate = check.getRequireFinishDate(); if (requireFinishDate != null) { Date actualFinishDate = check.getActualFinishDate(); Date today = new Date(); int checkStatus = check.getStatus(); if (checkStatus == 2) { if (actualFinishDate != null && actualFinishDate.after(requireFinishDate)) status = StatusEnum.cqwc; else status = StatusEnum.zcwc; } else { if (today.after(requireFinishDate)) status = StatusEnum.yq; else if ((requireFinishDate.getTime() - today.getTime()) / (1000 * 60 * 60 * 24) < 7) status = StatusEnum.lq; } if (status == StatusEnum.jxz || status == StatusEnum.lq || status == StatusEnum.yq) maintainStatus = StatusEnum.jxz; else if (maintainStatus != StatusEnum.jxz && (status == StatusEnum.cqwc || status == StatusEnum.zcwc)) { if (lastActualFinishDate == null) lastActualFinishDate = actualFinishDate; else if (actualFinishDate.after(lastActualFinishDate)) { lastActualFinishDate = actualFinishDate; } if (status == StatusEnum.cqwc) maintainStatus = StatusEnum.cqwc; else if (status != StatusEnum.cqwc && status == StatusEnum.zcwc) maintainStatus = StatusEnum.zcwc; } } else { // status = 节点没有定义需要完成时间 } } else { // status = 节点已经不存在了 }*/ status = statusMap.get(dataId); String textColor = fillColorArr[status.ordinal()]; if (status == StatusEnum.jxz) { textColor = fontColorArr[status.ordinal()]; } JsonUtils2.setJsonValueByPath(jsonObject, "attrs/text/fill".split("/"), textColor); JsonUtils2.setJsonValueByPath(jsonObject, "attrs/text/style/color".split("/"), textColor); JsonUtils2.setJsonValueByPath(jsonObject, "attrs/title/fill".split("/"), textColor); JsonUtils2.setJsonValueByPath(jsonObject, "attrs/title/style/color".split("/"), textColor); } } } } return dialgramJson.toString(); } public String createSimpleDiagram(List nodeList) { Map fontDefault = getFont("有限公司有限公司公司"); int breakFontWidth = fontDefault.get("width"); int minBoxWidth = Convert.toInt(breakFontWidth * 0.7); this.getPetsInfo(); Integer BoxHSpace = 30; Integer BoxVSpace = 10; initParamDto.setMajorTimeNodeWidth(networkDiagramPetsDto.getCirclePet2().getWidth()); //专业时间节点宽度 initParamDto.setMajorTimeNodeHeight(networkDiagramPetsDto.getCirclePet2().getHeight()); //专业基本高度 initParamDto.setMajorBaseHeightShowInspectNum(3); //专业基本高度能显示项目行数 initParamDto.setInspectRowHeight(networkDiagramPetsDto.getTextPet().getHeight()); // 显示一行项目高度 initParamDto.setMaxMajorNameWidth(80); initParamDto.setPhaseSpaceWidth(80); initParamDto.setItemSpaceWidth(10); /* initParamDto.setTotalMajorWidth(areaWidth); initParamDto.setMaxTimeNodeOfRow(lineNodes);*/ initParamDto.setMajorFirstFontWidth(0); int startY = 0; int startX = 0; JSONObject jsonObject_root = new JSONObject(); JSONArray jsonArray = new JSONArray(); for (DiagramNodeDto phaseDto : nodeList) { String text = phaseDto.getProcessName(); Map font = getFont(text); Integer width = font.get("width") < minBoxWidth ? minBoxWidth : font.get("width"); phaseDto.setFontWith(width); } startX = networkDiagramPetsDto.getCirclePet().getWidth() + initParamDto.getPhaseSpaceWidth(); for (DiagramNodeDto phaseDto : nodeList) { phaseDto.setX(startX); phaseDto.setY(0); //phaseDto.setWidth(phaseDto.getFontWith()); //phaseDto.setHeight(fontRowHeight * 3); //phaseDto.setBoxId(UUIDUtil.generateId()); phaseDto.setBoxId(phaseDto.getId()); phaseDto.setTopId(UUIDUtil.generateId()); phaseDto.setRightId(UUIDUtil.generateId()); phaseDto.setBottomId(UUIDUtil.generateId()); phaseDto.setLeftId(UUIDUtil.generateId()); startX = startX + networkDiagramPetsDto.getCirclePet().getWidth() + initParamDto.getPhaseSpaceWidth(); } if (nodeList.size() > 0) { String startId = "10000"; String startRightPortId = UUIDUtil.generateId().toString(); String endId = "20000"; String endLeftPortId = UUIDUtil.generateId().toString(); JSONObject jsonObject_start = new JSONObject(networkDiagramPetsDto.getCirclePet().getJson()); JsonUtils2.setJsonValueByPath(jsonObject_start, "id".split("/"), startId); JsonUtils2.setJsonValueByPath(jsonObject_start, "attrs/text/text".split("/"), "开始"); JsonUtils2.setJsonValueByPath(jsonObject_start, "attrs/title/text".split("/"), ""); JsonUtils2.setJsonValueByPath(jsonObject_start, "position/x".split("/"), 0); JsonUtils2.setJsonValueByPath(jsonObject_start, "position/y".split("/"), 0); JsonUtils2.setArrJsonValueByPath(jsonObject_start, "ports/items/".split("/"), "group", "top", "id", UUIDUtil.generateId().toString()); JsonUtils2.setArrJsonValueByPath(jsonObject_start, "ports/items/".split("/"), "group", "right", "id", startRightPortId); JsonUtils2.setArrJsonValueByPath(jsonObject_start, "ports/items/".split("/"), "group", "bottom", "id", UUIDUtil.generateId().toString()); JsonUtils2.setArrJsonValueByPath(jsonObject_start, "ports/items/".split("/"), "group", "left", "id", UUIDUtil.generateId().toString()); jsonArray.add(jsonObject_start); JSONObject jsonObject_end = new JSONObject(networkDiagramPetsDto.getCirclePet().getJson()); JsonUtils2.setJsonValueByPath(jsonObject_end, "id".split("/"), endId); JsonUtils2.setJsonValueByPath(jsonObject_end, "attrs/text/text".split("/"), "结束"); JsonUtils2.setJsonValueByPath(jsonObject_end, "attrs/title/text".split("/"), ""); JsonUtils2.setJsonValueByPath(jsonObject_end, "position/x".split("/"), startX); JsonUtils2.setJsonValueByPath(jsonObject_end, "position/y".split("/"), 0); JsonUtils2.setArrJsonValueByPath(jsonObject_end, "ports/items/".split("/"), "group", "top", "id", UUIDUtil.generateId().toString()); JsonUtils2.setArrJsonValueByPath(jsonObject_end, "ports/items/".split("/"), "group", "right", "id", UUIDUtil.generateId().toString()); JsonUtils2.setArrJsonValueByPath(jsonObject_end, "ports/items/".split("/"), "group", "bottom", "id", UUIDUtil.generateId().toString()); JsonUtils2.setArrJsonValueByPath(jsonObject_end, "ports/items/".split("/"), "group", "left", "id", endLeftPortId); jsonArray.add(jsonObject_end); DiagramNodeDto lastPhaseDto = null; for (DiagramNodeDto phaseDto : nodeList) { if (lastPhaseDto == null) { JSONObject jsonObject_edge = new JSONObject(networkDiagramPetsDto.getEdgePet().getJson()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "id".split("/"), UUIDUtil.generateId().toString()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "source/cell".split("/"), startId); JsonUtils2.setJsonValueByPath(jsonObject_edge, "source/port".split("/"), startRightPortId); JsonUtils2.setJsonValueByPath(jsonObject_edge, "target/cell".split("/"), phaseDto.getBoxId().toString()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "target/port".split("/"), phaseDto.getLeftId().toString()); JSONObject temp = (jsonObject_edge.getJSONArray("labels")).getJSONObject(0); JsonUtils2.setJsonValueByPath(temp, "attrs/text/text".split("/"), ""); jsonArray.add(jsonObject_edge); } else { JSONObject jsonObject_edge = new JSONObject(networkDiagramPetsDto.getEdgePet().getJson()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "id".split("/"), UUIDUtil.generateId().toString()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "source/cell".split("/"), lastPhaseDto.getBoxId().toString()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "source/port".split("/"), lastPhaseDto.getRightId().toString()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "target/cell".split("/"), phaseDto.getBoxId().toString()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "target/port".split("/"), phaseDto.getLeftId().toString()); JSONObject temp = (jsonObject_edge.getJSONArray("labels")).getJSONObject(0); JsonUtils2.setJsonValueByPath(temp, "attrs/text/text".split("/"), ""); jsonArray.add(jsonObject_edge); } JSONObject jsonObject_circle = new JSONObject(networkDiagramPetsDto.getCirclePet().getJson()); JsonUtils2.setJsonValueByPath(jsonObject_circle, "id".split("/"), phaseDto.getBoxId().toString()); JsonUtils2.setJsonValueByPath(jsonObject_circle, "data/dataId".split("/"), phaseDto.getId().toString()); //JsonUtils2.setJsonValueByPath(jsonObject_circle, "data/nodeType".split("/"), phaseDto.getDisplayLocation()); //JsonUtils2.setJsonValueByPath(jsonObject_circle, "data/finishDate".split("/"), DateUtils.format(phaseDto.getRequiredCompletion(), "yyyy-MM-dd")); JsonUtils2.setJsonValueByPath(jsonObject_circle, "position/x".split("/"), phaseDto.getX()); JsonUtils2.setJsonValueByPath(jsonObject_circle, "position/y".split("/"), phaseDto.getY()); //JsonUtils2.setJsonValueByPath(jsonObject_circle, "size/width".split("/"), phaseDto.getWidth()); //JsonUtils2.setJsonValueByPath(jsonObject_circle, "size/height".split("/"), phaseDto.getHeight()); JsonUtils2.setJsonValueByPath(jsonObject_circle, "attrs/text/text".split("/"), phaseDto.getProcessName()); JsonUtils2.setJsonValueByPath(jsonObject_circle, "attrs/title/text".split("/"), phaseDto.getRequiredCompletion()); JsonUtils2.setArrJsonValueByPath(jsonObject_circle, "ports/items/".split("/"), "group", "top", "id", phaseDto.getTopId().toString()); JsonUtils2.setArrJsonValueByPath(jsonObject_circle, "ports/items/".split("/"), "group", "right", "id", phaseDto.getRightId().toString()); JsonUtils2.setArrJsonValueByPath(jsonObject_circle, "ports/items/".split("/"), "group", "bottom", "id", phaseDto.getBottomId().toString()); JsonUtils2.setArrJsonValueByPath(jsonObject_circle, "ports/items/".split("/"), "group", "left", "id", phaseDto.getLeftId().toString()); jsonArray.add(jsonObject_circle); lastPhaseDto = phaseDto; } if (lastPhaseDto != null) { JSONObject jsonObject_edge = new JSONObject(networkDiagramPetsDto.getEdgePet().getJson()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "id".split("/"), UUIDUtil.generateId().toString()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "source/cell".split("/"), lastPhaseDto.getBoxId().toString()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "source/port".split("/"), lastPhaseDto.getRightId().toString()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "target/cell".split("/"), endId); JsonUtils2.setJsonValueByPath(jsonObject_edge, "target/port".split("/"), endLeftPortId); JSONObject temp = (jsonObject_edge.getJSONArray("labels")).getJSONObject(0); JsonUtils2.setJsonValueByPath(temp, "attrs/text/text".split("/"), ""); jsonArray.add(jsonObject_edge); } } jsonObject_root.put("cells", jsonArray); return jsonObject_root.toString(); } public String createDiagram(List listMajor, List allNodeList, String startDate, Integer diagramWidth, Integer lineNodeNum) { Map fontDefault = getFont("有限公司有限公司公司"); int breakFontWidth = fontDefault.get("width"); int minBoxWidth = Convert.toInt(breakFontWidth * 0.7); this.getPetsInfo(); Integer BoxHSpace = 30; Integer BoxVSpace = 10; initParamDto.setMajorTimeNodeWidth(networkDiagramPetsDto.getCirclePet2().getWidth()); //专业时间节点宽度 initParamDto.setMajorTimeNodeHeight(networkDiagramPetsDto.getCirclePet2().getHeight()); //专业基本高度 initParamDto.setMajorBaseHeightShowInspectNum(3); //专业基本高度能显示项目行数 initParamDto.setInspectRowHeight(networkDiagramPetsDto.getTextPet().getHeight()); // 显示一行项目高度 initParamDto.setMaxMajorNameWidth(80); initParamDto.setPhaseSpaceWidth(80); initParamDto.setItemSpaceWidth(10); initParamDto.setTotalMajorWidth(areaWidth); initParamDto.setMaxTimeNodeOfRow(lineNodes); initParamDto.setMajorFirstFontWidth(0); int startY = 0; int startX = 0; JSONObject jsonObject_root = new JSONObject(); JSONArray jsonArray = new JSONArray(); JSONObject digramParamsJson = new JSONObject(diagramParams); /* Integer diagramWidth = digramParamsJson.getInt("diagramWidth"); Integer lineNodeNum = digramParamsJson.getInt("lineNodeNum");*/ Integer majorFontsize = digramParamsJson.getInt("majorFontsize"); Integer dateFontsize = digramParamsJson.getInt("dateFontsize"); initParamDto.setTotalMajorWidth(diagramWidth); initParamDto.setMaxTimeNodeOfRow(lineNodeNum); listMajor = this.DiagramMajorData(listMajor, allNodeList, startDate); //List listMajor = baseDao.getTimeScope(networkDiagram); int maxMajorWidth = 0; int allHeight = 0; for (DiagramMajorDto majorDto : listMajor) { if (majorDto.getWidth() > maxMajorWidth) maxMajorWidth = majorDto.getWidth(); allHeight = allHeight + majorDto.getHeight(); } allHeight = allHeight + (listMajor.size() - 1) * BoxVSpace; int leftPhasesSize = resultDataDto.getLeftPhases().size() > 0 ? resultDataDto.getLeftPhases().size() : 1; int startWidth = (networkDiagramPetsDto.getCirclePet().getWidth() + initParamDto.getPhaseSpaceWidth()) * leftPhasesSize - initParamDto.getPhaseSpaceWidth(); int majorStartX = startWidth + initParamDto.getMaxMajorNameWidth() + 40; int maxX = 0; for (DiagramMajorDto majorDto : listMajor) { startX = majorStartX; int branchNo = 0; for (DiagramMajorBranchDto branchDto : majorDto.getBranchs()) { int branchY = 0; if (branchNo == 0) { branchY = majorDto.getBranchs().size() > 1 ? majorDto.getBranchs().get(1).getHeight() : 0; } else if (branchNo == 2) { branchY = majorDto.getBranchs().get(0).getHeight() + majorDto.getBranchs().get(1).getHeight(); } branchNo++; branchY = startY + branchY; for (DiagramMajorBranchTimeDto diagramMajorTimeDto : branchDto.getTimeNodes()) { int inspectionY = 30; //branchDto int x; int x2; int y; for (DiagramNode2Dto inspectionDto : diagramMajorTimeDto.getInspections()) { x = startX + diagramMajorTimeDto.getX() - diagramMajorTimeDto.getTimeNodeSpaceWidth() + (diagramMajorTimeDto.getTimeNodeSpaceWidth() - diagramMajorTimeDto.getInspectionWidth()) / 2; inspectionDto.setX(x); //inspectionDto.setX(startX + diagramMajorTimeDto.getX() - diagramMajorTimeDto.getTimeNodeSpaceWidth() // + (diagramMajorTimeDto.getTimeNodeSpaceWidth() - diagramMajorTimeDto.getInspectionWidth()) / 2); //inspectionDto.setY(branchY + diagramMajorTimeDto.getInsepectY() + inspectionY); y = branchY + (branchDto.getHeight() - diagramMajorTimeDto.getInspectionHeight()) / 2 + inspectionY; inspectionDto.setY(y); //inspectionDto.setY(branchY + (branchDto.getHeight() - diagramMajorTimeDto.getInspectionHeight()) / 2 + inspectionY); if (inspectionDto.getId().equals(1888761224410202114L)) { System.out.println(111); } inspectionDto.setBoxId(inspectionDto.getId()); inspectionDto.setTopId(UUIDUtil.generateId()); inspectionDto.setRightId(UUIDUtil.generateId()); inspectionDto.setBottomId(UUIDUtil.generateId()); inspectionDto.setLeftId(UUIDUtil.generateId()); inspectionY = inspectionY + inspectionDto.getHeight(); //startX = startX + inspectionDto.getWidth() ; } x2 = startX + diagramMajorTimeDto.getX(); diagramMajorTimeDto.setX(startX + diagramMajorTimeDto.getX()); y = branchY + (branchDto.getHeight() - networkDiagramPetsDto.getEdgePet2().getHeight()) / 2; diagramMajorTimeDto.setY(y); // diagramMajorTimeDto.setY(branchY + (branchDto.getHeight() - networkDiagramPetsDto.getEdgePet2().getHeight()) / 2); diagramMajorTimeDto.setBoxId(UUIDUtil.generateId()); diagramMajorTimeDto.setTopId(UUIDUtil.generateId()); diagramMajorTimeDto.setRightId(UUIDUtil.generateId()); diagramMajorTimeDto.setBottomId(UUIDUtil.generateId()); diagramMajorTimeDto.setLeftId(UUIDUtil.generateId()); if (x2 > maxX) maxX = x2; } } startY = startY + majorDto.getHeight() + BoxVSpace; } if (listMajor.size() > 0) { Map fontDate = getFont("2023-02-02", "仿宋", Font.PLAIN, dateFontsize); int dateFontWidth = fontDate.get("width") + 8; int dateFontHeight = fontDate.get("height") + 2; int timeY = -12; int timeY2 = timeY - dateFontHeight - 1; int lastViewX = majorStartX; int leftDiff = dateFontWidth / 2 - 18; String lastTimeId = UUIDUtil.generateId().toString(); Date curDate = resultDataDto.getMinDate(); JSONObject jsonObject_majorNode1 = new JSONObject(networkDiagramPetsDto.getImageRight().getJson()); JsonUtils2.setJsonValueByPath(jsonObject_majorNode1, "id".split("/"), lastTimeId); JsonUtils2.setJsonValueByPath(jsonObject_majorNode1, "position/x".split("/"), majorStartX); JsonUtils2.setJsonValueByPath(jsonObject_majorNode1, "position/y".split("/"), timeY); jsonArray.add(jsonObject_majorNode1); DateFormat sfd = new SimpleDateFormat("yyyy-MM-dd"); JSONObject jsonObject_text1 = new JSONObject(networkDiagramPetsDto.getTextPet().getJson()); JsonUtils2.setJsonValueByPath(jsonObject_text1, "id".split("/"), UUIDUtil.generateId().toString()); JsonUtils2.setJsonValueByPath(jsonObject_text1, "attrs/label/textWrap/text".split("/"), sfd.format(curDate)); JsonUtils2.setJsonValueByPath(jsonObject_text1, "attrs/label/textWrap/breakWord".split("/"), false); JsonUtils2.setJsonValueByPath(jsonObject_text1, "attrs/label/textWrap/width".split("/"), 0); JsonUtils2.setJsonValueByPath(jsonObject_text1, "attrs/line/strokeWidth".split("/"), 4); JsonUtils2.setJsonValueByPath(jsonObject_text1, "attrs/text/fontSize".split("/"), dateFontsize); JsonUtils2.setJsonValueByPath(jsonObject_text1, "attrs/title/fontSize".split("/"), dateFontsize); JsonUtils2.setJsonValueByPath(jsonObject_text1, "position/x".split("/"), majorStartX - leftDiff); JsonUtils2.setJsonValueByPath(jsonObject_text1, "position/y".split("/"), timeY2); JsonUtils2.setJsonValueByPath(jsonObject_text1, "size/width".split("/"), dateFontWidth); JsonUtils2.setJsonValueByPath(jsonObject_text1, "size/height".split("/"), dateFontHeight); jsonArray.add(jsonObject_text1); int i = 1; int days = (int) DateUtil.betweenDay(resultDataDto.getMinDate(), resultDataDto.getMaxDate(), true); String a = ""; while (curDate.before(resultDataDto.getMaxDate())) { if (days > 90) { a = "" + i + "月"; curDate = new Date(curDate.getTime() + 30 * 86400000L); } else { a = "" + i + "周"; curDate = new Date(curDate.getTime() + 7 * 86400000L); } i++; String timeId = UUIDUtil.generateId().toString(); int timeX = majorStartX + initParamDto.getMajorFirstFontWidth() + (initParamDto.getTotalMajorWidth() * (int) DateUtil.betweenDay(resultDataDto.getMinDate(), curDate, true)) / (int) DateUtil.betweenDay(resultDataDto.getMinDate(), resultDataDto.getMaxDate(), true); if (curDate.after(resultDataDto.getMaxDate())) { timeId = UUIDUtil.generateId().toString(); //curDate = resultDataDto.getMaxDate(); //timeX = majorStartX + initParamDto.getMajorFirstFontWidth() + initParamDto.getTotalMajorWidth(); jsonObject_majorNode1 = new JSONObject(networkDiagramPetsDto.getImageLeft().getJson()); JsonUtils2.setJsonValueByPath(jsonObject_majorNode1, "id".split("/"), timeId); JsonUtils2.setJsonValueByPath(jsonObject_majorNode1, "position/x".split("/"), timeX); JsonUtils2.setJsonValueByPath(jsonObject_majorNode1, "position/y".split("/"), timeY); JsonUtils2.setJsonValueByPath(jsonObject_majorNode1, "size/width".split("/"), 5); JsonUtils2.setJsonValueByPath(jsonObject_majorNode1, "size/height".split("/"), 5); jsonArray.add(jsonObject_majorNode1); jsonObject_text1 = new JSONObject(networkDiagramPetsDto.getTextPet().getJson()); JsonUtils2.setJsonValueByPath(jsonObject_text1, "id".split("/"), UUIDUtil.generateId().toString()); if (timeX > lastViewX + dateFontWidth) { JsonUtils2.setJsonValueByPath(jsonObject_text1, "attrs/label/textWrap/text".split("/"), sfd.format(curDate)); lastViewX = timeX; } else JsonUtils2.setJsonValueByPath(jsonObject_text1, "attrs/label/textWrap/text".split("/"), ""); JsonUtils2.setJsonValueByPath(jsonObject_text1, "attrs/line/strokeWidth".split("/"), 4); JsonUtils2.setJsonValueByPath(jsonObject_text1, "attrs/label/textWrap/breakWord".split("/"), false); JsonUtils2.setJsonValueByPath(jsonObject_text1, "attrs/label/textWrap/width".split("/"), 0); JsonUtils2.setJsonValueByPath(jsonObject_text1, "attrs/text/fill".split("/"), "#060606"); JsonUtils2.setJsonValueByPath(jsonObject_text1, "attrs/title/fill".split("/"), "#060606"); JsonUtils2.setJsonValueByPath(jsonObject_text1, "attrs/text/fontSize".split("/"), dateFontsize); JsonUtils2.setJsonValueByPath(jsonObject_text1, "attrs/title/fontSize".split("/"), dateFontsize); //JsonUtils2.setJsonValueByPath(jsonObject_text, "attrs/label/textWrap/width".split("/"), inspectionDto.getWidth()); JsonUtils2.setJsonValueByPath(jsonObject_text1, "position/x".split("/"), timeX - leftDiff); JsonUtils2.setJsonValueByPath(jsonObject_text1, "position/y".split("/"), timeY2); JsonUtils2.setJsonValueByPath(jsonObject_text1, "size/width".split("/"), dateFontWidth); JsonUtils2.setJsonValueByPath(jsonObject_text1, "size/height".split("/"), dateFontHeight); jsonArray.add(jsonObject_text1); JSONObject jsonObject_edge_image = new JSONObject(networkDiagramPetsDto.getEdgePet3().getJson()); JsonUtils2.setJsonValueByPath(jsonObject_edge_image, "id".split("/"), UUIDUtil.generateId().toString()); JsonUtils2.setJsonValueByPath(jsonObject_edge_image, "source/cell".split("/"), lastTimeId); JsonUtils2.setJsonValueByPath(jsonObject_edge_image, "source/port".split("/"), ""); JsonUtils2.setJsonValueByPath(jsonObject_edge_image, "target/cell".split("/"), timeId); JsonUtils2.setJsonValueByPath(jsonObject_edge_image, "target/port".split("/"), ""); JsonUtils2.setJsonValueByPath(jsonObject_edge_image, "attrs/line/strokeWidth".split("/"), 4); JsonUtils2.setJsonValueByPath(jsonObject_edge_image, "attrs/line/stroke".split("/"), "#060606"); JSONObject temp_image = (jsonObject_edge_image.getJSONArray("labels")).getJSONObject(0); JsonUtils2.setJsonValueByPath(temp_image, "attrs/text/text".split("/"), a); JsonUtils2.setJsonValueByPath(temp_image, "position/distance".split("/"), 0.6); jsonArray.add(jsonObject_edge_image); break; } jsonObject_majorNode1 = new JSONObject(networkDiagramPetsDto.getImageCenter().getJson()); JsonUtils2.setJsonValueByPath(jsonObject_majorNode1, "id".split("/"), timeId); JsonUtils2.setJsonValueByPath(jsonObject_majorNode1, "position/x".split("/"), timeX); JsonUtils2.setJsonValueByPath(jsonObject_majorNode1, "position/y".split("/"), timeY); jsonArray.add(jsonObject_majorNode1); jsonObject_text1 = new JSONObject(networkDiagramPetsDto.getTextPet().getJson()); JsonUtils2.setJsonValueByPath(jsonObject_text1, "id".split("/"), UUIDUtil.generateId().toString()); if (timeX > lastViewX + dateFontWidth) { JsonUtils2.setJsonValueByPath(jsonObject_text1, "attrs/label/textWrap/text".split("/"), sfd.format(curDate)); lastViewX = timeX; } else JsonUtils2.setJsonValueByPath(jsonObject_text1, "attrs/label/textWrap/text".split("/"), ""); JsonUtils2.setJsonValueByPath(jsonObject_text1, "attrs/label/textWrap/breakWord".split("/"), false); JsonUtils2.setJsonValueByPath(jsonObject_text1, "attrs/label/textWrap/width".split("/"), 0); JsonUtils2.setJsonValueByPath(jsonObject_text1, "position/x".split("/"), timeX - leftDiff); JsonUtils2.setJsonValueByPath(jsonObject_text1, "position/y".split("/"), timeY2); JsonUtils2.setJsonValueByPath(jsonObject_text1, "attrs/text/fontSize".split("/"), dateFontsize); JsonUtils2.setJsonValueByPath(jsonObject_text1, "attrs/title/fontSize".split("/"), dateFontsize); JsonUtils2.setJsonValueByPath(jsonObject_text1, "attrs/text/fill".split("/"), "#060606"); JsonUtils2.setJsonValueByPath(jsonObject_text1, "attrs/title/fill".split("/"), "#060606"); //JsonUtils2.setJsonValueByPath(jsonObject_text, "attrs/label/textWrap/width".split("/"), inspectionDto.getWidth()); JsonUtils2.setJsonValueByPath(jsonObject_text1, "size/width".split("/"), dateFontWidth); JsonUtils2.setJsonValueByPath(jsonObject_text1, "size/height".split("/"), dateFontHeight); jsonArray.add(jsonObject_text1); JSONObject jsonObject_edge = new JSONObject(networkDiagramPetsDto.getEdgePet3().getJson()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "id".split("/"), UUIDUtil.generateId().toString()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "source/cell".split("/"), lastTimeId); JsonUtils2.setJsonValueByPath(jsonObject_edge, "source/port".split("/"), ""); JsonUtils2.setJsonValueByPath(jsonObject_edge, "target/cell".split("/"), timeId); JsonUtils2.setJsonValueByPath(jsonObject_edge, "target/port".split("/"), ""); JsonUtils2.setJsonValueByPath(jsonObject_edge, "attrs/line/strokeWidth".split("/"), 4); JsonUtils2.setJsonValueByPath(jsonObject_edge, "attrs/line/stroke".split("/"), "#060606"); JSONObject temp = (jsonObject_edge.getJSONArray("labels")).getJSONObject(0); JsonUtils2.setJsonValueByPath(temp, "attrs/text/text".split("/"), a); JsonUtils2.setJsonValueByPath(temp, "position/distance".split("/"), 0.5); jsonArray.add(jsonObject_edge); lastTimeId = timeId; } int middleY = allHeight / 2; String startId = "10000"; String startRightPortId = UUIDUtil.generateId().toString(); String endId = "20000"; String endLeftPortId = UUIDUtil.generateId().toString(); int majorEndX = maxX + networkDiagramPetsDto.getCirclePet2().getWidth(); int endX = majorEndX + initParamDto.getMaxMajorNameWidth(); JSONObject jsonObject_start = new JSONObject(networkDiagramPetsDto.getCirclePet().getJson()); JsonUtils2.setJsonValueByPath(jsonObject_start, "id".split("/"), startId); JsonUtils2.setJsonValueByPath(jsonObject_start, "attrs/text/text".split("/"), "开始"); JsonUtils2.setJsonValueByPath(jsonObject_start, "attrs/title/text".split("/"), ""); JsonUtils2.setJsonValueByPath(jsonObject_start, "position/x".split("/"), 0); JsonUtils2.setJsonValueByPath(jsonObject_start, "position/y".split("/"), middleY); JsonUtils2.setArrJsonValueByPath(jsonObject_start, "ports/items/".split("/"), "group", "top", "id", UUIDUtil.generateId().toString()); JsonUtils2.setArrJsonValueByPath(jsonObject_start, "ports/items/".split("/"), "group", "right", "id", startRightPortId); JsonUtils2.setArrJsonValueByPath(jsonObject_start, "ports/items/".split("/"), "group", "bottom", "id", UUIDUtil.generateId().toString()); JsonUtils2.setArrJsonValueByPath(jsonObject_start, "ports/items/".split("/"), "group", "left", "id", UUIDUtil.generateId().toString()); jsonArray.add(jsonObject_start); JSONObject jsonObject_end = new JSONObject(networkDiagramPetsDto.getCirclePet().getJson()); JsonUtils2.setJsonValueByPath(jsonObject_end, "id".split("/"), endId); JsonUtils2.setJsonValueByPath(jsonObject_end, "attrs/text/text".split("/"), "结束"); JsonUtils2.setJsonValueByPath(jsonObject_end, "attrs/title/text".split("/"), ""); JsonUtils2.setJsonValueByPath(jsonObject_end, "position/x".split("/"), endX); JsonUtils2.setJsonValueByPath(jsonObject_end, "position/y".split("/"), middleY); JsonUtils2.setArrJsonValueByPath(jsonObject_end, "ports/items/".split("/"), "group", "top", "id", UUIDUtil.generateId().toString()); JsonUtils2.setArrJsonValueByPath(jsonObject_end, "ports/items/".split("/"), "group", "right", "id", UUIDUtil.generateId().toString()); JsonUtils2.setArrJsonValueByPath(jsonObject_end, "ports/items/".split("/"), "group", "bottom", "id", UUIDUtil.generateId().toString()); JsonUtils2.setArrJsonValueByPath(jsonObject_end, "ports/items/".split("/"), "group", "left", "id", endLeftPortId); jsonArray.add(jsonObject_end); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); for (DiagramMajorDto majorDto : listMajor) { String majorNodeId = UUIDUtil.generateId().toString(); for (int branchNo = 0; branchNo < majorDto.getBranchs().size(); branchNo++) { DiagramMajorBranchDto diagramMajorBranchDto = majorDto.getBranchs().get(branchNo); DiagramMajorBranchTimeDto lastDiagramMajorTimeDto = null; for (DiagramMajorBranchTimeDto diagramMajorTimeDto : diagramMajorBranchDto.getTimeNodes()) { String firstId = null; for (DiagramNode2Dto inspectionDto : diagramMajorTimeDto.getInspections()) { if (firstId == null) { firstId = inspectionDto.getId().toString(); } JSONObject jsonObject_text = new JSONObject(networkDiagramPetsDto.getTextPet().getJson()); JsonUtils2.setJsonValueByPath(jsonObject_text, "id".split("/"), inspectionDto.getBoxId().toString()); JsonUtils2.setJsonValueByPath(jsonObject_text, "attrs/label/textWrap/text".split("/"), inspectionDto.getProcessName()); JsonUtils2.setJsonValueByPath(jsonObject_text, "data/dataId".split("/"), inspectionDto.getId().toString()); //JsonUtils2.setJsonValueByPath(jsonObject_text, "data/inspectionCode".split("/"), inspectionDto.getInspectionCode().toString()); JsonUtils2.setJsonValueByPath(jsonObject_text, "data/constructionId".split("/"), inspectionDto.getConstructionId() == null ? "" : inspectionDto.getConstructionId().toString()); JsonUtils2.setJsonValueByPath(jsonObject_text, "position/x".split("/"), inspectionDto.getX()); JsonUtils2.setJsonValueByPath(jsonObject_text, "position/y".split("/"), inspectionDto.getY()); //JsonUtils2.setJsonValueByPath(jsonObject_text, "attrs/label/textWrap/width".split("/"), inspectionDto.getWidth()); JsonUtils2.setJsonValueByPath(jsonObject_text, "size/width".split("/"), diagramMajorTimeDto.getInspectionWidth()); JsonUtils2.setJsonValueByPath(jsonObject_text, "size/height".split("/"), inspectionDto.getHeight()); JsonUtils2.setArrJsonValueByPath(jsonObject_text, "ports/items/".split("/"), "group", "top", "id", inspectionDto.getTopId().toString()); JsonUtils2.setArrJsonValueByPath(jsonObject_text, "ports/items/".split("/"), "group", "right", "id", inspectionDto.getRightId().toString()); JsonUtils2.setArrJsonValueByPath(jsonObject_text, "ports/items/".split("/"), "group", "bottom", "id", inspectionDto.getBottomId().toString()); JsonUtils2.setArrJsonValueByPath(jsonObject_text, "ports/items/".split("/"), "group", "left", "id", inspectionDto.getLeftId().toString()); jsonArray.add(jsonObject_text); } JSONObject jsonObject_circle2 = new JSONObject(networkDiagramPetsDto.getCirclePet2().getJson()); JsonUtils2.setJsonValueByPath(jsonObject_circle2, "id".split("/"), diagramMajorTimeDto.getBoxId().toString()); JsonUtils2.setJsonValueByPath(jsonObject_circle2, "attrs/text/text".split("/"), sdf.format(diagramMajorTimeDto.getRequiredCompletionTime())); JsonUtils2.setJsonValueByPath(jsonObject_circle2, "data/dataId".split("/"), firstId); JsonUtils2.setJsonValueByPath(jsonObject_circle2, "position/x".split("/"), diagramMajorTimeDto.getX()); JsonUtils2.setJsonValueByPath(jsonObject_circle2, "position/y".split("/"), diagramMajorTimeDto.getY()); JsonUtils2.setArrJsonValueByPath(jsonObject_circle2, "ports/items/".split("/"), "group", "top", "id", diagramMajorTimeDto.getTopId().toString()); JsonUtils2.setArrJsonValueByPath(jsonObject_circle2, "ports/items/".split("/"), "group", "right", "id", diagramMajorTimeDto.getRightId().toString()); JsonUtils2.setArrJsonValueByPath(jsonObject_circle2, "ports/items/".split("/"), "group", "bottom", "id", diagramMajorTimeDto.getBottomId().toString()); JsonUtils2.setArrJsonValueByPath(jsonObject_circle2, "ports/items/".split("/"), "group", "left", "id", diagramMajorTimeDto.getLeftId().toString()); jsonArray.add(jsonObject_circle2); if (lastDiagramMajorTimeDto == null) { if (branchNo == 0) { JSONObject jsonObject_majorNode = new JSONObject(networkDiagramPetsDto.getCirclePet().getJson()); JsonUtils2.setJsonValueByPath(jsonObject_majorNode, "id".split("/"), majorNodeId); JsonUtils2.setJsonValueByPath(jsonObject_majorNode, "attrs/text/text".split("/"), ""); JsonUtils2.setJsonValueByPath(jsonObject_majorNode, "attrs/title/text".split("/"), ""); JsonUtils2.setJsonValueByPath(jsonObject_majorNode, "position/x".split("/"), majorStartX); JsonUtils2.setJsonValueByPath(jsonObject_majorNode, "position/y".split("/"), diagramMajorTimeDto.getY() + networkDiagramPetsDto.getCirclePet2().getHeight() / 2 - 3); JsonUtils2.setJsonValueByPath(jsonObject_majorNode, "size/width".split("/"), 5); JsonUtils2.setJsonValueByPath(jsonObject_majorNode, "size/height".split("/"), 5); JsonUtils2.setArrJsonValueByPath(jsonObject_majorNode, "ports/items/".split("/"), "group", "top", "id", UUIDUtil.generateId().toString()); JsonUtils2.setArrJsonValueByPath(jsonObject_majorNode, "ports/items/".split("/"), "group", "right", "id", startRightPortId); JsonUtils2.setArrJsonValueByPath(jsonObject_majorNode, "ports/items/".split("/"), "group", "bottom", "id", UUIDUtil.generateId().toString()); JsonUtils2.setArrJsonValueByPath(jsonObject_majorNode, "ports/items/".split("/"), "group", "left", "id", UUIDUtil.generateId().toString()); jsonArray.add(jsonObject_majorNode); JSONObject jsonObject_edge = new JSONObject(networkDiagramPetsDto.getEdgePet3().getJson()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "id".split("/"), UUIDUtil.generateId().toString()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "target/cell".split("/"), startId); JsonUtils2.setJsonValueByPath(jsonObject_edge, "target/port".split("/"), ""); JsonUtils2.setJsonValueByPath(jsonObject_edge, "source/cell".split("/"), majorNodeId); JsonUtils2.setJsonValueByPath(jsonObject_edge, "source/port".split("/"), ""); JsonUtils2.setJsonValueByPath(jsonObject_edge, "phaseType".split("/"), "left"); JSONObject temp = (jsonObject_edge.getJSONArray("labels")).getJSONObject(0); JsonUtils2.setJsonValueByPath(temp, "attrs/text/text".split("/"), majorDto.getMajorName()); JsonUtils2.setJsonValueByPath(temp, "attrs/text/fontSize".split("/"), majorFontsize); JsonUtils2.setJsonValueByPath(temp, "position/distance".split("/"), 0.4); jsonArray.add(jsonObject_edge); jsonObject_edge = new JSONObject(networkDiagramPetsDto.getEdgePet().getJson()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "id".split("/"), UUIDUtil.generateId().toString()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "source/cell".split("/"), majorNodeId); JsonUtils2.setJsonValueByPath(jsonObject_edge, "source/port".split("/"), ""); JsonUtils2.setJsonValueByPath(jsonObject_edge, "target/cell".split("/"), diagramMajorTimeDto.getBoxId().toString()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "target/port".split("/"), diagramMajorTimeDto.getLeftId().toString()); JSONObject temp1 = (jsonObject_edge.getJSONArray("labels")).getJSONObject(0); JsonUtils2.setJsonValueByPath(temp1, "attrs/text/text".split("/"), ""); JsonUtils2.setJsonValueByPath(temp1, "position/distance".split("/"), 0.4); /* JSONObject temp2 = (jsonObject_edge.getJSONArray("vertices")).getJSONObject(0); JsonUtils2.setJsonValueByPath(temp2, "x".split("/"), majorStartX); JsonUtils2.setJsonValueByPath(temp2, "y".split("/"), diagramMajorTimeDto.getY() + networkDiagramPetsDto.getCirclePet2().getHeight() / 2); */ jsonArray.add(jsonObject_edge); } else { JSONObject jsonObject_edge = new JSONObject(networkDiagramPetsDto.getEdgePet2().getJson()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "id".split("/"), UUIDUtil.generateId().toString()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "source/cell".split("/"), majorNodeId); JsonUtils2.setJsonValueByPath(jsonObject_edge, "source/port".split("/"), ""); JsonUtils2.setJsonValueByPath(jsonObject_edge, "target/cell".split("/"), diagramMajorTimeDto.getBoxId().toString()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "target/port".split("/"), diagramMajorTimeDto.getLeftId().toString()); JSONObject temp = (jsonObject_edge.getJSONArray("labels")).getJSONObject(0); JsonUtils2.setJsonValueByPath(temp, "attrs/text/text".split("/"), ""); JsonUtils2.setJsonValueByPath(temp, "position/distance".split("/"), 0.4); JSONObject temp2 = (jsonObject_edge.getJSONArray("vertices")).getJSONObject(0); JsonUtils2.setJsonValueByPath(temp2, "x".split("/"), majorStartX); JsonUtils2.setJsonValueByPath(temp2, "y".split("/"), diagramMajorTimeDto.getY() + networkDiagramPetsDto.getCirclePet2().getHeight() / 2); jsonArray.add(jsonObject_edge); } } else { JSONObject jsonObject_edge = new JSONObject(networkDiagramPetsDto.getEdgePet().getJson()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "id".split("/"), UUIDUtil.generateId().toString()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "source/cell".split("/"), lastDiagramMajorTimeDto.getBoxId().toString()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "source/port".split("/"), lastDiagramMajorTimeDto.getRightId().toString()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "target/cell".split("/"), diagramMajorTimeDto.getBoxId().toString()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "target/port".split("/"), diagramMajorTimeDto.getLeftId().toString()); JSONObject temp = (jsonObject_edge.getJSONArray("labels")).getJSONObject(0); JsonUtils2.setJsonValueByPath(temp, "attrs/text/text".split("/"), ""); jsonArray.add(jsonObject_edge); } lastDiagramMajorTimeDto = diagramMajorTimeDto; } if (lastDiagramMajorTimeDto != null) { JSONObject jsonObject_edge = new JSONObject(networkDiagramPetsDto.getEdgePet2().getJson()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "id".split("/"), UUIDUtil.generateId().toString()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "source/cell".split("/"), lastDiagramMajorTimeDto.getBoxId().toString()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "source/port".split("/"), lastDiagramMajorTimeDto.getRightId().toString()); JsonUtils2.setJsonValueByPath(jsonObject_edge, "target/cell".split("/"), endId); JsonUtils2.setJsonValueByPath(jsonObject_edge, "target/port".split("/"), endLeftPortId); JsonUtils2.setJsonValueByPath(jsonObject_edge, "phaseType".split("/"), "right"); JSONObject temp = (jsonObject_edge.getJSONArray("labels")).getJSONObject(0); JsonUtils2.setJsonValueByPath(temp, "attrs/text/text".split("/"), ""); JSONObject temp2 = (jsonObject_edge.getJSONArray("vertices")).getJSONObject(0); JsonUtils2.setJsonValueByPath(temp2, "x".split("/"), majorEndX); JsonUtils2.setJsonValueByPath(temp2, "y".split("/"), lastDiagramMajorTimeDto.getY() + networkDiagramPetsDto.getCirclePet2().getHeight() / 2); jsonArray.add(jsonObject_edge); } } } } jsonObject_root.put("cells", jsonArray); return jsonObject_root.toString(); } public List DiagramMajorData(List listMajor, List allNodeList, String beginDate) { //int branchInspectMaxNum = 0; Date maxDate = null; Date minDate = null; for (DiagramMajorDto majorDto : listMajor) { majorDto.setSumFontWith(0); majorDto.setMaxFontWith(0); Date lastRequiredCompletionTime = null; DiagramMajorBranchTimeDto majorTimeDto = null; Date requiredCompletionDate = null; List inspectionList = allNodeList.stream().filter(item -> item.getMajorId().equals(majorDto.getMajorId())).collect(Collectors.toList()); int timeNo = 0; int majorTimeWidth = 0; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); for (DiagramNode2Dto inspectionDto : inspectionList) { if (StringUtils.isNotBlank(inspectionDto.getRequiredCompletionTime())) { try { requiredCompletionDate = sdf.parse(inspectionDto.getRequiredCompletionTime()); } catch (ParseException e) { e.printStackTrace(); } } /*if (StringUtils.isNotBlank(node.getActualCompletion())) { actualCompletionDate = sdf.parse(node.getActualCompletion()); }*/ if (lastRequiredCompletionTime == null || !DateUtil.isSameDay(lastRequiredCompletionTime, requiredCompletionDate)) { if (majorTimeDto != null) { majorTimeDto.setMaxFontWith(majorTimeWidth); majorDto.getTimes().add(majorTimeDto); timeNo++; } majorTimeDto = new DiagramMajorBranchTimeDto(); majorTimeWidth = 0; lastRequiredCompletionTime = requiredCompletionDate; Date curDate = requiredCompletionDate; majorTimeDto.setRequiredCompletionTime(curDate); maxDate = maxDate == null ? requiredCompletionDate : requiredCompletionDate.after(maxDate) ? requiredCompletionDate : maxDate; minDate = minDate == null ? requiredCompletionDate : requiredCompletionDate.before(minDate) ? requiredCompletionDate : minDate; } majorTimeDto.getInspections().add(inspectionDto); /* if (majorDto.getLeftPhase() == null && phaseMap.get(inspectionDto.getBeginPhase()) != null) { majorDto.setLeftPhase(phaseMap.get(inspectionDto.getBeginPhase())); minDate = minDate == null ? inspectionDto.getLeftPhaseDate() : inspectionDto.getLeftPhaseDate().after(minDate) ? inspectionDto.getLeftPhaseDate() : minDate; } if (majorDto.getRightPhase() == null && phaseMap.get(inspectionDto.getEndPhase()) != null) majorDto.setRightPhase(phaseMap.get(inspectionDto.getEndPhase())); */ String text = inspectionDto.getProcessName(); Map font = getFont(text); Integer width = font.get("width"); Integer height = font.get("height"); inspectionDto.setFontWith(width); inspectionDto.setFontHeight(height); //width = width + initParamDto.getItemSpaceWidth(); if (width > majorTimeWidth) majorTimeWidth = width; } if (majorTimeDto != null) { majorTimeDto.setMaxFontWith(majorTimeWidth); majorDto.getTimes().add(majorTimeDto); } } if (maxDate != null) { if (StringUtils.isNotBlank(beginDate)) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); try { minDate = dateFormat.parse(beginDate); } catch (Exception ex) { } } else { Long totalDays = TimeUtils.daysBetween(minDate, maxDate, "day"); minDate = TimeUtils.dateAdd(minDate, (int) (-1 * totalDays / 12), "days"); } resultDataDto.setMinDate(minDate); resultDataDto.setMaxDate(maxDate); int totalDays = (int) DateUtil.betweenDay(minDate, maxDate, true); //int dayWidth = initParamDto.getTotalMajorWidth() / totalDays; for (DiagramMajorDto majorDto : listMajor) { int mustLineNum = 1; int mustMaxLineNum = 1; for (int i = 0; i < majorDto.getTimes().size(); i++) { DiagramMajorBranchTimeDto timeDto = majorDto.getTimes().get(i); int timeNodeX = initParamDto.getMajorFirstFontWidth() + (initParamDto.getTotalMajorWidth() * (int) DateUtil.betweenDay(minDate, timeDto.getRequiredCompletionTime(), true)) / totalDays; timeDto.setX(timeNodeX); if (i > 0) { DiagramMajorBranchTimeDto lastTimeDto = majorDto.getTimes().get(i - 1); int timeNodeDistance = timeDto.getX() - lastTimeDto.getX() - networkDiagramPetsDto.getCirclePet2().getWidth(); if (timeNodeDistance < 50 && timeNodeDistance < timeDto.getMaxFontWith()) { if (mustLineNum > 1) { DiagramMajorBranchTimeDto lastTimeDto2 = majorDto.getTimes().get(i - 2); timeNodeDistance = timeDto.getX() - lastTimeDto2.getX() - networkDiagramPetsDto.getCirclePet2().getWidth(); if (timeNodeDistance < 50 && timeNodeDistance < timeDto.getMaxFontWith()) { mustLineNum++; mustMaxLineNum = mustLineNum; break; } } else mustLineNum++; if (mustLineNum > mustMaxLineNum) { mustMaxLineNum = mustLineNum; } } else { mustLineNum = 1; } } } int maxTimeNodeOfRow = initParamDto.getMaxTimeNodeOfRow(); int lineNum = majorDto.getTimes().size() / maxTimeNodeOfRow; if (majorDto.getTimes().size() % maxTimeNodeOfRow != 0) lineNum = lineNum + 1; if (mustMaxLineNum > lineNum) { lineNum = mustMaxLineNum; } if (lineNum > 3) lineNum = 3; for (int i = 0; i < lineNum; i++) { majorDto.getBranchs().add(new DiagramMajorBranchDto()); } int timeNo = 0; for (DiagramMajorBranchTimeDto majorTimeDto : majorDto.getTimes()) { majorDto.getBranchs().get(timeNo % lineNum).getTimeNodes().add(majorTimeDto); timeNo++; } } for (DiagramMajorDto majorDto : listMajor) { int maxBranchWidth = 0; int sumBranchHeight = 0; for (DiagramMajorBranchDto branchDto : majorDto.getBranchs()) { int branchWidth = 0; int branchHeight = initParamDto.getMajorTimeNodeHeight(); for (int i = 0; i < branchDto.getTimeNodes().size(); i++) { DiagramMajorBranchTimeDto timeDto = branchDto.getTimeNodes().get(i); //int timeNodeX = initParamDto.getMajorFirstFontWidth() + dayWidth * (int) DateUtil.betweenDay(minDate, timeDto.getRequiredCompletionTime(), true); //timeDto.setX(timeNodeX); int timeNodeX = timeDto.getX(); int spaceWidth = timeNodeX - (i == 0 ? 0 : branchDto.getTimeNodes().get(i - 1).getX() + networkDiagramPetsDto.getCirclePet2().getWidth()); timeDto.setTimeNodeSpaceWidth(spaceWidth); timeDto.setInsepectX(timeNodeX - spaceWidth - initParamDto.getItemSpaceWidth()); branchWidth = timeDto.getMaxFontWith(); int validWidth = spaceWidth - (initParamDto.getItemSpaceWidth() + 2) * 2; int timeInspectionHeight = 0; int inspectionWidth = 0; if (timeDto.getTimeNodeSpaceWidth() > (timeDto.getMaxFontWith() + 10)) inspectionWidth = timeDto.getMaxFontWith(); else { inspectionWidth = timeDto.getTimeNodeSpaceWidth() - 10; } if (inspectionWidth < 30) { inspectionWidth = 30; } inspectionWidth = 10 + 20 * (int) (inspectionWidth / 20) + 10; timeDto.setInspectionWidth(inspectionWidth); int insepectY = 0; for (DiagramNode2Dto inspectDto : timeDto.getInspections()) { int inspectionRows = inspectDto.getFontWith() / (inspectionWidth - 10); if (inspectDto.getFontWith() % (inspectionWidth - 10) != 0) inspectionRows = inspectionRows + 1; Integer inspectionHeight = inspectionRows * 20 + 30 * (int) ((inspectionRows - 1) / 10) + ((inspectionRows - 1) % 10 > 5 ? 30 : (inspectionRows - 1) % 10 > 2 ? 20 : 10); inspectDto.setY(insepectY); insepectY = insepectY + inspectionHeight; inspectDto.setHeight(inspectionHeight); timeInspectionHeight = timeInspectionHeight + inspectionHeight; } timeDto.setInsepectX(timeDto.getX() - inspectionWidth - initParamDto.getItemSpaceWidth()); timeDto.setInsepectY(timeDto.getY() + (initParamDto.getInspectRowHeight() - timeInspectionHeight) / 2); if (timeInspectionHeight < networkDiagramPetsDto.getCirclePet2().getHeight()) timeInspectionHeight = networkDiagramPetsDto.getCirclePet2().getHeight(); timeDto.setInspectionHeight(timeInspectionHeight); if (timeInspectionHeight > branchHeight) branchHeight = timeInspectionHeight; } branchDto.setHeight(branchHeight); sumBranchHeight = sumBranchHeight + branchHeight; branchWidth = branchWidth + majorDto.getTimes().size() * (initParamDto.getMajorTimeNodeWidth() + 2 * initParamDto.getItemSpaceWidth()); branchDto.setWidth(branchWidth); if (branchWidth > maxBranchWidth) maxBranchWidth = branchWidth; } majorDto.setWidth(maxBranchWidth); majorDto.setHeight(sumBranchHeight); } } return listMajor; } public void getPetsInfo() { Map params = new HashMap(); params.put("projectId", 10000); params.put("diagramId", 10000); List list_style = baseDao.getList(params); if (list_style.size() > 0) { String modelStr = list_style.get(0).getContent(); JSONObject modelJson = new JSONObject(modelStr); JSONArray modelJsonArray = modelJson.getJSONArray("cells"); for (int i = 0; i < modelJsonArray.size(); i++ ) { JSONObject jsonObject = modelJsonArray.getJSONObject(i); if (jsonObject.get("shape").equals("custom-circle")) { Object nodeMarker = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/text/text".split("/")); if ("专业".equals(nodeMarker)) { fillColorArr[StatusEnum.zy.ordinal()] = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/body/fill".split("/")).toString(); fontColorArr[StatusEnum.zy.ordinal()] = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/text/fill".split("/")).toString(); } if ("进行中".equals(nodeMarker)) { fillColorArr[StatusEnum.jxz.ordinal()] = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/body/fill".split("/")).toString(); fontColorArr[StatusEnum.jxz.ordinal()] = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/text/fill".split("/")).toString(); } if ("临期".equals(nodeMarker)) { fillColorArr[StatusEnum.lq.ordinal()] = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/body/fill".split("/")).toString(); fontColorArr[StatusEnum.lq.ordinal()] = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/text/fill".split("/")).toString(); } if ("逾期".equals(nodeMarker)) { fillColorArr[StatusEnum.yq.ordinal()] = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/body/fill".split("/")).toString(); fontColorArr[StatusEnum.yq.ordinal()] = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/text/fill".split("/")).toString(); } if ("完成".equals(nodeMarker)) { fillColorArr[StatusEnum.zcwc.ordinal()] = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/body/fill".split("/")).toString(); fontColorArr[StatusEnum.zcwc.ordinal()] = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/text/fill".split("/")).toString(); } if ("超期完成".equals(nodeMarker)) { fillColorArr[StatusEnum.cqwc.ordinal()] = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/body/fill".split("/")).toString(); fontColorArr[StatusEnum.cqwc.ordinal()] = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/text/fill".split("/")).toString(); } if ("阶段名称".equals(nodeMarker)) { networkDiagramPetsDto.getCirclePet().setJson(jsonObject.toString()); int width = Convert.toInt(JsonUtils2.getJsonValueByPath(jsonObject, "size/width".split("/")).toString()); int height = Convert.toInt(JsonUtils2.getJsonValueByPath(jsonObject, "size/width".split("/")).toString()); networkDiagramPetsDto.getCirclePet().setWidth(width); networkDiagramPetsDto.getCirclePet().setHeight(height); } } else if (jsonObject.get("shape").equals("edge")) { JSONArray tmpArray = jsonObject.getJSONArray("labels"); JSONObject tmpJSONObject = (JSONObject) tmpArray.get(0); Object nodeMarker = JsonUtils2.getJsonValueByPath(tmpJSONObject, "attrs/text/text".split("/")); if ("线条样式1".equals(nodeMarker)) { networkDiagramPetsDto.getEdgePet().setJson(jsonObject.toString()); networkDiagramPetsDto.getEdgePet().setWidth(0); networkDiagramPetsDto.getEdgePet().setHeight(0); } else if ("线条样式2".equals(nodeMarker)) { networkDiagramPetsDto.getEdgePet2().setJson(jsonObject.toString()); networkDiagramPetsDto.getEdgePet2().setWidth(0); networkDiagramPetsDto.getEdgePet2().setHeight(0); } else if ("无箭头".equals(nodeMarker)) { networkDiagramPetsDto.getEdgePet3().setJson(jsonObject.toString()); networkDiagramPetsDto.getEdgePet3().setWidth(0); networkDiagramPetsDto.getEdgePet3().setHeight(0); } } else if (jsonObject.get("shape").equals("custom-circle1")) { int width = Convert.toInt(JsonUtils2.getJsonValueByPath(jsonObject, "size/width".split("/")).toString()); int height = Convert.toInt(JsonUtils2.getJsonValueByPath(jsonObject, "size/width".split("/")).toString()); networkDiagramPetsDto.getCirclePet2().setJson(jsonObject.toString()); networkDiagramPetsDto.getCirclePet2().setWidth(width); networkDiagramPetsDto.getCirclePet2().setHeight(height); } else if (jsonObject.get("shape").equals("custom-rect")) { Object nodeMarker = JsonUtils2.getJsonValueByPath(jsonObject, "attrs/label/textWrap/text".split("/")); if ("过程事件1".equals(nodeMarker)) { int width = Convert.toInt(JsonUtils2.getJsonValueByPath(jsonObject, "size/width".split("/")).toString()); int height = Convert.toInt(JsonUtils2.getJsonValueByPath(jsonObject, "size/height".split("/")).toString()); networkDiagramPetsDto.getTextPet().setJson(jsonObject.toString()); networkDiagramPetsDto.getTextPet().setWidth(width); networkDiagramPetsDto.getTextPet().setHeight(height); } } else if (jsonObject.get("shape").equals("image")) { Object nodeMarker = JsonUtils2.getJsonValueByPath(jsonObject, "data/imagePost".split("/")); if ("center".equals(nodeMarker)) { int width = Convert.toInt(JsonUtils2.getJsonValueByPath(jsonObject, "size/width".split("/")).toString()); int height = Convert.toInt(JsonUtils2.getJsonValueByPath(jsonObject, "size/height".split("/")).toString()); networkDiagramPetsDto.getImageCenter().setJson(jsonObject.toString()); networkDiagramPetsDto.getImageCenter().setWidth(width); networkDiagramPetsDto.getImageCenter().setHeight(height); } if ("top".equals(nodeMarker)) { int width = Convert.toInt(JsonUtils2.getJsonValueByPath(jsonObject, "size/width".split("/")).toString()); int height = Convert.toInt(JsonUtils2.getJsonValueByPath(jsonObject, "size/height".split("/")).toString()); networkDiagramPetsDto.getImageTop().setJson(jsonObject.toString()); networkDiagramPetsDto.getImageTop().setWidth(width); networkDiagramPetsDto.getImageTop().setHeight(height); } if ("right".equals(nodeMarker)) { int width = Convert.toInt(JsonUtils2.getJsonValueByPath(jsonObject, "size/width".split("/")).toString()); int height = Convert.toInt(JsonUtils2.getJsonValueByPath(jsonObject, "size/height".split("/")).toString()); networkDiagramPetsDto.getImageRight().setJson(jsonObject.toString()); networkDiagramPetsDto.getImageRight().setWidth(width); networkDiagramPetsDto.getImageRight().setHeight(height); } if ("bottom".equals(nodeMarker)) { int width = Convert.toInt(JsonUtils2.getJsonValueByPath(jsonObject, "size/width".split("/")).toString()); int height = Convert.toInt(JsonUtils2.getJsonValueByPath(jsonObject, "size/height".split("/")).toString()); networkDiagramPetsDto.getImageBottom().setJson(jsonObject.toString()); networkDiagramPetsDto.getImageBottom().setWidth(width); networkDiagramPetsDto.getImageBottom().setHeight(height); } if ("left".equals(nodeMarker)) { int width = Convert.toInt(JsonUtils2.getJsonValueByPath(jsonObject, "size/width".split("/")).toString()); int height = Convert.toInt(JsonUtils2.getJsonValueByPath(jsonObject, "size/height".split("/")).toString()); networkDiagramPetsDto.getImageLeft().setJson(jsonObject.toString()); networkDiagramPetsDto.getImageLeft().setWidth(width); networkDiagramPetsDto.getImageLeft().setHeight(height); } } } } } public Map getFont(String text) { return getFont(text, "仿宋", Font.PLAIN, 20); } public Map getFont(String text, String fontFamily, int fontType, int fontSize) { AffineTransform affinetransform = new AffineTransform(); FontRenderContext frc = new FontRenderContext(affinetransform, true, true); Font font = new Font(fontFamily, fontType, fontSize); /* int textwidth = (int)(font.getStringBounds(text, frc).getWidth()); int textheight = (int)(font.getStringBounds(text, frc).getHeight());*/ Map result = new HashMap<>(); result.put("width", (int) font.getStringBounds(text, frc).getWidth()); result.put("height", (int) font.getStringBounds(text, frc).getHeight()); return result; } public mxGraph getCsDiagram(mxGraph graph, String json, List nodeStatusList, Integer panelWidth, Integer panelHeight) { if (StringUtils.isBlank(json)) { return graph; } Map statusMap = new HashMap<>(); if (nodeStatusList != null) { Date today = new Date(); for (NetworkNodeStatusDto node : nodeStatusList) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date requiredCompletionDate = null; Date actualCompletionDate = null; try { if (StringUtils.isNotBlank(node.getRequiredCompletionTime())) { requiredCompletionDate = sdf.parse(node.getRequiredCompletionTime()); } if (StringUtils.isNotBlank(node.getActualCompletion())) { actualCompletionDate = sdf.parse(node.getActualCompletion()); } } catch (ParseException e) { e.printStackTrace(); } if (node.getCurrentStatus() == null || node.getCurrentStatus() == 0) { if (today.after(requiredCompletionDate)) { statusMap.put(node.getId(), StatusEnum.yq); } else if ((requiredCompletionDate.getTime() - today.getTime()) / (1000 * 60 * 60 * 24) < 7) { statusMap.put(node.getId(), StatusEnum.lq); } else { statusMap.put(node.getId(), StatusEnum.jxz); } } else if (node.getCurrentStatus() == 1) { // 已完成 if (node.getActualCompletion() != null && actualCompletionDate.after(requiredCompletionDate)) { statusMap.put(node.getId(), StatusEnum.cqwc); } else { statusMap.put(node.getId(), StatusEnum.zcwc); } } } } Object parent = graph.getDefaultParent(); graph.removeCells(graph.getChildVertices(parent)); graph.removeCells(graph.getChildEdges(parent)); graph.getModel().beginUpdate(); JSONObject jsonObject = new JSONObject(json); JSONArray jsonArray = jsonObject.getJSONArray("cells"); Map map = new HashMap<>(); Integer minX = 100000; Integer minY = 100000; Integer maxX = -100000; Integer maxY = -100000; /* Integer panelHeight = 600; Integer panelWidth = 800;*/ Integer defX = 0; Integer defY = 0; Map mapNodeInfo = new HashMap<>(); for (int i = 0; i < jsonArray.size(); i++) { JSONObject cellObject = jsonArray.getJSONObject(i); String shapeValue = cellObject.get("shape").toString(); if (!shapeValue.equals("edge")) { Integer x = (Integer) JsonUtils2.getJsonValueByPath(cellObject, "position/x".split("/")); Integer y = (Integer) JsonUtils2.getJsonValueByPath(cellObject, "position/y".split("/")); Integer width = (Integer) JsonUtils2.getJsonValueByPath(cellObject, "size/width".split("/")); Integer height = (Integer) JsonUtils2.getJsonValueByPath(cellObject, "size/height".split("/")); String idValue = cellObject.get("id").toString(); String text = "aaa"; if (shapeValue.contains("circle")) { text = (String) JsonUtils2.getJsonValueByPath(cellObject, "attrs/text/text".split("/")); mapNodeInfo.put(idValue, new Coordinate(x, y, width, height, text)); } if (shapeValue.equals("image")) { mapNodeInfo.put(idValue, new Coordinate(x, y, width, height, "")); } if (x < minX) minX = x; if (x + width > maxX) maxX = x + width; if (y < minY) minY = y; if (y + height > maxY) maxY = y + height; } } if (maxY - minY < panelHeight) { defY = (panelHeight - (maxY - minY)) / 2; } if (minY < 0) defY = defY - minY; if (defY > 0) { for (Coordinate coordinate : mapNodeInfo.values()) { coordinate.setY(coordinate.getY() + defY); } } if (maxX - minX < panelWidth) { defX = (panelWidth - (maxX - minX)) / 2; } if (minX < 0) defX = defX - minX; if (defX > 0) { for (Coordinate coordinate : mapNodeInfo.values()) { coordinate.setX(coordinate.getX() + defX); } } for (int i = 0; i < jsonArray.size(); i++) { String shapeValue = jsonArray.getJSONObject(i).get("shape").toString(); String idValue = jsonArray.getJSONObject(i).get("id").toString(); StatusEnum status = StatusEnum.jxz;//StatusEnum.wqd; if (!shapeValue.equals("edge")) { status = statusMap.get(Long.parseLong(idValue)); if ("1888761224410202114".equals(idValue)) { System.out.println(2222); } Object insertVertex = createInsertVertex(graph, jsonArray.getJSONObject(i), defX, defY, status); map.put(idValue, insertVertex); } } for (int i = 0; i < jsonArray.size(); i++) { String shapeValue = jsonArray.getJSONObject(i).get("shape").toString(); if (shapeValue.equals("edge")) { Object source = JsonUtils2.getJsonValueByPath(jsonArray.getJSONObject(i), "source/cell".split("/")); if (source == null) { //createLineSeg(graph, jsonArray.getJSONObject(i),parent); } else { Object target = JsonUtils2.getJsonValueByPath(jsonArray.getJSONObject(i), "target/cell".split("/")); Object lineLableObj = JsonUtils2.getJsonValueByPath(jsonArray.getJSONObject(i).getJSONArray("labels").getJSONObject(0), "attrs/text/text".split("/")); String lineLable = ""; if (lineLableObj != null) { lineLable = lineLableObj.toString(); } if (map.get(source) != null && map.get(target) != null) { Coordinate sourceC = mapNodeInfo.get(source); Coordinate targetC = mapNodeInfo.get(target); if (StringUtils.isBlank(sourceC.getType()) && !"开始".equals(targetC.getType())) { if (Math.abs((sourceC.getY() + sourceC.getHeight() / 2) - (targetC.getY() + targetC.getHeight() / 2)) > 5) { Object graphObject = graph.insertVertex(parent, "", "", sourceC.getX(), targetC.getY() + targetC.getHeight() / 2, 5, 5, "whiteSpace=wrap;labelWidth=60;" + mxConstants.STYLE_SHAPE + "=" + mxConstants.SHAPE_ELLIPSE); graph.insertEdge(parent, null, "", map.get(source), graphObject); graph.insertEdge(parent, null, "", graphObject, map.get(target)); } else { graph.insertEdge(parent, null, lineLable, map.get(source), map.get(target)); } } else if ("结束".equals(targetC.getType())) { if ((sourceC.getY() + sourceC.getHeight() / 2) != (targetC.getY() + targetC.getHeight() / 2)) { Object graphObject = graph.insertVertex(parent, "", "", targetC.getX() - 5, sourceC.getY() + sourceC.getHeight() / 2, 5, 5, "whiteSpace=wrap;labelWidth=60;" + mxConstants.STYLE_SHAPE + "=" + mxConstants.SHAPE_ELLIPSE); graph.insertEdge(parent, null, "", map.get(source), graphObject); graph.insertEdge(parent, null, "", graphObject, map.get(target)); } else { graph.insertEdge(parent, null, lineLable, map.get(source), map.get(target)); } } else { graph.insertEdge(parent, null, lineLable, map.get(source), map.get(target)); } } } } } for (int i = 0; i < jsonArray.size(); i++) { JSONObject jsonObject2 = jsonArray.getJSONObject(i); String shapeValue = jsonObject2.get("shape").toString(); if (shapeValue.equals("custom-circle")) { String text = (String) JsonUtils2.getJsonValueByPath(jsonObject2, "attrs/text/text".split("/")); if ("开始".equals(text) || "结束".equals(text)) { Integer x = (Integer) JsonUtils2.getJsonValueByPath(jsonObject2, "position/x".split("/")) + defX; Integer y = (Integer) JsonUtils2.getJsonValueByPath(jsonObject2, "position/y".split("/")) + defY; Integer width = (Integer) JsonUtils2.getJsonValueByPath(jsonObject2, "size/width".split("/")); Integer height = (Integer) JsonUtils2.getJsonValueByPath(jsonObject2, "size/height".split("/")); graph.insertVertex(parent, null, text, x, y, width, height, "whiteSpace=wrap;labelWidth=60;" + mxConstants.STYLE_SHAPE + "=" + mxConstants.SHAPE_ELLIPSE); } } } graph.getModel().endUpdate(); /* try { // 添加节点 Map map = new HashMap<>(); Object start = graph.insertVertex(parent, "start", "等哈结婚登记爱很简单哈哈大家哈就会加快", 220, 220, 130, 130, "whiteSpace=wrap;labelWidth=60;fillColor=red;"+ mxConstants.STYLE_SHAPE + "=" + mxConstants.SHAPE_DOUBLE_ELLIPSE); map.put("start",start); Object task1 = graph.insertVertex(parent, null, "等哈结婚登记爱很简单\r\n哈哈大家哈就会加快", 420, 220, 60, 130,"whiteSpace=wrap;strokeWidth=0 "); Object decision = graph.insertVertex(parent, "decision", "decision", 620, 220, 160, 130); map.put("decision",decision); Object task2 = graph.insertVertex(parent, null, "Task 2", 820, 220, 160, 130); Object end = graph.insertVertex(parent, null, "End", 3020, 220, 160, 130, mxConstants.STYLE_SHAPE + "=" + mxConstants.SHAPE_DOUBLE_ELLIPSE); // 添加连线 graph.insertEdge(parent, null, "", map.get("start"), map.get("decision"),"whiteSpace=wrap;labelWidth=60"); // graph.insertEdge(parent, null, "Task 1->Decision", task1, decision); //graph.insertEdge(parent, null, "Task 2->End", task2, end); graph.insertEdge(parent, null, "Decision(yes)jdhajsdhjashdjhajsdha
sjhdj->Task 2", decision, task2); graph.insertEdge(parent, null, "Decision(no)->End", decision, end); *//* Object circle1 = graph.insertVertex(parent, null, "", 50, 50, 1, 1 ,"shape=ellipse;strokeColor=black;strokeWidth=2"); Object circle2 = graph.insertVertex(parent, null, "", 200, 50, 1, 1, "shape=ellipse;strokeColor=black;strokeWidth=2"); // 创建一条连接两个圆点的线 graph.insertEdge(parent, null, "", circle1, circle2, "strokeColor=black;strokeWidth=2"); Object circle3 = graph.insertVertex(parent, null, "", 150, 150, 1, 1, "shape=ellipse;strokeColor=black;strokeWidth=2"); Object circle4 = graph.insertVertex(parent, null, "", 400, 150, 1, 1, "shape=ellipse;strokeColor=black;strokeWidth=2"); // 创建一条连接两个圆点的线 graph.insertEdge(parent, null, "", circle3, circle4, "strokeColor=black;strokeWidth=2;endArrow=none"); Object startVertex = graph.insertVertex(parent, null, "", 100, 100, 1, 1, "visible=0"); Object endVertex = graph.insertVertex(parent, null, "", 300, 100, 1, 1, "visible=0"); // 创建一条边连接这两个顶点 graph.insertEdge(parent, null, "", startVertex, endVertex, "strokeColor=black;strokeWidth=2;endArrow=none"); Object startVertex1 = graph.insertVertex(parent, null, "", 200, 200, 1, 1, "visible=0"); Object endVertex2 = graph.insertVertex(parent, null, "", 500, 200, 1, 1, "visible=0"); // 创建一条边连接这两个顶点 graph.insertEdge(parent, null, "", startVertex1, endVertex2, "strokeColor=black;strokeWidth=2;");*//* // 绘制十字架 Object crossVertex1 = graph.insertVertex(parent, null, "", 150, 150, 1, 1, "visible=0"); Object crossVertex2 = graph.insertVertex(parent, null, "", 250, 150, 1, 1, "visible=0"); Object crossVertex3 = graph.insertVertex(parent, null, "", 200, 100, 1, 1, "visible=0"); Object crossVertex4 = graph.insertVertex(parent, null, "", 200, 200, 1, 1, "visible=0"); graph.insertEdge(parent, null, "", crossVertex1, crossVertex2, "strokeColor=red;strokeWidth=2;endArrow=none"); graph.insertEdge(parent, null, "", crossVertex3, crossVertex4, "strokeColor=red;strokeWidth=2;endArrow=none"); Object vertex1 = graph.insertVertex(parent, null, "", 100, 100, 1, 1, "visible=0"); Object vertex2 = graph.insertVertex(parent, null, "", 300, 100, 1, 1, "visible=0"); Object vertex3 = graph.insertVertex(parent, null, "", 500, 100, 1, 1, "visible=0"); // 创建两条边,连接这三个顶点 graph.insertEdge(parent, null, "", vertex1, vertex2, "strokeColor=blue;strokeWidth=2;endArrow=none"); graph.insertEdge(parent, null, "", vertex2, vertex3, "strokeColor=blue;strokeWidth=2;endArrow=none"); graph.setCellsLocked(true); } finally { graph.getModel().endUpdate(); }*/ System.out.println(graph.toString()); graph.getView().validate(); return graph; } public Object createInsertVertex(mxGraph graph, JSONObject jsonObject, Integer defX, Integer defY, StatusEnum status) { Object parent = graph.getDefaultParent(); String shapeValue = jsonObject.get("shape").toString(); Object graphObject = null; switch (shapeValue) { case "custom-circle": case "custom-circle1": String text = (String) JsonUtils2.getJsonValueByPath(jsonObject, "attrs/text/text".split("/")); //String title = (String) JsonUtils2.getJsonValueByPath(jsonObject, "attrs/title/text".split("/")); String idValue = jsonObject.get("id").toString(); Integer x = (Integer) JsonUtils2.getJsonValueByPath(jsonObject, "position/x".split("/")) + defX; Integer y = (Integer) JsonUtils2.getJsonValueByPath(jsonObject, "position/y".split("/")) + defY; Integer width = (Integer) JsonUtils2.getJsonValueByPath(jsonObject, "size/width".split("/")); Integer height = (Integer) JsonUtils2.getJsonValueByPath(jsonObject, "size/height".split("/")); if (status != null) { String fontColor = "fontColor=" + fillColorArr[status.ordinal()] + ";"; graphObject = graph.insertVertex(parent, idValue, text, x, y, width, height, "whiteSpace=wrap;labelWidth=60;" + fontColor + mxConstants.STYLE_SHAPE + "=" + mxConstants.SHAPE_ELLIPSE); } else { if ("开始".equals(text) || "结束".equals(text)) { graphObject = graph.insertVertex(parent, idValue, "", x + width / 4, y + height / 4, width / 2, height / 2, "whiteSpace=wrap;labelWidth=60;" + mxConstants.STYLE_SHAPE + "=" + mxConstants.SHAPE_ELLIPSE); } else { graphObject = graph.insertVertex(parent, idValue, text, x, y, width, height, "whiteSpace=wrap;labelWidth=60;" + mxConstants.STYLE_SHAPE + "=" + mxConstants.SHAPE_ELLIPSE); } } /*if (StringUtils.isNotBlank(title)) { createText(graph, title, x, y, width, height); }*/ break; case "custom-rect": String label = (String) JsonUtils2.getJsonValueByPath(jsonObject, "attrs/label/textWrap/text".split("/")); String idValueRect = jsonObject.get("id").toString(); Integer xRect = (Integer) JsonUtils2.getJsonValueByPath(jsonObject, "position/x".split("/")) + defX; Integer yRect = (Integer) JsonUtils2.getJsonValueByPath(jsonObject, "position/y".split("/")) + defY; Integer widthRect = (Integer) JsonUtils2.getJsonValueByPath(jsonObject, "size/width".split("/")); Integer heightRect = (Integer) JsonUtils2.getJsonValueByPath(jsonObject, "size/height".split("/")); if (status != null) { String fontColor = "fontColor=" + fillColorArr[status.ordinal()] + ";"; graphObject = graph.insertVertex(parent, idValueRect, label, xRect, yRect, widthRect, heightRect, "whiteSpace=wrap;labelWidth=60;fillColor=none;strokeWidth=0;" + fontColor); } else { graphObject = graph.insertVertex(parent, idValueRect, label, xRect, yRect, widthRect, heightRect, "whiteSpace=wrap;labelWidth=60;fillColor=none;strokeWidth=0"); } break; case "image": String labelImg = ""; String idImg = jsonObject.get("id").toString(); Integer xImg = (Integer) JsonUtils2.getJsonValueByPath(jsonObject, "position/x".split("/")) + defX; Integer yImg = (Integer) JsonUtils2.getJsonValueByPath(jsonObject, "position/y".split("/")) + defY; Integer widthImg = 2; Integer heightImg = (Integer) JsonUtils2.getJsonValueByPath(jsonObject, "size/height".split("/")); graphObject = graph.insertVertex(parent, idImg, labelImg, xImg, yImg, widthImg, heightImg, "whiteSpace=wrap;labelWidth=60;strokeWidth=1;"); break; } return graphObject; } public void createText(mxGraph graph, String title, Integer x, Integer y, Integer width, Integer height) { Object parent = graph.getDefaultParent(); Object graphObject = null; graphObject = graph.insertVertex(parent, "", title, x, y + height + 5, width, 20, "whiteSpace=wrap;labelWidth=60;fillColor=none;strokeWidth=0"); } }