init:初始化最原始代码
This commit is contained in:
commit
6fba583b62
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
*.js linguist-language=java *.css linguist-language=java *.html linguist-language=java
|
||||||
27
.gitignore
vendored
Normal file
27
.gitignore
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
*/target/**
|
||||||
|
!kgmaker/.mvn/wrapper/maven-wrapper.jar
|
||||||
|
.mvn/
|
||||||
|
|
||||||
|
### STS ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea
|
||||||
|
.mvn
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.class
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/build/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
/kgBuilder-ui/.history/
|
||||||
64
README.md
Normal file
64
README.md
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
## 初衷
|
||||||
|
这是一个知识图谱构建工具,最开始是对产品和领导为了做ppt临时要求配合做图谱展示的不厌其烦,做着做着就抽出一个目前看着还算通用的小工具,知识图谱可视化,仅供做知识图谱的小伙伴参考
|
||||||
|
## 技术栈
|
||||||
|
小工具是前台是基于vue + d3.js ,后台是springboot配合Neo4j.
|
||||||
|
## 演示
|
||||||
|
demo地址:[http://kg.miaoleyan.com](http://kg.miaoleyan.com)
|
||||||
|
|
||||||
|
## 实现的基本功能:
|
||||||
|
1. 新增节点,添加连线,快速添加节点和关系
|
||||||
|
2. 节点的颜色和大小可修改
|
||||||
|
3. 节点和关系的编辑,删除
|
||||||
|
4. 导出成图片
|
||||||
|
5. csv导入
|
||||||
|
6. 导出csv
|
||||||
|
7. 添加图片和富文本
|
||||||
|
8. 节点之间多个关系
|
||||||
|
|
||||||
|
## 后续优化:
|
||||||
|
1. 接入数据源
|
||||||
|
2. 构建er图
|
||||||
|
3. 根据er图生成图谱
|
||||||
|
|
||||||
|
## 运行与启动
|
||||||
|
### 安装jdk
|
||||||
|
可参考:[https://blog.csdn.net/qq_42003566/article/details/82629570](https://blog.csdn.net/qq_42003566/article/details/82629570)
|
||||||
|
### 安装Neo4j
|
||||||
|
可参考:[https://www.cnblogs.com/ljhdo/p/5521577.html](https://www.cnblogs.com/ljhdo/p/5521577.html),注意开放外网访问 0.0.0.0
|
||||||
|
### IDEA 导入项目
|
||||||
|
导入成功后对着项目根目录,右键->maven->reimport,等待其执行完成,倘若下载jar包太慢,自己配置外部maven仓库[https://blog.csdn.net/liu_shi_jun/article/details/78733633](https://blog.csdn.net/liu_shi_jun/article/details/78733633)
|
||||||
|
以上配置在linux下配置自行百度
|
||||||
|
### 找到目录 src/main/resources
|
||||||
|
修改application.yml,neo4配置url,password,改成自己的,同理修改mysql(mysql脚本在根目录下,knowledgegraph.sql)
|
||||||
|
### 打包发布
|
||||||
|
在idea 右侧 有 maven project 工具栏,点击展开lifecycle-clean,然后install,等待完成后在控制台可以看见打包的目录,
|
||||||
|
例如:[INFO] Installing F:\git\Neo4j\kgmaker\target\kgmaker-0.0.1-SNAPSHOT.jar 复制jar包,
|
||||||
|
去windows 或者linux下
|
||||||
|
切换到jar包目录执行jar包
|
||||||
|
```
|
||||||
|
java -jar xxx.jar //即可启动
|
||||||
|
```
|
||||||
|
想部署到tomcat自行百度,springboot配置外部tomcat
|
||||||
|
### 安装nodejs
|
||||||
|
可参考[https://blog.csdn.net/qq_46351233/article/details/120314928](https://blog.csdn.net/qq_46351233/article/details/120314928)
|
||||||
|
启动前端
|
||||||
|
```
|
||||||
|
1.npm install // 安装依赖
|
||||||
|
2.npm run serve //启动
|
||||||
|
3.npm run build //发布
|
||||||
|
启动后访问http://localhost
|
||||||
|
```
|
||||||
|
|
||||||
|
### 访问路径
|
||||||
|
启动后访问[http://localhost](http://localhost)
|
||||||
|
### 启动视频教程
|
||||||
|
[https://www.bilibili.com/video/BV1Ki4y1D7Nj?share_source=copy_web](https://www.bilibili.com/video/BV1Ki4y1D7Nj?share_source=copy_web)
|
||||||
|
### 图谱三元组导入
|
||||||
|
支持,.xlsx,.xls,.csv,编码格式一定要是utf-8 无bom格式的,格式:节点-节点-关系,在本地测试时上传下载的文件要和neo4j在同一台电脑,当然如果能传到七牛或者hdfs上也是一样的,必须确认neo4j能访问到,否则load不成功
|
||||||
|
### 推荐前端组件
|
||||||
|
G6 [https://g6.antv.vision/zh/examples/gallery](https://g6.antv.vision/zh/examples/gallery)
|
||||||
|
### 推荐图数据库
|
||||||
|
Nebula [https://docs.nebula-graph.com.cn/2.5.1/](https://docs.nebula-graph.com.cn/2.5.1/)
|
||||||
|
## 交流
|
||||||
|

|
||||||
|

|
||||||
84
kgBuilder-base/pom.xml
Normal file
84
kgBuilder-base/pom.xml
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.warmer</groupId>
|
||||||
|
<artifactId>kgbuilder</artifactId>
|
||||||
|
<version>0.0.1</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<groupId>com.warmer</groupId>
|
||||||
|
<artifactId>kgBuilder-base</artifactId>
|
||||||
|
<version>0.0.1</version>
|
||||||
|
<name>kgBuilder-base</name>
|
||||||
|
<description>Demo project for Spring Boot</description>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
<version>${commons-lang3.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>${lombok.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>${mysql.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mybatis.spring.boot</groupId>
|
||||||
|
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||||
|
<version>${mybatis.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.neo4j.driver</groupId>
|
||||||
|
<artifactId>neo4j-java-driver</artifactId>
|
||||||
|
<version>${neo4j.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.pagehelper</groupId>
|
||||||
|
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||||
|
<version>${pagehelper.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-core</artifactId>
|
||||||
|
<version>${fasterxml.jackson.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
<version>${fasterxml.jackson.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-core</artifactId>
|
||||||
|
<version>${hutool.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.poi</groupId>
|
||||||
|
<artifactId>poi</artifactId>
|
||||||
|
<version>5.2.3</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.poi</groupId>
|
||||||
|
<artifactId>poi-ooxml</artifactId>
|
||||||
|
<version>5.2.3</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
@ -0,0 +1,89 @@
|
|||||||
|
package com.warmer.base.common;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class BaseEntity {
|
||||||
|
public BaseEntity() {
|
||||||
|
createUser = "tan";
|
||||||
|
updateUser = createUser;
|
||||||
|
createTime = new Date();
|
||||||
|
updateTime = createTime;
|
||||||
|
status = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 记录状态
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
/**
|
||||||
|
* 创建用户
|
||||||
|
*/
|
||||||
|
private String createUser;
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private Date createTime;
|
||||||
|
/**
|
||||||
|
* 修改用户
|
||||||
|
*/
|
||||||
|
private String updateUser;
|
||||||
|
/**
|
||||||
|
* 修改时间
|
||||||
|
*/
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public Integer getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
public void setStatus(Integer status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public String getCreateUser() {
|
||||||
|
return createUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
public void setCreateUser(String createUser) {
|
||||||
|
this.createUser = createUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public Date getCreateTime() {
|
||||||
|
return createTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
public void setCreateTime(Date createTime) {
|
||||||
|
this.createTime = createTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public String getUpdateUser() {
|
||||||
|
return updateUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
public void setUpdateUser(String updateUser) {
|
||||||
|
this.updateUser = updateUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
public Date getUpdateTime() {
|
||||||
|
return updateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
public void setUpdateTime(Date updateTime) {
|
||||||
|
this.updateTime = updateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,37 @@
|
|||||||
|
package com.warmer.base.common;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tc
|
||||||
|
* 组合列之间过滤条件
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@ToString
|
||||||
|
public class FieldQueryItem implements Serializable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多个条件拼接 符号,or | and
|
||||||
|
*/
|
||||||
|
private String joinOperate;
|
||||||
|
/**
|
||||||
|
* 字段和值之间的关系,0 模糊匹配% 还是 1 精确匹配=, -1=值类型,比较
|
||||||
|
*/
|
||||||
|
private Integer condition;
|
||||||
|
/**
|
||||||
|
* 操作符 > | >=| = | < |<=
|
||||||
|
*/
|
||||||
|
private String operate;
|
||||||
|
/**
|
||||||
|
* 数据库字段
|
||||||
|
*/
|
||||||
|
private String field;
|
||||||
|
/**
|
||||||
|
* 检索文本
|
||||||
|
*/
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,22 @@
|
|||||||
|
package com.warmer.base.common;
|
||||||
|
|
||||||
|
public class PageQuery {
|
||||||
|
private int currentPage=1;
|
||||||
|
private int pageSize=10;
|
||||||
|
|
||||||
|
public int getCurrentPage() {
|
||||||
|
return currentPage;
|
||||||
|
}
|
||||||
|
public void setCurrentPage(int currentPage) {
|
||||||
|
if(currentPage==0){
|
||||||
|
currentPage=1;
|
||||||
|
}
|
||||||
|
this.currentPage = currentPage;
|
||||||
|
}
|
||||||
|
public int getPageSize() {
|
||||||
|
return pageSize;
|
||||||
|
}
|
||||||
|
public void setPageSize(int pageSize) {
|
||||||
|
this.pageSize = pageSize;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,81 @@
|
|||||||
|
package com.warmer.base.common;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页的JavaBean
|
||||||
|
* @author tanc
|
||||||
|
*/
|
||||||
|
public class PageRecord<T> {
|
||||||
|
|
||||||
|
// 当前页,手动添加的默认值是1
|
||||||
|
private int pageIndex = 1;
|
||||||
|
|
||||||
|
// 总页数
|
||||||
|
// private int totalPage;
|
||||||
|
|
||||||
|
// 总记录数
|
||||||
|
private int totalCount;
|
||||||
|
|
||||||
|
// 每页显示的记录条数,每页显示5条
|
||||||
|
private int pageSize = 5;
|
||||||
|
|
||||||
|
// 每页显示的数据
|
||||||
|
private List<T> data;
|
||||||
|
|
||||||
|
public Object getHeads() {
|
||||||
|
return heads;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHeads(Object heads) {
|
||||||
|
this.heads = heads;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object heads;
|
||||||
|
|
||||||
|
public int getPageIndex() {
|
||||||
|
return pageIndex;
|
||||||
|
}
|
||||||
|
public void setPageIndex(int pageIndex) {
|
||||||
|
this.pageIndex = pageIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调用getTotalPage() 获取到总页数
|
||||||
|
* JavaBean的属性规定:totalPage是JavaBean是属性 ${pageBean.totalPage}
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getTotalPage() {
|
||||||
|
// 计算
|
||||||
|
int totalPage = totalCount / pageSize;
|
||||||
|
// 说明整除
|
||||||
|
if(totalCount % pageSize == 0){
|
||||||
|
return totalPage;
|
||||||
|
}else{
|
||||||
|
return totalPage + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*public void setTotalPage(int totalPage) {
|
||||||
|
this.totalPage = totalPage;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
public int getTotalCount() {
|
||||||
|
return totalCount;
|
||||||
|
}
|
||||||
|
public void setTotalCount(int totalCount) {
|
||||||
|
this.totalCount = totalCount;
|
||||||
|
}
|
||||||
|
public int getPageSize() {
|
||||||
|
return pageSize;
|
||||||
|
}
|
||||||
|
public void setPageSize(int pageSize) {
|
||||||
|
this.pageSize = pageSize;
|
||||||
|
}
|
||||||
|
public List<T> getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
public void setData(List<T> data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,70 @@
|
|||||||
|
package com.warmer.base.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public enum ReturnStatus {
|
||||||
|
Success("操作成功", 200),
|
||||||
|
OPERAFAIL("操作失败", 201),
|
||||||
|
DISTINCT("存在重复数据", 202),
|
||||||
|
FILENOTFIND("文件找不到", 203),
|
||||||
|
NoUser("用户不存在", 204),
|
||||||
|
ContentError("内容格式错误", 205),
|
||||||
|
RECORD_NOT_FOUND("记录不存在", 206),
|
||||||
|
ValidateFailure("参数验证错误", 400),
|
||||||
|
SessionTimeout("会话超时", 401),
|
||||||
|
LoginFailure("登录失败", 402),
|
||||||
|
NoRight("权限不足",403),
|
||||||
|
InvalidCSRF("无效的保护令牌",404),
|
||||||
|
NoIntentResult("意图识别没有结果",405),
|
||||||
|
MoreFieldIntentResult("意图命中多个字段",408),
|
||||||
|
RequestMissingBodyError("缺少请求体!",1004),
|
||||||
|
ParameterMissingError("确少必要请求参数!",1003),
|
||||||
|
ParameterError("请求参数有误!",1002),
|
||||||
|
NotFountResource("没有找到相关资源!",1001),
|
||||||
|
Error("服务器错误", 500);
|
||||||
|
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
private final Integer value;
|
||||||
|
|
||||||
|
private ReturnStatus(String name, Integer value) {
|
||||||
|
this.name = name;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return value.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ReturnStatus valueOf(int value) {
|
||||||
|
//手写的从int到enum的转换函数
|
||||||
|
switch (value) {
|
||||||
|
case 200:
|
||||||
|
return Success;
|
||||||
|
case 201:
|
||||||
|
return OPERAFAIL;
|
||||||
|
case 202:
|
||||||
|
return DISTINCT;
|
||||||
|
case 203:
|
||||||
|
return FILENOTFIND;
|
||||||
|
case 204:
|
||||||
|
return NoUser;
|
||||||
|
case 205:
|
||||||
|
return ContentError;
|
||||||
|
case 206:
|
||||||
|
return RECORD_NOT_FOUND;
|
||||||
|
case 401:
|
||||||
|
return SessionTimeout;
|
||||||
|
case 402:
|
||||||
|
return LoginFailure;
|
||||||
|
case 403:
|
||||||
|
return NoRight;
|
||||||
|
case 500:
|
||||||
|
return Error;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
package com.warmer.base.util;
|
||||||
|
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class BeanUtils {
|
||||||
|
|
||||||
|
public static <T> T trans(Object sourceObject, Class<T> clazz) throws IOException {
|
||||||
|
return JsonHelper.parseObject(JsonHelper.toJSONString(sourceObject), clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> List<T> trans(List list, Class<T> clazz) throws IOException {
|
||||||
|
ArrayList result = new ArrayList();
|
||||||
|
for (Object item : list) {
|
||||||
|
result.add(trans(item, clazz));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void copyProperties(Object source, Object target) {
|
||||||
|
org.springframework.beans.BeanUtils.copyProperties(source, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> PageInfo<T> transPage(PageInfo info, Class<T> clazz) throws IOException {
|
||||||
|
PageInfo<T> pageInfo = new PageInfo();
|
||||||
|
copyProperties(info, pageInfo);
|
||||||
|
List<T> trans = trans(info.getList(), clazz);
|
||||||
|
pageInfo.setList(trans);
|
||||||
|
return pageInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
package com.warmer.base.util;
|
||||||
|
|
||||||
|
|
||||||
|
public class ColorInfo {
|
||||||
|
/**
|
||||||
|
* 颜色的alpha值,此值控制了颜色的透明度
|
||||||
|
*/
|
||||||
|
public int A;
|
||||||
|
/**
|
||||||
|
* 颜色的红分量值,Red
|
||||||
|
*/
|
||||||
|
public int R;
|
||||||
|
/**
|
||||||
|
* 颜色的绿分量值,Green
|
||||||
|
*/
|
||||||
|
public int G;
|
||||||
|
/**
|
||||||
|
* 颜色的蓝分量值,Blue
|
||||||
|
*/
|
||||||
|
public int B;
|
||||||
|
|
||||||
|
public int toRGB() {
|
||||||
|
return this.R << 16 | this.G << 8 | this.B;
|
||||||
|
}
|
||||||
|
|
||||||
|
public java.awt.Color toAWTColor(){
|
||||||
|
return new java.awt.Color(this.R,this.G,this.B,this.A);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ColorInfo fromARGB(int red, int green, int blue) {
|
||||||
|
return new ColorInfo((int) 0xff, (int) red, (int) green, (int) blue);
|
||||||
|
}
|
||||||
|
public static ColorInfo fromARGB(int alpha, int red, int green, int blue) {
|
||||||
|
return new ColorInfo(alpha, red, green, blue);
|
||||||
|
}
|
||||||
|
public ColorInfo(int a,int r, int g , int b ) {
|
||||||
|
this.A = a;
|
||||||
|
this.B = b;
|
||||||
|
this.R = r;
|
||||||
|
this.G = g;
|
||||||
|
}
|
||||||
|
}
|
||||||
423
kgBuilder-base/src/main/java/com/warmer/base/util/DateUtil.java
Normal file
423
kgBuilder-base/src/main/java/com/warmer/base/util/DateUtil.java
Normal file
@ -0,0 +1,423 @@
|
|||||||
|
package com.warmer.base.util;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日期函数类,实现对日期的一些处理.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class DateUtil {
|
||||||
|
/**
|
||||||
|
* 构造器。
|
||||||
|
*/
|
||||||
|
public DateUtil() {
|
||||||
|
}
|
||||||
|
//
|
||||||
|
public static String getFormatDateTime() {
|
||||||
|
|
||||||
|
return formatChDate(DateUtil.getCurrentDate()) + " "
|
||||||
|
+ formatChTime(DateUtil.getCurrentTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getFormatDate() {
|
||||||
|
return formatDate(getCurrentDate());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回显示给用户的中文格式的日期。 将yyyymmdd格式变为yyyy年mm月dd日 格式
|
||||||
|
*/
|
||||||
|
public static String formatChDate(String date) {
|
||||||
|
try {
|
||||||
|
return date.substring(0, 4) + "年" + date.substring(4, 6) + "月"
|
||||||
|
+ date.substring(6, 8) + "日";
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 返回显示给用户的中文格式的日期。 将yyyy年mm月dd日格式变为yyyymmdd格式
|
||||||
|
*/
|
||||||
|
public static String formatEnDate(String date) {
|
||||||
|
try {
|
||||||
|
return date.substring(0, 4) + date.substring(5, 7)
|
||||||
|
+ date.substring(8, 10);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回显示给用户的中文格式的时间 即:将hhmm格式变为hh时mm分格式
|
||||||
|
*
|
||||||
|
* @param time
|
||||||
|
* 日间串hhmm格式
|
||||||
|
* @return hh时mm分
|
||||||
|
*/
|
||||||
|
public static String formatChTime(String time) {
|
||||||
|
return time.substring(0, 2) + "时" + time.substring(2, 4) + "分";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回显示给用户的中文格式的时间 即:将yyyymmdd hhmmss 格式为 yyyy年mm月dd日 hh时mm分ss秒 的格式
|
||||||
|
*
|
||||||
|
* @param dateTime
|
||||||
|
* 时间日期字符串
|
||||||
|
* @return yyyy年mm月dd日 hh时mm分ss秒
|
||||||
|
*/
|
||||||
|
public static String formatChDateTime(String dateTime) {
|
||||||
|
try {
|
||||||
|
return dateTime.substring(0, 4) + "年" + dateTime.substring(4, 6)
|
||||||
|
+ "月" + dateTime.substring(6, 8) + "日 "
|
||||||
|
+ dateTime.substring(9, 11) + "时"
|
||||||
|
+ dateTime.substring(11, 13) + "分"
|
||||||
|
+ dateTime.substring(13, 15) + "秒";
|
||||||
|
} catch (Exception e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回显示给用户的格式的日期 即:将yyyymmdd格式变为yyyy-mm-dd格式
|
||||||
|
*
|
||||||
|
* @param date 日期串 yyyymmdd格式
|
||||||
|
* @return yyyy-mm-dd格式
|
||||||
|
*/
|
||||||
|
public static String formatDate(String date) {
|
||||||
|
if(date==null || date.length()<8){
|
||||||
|
return "Error Date";
|
||||||
|
}
|
||||||
|
return date.substring(0, 4) + "-" + date.substring(4, 6) + "-"
|
||||||
|
+ date.substring(6, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回显示给用户的格式的日期 即:将mmdd格式变为mm-dd格式
|
||||||
|
*
|
||||||
|
* @param date
|
||||||
|
* 日期串 mmdd格式
|
||||||
|
* @return mm-dd格式
|
||||||
|
*/
|
||||||
|
public static String formatDate2(String date) {
|
||||||
|
return date.substring(0, 2) + "-" + date.substring(2, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回显示给用户的格式的时间 即:将hhmm格式变为hh:mm格式
|
||||||
|
*
|
||||||
|
* @param time
|
||||||
|
* hhmm格式串
|
||||||
|
* @return hh:mm格式
|
||||||
|
*/
|
||||||
|
public static String formatTime(String time) {
|
||||||
|
return time.substring(0, 2) + ":" + time.substring(2, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前日期时间。
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getCurrentDateTime() {
|
||||||
|
return getCurrentDate() + " " + getCurrentTime();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 返回当前日期 ,格式为2018年04月20日 10:34格式
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getNowDateHm() {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HH:mm");
|
||||||
|
long nowtime = System.currentTimeMillis();
|
||||||
|
String datetime = sdf.format(nowtime);
|
||||||
|
String date = datetime.substring(0, 8);
|
||||||
|
String time = datetime.substring(8, 14);
|
||||||
|
String newDate = formatChDate(date);
|
||||||
|
return newDate+time;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回当前日期 ,格式为yyyymmdd格式
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getCurrentDate() {
|
||||||
|
long time = System.currentTimeMillis();
|
||||||
|
Date date = new Date(time);
|
||||||
|
int year = 1900 + date.getYear();
|
||||||
|
int month = date.getMonth() + 1;
|
||||||
|
int day = date.getDate();
|
||||||
|
|
||||||
|
String ymd = String.valueOf(year);
|
||||||
|
if (month < 10)
|
||||||
|
ymd += "0";
|
||||||
|
ymd += String.valueOf(month);
|
||||||
|
if (day < 10)
|
||||||
|
ymd += "0";
|
||||||
|
ymd += String.valueOf(day);
|
||||||
|
return ymd;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回当前时间 ,格式为hhmmss格式
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getCurrentTime() {
|
||||||
|
Calendar cal = new GregorianCalendar();
|
||||||
|
int hour = cal.get(Calendar.HOUR_OF_DAY); // 0..23
|
||||||
|
int minute = cal.get(Calendar.MINUTE); // 0..59
|
||||||
|
int second = cal.get(Calendar.SECOND); // 0..59
|
||||||
|
String value = "";
|
||||||
|
if (hour < 10) {
|
||||||
|
value += "0" + hour;
|
||||||
|
} else {
|
||||||
|
value += hour;
|
||||||
|
}
|
||||||
|
if (minute < 10) {
|
||||||
|
value += "0" + minute;
|
||||||
|
} else {
|
||||||
|
value += minute;
|
||||||
|
}
|
||||||
|
if (second < 10) {
|
||||||
|
value += "0" + second;
|
||||||
|
} else {
|
||||||
|
value += second;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 返回要存到数据库里的日期字符串 本操作会对传入的日期进行验证 即:将yyyymmdd格式变为yyyymmdd格式
|
||||||
|
*
|
||||||
|
* @param str
|
||||||
|
* yyyymmdd格式串
|
||||||
|
* @return yyyymmdd格式
|
||||||
|
*/
|
||||||
|
public static String getDate(String str) {
|
||||||
|
if (!isLegalDate(str))
|
||||||
|
return null;
|
||||||
|
return str.substring(0, 4) + str.substring(4, 6) + str.substring(6, 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断给定的字符串是否是一个合法的日期表示 本系统中的日期表示均为:YYYYMMDD。 ?表示任一字符
|
||||||
|
* 注:这个格式是用户输入和显示给用户的,实际存到数据库里时要去掉?
|
||||||
|
*
|
||||||
|
* @param str
|
||||||
|
* 要进行处理的参数字符串
|
||||||
|
* @return boolean true or false
|
||||||
|
*/
|
||||||
|
public static boolean isLegalDate(String str) {
|
||||||
|
String tmp = str.trim();
|
||||||
|
// if(tmp.length()!=8) return false;
|
||||||
|
try {
|
||||||
|
int year = Integer.parseInt(tmp.substring(0, 4));
|
||||||
|
if (year < 1900 || year > 3000)
|
||||||
|
return false;
|
||||||
|
int month = Integer.parseInt(tmp.substring(4, 6));
|
||||||
|
if (month < 1 || month > 12)
|
||||||
|
return false;
|
||||||
|
int day = Integer.parseInt(tmp.substring(6, 8));
|
||||||
|
if (day < 1)
|
||||||
|
return false;
|
||||||
|
if (month == 2) {
|
||||||
|
if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) {
|
||||||
|
if (day > 29)
|
||||||
|
return false;
|
||||||
|
} else if (day > 28)
|
||||||
|
return false;
|
||||||
|
} else if (((month == 1) || (month == 3) || (month == 5)
|
||||||
|
|| (month == 7) || (month == 8) || (month == 10) || (month == 12))
|
||||||
|
&& day > 31)
|
||||||
|
return false;
|
||||||
|
else if (((month == 4) || (month == 6) || (month == 9) || (month == 11))
|
||||||
|
&& day > 30)
|
||||||
|
return false;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回显示给用户的格式的日期 即:将yyyy-mm-dd格式变为yyyymmdd格式
|
||||||
|
*
|
||||||
|
* @param date
|
||||||
|
* yyyy-mm-dd格式串
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String unformatDate(String date) {
|
||||||
|
if(null==date || "".equals(date)){
|
||||||
|
|
||||||
|
}else{
|
||||||
|
date = date.substring(0, 4) + date.substring(5, 7)
|
||||||
|
+ date.substring(8, 10);
|
||||||
|
}
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 传入一个日期,加上或减去一个数后,得到新的日期
|
||||||
|
*
|
||||||
|
* @param psDate
|
||||||
|
* String
|
||||||
|
* @param piValue
|
||||||
|
* int
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public static String getBeforeDate(String psDate, int piValue) {
|
||||||
|
int year, month, day;
|
||||||
|
String asDate;
|
||||||
|
Calendar cl = Calendar.getInstance();
|
||||||
|
year = Integer.valueOf(psDate.substring(0, 4)).intValue();
|
||||||
|
cl.set(cl.YEAR, year);
|
||||||
|
// Calendar的月份是从0开始的
|
||||||
|
month = Integer.valueOf(psDate.substring(4, 6)).intValue() - 1;
|
||||||
|
cl.set(cl.MONTH, month);
|
||||||
|
day = Integer.valueOf(psDate.substring(6)).intValue();
|
||||||
|
cl.set(cl.DAY_OF_MONTH, day);
|
||||||
|
cl.add(cl.DATE, piValue);
|
||||||
|
year = cl.get(cl.YEAR);
|
||||||
|
month = cl.get(cl.MONDAY) + 1;
|
||||||
|
day = cl.get(cl.DAY_OF_MONTH);
|
||||||
|
asDate = String.valueOf(year);
|
||||||
|
if (month < 10)
|
||||||
|
asDate += "0" + String.valueOf(month);
|
||||||
|
else
|
||||||
|
asDate += String.valueOf(month);
|
||||||
|
if (day < 10)
|
||||||
|
asDate += "0" + String.valueOf(day);
|
||||||
|
else
|
||||||
|
asDate += String.valueOf(day);
|
||||||
|
return asDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取某个月的最后一天
|
||||||
|
*
|
||||||
|
* @param psYear
|
||||||
|
* String
|
||||||
|
* @param psMon
|
||||||
|
* String
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public static String getLastDay(String psYear, String psMon) {
|
||||||
|
int year, month;
|
||||||
|
year = Integer.valueOf(psYear).intValue();
|
||||||
|
month = Integer.valueOf(psMon).intValue();
|
||||||
|
if (month == 12) {
|
||||||
|
year += 1;
|
||||||
|
month = 0;
|
||||||
|
}
|
||||||
|
Calendar cl = Calendar.getInstance();
|
||||||
|
cl.set(cl.YEAR, year);
|
||||||
|
cl.set(cl.MONTH, month);
|
||||||
|
cl.set(cl.DAY_OF_MONTH, 1);
|
||||||
|
cl.add(cl.DATE, -1);
|
||||||
|
return String.valueOf(cl.get(cl.DAY_OF_MONTH));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 输入两个日期,算之前相差多少天
|
||||||
|
*
|
||||||
|
* @param psDate1
|
||||||
|
* String 2008-09-09 OR 20080909
|
||||||
|
* @param psDate2
|
||||||
|
* String 2008-09-09 OR 20080909
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public static long getNumberOfDays(String psDate1, String psDate2) {
|
||||||
|
psDate1 = psDate1.replace('-', '/');
|
||||||
|
psDate2 = psDate2.replace('-', '/');
|
||||||
|
try {
|
||||||
|
|
||||||
|
psDate1 = psDate1.substring(0, 4) + "/" + psDate1.substring(4, 6)
|
||||||
|
+ "/" + psDate1.substring(6, 8);
|
||||||
|
psDate2 = psDate2.substring(0, 4) + "/" + psDate2.substring(4, 6)
|
||||||
|
+ "/" + psDate2.substring(6, 8);
|
||||||
|
|
||||||
|
Date dt1 = new Date(psDate1);
|
||||||
|
Date dt2 = new Date(psDate2);
|
||||||
|
long l = dt1.getTime() - dt2.getTime();
|
||||||
|
l = l / 60 / 60 / 1000 / 24;
|
||||||
|
return Math.abs(l);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 算两个日期之间一共有几个月
|
||||||
|
*
|
||||||
|
* @param qsrq
|
||||||
|
* @param jzrq
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Integer getNumOfMonths(String qsrq, String jzrq) {
|
||||||
|
Integer qs = Integer.parseInt(qsrq.substring(0, 4)) * 12
|
||||||
|
+ Integer.parseInt(qsrq.substring(4, 6));
|
||||||
|
Integer jz = Integer.parseInt(jzrq.substring(0, 4)) * 12
|
||||||
|
+ Integer.parseInt(jzrq.substring(4, 6));
|
||||||
|
return jz - qs + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 得到下个月
|
||||||
|
* @param rq
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getNextMonth(String rq) {
|
||||||
|
Integer nf = Integer.parseInt(rq.substring(0, 4));
|
||||||
|
Integer yf = Integer.parseInt(rq.substring(4, 6));
|
||||||
|
yf = yf + 1;
|
||||||
|
if (yf > 12) {
|
||||||
|
yf = 1;
|
||||||
|
nf = nf + 1;
|
||||||
|
}
|
||||||
|
return yf >= 10 ? nf.toString() + yf.toString() : nf.toString()
|
||||||
|
+ "0" + yf.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过两个日期(起始和截至)得到第几年
|
||||||
|
* @param args
|
||||||
|
*/
|
||||||
|
public static Integer getYear(String qsrq,String jzrq){
|
||||||
|
int m = DateUtil.getNumOfMonths(qsrq, jzrq);
|
||||||
|
int year = m%12==0?m/12:m/12+1;
|
||||||
|
return year;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 得到中文格式 2011年 04月
|
||||||
|
* @param date 201104
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String formatYearAndMonth(String date){
|
||||||
|
return date.substring(0,4)+"年"+date.substring(4,6)+"月";
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取现在时间
|
||||||
|
*
|
||||||
|
* @return 返回时间类型 yyyy-MM-dd HH:mm:ss
|
||||||
|
*/
|
||||||
|
public static Date getDateNow() {
|
||||||
|
Date currentTime = new Date();
|
||||||
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
String dateString = formatter.format(currentTime);
|
||||||
|
//ParsePosition pos = new ParsePosition(18);
|
||||||
|
Date currentTime_2 = null;
|
||||||
|
try {
|
||||||
|
currentTime_2 = formatter.parse(dateString);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return currentTime_2;
|
||||||
|
}
|
||||||
|
}
|
||||||
615
kgBuilder-base/src/main/java/com/warmer/base/util/DbUtils.java
Normal file
615
kgBuilder-base/src/main/java/com/warmer/base/util/DbUtils.java
Normal file
@ -0,0 +1,615 @@
|
|||||||
|
package com.warmer.base.util;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import com.warmer.base.common.FieldQueryItem;
|
||||||
|
import com.warmer.base.common.PageRecord;
|
||||||
|
import com.zaxxer.hikari.HikariConfig;
|
||||||
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class DbUtils {
|
||||||
|
private static Logger log = LoggerFactory.getLogger(Neo4jUtil.class);
|
||||||
|
|
||||||
|
private static HashMap<String, JdbcTemplate> urlAndJdbcTemplate = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据库字典信息(mysql8.0可用)
|
||||||
|
*/
|
||||||
|
public static HashMap<String, ArrayList<HashMap<String, String>>> getMetaData(String dbType, String dbName, String jdbcUrl, String username, String password, String driverClassName) {
|
||||||
|
ResultSet rs = null;
|
||||||
|
PreparedStatement pst = null;
|
||||||
|
Connection conn = getConnection(jdbcUrl, username, password, driverClassName);
|
||||||
|
ArrayList<String> tableList = getTables(dbType, dbName, username, password, driverClassName, jdbcUrl);
|
||||||
|
HashMap<String, ArrayList<HashMap<String, String>>> result = new HashMap<>();
|
||||||
|
dbType = dbType.toLowerCase();
|
||||||
|
try {
|
||||||
|
//遍历表获取字段及字段类型
|
||||||
|
for (String tableName : tableList) {
|
||||||
|
ArrayList<HashMap<String, String>> arrayList = new ArrayList<>();
|
||||||
|
//获取表
|
||||||
|
String sql = getTableColumnSQL(dbType, dbName, tableName);
|
||||||
|
if (StringUtil.isNotBlank(sql)) {
|
||||||
|
arrayList.addAll(getColumnItemByTable(conn, tableName, dbName, dbType));
|
||||||
|
result.put(tableName, arrayList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());;
|
||||||
|
} finally {
|
||||||
|
closeResource(rs, pst, conn);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HashMap<String, ArrayList<HashMap<String, String>>> getMetaData(String dbType, String dbName, String jdbcUrl, String username, String password, String driverClassName,List<String> tableList) {
|
||||||
|
|
||||||
|
HashMap<String, ArrayList<HashMap<String, String>>> result = new HashMap<>();
|
||||||
|
dbType = dbType.toLowerCase();
|
||||||
|
Connection conn = getConnection(jdbcUrl, username, password, driverClassName);
|
||||||
|
try {
|
||||||
|
//遍历表获取字段及字段类型备注
|
||||||
|
for (String tableName : tableList) {
|
||||||
|
//获取表
|
||||||
|
ArrayList<HashMap<String, String>> columnItems = getColumnItemByTable(conn, tableName, dbName,dbType);
|
||||||
|
result.put(tableName, columnItems);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());;
|
||||||
|
} finally {
|
||||||
|
closeResource(null, null, conn);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getTableColumnSQL(String dbType, String dbName, String tableName) {
|
||||||
|
String sql = "";
|
||||||
|
switch (dbType.toLowerCase()) {
|
||||||
|
case "mysql":
|
||||||
|
case "mariadb":
|
||||||
|
sql = String.format("select column_name as FieldName, column_comment as AliaName,column_type as FieldType,IF(column_key='PRI',1,0) as IsPrimary from INFORMATION_SCHEMA.Columns where table_name='%s' and table_schema='%s'",tableName,dbName);
|
||||||
|
break;
|
||||||
|
case "hive":
|
||||||
|
sql = "select TBL_ID, TBL_NAME, COLUMNS_V2.CD_ID, COLUMNS_V2.COLUMN_NAME as FieldName, COLUMNS_V2.COMMENT as AliaName from TBLS left join SDS on TBLS.SD_ID = SDS.SD_ID left join COLUMNS_V2 on SDS.CD_ID = COLUMNS_V2.CD_ID where TBLS.TBL_NAME ='" + tableName + "'";
|
||||||
|
break;
|
||||||
|
case "postgresql":
|
||||||
|
sql = "select a.attname as FieldName, d.description as AliaName from pg_class c, pg_attribute a, pg_description d where c.relname ='" + tableName + "'" + " and a.attnum>0 and a.attrelid = c.oid and d.objoid = a.attrelid and d.objsubid = a.attnum";
|
||||||
|
break;
|
||||||
|
case "oracle":
|
||||||
|
sql = "select column_name as FieldName, comments as AliaName from user_col_comments where table_name= '" + tableName + "'";
|
||||||
|
break;
|
||||||
|
case "sqlserver":
|
||||||
|
sql = "select a.name as table_name, b.name as FieldName, c.value as AliaName from sys.tables a inner join sys.columns b on b.object_id = a.object_id left join sys.extended_properties c on c.major_id = b.object_id and c.minor_id = b.column_id where a.name = '" + tableName + "'";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
return sql;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取指定url(库)的所有表
|
||||||
|
*/
|
||||||
|
public static ArrayList<String> getTables(String dbType, String dbName, String username, String password, String driverClassName, String jdbcUrl) {
|
||||||
|
ResultSet rs = null;
|
||||||
|
PreparedStatement pst = null;
|
||||||
|
Connection conn = null;
|
||||||
|
//数据库的所有表名称
|
||||||
|
ArrayList<String> tableList = new ArrayList<>();
|
||||||
|
|
||||||
|
dbType = dbType.toLowerCase();
|
||||||
|
String sql = getTableNameSQL(dbType, dbName);
|
||||||
|
if (StringUtil.isNotBlank(sql)) {
|
||||||
|
try {
|
||||||
|
conn = getConnection(jdbcUrl, username, password, driverClassName);
|
||||||
|
pst = conn.prepareStatement(sql);
|
||||||
|
rs = pst.executeQuery();
|
||||||
|
while (rs.next()) {
|
||||||
|
tableList.add(rs.getString(1));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());;
|
||||||
|
} finally {
|
||||||
|
closeResource(rs, pst, conn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tableList;
|
||||||
|
}
|
||||||
|
private static void closeResource(ResultSet rs, Statement pst, Connection conn) {
|
||||||
|
try {
|
||||||
|
if (rs != null && !rs.isClosed()) {
|
||||||
|
rs.close();
|
||||||
|
}
|
||||||
|
if (pst != null && !pst.isClosed()) {
|
||||||
|
pst.close();
|
||||||
|
}
|
||||||
|
if (conn != null && !conn.isClosed()) {
|
||||||
|
conn.close();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private static String getTableNameSQL(String dbType, String dbName) {
|
||||||
|
String sql = "";
|
||||||
|
switch (dbType) {
|
||||||
|
case "mysql":
|
||||||
|
case "mariadb":
|
||||||
|
sql = "SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'";
|
||||||
|
break;
|
||||||
|
case "hive":
|
||||||
|
sql = "show tables";
|
||||||
|
break;
|
||||||
|
case "postgresql":
|
||||||
|
sql = "select tablename from pg_tables where schemaname='" + dbName + "'";
|
||||||
|
break;
|
||||||
|
case "oracle":
|
||||||
|
sql = "select t.table_name from user_tables t";
|
||||||
|
break;
|
||||||
|
case "sqlserver":
|
||||||
|
sql = "select sysobjects.name from sysobjects where xtype='U'";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
return sql;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取视图
|
||||||
|
*/
|
||||||
|
public static ArrayList<String> getViews(String dbType, String dbName, String username, String password, String driverClassName, String jdbcUrl,
|
||||||
|
int MaximumPoolSize) {
|
||||||
|
ResultSet rs = null;
|
||||||
|
PreparedStatement pst = null;
|
||||||
|
Connection conn = null;
|
||||||
|
ArrayList<String> viewNameList = new ArrayList<>();
|
||||||
|
dbType = dbType.toLowerCase();
|
||||||
|
String sql = getViewNameSQL(dbType, dbName);
|
||||||
|
if (StringUtil.isNotBlank(sql)) {
|
||||||
|
try {
|
||||||
|
conn = getConnection(jdbcUrl, username, password, driverClassName);
|
||||||
|
pst = conn.prepareStatement(sql);
|
||||||
|
rs = pst.executeQuery();
|
||||||
|
while (rs.next()) {
|
||||||
|
viewNameList.add(rs.getString(1));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());;
|
||||||
|
} finally {
|
||||||
|
closeResource(rs, pst, conn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return viewNameList;
|
||||||
|
}
|
||||||
|
private static Connection getConnection(String jdbcUrl, String username, String password, String driverClassName) {
|
||||||
|
Connection conn = null;
|
||||||
|
try {
|
||||||
|
String cacheKey = getCacheKey(jdbcUrl, username);
|
||||||
|
if (urlAndJdbcTemplate.containsKey(cacheKey)) {
|
||||||
|
conn = urlAndJdbcTemplate.get(cacheKey).getDataSource().getConnection();
|
||||||
|
} else {
|
||||||
|
// 加载驱动
|
||||||
|
Class.forName(driverClassName);
|
||||||
|
// 获取链接
|
||||||
|
conn = DriverManager.getConnection(jdbcUrl, username, password);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());;
|
||||||
|
}
|
||||||
|
return conn;
|
||||||
|
}
|
||||||
|
private static String getViewNameSQL(String dbType, String dbName) {
|
||||||
|
String sql = "";
|
||||||
|
switch (dbType) {
|
||||||
|
case "mysql":
|
||||||
|
case "mariadb":
|
||||||
|
sql = "SHOW TABLE STATUS WHERE COMMENT='view'";
|
||||||
|
break;
|
||||||
|
case "postgresql":
|
||||||
|
sql = "SELECT viewname FROM pg_views WHERE schemaname = '" + dbName + "'";
|
||||||
|
break;
|
||||||
|
case "oracle":
|
||||||
|
sql = "select * from user_views";
|
||||||
|
break;
|
||||||
|
case "sqlserver":
|
||||||
|
sql = "SELECT * FROM INFORMATION_SCHEMA.VIEWS";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
return sql;
|
||||||
|
}
|
||||||
|
private static String getCacheKey(String jdbcUrl, String userName) {
|
||||||
|
return jdbcUrl + ":" + userName;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取指定表的字段信息
|
||||||
|
*/
|
||||||
|
public static ArrayList<HashMap<String, String>> getColumnItemByTable(String username, String password, String driverClassName, String jdbcUrl,
|
||||||
|
int MaximumPoolSize, String tableName, String dbName, String dbType) {
|
||||||
|
Connection conn = null;
|
||||||
|
ArrayList<HashMap<String, String>> arrayList = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
conn = getConnection(jdbcUrl, username, password, driverClassName);
|
||||||
|
arrayList = getColumnItemByTable(conn,tableName,dbName,dbType);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());;
|
||||||
|
} finally {
|
||||||
|
closeResource(null,null, conn);
|
||||||
|
}
|
||||||
|
return arrayList;
|
||||||
|
}
|
||||||
|
public static ArrayList<HashMap<String, String>> getColumnItemByTable(Connection conn, String tableName, String dbName, String dbType) {
|
||||||
|
ResultSet rs = null;
|
||||||
|
PreparedStatement pst = null;
|
||||||
|
ArrayList<HashMap<String, String>> arrayList = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
String sql = getTableColumnSQL(dbType, dbName, tableName);
|
||||||
|
pst = conn.prepareStatement(sql);
|
||||||
|
rs = pst.executeQuery();
|
||||||
|
while (rs.next()) {
|
||||||
|
HashMap<String, String> fieldMap = new HashMap<>();
|
||||||
|
fieldMap.put("ColumnName", rs.getString("FieldName"));
|
||||||
|
fieldMap.put("ColumnAlia", rs.getString("AliaName"));
|
||||||
|
fieldMap.put("ColumnType", rs.getString("FieldType"));
|
||||||
|
fieldMap.put("IsPrimary", rs.getString("IsPrimary"));
|
||||||
|
arrayList.add(fieldMap);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());;
|
||||||
|
} finally {
|
||||||
|
closeResource(rs, pst, null);
|
||||||
|
}
|
||||||
|
return arrayList;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取jdbc模板
|
||||||
|
*/
|
||||||
|
private static synchronized JdbcTemplate getJDBCTemplate(String username, String password, String driverClassName, String jdbcUrl,
|
||||||
|
int MaximumPoolSize) {
|
||||||
|
String cacheKey = getCacheKey(jdbcUrl, username);
|
||||||
|
if (!urlAndJdbcTemplate.containsKey(cacheKey)) {
|
||||||
|
HikariConfig dataSourceConfig = new HikariConfig();
|
||||||
|
dataSourceConfig.setUsername(username);
|
||||||
|
dataSourceConfig.setPassword(password);
|
||||||
|
dataSourceConfig.setDriverClassName(driverClassName);
|
||||||
|
dataSourceConfig.setJdbcUrl(jdbcUrl);
|
||||||
|
dataSourceConfig.setMaximumPoolSize(MaximumPoolSize);
|
||||||
|
dataSourceConfig.setMinimumIdle(1);
|
||||||
|
DataSource ds = new HikariDataSource(dataSourceConfig);
|
||||||
|
JdbcTemplate jdbcTemplate = new JdbcTemplate(ds);
|
||||||
|
urlAndJdbcTemplate.put(cacheKey, jdbcTemplate);
|
||||||
|
return jdbcTemplate;
|
||||||
|
} else {
|
||||||
|
return urlAndJdbcTemplate.get(cacheKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页获取表中的数据
|
||||||
|
*/
|
||||||
|
public static PageRecord<Map<String, Object>> getTableInfoByPage(int pageIndex, int pageSize, String dbType, String dbName, String jdbcUrl, String tableName, String username, String password, String driverClassName,
|
||||||
|
int MaximumPoolSize, int selectType, String selectMessage) {
|
||||||
|
// 分类创建jdbcUrl及sql
|
||||||
|
// 创建pageBean对象
|
||||||
|
PageRecord<Map<String, Object>> pageRecord = new PageRecord<Map<String, Object>>();
|
||||||
|
dbType = dbType.toLowerCase();
|
||||||
|
try {
|
||||||
|
JdbcTemplate jdbcTemplate = getJDBCTemplate(username, password, driverClassName, jdbcUrl, MaximumPoolSize);
|
||||||
|
String sql = getQuerySQL(selectType, selectMessage, dbType, tableName, dbName, pageIndex, pageSize, jdbcTemplate);
|
||||||
|
if (StringUtil.isNotBlank(sql)) {
|
||||||
|
// 赋值当前页
|
||||||
|
List<Map<String, Object>> arrayList = new ArrayList<>();
|
||||||
|
if (dbType.equals("hive")) {
|
||||||
|
List<Map<String, Object>> queryForList = jdbcTemplate.queryForList(sql);
|
||||||
|
for (Map<String, Object> map : queryForList) {
|
||||||
|
Map<String, Object> m = new HashMap<>();
|
||||||
|
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
||||||
|
String mapKey = entry.getKey();
|
||||||
|
mapKey = mapKey.substring(mapKey.lastIndexOf(".") + 1);
|
||||||
|
Object mapValue = entry.getValue();
|
||||||
|
m.put(mapKey, mapValue);
|
||||||
|
}
|
||||||
|
arrayList.add(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
arrayList = jdbcTemplate.queryForList(sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
pageRecord.setPageIndex(pageIndex);
|
||||||
|
// 赋值一页的项目数
|
||||||
|
pageRecord.setPageSize(pageSize);
|
||||||
|
// 赋值总记录数
|
||||||
|
Object[] params = null;
|
||||||
|
String countsql = getQueryCountSQL(tableName, selectType, selectMessage, dbType, dbName);
|
||||||
|
Integer totalCount = jdbcTemplate.queryForObject(countsql, params, Integer.class);
|
||||||
|
pageRecord.setTotalCount(totalCount);
|
||||||
|
// 赋值每页项目
|
||||||
|
pageRecord.setData(arrayList);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
return pageRecord;
|
||||||
|
}
|
||||||
|
public static PageRecord<Map<String, Object>> getTableInfoByPage(int pageIndex, int pageSize, String dbType, String dbName, String jdbcUrl, String tableName, String username, String password, String driverClassName,
|
||||||
|
int maximumPoolSize, List<FieldQueryItem> filterItems) {
|
||||||
|
return getTableInfoByPage(pageIndex,pageSize,dbType,dbName,jdbcUrl,tableName,username,password,driverClassName,maximumPoolSize,filterItems,null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PageRecord<Map<String, Object>> getTableInfoByPage(int pageIndex, int pageSize, String dbType, String dbName, String jdbcUrl, String tableName, String username, String password, String driverClassName,
|
||||||
|
int MaximumPoolSize, List<FieldQueryItem> filterItems,List<String> columns) {
|
||||||
|
// 分类创建jdbcUrl及sql
|
||||||
|
// 创建pageBean对象
|
||||||
|
PageRecord<Map<String, Object>> pageRecord = new PageRecord<Map<String, Object>>();
|
||||||
|
dbType = dbType.toLowerCase();
|
||||||
|
try {
|
||||||
|
JdbcTemplate jdbcTemplate = getJDBCTemplate(username, password, driverClassName, jdbcUrl, MaximumPoolSize);
|
||||||
|
String sql = getQuerySQL(filterItems, dbType, tableName, dbName, pageIndex, pageSize, jdbcTemplate,columns);
|
||||||
|
if (StringUtil.isNotBlank(sql)) {
|
||||||
|
// 赋值当前页
|
||||||
|
List<Map<String, Object>> arrayList = new ArrayList<>();
|
||||||
|
if (dbType.equals("hive")) {
|
||||||
|
List<Map<String, Object>> queryForList = jdbcTemplate.queryForList(sql);
|
||||||
|
for (Map<String, Object> map : queryForList) {
|
||||||
|
Map<String, Object> m = new HashMap<>();
|
||||||
|
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
||||||
|
String mapKey = entry.getKey();
|
||||||
|
mapKey = mapKey.substring(mapKey.lastIndexOf(".") + 1);
|
||||||
|
Object mapValue = entry.getValue();
|
||||||
|
m.put(mapKey, mapValue);
|
||||||
|
}
|
||||||
|
arrayList.add(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
arrayList = jdbcTemplate.queryForList(sql);
|
||||||
|
}
|
||||||
|
if(arrayList.size()>0){
|
||||||
|
List<String> headFields = new ArrayList<>(arrayList.get(0).keySet());
|
||||||
|
pageRecord.setHeads(headFields);
|
||||||
|
}
|
||||||
|
pageRecord.setPageIndex(pageIndex);
|
||||||
|
// 赋值一页的项目数
|
||||||
|
pageRecord.setPageSize(pageSize);
|
||||||
|
// 赋值总记录数
|
||||||
|
Object[] params = null;
|
||||||
|
String countSql = getQueryCountSQL(tableName, filterItems, dbType, dbName);
|
||||||
|
Integer totalCount = jdbcTemplate.queryForObject(countSql, params, Integer.class);
|
||||||
|
pageRecord.setTotalCount(totalCount);
|
||||||
|
// 赋值每页项目
|
||||||
|
pageRecord.setData(arrayList);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
return pageRecord;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getTableDataNum(String dbType, String dbName, String jdbcUrl, String tableName, String username, String password, String driverClassName,
|
||||||
|
int MaximumPoolSize) {
|
||||||
|
JdbcTemplate jdbcTemplate = null;
|
||||||
|
String sql = getQueryCountSQL(tableName, 0, "", dbType, dbName);
|
||||||
|
try {
|
||||||
|
jdbcTemplate = getJDBCTemplate(username, password, driverClassName, jdbcUrl, MaximumPoolSize);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());;
|
||||||
|
}
|
||||||
|
// 赋值总记录数
|
||||||
|
Object[] params = null;
|
||||||
|
Integer count = jdbcTemplate.queryForObject(sql, params, Integer.class);
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
private static String getQueryCountSQL(String tableName, int selectType, String selectMessage, String dbType, String dbName) {
|
||||||
|
String countsql = "";
|
||||||
|
switch (dbType) {
|
||||||
|
case "sqlserver":
|
||||||
|
countsql = "select rows from sysindexes where indid<2 and id = object_id('" + tableName + "')";
|
||||||
|
break;
|
||||||
|
case "postgresql":
|
||||||
|
countsql = "select count(1) from " + dbName + "." + tableName;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
countsql = "select count(1) from " + tableName;
|
||||||
|
if (selectType == 1) {
|
||||||
|
String whereSQL = getWhereSQL(selectMessage);
|
||||||
|
countsql = countsql + whereSQL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return countsql;
|
||||||
|
}
|
||||||
|
private static String getQueryCountSQL(String tableName, List<FieldQueryItem> filterItems, String dbType, String dbName) {
|
||||||
|
String countsql = "";
|
||||||
|
switch (dbType) {
|
||||||
|
case "sqlserver":
|
||||||
|
countsql = "select rows from sysindexes where indid<2 and id = object_id('" + tableName + "')";
|
||||||
|
break;
|
||||||
|
case "postgresql":
|
||||||
|
countsql = "select count(1) from " + dbName + "." + tableName;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
countsql = "select count(1) from " + tableName;
|
||||||
|
}
|
||||||
|
String whereSQL = buildWhereSql(dbType,filterItems);
|
||||||
|
if(StringUtil.isNotBlank(whereSQL)){
|
||||||
|
countsql=String.format(" %s where %s",countsql,whereSQL);
|
||||||
|
}
|
||||||
|
return countsql;
|
||||||
|
}
|
||||||
|
private static String getQuerySQL(int selectType, String selectMessage, String dbType, String tableName, String dbName, int pageIndex, int pageSize, JdbcTemplate jdbcTemplate) {
|
||||||
|
String sql = "";
|
||||||
|
if (selectType == 0) {
|
||||||
|
switch (dbType) {
|
||||||
|
case "mysql":
|
||||||
|
case "mariadb":
|
||||||
|
case "hive":
|
||||||
|
sql = "select * from " + tableName + " limit " + ((pageIndex - 1) * pageSize) + " ," + pageSize;
|
||||||
|
break;
|
||||||
|
case "postgresql":
|
||||||
|
sql = "select * from " + dbName + "." + tableName + " limit " + pageSize + " offset " + ((pageIndex - 1) * pageSize);
|
||||||
|
break;
|
||||||
|
case "oracle":
|
||||||
|
sql = "select t.* from (select e.*,rownum rn from " + tableName + " e) t where t.rn between "
|
||||||
|
+ ((pageIndex - 1) * pageSize + 1) + " and " + pageSize * pageIndex;
|
||||||
|
break;
|
||||||
|
case "sqlserver":
|
||||||
|
// 获取表中第一个字段名
|
||||||
|
String columnName = jdbcTemplate.queryForRowSet("select top 1 * from " + tableName).getMetaData().getColumnName(1);
|
||||||
|
sql = "select * from " + tableName + " order by " + columnName + " offset "
|
||||||
|
+ ((pageIndex - 1) * pageSize) + " row fetch next " + pageSize + " row only";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
} else if (selectType == 1) {
|
||||||
|
String whereSQL = getWhereSQL(selectMessage);
|
||||||
|
switch (dbType) {
|
||||||
|
case "mysql":
|
||||||
|
case "mariadb":
|
||||||
|
case "hive":
|
||||||
|
sql = "select * from " + tableName + whereSQL + " limit " + ((pageIndex - 1) * pageSize) + " ," + pageSize;
|
||||||
|
break;
|
||||||
|
case "postgresql":
|
||||||
|
sql = "select * from " + dbName + "." + tableName + whereSQL + " limit " + pageSize + " offset " + ((pageIndex - 1) * pageSize);
|
||||||
|
sql = sql.replaceAll("`", "");
|
||||||
|
break;
|
||||||
|
case "oracle":
|
||||||
|
sql = "select t.* from (select e.*,rownum rn from " + tableName + " e " + whereSQL + ") t where t.rn between "
|
||||||
|
+ ((pageIndex - 1) * pageSize + 1) + " and " + pageSize * pageIndex;
|
||||||
|
break;
|
||||||
|
case "sqlserver":
|
||||||
|
whereSQL = whereSQL.replaceAll("`", "");
|
||||||
|
// 获取表中第一个字段名
|
||||||
|
String columnName = jdbcTemplate.queryForRowSet("select top 1 * from " + tableName).getMetaData().getColumnName(1);
|
||||||
|
sql = "select * from " + tableName + whereSQL + " order by " + columnName + " offset "
|
||||||
|
+ ((pageIndex - 1) * pageSize) + " row fetch next " + pageSize + " row only";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
} else if (selectType == 2) {
|
||||||
|
sql = selectMessage;
|
||||||
|
}
|
||||||
|
return sql;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getQuerySQL( List<FieldQueryItem> filterItems,String dbType, String tableName, String dbName, int pageIndex, int pageSize, JdbcTemplate jdbcTemplate) {
|
||||||
|
return getQuerySQL(filterItems,dbType,tableName,dbName,pageIndex,pageSize,jdbcTemplate,null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getQuerySQL( List<FieldQueryItem> filterItems,String dbType, String tableName, String dbName, int pageIndex, int pageSize, JdbcTemplate jdbcTemplate,List<String> columns) {
|
||||||
|
String sql = "";
|
||||||
|
String whereSQL = buildWhereSql(dbType,filterItems);
|
||||||
|
if(StringUtil.isNotBlank(whereSQL)){
|
||||||
|
whereSQL=String.format(" where %s ",whereSQL);
|
||||||
|
}
|
||||||
|
String columnsStr="*";
|
||||||
|
if(columns!=null&&columns.size()>0){
|
||||||
|
columnsStr=String.join(",",columns);
|
||||||
|
}
|
||||||
|
switch (dbType) {
|
||||||
|
case "mysql":
|
||||||
|
case "mariadb":
|
||||||
|
case "hive":
|
||||||
|
sql = "select "+columnsStr+" from " + tableName + whereSQL + " limit " + ((pageIndex - 1) * pageSize) + " ," + pageSize;
|
||||||
|
break;
|
||||||
|
case "postgresql":
|
||||||
|
sql = "select "+columnsStr+" from " + dbName + "." + tableName + whereSQL + " limit " + pageSize + " offset " + ((pageIndex - 1) * pageSize);
|
||||||
|
sql = sql.replaceAll("`", "");
|
||||||
|
break;
|
||||||
|
case "oracle":
|
||||||
|
if(columns!=null&&columns.size()>0){
|
||||||
|
columnsStr=columns.stream().map(n->String.format("t.%s",n)).collect(Collectors.joining(","));
|
||||||
|
}
|
||||||
|
sql = "select "+columnsStr+" from (select e.*,rownum rn from " + tableName + " e " + whereSQL + ") t where t.rn between "
|
||||||
|
+ ((pageIndex - 1) * pageSize + 1) + " and " + pageSize * pageIndex;
|
||||||
|
break;
|
||||||
|
case "sqlserver":
|
||||||
|
whereSQL = whereSQL.replaceAll("`", "");
|
||||||
|
// 获取表中第一个字段名
|
||||||
|
String columnName = jdbcTemplate.queryForRowSet("select top 1 * from " + tableName).getMetaData().getColumnName(1);
|
||||||
|
sql = "select "+columnsStr+" from " + tableName + whereSQL + " order by " + columnName + " offset "
|
||||||
|
+ ((pageIndex - 1) * pageSize) + " row fetch next " + pageSize + " row only";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
return sql;
|
||||||
|
}
|
||||||
|
private static String getWhereSQL(String selectMessage) {
|
||||||
|
StringBuilder ret = new StringBuilder();
|
||||||
|
ret.append(" where ");
|
||||||
|
try {
|
||||||
|
List<Map<String, String>> array = JsonHelper.parseObject(selectMessage, new TypeReference<List<Map<String, String>>>() {
|
||||||
|
});
|
||||||
|
if (array.size() > 0) {
|
||||||
|
for (Map<String, String> map : array) {
|
||||||
|
if (map.get("relation").equals("not")) {
|
||||||
|
ret.append(" and " + "`" + map.get("fieldname") + "`" + " not like " + "'" + map.get("fieldval") + "'" + " ");
|
||||||
|
} else {
|
||||||
|
ret.append(map.get("relation") + " ").append("`" + map.get("fieldname") + "`" + " ").append(map.get("fieldrel") + " ").append("'" + map.get("fieldval") + "'" + " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
log.error(e.getMessage());;
|
||||||
|
}
|
||||||
|
return ret.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String buildWhereSql(String dbType,List<FieldQueryItem> filterItems) {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
if (filterItems != null && filterItems.size() > 0) {
|
||||||
|
int i=0;
|
||||||
|
for (FieldQueryItem item : filterItems) {
|
||||||
|
if (StringUtil.isBlank(item.getValue()) || StringUtil.isBlank(item.getJoinOperate()) || item.getCondition() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String str ="";
|
||||||
|
switch (dbType.toLowerCase()){
|
||||||
|
case "mongo":
|
||||||
|
break;
|
||||||
|
default://mysql ,postgresql,sqlserver,oracle
|
||||||
|
if(item.getCondition()==-1){
|
||||||
|
str=String.format(" %s ( %s%s'%s') ", i == 0 ? "" : item.getJoinOperate(), item.getField(), item.getOperate(), item.getValue());
|
||||||
|
}else {
|
||||||
|
str=String.format(" %s ( %s%s'%s') ", i == 0 ? "" : item.getJoinOperate(), item.getField(), "like", "%"+item.getValue()+"%");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(StringUtil.isNotBlank(str)){
|
||||||
|
builder.append(str);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<String> parserFieldList(String sql) {
|
||||||
|
List<String> result = null;
|
||||||
|
try {
|
||||||
|
sql = sql.toLowerCase();
|
||||||
|
String field = sql.substring(7, sql.indexOf(" from "));
|
||||||
|
String[] fieldList = field.split(",");
|
||||||
|
List<String> fields = Arrays.stream(fieldList).map(n -> {
|
||||||
|
if (n.contains(" as ")) {
|
||||||
|
n = n.substring(n.lastIndexOf("as") + 2).trim();
|
||||||
|
}
|
||||||
|
n = n.replace("`", "");
|
||||||
|
return n;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
result = fields;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,96 @@
|
|||||||
|
package com.warmer.base.util;
|
||||||
|
|
||||||
|
import org.apache.poi.openxml4j.opc.OPCPackage;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class ExcelUtil {
|
||||||
|
// *************xlsx文件读取函数************************
|
||||||
|
// 在jdbc.properties上加上 excelUrl:xlsx文件的目录
|
||||||
|
// excel_name为文件名,arg为需要查询的列号(输入数字则返回对应列 , 输入字符串则固定返回这个字符串)
|
||||||
|
// 返回
|
||||||
|
@SuppressWarnings({ "resource", "unused" })
|
||||||
|
public static ArrayList<ArrayList<String>> xlsx_reader(String excel_name, ArrayList<Object> args)
|
||||||
|
throws IOException {
|
||||||
|
// 读取excel文件夹url
|
||||||
|
|
||||||
|
String excelUrl = "";
|
||||||
|
File xlsxFile = new File(excelUrl + excel_name);
|
||||||
|
if (!xlsxFile.exists()) {
|
||||||
|
System.err.println("Not found or not a file: " + xlsxFile.getPath());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ArrayList<ArrayList<String>> excel_output = new ArrayList<ArrayList<String>>();
|
||||||
|
try {
|
||||||
|
OPCPackage p;
|
||||||
|
// p = OPCPackage.open(xlsxFile.getPath(), PackageAccess.READ);
|
||||||
|
/*
|
||||||
|
* XLSX2CSV xlsx2csv = new XLSX2CSV(p, 20); // 20代表最大列数 xlsx2csv.process();
|
||||||
|
* excel_output = xlsx2csv.get_output();
|
||||||
|
*/
|
||||||
|
// p.close(); //释放
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ArrayList<ArrayList<String>> ans = new ArrayList<ArrayList<String>>();
|
||||||
|
// 遍历xlsx中的sheet
|
||||||
|
|
||||||
|
// 对于每个sheet,读取其中的每一行
|
||||||
|
for (int rowNum = 0; rowNum < excel_output.size(); rowNum++) {
|
||||||
|
ArrayList<String> cur_output = excel_output.get(rowNum);
|
||||||
|
ArrayList<String> curarr = new ArrayList<String>();
|
||||||
|
for (int columnNum = 0; columnNum < args.size(); columnNum++) {
|
||||||
|
Object obj = args.get(columnNum);
|
||||||
|
if (obj instanceof String) {
|
||||||
|
curarr.add(obj.toString());
|
||||||
|
} else if (obj instanceof Integer) {
|
||||||
|
String cell = cur_output.get((int) obj);
|
||||||
|
curarr.add(cell);
|
||||||
|
} else {
|
||||||
|
System.out.print("类型错误!");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ans.add(curarr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ans;
|
||||||
|
}
|
||||||
|
|
||||||
|
// // 判断后缀为xlsx的excel文件的数据类
|
||||||
|
// @SuppressWarnings("deprecation")
|
||||||
|
// private static String getValue(XSSFCell xssfRow) {
|
||||||
|
// if (xssfRow == null) {
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
// if (xssfRow.getCellType() == xssfRow.CELL_TYPE_BOOLEAN) {
|
||||||
|
// return String.valueOf(xssfRow.getBooleanCellValue());
|
||||||
|
// } else if (xssfRow.getCellType() == xssfRow.CELL_TYPE_NUMERIC) {
|
||||||
|
// double cur = xssfRow.getNumericCellValue();
|
||||||
|
// long longVal = Math.round(cur);
|
||||||
|
// Object inputValue = null;
|
||||||
|
// if (Double.parseDouble(longVal + ".0") == cur)
|
||||||
|
// inputValue = longVal;
|
||||||
|
// else
|
||||||
|
// inputValue = cur;
|
||||||
|
// return String.valueOf(inputValue);
|
||||||
|
// } else if (xssfRow.getCellType() == xssfRow.CELL_TYPE_BLANK
|
||||||
|
// || xssfRow.getCellType() == xssfRow.CELL_TYPE_ERROR) {
|
||||||
|
// return "";
|
||||||
|
// } else {
|
||||||
|
// return String.valueOf(xssfRow.getStringCellValue());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
public static boolean isExcel2003(String filePath) {
|
||||||
|
return filePath.matches("^.+\\.(?i)(xls)$");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isExcel2007(String filePath) {
|
||||||
|
return filePath.matches("^.+\\.(?i)(xlsx)$");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,49 @@
|
|||||||
|
package com.warmer.base.util;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class FileResponse {
|
||||||
|
private int success; //成功标准 0失败 1成功
|
||||||
|
private List<FileResult> results;//文件results
|
||||||
|
private String message; //错误信息
|
||||||
|
|
||||||
|
public FileResponse() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileResponse(int success, List<FileResult> results, String message) {
|
||||||
|
this.success = success;
|
||||||
|
this.results = results;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSuccess() {
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSuccess(int success) {
|
||||||
|
this.success = success;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the results
|
||||||
|
*/
|
||||||
|
public List<FileResult> getResults() {
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param results the results to set
|
||||||
|
*/
|
||||||
|
public void setResults(List<FileResult> results) {
|
||||||
|
this.results = results;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,47 @@
|
|||||||
|
/**
|
||||||
|
* @Title: FileResult.java
|
||||||
|
* @Package warmer.star.blog.util
|
||||||
|
* @Description: TODO(用一句话描述该文件做什么)
|
||||||
|
* @author tc
|
||||||
|
* @date 2018年6月1日 下午5:37:09
|
||||||
|
* @version V1.0
|
||||||
|
*/
|
||||||
|
package com.warmer.base.util;
|
||||||
|
|
||||||
|
|
||||||
|
public class FileResult {
|
||||||
|
private String name;
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
public int getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
public void setStatus(int status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
public void setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @return the url
|
||||||
|
*/
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param url the url to set
|
||||||
|
*/
|
||||||
|
public void setUrl(String url) {
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
private int status;
|
||||||
|
private String message;
|
||||||
|
private String url;
|
||||||
|
}
|
||||||
@ -0,0 +1,96 @@
|
|||||||
|
package com.warmer.base.util;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class FileUtil {
|
||||||
|
public static boolean createFile(String destFileName) {
|
||||||
|
File file = new File(destFileName);
|
||||||
|
if(file.exists()) {
|
||||||
|
System.out.println("创建单个文件" + destFileName + "失败,目标文件已存在!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (destFileName.endsWith(File.separator)) {
|
||||||
|
System.out.println("创建单个文件" + destFileName + "失败,目标文件不能为目录!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//判断目标文件所在的目录是否存在
|
||||||
|
if(!file.getParentFile().exists()) {
|
||||||
|
//如果目标文件所在的目录不存在,则创建父目录
|
||||||
|
System.out.println("目标文件所在目录不存在,准备创建它!");
|
||||||
|
if(!file.getParentFile().mkdirs()) {
|
||||||
|
System.out.println("创建目标文件所在目录失败!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//创建目标文件
|
||||||
|
try {
|
||||||
|
if (file.createNewFile()) {
|
||||||
|
System.out.println("创建单个文件" + destFileName + "成功!");
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
System.out.println("创建单个文件" + destFileName + "失败!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
System.out.println("创建单个文件" + destFileName + "失败!" + e.getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static boolean createDir(String destDirName) {
|
||||||
|
File dir = new File(destDirName);
|
||||||
|
if (dir.exists()) {
|
||||||
|
System.out.println("创建目录" + destDirName + "失败,目标目录已经存在");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!destDirName.endsWith(File.separator)) {
|
||||||
|
destDirName = destDirName + File.separator;
|
||||||
|
}
|
||||||
|
//创建目录
|
||||||
|
if (dir.mkdirs()) {
|
||||||
|
System.out.println("创建目录" + destDirName + "成功!");
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
System.out.println("创建目录" + destDirName + "失败!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String createTempFile(String prefix, String suffix, String dirName) {
|
||||||
|
File tempFile = null;
|
||||||
|
if (dirName == null) {
|
||||||
|
try{
|
||||||
|
//在默认文件夹下创建临时文件
|
||||||
|
tempFile = File.createTempFile(prefix, suffix);
|
||||||
|
//返回临时文件的路径
|
||||||
|
return tempFile.getCanonicalPath();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
System.out.println("创建临时文件失败!" + e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
File dir = new File(dirName);
|
||||||
|
//如果临时文件所在目录不存在,首先创建
|
||||||
|
if (!dir.exists()) {
|
||||||
|
if (!FileUtil.createDir(dirName)) {
|
||||||
|
System.out.println("创建临时文件失败,不能创建临时文件所在的目录!");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
//在指定目录下创建临时文件
|
||||||
|
tempFile = File.createTempFile(prefix, suffix, dir);
|
||||||
|
return tempFile.getCanonicalPath();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
System.out.println("创建临时文件失败!" + e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,66 @@
|
|||||||
|
package com.warmer.base.util;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@SuppressWarnings("serial")
|
||||||
|
public class GraphPageRecord<T> implements Serializable{
|
||||||
|
private int pageSize = 10;
|
||||||
|
private int pageIndex = 1;
|
||||||
|
private long totalCount = 0;
|
||||||
|
private List<T> nodeList = new ArrayList<T>();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取分页记录数量
|
||||||
|
*/
|
||||||
|
public int getPageSize() {
|
||||||
|
return pageSize;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取当前页序号
|
||||||
|
*/
|
||||||
|
public int getPageIndex() {
|
||||||
|
return pageIndex;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 设置当前页序号
|
||||||
|
*/
|
||||||
|
public void setPageIndex(int pageIndex) {
|
||||||
|
if(pageIndex <= 0) {
|
||||||
|
pageIndex = 1;
|
||||||
|
}
|
||||||
|
this.pageIndex = pageIndex;
|
||||||
|
}
|
||||||
|
public void setPageSize(int pageSize) {
|
||||||
|
if(pageSize <= 0) {
|
||||||
|
pageSize = 1;
|
||||||
|
}
|
||||||
|
this.pageSize = pageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取总记录数
|
||||||
|
*/
|
||||||
|
public long getTotalCount() {
|
||||||
|
return totalCount;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取总记录数
|
||||||
|
*/
|
||||||
|
public void setTotalCount(long totalCount) {
|
||||||
|
this.totalCount = totalCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取Node检索结果列表
|
||||||
|
*/
|
||||||
|
public List<T> getNodeList() {
|
||||||
|
return nodeList;
|
||||||
|
}
|
||||||
|
public void setNodeList(List<T> nodeList) {
|
||||||
|
this.nodeList=nodeList;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,108 @@
|
|||||||
|
package com.warmer.base.util;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import com.fasterxml.jackson.databind.type.CollectionType;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* json工具类
|
||||||
|
* @author yindm
|
||||||
|
*/
|
||||||
|
public class JsonHelper {
|
||||||
|
private static ObjectMapper mapper;
|
||||||
|
|
||||||
|
static {
|
||||||
|
mapper = new ObjectMapper();
|
||||||
|
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 反序列化成对象
|
||||||
|
* @param json
|
||||||
|
* @param clazz
|
||||||
|
* @param <T>
|
||||||
|
* @return
|
||||||
|
* @throws JsonProcessingException
|
||||||
|
*/
|
||||||
|
public static <T> T parseObject(String json, Class<T> clazz) throws JsonProcessingException {
|
||||||
|
return mapper.readValue(json, clazz);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 反序列化成List
|
||||||
|
* @param json
|
||||||
|
* @param clazz
|
||||||
|
* @param <T>
|
||||||
|
* @return
|
||||||
|
* @throws JsonProcessingException
|
||||||
|
*/
|
||||||
|
public static <T> ArrayList<T> parseArray(String json, Class<T> clazz) throws JsonProcessingException {
|
||||||
|
CollectionType listType = mapper.getTypeFactory().constructCollectionType(ArrayList.class, clazz);
|
||||||
|
return mapper.readValue(json, listType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 反序列化成对象
|
||||||
|
* @param json
|
||||||
|
* @param type
|
||||||
|
* @param <T>
|
||||||
|
* @return
|
||||||
|
* @throws JsonProcessingException
|
||||||
|
*/
|
||||||
|
public static <T> T parseObject(String json, TypeReference<T> type) throws JsonProcessingException {
|
||||||
|
return mapper.readValue(json, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 反序列化成对象
|
||||||
|
* @param json
|
||||||
|
* @return
|
||||||
|
* @throws JsonProcessingException
|
||||||
|
*/
|
||||||
|
public static JsonNode parseObject(String json) throws JsonProcessingException {
|
||||||
|
return mapper.readTree(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 序列化成对象
|
||||||
|
* @param value
|
||||||
|
* @return
|
||||||
|
* @throws JsonProcessingException
|
||||||
|
*/
|
||||||
|
public static String toJSONString(Object value) throws JsonProcessingException {
|
||||||
|
return mapper.writeValueAsString(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象转换成List
|
||||||
|
* @param value
|
||||||
|
* @param <T>
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static <T extends JsonNode> T valueToTree(Object value) {
|
||||||
|
return mapper.valueToTree(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建Json节点
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static ObjectNode createNode() {
|
||||||
|
return mapper.createObjectNode();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建JsonList
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static ArrayNode createArray() {
|
||||||
|
return mapper.createArrayNode();
|
||||||
|
}
|
||||||
|
}
|
||||||
705
kgBuilder-base/src/main/java/com/warmer/base/util/Neo4jUtil.java
Normal file
705
kgBuilder-base/src/main/java/com/warmer/base/util/Neo4jUtil.java
Normal file
@ -0,0 +1,705 @@
|
|||||||
|
package com.warmer.base.util;
|
||||||
|
|
||||||
|
import org.neo4j.driver.*;
|
||||||
|
import org.neo4j.driver.Record;
|
||||||
|
import org.neo4j.driver.types.Node;
|
||||||
|
import org.neo4j.driver.types.Path;
|
||||||
|
import org.neo4j.driver.types.Relationship;
|
||||||
|
import org.neo4j.driver.util.Pair;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Lazy;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Lazy(false)
|
||||||
|
public class Neo4jUtil implements AutoCloseable {
|
||||||
|
|
||||||
|
private static Driver neo4jDriver;
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(Neo4jUtil.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Lazy
|
||||||
|
public void setNeo4jDriver(Driver neo4jDriver) {
|
||||||
|
Neo4jUtil.neo4jDriver = neo4jDriver;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试neo4j连接是否打开
|
||||||
|
*/
|
||||||
|
public static boolean isNeo4jOpen() {
|
||||||
|
try (Session session = neo4jDriver.session()) {
|
||||||
|
log.debug("连接成功:" + session.isOpen());
|
||||||
|
return session.isOpen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* neo4j驱动执行cypher
|
||||||
|
*
|
||||||
|
* @param cypherSql cypherSql
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static void runCypherSql(String cypherSql) {
|
||||||
|
try (Session session = neo4jDriver.session()) {
|
||||||
|
log.debug(cypherSql);
|
||||||
|
session.run(cypherSql);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> List<T> readCyphers(String cypherSql, Function<Record, T> mapper) {
|
||||||
|
try (Session session = neo4jDriver.session()) {
|
||||||
|
log.debug(cypherSql);
|
||||||
|
Result result = session.run(cypherSql);
|
||||||
|
return result.list(mapper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回节点集合,此方法不保留关系
|
||||||
|
*
|
||||||
|
* @param cypherSql cypherSql
|
||||||
|
*/
|
||||||
|
public static List<HashMap<String, Object>> getGraphNode(String cypherSql) {
|
||||||
|
List<HashMap<String, Object>> ents = new ArrayList<HashMap<String, Object>>();
|
||||||
|
try (Session session = neo4jDriver.session()) {
|
||||||
|
log.debug(cypherSql);
|
||||||
|
Result result = session.run(cypherSql);
|
||||||
|
if (result.hasNext()) {
|
||||||
|
List<Record> records = result.list();
|
||||||
|
for (Record recordItem : records) {
|
||||||
|
List<Pair<String, Value>> f = recordItem.fields();
|
||||||
|
for (Pair<String, Value> pair : f) {
|
||||||
|
HashMap<String, Object> rss = new HashMap<String, Object>();
|
||||||
|
String typeName = pair.value().type().name();
|
||||||
|
if (typeName.equals("NODE")) {
|
||||||
|
Node noe4jNode = pair.value().asNode();
|
||||||
|
String uuid = String.valueOf(noe4jNode.id());
|
||||||
|
Map<String, Object> map = noe4jNode.asMap();
|
||||||
|
for (Entry<String, Object> entry : map.entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
rss.put(key, entry.getValue());
|
||||||
|
}
|
||||||
|
rss.put("uuid", uuid);
|
||||||
|
ents.add(rss);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
return ents;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据库索引
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static List<HashMap<String, Object>> getGraphIndex() {
|
||||||
|
List<HashMap<String, Object>> ents = new ArrayList<HashMap<String, Object>>();
|
||||||
|
try (Session session = neo4jDriver.session()) {
|
||||||
|
String cypherSql="call db.indexes";
|
||||||
|
Result result = session.run(cypherSql);
|
||||||
|
if (result.hasNext()) {
|
||||||
|
List<Record> records = result.list();
|
||||||
|
for (Record recordItem : records) {
|
||||||
|
List<Pair<String, Value>> f = recordItem.fields();
|
||||||
|
HashMap<String, Object> rss = new HashMap<String, Object>();
|
||||||
|
for (Pair<String, Value> pair : f) {
|
||||||
|
String key = pair.key();
|
||||||
|
Value value = pair.value();
|
||||||
|
if(key.equalsIgnoreCase("labelsOrTypes")){
|
||||||
|
String objects = value.asList().stream().map(n->n.toString()).collect(Collectors.joining(","));
|
||||||
|
rss.put(key, objects);
|
||||||
|
}else{
|
||||||
|
rss.put(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ents.add(rss);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
return ents;
|
||||||
|
}
|
||||||
|
public static List<HashMap<String, Object>> getGraphLabels() {
|
||||||
|
List<HashMap<String, Object>> ents = new ArrayList<HashMap<String, Object>>();
|
||||||
|
try (Session session = neo4jDriver.session()) {
|
||||||
|
String cypherSql="call db.labels";
|
||||||
|
Result result = session.run(cypherSql);
|
||||||
|
if (result.hasNext()) {
|
||||||
|
List<Record> records = result.list();
|
||||||
|
for (Record recordItem : records) {
|
||||||
|
List<Pair<String, Value>> f = recordItem.fields();
|
||||||
|
HashMap<String, Object> rss = new HashMap<String, Object>();
|
||||||
|
for (Pair<String, Value> pair : f) {
|
||||||
|
String key = pair.key();
|
||||||
|
Value value = pair.value();
|
||||||
|
if(key.equalsIgnoreCase("label")){
|
||||||
|
String objects =value.toString().replace("\"","");
|
||||||
|
rss.put(key, objects);
|
||||||
|
}else{
|
||||||
|
rss.put(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ents.add(rss);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
return ents;
|
||||||
|
}
|
||||||
|
public static Map<String,Object> getLabelsInfo() {
|
||||||
|
Map<String,Object> ent = new HashMap<>();
|
||||||
|
try (Session session = neo4jDriver.session()) {
|
||||||
|
String cypherSql="CALL apoc.meta.stats() YIELD labels RETURN labels";
|
||||||
|
Result result = session.run(cypherSql);
|
||||||
|
if (result.hasNext()) {
|
||||||
|
Record record = result.single();
|
||||||
|
Map<String, Object> mp = record.asMap();
|
||||||
|
ent = (Map<String, Object>) mp.get("labels");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
return ent;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 删除索引
|
||||||
|
* @param label
|
||||||
|
*/
|
||||||
|
public static void deleteIndex(String label) {
|
||||||
|
try (Session session = neo4jDriver.session()) {
|
||||||
|
String cypherSql=String.format("DROP INDEX ON :`%s`(name)",label);
|
||||||
|
session.run(cypherSql);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建索引
|
||||||
|
* @param label
|
||||||
|
* @param prop
|
||||||
|
*/
|
||||||
|
public static void createIndex(String label,String prop) {
|
||||||
|
try (Session session = neo4jDriver.session()) {
|
||||||
|
String cypherSql=String.format("CREATE INDEX ON :`%s`(%s)",label,prop);
|
||||||
|
session.run(cypherSql);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static HashMap<String, Object> getSingleGraphNode(String cypherSql) {
|
||||||
|
List<HashMap<String, Object>> ent = getGraphNode(cypherSql);
|
||||||
|
if (ent.size() > 0) {
|
||||||
|
return ent.get(0);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取一个标准的表格,一般用于语句里使用as
|
||||||
|
*
|
||||||
|
* @param cypherSql
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static List<HashMap<String, Object>> getGraphTable(String cypherSql) {
|
||||||
|
List<HashMap<String, Object>> resultData = new ArrayList<HashMap<String, Object>>();
|
||||||
|
try (Session session = neo4jDriver.session()) {
|
||||||
|
log.debug(cypherSql);
|
||||||
|
Result result = session.run(cypherSql);
|
||||||
|
if (result.hasNext()) {
|
||||||
|
List<Record> records = result.list();
|
||||||
|
for (Record recordItem : records) {
|
||||||
|
List<Pair<String, Value>> f = recordItem.fields();
|
||||||
|
HashMap<String, Object> rss = new HashMap<String, Object>();
|
||||||
|
for (Pair<String, Value> pair : f) {
|
||||||
|
String key = pair.key();
|
||||||
|
Value value = pair.value();
|
||||||
|
rss.put(key, value);
|
||||||
|
}
|
||||||
|
resultData.add(rss);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
return resultData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回关系,不保留节点内容
|
||||||
|
*
|
||||||
|
* @param cypherSql
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static List<HashMap<String, Object>> getGraphRelationShip(String cypherSql) {
|
||||||
|
List<HashMap<String, Object>> ents = new ArrayList<HashMap<String, Object>>();
|
||||||
|
try (Session session = neo4jDriver.session()) {
|
||||||
|
log.debug(cypherSql);
|
||||||
|
Result result = session.run(cypherSql);
|
||||||
|
if (result.hasNext()) {
|
||||||
|
List<Record> records = result.list();
|
||||||
|
for (Record recordItem : records) {
|
||||||
|
List<Pair<String, Value>> f = recordItem.fields();
|
||||||
|
for (Pair<String, Value> pair : f) {
|
||||||
|
HashMap<String, Object> rss = new HashMap<String, Object>();
|
||||||
|
String typeName = pair.value().type().name();
|
||||||
|
if (typeName.equals("RELATIONSHIP")) {
|
||||||
|
Relationship rship = pair.value().asRelationship();
|
||||||
|
String uuid = String.valueOf(rship.id());
|
||||||
|
String sourceId = String.valueOf(rship.startNodeId());
|
||||||
|
String targetId = String.valueOf(rship.endNodeId());
|
||||||
|
Map<String, Object> map = rship.asMap();
|
||||||
|
for (Entry<String, Object> entry : map.entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
rss.put(key, entry.getValue());
|
||||||
|
}
|
||||||
|
rss.put("uuid", uuid);
|
||||||
|
rss.put("sourceId", sourceId);
|
||||||
|
rss.put("targetId", targetId);
|
||||||
|
ents.add(rss);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
return ents;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取值类型的结果,如count,uuid
|
||||||
|
*
|
||||||
|
* @return 1 2 3 等数字类型
|
||||||
|
*/
|
||||||
|
public static long getGraphValue(String cypherSql) {
|
||||||
|
long val = 0;
|
||||||
|
try (Session session = neo4jDriver.session()) {
|
||||||
|
log.debug(cypherSql);
|
||||||
|
Result cypherResult = session.run(cypherSql);
|
||||||
|
if (cypherResult.hasNext()) {
|
||||||
|
Record record = cypherResult.next();
|
||||||
|
for (Value value : record.values()) {
|
||||||
|
val = value.asLong();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回节点和关系,节点node,关系relationship,路径path,集合list,map
|
||||||
|
*
|
||||||
|
* @param cypherSql
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static HashMap<String, Object> getGraphNodeAndShip(String cypherSql) {
|
||||||
|
HashMap<String, Object> mo = new HashMap<String, Object>();
|
||||||
|
try (Session session = neo4jDriver.session()) {
|
||||||
|
log.debug(cypherSql);
|
||||||
|
Result result = session.run(cypherSql);
|
||||||
|
if (result.hasNext()) {
|
||||||
|
List<Record> records = result.list();
|
||||||
|
List<HashMap<String, Object>> ents = new ArrayList<HashMap<String, Object>>();
|
||||||
|
List<HashMap<String, Object>> ships = new ArrayList<HashMap<String, Object>>();
|
||||||
|
List<String> uuids = new ArrayList<String>();
|
||||||
|
for (Record recordItem : records) {
|
||||||
|
List<Pair<String, Value>> f = recordItem.fields();
|
||||||
|
for (Pair<String, Value> pair : f) {
|
||||||
|
HashMap<String, Object> rShips = new HashMap<String, Object>();
|
||||||
|
HashMap<String, Object> rss = new HashMap<String, Object>();
|
||||||
|
String typeName = pair.value().type().name();
|
||||||
|
if ("NULL".equals(typeName)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ("NODE".equals(typeName)) {
|
||||||
|
Node noe4jNode = pair.value().asNode();
|
||||||
|
Map<String, Object> map = noe4jNode.asMap();
|
||||||
|
String uuid = String.valueOf(noe4jNode.id());
|
||||||
|
if (!uuids.contains(uuid)) {
|
||||||
|
for (Entry<String, Object> entry : map.entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
rss.put(key, entry.getValue());
|
||||||
|
}
|
||||||
|
rss.put("uuid", uuid);
|
||||||
|
uuids.add(uuid);
|
||||||
|
}
|
||||||
|
if (!rss.isEmpty()) {
|
||||||
|
ents.add(rss);
|
||||||
|
}
|
||||||
|
} else if ("RELATIONSHIP".equals(typeName)) {
|
||||||
|
Relationship rship = pair.value().asRelationship();
|
||||||
|
String uuid = String.valueOf(rship.id());
|
||||||
|
String sourceId = String.valueOf(rship.startNodeId());
|
||||||
|
String targetId = String.valueOf(rship.endNodeId());
|
||||||
|
Map<String, Object> map = rship.asMap();
|
||||||
|
for (Entry<String, Object> entry : map.entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
rShips.put(key, entry.getValue());
|
||||||
|
}
|
||||||
|
rShips.put("uuid", uuid);
|
||||||
|
rShips.put("sourceId", sourceId);
|
||||||
|
rShips.put("targetId", targetId);
|
||||||
|
ships.add(rShips);
|
||||||
|
} else if ("PATH".equals(typeName)) {
|
||||||
|
Path path = pair.value().asPath();
|
||||||
|
for (Node nodeItem : path.nodes()) {
|
||||||
|
Map<String, Object> map = nodeItem.asMap();
|
||||||
|
String uuid = String.valueOf(nodeItem.id());
|
||||||
|
rss = new HashMap<String, Object>();
|
||||||
|
if (!uuids.contains(uuid)) {
|
||||||
|
for (Entry<String, Object> entry : map.entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
rss.put(key, entry.getValue());
|
||||||
|
}
|
||||||
|
rss.put("uuid", uuid);
|
||||||
|
uuids.add(uuid);
|
||||||
|
}
|
||||||
|
if (!rss.isEmpty()) {
|
||||||
|
ents.add(rss);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (Relationship next : path.relationships()) {
|
||||||
|
rShips = new HashMap<String, Object>();
|
||||||
|
String uuid = String.valueOf(next.id());
|
||||||
|
String sourceId = String.valueOf(next.startNodeId());
|
||||||
|
String targetId = String.valueOf(next.endNodeId());
|
||||||
|
Map<String, Object> map = next.asMap();
|
||||||
|
for (Entry<String, Object> entry : map.entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
rShips.put(key, entry.getValue());
|
||||||
|
}
|
||||||
|
rShips.put("uuid", uuid);
|
||||||
|
rShips.put("sourceId", sourceId);
|
||||||
|
rShips.put("targetId", targetId);
|
||||||
|
ships.add(rShips);
|
||||||
|
}
|
||||||
|
} else if (typeName.contains("LIST")) {
|
||||||
|
Iterable<Value> val = pair.value().values();
|
||||||
|
Value next = val.iterator().next();
|
||||||
|
String type = next.type().name();
|
||||||
|
if ("RELATIONSHIP".equals(type)) {
|
||||||
|
Relationship rship = next.asRelationship();
|
||||||
|
String uuid = String.valueOf(rship.id());
|
||||||
|
String sourceId = String.valueOf(rship.startNodeId());
|
||||||
|
String targetId = String.valueOf(rship.endNodeId());
|
||||||
|
Map<String, Object> map = rship.asMap();
|
||||||
|
for (Entry<String, Object> entry : map.entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
rShips.put(key, entry.getValue());
|
||||||
|
}
|
||||||
|
rShips.put("uuid", uuid);
|
||||||
|
rShips.put("sourceId", sourceId);
|
||||||
|
rShips.put("targetId", targetId);
|
||||||
|
ships.add(rShips);
|
||||||
|
}
|
||||||
|
} else if (typeName.contains("MAP")) {
|
||||||
|
rss.put(pair.key(), pair.value().asMap());
|
||||||
|
} else {
|
||||||
|
rss.put(pair.key(), pair.value().toString());
|
||||||
|
ents.add(rss);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mo.put("node", ents);
|
||||||
|
mo.put("relationship", toDistinctList(ships));
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
return mo;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 去掉json键的引号,否则neo4j会报错
|
||||||
|
*
|
||||||
|
* @param jsonStr
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getFilterPropertiesJson(String jsonStr) {
|
||||||
|
return jsonStr.replaceAll("\"(\\w+)\"(\\s*:\\s*)", "$1$2"); // 去掉key的引号
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象转json,key=value,用于 cypher set语句
|
||||||
|
*
|
||||||
|
* @param obj
|
||||||
|
* @param <T>
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static <T> String getKeyValCyphersql(T obj) {
|
||||||
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
|
List<String> sqlList = new ArrayList<String>();
|
||||||
|
// 得到类对象
|
||||||
|
Class userCla = obj.getClass();
|
||||||
|
/* 得到类中的所有属性集合 */
|
||||||
|
Field[] fs = userCla.getDeclaredFields();
|
||||||
|
for (int i = 0; i < fs.length; i++) {
|
||||||
|
Field f = fs[i];
|
||||||
|
Class type = f.getType();
|
||||||
|
|
||||||
|
f.setAccessible(true); // 设置些属性是可以访问的
|
||||||
|
Object val = new Object();
|
||||||
|
try {
|
||||||
|
val = f.get(obj);
|
||||||
|
if (val == null) {
|
||||||
|
val = "";
|
||||||
|
}
|
||||||
|
String sql = "";
|
||||||
|
String key = f.getName();
|
||||||
|
if (val instanceof String[]) {
|
||||||
|
//如果为true则强转成String数组
|
||||||
|
String[] arr = (String[]) val;
|
||||||
|
String v = "";
|
||||||
|
for (int j = 0; j < arr.length; j++) {
|
||||||
|
arr[j] = "'" + arr[j] + "'";
|
||||||
|
}
|
||||||
|
v = String.join(",", arr);
|
||||||
|
sql = "n." + key + "=[" + val + "]";
|
||||||
|
} else if (val instanceof List) {
|
||||||
|
//如果为true则强转成String数组
|
||||||
|
List<String> arr = (ArrayList<String>) val;
|
||||||
|
List<String> aa = new ArrayList<String>();
|
||||||
|
String v = "";
|
||||||
|
for (String s : arr) {
|
||||||
|
s = "'" + s + "'";
|
||||||
|
aa.add(s);
|
||||||
|
}
|
||||||
|
v = String.join(",", aa);
|
||||||
|
sql = "n." + key + "=[" + v + "]";
|
||||||
|
} else {
|
||||||
|
// 得到此属性的值
|
||||||
|
map.put(key, val);// 设置键值
|
||||||
|
if (type.getName().equals("int")) {
|
||||||
|
sql = "n." + key + "=" + val + "";
|
||||||
|
} else {
|
||||||
|
sql = "n." + key + "='" + val + "'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlList.add(sql);
|
||||||
|
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return String.join(",", sqlList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将haspmap集合反序列化成对象集合
|
||||||
|
*
|
||||||
|
* @param maps
|
||||||
|
* @param type
|
||||||
|
* @param <T>
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static <T> List<T> hashMapToObject(List<HashMap<String, Object>> maps, Class<T> type) {
|
||||||
|
try {
|
||||||
|
List<T> list = new ArrayList<T>();
|
||||||
|
for (HashMap<String, Object> r : maps) {
|
||||||
|
T t = type.newInstance();
|
||||||
|
Iterator iter = r.entrySet().iterator();// 该方法获取列名.获取一系列字段名称.例如name,age...
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
Entry entry = (Entry) iter.next();// 把hashmap转成Iterator再迭代到entry
|
||||||
|
String key = entry.getKey().toString(); // 从iterator遍历获取key
|
||||||
|
Object value = entry.getValue(); // 从hashmap遍历获取value
|
||||||
|
if ("serialVersionUID".toLowerCase().equals(key.toLowerCase())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Field field = type.getDeclaredField(key);// 获取field对象
|
||||||
|
if (field != null) {
|
||||||
|
//System.out.print(field.getType());
|
||||||
|
field.setAccessible(true);
|
||||||
|
//System.out.print(field.getType().getName());
|
||||||
|
if (field.getType() == int.class || field.getType() == Integer.class) {
|
||||||
|
if (value == null || StringUtil.isBlank(value.toString())) {
|
||||||
|
field.set(t, 0);// 设置值
|
||||||
|
} else {
|
||||||
|
field.set(t, Integer.parseInt(value.toString()));// 设置值
|
||||||
|
}
|
||||||
|
} else if (field.getType() == long.class || field.getType() == Long.class) {
|
||||||
|
if (value == null || StringUtil.isBlank(value.toString())) {
|
||||||
|
field.set(t, 0);// 设置值
|
||||||
|
} else {
|
||||||
|
field.set(t, Long.parseLong(value.toString()));// 设置值
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (field.getType() == Double.class) {
|
||||||
|
if (value == null || StringUtil.isBlank(value.toString())) {
|
||||||
|
field.set(t, 0.0);// 设置值
|
||||||
|
} else {
|
||||||
|
field.set(t, Double.parseDouble(value.toString()));// 设置值
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (field.getType().equals(List.class)) {
|
||||||
|
if (value == null || StringUtil.isBlank(value.toString())) {
|
||||||
|
field.set(t, null);
|
||||||
|
} else {
|
||||||
|
field.set(t, value);// 设置值
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
field.set(t, value);// 设置值
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
list.add(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将haspmap反序列化成对象
|
||||||
|
*
|
||||||
|
* @param map
|
||||||
|
* @param type
|
||||||
|
* @param <T>
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static <T> T hashMapToObjectItem(HashMap<String, Object> map, Class<T> type) {
|
||||||
|
try {
|
||||||
|
T t = type.newInstance();
|
||||||
|
Iterator iter = map.entrySet().iterator();
|
||||||
|
while (iter.hasNext()) {
|
||||||
|
Entry entry = (Entry) iter.next();// 把hashmap转成Iterator再迭代到entry
|
||||||
|
String key = entry.getKey().toString(); // 从iterator遍历获取key
|
||||||
|
Object value = entry.getValue(); // 从hashmap遍历获取value
|
||||||
|
if ("serialVersionUID".toLowerCase().equals(key.toLowerCase())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Field field = type.getDeclaredField(key);// 获取field对象
|
||||||
|
if (field != null) {
|
||||||
|
field.setAccessible(true);
|
||||||
|
if (field.getType() == int.class || field.getType() == Integer.class) {
|
||||||
|
if (value == null || StringUtil.isBlank(value.toString())) {
|
||||||
|
field.set(t, 0);// 设置值
|
||||||
|
} else {
|
||||||
|
field.set(t, Integer.parseInt(value.toString()));// 设置值
|
||||||
|
}
|
||||||
|
} else if (field.getType() == long.class || field.getType() == Long.class) {
|
||||||
|
if (value == null || StringUtil.isBlank(value.toString())) {
|
||||||
|
field.set(t, 0);// 设置值
|
||||||
|
} else {
|
||||||
|
field.set(t, Long.parseLong(value.toString()));// 设置值
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (field.getType() == Double.class) {
|
||||||
|
if (value == null || StringUtil.isBlank(value.toString())) {
|
||||||
|
field.set(t, 0.0);// 设置值
|
||||||
|
} else {
|
||||||
|
field.set(t, Double.parseDouble(value.toString()));// 设置值
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (field.getType().equals(List.class)) {
|
||||||
|
if (value == null || StringUtil.isBlank(value.toString())) {
|
||||||
|
field.set(t, null);
|
||||||
|
} else {
|
||||||
|
field.set(t, value);// 设置值
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
field.set(t, value);// 设置值
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return t;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回单个节点信息
|
||||||
|
*/
|
||||||
|
public static HashMap<String, Object> getOneNode(String cypherSql) {
|
||||||
|
HashMap<String, Object> ret = new HashMap<String, Object>();
|
||||||
|
try (Session session = neo4jDriver.session()) {
|
||||||
|
log.debug(cypherSql);
|
||||||
|
Result result = session.run(cypherSql);
|
||||||
|
if (result.hasNext()) {
|
||||||
|
Record record = result.list().get(0);
|
||||||
|
Pair<String, Value> f = record.fields().get(0);
|
||||||
|
String typeName = f.value().type().name();
|
||||||
|
if ("NODE".equals(typeName)) {
|
||||||
|
Node noe4jNode = f.value().asNode();
|
||||||
|
String uuid = String.valueOf(noe4jNode.id());
|
||||||
|
Map<String, Object> map = noe4jNode.asMap();
|
||||||
|
for (Entry<String, Object> entry : map.entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
ret.put(key, entry.getValue());
|
||||||
|
}
|
||||||
|
ret.put("uuid", uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean batchRunCypherWithTx(List<String> cyphers) {
|
||||||
|
Session session = neo4jDriver.session();
|
||||||
|
try (Transaction tx = session.beginTransaction()) {
|
||||||
|
for (String cypher : cyphers) {
|
||||||
|
tx.run(cypher);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info(e.getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static List<HashMap<String, Object>> toDistinctList(List<HashMap<String, Object>> list) {
|
||||||
|
Set<String> keysSet = new HashSet<String>();
|
||||||
|
Iterator<HashMap<String, Object>> it = list.iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
HashMap<String, Object> map = it.next();
|
||||||
|
String uuid = (String) map.get("uuid");
|
||||||
|
int beforeSize = keysSet.size();
|
||||||
|
keysSet.add(uuid);
|
||||||
|
int afterSize = keysSet.size();
|
||||||
|
if (afterSize != (beforeSize + 1)) {
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws Exception {
|
||||||
|
neo4jDriver.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
122
kgBuilder-base/src/main/java/com/warmer/base/util/R.java
Normal file
122
kgBuilder-base/src/main/java/com/warmer/base/util/R.java
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
package com.warmer.base.util;
|
||||||
|
|
||||||
|
import com.warmer.base.enums.ReturnStatus;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接口统一返回结果
|
||||||
|
*
|
||||||
|
* 推荐使用
|
||||||
|
* <p>成功:R.success() </p>
|
||||||
|
* <p>成功:R.success(data) </p>
|
||||||
|
* <p>成功:R.success(data,msg)</p>
|
||||||
|
* <p>出错:R.error()</p>
|
||||||
|
* <p>出错:R.error(msg)</p>
|
||||||
|
* <p>验证型错误:R.warn(msg)</p>
|
||||||
|
* <p>定义参数的错误:R.create(returnStatus)</p>
|
||||||
|
* @param <T>
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class R<T> {
|
||||||
|
public int code;
|
||||||
|
public T data;
|
||||||
|
public String msg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数验证失败
|
||||||
|
*
|
||||||
|
* @param msg
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static R warn(String msg) {
|
||||||
|
return new R(ReturnStatus.ValidateFailure.getValue(), msg, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建实例
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static R create(ReturnStatus returnStatus) {
|
||||||
|
return new R(returnStatus.getValue(), returnStatus.getName(), "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建实例
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static R create(ReturnStatus returnStatus, String msg) {
|
||||||
|
return new R(returnStatus.getValue(), msg, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 出错
|
||||||
|
*
|
||||||
|
* @param msg
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static R error(String msg) {
|
||||||
|
return new R(ReturnStatus.Error.getValue(), msg, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 出错
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static R error() {
|
||||||
|
return new R(ReturnStatus.Error.getValue(), ReturnStatus.Error.getName(), "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成功
|
||||||
|
*
|
||||||
|
* @param <T>
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static <T> R success() {
|
||||||
|
return new R(ReturnStatus.Success.getValue(), "", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成功
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
|
* @param <T>
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static <T> R success(T data) {
|
||||||
|
return new R(ReturnStatus.Success.getValue(), "", data);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 成功
|
||||||
|
*
|
||||||
|
* @param msg
|
||||||
|
* @param <T>
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static <T> R success(String msg) {
|
||||||
|
return new R(ReturnStatus.Success.getValue(), msg, null);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 成功
|
||||||
|
*
|
||||||
|
* @param data
|
||||||
|
* @param <T>
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static <T> R success(T data, String msg) {
|
||||||
|
return new R(ReturnStatus.Success.getValue(), msg, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 私有构建方法,请使用静态方法构建实例
|
||||||
|
*/
|
||||||
|
private R(int code, String msg, T data) {
|
||||||
|
this.code = code;
|
||||||
|
this.msg = msg;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,76 @@
|
|||||||
|
package com.warmer.base.util;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class StringUtil {
|
||||||
|
/*
|
||||||
|
* 是否为空字符串
|
||||||
|
* @param str
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean isBlank(String str){
|
||||||
|
int strLen;
|
||||||
|
if (str == null || (strLen = str.length()) == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < strLen; i++) {
|
||||||
|
if (Character.isWhitespace(str.charAt(i)) == false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNotBlank(String str){
|
||||||
|
return !isBlank(str);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 连接方法 类似于javascript
|
||||||
|
* @param join 连接字符串
|
||||||
|
* @param strAry 需要连接的集合
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String join(String join,String[] strAry){
|
||||||
|
StringBuffer sb=new StringBuffer();
|
||||||
|
for(int i=0,len =strAry.length;i<len;i++){
|
||||||
|
if(i==(len-1)){
|
||||||
|
sb.append(strAry[i]);
|
||||||
|
}else{
|
||||||
|
sb.append(strAry[i]).append(join);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将结果集中的一列用指定字符连接起来
|
||||||
|
* @param join 指定字符
|
||||||
|
* @param cols 结果集
|
||||||
|
* @param colName 列名
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String join(String join,List<Map> cols,String colName){
|
||||||
|
List<String> aColCons = new ArrayList<String>();
|
||||||
|
for (Map map:
|
||||||
|
cols) {
|
||||||
|
aColCons.add(ObjectUtils.toString(map.get(colName)));
|
||||||
|
}
|
||||||
|
return join(join,aColCons);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String join(String join,List<String> listStr){
|
||||||
|
StringBuffer sb=new StringBuffer();
|
||||||
|
for(int i=0,len =listStr.size();i<len;i++){
|
||||||
|
if(i==(len-1)){
|
||||||
|
sb.append(listStr.get(i));
|
||||||
|
}else{
|
||||||
|
sb.append(listStr.get(i)).append(join);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
24
kgBuilder-meta/pom.xml
Normal file
24
kgBuilder-meta/pom.xml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.warmer</groupId>
|
||||||
|
<artifactId>kgbuilder</artifactId>
|
||||||
|
<version>0.0.1</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<groupId>com.warmer</groupId>
|
||||||
|
<artifactId>kgBuilder-meta</artifactId>
|
||||||
|
<version>0.0.1</version>
|
||||||
|
<name>kgBuilder-meta</name>
|
||||||
|
<description>Demo project for Spring Boot</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.warmer</groupId>
|
||||||
|
<artifactId>kgBuilder-base</artifactId>
|
||||||
|
<version>0.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
@ -0,0 +1,57 @@
|
|||||||
|
package com.warmer.meta.dao;
|
||||||
|
|
||||||
|
import com.warmer.meta.entity.MetaDataColumn;
|
||||||
|
import com.warmer.meta.vo.DataTableVo;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (MetaDataColumn)表数据库访问层
|
||||||
|
*
|
||||||
|
* @author tanc
|
||||||
|
* @since 2021-11-21 11:00:14
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface MetaDataColumnDao {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过ID查询单条数据
|
||||||
|
*
|
||||||
|
* @param dataColumnId 主键
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
MetaDataColumn queryById(Integer dataColumnId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过实体作为筛选条件查询
|
||||||
|
*
|
||||||
|
* @return 对象列表
|
||||||
|
*/
|
||||||
|
List<MetaDataColumn> queryAll();
|
||||||
|
List<MetaDataColumn> queryByTableId(@Param("dataTableId") Integer dataTableId);
|
||||||
|
/**
|
||||||
|
* 新增数据
|
||||||
|
*
|
||||||
|
* @param metaDataColumn 实例对象
|
||||||
|
* @return 影响行数
|
||||||
|
*/
|
||||||
|
int insert(MetaDataColumn metaDataColumn);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改数据
|
||||||
|
*
|
||||||
|
* @param metaDataColumn 实例对象
|
||||||
|
* @return 影响行数
|
||||||
|
*/
|
||||||
|
int update(MetaDataColumn metaDataColumn);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过主键删除数据
|
||||||
|
*
|
||||||
|
* @param dataColumnId 主键
|
||||||
|
* @return 影响行数
|
||||||
|
*/
|
||||||
|
int deleteById(Integer dataColumnId);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,56 @@
|
|||||||
|
package com.warmer.meta.dao;
|
||||||
|
|
||||||
|
import com.warmer.meta.entity.MetaDataSource;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据源(MetaDataSource)表数据库访问层
|
||||||
|
*
|
||||||
|
* @author tanc
|
||||||
|
* @since 2021-11-21 11:00:18
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface MetaDataSourceDao {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过ID查询单条数据
|
||||||
|
*
|
||||||
|
* @param dataSourceId 主键
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
MetaDataSource queryById(Integer dataSourceId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过实体作为筛选条件查询
|
||||||
|
*
|
||||||
|
* @return 对象列表
|
||||||
|
*/
|
||||||
|
List<MetaDataSource> queryAll();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增数据
|
||||||
|
*
|
||||||
|
* @param metaDataSource 实例对象
|
||||||
|
* @return 影响行数
|
||||||
|
*/
|
||||||
|
int insert(MetaDataSource metaDataSource);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改数据
|
||||||
|
*
|
||||||
|
* @param metaDataSource 实例对象
|
||||||
|
* @return 影响行数
|
||||||
|
*/
|
||||||
|
int update(MetaDataSource metaDataSource);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过主键删除数据
|
||||||
|
*
|
||||||
|
* @param dataSourceId 主键
|
||||||
|
* @return 影响行数
|
||||||
|
*/
|
||||||
|
int deleteById(Integer dataSourceId);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,58 @@
|
|||||||
|
package com.warmer.meta.dao;
|
||||||
|
|
||||||
|
import com.warmer.meta.entity.MetaDataTable;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (MetaDataTable)表数据库访问层
|
||||||
|
*
|
||||||
|
* @author tanc
|
||||||
|
* @since 2021-11-21 11:00:21
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface MetaDataTableDao {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过ID查询单条数据
|
||||||
|
*
|
||||||
|
* @param dataTableId 主键
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
MetaDataTable queryById(Integer dataTableId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过实体作为筛选条件查询
|
||||||
|
*
|
||||||
|
* @return 对象列表
|
||||||
|
*/
|
||||||
|
List<MetaDataTable> queryAll();
|
||||||
|
List<MetaDataTable> queryByDatasourceId(@Param("datasourceId") Integer datasourceId);
|
||||||
|
MetaDataTable queryByDatasourceIdAndTableCode(@Param("datasourceId") Integer datasourceId,@Param("dataTableCode") String dataTableCode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增数据
|
||||||
|
*
|
||||||
|
* @param metaDataTable 实例对象
|
||||||
|
* @return 影响行数
|
||||||
|
*/
|
||||||
|
int insert(MetaDataTable metaDataTable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改数据
|
||||||
|
*
|
||||||
|
* @param metaDataTable 实例对象
|
||||||
|
* @return 影响行数
|
||||||
|
*/
|
||||||
|
int update(MetaDataTable metaDataTable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过主键删除数据
|
||||||
|
*
|
||||||
|
* @param dataTableId 主键
|
||||||
|
* @return 影响行数
|
||||||
|
*/
|
||||||
|
int deleteById(Integer dataTableId);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
package com.warmer.meta.dto;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class DataTableSubmitItem {
|
||||||
|
|
||||||
|
private Integer dataSourceId;
|
||||||
|
|
||||||
|
private List<String> dataTables;
|
||||||
|
|
||||||
|
public Integer getDataSourceId() {
|
||||||
|
return dataSourceId==null?0:dataSourceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDataSourceId(Integer dataSourceId) {
|
||||||
|
this.dataSourceId = dataSourceId==null?0:dataSourceId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,85 @@
|
|||||||
|
package com.warmer.meta.dto;
|
||||||
|
|
||||||
|
import com.warmer.meta.entity.MetaDataSource;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class DatasourceSubmitItem {
|
||||||
|
|
||||||
|
public Integer getDataSourceId() {
|
||||||
|
return dataSourceId==null?0:dataSourceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDataSourceId(Integer dataSourceId) {
|
||||||
|
this.dataSourceId = dataSourceId==null?0:dataSourceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer dataSourceId;
|
||||||
|
/**
|
||||||
|
* 数据源类型
|
||||||
|
*/
|
||||||
|
private String dbType;
|
||||||
|
|
||||||
|
private String driverName;
|
||||||
|
/**
|
||||||
|
* IP及端口号
|
||||||
|
*/
|
||||||
|
private String ipAndPort;
|
||||||
|
/**
|
||||||
|
* 数据库别名
|
||||||
|
*/
|
||||||
|
private String dbName;
|
||||||
|
/**
|
||||||
|
* 数据库名称
|
||||||
|
*/
|
||||||
|
private String dbCode;
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
private String dbUserName;
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
private String dbPassWord;
|
||||||
|
|
||||||
|
|
||||||
|
public String buildConnUrl() {
|
||||||
|
String dbType = this.getDbType().toUpperCase();
|
||||||
|
String dbCode = this.getDbCode();
|
||||||
|
String connUrl="";
|
||||||
|
switch (dbType) {
|
||||||
|
case "MYSQL":
|
||||||
|
connUrl = String.format("jdbc:mysql://%s/%s?useSSL=false&serverTimezone=Asia/Shanghai", ipAndPort, dbCode);
|
||||||
|
break;
|
||||||
|
case "SQLSERVER":
|
||||||
|
connUrl = String.format("jdbc:sqlserver://%s;databaseName=%s", ipAndPort, dbCode);
|
||||||
|
break;
|
||||||
|
case "POSTGRESQL":
|
||||||
|
connUrl = String.format("jdbc:postgresql://%s", ipAndPort);
|
||||||
|
break;
|
||||||
|
case "ORACLE":
|
||||||
|
connUrl = String.format("jdbc:oracle:thin:@//%s/%s", ipAndPort, dbCode);
|
||||||
|
break;
|
||||||
|
case "MARIADB":
|
||||||
|
connUrl = String.format("jdbc:mariadb://%s/%s", ipAndPort, dbCode);
|
||||||
|
break;
|
||||||
|
case "HIVE":
|
||||||
|
connUrl = String.format("jdbc:hive2://%s/%s", ipAndPort, dbCode);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return connUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetaDataSource transfer(){
|
||||||
|
MetaDataSource source = new MetaDataSource();
|
||||||
|
BeanUtils.copyProperties(this, source);
|
||||||
|
source.setConnectUrl(this.buildConnUrl());
|
||||||
|
source.setIPAndPort(this.ipAndPort);
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,47 @@
|
|||||||
|
package com.warmer.meta.entity;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import com.warmer.base.common.BaseEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
/**
|
||||||
|
* (MetaDataColumn)实体类
|
||||||
|
*
|
||||||
|
* @author tanc
|
||||||
|
* @since 2021-11-21 11:00:13
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class MetaDataColumn extends BaseEntity implements Serializable {
|
||||||
|
private static final long serialVersionUID = 728550695358682173L;
|
||||||
|
/**
|
||||||
|
* 数据列id
|
||||||
|
*/
|
||||||
|
private Integer dataColumnId;
|
||||||
|
/**
|
||||||
|
* 数据表id
|
||||||
|
*/
|
||||||
|
private Integer dataTableId;
|
||||||
|
/**
|
||||||
|
* 数据列名称
|
||||||
|
*/
|
||||||
|
private String dataColumnCode;
|
||||||
|
/**
|
||||||
|
* 数据列别名
|
||||||
|
*/
|
||||||
|
private String dataColumnName;
|
||||||
|
/**
|
||||||
|
* 数据列描述
|
||||||
|
*/
|
||||||
|
private String dataColumnComment;
|
||||||
|
/**
|
||||||
|
* 数据类型
|
||||||
|
*/
|
||||||
|
private String dataColumnType;
|
||||||
|
/**
|
||||||
|
* 是否主键
|
||||||
|
*/
|
||||||
|
private Integer isPrimary;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,64 @@
|
|||||||
|
package com.warmer.meta.entity;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import com.warmer.base.common.BaseEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
/**
|
||||||
|
* 数据源(MetaDataSource)实体类
|
||||||
|
*
|
||||||
|
* @author tanc
|
||||||
|
* @since 2021-11-21 11:00:17
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class MetaDataSource extends BaseEntity implements Serializable {
|
||||||
|
private static final long serialVersionUID = 931209553011500059L;
|
||||||
|
/**
|
||||||
|
* 数据源主键
|
||||||
|
*/
|
||||||
|
private Integer dataSourceId;
|
||||||
|
/**
|
||||||
|
* 数据源类型
|
||||||
|
*/
|
||||||
|
private String dbType;
|
||||||
|
|
||||||
|
private String driverName;
|
||||||
|
/**
|
||||||
|
* IP及端口号
|
||||||
|
*/
|
||||||
|
private String iPAndPort;
|
||||||
|
/**
|
||||||
|
* url
|
||||||
|
*/
|
||||||
|
private String connectUrl;
|
||||||
|
/**
|
||||||
|
* 数据库别名
|
||||||
|
*/
|
||||||
|
private String dbName;
|
||||||
|
/**
|
||||||
|
* 数据库名称
|
||||||
|
*/
|
||||||
|
private String dbCode;
|
||||||
|
/**
|
||||||
|
* 用户名
|
||||||
|
*/
|
||||||
|
private String dbUserName;
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
private String dbPassWord;
|
||||||
|
/**
|
||||||
|
* 最大连接数
|
||||||
|
*/
|
||||||
|
private Integer maxPoolSize;
|
||||||
|
/**
|
||||||
|
* 数据库编码
|
||||||
|
*/
|
||||||
|
private String databaseCoding;
|
||||||
|
/**
|
||||||
|
* 转换编码
|
||||||
|
*/
|
||||||
|
private String transcoding;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
package com.warmer.meta.entity;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import com.warmer.base.common.BaseEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
/**
|
||||||
|
* (MetaDataTable)实体类
|
||||||
|
*
|
||||||
|
* @author tanc
|
||||||
|
* @since 2021-11-21 11:00:20
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class MetaDataTable extends BaseEntity implements Serializable {
|
||||||
|
private static final long serialVersionUID = 146313789945681038L;
|
||||||
|
/**
|
||||||
|
* 数据表主键
|
||||||
|
*/
|
||||||
|
private Integer dataTableId;
|
||||||
|
/**
|
||||||
|
* 数据源id
|
||||||
|
*/
|
||||||
|
private Integer datasourceId;
|
||||||
|
/**
|
||||||
|
* 表名
|
||||||
|
*/
|
||||||
|
private String dataTableCode;
|
||||||
|
/**
|
||||||
|
* 表别名
|
||||||
|
*/
|
||||||
|
private String dataTableName;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
package com.warmer.meta.query;
|
||||||
|
|
||||||
|
import com.warmer.base.common.FieldQueryItem;
|
||||||
|
import com.warmer.base.common.PageQuery;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class TableQuery extends PageQuery {
|
||||||
|
private Integer dataSourceId;
|
||||||
|
private Integer dataTableId;
|
||||||
|
private String dataTableName;
|
||||||
|
private List<FieldQueryItem> filterItems;
|
||||||
|
}
|
||||||
@ -0,0 +1,57 @@
|
|||||||
|
package com.warmer.meta.service;
|
||||||
|
|
||||||
|
import com.warmer.meta.entity.MetaDataColumn;
|
||||||
|
import com.warmer.meta.vo.DataColumnVo;
|
||||||
|
import com.warmer.meta.vo.DataTableVo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (MetaDataColumn)表服务接口
|
||||||
|
*
|
||||||
|
* @author tanc
|
||||||
|
* @since 2021-11-21 11:00:15
|
||||||
|
*/
|
||||||
|
public interface MetaDataColumnService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过ID查询单条数据
|
||||||
|
*
|
||||||
|
* @param dataColumnId 主键
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
MetaDataColumn queryById(Integer dataColumnId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询多条数据
|
||||||
|
*
|
||||||
|
* @return 对象列表
|
||||||
|
*/
|
||||||
|
List<MetaDataColumn> queryAll();
|
||||||
|
|
||||||
|
List<DataColumnVo> queryByTableId(Integer tableId);
|
||||||
|
/**
|
||||||
|
* 新增数据
|
||||||
|
*
|
||||||
|
* @param metaDataColumn 实例对象
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
MetaDataColumn insert(MetaDataColumn metaDataColumn);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改数据
|
||||||
|
*
|
||||||
|
* @param metaDataColumn 实例对象
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
MetaDataColumn update(MetaDataColumn metaDataColumn);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过主键删除数据
|
||||||
|
*
|
||||||
|
* @param dataColumnId 主键
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
boolean deleteById(Integer dataColumnId);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,61 @@
|
|||||||
|
package com.warmer.meta.service;
|
||||||
|
|
||||||
|
import com.warmer.meta.entity.MetaDataSource;
|
||||||
|
import com.warmer.meta.vo.DatasourceVo;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据源(MetaDataSource)表服务接口
|
||||||
|
*
|
||||||
|
* @author tanc
|
||||||
|
* @since 2021-11-21 11:00:18
|
||||||
|
*/
|
||||||
|
public interface MetaDataSourceService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过ID查询单条数据
|
||||||
|
*
|
||||||
|
* @param dataSourceId 主键
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
MetaDataSource queryById(Integer dataSourceId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询多条数据
|
||||||
|
*
|
||||||
|
* @return 对象列表
|
||||||
|
*/
|
||||||
|
List<MetaDataSource> queryAll();
|
||||||
|
|
||||||
|
List<DatasourceVo> queryList();
|
||||||
|
/**
|
||||||
|
* 新增数据
|
||||||
|
*
|
||||||
|
* @param metaDataSource 实例对象
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
MetaDataSource insert(MetaDataSource metaDataSource);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改数据
|
||||||
|
*
|
||||||
|
* @param metaDataSource 实例对象
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
MetaDataSource update(MetaDataSource metaDataSource);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过主键删除数据
|
||||||
|
*
|
||||||
|
* @param dataSourceId 主键
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
boolean deleteById(Integer dataSourceId);
|
||||||
|
|
||||||
|
HashMap<String, ArrayList<HashMap<String, String>>> getMetaData(MetaDataSource metaDataSource);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,67 @@
|
|||||||
|
package com.warmer.meta.service;
|
||||||
|
|
||||||
|
import com.warmer.base.common.PageRecord;
|
||||||
|
import com.warmer.base.util.DbUtils;
|
||||||
|
import com.warmer.meta.dto.DataTableSubmitItem;
|
||||||
|
import com.warmer.meta.entity.MetaDataSource;
|
||||||
|
import com.warmer.meta.entity.MetaDataTable;
|
||||||
|
import com.warmer.meta.query.TableQuery;
|
||||||
|
import com.warmer.meta.vo.DataTableVo;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (MetaDataTable)表服务接口
|
||||||
|
*
|
||||||
|
* @author tanc
|
||||||
|
* @since 2021-11-21 11:00:21
|
||||||
|
*/
|
||||||
|
public interface MetaDataTableService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过ID查询单条数据
|
||||||
|
*
|
||||||
|
* @param dataTableId 主键
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
MetaDataTable queryById(Integer dataTableId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询多条数据
|
||||||
|
*
|
||||||
|
* @return 对象列表
|
||||||
|
*/
|
||||||
|
List<MetaDataTable> queryAll();
|
||||||
|
|
||||||
|
List<DataTableVo> queryByDatasourceId(Integer datasourceId);
|
||||||
|
/**
|
||||||
|
* 新增数据
|
||||||
|
*
|
||||||
|
* @param metaDataTable 实例对象
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
MetaDataTable insert(MetaDataTable metaDataTable);
|
||||||
|
/**
|
||||||
|
* 修改数据
|
||||||
|
*
|
||||||
|
* @param metaDataTable 实例对象
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
MetaDataTable update(MetaDataTable metaDataTable);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过主键删除数据
|
||||||
|
*
|
||||||
|
* @param dataTableId 主键
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
boolean deleteById(Integer dataTableId);
|
||||||
|
|
||||||
|
ArrayList<String> getMetaTables(MetaDataSource metaDataSource) ;
|
||||||
|
|
||||||
|
void saveTables(DataTableSubmitItem submitItem);
|
||||||
|
|
||||||
|
PageRecord<Map<String, Object>> getTableRecords(TableQuery queryItem);
|
||||||
|
}
|
||||||
@ -0,0 +1,97 @@
|
|||||||
|
package com.warmer.meta.service.impl;
|
||||||
|
|
||||||
|
import com.warmer.base.util.DbUtils;
|
||||||
|
import com.warmer.meta.entity.MetaDataColumn;
|
||||||
|
import com.warmer.meta.dao.MetaDataColumnDao;
|
||||||
|
import com.warmer.meta.entity.MetaDataSource;
|
||||||
|
import com.warmer.meta.entity.MetaDataTable;
|
||||||
|
import com.warmer.meta.service.MetaDataColumnService;
|
||||||
|
import com.warmer.meta.vo.DataColumnVo;
|
||||||
|
import com.warmer.meta.vo.DataTableVo;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (MetaDataColumn)表服务实现类
|
||||||
|
*
|
||||||
|
* @author tanc
|
||||||
|
* @since 2021-11-21 11:00:15
|
||||||
|
*/
|
||||||
|
@Service("metaDataColumnService")
|
||||||
|
public class MetaDataColumnServiceImpl implements MetaDataColumnService {
|
||||||
|
@Resource
|
||||||
|
private MetaDataColumnDao metaDataColumnDao;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过ID查询单条数据
|
||||||
|
*
|
||||||
|
* @param dataColumnId 主键
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public MetaDataColumn queryById(Integer dataColumnId) {
|
||||||
|
return this.metaDataColumnDao.queryById(dataColumnId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询多条数据
|
||||||
|
*
|
||||||
|
* @return 对象列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<MetaDataColumn> queryAll() {
|
||||||
|
return this.metaDataColumnDao.queryAll();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public List<DataColumnVo> queryByTableId(Integer tableId){
|
||||||
|
List<MetaDataColumn> dataColumns= this.metaDataColumnDao.queryByTableId(tableId);
|
||||||
|
List<DataColumnVo> voList = dataColumns.stream().map(n -> {
|
||||||
|
DataColumnVo item = new DataColumnVo();
|
||||||
|
item.setDataColumnId(n.getDataColumnId());
|
||||||
|
item.setDataColumnName(n.getDataColumnCode());
|
||||||
|
item.setDataColumnAlia(n.getDataColumnName());
|
||||||
|
item.setDataColumnType(n.getDataColumnType());
|
||||||
|
item.setIsPrimary(n.getIsPrimary());
|
||||||
|
return item;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
return voList;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 新增数据
|
||||||
|
*
|
||||||
|
* @param metaDataColumn 实例对象
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public MetaDataColumn insert(MetaDataColumn metaDataColumn) {
|
||||||
|
this.metaDataColumnDao.insert(metaDataColumn);
|
||||||
|
return metaDataColumn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改数据
|
||||||
|
*
|
||||||
|
* @param metaDataColumn 实例对象
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public MetaDataColumn update(MetaDataColumn metaDataColumn) {
|
||||||
|
this.metaDataColumnDao.update(metaDataColumn);
|
||||||
|
return this.queryById(metaDataColumn.getDataColumnId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过主键删除数据
|
||||||
|
*
|
||||||
|
* @param dataColumnId 主键
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean deleteById(Integer dataColumnId) {
|
||||||
|
return this.metaDataColumnDao.deleteById(dataColumnId) > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,114 @@
|
|||||||
|
package com.warmer.meta.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import com.warmer.base.util.DbUtils;
|
||||||
|
import com.warmer.meta.dto.DataTableSubmitItem;
|
||||||
|
import com.warmer.meta.entity.MetaDataSource;
|
||||||
|
import com.warmer.meta.dao.MetaDataSourceDao;
|
||||||
|
import com.warmer.meta.entity.MetaDataTable;
|
||||||
|
import com.warmer.meta.service.MetaDataSourceService;
|
||||||
|
import com.warmer.meta.vo.DatasourceVo;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据源(MetaDataSource)表服务实现类
|
||||||
|
*
|
||||||
|
* @author tanc
|
||||||
|
* @since 2021-11-21 11:00:19
|
||||||
|
*/
|
||||||
|
@Service("metaDataSourceService")
|
||||||
|
public class MetaDataSourceServiceImpl implements MetaDataSourceService {
|
||||||
|
@Resource
|
||||||
|
private MetaDataSourceDao metaDataSourceDao;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过ID查询单条数据
|
||||||
|
*
|
||||||
|
* @param dataSourceId 主键
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public MetaDataSource queryById(Integer dataSourceId) {
|
||||||
|
return this.metaDataSourceDao.queryById(dataSourceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DatasourceVo> queryList() {
|
||||||
|
List<MetaDataSource> dataSources= this.metaDataSourceDao.queryAll();
|
||||||
|
List<DatasourceVo> voList = dataSources.stream().map(n -> {
|
||||||
|
DatasourceVo item = new DatasourceVo();
|
||||||
|
item.setDatasourceId(n.getDataSourceId());
|
||||||
|
item.setDatasourceAlia(n.getDbName());
|
||||||
|
item.setDatasourceName(n.getDbCode());
|
||||||
|
item.setDatasourceType(n.getDbType());
|
||||||
|
return item;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
return voList;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 查询多条数据
|
||||||
|
*
|
||||||
|
* @return 对象列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<MetaDataSource> queryAll() {
|
||||||
|
return this.metaDataSourceDao.queryAll();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 新增数据
|
||||||
|
*
|
||||||
|
* @param metaDataSource 实例对象
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public MetaDataSource insert(MetaDataSource metaDataSource) {
|
||||||
|
this.metaDataSourceDao.insert(metaDataSource);
|
||||||
|
return metaDataSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改数据
|
||||||
|
*
|
||||||
|
* @param metaDataSource 实例对象
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public MetaDataSource update(MetaDataSource metaDataSource) {
|
||||||
|
this.metaDataSourceDao.update(metaDataSource);
|
||||||
|
return this.queryById(metaDataSource.getDataSourceId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过主键删除数据
|
||||||
|
*
|
||||||
|
* @param dataSourceId 主键
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean deleteById(Integer dataSourceId) {
|
||||||
|
return this.metaDataSourceDao.deleteById(dataSourceId) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<String, ArrayList<HashMap<String, String>>> getMetaData(MetaDataSource metaDataSource) {
|
||||||
|
String dbType = metaDataSource.getDbType();
|
||||||
|
String userName = metaDataSource.getDbUserName();
|
||||||
|
String password = metaDataSource.getDbPassWord();
|
||||||
|
String driverClassName = metaDataSource.getDriverName();
|
||||||
|
HashMap<String, ArrayList<HashMap<String, String>>> result = null;
|
||||||
|
try {
|
||||||
|
result = DbUtils.getMetaData(dbType, metaDataSource.getDbCode(), metaDataSource.getConnectUrl(), userName, password,
|
||||||
|
driverClassName);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,183 @@
|
|||||||
|
package com.warmer.meta.service.impl;
|
||||||
|
|
||||||
|
import com.warmer.base.common.PageRecord;
|
||||||
|
import com.warmer.base.util.DbUtils;
|
||||||
|
import com.warmer.meta.dao.MetaDataColumnDao;
|
||||||
|
import com.warmer.meta.dao.MetaDataSourceDao;
|
||||||
|
import com.warmer.meta.dto.DataTableSubmitItem;
|
||||||
|
import com.warmer.meta.entity.MetaDataColumn;
|
||||||
|
import com.warmer.meta.entity.MetaDataSource;
|
||||||
|
import com.warmer.meta.entity.MetaDataTable;
|
||||||
|
import com.warmer.meta.dao.MetaDataTableDao;
|
||||||
|
import com.warmer.meta.query.TableQuery;
|
||||||
|
import com.warmer.meta.service.MetaDataColumnService;
|
||||||
|
import com.warmer.meta.service.MetaDataSourceService;
|
||||||
|
import com.warmer.meta.service.MetaDataTableService;
|
||||||
|
import com.warmer.meta.vo.DataColumnVo;
|
||||||
|
import com.warmer.meta.vo.DataTableVo;
|
||||||
|
import com.warmer.meta.vo.DatasourceVo;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (MetaDataTable)表服务实现类
|
||||||
|
*
|
||||||
|
* @author tanc
|
||||||
|
* @since 2021-11-21 11:00:22
|
||||||
|
*/
|
||||||
|
@Service("metaDataTableService")
|
||||||
|
public class MetaDataTableServiceImpl implements MetaDataTableService {
|
||||||
|
@Resource
|
||||||
|
private MetaDataSourceDao metaDataSourceDao;
|
||||||
|
@Resource
|
||||||
|
private MetaDataTableDao metaDataTableDao;
|
||||||
|
@Resource
|
||||||
|
private MetaDataColumnService metaDataColumnService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过ID查询单条数据
|
||||||
|
*
|
||||||
|
* @param dataTableId 主键
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public MetaDataTable queryById(Integer dataTableId) {
|
||||||
|
return this.metaDataTableDao.queryById(dataTableId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询多条数据
|
||||||
|
*
|
||||||
|
* @return 对象列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<MetaDataTable> queryAll() {
|
||||||
|
return this.metaDataTableDao.queryAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<DataTableVo> queryByDatasourceId(Integer datasourceId) {
|
||||||
|
List<MetaDataTable> dataTable = this.metaDataTableDao.queryByDatasourceId(datasourceId);
|
||||||
|
List<DataTableVo> voList = dataTable.stream().map(n -> {
|
||||||
|
DataTableVo item = new DataTableVo();
|
||||||
|
item.setDataTableId(n.getDataTableId());
|
||||||
|
item.setDatasourceId(n.getDatasourceId());
|
||||||
|
item.setDataTableAlia(n.getDataTableName());
|
||||||
|
item.setDataTableName(n.getDataTableCode());
|
||||||
|
return item;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
return voList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增数据
|
||||||
|
*
|
||||||
|
* @param metaDataTable 实例对象
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public MetaDataTable insert(MetaDataTable metaDataTable) {
|
||||||
|
this.metaDataTableDao.insert(metaDataTable);
|
||||||
|
return metaDataTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改数据
|
||||||
|
*
|
||||||
|
* @param metaDataTable 实例对象
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public MetaDataTable update(MetaDataTable metaDataTable) {
|
||||||
|
this.metaDataTableDao.update(metaDataTable);
|
||||||
|
return this.queryById(metaDataTable.getDataTableId());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过主键删除数据
|
||||||
|
*
|
||||||
|
* @param dataTableId 主键
|
||||||
|
* @return 是否成功
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean deleteById(Integer dataTableId) {
|
||||||
|
return this.metaDataTableDao.deleteById(dataTableId) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ArrayList<String> getMetaTables(MetaDataSource metaDataSource) {
|
||||||
|
String dbType = metaDataSource.getDbType();
|
||||||
|
String userName = metaDataSource.getDbUserName();
|
||||||
|
String password = metaDataSource.getDbPassWord();
|
||||||
|
String driverClassName = metaDataSource.getDriverName();
|
||||||
|
ArrayList<String> tables = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
tables = DbUtils.getTables(dbType, metaDataSource.getDbCode(), userName, password,
|
||||||
|
driverClassName, metaDataSource.getConnectUrl());
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
return tables;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void saveTables(DataTableSubmitItem submitItem) {
|
||||||
|
MetaDataSource dataSource = metaDataSourceDao.queryById(submitItem.getDataSourceId());
|
||||||
|
String dbType = dataSource.getDbType();
|
||||||
|
String userName = dataSource.getDbUserName();
|
||||||
|
String password = dataSource.getDbPassWord();
|
||||||
|
String driverClassName = dataSource.getDriverName();
|
||||||
|
HashMap<String, ArrayList<HashMap<String, String>>> metaData = DbUtils.getMetaData(dbType, dataSource.getDbCode(), dataSource.getConnectUrl(), userName, password,
|
||||||
|
driverClassName, submitItem.getDataTables());
|
||||||
|
for (String table : metaData.keySet()) {
|
||||||
|
MetaDataTable dataTable = new MetaDataTable();
|
||||||
|
dataTable.setDataTableName(table);
|
||||||
|
dataTable.setDataTableCode(table);
|
||||||
|
dataTable.setDatasourceId(dataSource.getDataSourceId());
|
||||||
|
insert(dataTable);
|
||||||
|
Integer tableId = dataTable.getDataTableId();
|
||||||
|
ArrayList<HashMap<String, String>> columns = metaData.get(table);
|
||||||
|
for (HashMap<String, String> column : columns) {
|
||||||
|
String columnName = column.get("ColumnName");
|
||||||
|
String columnAlia = column.get("ColumnAlia");
|
||||||
|
String columnType = column.get("ColumnType");
|
||||||
|
String isPrimary = column.get("IsPrimary");
|
||||||
|
MetaDataColumn columnItem = new MetaDataColumn();
|
||||||
|
columnItem.setDataColumnCode(columnName);
|
||||||
|
columnItem.setDataColumnName(columnAlia);
|
||||||
|
columnItem.setDataColumnComment(columnAlia);
|
||||||
|
columnItem.setDataColumnType(columnType);
|
||||||
|
columnItem.setDataTableId(tableId);
|
||||||
|
columnItem.setIsPrimary(isPrimary.equals("1") ? 1 : 0);
|
||||||
|
metaDataColumnService.insert(columnItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public PageRecord<Map<String, Object>> getTableRecords(TableQuery queryItem) {
|
||||||
|
MetaDataSource metaDataSource = metaDataSourceDao.queryById(queryItem.getDataSourceId());
|
||||||
|
String dbType = metaDataSource.getDbType();
|
||||||
|
String userName = metaDataSource.getDbUserName();
|
||||||
|
String password = metaDataSource.getDbPassWord();
|
||||||
|
String driverClassName = metaDataSource.getDriverName();
|
||||||
|
PageRecord<Map<String, Object>> records = new PageRecord<>();
|
||||||
|
MetaDataTable metaDataTable = metaDataTableDao.queryByDatasourceIdAndTableCode(queryItem.getDataSourceId(), queryItem.getDataTableName());
|
||||||
|
List<DataColumnVo> dataColumnVos = metaDataColumnService.queryByTableId(metaDataTable.getDataTableId());
|
||||||
|
try {
|
||||||
|
records = DbUtils.getTableInfoByPage(queryItem.getCurrentPage(), queryItem.getPageSize(), dbType, metaDataSource.getDbCode(), metaDataSource.getConnectUrl(), queryItem.getDataTableName(), userName, password,
|
||||||
|
driverClassName, 10, queryItem.getFilterItems());
|
||||||
|
records.setHeads(dataColumnVos);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
return records;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
package com.warmer.meta.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class DataColumnVo {
|
||||||
|
private String DataColumnName;
|
||||||
|
private Integer DataColumnId;
|
||||||
|
private String DataColumnAlia;
|
||||||
|
private String DataColumnType;
|
||||||
|
private Integer IsPrimary;
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
package com.warmer.meta.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class DataTableVo {
|
||||||
|
private String DataTableName;
|
||||||
|
private Integer DataTableId;
|
||||||
|
private Integer DatasourceId;
|
||||||
|
private String DataTableAlia;
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
package com.warmer.meta.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class DatasourceVo {
|
||||||
|
private String DatasourceName;
|
||||||
|
private Integer DatasourceId;
|
||||||
|
private String DatasourceType;
|
||||||
|
private String DatasourceAlia;
|
||||||
|
}
|
||||||
@ -0,0 +1,61 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.warmer.meta.dao.MetaDataColumnDao">
|
||||||
|
|
||||||
|
<resultMap id="BaseResultMap" type="com.warmer.meta.entity.MetaDataColumn">
|
||||||
|
<!--@Table meta_data_column-->
|
||||||
|
<result property="dataColumnId" column="DataColumnId" jdbcType="INTEGER"/>
|
||||||
|
<result property="dataTableId" column="DataTableId" jdbcType="INTEGER"/>
|
||||||
|
<result property="dataColumnCode" column="DataColumnCode" jdbcType="VARCHAR"/>
|
||||||
|
<result property="dataColumnName" column="DataColumnName" jdbcType="VARCHAR"/>
|
||||||
|
<result property="dataColumnComment" column="DataColumnComment" jdbcType="VARCHAR"/>
|
||||||
|
<result property="dataColumnType" column="DataColumnType" jdbcType="VARCHAR"/>
|
||||||
|
<result property="isPrimary" column="IsPrimary" jdbcType="INTEGER"/>
|
||||||
|
<result property="status" column="Status" jdbcType="INTEGER"/>
|
||||||
|
<result property="createUser" column="CreateUser" jdbcType="VARCHAR"/>
|
||||||
|
<result property="createTime" column="CreateTime" jdbcType="TIMESTAMP"/>
|
||||||
|
<result property="updateUser" column="UpdateUser" jdbcType="VARCHAR"/>
|
||||||
|
<result property="updateTime" column="UpdateTime" jdbcType="TIMESTAMP"/>
|
||||||
|
</resultMap>
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
DataColumnId, DataTableId, DataColumnCode,IsPrimary, DataColumnName, DataColumnComment, DataColumnType, Status, CreateUser, CreateTime, UpdateUser, UpdateTime </sql>
|
||||||
|
<!--查询单个-->
|
||||||
|
<select id="queryById" resultMap="BaseResultMap">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List" />
|
||||||
|
from meta_data_column
|
||||||
|
where DataColumnId = #{datacolumnid}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
<!--通过实体作为筛选条件查询-->
|
||||||
|
<select id="queryAll" resultMap="BaseResultMap">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List" />
|
||||||
|
from meta_data_column
|
||||||
|
</select>
|
||||||
|
<select id="queryByTableId" resultMap="BaseResultMap">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List" />
|
||||||
|
from meta_data_column where DataTableId=#{dataTableId}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!--新增所有列-->
|
||||||
|
<insert id="insert" keyProperty="dataColumnId" useGeneratedKeys="true">
|
||||||
|
insert into meta_data_column(DataTableId, DataColumnCode, DataColumnName, DataColumnComment, DataColumnType,IsPrimary, Status, CreateUser, CreateTime, UpdateUser, UpdateTime)
|
||||||
|
values (#{dataTableId}, #{dataColumnCode}, #{dataColumnName}, #{dataColumnComment}, #{dataColumnType},#{isPrimary}, #{status}, #{createUser}, #{createTime}, #{updateUser}, #{updateTime})
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<!--通过主键修改数据-->
|
||||||
|
<update id="update">
|
||||||
|
update meta_data_column
|
||||||
|
set
|
||||||
|
where DataColumnId = #{datacolumnid}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<!--通过主键删除-->
|
||||||
|
<update id="deleteById">
|
||||||
|
update meta_data_column set Status=0 where DataColumnId = #{datacolumnid}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@ -0,0 +1,61 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.warmer.meta.dao.MetaDataSourceDao">
|
||||||
|
|
||||||
|
<resultMap id="BaseResultMap" type="com.warmer.meta.entity.MetaDataSource">
|
||||||
|
<!--@Table meta_data_source-->
|
||||||
|
<result property="dataSourceId" column="DataSourceId" jdbcType="INTEGER"/>
|
||||||
|
<result property="dbType" column="DbType" jdbcType="VARCHAR"/>
|
||||||
|
<result property="driverName" column="DriverName" jdbcType="VARCHAR"/>
|
||||||
|
<result property="iPAndPort" column="IPAndPort" jdbcType="VARCHAR"/>
|
||||||
|
<result property="connectUrl" column="ConnectUrl" jdbcType="VARCHAR"/>
|
||||||
|
<result property="dbName" column="DbName" jdbcType="VARCHAR"/>
|
||||||
|
<result property="dbCode" column="DbCode" jdbcType="VARCHAR"/>
|
||||||
|
<result property="dbUserName" column="DbUserName" jdbcType="VARCHAR"/>
|
||||||
|
<result property="dbPassWord" column="DbPassWord" jdbcType="VARCHAR"/>
|
||||||
|
<result property="maxPoolSize" column="MaxPoolSize" jdbcType="INTEGER"/>
|
||||||
|
<result property="status" column="Status" jdbcType="INTEGER"/>
|
||||||
|
<result property="databaseCoding" column="DatabaseCoding" jdbcType="VARCHAR"/>
|
||||||
|
<result property="transcoding" column="Transcoding" jdbcType="VARCHAR"/>
|
||||||
|
<result property="createUser" column="CreateUser" jdbcType="VARCHAR"/>
|
||||||
|
<result property="createTime" column="CreateTime" jdbcType="TIMESTAMP"/>
|
||||||
|
<result property="updateUser" column="UpdateUser" jdbcType="VARCHAR"/>
|
||||||
|
<result property="updateTime" column="UpdateTime" jdbcType="TIMESTAMP"/>
|
||||||
|
</resultMap>
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
DataSourceId, DbType, DriverName, IPAndPort, ConnectUrl, DbName, DbCode, DbUserName, DbPassWord, MaxPoolSize, Status, DatabaseCoding, Transcoding, CreateUser, CreateTime, UpdateUser, UpdateTime </sql>
|
||||||
|
<!--查询单个-->
|
||||||
|
<select id="queryById" resultMap="BaseResultMap">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List" />
|
||||||
|
from meta_data_source
|
||||||
|
where DataSourceId = #{datasourceid}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
<!--通过实体作为筛选条件查询-->
|
||||||
|
<select id="queryAll" resultMap="BaseResultMap">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List" />
|
||||||
|
from meta_data_source
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!--新增所有列-->
|
||||||
|
<insert id="insert" keyProperty="dataSourceId" useGeneratedKeys="true">
|
||||||
|
insert into meta_data_source(DbType, DriverName, IPAndPort, ConnectUrl, DbName, DbCode, DbUserName, DbPassWord, MaxPoolSize, Status, DatabaseCoding, Transcoding, CreateUser, CreateTime, UpdateUser, UpdateTime)
|
||||||
|
values (#{dbType}, #{driverName}, #{iPAndPort}, #{connectUrl}, #{dbName}, #{dbCode}, #{dbUserName}, #{dbPassWord}, #{maxPoolSize}, #{status}, #{databaseCoding}, #{transcoding}, #{createUser}, #{createTime}, #{updateUser}, #{updateTime})
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<!--通过主键修改数据-->
|
||||||
|
<update id="update">
|
||||||
|
update meta_data_source
|
||||||
|
set
|
||||||
|
where DataSourceId = #{datasourceid}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<!--通过主键删除-->
|
||||||
|
<update id="deleteById">
|
||||||
|
update meta_data_source set Status=0 where DataSourceId = #{datasourceid}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@ -0,0 +1,62 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.warmer.meta.dao.MetaDataTableDao">
|
||||||
|
|
||||||
|
<resultMap id="BaseResultMap" type="com.warmer.meta.entity.MetaDataTable">
|
||||||
|
<!--@Table meta_data_table-->
|
||||||
|
<result property="dataTableId" column="DataTableId" jdbcType="INTEGER"/>
|
||||||
|
<result property="datasourceId" column="DatasourceId" jdbcType="INTEGER"/>
|
||||||
|
<result property="dataTableCode" column="DataTableCode" jdbcType="VARCHAR"/>
|
||||||
|
<result property="dataTableName" column="DataTableName" jdbcType="VARCHAR"/>
|
||||||
|
<result property="status" column="Status" jdbcType="INTEGER"/>
|
||||||
|
<result property="createUser" column="CreateUser" jdbcType="VARCHAR"/>
|
||||||
|
<result property="createTime" column="CreateTime" jdbcType="TIMESTAMP"/>
|
||||||
|
<result property="updateUser" column="UpdateUser" jdbcType="VARCHAR"/>
|
||||||
|
<result property="updateTime" column="UpdateTime" jdbcType="TIMESTAMP"/>
|
||||||
|
</resultMap>
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
DataTableId, DatasourceId, DataTableCode, DataTableName, Status, CreateUser, CreateTime, UpdateUser, UpdateTime </sql>
|
||||||
|
<!--查询单个-->
|
||||||
|
<select id="queryById" resultMap="BaseResultMap">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List" />
|
||||||
|
from meta_data_table
|
||||||
|
where DataTableId = #{datatableid}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
<!--通过实体作为筛选条件查询-->
|
||||||
|
<select id="queryAll" resultMap="BaseResultMap">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List" />
|
||||||
|
from meta_data_table
|
||||||
|
</select>
|
||||||
|
<select id="queryByDatasourceId" resultMap="BaseResultMap">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List" />
|
||||||
|
from meta_data_table where DatasourceId=#{datasourceId}
|
||||||
|
</select>
|
||||||
|
<select id="queryByDatasourceIdAndTableCode" resultMap="BaseResultMap">
|
||||||
|
select
|
||||||
|
<include refid="Base_Column_List" />
|
||||||
|
from meta_data_table where DatasourceId=#{datasourceId} and DataTableCode=#{dataTableCode}
|
||||||
|
</select>
|
||||||
|
<!--新增所有列-->
|
||||||
|
<insert id="insert" keyProperty="dataTableId" useGeneratedKeys="true">
|
||||||
|
insert into meta_data_table(DatasourceId, DataTableCode, DataTableName, Status, CreateUser, CreateTime, UpdateUser, UpdateTime)
|
||||||
|
values (#{datasourceId}, #{dataTableCode}, #{dataTableName}, #{status}, #{createUser}, #{createTime}, #{updateUser}, #{updateTime})
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<!--通过主键修改数据-->
|
||||||
|
<update id="update">
|
||||||
|
update meta_data_table
|
||||||
|
set
|
||||||
|
where DataTableId = #{datatableid}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<!--通过主键删除-->
|
||||||
|
<update id="deleteById">
|
||||||
|
update meta_data_table set Status=0 where DataTableId = #{datatableid}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
71
kgBuilder-pro/pom.xml
Normal file
71
kgBuilder-pro/pom.xml
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.warmer</groupId>
|
||||||
|
<artifactId>kgbuilder</artifactId>
|
||||||
|
<version>0.0.1</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
<groupId>com.warmer</groupId>
|
||||||
|
<artifactId>kgBuilder-pro</artifactId>
|
||||||
|
<version>release</version>
|
||||||
|
<name>kgBuilder-pro</name>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<description>Demo project for Spring Boot</description>
|
||||||
|
<properties>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.warmer</groupId>
|
||||||
|
<artifactId>kgBuilder-base</artifactId>
|
||||||
|
<version>0.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.warmer</groupId>
|
||||||
|
<artifactId>kgBuilder-meta</artifactId>
|
||||||
|
<version>0.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-jdbc</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.neo4j.driver</groupId>
|
||||||
|
<artifactId>neo4j-java-driver</artifactId>
|
||||||
|
<version>4.4.12</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<version>2.5.6</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
64
kgBuilder-pro/src/main/java/com/warmer/Application.java
Normal file
64
kgBuilder-pro/src/main/java/com/warmer/Application.java
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
package com.warmer;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import com.warmer.base.util.DateUtil;
|
||||||
|
import com.warmer.base.util.Neo4jUtil;
|
||||||
|
import com.warmer.web.entity.KgDomain;
|
||||||
|
import com.warmer.web.service.KGGraphService;
|
||||||
|
import com.warmer.web.service.KGManagerService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.ApplicationArguments;
|
||||||
|
import org.springframework.boot.ApplicationRunner;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
@ComponentScan(basePackages = {"com.warmer"})
|
||||||
|
public class Application implements ApplicationRunner {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private KGManagerService kgManagerService;
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(Application.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启动时初始化现有的neo4j 标签到mysql
|
||||||
|
* 将标签同步到mysql管理是为了权限区分,根据需要选择,mysql不是必须
|
||||||
|
* @param args
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void run(ApplicationArguments args) throws Exception {
|
||||||
|
Map<String, Object> labelsInfo = Neo4jUtil.getLabelsInfo();
|
||||||
|
if(labelsInfo!=null&&labelsInfo.keySet().size()>0){
|
||||||
|
for (String label : labelsInfo.keySet()) {
|
||||||
|
long value=(Long) labelsInfo.get(label);
|
||||||
|
KgDomain domainModel = kgManagerService.getDomainByLabel(label);
|
||||||
|
if(domainModel!=null){
|
||||||
|
domainModel.setModifyTime(DateUtil.getDateNow());
|
||||||
|
domainModel.setModifyUser("sa");
|
||||||
|
domainModel.setNodeCount(value);
|
||||||
|
kgManagerService.updateDomain(domainModel);
|
||||||
|
}else {
|
||||||
|
domainModel=KgDomain.builder()
|
||||||
|
.label(label)
|
||||||
|
.name(label)
|
||||||
|
.nodeCount(value)
|
||||||
|
.createTime(DateUtil.getDateNow())
|
||||||
|
.shipCount(0)
|
||||||
|
.type(0)
|
||||||
|
.status(1)
|
||||||
|
.commend(0)
|
||||||
|
.build();
|
||||||
|
kgManagerService.saveDomain(domainModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
package com.warmer.web.config;
|
||||||
|
|
||||||
|
import org.neo4j.driver.AuthTokens;
|
||||||
|
import org.neo4j.driver.Driver;
|
||||||
|
import org.neo4j.driver.GraphDatabase;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "spring.neo4j") //指明配置节点
|
||||||
|
public class Neo4jConfig {
|
||||||
|
@Value("${spring.neo4j.url}")
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
@Value("${spring.neo4j.username}")
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
@Value("${spring.neo4j.password}")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图数据库驱动模式
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Driver neo4jDriver() {
|
||||||
|
return GraphDatabase.driver(url, AuthTokens.basic(username, password));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
|
||||||
|
package com.warmer.web.config;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@Data
|
||||||
|
public class WebAppConfig{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在配置文件中配置的文件保存路径
|
||||||
|
*/
|
||||||
|
@Value("${file.location}")
|
||||||
|
private String location;
|
||||||
|
|
||||||
|
public String getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocation(String location) {
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
package com.warmer.web.controller;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class BaseController {
|
||||||
|
Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
}
|
||||||
@ -0,0 +1,101 @@
|
|||||||
|
package com.warmer.web.controller;
|
||||||
|
|
||||||
|
import com.warmer.base.util.R;
|
||||||
|
import com.warmer.base.util.StringUtil;
|
||||||
|
import com.warmer.web.entity.CategoryNode;
|
||||||
|
import com.warmer.web.model.TreeExcel;
|
||||||
|
import com.warmer.web.model.TreeExcelRecordData;
|
||||||
|
import com.warmer.web.service.CategoryNodeService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public class CategoryController extends BaseController{
|
||||||
|
@Autowired
|
||||||
|
CategoryNodeService categoryNodeService;
|
||||||
|
@PostMapping("/importKGNodes")
|
||||||
|
@ResponseBody
|
||||||
|
public R<String> importKGNodes(Long categoryId, Integer parentId, HttpServletRequest request) {
|
||||||
|
if (parentId == null) {
|
||||||
|
parentId = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
String parentCode="";
|
||||||
|
CategoryNode searchCategoryDetail = categoryNodeService.selectByPrimaryKey(parentId);
|
||||||
|
if(searchCategoryDetail!=null){
|
||||||
|
parentCode=searchCategoryDetail.getSystemCode();
|
||||||
|
}
|
||||||
|
MultipartHttpServletRequest multipartHttpServletRequest = (MultipartHttpServletRequest) request;
|
||||||
|
MultipartFile file = multipartHttpServletRequest.getFile("file");
|
||||||
|
String count = "";
|
||||||
|
try {
|
||||||
|
if (file == null) {
|
||||||
|
return R.error("请上传 有效的excel的文件");
|
||||||
|
}
|
||||||
|
String fileName = file.getOriginalFilename();
|
||||||
|
String extName = fileName != null ? fileName.substring(fileName.lastIndexOf(".")) : null;
|
||||||
|
|
||||||
|
if (StringUtil.isBlank(fileName) || (!extName.equals(".xls") && !extName.equals(".xlsx"))) {
|
||||||
|
return R.error("请上传 xls 或 xlsx 类型的文件");
|
||||||
|
}
|
||||||
|
TreeExcel treeExcel = new TreeExcel(String.valueOf(parentId), parentCode, fileName, file.getInputStream(), new TreeExcel.IResultHandler() {
|
||||||
|
@Override
|
||||||
|
public TreeExcelRecordData store(String cellVal, String cellColor, TreeExcelRecordData parent, boolean isLeaf) {
|
||||||
|
CategoryNode submitItem = new CategoryNode();
|
||||||
|
submitItem.setCategoryNodeName(cellVal);
|
||||||
|
submitItem.setCreateUser("tc");
|
||||||
|
submitItem.setUpdateUser("tc");
|
||||||
|
submitItem.setSystemCode("");
|
||||||
|
submitItem.setCategoryId(categoryId);
|
||||||
|
List<CategoryNode> brotherNodes = categoryNodeService.selectByParentIdAndName(categoryId, Integer.parseInt(parent.getRecordId()), cellVal.trim());
|
||||||
|
if (brotherNodes != null && brotherNodes.size() > 0) { // 如果同一级下已有同名的,不在新增。
|
||||||
|
TreeExcelRecordData data = new TreeExcelRecordData();
|
||||||
|
data.setRecordId(String.valueOf(brotherNodes.get(0).getCategoryNodeId()));
|
||||||
|
data.setClassCode(brotherNodes.get(0).getSystemCode());
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
Integer parentId = parent.getRecordId() != null ? Integer.parseInt(parent.getRecordId()) : 0;
|
||||||
|
submitItem.setParentId(parentId);
|
||||||
|
int parentIsLeaf = 0;
|
||||||
|
if (parentId == 0) {
|
||||||
|
submitItem.setTreeLevel(0);
|
||||||
|
} else {
|
||||||
|
CategoryNode parentNode = categoryNodeService.selectByPrimaryKey(parentId);
|
||||||
|
if (parentNode != null) {
|
||||||
|
if(parentNode.getTreeLevel()==null){
|
||||||
|
parentNode.setTreeLevel(0);
|
||||||
|
}
|
||||||
|
submitItem.setTreeLevel(parentNode.getTreeLevel() + 1);
|
||||||
|
parentIsLeaf = parentNode.getIsLeaf();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
submitItem.setIsLeaf(isLeaf ? 1 : 0);
|
||||||
|
categoryNodeService.insert(submitItem);
|
||||||
|
Integer id = submitItem.getCategoryNodeId();
|
||||||
|
String classCode = String.format("%s%s%s", parent.getClassCode() != null ? parent.getClassCode() : "", StringUtil.isNotBlank(parent.getClassCode()) ? "/" : "", id);
|
||||||
|
categoryNodeService.updateCodeByPrimaryKey(id, classCode);
|
||||||
|
if (parentIsLeaf == 1) {
|
||||||
|
categoryNodeService.updateLeafStatusByPrimaryKey(parentId, 0);
|
||||||
|
}
|
||||||
|
TreeExcelRecordData data = new TreeExcelRecordData();
|
||||||
|
data.setRecordId(String.valueOf(id));
|
||||||
|
data.setClassCode(classCode);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
treeExcel.handleByStream();
|
||||||
|
return R.success(count);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
log.error(e.getMessage());
|
||||||
|
return R.error("处理失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,116 @@
|
|||||||
|
package com.warmer.web.controller;
|
||||||
|
|
||||||
|
import com.warmer.base.common.PageRecord;
|
||||||
|
import com.warmer.base.util.R;
|
||||||
|
import com.warmer.meta.dto.DataTableSubmitItem;
|
||||||
|
import com.warmer.meta.dto.DatasourceSubmitItem;
|
||||||
|
import com.warmer.meta.entity.MetaDataSource;
|
||||||
|
import com.warmer.meta.entity.MetaDataTable;
|
||||||
|
import com.warmer.meta.query.TableQuery;
|
||||||
|
import com.warmer.meta.service.MetaDataColumnService;
|
||||||
|
import com.warmer.meta.service.MetaDataSourceService;
|
||||||
|
import com.warmer.meta.service.MetaDataTableService;
|
||||||
|
import com.warmer.meta.vo.DataColumnVo;
|
||||||
|
import com.warmer.meta.vo.DataTableVo;
|
||||||
|
import com.warmer.meta.vo.DatasourceVo;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/datasource")
|
||||||
|
public class DatasourceController extends BaseController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
MetaDataSourceService metaDataSourceService;
|
||||||
|
@Autowired
|
||||||
|
MetaDataTableService metaDataTableService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
MetaDataColumnService metaDataColumnService;
|
||||||
|
|
||||||
|
@GetMapping("/getDataSource")
|
||||||
|
@ResponseBody
|
||||||
|
public R<List<DatasourceVo>> getDataSource() {
|
||||||
|
List<DatasourceVo> voList = metaDataSourceService.queryList();
|
||||||
|
return R.success(voList, "操作成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/getDataTable")
|
||||||
|
@ResponseBody
|
||||||
|
public R<List<DataTableVo>> getDataTable(Integer datasourceId) {
|
||||||
|
List<DataTableVo> voList = metaDataTableService.queryByDatasourceId(datasourceId);
|
||||||
|
return R.success(voList, "操作成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/getDataColumn")
|
||||||
|
@ResponseBody
|
||||||
|
public R<List<DataColumnVo>> getDataColumn(Integer dataTableId) {
|
||||||
|
List<DataColumnVo> voList = metaDataColumnService.queryByTableId(dataTableId);
|
||||||
|
return R.success(voList, "操作成功");
|
||||||
|
}
|
||||||
|
@GetMapping("/getDataTableInfo")
|
||||||
|
@ResponseBody
|
||||||
|
public R<Map<String,Object>> getDataTableInfo(Integer dataTableId) {
|
||||||
|
Map<String,Object> data=new HashMap<>();
|
||||||
|
MetaDataTable metaDataTable = metaDataTableService.queryById(dataTableId);
|
||||||
|
DataTableVo tableItem=new DataTableVo();
|
||||||
|
tableItem.setDataTableId(metaDataTable.getDataTableId());
|
||||||
|
tableItem.setDatasourceId(metaDataTable.getDatasourceId());
|
||||||
|
tableItem.setDataTableName(metaDataTable.getDataTableCode());
|
||||||
|
tableItem.setDataTableAlia(metaDataTable.getDataTableName());
|
||||||
|
data.put("table",tableItem);
|
||||||
|
List<DataColumnVo> voList = metaDataColumnService.queryByTableId(dataTableId);
|
||||||
|
data.put("column",voList);
|
||||||
|
return R.success(data, "操作成功");
|
||||||
|
}
|
||||||
|
@PostMapping("/getTableRecords")
|
||||||
|
@ResponseBody
|
||||||
|
public R<PageRecord<Map<String, Object>>> getTableRecords(@RequestBody TableQuery queryItem) {
|
||||||
|
PageRecord<Map<String, Object>> voList = metaDataTableService.getTableRecords(queryItem);
|
||||||
|
return R.success(voList, "操作成功");
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 保存数据源
|
||||||
|
*
|
||||||
|
* @param submitItem
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@ResponseBody
|
||||||
|
@PostMapping(value = "/saveDataSource")
|
||||||
|
public R<Map<String,Object>> saveDataSource(@RequestBody DatasourceSubmitItem submitItem) {
|
||||||
|
Map<String,Object> result=new HashMap<>();
|
||||||
|
if (submitItem.getDataSourceId() == 0) {
|
||||||
|
// 插入指标来源
|
||||||
|
MetaDataSource dataSource = metaDataSourceService.insert(submitItem.transfer());
|
||||||
|
ArrayList<String> tableList = metaDataTableService.getMetaTables(submitItem.transfer());
|
||||||
|
result.put("sourceId",dataSource.getDataSourceId());
|
||||||
|
result.put("tables",tableList);
|
||||||
|
}else{
|
||||||
|
return R.error("暂不支持编辑");
|
||||||
|
}
|
||||||
|
return R.success(result, "操作成功");
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 保存数据源
|
||||||
|
*
|
||||||
|
* @param submitItem
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@ResponseBody
|
||||||
|
@RequestMapping(value = "/saveDataTable")
|
||||||
|
public R<Map<String,Object>> saveDataTable(@RequestBody DataTableSubmitItem submitItem) {
|
||||||
|
Map<String,Object> result=new HashMap<>();
|
||||||
|
MetaDataSource dataSource = metaDataSourceService.queryById(submitItem.getDataSourceId());
|
||||||
|
if(dataSource==null){
|
||||||
|
return R.error("数据源不存在");
|
||||||
|
}
|
||||||
|
metaDataTableService.saveTables(submitItem);
|
||||||
|
return R.success(result, "操作成功");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,60 @@
|
|||||||
|
package com.warmer.web.controller;
|
||||||
|
|
||||||
|
import com.warmer.base.util.R;
|
||||||
|
import com.warmer.web.entity.KgDomain;
|
||||||
|
import com.warmer.web.request.GraphItem;
|
||||||
|
import com.warmer.web.service.KgGraphNodeService;
|
||||||
|
import com.warmer.web.service.KGManagerService;
|
||||||
|
import com.warmer.web.service.impl.WorkFlowDirectorServiceImpl;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping(value = "/er")
|
||||||
|
public class ERBuilderController extends BaseController {
|
||||||
|
@Autowired
|
||||||
|
private KGManagerService kgService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private KgGraphNodeService kgGraphNodeService;
|
||||||
|
@Autowired
|
||||||
|
WorkFlowDirectorServiceImpl workFlowDirectorService;
|
||||||
|
@ResponseBody
|
||||||
|
@PostMapping(value = "/saveData")
|
||||||
|
public R<Map<String, Object>> saveDataSource(@RequestBody GraphItem submitItem) throws IOException {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
KgDomain domainItem = kgService.selectById(submitItem.getDomainId());
|
||||||
|
if (domainItem == null) {
|
||||||
|
return R.error("领域不存在");
|
||||||
|
}
|
||||||
|
kgGraphNodeService.createNode(submitItem);
|
||||||
|
return R.success(result, "操作成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
@ResponseBody
|
||||||
|
@GetMapping(value = "/getDomainNode")
|
||||||
|
public R<GraphItem> saveDataSource(Integer domainId) throws IOException {
|
||||||
|
KgDomain domainItem = kgService.selectById(domainId);
|
||||||
|
if (domainItem == null) {
|
||||||
|
return R.error("领域不存在");
|
||||||
|
}
|
||||||
|
GraphItem domainNode = kgGraphNodeService.getDomainNode(domainId);
|
||||||
|
return R.success(domainNode, "操作成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
@ResponseBody
|
||||||
|
@GetMapping(value = "/execute")
|
||||||
|
public R<GraphItem> execute(Integer domainId){
|
||||||
|
KgDomain domainItem = kgService.selectById(domainId);
|
||||||
|
if (domainItem == null) {
|
||||||
|
return R.error("领域不存在");
|
||||||
|
}
|
||||||
|
workFlowDirectorService.direct(domainId);
|
||||||
|
return R.success();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,114 @@
|
|||||||
|
package com.warmer.web.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import com.warmer.base.util.FileResponse;
|
||||||
|
import com.warmer.base.util.FileResult;
|
||||||
|
import com.warmer.web.config.WebAppConfig;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/file")
|
||||||
|
public class FileController extends BaseController {
|
||||||
|
@Autowired
|
||||||
|
private WebAppConfig appConfig;
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/upload")
|
||||||
|
@ResponseBody
|
||||||
|
public FileResponse upload(HttpServletRequest req) {
|
||||||
|
FileResponse res = new FileResponse();
|
||||||
|
List<FileResult> fre = new ArrayList<FileResult>();
|
||||||
|
List<MultipartFile> files = ((MultipartHttpServletRequest) req).getFiles("file");
|
||||||
|
String filePath = appConfig.getLocation();
|
||||||
|
try {
|
||||||
|
for (MultipartFile file : files) {
|
||||||
|
FileResult fileResult = new FileResult();
|
||||||
|
String rootFileName = file.getOriginalFilename();
|
||||||
|
String suffix= rootFileName.substring(rootFileName.lastIndexOf("."));
|
||||||
|
String fileName =filePath+ IdUtil.getSnowflakeNextIdStr()+"."+suffix;
|
||||||
|
File saveFile = new File(fileName);
|
||||||
|
file.transferTo(saveFile); // 文件保存
|
||||||
|
if (StringUtils.isNotBlank(fileName)) {
|
||||||
|
String success = "上传成功";
|
||||||
|
fileResult.setMessage(success);
|
||||||
|
fileResult.setName(rootFileName);
|
||||||
|
fileResult.setStatus(0);
|
||||||
|
String src="/file/download/";
|
||||||
|
fileResult.setUrl(src + fileName);
|
||||||
|
fre.add(fileResult);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res.setSuccess(1);
|
||||||
|
res.setMessage("操作成功");
|
||||||
|
res.setResults(fre);
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error(e.getMessage());
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
//文件下载相关代码
|
||||||
|
@GetMapping(value = "/download/{fileName}")
|
||||||
|
public String downloadImage(@PathVariable("fileName")String fileName, HttpServletResponse response) {
|
||||||
|
String filePath = appConfig.getLocation() ;
|
||||||
|
String fileUrl = filePath+ File.separator + fileName;
|
||||||
|
String[] arr = fileName.split("\\.");
|
||||||
|
String suffix = arr[1];
|
||||||
|
File file = new File(fileUrl);
|
||||||
|
|
||||||
|
if (file.exists()) {
|
||||||
|
//response.setContentType("application/force-download");// 设置强制下载不打开
|
||||||
|
response.addHeader("Content-Disposition","attachment;fileName=" + fileName);// 设置文件名
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
FileInputStream fis = null;
|
||||||
|
BufferedInputStream bis = null;
|
||||||
|
try {
|
||||||
|
fis = new FileInputStream(file);
|
||||||
|
bis = new BufferedInputStream(fis);
|
||||||
|
OutputStream os = response.getOutputStream();
|
||||||
|
if("csv".equalsIgnoreCase(suffix)){
|
||||||
|
//加上UTF-8文件的标识字符,避免乱码
|
||||||
|
os.write(new byte []{( byte ) 0xEF ,( byte ) 0xBB ,( byte ) 0xBF });
|
||||||
|
}
|
||||||
|
int i = bis.read(buffer);
|
||||||
|
while (i != -1) {
|
||||||
|
os.write(buffer, 0, i);
|
||||||
|
i = bis.read(buffer);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
if (bis != null) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
bis.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fis != null) {
|
||||||
|
try {
|
||||||
|
fis.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,687 @@
|
|||||||
|
package com.warmer.web.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.text.csv.CsvUtil;
|
||||||
|
import cn.hutool.core.text.csv.CsvWriter;
|
||||||
|
import cn.hutool.core.util.CharsetUtil;
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import com.warmer.base.enums.ReturnStatus;
|
||||||
|
import com.warmer.base.util.*;
|
||||||
|
import com.warmer.web.config.WebAppConfig;
|
||||||
|
import com.warmer.web.entity.KgDomain;
|
||||||
|
import com.warmer.web.entity.KgFeedBack;
|
||||||
|
import com.warmer.web.entity.KgNodeDetail;
|
||||||
|
import com.warmer.web.entity.KgNodeDetailFile;
|
||||||
|
import com.warmer.web.model.NodeItem;
|
||||||
|
import com.warmer.web.request.*;
|
||||||
|
import com.warmer.web.service.FeedBackService;
|
||||||
|
import com.warmer.web.service.KGGraphService;
|
||||||
|
import com.warmer.web.service.KGManagerService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Pattern;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(value = "/")
|
||||||
|
public class KGBuilderController extends BaseController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private WebAppConfig config;
|
||||||
|
@Autowired
|
||||||
|
private KGGraphService kgGraphService;
|
||||||
|
@Autowired
|
||||||
|
private KGManagerService kgManagerService;
|
||||||
|
@Autowired
|
||||||
|
FeedBackService feedBackService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取图谱标签列表(存放mysql表)
|
||||||
|
*
|
||||||
|
* @param queryItem
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping(value = "/getGraph") // call db.labels
|
||||||
|
public R<GraphPageRecord<KgDomain>> getGraph(@RequestBody GraphQuery queryItem) {
|
||||||
|
GraphPageRecord<KgDomain> resultRecord = new GraphPageRecord<KgDomain>();
|
||||||
|
try {
|
||||||
|
PageHelper.startPage(queryItem.getPageIndex(), queryItem.getPageSize(), true);
|
||||||
|
List<KgDomain> domainList = kgManagerService.getDomainList(queryItem.getDomain(), queryItem.getType(), queryItem.getCommend());
|
||||||
|
PageInfo<KgDomain> pageInfo = new PageInfo<KgDomain>(domainList);
|
||||||
|
long total = pageInfo.getTotal();
|
||||||
|
resultRecord.setPageIndex(queryItem.getPageIndex());
|
||||||
|
resultRecord.setPageSize(queryItem.getPageSize());
|
||||||
|
resultRecord.setTotalCount(new Long(total).intValue());
|
||||||
|
resultRecord.setNodeList(pageInfo.getList());
|
||||||
|
return R.success(resultRecord);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return R.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索框查询相关节点和关系
|
||||||
|
*
|
||||||
|
* @param query
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping(value = "/queryGraphResult")
|
||||||
|
public R<HashMap<String, Object>> queryGraphResult(@RequestBody GraphQuery query) {
|
||||||
|
try {
|
||||||
|
HashMap<String, Object> graphData = kgGraphService.queryGraphResult(query);
|
||||||
|
return R.success(graphData);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return R.error(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据自定义cypher查询结果
|
||||||
|
*
|
||||||
|
* @param cypher
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RequestMapping(value = "/getCypherResult")
|
||||||
|
public R<KgDomain> getCypherResult(String cypher) {
|
||||||
|
try {
|
||||||
|
HashMap<String, Object> graphData = Neo4jUtil.getGraphNodeAndShip(cypher);
|
||||||
|
return R.success(graphData);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return R.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取某个领域指定节点拥有的上下级的节点数
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* @param nodeId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RequestMapping(value = "/getRelationNodeCount")
|
||||||
|
public R<String> getRelationNodeCount(String domain, long nodeId) {
|
||||||
|
try {
|
||||||
|
long totalCount = 0;
|
||||||
|
if (!StringUtil.isBlank(domain)) {
|
||||||
|
totalCount = kgGraphService.getRelationNodeCount(domain, nodeId);
|
||||||
|
return R.success(totalCount);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return R.error(e.getMessage());
|
||||||
|
}
|
||||||
|
return R.error("操作失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建领域标签
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* @param type
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RequestMapping(value = "/createDomain")
|
||||||
|
public R<String> createDomain(String domain, Integer type) {
|
||||||
|
try {
|
||||||
|
if (!StringUtil.isBlank(domain)) {
|
||||||
|
List<KgDomain> domainItem = kgManagerService.getDomainByName(domain);
|
||||||
|
if (domainItem.size() > 0) {
|
||||||
|
return R.create(ReturnStatus.Error, "领域已存在");
|
||||||
|
} else {
|
||||||
|
String label=String.format("%s_%s",domain, IdUtil.nanoId(6));
|
||||||
|
int domainId = kgManagerService.quickCreateDomain(label,domain, type);// 保存到mysql
|
||||||
|
kgGraphService.createDomain(label);// 保存到图数据
|
||||||
|
return R.success(domainId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return R.error(e.getMessage());
|
||||||
|
}
|
||||||
|
return R.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前节点的下级节点
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* @param nodeId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RequestMapping(value = "/getMoreRelationNode")
|
||||||
|
public R<HashMap<String, Object>> getMoreRelationNode(String domain, String nodeId) {
|
||||||
|
try {
|
||||||
|
if (!StringUtil.isBlank(domain)) {
|
||||||
|
HashMap<String, Object> graphModel = kgGraphService.getMoreRelationNode(domain, nodeId);
|
||||||
|
if (graphModel != null) {
|
||||||
|
return R.success(graphModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return R.error(e.getMessage());
|
||||||
|
}
|
||||||
|
return R.error("没有更多数据了");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新节点名称
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RequestMapping(value = "/updateNodeName")
|
||||||
|
public R<HashMap<String, Object>> updateNodeName(@RequestBody KgNodeItem request) {
|
||||||
|
HashMap<String, Object> graphNodeList = new HashMap<String, Object>();
|
||||||
|
try {
|
||||||
|
if (!StringUtil.isBlank(request.getDomain())) {
|
||||||
|
graphNodeList = kgGraphService.updateNodeName(request.getDomain(), request.getNodeId(), request.getNodeName());
|
||||||
|
if (graphNodeList.size() > 0) {
|
||||||
|
return R.success(graphNodeList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return R.error(e.getMessage());
|
||||||
|
}
|
||||||
|
return R.error("操作失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新节点坐标
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RequestMapping(value = "/updateCoordinateOfNode")
|
||||||
|
public R<String> updateCoordinateOfNode(@RequestBody NodeCoordinateSubmitItem request) {
|
||||||
|
try {
|
||||||
|
String domain = request.getDomain();
|
||||||
|
List<NodeCoordinateItem> nodes = request.getNodes();
|
||||||
|
kgGraphService.batchUpdateGraphNodesCoordinate(domain, nodes);
|
||||||
|
return R.success();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return R.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建节点
|
||||||
|
*
|
||||||
|
* @param entity
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RequestMapping(value = "/createNode")
|
||||||
|
public R<HashMap<String, Object>> createNode(@RequestBody NodeItem entity) {
|
||||||
|
HashMap<String, Object> graphNode = new HashMap<String, Object>();
|
||||||
|
try {
|
||||||
|
graphNode = kgGraphService.createNode(entity.getDomain(), entity);
|
||||||
|
if (graphNode != null && graphNode.size() > 0) {
|
||||||
|
return R.success(graphNode);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return R.error(e.getMessage());
|
||||||
|
}
|
||||||
|
return R.error("操作失败");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量创建节点
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RequestMapping(value = "/batchCreateNode")
|
||||||
|
public R<HashMap<String, Object>> batchCreateNode(@RequestBody BatchCreateNodeItem request) {
|
||||||
|
|
||||||
|
HashMap<String, Object> rss = new HashMap<String, Object>();
|
||||||
|
try {
|
||||||
|
String[] tNames = request.getTargetNames().split(",");
|
||||||
|
rss = kgGraphService.batchCreateNode(request.getDomain(), request.getSourceName(), request.getRelation(), tNames);
|
||||||
|
return R.success(rss);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
|
||||||
|
return R.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量创建子节点
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RequestMapping(value = "/batchCreateChildNode")
|
||||||
|
public R<HashMap<String, Object>> batchCreateChildNode(@RequestBody BatchCreateNodeItem request) {
|
||||||
|
|
||||||
|
HashMap<String, Object> rss = new HashMap<String, Object>();
|
||||||
|
try {
|
||||||
|
String[] tNames = request.getTargetNames().split(",");
|
||||||
|
rss = kgGraphService.batchCreateChildNode(request.getDomain(), request.getSourceId(), request.getEntityType(), tNames, request.getRelation());
|
||||||
|
return R.success(rss);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
|
||||||
|
return R.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量创建同级节点
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RequestMapping(value = "/batchCreateSameNode")
|
||||||
|
public R<List<HashMap<String, Object>>> batchCreateSameNode(@RequestBody BatchCreateNodeItem request) {
|
||||||
|
List<HashMap<String, Object>> rss = new ArrayList<HashMap<String, Object>>();
|
||||||
|
try {
|
||||||
|
rss = kgGraphService.batchCreateSameNode(request.getDomain(), request.getEntityType(), request.getSourceNames());
|
||||||
|
return R.success(rss);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return R.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建连线
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RequestMapping(value = "/createLink")
|
||||||
|
public R<HashMap<String, Object>> createLink(@RequestBody CreateLinkItem request) {
|
||||||
|
try {
|
||||||
|
HashMap<String, Object> cypherResult = kgGraphService.createLink(request.getDomain(), request.getSourceId(), request.getTargetId(), request.getShip());
|
||||||
|
return R.success(cypherResult);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return R.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新连线信息
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* @param shipId
|
||||||
|
* @param shipName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RequestMapping(value = "/updateLink")
|
||||||
|
public R<HashMap<String, Object>> updateLink(String domain, long shipId, String shipName) {
|
||||||
|
try {
|
||||||
|
HashMap<String, Object> cypherResult = kgGraphService.updateLink(domain, shipId, shipName);
|
||||||
|
return R.success(cypherResult);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return R.error(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除节点
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* @param nodeId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RequestMapping(value = "/deleteNode")
|
||||||
|
public R<List<HashMap<String, Object>>> deleteNode(String domain, long nodeId) {
|
||||||
|
try {
|
||||||
|
List<HashMap<String, Object>> rList = kgGraphService.deleteNode(domain, nodeId);
|
||||||
|
return R.success(rList);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return R.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除领域标签
|
||||||
|
*
|
||||||
|
* @param domainId
|
||||||
|
* @param domain
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RequestMapping(value = "/deleteDomain")
|
||||||
|
public R<List<HashMap<String, Object>>> deleteDomain(Integer domainId, String domain) {
|
||||||
|
try {
|
||||||
|
kgManagerService.deleteDomain(domainId);
|
||||||
|
kgGraphService.deleteKGDomain(domain);
|
||||||
|
return R.success();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return R.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除连线
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* @param shipId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RequestMapping(value = "/deleteLink")
|
||||||
|
public R<HashMap<String, Object>> deleteLink(String domain, long shipId) {
|
||||||
|
try {
|
||||||
|
kgGraphService.deleteLink(domain, shipId);
|
||||||
|
return R.success();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return R.error(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入图谱
|
||||||
|
*
|
||||||
|
* @param file
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RequestMapping(value = "/importGraph")
|
||||||
|
public R<String> importGraph(@RequestParam(value = "file", required = true)
|
||||||
|
@Validated @NotNull(message = "请上传有效的excel的文件") @Pattern(regexp = "^(?:\\w+\\.xlsx|\\w+\\.xls)$",
|
||||||
|
message = "请上传有效的excel的文件")
|
||||||
|
MultipartFile file,
|
||||||
|
HttpServletRequest request) {
|
||||||
|
try {
|
||||||
|
String domain = request.getParameter("domain");
|
||||||
|
Integer type = Integer.parseInt(request.getParameter("type"));
|
||||||
|
List<KgDomain> domainList = kgManagerService.getDomainByName(domain);
|
||||||
|
int domainExist = 0;
|
||||||
|
if (domainList != null && domainList.size() > 0) {
|
||||||
|
//导入已有图谱,更新图谱创建时间
|
||||||
|
KgDomain domainItem = domainList.get(0);
|
||||||
|
domainItem.setModifyTime(DateUtil.getDateNow());
|
||||||
|
kgManagerService.updateDomain(domainItem);
|
||||||
|
domainExist = 1;
|
||||||
|
} else {
|
||||||
|
kgManagerService.quickCreateDomain(domain,domain, type);// 三元组
|
||||||
|
}
|
||||||
|
if (type.equals(1)) {//三元组导入
|
||||||
|
kgGraphService.importBySyz(file, request, domain, domainExist);
|
||||||
|
} else {
|
||||||
|
kgGraphService.importByCategory(file, request, domain);
|
||||||
|
}
|
||||||
|
return R.success("操作成功");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
log.error(e.getMessage());
|
||||||
|
return R.error("处理失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出图谱
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RequestMapping(value = "/exportGraph")
|
||||||
|
public Map<String, Object> exportGraph(HttpServletRequest request) {
|
||||||
|
Map<String, Object> res = new HashMap<>();
|
||||||
|
String label = request.getParameter("domain");
|
||||||
|
String filePath = config.getLocation();
|
||||||
|
String fileName = UUID.randomUUID() + ".csv";
|
||||||
|
String fileUrl = filePath + fileName;
|
||||||
|
String cypher = String.format(
|
||||||
|
"MATCH (n:`%s`) -[r]->(m:`%s`) return n.name as source,m.name as target,r.name as relation", label, label);
|
||||||
|
List<HashMap<String, Object>> list = Neo4jUtil.getGraphTable(cypher);
|
||||||
|
if (list.size() == 0) {
|
||||||
|
res.put("code", -1);
|
||||||
|
res.put("message", "该领域没有任何有关系的实体!");
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
CsvWriter csvWriter = CsvUtil.getWriter(fileUrl, CharsetUtil.CHARSET_UTF_8);
|
||||||
|
String[] header = {"source", "target", "relation"};
|
||||||
|
//写入表头
|
||||||
|
csvWriter.write(header);
|
||||||
|
for (HashMap<String, Object> hashMap : list) {
|
||||||
|
int colSize = hashMap.size();
|
||||||
|
String[] cntArr = new String[colSize];
|
||||||
|
cntArr[0] = hashMap.get("source").toString().replace("\"", "");
|
||||||
|
cntArr[1] = hashMap.get("target").toString().replace("\"", "");
|
||||||
|
cntArr[2] = hashMap.get("relation").toString().replace("\"", "");
|
||||||
|
csvWriter.write(cntArr);
|
||||||
|
}
|
||||||
|
csvWriter.close();
|
||||||
|
String csvUrl = "/file/download/" + fileName;
|
||||||
|
res.put("code", 200);
|
||||||
|
res.put("fileName", csvUrl);
|
||||||
|
res.put("message", "success!");
|
||||||
|
return res;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取节点图片
|
||||||
|
*
|
||||||
|
* @param domainId
|
||||||
|
* @param nodeId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RequestMapping(value = "/getNodeImage")
|
||||||
|
public R<List<Map<String, Object>>> getNodeImageList(int domainId, int nodeId) {
|
||||||
|
try {
|
||||||
|
List<KgNodeDetailFile> images = kgManagerService.getNodeImageList(domainId, nodeId);
|
||||||
|
return R.success(images);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return R.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取节点描述信息
|
||||||
|
*
|
||||||
|
* @param domainId
|
||||||
|
* @param nodeId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RequestMapping(value = "/getNodeContent")
|
||||||
|
public R<Map<String, Object>> getNodeContent(int domainId, int nodeId) {
|
||||||
|
try {
|
||||||
|
List<KgNodeDetail> contents = kgManagerService.getNodeContent(domainId, nodeId);
|
||||||
|
if (contents != null && contents.size() > 0) {
|
||||||
|
return R.success(contents.get(0));
|
||||||
|
}
|
||||||
|
return R.success(new ArrayList<>());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return R.error(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取节点详情
|
||||||
|
*
|
||||||
|
* @param domainId
|
||||||
|
* @param nodeId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RequestMapping(value = "/getNodeDetail")
|
||||||
|
public R<Map<String, Object>> getNodeDetail(int domainId, int nodeId) {
|
||||||
|
try {
|
||||||
|
Map<String, Object> res = new HashMap<String, Object>();
|
||||||
|
res.put("content", "");
|
||||||
|
res.put("imageList", new String[]{});
|
||||||
|
List<KgNodeDetail> contents = kgManagerService.getNodeContent(domainId, nodeId);
|
||||||
|
if (contents != null && contents.size() > 0) {
|
||||||
|
res.replace("content", contents.get(0).getContent());
|
||||||
|
}
|
||||||
|
List<KgNodeDetailFile> images = kgManagerService.getNodeImageList(domainId, nodeId);
|
||||||
|
if (images != null && images.size() > 0) {
|
||||||
|
res.replace("imageList", images);
|
||||||
|
}
|
||||||
|
return R.success(res);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return R.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内容反馈
|
||||||
|
*
|
||||||
|
* @param submitItem
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RequestMapping(value = "/feedBack")
|
||||||
|
public R<Map<String, Object>> feedBack(KgFeedBack submitItem) {
|
||||||
|
try {
|
||||||
|
feedBackService.insert(submitItem);
|
||||||
|
return R.success();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return R.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存节点图片
|
||||||
|
*
|
||||||
|
* @param params
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RequestMapping(value = "/saveNodeImage")
|
||||||
|
public R<String> saveNodeImage(@RequestBody Map<String, Object> params) {
|
||||||
|
try {
|
||||||
|
int domainId = (int) params.get("domainId");
|
||||||
|
String nodeId = params.get("nodeId").toString();
|
||||||
|
String imagePath = params.get("imagePath").toString();
|
||||||
|
List<KgDomain> domainList = kgManagerService.getDomainById(domainId);
|
||||||
|
if (domainList != null && domainList.size() > 0) {
|
||||||
|
String domainName = domainList.get(0).getName();
|
||||||
|
if (StringUtil.isNotBlank(imagePath)) {
|
||||||
|
List<Map<String, Object>> submitItemList = new ArrayList<Map<String, Object>>();
|
||||||
|
Map<String, Object> sb = new HashMap<String, Object>();
|
||||||
|
sb.put("file", imagePath);
|
||||||
|
sb.put("imageType", 0);
|
||||||
|
sb.put("domainId", domainId);
|
||||||
|
sb.put("nodeId", nodeId);
|
||||||
|
sb.put("status", 1);
|
||||||
|
sb.put("createUser", "tc");
|
||||||
|
sb.put("createTime", DateUtil.getDateNow());
|
||||||
|
submitItemList.add(sb);
|
||||||
|
kgManagerService.deleteNodeImage(domainId, Integer.parseInt(nodeId));
|
||||||
|
kgManagerService.saveNodeImage(submitItemList);
|
||||||
|
// 更新到图数据库,表明该节点有附件,加个标识,0=没有,1=有
|
||||||
|
kgGraphService.updateNodeImg(domainName, Long.parseLong(nodeId), imagePath);
|
||||||
|
return R.success("操作成功");
|
||||||
|
} else {
|
||||||
|
kgManagerService.deleteNodeImage(domainId, Integer.parseInt(nodeId));
|
||||||
|
kgGraphService.removeNodeImg(domainName, Long.parseLong(nodeId));
|
||||||
|
return R.success("操作成功");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return R.error(e.getMessage());
|
||||||
|
}
|
||||||
|
return R.error("操作失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存节点正文
|
||||||
|
*
|
||||||
|
* @param params
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RequestMapping(value = "/saveNodeContent")
|
||||||
|
public R<String> saveNodeContent(@RequestBody Map<String, Object> params) {
|
||||||
|
try {
|
||||||
|
String username = "tc";
|
||||||
|
int domainId = (int) params.get("domainId");
|
||||||
|
String nodeId = params.get("nodeId").toString();
|
||||||
|
String content = params.get("content").toString();
|
||||||
|
List<KgDomain> domainList = kgManagerService.getDomainById(domainId);
|
||||||
|
if (domainList != null && domainList.size() > 0) {
|
||||||
|
String domainName = domainList.get(0).getName();
|
||||||
|
// 检查是否存在
|
||||||
|
List<KgNodeDetail> items = kgManagerService.getNodeContent(domainId, Integer.parseInt(nodeId));
|
||||||
|
if (items != null && items.size() > 0) {
|
||||||
|
KgNodeDetail oldItem = items.get(0);
|
||||||
|
Map<String, Object> item = new HashMap<String, Object>();
|
||||||
|
item.put("domainId", oldItem.getDomainId());
|
||||||
|
item.put("nodeId", oldItem.getNodeId());
|
||||||
|
item.put("content", content);
|
||||||
|
item.put("modifyUser", username);
|
||||||
|
item.put("modifyTime", DateUtil.getDateNow());
|
||||||
|
kgManagerService.updateNodeContent(item);
|
||||||
|
return R.success("更新成功");
|
||||||
|
} else {
|
||||||
|
Map<String, Object> sb = new HashMap<String, Object>();
|
||||||
|
sb.put("content", content);
|
||||||
|
sb.put("domainId", domainId);
|
||||||
|
sb.put("nodeId", nodeId);
|
||||||
|
sb.put("status", 1);
|
||||||
|
sb.put("createUser", username);
|
||||||
|
sb.put("createTime", DateUtil.getDateNow());
|
||||||
|
if (sb.size() > 0) {
|
||||||
|
kgManagerService.saveNodeContent(sb);
|
||||||
|
return R.success("保存成功");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 更新到图数据库,表明该节点有附件,加个标识,0=没有,1=有
|
||||||
|
kgGraphService.updateNodeFileStatus(domainName, Long.parseLong(nodeId), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return R.error(e.getMessage());
|
||||||
|
}
|
||||||
|
return R.error("操作失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,55 @@
|
|||||||
|
package com.warmer.web.dao;
|
||||||
|
|
||||||
|
import com.warmer.web.entity.CategoryNode;
|
||||||
|
import com.warmer.web.request.CategoryNodeQuery;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface CategoryNodeDao {
|
||||||
|
int deleteByPrimaryKey(Integer id);
|
||||||
|
|
||||||
|
int insert(CategoryNode record);
|
||||||
|
|
||||||
|
int batchInsert(List<CategoryNode> records);
|
||||||
|
|
||||||
|
void batchUpdateExpression(List<CategoryNode> records);
|
||||||
|
|
||||||
|
CategoryNode selectByPrimaryKey(@Param("categoryNodeId")Integer categoryNodeId);
|
||||||
|
|
||||||
|
int updateByPrimaryKey(CategoryNode record);
|
||||||
|
|
||||||
|
int reName(@Param("categoryNodeId")Integer categoryNodeId,@Param("categoryNodeName")String categoryNodeName);
|
||||||
|
|
||||||
|
int updateCodeByPrimaryKey(@Param("categoryNodeId")Integer categoryNodeId,@Param("systemCode")String systemCode);
|
||||||
|
|
||||||
|
void initSystemCode(@Param("categoryId")Long categoryId,@Param("fileUuid")String fileUuid);
|
||||||
|
|
||||||
|
void updateNodeRelation(@Param("categoryId")Long categoryId,@Param("fileUuid")String fileUuid,@Param("categoryNodeId")Integer categoryNodeId);
|
||||||
|
|
||||||
|
void updateSystemCodeFullPath(@Param("categoryId")Long categoryId,@Param("fileUuid")String fileUuid);
|
||||||
|
|
||||||
|
void updateTreeLevel(@Param("categoryId")Long categoryId);
|
||||||
|
|
||||||
|
int updateLeafStatusByPrimaryKey(@Param("categoryNodeId")Integer categoryNodeId,@Param("isLeaf")Integer isLeaf);
|
||||||
|
|
||||||
|
List<CategoryNode> queryForList(CategoryNodeQuery queryItem);
|
||||||
|
|
||||||
|
List<CategoryNode> selectByParentId(@Param("categoryId")Long categoryId, @Param("parentId") Integer parentId);
|
||||||
|
|
||||||
|
List<CategoryNode> selectByParentIdAndName(@Param("categoryId")Long categoryId,@Param("parentId") Integer parentId,@Param("categoryNodeName") String categoryNodeName);
|
||||||
|
|
||||||
|
List<CategoryNode> queryForTree(@Param("categoryId") Long categoryId, @Param("categoryNodeId") Integer categoryNodeId);
|
||||||
|
List<CategoryNode> selectTreeForParent(@Param("categoryNodeId") Integer categoryNodeId);
|
||||||
|
List<CategoryNode> selectTreeForParentBySystemCode(@Param("systemCode") String systemCode);
|
||||||
|
List<CategoryNode> selectRecentEditNode(@Param("categoryId") Long categoryId);
|
||||||
|
|
||||||
|
int deleteNodeByFileUuid(@Param("fileUuid") String fileUuid,@Param("systemCode") String systemCode);
|
||||||
|
|
||||||
|
int deleteNodeBySystemLeftRegular(@Param("systemCode") String systemCode);
|
||||||
|
|
||||||
|
List<CategoryNode> selectByFileUuid(@Param("fileUuid") String fileUuid);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
package com.warmer.web.dao;
|
||||||
|
|
||||||
|
import com.warmer.web.entity.KgFeedBack;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface FeedBackDao {
|
||||||
|
int deleteByPrimaryKey(Integer id);
|
||||||
|
|
||||||
|
int insert(KgFeedBack record);
|
||||||
|
|
||||||
|
KgFeedBack selectByPrimaryKey(@Param("id") Integer id);
|
||||||
|
|
||||||
|
List<KgFeedBack> queryForList(KgFeedBack queryItem);
|
||||||
|
|
||||||
|
}
|
||||||
242
kgBuilder-pro/src/main/java/com/warmer/web/dao/KGGraphDao.java
Normal file
242
kgBuilder-pro/src/main/java/com/warmer/web/dao/KGGraphDao.java
Normal file
@ -0,0 +1,242 @@
|
|||||||
|
package com.warmer.web.dao;
|
||||||
|
|
||||||
|
|
||||||
|
import com.warmer.web.model.NodeItem;
|
||||||
|
import com.warmer.web.request.GraphQuery;
|
||||||
|
import com.warmer.base.util.GraphPageRecord;
|
||||||
|
import com.warmer.web.request.NodeCoordinateItem;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface KGGraphDao {
|
||||||
|
/**
|
||||||
|
* 领域标签分页
|
||||||
|
* @param queryItem
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
GraphPageRecord<HashMap<String, Object>> getPageDomain(GraphQuery queryItem);
|
||||||
|
/**
|
||||||
|
* 删除Neo4j 标签
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
*/
|
||||||
|
void deleteKgDomain(String domain);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询图谱节点和关系
|
||||||
|
*
|
||||||
|
* @param query
|
||||||
|
* @return node relationship
|
||||||
|
*/
|
||||||
|
HashMap<String, Object> queryGraphResult(GraphQuery query);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取节点列表
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* @param pageIndex
|
||||||
|
* @param pageSize
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
HashMap<String, Object> getDomainNodes(String domain, Integer pageIndex, Integer pageSize);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取某个领域指定节点拥有的上下级的节点数
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* @param nodeId
|
||||||
|
* @return long 数值
|
||||||
|
*/
|
||||||
|
long getRelationNodeCount(String domain, long nodeId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建领域,默认创建一个新的节点,给节点附上默认属性
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
*/
|
||||||
|
void createDomain(String domain);
|
||||||
|
void quickCreateDomain(String domain,String nodeName);
|
||||||
|
/**
|
||||||
|
* 获取/展开更多节点,找到和该节点有关系的节点
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* @param nodeId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
HashMap<String, Object> getMoreRelationNode(String domain, String nodeId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新节点名称
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* @param nodeId
|
||||||
|
* @param nodeName
|
||||||
|
* @return 修改后的节点
|
||||||
|
*/
|
||||||
|
HashMap<String, Object> updateNodeName(String domain, String nodeId, String nodeName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建单个节点
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* @param entity
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
HashMap<String, Object> createNode(String domain, NodeItem entity);
|
||||||
|
HashMap<String, Object> createNodeWithUUid(String domain, NodeItem entity);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量创建节点和关系
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* 领域
|
||||||
|
* @param sourceName
|
||||||
|
* 源节点
|
||||||
|
* @param relation
|
||||||
|
* 关系
|
||||||
|
* @param targetNames
|
||||||
|
* 目标节点数组
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
HashMap<String, Object> batchCreateNode(String domain, String sourceName, String relation, String[] targetNames);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量创建下级节点
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* 领域
|
||||||
|
* @param sourceId
|
||||||
|
* 源节点id
|
||||||
|
* @param entityType
|
||||||
|
* 节点类型
|
||||||
|
* @param targetNames
|
||||||
|
* 目标节点名称数组
|
||||||
|
* @param relation
|
||||||
|
* 关系
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
HashMap<String, Object> batchCreateChildNode(String domain, String sourceId, Integer entityType,
|
||||||
|
String[] targetNames, String relation);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量创建同级节点
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* 领域
|
||||||
|
* @param entityType
|
||||||
|
* 节点类型
|
||||||
|
* @param sourceNames
|
||||||
|
* 节点名称
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<HashMap<String, Object>> batchCreateSameNode(String domain, Integer entityType, String[] sourceNames);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加关系
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* 领域
|
||||||
|
* @param sourceId
|
||||||
|
* 源节点id
|
||||||
|
* @param targetId
|
||||||
|
* 目标节点id
|
||||||
|
* @param ship
|
||||||
|
* 关系
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
HashMap<String, Object> createLink(String domain, long sourceId, long targetId, String ship);
|
||||||
|
HashMap<String, Object> createLinkByUuid(String domain, long sourceId, long targetId, String ship);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新关系
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* 领域
|
||||||
|
* @param shipId
|
||||||
|
* 关系id
|
||||||
|
* @param shipName
|
||||||
|
* 关系名称
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
HashMap<String, Object> updateLink(String domain, long shipId, String shipName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除节点(先删除关系再删除节点)
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* @param nodeId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<HashMap<String, Object>> deleteNode(String domain, long nodeId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除关系
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* @param shipId
|
||||||
|
*/
|
||||||
|
void deleteLink(String domain, long shipId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 段落识别出的三元组生成图谱
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* @param entityType
|
||||||
|
* @param operateType
|
||||||
|
* @param sourceId
|
||||||
|
* @param rss
|
||||||
|
* 关系三元组
|
||||||
|
* [[startname;ship;endname],[startname1;ship1;endname1],[startname2;ship2;endname2]]
|
||||||
|
* @return node relationship
|
||||||
|
*/
|
||||||
|
HashMap<String, Object> createGraphByText(String domain, Integer entityType, Integer operateType, Integer sourceId,
|
||||||
|
String[] rss);
|
||||||
|
/**
|
||||||
|
* 批量创建节点,关系
|
||||||
|
* @param domain
|
||||||
|
* @param params 三元组 sourceNode,relationship,targetNode
|
||||||
|
*/
|
||||||
|
void batchCreateGraph(String domain, List<Map<String,Object>> params);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量更新节点坐标
|
||||||
|
* @param domain
|
||||||
|
* @param params
|
||||||
|
*/
|
||||||
|
void batchUpdateGraphNodesCoordinate(String domain,List<NodeCoordinateItem> params);
|
||||||
|
/**
|
||||||
|
* 更新节点有无附件
|
||||||
|
* @param domain
|
||||||
|
* @param nodeId
|
||||||
|
* @param status
|
||||||
|
*/
|
||||||
|
void updateNodeFileStatus(String domain,long nodeId, int status);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新图谱节点的图片
|
||||||
|
* @param domain
|
||||||
|
* @param nodeId
|
||||||
|
* @param img
|
||||||
|
*/
|
||||||
|
void updateNodeImg(String domain, long nodeId, String img);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除节点图片
|
||||||
|
* @param domain
|
||||||
|
* @param nodeId
|
||||||
|
*/
|
||||||
|
void removeNodeImg(String domain, long nodeId);
|
||||||
|
/**
|
||||||
|
* 导入csv
|
||||||
|
* @param domain
|
||||||
|
* @param csvUrl
|
||||||
|
* @param status
|
||||||
|
*/
|
||||||
|
void batchInsertByCsv(String domain, String csvUrl, int status) ;
|
||||||
|
void updateCoordinateOfNode(String domain, String uuid, Double fx, Double fy);
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
package com.warmer.web.dao;
|
||||||
|
|
||||||
|
import com.warmer.web.entity.KgGraphLink;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface KgGraphLinkDao {
|
||||||
|
List<KgGraphLink> selectByDomainId(Integer domainId);
|
||||||
|
int insert(KgGraphLink record);
|
||||||
|
int batchInsert(List<KgGraphLink> records);
|
||||||
|
int deleteByDomainId(Integer domainId);
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package com.warmer.web.dao;
|
||||||
|
|
||||||
|
import com.warmer.web.entity.KgGraphNode;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface KgGraphNodeDao {
|
||||||
|
List<KgGraphNode> selectByDomainId(Integer domainId);
|
||||||
|
|
||||||
|
int insert(KgGraphNode record);
|
||||||
|
|
||||||
|
int batchInsert(List<KgGraphNode> record);
|
||||||
|
|
||||||
|
int deleteByDomainId(Integer domainId);
|
||||||
|
}
|
||||||
@ -0,0 +1,20 @@
|
|||||||
|
package com.warmer.web.dao;
|
||||||
|
|
||||||
|
import com.warmer.web.entity.KgGraphNodeMap;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface KgGraphNodeMapDao {
|
||||||
|
|
||||||
|
int insert(KgGraphNodeMap record);
|
||||||
|
|
||||||
|
int batchInsert(List<KgGraphNodeMap> records);
|
||||||
|
|
||||||
|
int deleteByDomainId(Integer domainId);
|
||||||
|
|
||||||
|
List<KgGraphNodeMap> selectByDomainId(Integer domainId);
|
||||||
|
|
||||||
|
List<KgGraphNodeMap> selectByDomainIdAndNodeId(Integer domainId,Long nodeId);
|
||||||
|
}
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
package com.warmer.web.dao;
|
||||||
|
|
||||||
|
import com.warmer.web.entity.KgDomain;
|
||||||
|
import com.warmer.web.entity.KgNodeDetail;
|
||||||
|
import com.warmer.web.entity.KgNodeDetailFile;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface KnowledgeGraphDao {
|
||||||
|
List<KgDomain> getDomains();
|
||||||
|
List<KgDomain> getDomainList(@Param("domainName")String domainName, @Param("type")Integer type,@Param("commend")Integer commend);
|
||||||
|
void saveDomain(KgDomain map);
|
||||||
|
void updateDomain(KgDomain map);
|
||||||
|
void deleteDomain(@Param("id") Integer id);
|
||||||
|
List<KgDomain> getDomainByName(@Param("domainName") String domainName);
|
||||||
|
KgDomain getDomainByLabel(@Param("label") String label);
|
||||||
|
List<KgDomain> getDomainById(@Param("domainId")Integer domainId);
|
||||||
|
KgDomain selectById(@Param("domainId")Integer domainId);
|
||||||
|
void saveNodeImage(@Param("maplist") List<Map<String, Object>> mapList);
|
||||||
|
void saveNodeContent(@Param("params") Map<String, Object> map);
|
||||||
|
void updateNodeContent(@Param("params") Map<String, Object> map);
|
||||||
|
List<KgNodeDetailFile> getNodeImageList(@Param("domainId") Integer domainId, @Param("nodeId") Integer nodeId);
|
||||||
|
List<KgNodeDetail> getNodeContent(@Param("domainId") Integer domainId, @Param("nodeId") Integer nodeId);
|
||||||
|
void deleteNodeImage(@Param("domainId") Integer domainId,@Param("nodeId") Integer nodeId);
|
||||||
|
}
|
||||||
@ -0,0 +1,726 @@
|
|||||||
|
package com.warmer.web.dao.impl;
|
||||||
|
|
||||||
|
import com.warmer.base.util.JsonHelper;
|
||||||
|
import com.warmer.base.util.Neo4jUtil;
|
||||||
|
import com.warmer.web.dao.KGGraphDao;
|
||||||
|
import com.warmer.web.model.NodeItem;
|
||||||
|
|
||||||
|
import com.warmer.web.request.GraphQuery;
|
||||||
|
import com.warmer.base.util.GraphPageRecord;
|
||||||
|
import com.warmer.base.util.StringUtil;
|
||||||
|
import com.warmer.web.request.NodeCoordinateItem;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public class KGGraphRepository implements KGGraphDao {
|
||||||
|
/**
|
||||||
|
* 领域标签分页
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public GraphPageRecord<HashMap<String, Object>> getPageDomain(GraphQuery queryItem) {
|
||||||
|
GraphPageRecord<HashMap<String, Object>> resultRecord = new GraphPageRecord<HashMap<String, Object>>();
|
||||||
|
try {
|
||||||
|
String totalCountQuery = "MATCH (n) RETURN count(distinct labels(n)) as count";
|
||||||
|
long totalCount = 0;
|
||||||
|
totalCount = Neo4jUtil.getGraphValue(totalCountQuery);
|
||||||
|
if (totalCount > 0) {
|
||||||
|
int skipCount = (queryItem.getPageIndex() - 1) * queryItem.getPageSize();
|
||||||
|
int limitCount = queryItem.getPageSize();
|
||||||
|
String domainSql = String.format(
|
||||||
|
"START n=node(*) RETURN distinct labels(n) as domain,count(n) as nodeCount order by nodeCount desc SKIP %s LIMIT %s",
|
||||||
|
skipCount, limitCount);
|
||||||
|
List<HashMap<String, Object>> pageList = Neo4jUtil.getGraphNode(domainSql);
|
||||||
|
resultRecord.setPageIndex(queryItem.getPageIndex());
|
||||||
|
resultRecord.setPageSize(queryItem.getPageSize());
|
||||||
|
resultRecord.setTotalCount(totalCount);
|
||||||
|
resultRecord.setNodeList(pageList);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultRecord;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除Neo4j 标签
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void deleteKgDomain(String domain) {
|
||||||
|
try {
|
||||||
|
String deleteRelation = String.format("MATCH (n:`%s`)-[r]-(m) detach delete r", domain);
|
||||||
|
Neo4jUtil.runCypherSql(deleteRelation);
|
||||||
|
String deleteNode = String.format("MATCH (n:`%s`) detach delete n", domain);
|
||||||
|
Neo4jUtil.runCypherSql(deleteNode);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询图谱节点和关系
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public HashMap<String, Object> queryGraphResult(GraphQuery query) {
|
||||||
|
HashMap<String, Object> nr = new HashMap<String, Object>();
|
||||||
|
try {
|
||||||
|
String domain = query.getDomain();
|
||||||
|
// MATCH (n:`症状`) -[r]-(m:症状) where r.name='治疗' or r.name='危险因素' return n,m
|
||||||
|
if (!StringUtil.isBlank(domain)) {
|
||||||
|
String cqr = "";
|
||||||
|
List<String> lis = new ArrayList<String>();
|
||||||
|
if (query.getRelation() != null && query.getRelation().length > 0) {
|
||||||
|
for (String r : query.getRelation()) {
|
||||||
|
String it = String.format("r.name='%s'", r);
|
||||||
|
lis.add(it);
|
||||||
|
}
|
||||||
|
cqr = String.join(" or ", lis);
|
||||||
|
}
|
||||||
|
String cqWhere = "";
|
||||||
|
if (!StringUtil.isBlank(query.getNodeName()) || !StringUtil.isBlank(cqr)) {
|
||||||
|
|
||||||
|
if (!StringUtil.isBlank(query.getNodeName())) {
|
||||||
|
if (query.getMatchType() == 1) {
|
||||||
|
cqWhere = String.format("where n.name ='%s' ", query.getNodeName());
|
||||||
|
|
||||||
|
} else {
|
||||||
|
cqWhere = String.format("where n.name contains('%s')", query.getNodeName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String nodeOnly = cqWhere;
|
||||||
|
if (!StringUtil.isBlank(cqr)) {
|
||||||
|
if (StringUtil.isBlank(cqWhere)) {
|
||||||
|
cqWhere = String.format(" where ( %s )", cqr);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
cqWhere += String.format(" and ( %s )", cqr);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// 下边的查询查不到单个没有关系的节点,考虑要不要左箭头
|
||||||
|
String nodeSql = String.format("MATCH (n:`%s`) <-[r]->(m) %s return * limit %s", domain, cqWhere,
|
||||||
|
query.getPageSize());
|
||||||
|
HashMap<String, Object> graphNode = Neo4jUtil.getGraphNodeAndShip(nodeSql);
|
||||||
|
Object node = graphNode.get("node");
|
||||||
|
// 没有关系显示则显示节点
|
||||||
|
if (node != null) {
|
||||||
|
nr.put("node", graphNode.get("node"));
|
||||||
|
nr.put("relationship", graphNode.get("relationship"));
|
||||||
|
} else {
|
||||||
|
String nodecql = String.format("MATCH (n:`%s`) %s RETURN distinct(n) limit %s", domain,
|
||||||
|
nodeOnly, query.getPageSize());
|
||||||
|
List<HashMap<String, Object>> nodeItem = Neo4jUtil.getGraphNode(nodecql);
|
||||||
|
nr.put("node", nodeItem);
|
||||||
|
nr.put("relationship", new ArrayList<HashMap<String, Object>>());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
String nodeSql = String.format("MATCH (n:`%s`) %s RETURN distinct(n) limit %s", domain, cqWhere,
|
||||||
|
query.getPageSize());
|
||||||
|
List<HashMap<String, Object>> graphNode = Neo4jUtil.getGraphNode(nodeSql);
|
||||||
|
nr.put("node", graphNode);
|
||||||
|
String domainSql = String.format("MATCH (n:`%s`)<-[r]-> (m) %s RETURN distinct(r) limit %s", domain,
|
||||||
|
cqWhere, query.getPageSize());// m是否加领域
|
||||||
|
List<HashMap<String, Object>> graphRelation = Neo4jUtil.getGraphRelationShip(domainSql);
|
||||||
|
nr.put("relationship", graphRelation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return nr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取节点列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public HashMap<String, Object> getDomainNodes(String domain, Integer pageIndex, Integer pageSize) {
|
||||||
|
HashMap<String, Object> resultItem = new HashMap<String, Object>();
|
||||||
|
List<HashMap<String, Object>> ents = new ArrayList<HashMap<String, Object>>();
|
||||||
|
List<HashMap<String, Object>> concepts = new ArrayList<HashMap<String, Object>>();
|
||||||
|
List<HashMap<String, Object>> props = new ArrayList<HashMap<String, Object>>();
|
||||||
|
List<HashMap<String, Object>> methods = new ArrayList<HashMap<String, Object>>();
|
||||||
|
List<HashMap<String, Object>> entitys = new ArrayList<HashMap<String, Object>>();
|
||||||
|
try {
|
||||||
|
int skipCount = (pageIndex - 1) * pageSize;
|
||||||
|
int limitCount = pageSize;
|
||||||
|
String domainSql = String.format("START n=node(*) MATCH (n:`%s`) RETURN n SKIP %s LIMIT %s", domain,
|
||||||
|
skipCount, limitCount);
|
||||||
|
if (!StringUtil.isBlank(domain)) {
|
||||||
|
ents = Neo4jUtil.getGraphNode(domainSql);
|
||||||
|
for (HashMap<String, Object> hashMap : ents) {
|
||||||
|
Object et = hashMap.get("entityType");
|
||||||
|
if (et != null) {
|
||||||
|
String typeStr = et.toString();
|
||||||
|
if (StringUtil.isNotBlank(typeStr)) {
|
||||||
|
int type = Integer.parseInt(et.toString());
|
||||||
|
if (type == 0) {
|
||||||
|
concepts.add(hashMap);
|
||||||
|
} else if (type == 1) {
|
||||||
|
entitys.add(hashMap);
|
||||||
|
} else if (type == 2 || type == 3) {
|
||||||
|
props.add(hashMap);// 属性和方法放在一起展示
|
||||||
|
} else {
|
||||||
|
// methods.add(hashMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resultItem.put("concepts", concepts);
|
||||||
|
resultItem.put("props", props);
|
||||||
|
resultItem.put("methods", methods);
|
||||||
|
resultItem.put("entitys", entitys);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取某个领域指定节点拥有的上下级的节点数
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public long getRelationNodeCount(String domain, long nodeId) {
|
||||||
|
long totalCount = 0;
|
||||||
|
try {
|
||||||
|
if (!StringUtil.isBlank(domain)) {
|
||||||
|
String nodeSql = String.format("MATCH (n:`%s`) <-[r]->(m) where id(n)=%s return count(m)", domain,
|
||||||
|
nodeId);
|
||||||
|
totalCount = Neo4jUtil.getGraphValue(nodeSql);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return totalCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建领域,默认创建一个新的节点,给节点附上默认属性
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void createDomain(String domain) {
|
||||||
|
try {
|
||||||
|
String cypherSql = String.format(
|
||||||
|
"create (n:`%s`{entityType:0,name:''}) return id(n)", domain);
|
||||||
|
Neo4jUtil.runCypherSql(cypherSql);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void quickCreateDomain(String domain,String nodeName) {
|
||||||
|
try {
|
||||||
|
String cypherSql = String.format(
|
||||||
|
"create (n:`%s`{entityType:0,name:'%s'}) return id(n)", domain,nodeName);
|
||||||
|
Neo4jUtil.runCypherSql(cypherSql);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取/展开更多节点,找到和该节点有关系的节点
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public HashMap<String, Object> getMoreRelationNode(String domain, String nodeId) {
|
||||||
|
HashMap<String, Object> result = new HashMap<String, Object>();
|
||||||
|
try {
|
||||||
|
String cypherSql = String.format("MATCH (n:`%s`) -[r]-(m) where id(n)=%s return * limit 100", domain,
|
||||||
|
nodeId);
|
||||||
|
result = Neo4jUtil.getGraphNodeAndShip(cypherSql);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新节点名称
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public HashMap<String, Object> updateNodeName(String domain, String nodeId, String nodeName) {
|
||||||
|
HashMap<String, Object> result = new HashMap<String, Object>();
|
||||||
|
List<HashMap<String, Object>> graphNodeList = new ArrayList<HashMap<String, Object>>();
|
||||||
|
try {
|
||||||
|
String cypherSql = String.format("MATCH (n:`%s`) where id(n)=%s set n.name='%s' return n", domain, nodeId,
|
||||||
|
nodeName);
|
||||||
|
graphNodeList = Neo4jUtil.getGraphNode(cypherSql);
|
||||||
|
if (graphNodeList.size() > 0) {
|
||||||
|
return graphNodeList.get(0);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建单个节点
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public HashMap<String, Object> createNode(String domain, NodeItem entity) {
|
||||||
|
HashMap<String, Object> rss = new HashMap<String, Object>();
|
||||||
|
List<HashMap<String, Object>> graphNodeList = new ArrayList<HashMap<String, Object>>();
|
||||||
|
try {
|
||||||
|
if (entity.getUuid() != 0) {
|
||||||
|
String sqlKeyVal = Neo4jUtil.getKeyValCyphersql(entity);
|
||||||
|
String cypherSql = String.format("match (n:`%s`) where id(n)=%s set %s return n", domain,
|
||||||
|
entity.getUuid(), sqlKeyVal);
|
||||||
|
graphNodeList = Neo4jUtil.getGraphNode(cypherSql);
|
||||||
|
} else {
|
||||||
|
entity.setColor("#ff4500");// 默认颜色
|
||||||
|
entity.setR(30);// 默认半径
|
||||||
|
String propertiesString = Neo4jUtil.getFilterPropertiesJson(JsonHelper.toJSONString(entity));
|
||||||
|
String cypherSql = String.format("create (n:`%s` %s) return n", domain, propertiesString);
|
||||||
|
graphNodeList = Neo4jUtil.getGraphNode(cypherSql);
|
||||||
|
}
|
||||||
|
if (graphNodeList.size() > 0) {
|
||||||
|
rss = graphNodeList.get(0);
|
||||||
|
return rss;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return rss;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义uuid,重复则返回节点,不存在则创建
|
||||||
|
* @param domain
|
||||||
|
* @param entity
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public HashMap<String, Object> createNodeWithUUid(String domain, NodeItem entity) {
|
||||||
|
HashMap<String, Object> rss = new HashMap<String, Object>();
|
||||||
|
List<HashMap<String, Object>> graphNodeList = new ArrayList<HashMap<String, Object>>();
|
||||||
|
try {
|
||||||
|
if (entity.getUuid() != 0) {
|
||||||
|
String sqlKeyVal = Neo4jUtil.getKeyValCyphersql(entity);
|
||||||
|
String cypherSql = String.format("match (n:`%s`) where id(n)=%s set %s return n", domain,
|
||||||
|
entity.getUuid(), sqlKeyVal);
|
||||||
|
graphNodeList = Neo4jUtil.getGraphNode(cypherSql);
|
||||||
|
}
|
||||||
|
if (graphNodeList.size() > 0) {
|
||||||
|
rss = graphNodeList.get(0);
|
||||||
|
return rss;
|
||||||
|
}
|
||||||
|
entity.setName(entity.getName());
|
||||||
|
entity.setColor(entity.getColor());
|
||||||
|
entity.setR(30);// 默认半径
|
||||||
|
entity.setUuid(entity.getUuid());
|
||||||
|
String propertiesString = Neo4jUtil.getFilterPropertiesJson(JsonHelper.toJSONString(entity));
|
||||||
|
String cypherSql = String.format("create (n:`%s` %s) return n", domain, propertiesString);
|
||||||
|
graphNodeList = Neo4jUtil.getGraphNode(cypherSql);
|
||||||
|
if (graphNodeList.size() > 0) {
|
||||||
|
rss = graphNodeList.get(0);
|
||||||
|
return rss;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return rss;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量创建节点和关系
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public HashMap<String, Object> batchCreateNode(String domain, String sourceName, String relation,
|
||||||
|
String[] targetNames) {
|
||||||
|
HashMap<String, Object> rss = new HashMap<String, Object>();
|
||||||
|
List<HashMap<String, Object>> nodes = new ArrayList<HashMap<String, Object>>();
|
||||||
|
List<HashMap<String, Object>> ships = new ArrayList<HashMap<String, Object>>();
|
||||||
|
try {
|
||||||
|
String cypherSqlFmt = "create (n:`%s` {name:'%s',color:'#ff4500',r:30}) return n";
|
||||||
|
String cypherSql = String.format(cypherSqlFmt, domain, sourceName);// 概念实体
|
||||||
|
List<HashMap<String, Object>> graphNodeList = Neo4jUtil.getGraphNode(cypherSql);
|
||||||
|
if (graphNodeList.size() > 0) {
|
||||||
|
HashMap<String, Object> sourceNode = graphNodeList.get(0);
|
||||||
|
nodes.add(sourceNode);
|
||||||
|
String sourceUuid = String.valueOf(sourceNode.get("uuid"));
|
||||||
|
for (String tn : targetNames) {
|
||||||
|
String targetNodeSql = String.format(cypherSqlFmt, domain, tn);
|
||||||
|
List<HashMap<String, Object>> targetNodeList = Neo4jUtil.getGraphNode(targetNodeSql);
|
||||||
|
if (targetNodeList.size() > 0) {
|
||||||
|
HashMap<String, Object> targetNode = targetNodeList.get(0);
|
||||||
|
nodes.add(targetNode);
|
||||||
|
String targetUuid = String.valueOf(targetNode.get("uuid"));
|
||||||
|
String rSql = String.format(
|
||||||
|
"match(n:`%s`),(m:`%s`) where id(n)=%s and id(m)=%s create (n)-[r:RE {name:'%s'}]->(m) return r",
|
||||||
|
domain, domain, sourceUuid, targetUuid, relation);
|
||||||
|
List<HashMap<String, Object>> rShipList = Neo4jUtil.getGraphRelationShip(rSql);
|
||||||
|
ships.addAll(rShipList);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rss.put("nodes", nodes);
|
||||||
|
rss.put("ships", ships);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return rss;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量创建下级节点
|
||||||
|
*
|
||||||
|
* @param domain 领域
|
||||||
|
* @param sourceId 源节点id
|
||||||
|
* @param entityType 节点类型
|
||||||
|
* @param targetNames 目标节点名称数组
|
||||||
|
* @param relation 关系
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public HashMap<String, Object> batchCreateChildNode(String domain, String sourceId, Integer entityType,
|
||||||
|
String[] targetNames, String relation) {
|
||||||
|
HashMap<String, Object> rss = new HashMap<String, Object>();
|
||||||
|
List<HashMap<String, Object>> nodes = new ArrayList<HashMap<String, Object>>();
|
||||||
|
List<HashMap<String, Object>> ships = new ArrayList<HashMap<String, Object>>();
|
||||||
|
try {
|
||||||
|
String cypherSqlFmt = "create (n:`%s`{name:'%s',color:'#ff4500',r:30}) return n";
|
||||||
|
String cypherSql = String.format("match (n:`%s`) where id(n)=%s return n", domain, sourceId);
|
||||||
|
List<HashMap<String, Object>> sourceNodeList = Neo4jUtil.getGraphNode(cypherSql);
|
||||||
|
if (sourceNodeList.size() > 0) {
|
||||||
|
nodes.addAll(sourceNodeList);
|
||||||
|
for (String tn : targetNames) {
|
||||||
|
String targetNodeSql = String.format(cypherSqlFmt, domain, tn);
|
||||||
|
List<HashMap<String, Object>> targetNodeList = Neo4jUtil.getGraphNode(targetNodeSql);
|
||||||
|
if (targetNodeList.size() > 0) {
|
||||||
|
HashMap<String, Object> targetNode = targetNodeList.get(0);
|
||||||
|
nodes.add(targetNode);
|
||||||
|
String targetUuid = String.valueOf(targetNode.get("uuid"));
|
||||||
|
// 创建关系
|
||||||
|
String rSql = String.format(
|
||||||
|
"match(n:`%s`),(m:`%s`) where id(n)=%s and id(m)=%s create (n)-[r:RE {name:'%s'}]->(m) return r",
|
||||||
|
domain, domain, sourceId, targetUuid, relation);
|
||||||
|
List<HashMap<String, Object>> shipList = Neo4jUtil.getGraphRelationShip(rSql);
|
||||||
|
ships.addAll(shipList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rss.put("nodes", nodes);
|
||||||
|
rss.put("ships", ships);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return rss;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量创建同级节点
|
||||||
|
*
|
||||||
|
* @param domain 领域
|
||||||
|
* @param entityType 节点类型
|
||||||
|
* @param sourceNames 节点名称
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<HashMap<String, Object>> batchCreateSameNode(String domain, Integer entityType, String[] sourceNames) {
|
||||||
|
List<HashMap<String, Object>> rss = new ArrayList<HashMap<String, Object>>();
|
||||||
|
try {
|
||||||
|
String cypherSqlFmt = "create (n:`%s`{name:'%s',color:'#ff4500',r:30}) return n";
|
||||||
|
for (String tn : sourceNames) {
|
||||||
|
String sourceNodeSql = String.format(cypherSqlFmt, domain, tn, entityType);
|
||||||
|
List<HashMap<String, Object>> targetNodeList = Neo4jUtil.getGraphNode(sourceNodeSql);
|
||||||
|
rss.addAll(targetNodeList);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return rss;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加关系
|
||||||
|
*
|
||||||
|
* @param domain 领域
|
||||||
|
* @param sourceId 源节点id
|
||||||
|
* @param targetId 目标节点id
|
||||||
|
* @param ship 关系
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public HashMap<String, Object> createLink(String domain, long sourceId, long targetId, String ship) {
|
||||||
|
HashMap<String, Object> rss = new HashMap<String, Object>();
|
||||||
|
try {
|
||||||
|
String cypherSql = String.format("MATCH (n:`%s`),(m:`%s`) WHERE id(n)=%s AND id(m) = %s "
|
||||||
|
+ "CREATE (n)-[r:RE{name:'%s'}]->(m)" + "RETURN r", domain, domain, sourceId, targetId, ship);
|
||||||
|
List<HashMap<String, Object>> cypherResult = Neo4jUtil.getGraphRelationShip(cypherSql);
|
||||||
|
if (cypherResult.size() > 0) {
|
||||||
|
rss = cypherResult.get(0);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return rss;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HashMap<String, Object> createLinkByUuid(String domain, long sourceId, long targetId, String ship) {
|
||||||
|
HashMap<String, Object> rss = new HashMap<String, Object>();
|
||||||
|
try {
|
||||||
|
String cypherSql = String.format("MATCH (n:`%s`),(m:`%s`) WHERE n.uuid=%s AND m.uuid = %s "
|
||||||
|
+ "CREATE (n)-[r:RE{name:'%s'}]->(m)" + "RETURN r", domain, domain, sourceId, targetId, ship);
|
||||||
|
List<HashMap<String, Object>> cypherResult = Neo4jUtil.getGraphRelationShip(cypherSql);
|
||||||
|
if (cypherResult.size() > 0) {
|
||||||
|
rss = cypherResult.get(0);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return rss;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 更新关系
|
||||||
|
*
|
||||||
|
* @param domain 领域
|
||||||
|
* @param shipId 关系id
|
||||||
|
* @param shipName 关系名称
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public HashMap<String, Object> updateLink(String domain, long shipId, String shipName) {
|
||||||
|
HashMap<String, Object> rss = new HashMap<String, Object>();
|
||||||
|
try {
|
||||||
|
String cypherSql = String.format("MATCH (n:`%s`) -[r]->(m) where id(r)=%s set r.name='%s' return r", domain,
|
||||||
|
shipId, shipName);
|
||||||
|
List<HashMap<String, Object>> cypherResult = Neo4jUtil.getGraphRelationShip(cypherSql);
|
||||||
|
if (cypherResult.size() > 0) {
|
||||||
|
rss = cypherResult.get(0);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return rss;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除节点(先删除关系再删除节点)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<HashMap<String, Object>> deleteNode(String domain, long nodeId) {
|
||||||
|
List<HashMap<String, Object>> result = new ArrayList<HashMap<String, Object>>();
|
||||||
|
try {
|
||||||
|
String nSql = String.format("MATCH (n:`%s`) where id(n)=%s return n", domain, nodeId);
|
||||||
|
result = Neo4jUtil.getGraphNode(nSql);
|
||||||
|
String deleteRelationSql = String.format("MATCH (n:`%s`) -[r]-(m) where id(n)=%s detach delete r", domain, nodeId);
|
||||||
|
Neo4jUtil.runCypherSql(deleteRelationSql);
|
||||||
|
String deleteNodeSql = String.format("MATCH (n:`%s`) where id(n)=%s detach delete n", domain, nodeId);
|
||||||
|
Neo4jUtil.runCypherSql(deleteNodeSql);
|
||||||
|
return result;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除关系
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void deleteLink(String domain, long shipId) {
|
||||||
|
try {
|
||||||
|
String cypherSql = String.format("MATCH (n:`%s`) -[r]-(m) where id(r)=%s detach delete r", domain, shipId);
|
||||||
|
Neo4jUtil.runCypherSql(cypherSql);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 段落识别出的三元组生成图谱
|
||||||
|
*
|
||||||
|
* @param domain 领域名称
|
||||||
|
* @param entityType 实体类型
|
||||||
|
* @param operateType 操作类型
|
||||||
|
* @param sourceId 节点id
|
||||||
|
* @param rss 关系三元组
|
||||||
|
* [[startname;ship;endname],[startname1;ship1;endname1],[startname2;ship2;endname2]]
|
||||||
|
* @return node relationship
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public HashMap<String, Object> createGraphByText(String domain, Integer entityType, Integer operateType,
|
||||||
|
Integer sourceId, String[] rss) {
|
||||||
|
HashMap<String, Object> rsList = new HashMap<String, Object>();
|
||||||
|
try {
|
||||||
|
List<Object> nodeIds = new ArrayList<Object>();
|
||||||
|
List<HashMap<String, Object>> nodeList = new ArrayList<HashMap<String, Object>>();
|
||||||
|
List<HashMap<String, Object>> shipList = new ArrayList<HashMap<String, Object>>();
|
||||||
|
|
||||||
|
if (rss != null && rss.length > 0) {
|
||||||
|
for (String item : rss) {
|
||||||
|
String[] ns = item.split(";");
|
||||||
|
String nodeStart = ns[0];
|
||||||
|
String ship = ns[1];
|
||||||
|
String nodeEnd = ns[2];
|
||||||
|
String nodeStartSql = String.format("MERGE (n:`%s`{name:'%s',entityType:'%s'}) return n", domain,
|
||||||
|
nodeStart, entityType);
|
||||||
|
String nodeEndSql = String.format("MERGE (n:`%s`{name:'%s',entityType:'%s'}) return n", domain,
|
||||||
|
nodeEnd, entityType);
|
||||||
|
// 创建初始节点
|
||||||
|
List<HashMap<String, Object>> startNode = Neo4jUtil.getGraphNode(nodeStartSql);
|
||||||
|
// 创建结束节点
|
||||||
|
List<HashMap<String, Object>> endNode = Neo4jUtil.getGraphNode(nodeEndSql);
|
||||||
|
Object startId = startNode.get(0).get("uuid");
|
||||||
|
if (!nodeIds.contains(startId)) {
|
||||||
|
nodeIds.add(startId);
|
||||||
|
nodeList.addAll(startNode);
|
||||||
|
}
|
||||||
|
Object endId = endNode.get(0).get("uuid");
|
||||||
|
if (!nodeIds.contains(endId)) {
|
||||||
|
nodeIds.add(endId);
|
||||||
|
nodeList.addAll(endNode);
|
||||||
|
}
|
||||||
|
if (sourceId != null && sourceId > 0 && operateType == 2) {// 添加下级
|
||||||
|
String shipSql = String.format(
|
||||||
|
"MATCH (n:`%s`),(m:`%s`) WHERE id(n)=%s AND id(m) = %s "
|
||||||
|
+ "CREATE (n)-[r:RE{name:'%s'}]->(m)" + "RETURN r",
|
||||||
|
domain, domain, sourceId, startId, "");
|
||||||
|
List<HashMap<String, Object>> shipResult = Neo4jUtil.getGraphRelationShip(shipSql);
|
||||||
|
shipList.add(shipResult.get(0));
|
||||||
|
}
|
||||||
|
String shipSql = String.format("MATCH (n:`%s`),(m:`%s`) WHERE id(n)=%s AND id(m) = %s "
|
||||||
|
+ "CREATE (n)-[r:RE{name:'%s'}]->(m)" + "RETURN r", domain, domain, startId, endId, ship);
|
||||||
|
List<HashMap<String, Object>> shipResult = Neo4jUtil.getGraphRelationShip(shipSql);
|
||||||
|
shipList.addAll(shipResult);
|
||||||
|
|
||||||
|
}
|
||||||
|
rsList.put("node", nodeList);
|
||||||
|
rsList.put("relationship", shipList);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return rsList;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void batchCreateGraph(String domain, List<Map<String, Object>> params) {
|
||||||
|
try {
|
||||||
|
if (params != null && params.size() > 0) {
|
||||||
|
String nodeStr = Neo4jUtil.getFilterPropertiesJson(JsonHelper.toJSONString(params));
|
||||||
|
String nodeCypher = String
|
||||||
|
.format("UNWIND %s as row " + " MERGE (n:`%s` {name:row.SourceNode,source:row.Source})"
|
||||||
|
+ " MERGE (m:`%s` {name:row.TargetNode,source:row.Source})", nodeStr, domain, domain);
|
||||||
|
Neo4jUtil.runCypherSql(nodeCypher);
|
||||||
|
String relationShipCypher = String.format("UNWIND %s as row " + " MATCH (n:`%s` {name:row.SourceNode})"
|
||||||
|
+ " MATCH (m:`%s` {name:row.TargetNode})" + " MERGE (n)-[:RE{name:row.RelationShip}]->(m)",
|
||||||
|
nodeStr, domain, domain);
|
||||||
|
Neo4jUtil.runCypherSql(relationShipCypher);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void batchUpdateGraphNodesCoordinate(String domain,List<NodeCoordinateItem> params) {
|
||||||
|
try {
|
||||||
|
if (params != null && params.size() > 0) {
|
||||||
|
String nodeStr = Neo4jUtil.getFilterPropertiesJson(JsonHelper.toJSONString(params));
|
||||||
|
String nodeCypher = String
|
||||||
|
.format("UNWIND %s as row " + " MATCH (n:`%s`) where id(n)=row.uuid SET n.fx=row.fx,n.fy=row.fy", nodeStr, domain);
|
||||||
|
Neo4jUtil.runCypherSql(nodeCypher);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 批量导入csv
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void batchInsertByCsv(String domain, String csvUrl, int isCreateIndex) {
|
||||||
|
String loadNodeCypher1 = null;
|
||||||
|
String loadNodeCypher2 = null;
|
||||||
|
String addIndexCypher = null;
|
||||||
|
addIndexCypher = " CREATE INDEX ON :`" + domain + "`(name);";
|
||||||
|
loadNodeCypher1 = " USING PERIODIC COMMIT 500 LOAD CSV FROM '" + csvUrl + "' AS line " + " MERGE (:`" + domain
|
||||||
|
+ "` {name:line[0]});";
|
||||||
|
loadNodeCypher2 = " USING PERIODIC COMMIT 500 LOAD CSV FROM '" + csvUrl + "' AS line " + " MERGE (:`" + domain
|
||||||
|
+ "` {name:line[1]});";
|
||||||
|
// 拼接生产关系导入cypher
|
||||||
|
String loadRelCypher = null;
|
||||||
|
String type = "RE";
|
||||||
|
loadRelCypher = " USING PERIODIC COMMIT 500 LOAD CSV FROM '" + csvUrl + "' AS line " + " MATCH (m:`" + domain
|
||||||
|
+ "`),(n:`" + domain + "`) WHERE m.name=line[0] AND n.name=line[1] " + " MERGE (m)-[r:" + type + "]->(n) "
|
||||||
|
+ " SET r.name=line[2];";
|
||||||
|
if(isCreateIndex==0){//已经创建索引的不能重新创建
|
||||||
|
Neo4jUtil.runCypherSql(addIndexCypher);
|
||||||
|
}
|
||||||
|
Neo4jUtil.runCypherSql(loadNodeCypher1);
|
||||||
|
Neo4jUtil.runCypherSql(loadNodeCypher2);
|
||||||
|
Neo4jUtil.runCypherSql(loadRelCypher);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateNodeFileStatus(String domain, long nodeId, int status) {
|
||||||
|
try {
|
||||||
|
String nodeCypher = String.format("match (n:`%s`) where id(n)=%s set n.hasFile=%s ", domain, nodeId, status);
|
||||||
|
Neo4jUtil.runCypherSql(nodeCypher);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void updateNodeImg(String domain, long nodeId, String img) {
|
||||||
|
try {
|
||||||
|
String nodeCypher = String.format("match (n:`%s`) where id(n)=%s set n.image='%s' ", domain, nodeId, img);
|
||||||
|
Neo4jUtil.runCypherSql(nodeCypher);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void removeNodeImg(String domain, long nodeId) {
|
||||||
|
try {
|
||||||
|
String nodeCypher = String.format("match (n:`%s`) where id(n)=%s remove n.image ", domain, nodeId);
|
||||||
|
Neo4jUtil.runCypherSql(nodeCypher);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void updateCoordinateOfNode(String domain, String uuid, Double fx, Double fy) {
|
||||||
|
String cypher = null;
|
||||||
|
if (fx == null && fy == null) {
|
||||||
|
cypher = " MATCH (n:`" + domain + "`) where ID(n)=" + uuid
|
||||||
|
+ " set n.fx=null, n.fy=null; ";
|
||||||
|
} else {
|
||||||
|
assert fx != null;
|
||||||
|
if ("0.0".equals(fx.toString()) && "0.0".equals(fy.toString())) {
|
||||||
|
cypher = " MATCH (n:`" + domain + "`) where ID(n)=" + uuid
|
||||||
|
+ " set n.fx=null, n.fy=null; ";
|
||||||
|
} else {
|
||||||
|
cypher = " MATCH (n:`" + domain + "`) where ID(n)=" + uuid
|
||||||
|
+ " set n.fx='" + fx + "', n.fy='" + fy + "';";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Neo4jUtil.runCypherSql(cypher);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,153 @@
|
|||||||
|
package com.warmer.web.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DataNode 构成的 map
|
||||||
|
* key: 组件DataNode 的id
|
||||||
|
* value: 组件DataNode 对象
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ComponentContainer {
|
||||||
|
HashMap<String, DataNode> dataNodeList;
|
||||||
|
List<DataLink> dataLinkList;
|
||||||
|
/**
|
||||||
|
* 构造方法
|
||||||
|
*/
|
||||||
|
public ComponentContainer() {
|
||||||
|
this.dataNodeList = new HashMap<>();
|
||||||
|
this.dataLinkList = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加DataNode 键值对
|
||||||
|
* @param dataNode
|
||||||
|
*/
|
||||||
|
public void addNode(DataNode dataNode) {
|
||||||
|
this.dataNodeList.put(dataNode.getId(), dataNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取map中的所有DataNode, 即全部map 中所有 value
|
||||||
|
* @return List<DataNode>
|
||||||
|
*/
|
||||||
|
public List<DataNode> getNodes() {
|
||||||
|
return new ArrayList<>(this.dataNodeList.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据key(nodeId), 把value(DataNode) 标记为 executedNode
|
||||||
|
*/
|
||||||
|
public void markExecutedDone(String nodeId) {
|
||||||
|
this.dataNodeList.get(nodeId).setExecuted(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标记该DataNode 为 executedNode
|
||||||
|
*/
|
||||||
|
public void markExecutedDone(DataNode dataNode) {
|
||||||
|
String nodeId = dataNode.getId();
|
||||||
|
this.markExecutedDone(nodeId);
|
||||||
|
}
|
||||||
|
public void markValidDone(DataNode dataNode) {
|
||||||
|
//String nodeId = dataNode.getId();
|
||||||
|
//this.dataNodeList.get(nodeId).setValid(true);
|
||||||
|
dataNode.setValid(true);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取startNode list
|
||||||
|
*/
|
||||||
|
public List<DataNode> getStartNodes() {
|
||||||
|
List<DataNode> startNodes=new ArrayList<>();
|
||||||
|
for (String key : this.dataNodeList.keySet()) {
|
||||||
|
List<String> sourceIds = this.getTargetIds();
|
||||||
|
boolean isStart = !sourceIds.contains(key);
|
||||||
|
if (isStart) {
|
||||||
|
DataNode dataNode = this.dataNodeList.get(key);
|
||||||
|
dataNode.setStart(true);
|
||||||
|
startNodes.add(dataNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return startNodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据nodeId 获取 DataNode
|
||||||
|
*/
|
||||||
|
public DataNode getDataNodeByNodeId(String nodeId) {
|
||||||
|
return this.dataNodeList.get(nodeId);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 根据nodeId list 获取 DataNode list
|
||||||
|
* @param list
|
||||||
|
* @return List<DataNode>
|
||||||
|
*/
|
||||||
|
public List<DataNode> getNodesByList(List<String> list) {
|
||||||
|
List<DataNode> nodeList = new ArrayList<>();
|
||||||
|
list.forEach(nodeId -> {
|
||||||
|
DataNode node = this.dataNodeList.get(nodeId);
|
||||||
|
nodeList.add(node);
|
||||||
|
});
|
||||||
|
return nodeList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断当前节点所有一度前置节点是否全部执行完毕
|
||||||
|
* @param nodeId 节点id
|
||||||
|
* @return true 一度前置节点全部执行完毕
|
||||||
|
* false 一度前置节点未执行完毕
|
||||||
|
*/
|
||||||
|
public boolean isPreNodesExecuted(String nodeId) {
|
||||||
|
DataNode currentNode = this.dataNodeList.get(nodeId);
|
||||||
|
List<DataNode> preNodes = currentNode.getPrevNodes();
|
||||||
|
return preNodes.stream().allMatch(DataNode::isExecuted);
|
||||||
|
}
|
||||||
|
public boolean isPreNodesValid(String nodeId) {
|
||||||
|
DataNode currentNode = this.dataNodeList.get(nodeId);
|
||||||
|
List<DataNode> preNodes = currentNode.getPrevNodes();
|
||||||
|
return preNodes.stream().allMatch(DataNode::isValid);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 所有节点是否全部执行完毕
|
||||||
|
* @return true 流程节点全部执行完毕
|
||||||
|
* false 流程未执行完毕
|
||||||
|
*/
|
||||||
|
public boolean isAllExecuted() {
|
||||||
|
return this.getNodes().stream().allMatch(DataNode::isExecuted);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAllValid() {
|
||||||
|
return this.getNodes().stream().allMatch(DataNode::isValid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*添加link元素到linkList
|
||||||
|
* @param dataLink
|
||||||
|
*/
|
||||||
|
public void addLink(DataLink dataLink) {
|
||||||
|
this.dataLinkList.add(dataLink);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前link list中所有target节点的id,及除起始节点外的所有节点
|
||||||
|
* 如 a->b b->c b->d
|
||||||
|
* 则 b c d
|
||||||
|
* 的id会被返回
|
||||||
|
*/
|
||||||
|
public List<String> getTargetIds() {
|
||||||
|
List<String> list = new ArrayList<>();
|
||||||
|
this.dataLinkList.forEach(link -> {
|
||||||
|
String targetId = link.getTargetId();
|
||||||
|
if ( !list.contains(targetId) ) {
|
||||||
|
list.add(targetId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
package com.warmer.web.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据分析流程化配置中的 组件连接
|
||||||
|
* ComponentLink
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class DataLink {
|
||||||
|
|
||||||
|
String sourceId;
|
||||||
|
|
||||||
|
String targetId;
|
||||||
|
|
||||||
|
String label;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,46 @@
|
|||||||
|
package com.warmer.web.domain;
|
||||||
|
|
||||||
|
import com.warmer.web.request.GraphNodeItem;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
/**
|
||||||
|
* 数据分析流程化配置中的节点数据存放对象
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class DataNode {
|
||||||
|
/**
|
||||||
|
* 组件id
|
||||||
|
*/
|
||||||
|
private String id;
|
||||||
|
private String domain;
|
||||||
|
|
||||||
|
private String nodeName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 组件类型code:调用相关的服务
|
||||||
|
*/
|
||||||
|
private String nodeCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 组件数据json
|
||||||
|
*/
|
||||||
|
private GraphNodeItem data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 组件输入:所有指向当前节点的上一组件id集合
|
||||||
|
*/
|
||||||
|
private List<DataNode> prevNodes;
|
||||||
|
/**
|
||||||
|
* 组件输出:当前节点的下一组件id集合
|
||||||
|
*/
|
||||||
|
private List<DataNode> nextNodes;
|
||||||
|
|
||||||
|
|
||||||
|
private boolean isStart;
|
||||||
|
|
||||||
|
private boolean isExecuted;
|
||||||
|
private boolean isValid;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,75 @@
|
|||||||
|
package com.warmer.web.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CategoryNode {
|
||||||
|
/**
|
||||||
|
*节点id
|
||||||
|
*/
|
||||||
|
|
||||||
|
private Integer categoryNodeId;
|
||||||
|
/**
|
||||||
|
*节点名称
|
||||||
|
*/
|
||||||
|
private String categoryNodeName;
|
||||||
|
/**
|
||||||
|
*节点编码
|
||||||
|
*/
|
||||||
|
private String categoryNodeCode;
|
||||||
|
/**
|
||||||
|
*节点颜色
|
||||||
|
*/
|
||||||
|
private String color;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统编码
|
||||||
|
*/
|
||||||
|
private String systemCode;
|
||||||
|
/**
|
||||||
|
*分类id
|
||||||
|
*/
|
||||||
|
private Long categoryId;
|
||||||
|
/**
|
||||||
|
*节点父id
|
||||||
|
*/
|
||||||
|
private Integer parentId;
|
||||||
|
/**
|
||||||
|
*节点父编码
|
||||||
|
*/
|
||||||
|
private String parentCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 附件uuid
|
||||||
|
*/
|
||||||
|
private String fileUuid;
|
||||||
|
/**
|
||||||
|
*层数
|
||||||
|
*/
|
||||||
|
private Integer treeLevel;
|
||||||
|
/**
|
||||||
|
*是否叶子节点
|
||||||
|
*/
|
||||||
|
private Integer isLeaf;
|
||||||
|
/**
|
||||||
|
*状态
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
|
||||||
|
private String createUser;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Date createTime;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private String updateUser;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private Date updateTime;
|
||||||
|
}
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
package com.warmer.web.entity;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.Tolerate;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
public class KgDomain {
|
||||||
|
private Integer id;
|
||||||
|
private String name;
|
||||||
|
private String label;
|
||||||
|
private long nodeCount;
|
||||||
|
private long shipCount;
|
||||||
|
private Integer status;
|
||||||
|
private String createUser;
|
||||||
|
private String modifyUser;
|
||||||
|
private Integer type;
|
||||||
|
private Integer commend;
|
||||||
|
private Date createTime;
|
||||||
|
private Date modifyTime;
|
||||||
|
@Tolerate
|
||||||
|
public KgDomain(){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
package com.warmer.web.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class KgFeedBack {
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String desc;
|
||||||
|
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
private Date createTime;
|
||||||
|
}
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
package com.warmer.web.entity;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* kg_graph_link
|
||||||
|
* @author
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class KgGraphLink implements Serializable {
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
private String from;
|
||||||
|
|
||||||
|
private String to;
|
||||||
|
|
||||||
|
private String label;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 领域id
|
||||||
|
*/
|
||||||
|
private Integer domainId;
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
}
|
||||||
@ -0,0 +1,78 @@
|
|||||||
|
package com.warmer.web.entity;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* kg_graph_node
|
||||||
|
* @author
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class KgGraphNode implements Serializable {
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
private Long nodeId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点唯一标识
|
||||||
|
*/
|
||||||
|
private String nodeKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据表id
|
||||||
|
*/
|
||||||
|
private Integer tableId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点名称
|
||||||
|
*/
|
||||||
|
private String nodeName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点类型
|
||||||
|
*/
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点左位置
|
||||||
|
*/
|
||||||
|
private String left;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点右位置
|
||||||
|
*/
|
||||||
|
private String top;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点图标
|
||||||
|
*/
|
||||||
|
private String ico;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点状态
|
||||||
|
*/
|
||||||
|
private String state;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否可以拖动,1=是,0=否
|
||||||
|
*/
|
||||||
|
private Integer viewOnly;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据源id
|
||||||
|
*/
|
||||||
|
private Integer sourceId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 领域id
|
||||||
|
*/
|
||||||
|
private Integer domainId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否是起点
|
||||||
|
*/
|
||||||
|
private Integer startNode;
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
}
|
||||||
@ -0,0 +1,65 @@
|
|||||||
|
package com.warmer.web.entity;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* kg_graph_node_map
|
||||||
|
* @author
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class KgGraphNodeMap implements Serializable {
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列id
|
||||||
|
*/
|
||||||
|
private Integer columnId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列图标
|
||||||
|
*/
|
||||||
|
private String ico;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否主键
|
||||||
|
*/
|
||||||
|
private Integer isPrimary;
|
||||||
|
/**
|
||||||
|
* 主实体
|
||||||
|
*/
|
||||||
|
private Integer isMainEntity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据列key
|
||||||
|
*/
|
||||||
|
private String itemId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 原始数据列字段
|
||||||
|
*/
|
||||||
|
private String itemCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列别名
|
||||||
|
*/
|
||||||
|
private String itemName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字段类型
|
||||||
|
*/
|
||||||
|
private String itemType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点id
|
||||||
|
*/
|
||||||
|
private Long nodeId;
|
||||||
|
/**
|
||||||
|
* 领域id
|
||||||
|
*/
|
||||||
|
private Integer domainId;
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
package com.warmer.web.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class KgNodeDetail {
|
||||||
|
private Integer id;
|
||||||
|
private Integer domainId;
|
||||||
|
private Integer nodeId;
|
||||||
|
private String content;
|
||||||
|
private Integer status;
|
||||||
|
private String createUser;
|
||||||
|
private String createTime;
|
||||||
|
private String modifyUser;
|
||||||
|
private String modifyTime;
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package com.warmer.web.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class KgNodeDetailFile {
|
||||||
|
private Integer id;
|
||||||
|
private Integer domainId;
|
||||||
|
private Integer nodeId;
|
||||||
|
private String fileName;
|
||||||
|
private Integer imageType;
|
||||||
|
private Integer status;
|
||||||
|
private String createUser;
|
||||||
|
private String createTime;
|
||||||
|
private String modifyUser;
|
||||||
|
private String modifyTime;
|
||||||
|
}
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
package com.warmer.web.job;
|
||||||
|
|
||||||
|
import com.warmer.base.util.Neo4jUtil;
|
||||||
|
import com.warmer.web.entity.KgDomain;
|
||||||
|
import com.warmer.web.service.KGGraphService;
|
||||||
|
import com.warmer.web.service.KGManagerService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class DomainCleanService {
|
||||||
|
@Autowired
|
||||||
|
private KGGraphService kgGraphService;
|
||||||
|
@Autowired
|
||||||
|
private KGManagerService kgService;
|
||||||
|
@Scheduled(cron = "0 0 1 * * ? ")
|
||||||
|
public void clearDomain(){
|
||||||
|
List<KgDomain> domains = kgService.getDomains();
|
||||||
|
if(domains!=null&&domains.size()>0){
|
||||||
|
for (KgDomain domainItem : domains) {
|
||||||
|
String cypher=String.format("match(n:`%s`) return count(n)",domainItem.getName());
|
||||||
|
long nodeCount = Neo4jUtil.getGraphValue(cypher);
|
||||||
|
if(nodeCount<10){
|
||||||
|
kgService.deleteDomain(domainItem.getId());
|
||||||
|
kgGraphService.deleteKGDomain(domainItem.getName());
|
||||||
|
// 删除索引
|
||||||
|
Neo4jUtil.deleteIndex(domainItem.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
package com.warmer.web.model;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class NodeItem{
|
||||||
|
private long uuid;
|
||||||
|
private String name;//显示名称
|
||||||
|
private String domain;//显示名称
|
||||||
|
private String color;//对应关系数据库字段
|
||||||
|
private Integer r;
|
||||||
|
/*private String x;
|
||||||
|
private String y;*/
|
||||||
|
public NodeItem(){
|
||||||
|
|
||||||
|
}
|
||||||
|
public NodeItem(long uuid,String name,String color){
|
||||||
|
this.uuid=uuid;
|
||||||
|
this.name=name;
|
||||||
|
this.color=color;
|
||||||
|
}
|
||||||
|
public NodeItem(long uuid,String name,String color,Integer r){
|
||||||
|
this.uuid=uuid;
|
||||||
|
this.name=name;
|
||||||
|
this.color=color;
|
||||||
|
this.r=r;
|
||||||
|
}
|
||||||
|
public NodeItem(long uuid,String name,String color,Integer r,String domain){
|
||||||
|
this.uuid=uuid;
|
||||||
|
this.name=name;
|
||||||
|
this.color=color;
|
||||||
|
this.r=r;
|
||||||
|
this.domain=domain;
|
||||||
|
}
|
||||||
|
}
|
||||||
324
kgBuilder-pro/src/main/java/com/warmer/web/model/TreeExcel.java
Normal file
324
kgBuilder-pro/src/main/java/com/warmer/web/model/TreeExcel.java
Normal file
@ -0,0 +1,324 @@
|
|||||||
|
package com.warmer.web.model;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.warmer.base.util.ColorInfo;
|
||||||
|
import com.warmer.base.util.JsonHelper;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
|
||||||
|
import org.apache.poi.hssf.usermodel.HSSFFont;
|
||||||
|
import org.apache.poi.hssf.util.HSSFColor;
|
||||||
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
|
import org.apache.poi.ss.usermodel.*;
|
||||||
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFColor;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFFont;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
|
||||||
|
public class TreeExcel {
|
||||||
|
protected Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
|
public interface IResultHandler {
|
||||||
|
TreeExcelRecordData store(String cellVal, String cellColor, TreeExcelRecordData parent, boolean isLeaf);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String filePath;
|
||||||
|
private InputStream inputStream;
|
||||||
|
private final boolean isExcel2003;
|
||||||
|
private Workbook wb = null;
|
||||||
|
private final IResultHandler resultHandler;
|
||||||
|
|
||||||
|
private String classId = "0";
|
||||||
|
private String classCode = "";
|
||||||
|
|
||||||
|
public TreeExcel(String filePath, IResultHandler handler) {
|
||||||
|
this.filePath = filePath;
|
||||||
|
this.resultHandler = handler;
|
||||||
|
isExcel2003 = filePath.matches("^.+\\.(?i)(xls)$");
|
||||||
|
}
|
||||||
|
|
||||||
|
public TreeExcel(String classId, String classCode, String filePath, IResultHandler handler) {
|
||||||
|
this.classId = classId;
|
||||||
|
this.classCode = classCode;
|
||||||
|
|
||||||
|
this.filePath = filePath;
|
||||||
|
this.resultHandler = handler;
|
||||||
|
isExcel2003 = filePath.matches("^.+\\.(?i)(xls)$");
|
||||||
|
}
|
||||||
|
|
||||||
|
public TreeExcel(String classId, String classCode, String fileName, InputStream inputStream, IResultHandler handler) {
|
||||||
|
this.classId = classId;
|
||||||
|
this.classCode = classCode;
|
||||||
|
this.inputStream = inputStream;
|
||||||
|
this.resultHandler = handler;
|
||||||
|
isExcel2003 = fileName.matches("^.+\\.(?i)(xls)$");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理流数据,无需保存临时excel
|
||||||
|
*/
|
||||||
|
public void handleByStream() throws IOException, InvalidFormatException {
|
||||||
|
wb = WorkbookFactory.create(inputStream);
|
||||||
|
handExcelData(wb);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理业务方法,需要保存临时execl副本,供后续业务使用
|
||||||
|
*/
|
||||||
|
public void handleByFile() throws IOException, InvalidFormatException {
|
||||||
|
InputStream stream = new FileInputStream(filePath);
|
||||||
|
wb = WorkbookFactory.create(stream);
|
||||||
|
handExcelData(wb);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理excel数据
|
||||||
|
*/
|
||||||
|
private void handExcelData(Workbook wb) throws JsonProcessingException {
|
||||||
|
for (int i = 0; i < wb.getNumberOfSheets(); i++) {
|
||||||
|
Sheet sheet = wb.getSheetAt(i);
|
||||||
|
if (sheet == null || sheet.getLastRowNum() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Row row = null;
|
||||||
|
int totalRow = sheet.getLastRowNum();
|
||||||
|
log.info("共有" + totalRow + "行");
|
||||||
|
for (int r = 0; r <= sheet.getLastRowNum(); r++) {
|
||||||
|
row = sheet.getRow(r);
|
||||||
|
if (null == row) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
short minColIx = row.getFirstCellNum();
|
||||||
|
short maxColIx = row.getLastCellNum();
|
||||||
|
for (short colIx = minColIx; colIx < maxColIx; colIx++) {
|
||||||
|
Cell cell = row.getCell(colIx);
|
||||||
|
String cellVal = getCellVal(cell);
|
||||||
|
String cellColor = getCellColor(cell);
|
||||||
|
TreeExcelRecordData data = new TreeExcelRecordData();
|
||||||
|
data.setClassCode(this.classCode);
|
||||||
|
data.setRecordId(this.classId);
|
||||||
|
if (colIx > minColIx) {
|
||||||
|
CellModel cellModel = getCellValIfMerged(wb, sheet, row, r, colIx - 1);
|
||||||
|
if (cellModel != null) {
|
||||||
|
String val = cellModel.getFontName();
|
||||||
|
data = JsonHelper.parseObject(val, TreeExcelRecordData.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String recordId = "";
|
||||||
|
boolean isLeaf = colIx == maxColIx - 1;
|
||||||
|
if (StringUtils.isNotBlank(cellVal)) {
|
||||||
|
TreeExcelRecordData result = resultHandler.store(cellVal, cellColor, data, isLeaf);
|
||||||
|
String json = JsonHelper.toJSONString(result);
|
||||||
|
setFont(wb, json, colIx, row);
|
||||||
|
}
|
||||||
|
log.info(String.format("cellVal:%s recordId:%s parentId:%s isLeaf:%s,color:%s", cellVal, recordId, data.getRecordId(), isLeaf, cellColor));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String getCellVal(Cell cell) {
|
||||||
|
if (cell == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
String cellVal = "";
|
||||||
|
if (cell.getCellType() == CellType.NUMERIC) {
|
||||||
|
|
||||||
|
java.text.DecimalFormat formatter = new java.text.DecimalFormat("########.####");
|
||||||
|
cellVal = formatter.format(cell.getNumericCellValue());
|
||||||
|
|
||||||
|
} else if (cell.getCellType() == CellType.BOOLEAN) {
|
||||||
|
cellVal = String.valueOf(cell.getBooleanCellValue());
|
||||||
|
} else if (cell.getCellType() == CellType.FORMULA) {
|
||||||
|
try {
|
||||||
|
cellVal = cell.getStringCellValue();
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
cellVal = String.valueOf(cell.getNumericCellValue());
|
||||||
|
}
|
||||||
|
System.out.println(cellVal);
|
||||||
|
} else {
|
||||||
|
cellVal = cell.getStringCellValue();
|
||||||
|
}
|
||||||
|
return cellVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getCellColor(Cell cell) {
|
||||||
|
if (cell == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
CellStyle cellStyle = cell.getCellStyle();
|
||||||
|
ColorInfo bgColor = null;
|
||||||
|
if (cellStyle.getFillPattern() == FillPatternType.SOLID_FOREGROUND) {
|
||||||
|
bgColor = excelColor2UOF(cellStyle.getFillForegroundColorColor());
|
||||||
|
}
|
||||||
|
if (bgColor == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
if (bgColor.A > 0) {
|
||||||
|
return String.format("rgba(%s,%s,%s,%s)", bgColor.R, bgColor.G, bgColor.B, bgColor.A);
|
||||||
|
}
|
||||||
|
return String.format("rgb(%s,%s,%s)", bgColor.R, bgColor.G, bgColor.B);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* excel(包含97和2007)中颜色转化为uof颜色
|
||||||
|
*
|
||||||
|
* @param color 颜色序号
|
||||||
|
* @return 颜色或者null
|
||||||
|
*/
|
||||||
|
private static ColorInfo excelColor2UOF(Color color) {
|
||||||
|
if (color == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ColorInfo ci = null;
|
||||||
|
if (color instanceof XSSFColor) {// .xlsx
|
||||||
|
XSSFColor xc = (XSSFColor) color;
|
||||||
|
byte[] b = xc.getRGB();
|
||||||
|
//CTColor ctColor = xc.getCTColor();
|
||||||
|
if (b != null) {// 一定是argb
|
||||||
|
int t = 0;
|
||||||
|
if (b[0] < 0) {
|
||||||
|
t = b[0] + 255;
|
||||||
|
}
|
||||||
|
if (b.length > 3) {
|
||||||
|
ci = ColorInfo.fromARGB(formatColorIndex(b[0]),formatColorIndex(b[1]),formatColorIndex(b[2]), b[3]);
|
||||||
|
} else {
|
||||||
|
ci = ColorInfo.fromARGB(formatColorIndex(b[0]),formatColorIndex(b[1]),formatColorIndex(b[2]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (color instanceof HSSFColor) {// .xls
|
||||||
|
HSSFColor hc = (HSSFColor) color;
|
||||||
|
short[] s = hc.getTriplet();// 一定是rgb
|
||||||
|
if (s != null) {
|
||||||
|
int t = 0;
|
||||||
|
if (s[0] < 0) {
|
||||||
|
t = s[0] + 255;
|
||||||
|
}
|
||||||
|
if (s.length > 3) {
|
||||||
|
ci = ColorInfo.fromARGB(formatColorIndex(s[0]),formatColorIndex(s[1]),formatColorIndex(s[2]), s[3]);
|
||||||
|
} else {
|
||||||
|
ci = ColorInfo.fromARGB(formatColorIndex(s[0]),formatColorIndex(s[1]),formatColorIndex(s[2]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ci;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int formatColorIndex(short v) {
|
||||||
|
int t = v;
|
||||||
|
if (v < 0) {
|
||||||
|
t = v + 255;
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setFont(Workbook wb, String val, int col, Row row) {
|
||||||
|
if (isExcel2003) {
|
||||||
|
HSSFCellStyle style = (HSSFCellStyle) wb.createCellStyle();
|
||||||
|
HSSFFont font = (HSSFFont) wb.createFont();
|
||||||
|
font.setFontName(val);
|
||||||
|
style.setFont(font);
|
||||||
|
row.getCell(col).setCellStyle(style);
|
||||||
|
} else {
|
||||||
|
XSSFCellStyle style = (XSSFCellStyle) wb.createCellStyle();
|
||||||
|
XSSFFont font = (XSSFFont) wb.createFont();
|
||||||
|
font.setFontName(val);
|
||||||
|
style.setFont(font);
|
||||||
|
row.getCell(col).setCellStyle(style);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getFont(Workbook wb, int col, Row row) {
|
||||||
|
String name = "";
|
||||||
|
if (row == null || row.getCell(col) == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
if (isExcel2003) {
|
||||||
|
name = ((HSSFCellStyle) row.getCell(col).getCellStyle()).getFont(wb).getFontName();
|
||||||
|
} else {
|
||||||
|
name = ((XSSFCellStyle) row.getCell(col).getCellStyle()).getFont().getFontName();
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CellModel getCellValIfMerged(Workbook wb, Sheet sheet, Row row, int rowIndex, int col) {
|
||||||
|
Cell cell = row.getCell(col);
|
||||||
|
String cellVal = getCellVal(cell);
|
||||||
|
String cellColor = getCellColor(cell);
|
||||||
|
String fontName = getFont(wb, col, row);
|
||||||
|
if (!StringUtils.isNotBlank(cellVal)) {
|
||||||
|
return getMergedRegionValue(wb, sheet, rowIndex, col);
|
||||||
|
}
|
||||||
|
return new CellModel(cellVal, fontName, cellColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
private CellModel getMergedRegionValue(Workbook wb, Sheet sheet, int row, int column) {
|
||||||
|
int sheetMergeCount = sheet.getNumMergedRegions();
|
||||||
|
|
||||||
|
for (int i = 0; i < sheetMergeCount; i++) {
|
||||||
|
CellRangeAddress ca = sheet.getMergedRegion(i);
|
||||||
|
int firstColumn = ca.getFirstColumn();
|
||||||
|
int lastColumn = ca.getLastColumn();
|
||||||
|
int firstRow = ca.getFirstRow();
|
||||||
|
int lastRow = ca.getLastRow();
|
||||||
|
|
||||||
|
if (row >= firstRow && row <= lastRow) {
|
||||||
|
if (column >= firstColumn && column <= lastColumn) {
|
||||||
|
Row fRow = sheet.getRow(firstRow);
|
||||||
|
Cell fCell = fRow.getCell(firstColumn);
|
||||||
|
String fontName = getFont(wb, firstColumn, fRow);
|
||||||
|
String cellVal = getCellVal(fCell);
|
||||||
|
|
||||||
|
return new CellModel(cellVal, fontName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
class CellModel {
|
||||||
|
private String cellVal;
|
||||||
|
private String fontName;
|
||||||
|
private String cellColor;
|
||||||
|
|
||||||
|
public CellModel(String cellVal, String fontName) {
|
||||||
|
this.cellVal = cellVal;
|
||||||
|
this.fontName = fontName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CellModel(String cellVal, String fontName, String cellColor) {
|
||||||
|
this.cellVal = cellVal;
|
||||||
|
this.fontName = fontName;
|
||||||
|
this.cellColor = cellColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCellVal() {
|
||||||
|
return cellVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCellVal(String cellVal) {
|
||||||
|
this.cellVal = cellVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFontName() {
|
||||||
|
return fontName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFontName(String fontName) {
|
||||||
|
this.fontName = fontName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
package com.warmer.web.model;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class TreeExcelRecordData {
|
||||||
|
private String recordId;
|
||||||
|
private String classCode;
|
||||||
|
private String classPath;
|
||||||
|
private String linkName;
|
||||||
|
|
||||||
|
public String getClassPath() {
|
||||||
|
if (classPath == null){
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return classPath;
|
||||||
|
}
|
||||||
|
public String getClassCode(){
|
||||||
|
if (classCode == null){
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return classCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,63 @@
|
|||||||
|
package com.warmer.web.model;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class TreeNode {
|
||||||
|
/**
|
||||||
|
* 节点key值,可自由组合,需保证唯一
|
||||||
|
*/
|
||||||
|
private String key;
|
||||||
|
/**
|
||||||
|
* 节点ID
|
||||||
|
*/
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点Level
|
||||||
|
*/
|
||||||
|
private Integer treeLevel;
|
||||||
|
/**
|
||||||
|
* 显示节点文本
|
||||||
|
*/
|
||||||
|
private String label;
|
||||||
|
/**
|
||||||
|
* 节点状态,open=1 closed=0
|
||||||
|
*/
|
||||||
|
private Integer state;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点是否被选中 true false
|
||||||
|
*/
|
||||||
|
private boolean checked = false;
|
||||||
|
/**
|
||||||
|
* 节点属性
|
||||||
|
*/
|
||||||
|
private Map<String, Object> attributes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 节点的子节点
|
||||||
|
*/
|
||||||
|
private List<TreeNode> children = new ArrayList<TreeNode>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父ID
|
||||||
|
*/
|
||||||
|
private Integer parentId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父节点唯一标识,自由组合,保证唯一
|
||||||
|
*/
|
||||||
|
private String parentKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否是叶子节点
|
||||||
|
*/
|
||||||
|
private boolean isLeaf = false;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
package com.warmer.web.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class BatchCreateNodeItem {
|
||||||
|
private String domain;
|
||||||
|
private String sourceId;
|
||||||
|
private String sourceName;
|
||||||
|
private Integer entityType;
|
||||||
|
private String targetNames ;
|
||||||
|
private String[] sourceNames ;
|
||||||
|
private String relation;
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
package com.warmer.web.request;
|
||||||
|
|
||||||
|
|
||||||
|
import com.warmer.base.common.PageQuery;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CategoryNodeQuery extends PageQuery {
|
||||||
|
private String Name;
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
package com.warmer.web.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CreateLinkItem {
|
||||||
|
private String domain;
|
||||||
|
private long sourceId;
|
||||||
|
private long targetId;
|
||||||
|
private String ship;
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
package com.warmer.web.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class GraphItem implements Serializable {
|
||||||
|
Integer domainId;
|
||||||
|
String domainName;
|
||||||
|
private List<GraphNodeItem> nodeList;
|
||||||
|
private List<GraphLinkItem> lineList;
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
package com.warmer.web.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class GraphLinkItem implements Serializable {
|
||||||
|
private String from;
|
||||||
|
private String to;
|
||||||
|
private String label;
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package com.warmer.web.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class GraphNodeColumnItem implements Serializable {
|
||||||
|
private Integer columnId;
|
||||||
|
private String ico;
|
||||||
|
private Integer isPrimary;
|
||||||
|
private Integer isMainEntity;
|
||||||
|
private String itemId;
|
||||||
|
private String itemCode;
|
||||||
|
private String itemName;
|
||||||
|
private String itemType;
|
||||||
|
private Long nodeId;
|
||||||
|
}
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
package com.warmer.web.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class GraphNodeItem implements Serializable {
|
||||||
|
private String nodeKey;
|
||||||
|
private String nodeName;
|
||||||
|
private String type;
|
||||||
|
private String left;
|
||||||
|
private String top;
|
||||||
|
private String ico;
|
||||||
|
private String state;
|
||||||
|
private Integer viewOnly;
|
||||||
|
private String alia;
|
||||||
|
private Integer sourceId;
|
||||||
|
private Integer tableId;
|
||||||
|
private Integer domainId;
|
||||||
|
private Integer startNode;
|
||||||
|
private List<GraphNodeColumnItem> items;
|
||||||
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package com.warmer.web.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class GraphQuery{
|
||||||
|
|
||||||
|
private int domainId;
|
||||||
|
private Integer type;//0=手动创建,1=三元组导入,2=excel导入,3=er图构建
|
||||||
|
private Integer commend;
|
||||||
|
private String domain;
|
||||||
|
private String nodeName;
|
||||||
|
private String[] relation;
|
||||||
|
private int matchType;
|
||||||
|
private int pageSize = 10;
|
||||||
|
private int pageIndex = 1;
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
package com.warmer.web.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class KgNodeItem {
|
||||||
|
private String domain;
|
||||||
|
private String nodeId;
|
||||||
|
private String nodeName;
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
package com.warmer.web.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class NodeCoordinateItem {
|
||||||
|
private Integer uuid;
|
||||||
|
private Double fx;
|
||||||
|
private Double fy;
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
package com.warmer.web.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class NodeCoordinateSubmitItem {
|
||||||
|
private String domain;
|
||||||
|
private List<NodeCoordinateItem> nodes;
|
||||||
|
}
|
||||||
@ -0,0 +1,27 @@
|
|||||||
|
package com.warmer.web.service;
|
||||||
|
|
||||||
|
import com.warmer.web.domain.DataNode;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 流程组件父类
|
||||||
|
*
|
||||||
|
* @author tanc
|
||||||
|
* @time 2022-1-21 10:03:59
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@Data
|
||||||
|
@Slf4j
|
||||||
|
public abstract class AbstractWorkFlowService {
|
||||||
|
/**
|
||||||
|
* 传入参数为CpNode的id
|
||||||
|
* 组建逻辑之执行成功返回true, 执行失败返回false
|
||||||
|
*
|
||||||
|
* @param dataNode 当前组件
|
||||||
|
* @return 是否处理成功
|
||||||
|
*/
|
||||||
|
public abstract boolean process(DataNode dataNode);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,62 @@
|
|||||||
|
package com.warmer.web.service;
|
||||||
|
|
||||||
|
import com.warmer.web.entity.CategoryNode;
|
||||||
|
import com.warmer.web.model.TreeNode;
|
||||||
|
import com.warmer.web.request.CategoryNodeQuery;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public interface CategoryNodeService {
|
||||||
|
int deleteByPrimaryKey(Integer id);
|
||||||
|
|
||||||
|
int insert(CategoryNode record);
|
||||||
|
|
||||||
|
int batchInsert(List<CategoryNode> records);
|
||||||
|
|
||||||
|
void batchUpdateExpression(List<CategoryNode> records);
|
||||||
|
|
||||||
|
CategoryNode selectByPrimaryKey(Integer categoryNodeId);
|
||||||
|
|
||||||
|
int updateByPrimaryKey(CategoryNode record);
|
||||||
|
|
||||||
|
int reName(Integer categoryNodeId,String categoryNodeName);
|
||||||
|
|
||||||
|
int updateCodeByPrimaryKey(Integer categoryNodeId,String systemCode);
|
||||||
|
|
||||||
|
void initSystemCode(Long categoryId,String fileUuid);
|
||||||
|
|
||||||
|
void updateNodeRelation(Long categoryId,String fileUuid,Integer categoryNodeId);
|
||||||
|
|
||||||
|
void updateSystemCodeFullPath(Long categoryId,String fileUuid);
|
||||||
|
|
||||||
|
void updateTreeLevel(Long categoryId);
|
||||||
|
|
||||||
|
int updateLeafStatusByPrimaryKey(Integer categoryNodeId,Integer isLeaf);
|
||||||
|
|
||||||
|
List<CategoryNode> queryForList(CategoryNodeQuery queryItem);
|
||||||
|
|
||||||
|
List<TreeNode> selectByParentId(Long categoryId, Integer parentId);
|
||||||
|
|
||||||
|
List<CategoryNode> selectByParentIdAndName(Long categoryId,Integer parentId,String categoryNodeName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前分类的所有节点数据,使用mysql8.0递归查询
|
||||||
|
* @param categoryId 指定分类id
|
||||||
|
* @return 当前分类的所有节点数据
|
||||||
|
*/
|
||||||
|
List<CategoryNode> queryForTree( Long categoryId, Integer categoryNodeId);
|
||||||
|
List<CategoryNode> selectTreeForParent( Integer categoryNodeId);
|
||||||
|
List<CategoryNode> selectTreeForParentBySystemCode( String systemCode);
|
||||||
|
List<CategoryNode> selectRecentEditNode( Long categoryId);
|
||||||
|
List<TreeNode> getTreeData(Long categoryId, Integer categoryNodeId);
|
||||||
|
/**
|
||||||
|
* 删除附件导入的节点
|
||||||
|
* @param fileUuid 附件生成的uuid
|
||||||
|
*/
|
||||||
|
int deleteNodeByFileUuid( String fileUuid, String systemCode);
|
||||||
|
|
||||||
|
int deleteNodeBySystemLeftRegular( String systemCode);
|
||||||
|
|
||||||
|
List<CategoryNode> selectByFileUuid( String fileUuid);
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package com.warmer.web.service;
|
||||||
|
|
||||||
|
import com.warmer.web.entity.KgFeedBack;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface FeedBackService {
|
||||||
|
int deleteByPrimaryKey(Integer id);
|
||||||
|
|
||||||
|
int insert(KgFeedBack record);
|
||||||
|
|
||||||
|
KgFeedBack selectByPrimaryKey(Integer id);
|
||||||
|
|
||||||
|
List<KgFeedBack> queryForList(KgFeedBack queryItem);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package com.warmer.web.service;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface IWorkFlowDirectorService {
|
||||||
|
/**
|
||||||
|
* 导演方法。
|
||||||
|
* 从config json串中提取组件和连接信息
|
||||||
|
* 然后依次执行执行流程
|
||||||
|
* 1. 先执行开始节点组件,
|
||||||
|
* 2. 根据last pre nodes是否执行完毕,调用后置组件服务
|
||||||
|
*
|
||||||
|
* @param dataAnalyseId 数据分析配置id
|
||||||
|
*/
|
||||||
|
void direct(int dataAnalyseId) throws JsonProcessingException;
|
||||||
|
}
|
||||||
@ -0,0 +1,242 @@
|
|||||||
|
package com.warmer.web.service;
|
||||||
|
|
||||||
|
import com.warmer.base.util.GraphPageRecord;
|
||||||
|
import com.warmer.web.model.NodeItem;
|
||||||
|
import com.warmer.web.request.GraphQuery;
|
||||||
|
import com.warmer.web.request.NodeCoordinateItem;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface KGGraphService {
|
||||||
|
/**
|
||||||
|
* 领域标签分页
|
||||||
|
* @param queryItem
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
GraphPageRecord<HashMap<String, Object>> getPageDomain(GraphQuery queryItem);
|
||||||
|
/**
|
||||||
|
* 删除Neo4j 标签
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
*/
|
||||||
|
void deleteKGDomain(String domain);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询图谱节点和关系
|
||||||
|
*
|
||||||
|
* @param query
|
||||||
|
* @return node relationship
|
||||||
|
*/
|
||||||
|
HashMap<String, Object> queryGraphResult(GraphQuery query);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取节点列表
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* @param pageIndex
|
||||||
|
* @param pageSize
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
HashMap<String, Object> getdomainnodes(String domain, Integer pageIndex, Integer pageSize);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取某个领域指定节点拥有的上下级的节点数
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* @param nodeId
|
||||||
|
* @return long 数值
|
||||||
|
*/
|
||||||
|
long getRelationNodeCount(String domain, long nodeId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建领域,默认创建一个新的节点,给节点附上默认属性
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
*/
|
||||||
|
void createDomain(String domain);
|
||||||
|
void quickCreateDomain(String domain,String nodeName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取/展开更多节点,找到和该节点有关系的节点
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* @param nodeId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
HashMap<String, Object> getMoreRelationNode(String domain, String nodeId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新节点名称
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* @param nodeId
|
||||||
|
* @param nodeName
|
||||||
|
* @return 修改后的节点
|
||||||
|
*/
|
||||||
|
HashMap<String, Object> updateNodeName(String domain, String nodeId, String nodeName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建单个节点
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* @param entity
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
HashMap<String, Object> createNode(String domain, NodeItem entity);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量创建节点和关系
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* 领域
|
||||||
|
* @param sourceName
|
||||||
|
* 源节点
|
||||||
|
* @param relation
|
||||||
|
* 关系
|
||||||
|
* @param targetNames
|
||||||
|
* 目标节点数组
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
HashMap<String, Object> batchCreateNode(String domain, String sourceName, String relation, String[] targetNames);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量创建下级节点
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* 领域
|
||||||
|
* @param sourceId
|
||||||
|
* 源节点id
|
||||||
|
* @param entityType
|
||||||
|
* 节点类型
|
||||||
|
* @param targetNames
|
||||||
|
* 目标节点名称数组
|
||||||
|
* @param relation
|
||||||
|
* 关系
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
HashMap<String, Object> batchCreateChildNode(String domain, String sourceId, Integer entityType,
|
||||||
|
String[] targetNames, String relation);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量创建同级节点
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* 领域
|
||||||
|
* @param entityType
|
||||||
|
* 节点类型
|
||||||
|
* @param sourceNames
|
||||||
|
* 节点名称
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<HashMap<String, Object>> batchCreateSameNode(String domain, Integer entityType, String[] sourceNames);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加关系
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* 领域
|
||||||
|
* @param sourceId
|
||||||
|
* 源节点id
|
||||||
|
* @param targetId
|
||||||
|
* 目标节点id
|
||||||
|
* @param ship
|
||||||
|
* 关系
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
HashMap<String, Object> createLink(String domain, long sourceId, long targetId, String ship);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新关系
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* 领域
|
||||||
|
* @param shipId
|
||||||
|
* 关系id
|
||||||
|
* @param shipName
|
||||||
|
* 关系名称
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
HashMap<String, Object> updateLink(String domain, long shipId, String shipName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除节点(先删除关系再删除节点)
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* @param nodeId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<HashMap<String, Object>> deleteNode(String domain, long nodeId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除关系
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* @param shipId
|
||||||
|
*/
|
||||||
|
void deleteLink(String domain, long shipId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 段落识别出的三元组生成图谱
|
||||||
|
*
|
||||||
|
* @param domain
|
||||||
|
* @param entityType
|
||||||
|
* @param operateType
|
||||||
|
* @param sourceId
|
||||||
|
* @param rss
|
||||||
|
* 关系三元组
|
||||||
|
* [[startname;ship;endname],[startname1;ship1;endname1],[startname2;ship2;endname2]]
|
||||||
|
* @return node relationship
|
||||||
|
*/
|
||||||
|
HashMap<String, Object> createGraphByText(String domain, Integer entityType, Integer operateType, Integer sourceId,
|
||||||
|
String[] rss);
|
||||||
|
/**
|
||||||
|
* 批量创建节点,关系
|
||||||
|
* @param domain
|
||||||
|
* @param params 三元组 sourceNode,relationship,targetNode
|
||||||
|
*/
|
||||||
|
void batchCreateGraph(String domain, List<Map<String,Object>> params);
|
||||||
|
/**
|
||||||
|
* 导入csv
|
||||||
|
* @param domain
|
||||||
|
* @param csvUrl
|
||||||
|
* @param status
|
||||||
|
*/
|
||||||
|
void batchInsertByCSV(String domain, String csvUrl, int status) ;
|
||||||
|
/**
|
||||||
|
* 更新节点有无附件
|
||||||
|
* @param domain
|
||||||
|
* @param nodeId
|
||||||
|
* @param status
|
||||||
|
*/
|
||||||
|
void updateNodeFileStatus(String domain,long nodeId, int status);
|
||||||
|
/**
|
||||||
|
* 更新图谱节点的图片
|
||||||
|
* @param domain
|
||||||
|
* @param nodeId
|
||||||
|
* @param img
|
||||||
|
*/
|
||||||
|
void updateNodeImg(String domain, long nodeId, String img);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 移除节点图片
|
||||||
|
* @param domain
|
||||||
|
* @param nodeId
|
||||||
|
*/
|
||||||
|
void removeNodeImg(String domain, long nodeId);
|
||||||
|
|
||||||
|
void updateCoordinateOfNode(String domain, String uuid, Double fx, Double fy);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量更新节点坐标
|
||||||
|
* @param domain
|
||||||
|
* @param nodes
|
||||||
|
*/
|
||||||
|
void batchUpdateGraphNodesCoordinate(String domain,List<NodeCoordinateItem> nodes);
|
||||||
|
|
||||||
|
void importBySyz(MultipartFile file, HttpServletRequest request,String label,Integer isCreateIndex)throws Exception ;
|
||||||
|
void importByCategory(MultipartFile file, HttpServletRequest request,String label)throws Exception ;
|
||||||
|
}
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
package com.warmer.web.service;
|
||||||
|
|
||||||
|
|
||||||
|
import com.warmer.web.entity.KgDomain;
|
||||||
|
import com.warmer.web.entity.KgNodeDetail;
|
||||||
|
import com.warmer.web.entity.KgNodeDetailFile;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface KGManagerService {
|
||||||
|
List<KgDomain> getDomains();
|
||||||
|
List<KgDomain> getDomainList(String domainName,Integer type,Integer commend);
|
||||||
|
Integer saveDomain(KgDomain map);
|
||||||
|
Integer quickCreateDomain(String domain,String domainAlia,Integer type);
|
||||||
|
void updateDomain(KgDomain map);
|
||||||
|
void deleteDomain(Integer id);
|
||||||
|
List<KgDomain> getDomainByName(String domainName);
|
||||||
|
KgDomain getDomainByLabel(String label);
|
||||||
|
List<KgDomain> getDomainById(Integer domainId);
|
||||||
|
KgDomain selectById(Integer domainId);
|
||||||
|
void saveNodeImage(List<Map<String, Object>> mapList);
|
||||||
|
void saveNodeContent(Map<String, Object> map);
|
||||||
|
void updateNodeContent(Map<String, Object> map);
|
||||||
|
List<KgNodeDetailFile> getNodeImageList(Integer domainId, Integer nodeId);
|
||||||
|
List<KgNodeDetail> getNodeContent(Integer domainId, Integer nodeId);
|
||||||
|
void deleteNodeImage(Integer domainId,Integer nodeId);
|
||||||
|
}
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
package com.warmer.web.service;
|
||||||
|
|
||||||
|
import com.warmer.web.entity.KgGraphLink;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (KgGraphLink)表服务接口
|
||||||
|
*
|
||||||
|
* @author tanc
|
||||||
|
* @since 2021-12-24 15:53:53
|
||||||
|
*/
|
||||||
|
public interface KgGraphLinkService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过ID查询单条数据
|
||||||
|
*
|
||||||
|
* @param domainId 领域id
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
List<KgGraphLink> queryById(Integer domainId);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增数据
|
||||||
|
*
|
||||||
|
* @param kgGraphLink 实例对象
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
Integer insert(KgGraphLink kgGraphLink);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
package com.warmer.web.service;
|
||||||
|
|
||||||
|
import com.warmer.web.entity.KgGraphNodeMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (KgGraphNodeMap)表服务接口
|
||||||
|
*
|
||||||
|
* @author tanc
|
||||||
|
* @since 2021-12-24 15:53:51
|
||||||
|
*/
|
||||||
|
public interface KgGraphNodeMapService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过ID查询单条数据
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
List<KgGraphNodeMap> queryById(Integer id);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增数据
|
||||||
|
*
|
||||||
|
* @param kgGraphNodeMap 实例对象
|
||||||
|
* @return 实例对象
|
||||||
|
*/
|
||||||
|
Integer insert(KgGraphNodeMap kgGraphNodeMap);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package com.warmer.web.service;
|
||||||
|
|
||||||
|
import com.warmer.web.request.GraphItem;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (KgGraphNode)表服务接口
|
||||||
|
*
|
||||||
|
* @author tanc
|
||||||
|
* @since 2021-12-24 12:14:23
|
||||||
|
*/
|
||||||
|
public interface KgGraphNodeService {
|
||||||
|
|
||||||
|
void createNode(GraphItem submitItem) throws IOException;
|
||||||
|
|
||||||
|
GraphItem getDomainNode(Integer domainId) throws IOException;
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
package com.warmer.web.service;
|
||||||
|
|
||||||
|
public interface QuestionService {
|
||||||
|
|
||||||
|
void showDictPath();
|
||||||
|
String answer(String question) throws Exception;
|
||||||
|
}
|
||||||
@ -0,0 +1,181 @@
|
|||||||
|
package com.warmer.web.service.impl;
|
||||||
|
|
||||||
|
import com.warmer.web.dao.CategoryNodeDao;
|
||||||
|
import com.warmer.web.entity.CategoryNode;
|
||||||
|
import com.warmer.web.model.TreeNode;
|
||||||
|
import com.warmer.web.request.CategoryNodeQuery;
|
||||||
|
import com.warmer.web.service.CategoryNodeService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class CategoryNodeServiceImpl implements CategoryNodeService {
|
||||||
|
@Autowired
|
||||||
|
CategoryNodeDao categoryNodeRepository;
|
||||||
|
@Override
|
||||||
|
public int deleteByPrimaryKey(Integer id) {
|
||||||
|
return categoryNodeRepository.deleteByPrimaryKey(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int insert(CategoryNode record) {
|
||||||
|
return categoryNodeRepository.insert(record);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public int batchInsert(List<CategoryNode> records) {
|
||||||
|
return categoryNodeRepository.batchInsert(records);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void batchUpdateExpression(List<CategoryNode> records) {
|
||||||
|
categoryNodeRepository.batchUpdateExpression(records);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CategoryNode selectByPrimaryKey(Integer id) {
|
||||||
|
return categoryNodeRepository.selectByPrimaryKey(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int updateByPrimaryKey(CategoryNode record) {
|
||||||
|
return categoryNodeRepository.updateByPrimaryKey(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int updateCodeByPrimaryKey(Integer categoryNodeId, String systemCode) {
|
||||||
|
return categoryNodeRepository.updateCodeByPrimaryKey(categoryNodeId, systemCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initSystemCode(Long categoryId, String fileUuid) {
|
||||||
|
categoryNodeRepository.initSystemCode(categoryId,fileUuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateNodeRelation(Long categoryId, String fileUuid, Integer categoryNodeId) {
|
||||||
|
categoryNodeRepository.updateNodeRelation(categoryId,fileUuid,categoryNodeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateSystemCodeFullPath(Long categoryId, String fileUuid) {
|
||||||
|
categoryNodeRepository.updateSystemCodeFullPath(categoryId,fileUuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateTreeLevel(Long categoryId) {
|
||||||
|
categoryNodeRepository.updateTreeLevel(categoryId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int updateLeafStatusByPrimaryKey(Integer categoryNodeId, Integer isLeaf) {
|
||||||
|
return categoryNodeRepository.updateLeafStatusByPrimaryKey(categoryNodeId, isLeaf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int reName(Integer categoryNodeId, String categoryNodeName) {
|
||||||
|
return categoryNodeRepository.reName(categoryNodeId, categoryNodeName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int deleteNodeByFileUuid(String fileUuid,String systemCode) {
|
||||||
|
//删除与本身节点来自同一个文件的所有子节点
|
||||||
|
return categoryNodeRepository.deleteNodeByFileUuid(fileUuid,systemCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int deleteNodeBySystemLeftRegular(String systemCode) {
|
||||||
|
return categoryNodeRepository.deleteNodeBySystemLeftRegular(systemCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CategoryNode> selectByFileUuid(String fileUuid) {
|
||||||
|
return categoryNodeRepository.selectByFileUuid(fileUuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CategoryNode> queryForList(CategoryNodeQuery queryItem) {
|
||||||
|
return categoryNodeRepository.queryForList(queryItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TreeNode> selectByParentId(Long categoryId, Integer parentId) {
|
||||||
|
List<CategoryNode> nodeData = categoryNodeRepository.selectByParentId(categoryId, parentId);
|
||||||
|
List<TreeNode> item = new ArrayList<>();
|
||||||
|
for (CategoryNode cate : nodeData) {
|
||||||
|
TreeNode cateModel = new TreeNode();
|
||||||
|
cateModel.setId(cate.getCategoryNodeId());
|
||||||
|
cateModel.setLabel(cate.getCategoryNodeName());
|
||||||
|
cateModel.setParentId(cate.getParentId());
|
||||||
|
cateModel.setTreeLevel(cateModel.getTreeLevel());
|
||||||
|
//添加额外的属性
|
||||||
|
Map<String, Object> attributes = new HashMap<>();
|
||||||
|
attributes.put("categoryId", cate.getCategoryId());
|
||||||
|
attributes.put("categoryNodeCode", cate.getCategoryNodeCode());
|
||||||
|
attributes.put("systemCode", cate.getSystemCode());
|
||||||
|
cateModel.setAttributes(attributes);
|
||||||
|
cateModel.setLeaf(cate.getIsLeaf() == 1);
|
||||||
|
item.add(cateModel);
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CategoryNode> selectByParentIdAndName(Long categoryId, Integer parentId, String categoryNodeName) {
|
||||||
|
return categoryNodeRepository.selectByParentIdAndName(categoryId,parentId,categoryNodeName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CategoryNode> queryForTree(Long categoryId, Integer categoryNodeId) {
|
||||||
|
return categoryNodeRepository.queryForTree(categoryId,categoryNodeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CategoryNode> selectTreeForParent(Integer categoryNodeId) {
|
||||||
|
return categoryNodeRepository.selectTreeForParent(categoryNodeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CategoryNode> selectTreeForParentBySystemCode(String systemCode) {
|
||||||
|
return categoryNodeRepository.selectTreeForParentBySystemCode(systemCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CategoryNode> selectRecentEditNode(Long categoryId) {
|
||||||
|
return categoryNodeRepository.selectRecentEditNode(categoryId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TreeNode> getTreeData(Long categoryId, Integer categoryNodeId) {
|
||||||
|
List<CategoryNode> CategoryNodes = categoryNodeRepository.queryForTree(categoryId, categoryNodeId);
|
||||||
|
return getTree(categoryNodeId, CategoryNodes);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<TreeNode> getTree(int parentId, List<CategoryNode> nodeList) {
|
||||||
|
List<TreeNode> item = new ArrayList<>();
|
||||||
|
Iterator<CategoryNode> treeList = nodeList.stream().filter(m -> m.getParentId() == parentId).iterator();
|
||||||
|
while (treeList.hasNext()) {
|
||||||
|
CategoryNode cate = treeList.next();
|
||||||
|
TreeNode cateModel = new TreeNode();
|
||||||
|
cateModel.setId(cate.getCategoryNodeId());
|
||||||
|
cateModel.setLabel(cate.getCategoryNodeName());
|
||||||
|
cateModel.setParentId(cate.getParentId());
|
||||||
|
cateModel.setTreeLevel(cateModel.getTreeLevel());
|
||||||
|
//添加额外的属性
|
||||||
|
Map<String, Object> attributes = new HashMap<>();
|
||||||
|
attributes.put("categoryId", cate.getCategoryId());
|
||||||
|
attributes.put("categoryNodeCode", cate.getCategoryNodeCode());
|
||||||
|
cateModel.setAttributes(attributes);
|
||||||
|
List<TreeNode> childrenList = getTree(cate.getCategoryNodeId(), nodeList);
|
||||||
|
if (!childrenList.isEmpty()) {
|
||||||
|
cateModel.setChildren(childrenList);
|
||||||
|
}
|
||||||
|
cateModel.setLeaf(childrenList.isEmpty());
|
||||||
|
item.add(cateModel);
|
||||||
|
}
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user