Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
neo4jRelation
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
qiuchaofei
neo4jRelation
Commits
e60aa06f
Commit
e60aa06f
authored
Jun 23, 2022
by
qiuchaofei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1,添加上传文件,2对关系进行排序
parent
1ff1be19
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
97 additions
and
40 deletions
+97
-40
MetadataRelationApplication.java
...etadata/metadataRelation/MetadataRelationApplication.java
+13
-0
DataRelationAnalyController.java
...adataRelation/controller/DataRelationAnalyController.java
+13
-0
Excel2Neo4jService.java
...metadata/metadataRelation/service/Excel2Neo4jService.java
+5
-0
Excel2Neo4jServiceImpl.java
...metadataRelation/service/impl/Excel2Neo4jServiceImpl.java
+63
-37
MetadataServiceImpl.java
...ta/metadataRelation/service/impl/MetadataServiceImpl.java
+3
-3
No files found.
src/main/java/com/keymobile/metadata/metadataRelation/MetadataRelationApplication.java
View file @
e60aa06f
...
@@ -5,7 +5,10 @@ import com.ulisesbocchio.jasyptspringboot.environment.StandardEncryptableEnviron
...
@@ -5,7 +5,10 @@ import com.ulisesbocchio.jasyptspringboot.environment.StandardEncryptableEnviron
import
org.jasypt.encryption.StringEncryptor
;
import
org.jasypt.encryption.StringEncryptor
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer
;
import
org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
@EnableScheduling
@EnableScheduling
...
@@ -32,5 +35,15 @@ public class MetadataRelationApplication {
...
@@ -32,5 +35,15 @@ public class MetadataRelationApplication {
}
}
};
};
}
}
@Bean
public
TomcatServletWebServerFactory
tomcatServletWebServerFactory
(){
// 修改内置的 tomcat 容器配置
TomcatServletWebServerFactory
tomcatServlet
=
new
TomcatServletWebServerFactory
();
tomcatServlet
.
addConnectorCustomizers
(
(
TomcatConnectorCustomizer
)
connector
->
connector
.
setProperty
(
"relaxedQueryChars"
,
"[]{}"
)
);
return
tomcatServlet
;
}
}
}
src/main/java/com/keymobile/metadata/metadataRelation/controller/DataRelationAnalyController.java
View file @
e60aa06f
...
@@ -10,7 +10,9 @@ import org.slf4j.LoggerFactory;
...
@@ -10,7 +10,9 @@ import org.slf4j.LoggerFactory;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
...
@@ -149,4 +151,15 @@ public class DataRelationAnalyController {
...
@@ -149,4 +151,15 @@ public class DataRelationAnalyController {
return
""
;
return
""
;
}
}
//解析excel,存入neo4j
@ApiOperation
(
tags
=
""
,
value
=
"从excel生成neo4j的节点与关系。"
)
@RequestMapping
(
path
=
"/uploadExcelToNeo4j"
,
method
=
RequestMethod
.
POST
)
public
String
uploadExcelToNeo4j
(
@RequestParam
(
value
=
"excelFile"
)
MultipartFile
file
)
{
logger
.
info
(
"上传excel文件节点与关系:"
+
file
.
getOriginalFilename
()
);
excel2Neo4jService
.
uploadExcel
(
file
)
;
logger
.
info
(
"上传excel文件节点与关系完成。"
);
return
""
;
}
}
}
src/main/java/com/keymobile/metadata/metadataRelation/service/Excel2Neo4jService.java
View file @
e60aa06f
package
com
.
keymobile
.
metadata
.
metadataRelation
.
service
;
package
com
.
keymobile
.
metadata
.
metadataRelation
.
service
;
import
org.springframework.web.multipart.MultipartFile
;
public
interface
Excel2Neo4jService
{
public
interface
Excel2Neo4jService
{
String
generalRelationFromExcel
(
String
filePath
);
String
generalRelationFromExcel
(
String
filePath
);
// fileName, file
String
uploadExcel
(
MultipartFile
file
)
;
}
}
src/main/java/com/keymobile/metadata/metadataRelation/service/impl/Excel2Neo4jServiceImpl.java
View file @
e60aa06f
...
@@ -13,11 +13,9 @@ import org.neo4j.driver.v1.Session;
...
@@ -13,11 +13,9 @@ import org.neo4j.driver.v1.Session;
import
org.neo4j.driver.v1.StatementResult
;
import
org.neo4j.driver.v1.StatementResult
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.File
;
import
java.io.*
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
...
@@ -31,8 +29,27 @@ public class Excel2Neo4jServiceImpl implements Excel2Neo4jService {
...
@@ -31,8 +29,27 @@ public class Excel2Neo4jServiceImpl implements Excel2Neo4jService {
private
Session
neo4jSession
;
private
Session
neo4jSession
;
@Override
@Override
public
String
generalRelationFromExcel
(
String
filePath
)
{
public
String
uploadExcel
(
MultipartFile
file
)
{
File
file
=
new
File
(
filePath
);
String
fileName
=
file
.
getOriginalFilename
();
try
{
InputStream
inputStream
=
file
.
getInputStream
();
Workbook
workbook
;
if
(
fileName
.
matches
(
"^.+\\.(?i)(xlsx)$"
))
{
workbook
=
new
XSSFWorkbook
(
inputStream
);
}
else
{
workbook
=
new
HSSFWorkbook
(
inputStream
);
}
generalRelationFromWorkBook
(
workbook
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
return
"failed"
;
}
return
"OK"
;
}
private
String
generalRelationFromWorkBook
(
Workbook
workbook
){
//先删除数据
//先删除数据
String
deleteCypher
=
"MATCH (n:softplatform) detach delete n"
;
String
deleteCypher
=
"MATCH (n:softplatform) detach delete n"
;
...
@@ -40,26 +57,8 @@ public class Excel2Neo4jServiceImpl implements Excel2Neo4jService {
...
@@ -40,26 +57,8 @@ public class Excel2Neo4jServiceImpl implements Excel2Neo4jService {
List
<
SystemNode
>
systemNodeList
=
new
ArrayList
<>();
List
<
SystemNode
>
systemNodeList
=
new
ArrayList
<>();
List
<
SystemRelation
>
systemRelationList
=
new
ArrayList
<>();
List
<
SystemRelation
>
systemRelationList
=
new
ArrayList
<>();
FileInputStream
is
=
null
;
Workbook
workbook
=
null
;
try
{
String
fileName
=
file
.
getName
();
// 创建Workbook工作薄对象,表示整个excel
// 获取excel文件的io流
is
=
new
FileInputStream
(
file
);
// 根据文件后缀名不同(xls和xlsx)获得不同的Workbook实现类对象
if
(
fileName
.
endsWith
(
".xlsx"
))
{
// 2007 及2007以上
workbook
=
new
XSSFWorkbook
(
is
);
}
Map
<
String
,
String
>
colorMap
=
new
HashMap
<>();
Map
<
String
,
String
>
colorMap
=
new
HashMap
<>();
// 第一个sheet是 node,先解析入neo4j。
// 第二个sheet 是 关系,
if
(
workbook
!=
null
)
{
Sheet
yanseSHeet
=
workbook
.
getSheet
(
"形式颜色"
);
Sheet
yanseSHeet
=
workbook
.
getSheet
(
"形式颜色"
);
{
{
int
firstRowNum
=
yanseSHeet
.
getFirstRowNum
();
int
firstRowNum
=
yanseSHeet
.
getFirstRowNum
();
...
@@ -145,6 +144,8 @@ public class Excel2Neo4jServiceImpl implements Excel2Neo4jService {
...
@@ -145,6 +144,8 @@ public class Excel2Neo4jServiceImpl implements Excel2Neo4jService {
String
[]
cells
=
new
String
[
row
.
getLastCellNum
()];
String
[]
cells
=
new
String
[
row
.
getLastCellNum
()];
// 循环当前行
// 循环当前行
SystemRelation
systemRelation
=
new
SystemRelation
();
SystemRelation
systemRelation
=
new
SystemRelation
();
String
xuhao
=
getCellValue
(
row
.
getCell
(
0
));
String
fromId
=
getCellValue
(
row
.
getCell
(
1
));
String
fromId
=
getCellValue
(
row
.
getCell
(
1
));
String
toId
=
getCellValue
(
row
.
getCell
(
2
));
String
toId
=
getCellValue
(
row
.
getCell
(
2
));
...
@@ -155,6 +156,7 @@ public class Excel2Neo4jServiceImpl implements Excel2Neo4jService {
...
@@ -155,6 +156,7 @@ public class Excel2Neo4jServiceImpl implements Excel2Neo4jService {
String
color
=
colorMap
.
get
(
xingshi
);
String
color
=
colorMap
.
get
(
xingshi
);
systemRelation
.
getAttributeMap
().
put
(
"颜色"
,
color
);
systemRelation
.
getAttributeMap
().
put
(
"颜色"
,
color
);
systemRelation
.
getAttributeMap
().
put
(
"序号"
,
xuhao
);
systemRelation
.
getAttributeMap
().
put
(
"协议"
,
getCellValue
(
row
.
getCell
(
4
)));
systemRelation
.
getAttributeMap
().
put
(
"协议"
,
getCellValue
(
row
.
getCell
(
4
)));
systemRelation
.
getAttributeMap
().
put
(
"业务类别"
,
getCellValue
(
row
.
getCell
(
5
)));
systemRelation
.
getAttributeMap
().
put
(
"业务类别"
,
getCellValue
(
row
.
getCell
(
5
)));
...
@@ -163,17 +165,6 @@ public class Excel2Neo4jServiceImpl implements Excel2Neo4jService {
...
@@ -163,17 +165,6 @@ public class Excel2Neo4jServiceImpl implements Excel2Neo4jService {
systemRelationList
.
add
(
systemRelation
);
systemRelationList
.
add
(
systemRelation
);
}
}
}
}
}
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
finally
{
try
{
is
.
close
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
toString
());
}
}
for
(
SystemNode
systemNode:
systemNodeList
){
for
(
SystemNode
systemNode:
systemNodeList
){
String
hang
=
systemNode
.
getNodeAttributeMap
().
get
(
"行"
);
String
hang
=
systemNode
.
getNodeAttributeMap
().
get
(
"行"
);
...
@@ -196,6 +187,7 @@ public class Excel2Neo4jServiceImpl implements Excel2Neo4jService {
...
@@ -196,6 +187,7 @@ public class Excel2Neo4jServiceImpl implements Excel2Neo4jService {
String
fromId
=
relation
.
getFrom
();
String
fromId
=
relation
.
getFrom
();
String
toId
=
relation
.
getTo
();
String
toId
=
relation
.
getTo
();
String
xuhao
=
relation
.
getAttributeMap
().
get
(
"序号"
);
String
type
=
relation
.
getAttributeMap
().
get
(
"形式"
);
String
type
=
relation
.
getAttributeMap
().
get
(
"形式"
);
String
yanse
=
relation
.
getAttributeMap
().
get
(
"颜色"
);
String
yanse
=
relation
.
getAttributeMap
().
get
(
"颜色"
);
String
xieyi
=
relation
.
getAttributeMap
().
get
(
"协议"
);
String
xieyi
=
relation
.
getAttributeMap
().
get
(
"协议"
);
...
@@ -205,14 +197,48 @@ public class Excel2Neo4jServiceImpl implements Excel2Neo4jService {
...
@@ -205,14 +197,48 @@ 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.颜色=\""
+
yanse
+
"\" , r.业务类别 = \""
+
zubie
+
"\" ,r.数据结构= \""
+
shujujiegou
+
"\",r.业务说明= \""
+
yewushuoming
+
"\" "
+
"set r.协议=\""
+
xieyi
+
"\" ,
r.序号= \""
+
xuhao
+
"\" ,
r.颜色=\""
+
yanse
+
"\" , r.业务类别 = \""
+
zubie
+
"\" ,r.数据结构= \""
+
shujujiegou
+
"\",r.业务说明= \""
+
yewushuoming
+
"\" "
+
" return r "
;
" return r "
;
neo4jSession
.
run
(
addRelationCypher
);
neo4jSession
.
run
(
addRelationCypher
);
}
}
return
""
;
return
""
;
}
}
@Override
public
String
generalRelationFromExcel
(
String
filePath
)
{
File
file
=
new
File
(
filePath
);
FileInputStream
is
=
null
;
Workbook
workbook
=
null
;
try
{
String
fileName
=
file
.
getName
();
// 创建Workbook工作薄对象,表示整个excel
// 获取excel文件的io流
is
=
new
FileInputStream
(
file
);
// 根据文件后缀名不同(xls和xlsx)获得不同的Workbook实现类对象
if
(
fileName
.
endsWith
(
".xlsx"
))
{
// 2007 及2007以上
workbook
=
new
XSSFWorkbook
(
is
);
}
generalRelationFromWorkBook
(
workbook
);
}
catch
(
Exception
e
){
e
.
printStackTrace
();
return
"failed"
;
}
finally
{
try
{
is
.
close
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
e
.
toString
());
}
}
return
"OK"
;
}
public
static
String
getCellValue
(
Cell
cell
)
{
public
static
String
getCellValue
(
Cell
cell
)
{
String
cellValue
=
""
;
String
cellValue
=
""
;
if
(
cell
==
null
)
{
if
(
cell
==
null
)
{
...
...
src/main/java/com/keymobile/metadata/metadataRelation/service/impl/MetadataServiceImpl.java
View file @
e60aa06f
...
@@ -563,7 +563,7 @@ public class MetadataServiceImpl implements IMetadataService {
...
@@ -563,7 +563,7 @@ public class MetadataServiceImpl implements IMetadataService {
Map
<
Long
,
ReturnNode
>
nodesMap
=
new
HashMap
<>();
Map
<
Long
,
ReturnNode
>
nodesMap
=
new
HashMap
<>();
Map
<
String
,
MetaModel
>
metaModelMap
=
new
HashMap
<>();
Map
<
String
,
MetaModel
>
metaModelMap
=
new
HashMap
<>();
Map
<
String
,
ReturnEdge
>
returnEdgeMap
=
new
Hash
Map
<>();
Map
<
String
,
ReturnEdge
>
returnEdgeMap
=
new
Tree
Map
<>();
Map
<
String
,
String
>
colorMap
=
new
HashMap
<>();
Map
<
String
,
String
>
colorMap
=
new
HashMap
<>();
while
(
statementResult
.
hasNext
())
{
while
(
statementResult
.
hasNext
())
{
...
@@ -606,7 +606,7 @@ public class MetadataServiceImpl implements IMetadataService {
...
@@ -606,7 +606,7 @@ public class MetadataServiceImpl implements IMetadataService {
* asMap 相当于 节点的properties属性信息
* asMap 相当于 节点的properties属性信息
*/
*/
// relationship.id();
// relationship.id();
//
String
xuhao
=
""
+
relationship
.
asMap
().
get
(
"序号"
);
String
xieyi
=
""
+
relationship
.
asMap
().
get
(
"协议"
);
String
xieyi
=
""
+
relationship
.
asMap
().
get
(
"协议"
);
String
yanse
=
""
+
relationship
.
asMap
().
get
(
"颜色"
);
String
yanse
=
""
+
relationship
.
asMap
().
get
(
"颜色"
);
String
yewuleibie
=
""
+
relationship
.
asMap
().
get
(
"业务类别"
);
String
yewuleibie
=
""
+
relationship
.
asMap
().
get
(
"业务类别"
);
...
@@ -636,7 +636,7 @@ public class MetadataServiceImpl implements IMetadataService {
...
@@ -636,7 +636,7 @@ public class MetadataServiceImpl implements IMetadataService {
edge
.
getAttributeMaps
().
put
(
"业务说明"
,
yewushuoming
);
edge
.
getAttributeMaps
().
put
(
"业务说明"
,
yewushuoming
);
//
//
returnEdgeMap
.
put
(
edgeId
,
edge
);
returnEdgeMap
.
put
(
xuhao
,
edge
);
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment