Commit bc7c3367 by qiuchaofei

关系添加属性:“颜色”

parent b88c8fd5
...@@ -144,7 +144,9 @@ public class DataRelationAnalyController { ...@@ -144,7 +144,9 @@ public class DataRelationAnalyController {
filePath = "D:\\dev\\neo4j-community-3.3.5\\systemRelation.xlsx"; filePath = "D:\\dev\\neo4j-community-3.3.5\\systemRelation.xlsx";
} }
return excel2Neo4jService.generalRelationFromExcel(filePath) ; excel2Neo4jService.generalRelationFromExcel(filePath) ;
logger.info("从excel生成neo4j的节点与关系完成。" );
return "";
} }
} }
...@@ -54,91 +54,116 @@ public class Excel2Neo4jServiceImpl implements Excel2Neo4jService { ...@@ -54,91 +54,116 @@ public class Excel2Neo4jServiceImpl implements Excel2Neo4jService {
workbook = new XSSFWorkbook(is); workbook = new XSSFWorkbook(is);
} }
Map<String,String> colorMap = new HashMap<>();
// 第一个sheet是 node,先解析入neo4j。 // 第一个sheet是 node,先解析入neo4j。
// 第二个sheet 是 关系, // 第二个sheet 是 关系,
if (workbook != null) { if (workbook != null) {
// 开始循环sheet页 从0开始(workbook.getNumberOfSheets()获取sheet页的数量)
for (int sheetIndex = 0; sheetIndex < workbook.getNumberOfSheets(); sheetIndex++) {
Sheet sheet = workbook.getSheetAt(sheetIndex);
if (sheet == null) { Sheet yanseSHeet = workbook.getSheet("形式颜色");
continue; {
int firstRowNum = yanseSHeet.getFirstRowNum();
int lastRowNum = yanseSHeet.getLastRowNum();
for (int rowNum = firstRowNum + 1; rowNum <= lastRowNum; rowNum++) {
// 获得当前行
Row row = yanseSHeet.getRow(rowNum);
if (row == null) {
continue;
}
// 获得当前行的开始列
int firstCellNum = row.getFirstCellNum();
// 获得当前行的列数
int lastCellNum = row.getLastCellNum();
String[] cells = new String[row.getLastCellNum()];
// 循环当前行
String typeName = getCellValue(row.getCell(1));
String color = getCellValue(row.getCell(2));
colorMap.put(typeName,color);
} }
if("系统节点".equals(sheet.getSheetName())){
// 获得当前sheet的开始行 }
int firstRowNum = sheet.getFirstRowNum();
// 获得当前sheet的结束行 Sheet jiedianSHeet = workbook.getSheet("系统节点");
int lastRowNum = sheet.getLastRowNum(); {
// 循环除第一行外的所有行 // 获得当前sheet的开始行
for (int rowNum = firstRowNum + 1; rowNum <= lastRowNum; rowNum++) { int firstRowNum = jiedianSHeet.getFirstRowNum();
// 获得当前行 // 获得当前sheet的结束行
Row row = sheet.getRow(rowNum); int lastRowNum = jiedianSHeet.getLastRowNum();
if (row == null) { // 循环除第一行外的所有行
continue; for (int rowNum = firstRowNum + 1; rowNum <= lastRowNum; rowNum++) {
} // 获得当前行
// 获得当前行的开始列 Row row = jiedianSHeet.getRow(rowNum);
int firstCellNum = row.getFirstCellNum(); if (row == null) {
// 获得当前行的列数 continue;
int lastCellNum = row.getLastCellNum();
String[] cells = new String[row.getLastCellNum()];
// 循环当前行
Map<String,String> nodeAttribute = new HashMap<>();
String systemName = "";
SystemNode systemNode = new SystemNode();
for (int cellNum = firstCellNum; cellNum < lastCellNum; cellNum++) {
Cell cell = row.getCell(cellNum);
String value = getCellValue(cell);
if(cellNum == 1 ){
systemName = getCellValue(cell);
systemNode.setName(systemName);
}else if(cellNum ==2 ){
nodeAttribute.put("内部",getCellValue(cell));
systemNode.getNodeAttributeMap().put("内外部系统",getCellValue(cell));
}else if(cellNum ==3 ){
systemNode.getNodeAttributeMap().put("行",getCellValue(cell));
}else if(cellNum ==4 ){
systemNode.getNodeAttributeMap().put("列",getCellValue(cell));;
}
}
systemNodeList.add(systemNode);
} }
}else if("关系".equals(sheet.getSheetName())){ // 获得当前行的开始列
// 获得当前sheet的开始行 int firstCellNum = row.getFirstCellNum();
int firstRowNum = sheet.getFirstRowNum(); // 获得当前行的列数
// 获得当前sheet的结束行 int lastCellNum = row.getLastCellNum();
int lastRowNum = sheet.getLastRowNum(); String[] cells = new String[row.getLastCellNum()];
// 循环除第一行外的所有行 // 循环当前行
for (int rowNum = firstRowNum + 1; rowNum <= lastRowNum; rowNum++) { Map<String,String> nodeAttribute = new HashMap<>();
// 获得当前行 String systemName = "";
Row row = sheet.getRow(rowNum); SystemNode systemNode = new SystemNode();
if (row == null) { for (int cellNum = firstCellNum; cellNum < lastCellNum; cellNum++) {
continue; Cell cell = row.getCell(cellNum);
String value = getCellValue(cell);
if(cellNum == 1 ){
systemName = getCellValue(cell);
systemNode.setName(systemName);
}else if(cellNum ==2 ){
nodeAttribute.put("内部",getCellValue(cell));
systemNode.getNodeAttributeMap().put("内外部系统",getCellValue(cell));
}else if(cellNum ==3 ){
systemNode.getNodeAttributeMap().put("行",getCellValue(cell));
}else if(cellNum ==4 ){
systemNode.getNodeAttributeMap().put("列",getCellValue(cell));;
} }
// 获得当前行的开始列
int firstCellNum = row.getFirstCellNum();
// 获得当前行的列数
int lastCellNum = row.getLastCellNum();
String[] cells = new String[row.getLastCellNum()];
// 循环当前行
SystemRelation systemRelation = new SystemRelation();
String fromId = getCellValue(row.getCell(1));
String toId = getCellValue(row.getCell(2));
systemRelation.setFrom(fromId);
systemRelation.setTo(toId);
systemRelation.getAttributeMap().put("形式",getCellValue(row.getCell(3)));
systemRelation.getAttributeMap().put("协议",getCellValue(row.getCell(4)));
systemRelation.getAttributeMap().put("业务类别",getCellValue(row.getCell(5)));
systemRelation.getAttributeMap().put("数据结构",getCellValue(row.getCell(6)));
systemRelation.getAttributeMap().put("业务说明",getCellValue(row.getCell(7)));
systemRelationList.add(systemRelation);
} }
systemNodeList.add(systemNode);
} }
} }
}
Sheet guanxiSHeet = workbook.getSheet("关系");
{
// 获得当前sheet的开始行
int firstRowNum = guanxiSHeet.getFirstRowNum();
// 获得当前sheet的结束行
int lastRowNum = guanxiSHeet.getLastRowNum();
// 循环除第一行外的所有行
for (int rowNum = firstRowNum + 1; rowNum <= lastRowNum; rowNum++) {
// 获得当前行
Row row = guanxiSHeet.getRow(rowNum);
if (row == null) {
continue;
}
// 获得当前行的开始列
int firstCellNum = row.getFirstCellNum();
// 获得当前行的列数
int lastCellNum = row.getLastCellNum();
String[] cells = new String[row.getLastCellNum()];
// 循环当前行
SystemRelation systemRelation = new SystemRelation();
String fromId = getCellValue(row.getCell(1));
String toId = getCellValue(row.getCell(2));
systemRelation.setFrom(fromId);
systemRelation.setTo(toId);
String xingshi = getCellValue(row.getCell(3));
systemRelation.getAttributeMap().put("形式",xingshi);
String color = colorMap.get(xingshi);
systemRelation.getAttributeMap().put("颜色",color);
systemRelation.getAttributeMap().put("协议",getCellValue(row.getCell(4)));
systemRelation.getAttributeMap().put("业务类别",getCellValue(row.getCell(5)));
systemRelation.getAttributeMap().put("数据结构",getCellValue(row.getCell(6)));
systemRelation.getAttributeMap().put("业务说明",getCellValue(row.getCell(7)));
systemRelationList.add(systemRelation);
}
}
}
}catch (Exception e){ }catch (Exception e){
e.printStackTrace(); e.printStackTrace();
} }
...@@ -172,6 +197,7 @@ public class Excel2Neo4jServiceImpl implements Excel2Neo4jService { ...@@ -172,6 +197,7 @@ public class Excel2Neo4jServiceImpl implements Excel2Neo4jService {
String fromId = relation.getFrom(); String fromId = relation.getFrom();
String toId = relation.getTo(); String toId = relation.getTo();
String type = relation.getAttributeMap().get("形式"); String type = relation.getAttributeMap().get("形式");
String yanse = relation.getAttributeMap().get("颜色");
String xieyi = relation.getAttributeMap().get("协议"); String xieyi = relation.getAttributeMap().get("协议");
String zubie = relation.getAttributeMap().get("业务类别"); String zubie = relation.getAttributeMap().get("业务类别");
String shujujiegou = relation.getAttributeMap().get("数据结构"); String shujujiegou = relation.getAttributeMap().get("数据结构");
...@@ -179,7 +205,7 @@ public class Excel2Neo4jServiceImpl implements Excel2Neo4jService { ...@@ -179,7 +205,7 @@ public class Excel2Neo4jServiceImpl implements Excel2Neo4jService {
String addRelationCypher = " match( a:softplatform {name:\"" + fromId + "\"} ),(b:softplatform {name:\"" + toId + "\"} ) " + String addRelationCypher = " match( a:softplatform {name:\"" + fromId + "\"} ),(b:softplatform {name:\"" + toId + "\"} ) " +
" merge (a)-[r:"+type+"]-> (b) " + " merge (a)-[r:"+type+"]-> (b) " +
"set r.协议=\""+ xieyi + "\" ,r.业务类别 = \""+zubie+"\" ,r.数据结构= \""+shujujiegou+"\",r.业务说明= \""+yewushuoming+"\" " + "set r.协议=\""+ xieyi + "\" , r.颜色=\""+ yanse +"\" , r.业务类别 = \""+zubie+"\" ,r.数据结构= \""+shujujiegou+"\",r.业务说明= \""+yewushuoming+"\" " +
" return r "; " return r ";
neo4jSession.run(addRelationCypher); neo4jSession.run(addRelationCypher);
} }
......
...@@ -564,7 +564,6 @@ public class MetadataServiceImpl implements IMetadataService { ...@@ -564,7 +564,6 @@ public class MetadataServiceImpl implements IMetadataService {
Map<String ,ReturnEdge> returnEdgeMap = new HashMap<>(); Map<String ,ReturnEdge> returnEdgeMap = new HashMap<>();
int size = 300;
while (statementResult.hasNext()) { while (statementResult.hasNext()) {
Record record = statementResult.next(); Record record = statementResult.next();
List<Value> values = record.values(); List<Value> values = record.values();
...@@ -606,6 +605,7 @@ public class MetadataServiceImpl implements IMetadataService { ...@@ -606,6 +605,7 @@ public class MetadataServiceImpl implements IMetadataService {
// relationship.id(); // relationship.id();
// //
String xieyi =""+ relationship.asMap().get("协议"); String xieyi =""+ relationship.asMap().get("协议");
String yanse =""+ relationship.asMap().get("颜色");
String yewuleibie =""+ relationship.asMap().get("业务类别"); String yewuleibie =""+ relationship.asMap().get("业务类别");
String shujujiegou =""+ relationship.asMap().get("数据结构"); String shujujiegou =""+ relationship.asMap().get("数据结构");
String yewushuoming =""+ relationship.asMap().get("业务说明"); String yewushuoming =""+ relationship.asMap().get("业务说明");
...@@ -630,6 +630,7 @@ public class MetadataServiceImpl implements IMetadataService { ...@@ -630,6 +630,7 @@ public class MetadataServiceImpl implements IMetadataService {
edge.getAttributeMaps().put("业务类别",yewuleibie); edge.getAttributeMaps().put("业务类别",yewuleibie);
edge.getAttributeMaps().put("数据结构",shujujiegou); edge.getAttributeMaps().put("数据结构",shujujiegou);
edge.getAttributeMaps().put("业务说明",yewushuoming); edge.getAttributeMaps().put("业务说明",yewushuoming);
edge.getAttributeMaps().put("颜色",yanse);
returnEdgeMap .put(edgeId,edge ); returnEdgeMap .put(edgeId,edge );
} }
...@@ -1384,6 +1385,9 @@ public class MetadataServiceImpl implements IMetadataService { ...@@ -1384,6 +1385,9 @@ public class MetadataServiceImpl implements IMetadataService {
while (tableCursor.hasNext()) { while (tableCursor.hasNext()) {
Document tableDocument = tableCursor.next(); Document tableDocument = tableCursor.next();
String tableId =(String) tableDocument.get("_id"); String tableId =(String) tableDocument.get("_id");
if("Table=1=0c0553306fd24e34897a172338ccb38f".equals(tableId)){
System.out.println("Table=1=4e048d23a0c0477e9f67792b34e51df7");
}
//存在了,就不写入 //存在了,就不写入
if(tableIdMapFromNeo4j.containsKey(tableId)){ if(tableIdMapFromNeo4j.containsKey(tableId)){
tableIdMapFromNeo4j.remove(tableId); tableIdMapFromNeo4j.remove(tableId);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment