Compare commits

...

20 Commits

Author SHA1 Message Date
  chenpeng b768e6b2f2 新增知识图谱模块 10 months ago
  chenpeng 5b9b2860e6 知识图谱-版本接口联调 10 months ago
  chenpeng 0f693a25b8 知识图谱-增量更新和全量更新开发 10 months ago
  chenpeng 89e9c83244 Merge branch 'dev' into dev-cp 10 months ago
  chenpeng aa9c926599 服务本地化配置 10 months ago
  chenpeng 9711487c20 知识图谱-图谱全量更新 10 months ago
  chenpeng 2b7a1c1219 知识图谱-图谱保存 10 months ago
  chenpeng f202067b9c 知识图谱-图谱保存 11 months ago
  chenpeng 4e208408b8 知识图谱-主体详情接口联调 11 months ago
  chenpeng 6ea6e4e2fc 知识图谱-主体接口联调 11 months ago
  chenpeng 17677122bb 知识图谱-主体关联实体修改接口 11 months ago
  chenpeng 028aaff3b5 Kg 主体、实体增删接口 11 months ago
  chenpeng 065eb9cf8f Kg controller update 11 months ago
  chenpeng c8a1cbcf15 Kg Entity init 11 months ago
  chenpeng f0e07a4b8b Kg EntityRelations init 11 months ago
  chenpeng e4f567da45 Kg EntityProperties init 11 months ago
  chenpeng 2d9db72efe Kg OntologyInfo init 11 months ago
  chenpeng 1a81e831e6 kg init 1 year ago
  liuhuazhong a00c04d757 test 1 year ago
  liuhuazhong 2a40f169d3 kg部分代码 1 year ago
100 changed files with 8263 additions and 9 deletions
Split View
  1. +6
    -4
      ruoyi-auth/src/main/resources/bootstrap.yml
  2. +30
    -0
      ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/enums/KgStatus.java
  3. +30
    -0
      ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/enums/KgUpdateMethod.java
  4. +6
    -4
      ruoyi-gateway/src/main/resources/bootstrap.yml
  5. +536
    -0
      ruoyi-modules/knowledge-graph/pom.xml
  6. +34
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/KnowledgeGraphApplication.java
  7. +27
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/config/Neo4jConfig.java
  8. +17
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/config/WebSocketConfig.java
  9. +94
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgEntityController.java
  10. +93
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgEntityPropertiesController.java
  11. +94
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgEntityRelationsController.java
  12. +85
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgInfoController.java
  13. +145
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgOntologyInfoController.java
  14. +134
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgVersionController.java
  15. +37
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/CsvParser.java
  16. +23
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/CsvToMap.java
  17. +31
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/FriendsWith.java
  18. +84
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgEntityInfo.java
  19. +68
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgEntityProperty.java
  20. +73
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgEntityRelation.java
  21. +83
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgInfo.java
  22. +93
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgInfoPageVo.java
  23. +72
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgOntologyInfo.java
  24. +37
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KnowledgeGraph.java
  25. +14
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KnowledgeGraphLabel.java
  26. +54
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KnowledgeGraphVersion.java
  27. +38
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/Person.java
  28. +15
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/GraphData.java
  29. +77
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgEntityInfoDTO.java
  30. +72
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgEntityRelationDTO.java
  31. +30
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgInfoIdDTO.java
  32. +26
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgInfoPageDTO.java
  33. +30
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgOntologyInfoPageDTO.java
  34. +19
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgOntologyNameAndIdDTO.java
  35. +20
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgOntologyUpdateDTO.java
  36. +21
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgVersionInsertDTO.java
  37. +28
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KgEntityInfoMapper.java
  38. +27
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KgEntityPropertiesMapper.java
  39. +27
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KgEntityRelationsMapper.java
  40. +26
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KgInfoMapper.java
  41. +41
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KgOntologyInfoMapper.java
  42. +86
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KnowledgeGraphDao.java
  43. +99
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KnowledgeGraphVersionDao.java
  44. +26
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgEntityInfoService.java
  45. +26
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgEntityPropertiesService.java
  46. +28
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgEntityRelationsService.java
  47. +7
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgEntityRepository.java
  48. +20
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgInfoService.java
  49. +34
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgOntologyInfoService.java
  50. +26
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgVersionService.java
  51. +18
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/MinioService.java
  52. +7
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/PersonRepository.java
  53. +90
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgEntityInfoServiceImpl.java
  54. +73
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgEntityPropertiesServiceImpl.java
  55. +74
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgEntityRelationsServiceImpl.java
  56. +50
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgInfoServiceImpl.java
  57. +121
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgOntologyInfoServiceImpl.java
  58. +228
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgVersionServiceImpl.java
  59. +101
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/MinioServiceImpl.java
  60. +641
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/utils/DVCUtils.java
  61. +189
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/utils/FileUtil.java
  62. +457
    -0
      ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/utils/MinioUtil.java
  63. +8
    -0
      ruoyi-modules/knowledge-graph/src/main/resources/banner.txt
  64. +27
    -0
      ruoyi-modules/knowledge-graph/src/main/resources/bootstrap-prod.yml
  65. +38
    -0
      ruoyi-modules/knowledge-graph/src/main/resources/bootstrap.yml
  66. +13
    -0
      ruoyi-modules/knowledge-graph/src/main/resources/k8sconfig/clusterrolebinding.yaml
  67. +93
    -0
      ruoyi-modules/knowledge-graph/src/main/resources/logback.xml
  68. +201
    -0
      ruoyi-modules/knowledge-graph/src/main/resources/mapper/KgEntityInfoMapper.xml
  69. +171
    -0
      ruoyi-modules/knowledge-graph/src/main/resources/mapper/KgEntityPropertiesMapper.xml
  70. +182
    -0
      ruoyi-modules/knowledge-graph/src/main/resources/mapper/KgEntityRelationsMapper.xml
  71. +188
    -0
      ruoyi-modules/knowledge-graph/src/main/resources/mapper/KgInfoMapper.xml
  72. +178
    -0
      ruoyi-modules/knowledge-graph/src/main/resources/mapper/KgOntologyInfoMapper.xml
  73. +162
    -0
      ruoyi-modules/knowledge-graph/src/main/resources/mapper/KnowledgeGraphDao.xml
  74. +227
    -0
      ruoyi-modules/knowledge-graph/src/main/resources/mapper/KnowledgeGraphVersionDao.xml
  75. +29
    -1
      ruoyi-modules/management-platform/pom.xml
  76. +28
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/config/Neo4jConfig.java
  77. +94
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/kg/KgEntityController.java
  78. +93
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/kg/KgEntityPropertiesController.java
  79. +94
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/kg/KgEntityRelationsController.java
  80. +90
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/kg/KgInfoController.java
  81. +145
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/kg/KgOntologyInfoController.java
  82. +134
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/kg/KgVersionController.java
  83. +126
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/kg/KnowledgeGraphController.java
  84. +93
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/kg/KnowledgeGraphVersionController.java
  85. +124
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/kg/MatKGController.java
  86. +37
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/CsvParser.java
  87. +23
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/CsvToMap.java
  88. +84
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/kg/KgEntityInfo.java
  89. +68
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/kg/KgEntityProperty.java
  90. +73
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/kg/KgEntityRelation.java
  91. +83
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/kg/KgInfo.java
  92. +93
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/kg/KgInfoPageVo.java
  93. +72
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/kg/KgOntologyInfo.java
  94. +37
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/kg/KnowledgeGraph.java
  95. +14
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/kg/KnowledgeGraphLabel.java
  96. +54
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/kg/KnowledgeGraphVersion.java
  97. +15
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/kg/dto/GraphData.java
  98. +74
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/kg/dto/KgEntityInfoDTO.java
  99. +70
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/kg/dto/KgEntityRelationDTO.java
  100. +30
    -0
      ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/kg/dto/KgInfoIdDTO.java

+ 6
- 4
ruoyi-auth/src/main/resources/bootstrap.yml View File

@@ -14,16 +14,18 @@ spring:
nacos:
discovery:
# 服务注册地址
server-addr: nacos-ci4s.argo.svc:8848
server-addr: ${NACOS_ADDR:127.0.0.1:8848}
namespace: ${NACOS_NAMESPACE:public}
username: nacos
password: h1n2x3j4y5@
password: ${NACOS_PWD:h1n2x3j4y5@}
retry:
enabled: true
config:
username: nacos
password: h1n2x3j4y5@
password: ${NACOS_PWD:h1n2x3j4y5@}
# 配置中心地址
server-addr: nacos-ci4s.argo.svc:8848
server-addr: ${NACOS_ADDR:127.0.0.1:8848}
namespace: ${NACOS_NAMESPACE:public}
# 配置文件格式
file-extension: yml
# 共享配置


+ 30
- 0
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/enums/KgStatus.java View File

@@ -0,0 +1,30 @@
package com.ruoyi.common.core.enums;

/**
* 用户状态
*
* @author ruoyi
*/
public enum KgStatus
{
ONLINE(1, "在线"), OFFLINE(0, "离线");

private final Integer code;
private final String info;

KgStatus(Integer code, String info)
{
this.code = code;
this.info = info;
}

public Integer getCode()
{
return code;
}

public String getInfo()
{
return info;
}
}

+ 30
- 0
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/enums/KgUpdateMethod.java View File

@@ -0,0 +1,30 @@
package com.ruoyi.common.core.enums;

/**
* 用户状态
*
* @author ruoyi
*/
public enum KgUpdateMethod
{
PENDING_UPDATE(0, "待更新"), INCREMENTAL_UPDATE(1, "增量更新"), FULL_UPDATE(2, "全量更新");

private final Integer code;
private final String info;

KgUpdateMethod(Integer code, String info)
{
this.code = code;
this.info = info;
}

public Integer getCode()
{
return code;
}

public String getInfo()
{
return info;
}
}

+ 6
- 4
ruoyi-gateway/src/main/resources/bootstrap.yml View File

@@ -14,16 +14,18 @@ spring:
nacos:
discovery:
# 服务注册地址
server-addr: nacos-ci4s.argo.svc:8848
server-addr: ${NACOS_ADDR:127.0.0.1:8848}
namespace: ${NACOS_NAMESPACE:public}
username: nacos
password: h1n2x3j4y5@
password: ${NACOS_PWD:h1n2x3j4y5@}
retry:
enabled: true
config:
username: nacos
password: h1n2x3j4y5@
password: ${NACOS_PWD:h1n2x3j4y5@}
# 配置中心地址
server-addr: nacos-ci4s.argo.svc:8848
server-addr: ${NACOS_ADDR:127.0.0.1:8848}
namespace: ${NACOS_NAMESPACE:public}
# 配置文件格式
file-extension: yml
# 共享配置


+ 536
- 0
ruoyi-modules/knowledge-graph/pom.xml View File

@@ -0,0 +1,536 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<parent>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-modules</artifactId>
<version>3.6.3</version>
</parent>

<artifactId>knowledge-graph</artifactId>
<modelVersion>4.0.0</modelVersion>
<description>
知识图谱模块
</description>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<!-- Druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${druid.version}</version>
</dependency>
<!-- SpringCloud Alibaba Nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>

<!-- SpringCloud Alibaba Nacos Config -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>

<!-- SpringCloud Alibaba Sentinel -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>

<!-- SpringBoot Actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<!-- Swagger UI -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.fox.version}</version>
</dependency>
<!-- Mysql Connector -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>

<!-- RuoYi Common DataSource -->
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-common-datasource</artifactId>
</dependency>
<!-- RuoYi Common DataSource -->
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-common-datasource</artifactId>
</dependency>

<!-- RuoYi Common DataScope -->
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-common-datascope</artifactId>
</dependency>

<!-- RuoYi Common Log -->
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-common-log</artifactId>
</dependency>

<!-- RuoYi Common Swagger -->
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-common-swagger</artifactId>
</dependency>
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-common-security</artifactId>
</dependency>
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-common-swagger</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
</dependency>
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-common-log</artifactId>
</dependency>
<dependency>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi-common-core</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>


<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.5</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5</version>
</dependency>


<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.13</version>
</dependency>
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java</artifactId>
<version>17.0.0</version>
</dependency>
<dependency>
<groupId>com.github.docker-java</groupId>
<artifactId>docker-java</artifactId>
<version>3.2.13</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.4</version>
</dependency>
<dependency>
<groupId>com.github.docker-java</groupId>
<artifactId>docker-java-transport-httpclient5</artifactId>
<version>3.2.13</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-annotation</artifactId>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-core</artifactId>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java-api</artifactId>
<version>16.0.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java-api</artifactId>
<version>12.0.1</version>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>5.7.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.9.0</version>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
<version>4.11.1</version>
</dependency>
<dependency>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
<version>4.8.83</version>
</dependency>
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>8.2.2</version>
</dependency>
<dependency>
<groupId>org.mlflow</groupId>
<artifactId>mlflow-client</artifactId>
<version>1.28.0</version>
</dependency>
<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>checker-qual</artifactId>
<version>3.19.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.55</version> <!-- 检查最新版本 -->
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20210307</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>3.0.8</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>5.13.0.202109080827-r</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.6.0</version>
</dependency>

<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.5</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>
<dependency>
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>4.0.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>


<!-- <dependencies>-->
<!-- &lt;!&ndash; Druid &ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>com.alibaba</groupId>-->
<!-- <artifactId>druid-spring-boot-starter</artifactId>-->
<!-- <version>${druid.version}</version>-->
<!-- </dependency>-->
<!-- &lt;!&ndash; SpringCloud Alibaba Nacos &ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>com.alibaba.cloud</groupId>-->
<!-- <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>-->
<!-- </dependency>-->

<!-- &lt;!&ndash; SpringCloud Alibaba Nacos Config &ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>com.alibaba.cloud</groupId>-->
<!-- <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>-->
<!-- </dependency>-->

<!-- &lt;!&ndash; SpringCloud Alibaba Sentinel &ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>com.alibaba.cloud</groupId>-->
<!-- <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>-->
<!-- </dependency>-->

<!-- &lt;!&ndash; SpringBoot Actuator &ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-actuator</artifactId>-->
<!-- </dependency>-->
<!-- &lt;!&ndash; Mysql Connector &ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>com.mysql</groupId>-->
<!-- <artifactId>mysql-connector-j</artifactId>-->
<!-- </dependency>-->

<!-- &lt;!&ndash; RuoYi Common DataSource &ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>com.ruoyi</groupId>-->
<!-- <artifactId>ruoyi-common-datasource</artifactId>-->
<!-- </dependency>-->
<!-- &lt;!&ndash; RuoYi Common DataSource &ndash;&gt;-->

<!-- &lt;!&ndash; RuoYi Common DataScope &ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>com.ruoyi</groupId>-->
<!-- <artifactId>ruoyi-common-datascope</artifactId>-->
<!-- </dependency>-->

<!-- &lt;!&ndash; RuoYi Common Log &ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>com.ruoyi</groupId>-->
<!-- <artifactId>ruoyi-common-log</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.ruoyi</groupId>-->
<!-- <artifactId>ruoyi-common-security</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.security</groupId>-->
<!-- <artifactId>spring-security-core</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.ruoyi</groupId>-->
<!-- <artifactId>ruoyi-common-core</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.projectlombok</groupId>-->
<!-- <artifactId>lombok</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.apache.httpcomponents</groupId>-->
<!-- <artifactId>httpclient</artifactId>-->
<!-- <version>4.5.5</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.apache.httpcomponents</groupId>-->
<!-- <artifactId>httpmime</artifactId>-->
<!-- <version>4.5</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.apache.httpcomponents</groupId>-->
<!-- <artifactId>httpcore</artifactId>-->
<!-- <version>4.4.13</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>io.kubernetes</groupId>-->
<!-- <artifactId>client-java</artifactId>-->
<!-- <version>17.0.0</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.github.docker-java</groupId>-->
<!-- <artifactId>docker-java</artifactId>-->
<!-- <version>3.2.13</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>commons-beanutils</groupId>-->
<!-- <artifactId>commons-beanutils</artifactId>-->
<!-- <version>1.9.4</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.github.docker-java</groupId>-->
<!-- <artifactId>docker-java-transport-httpclient5</artifactId>-->
<!-- <version>3.2.13</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.baomidou</groupId>-->
<!-- <artifactId>mybatis-plus-annotation</artifactId>-->
<!-- <version>3.3.2</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.baomidou</groupId>-->
<!-- <artifactId>mybatis-plus-core</artifactId>-->
<!-- <version>3.3.2</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>javax.persistence</groupId>-->
<!-- <artifactId>persistence-api</artifactId>-->
<!-- <version>1.0.2</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>io.kubernetes</groupId>-->
<!-- <artifactId>client-java-api</artifactId>-->
<!-- <version>16.0.3</version>-->
<!-- <scope>compile</scope>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>io.kubernetes</groupId>-->
<!-- <artifactId>client-java-api</artifactId>-->
<!-- <version>12.0.1</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.opencsv</groupId>-->
<!-- <artifactId>opencsv</artifactId>-->
<!-- <version>5.7.1</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.apache.commons</groupId>-->
<!-- <artifactId>commons-csv</artifactId>-->
<!-- <version>1.9.0</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>io.fabric8</groupId>-->
<!-- <artifactId>kubernetes-client</artifactId>-->
<!-- <version>4.11.1</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>io.github.classgraph</groupId>-->
<!-- <artifactId>classgraph</artifactId>-->
<!-- <version>4.8.83</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>io.minio</groupId>-->
<!-- <artifactId>minio</artifactId>-->
<!-- <version>8.2.2</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.mlflow</groupId>-->
<!-- <artifactId>mlflow-client</artifactId>-->
<!-- <version>1.28.0</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.checkerframework</groupId>-->
<!-- <artifactId>checker-qual</artifactId>-->
<!-- <version>3.19.0</version>-->
<!-- <scope>compile</scope>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.jcraft</groupId>-->
<!-- <artifactId>jsch</artifactId>-->
<!-- <version>0.1.55</version> &lt;!&ndash; 检查最新版本 &ndash;&gt;-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-websocket</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.json</groupId>-->
<!-- <artifactId>json</artifactId>-->
<!-- <version>20210307</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.apache.dubbo</groupId>-->
<!-- <artifactId>dubbo</artifactId>-->
<!-- <version>3.0.8</version>-->
<!-- <scope>compile</scope>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>commons-lang</groupId>-->
<!-- <artifactId>commons-lang</artifactId>-->
<!-- <version>2.6</version>-->
<!-- <scope>compile</scope>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.eclipse.jgit</groupId>-->
<!-- <artifactId>org.eclipse.jgit</artifactId>-->
<!-- <version>5.13.0.202109080827-r</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>redis.clients</groupId>-->
<!-- <artifactId>jedis</artifactId>-->
<!-- <version>3.6.0</version>-->
<!-- </dependency>-->

<!-- <dependency>-->
<!-- <groupId>cn.hutool</groupId>-->
<!-- <artifactId>hutool-all</artifactId>-->
<!-- <version>5.8.5</version>-->
<!-- </dependency>-->

<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-data-neo4j</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.neo4j.driver</groupId>-->
<!-- <artifactId>neo4j-java-driver</artifactId>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.alibaba</groupId>-->
<!-- <artifactId>easyexcel</artifactId>-->
<!-- <version>4.0.3</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-test</artifactId>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
<!-- </dependencies>-->

<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>

+ 34
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/KnowledgeGraphApplication.java View File

@@ -0,0 +1,34 @@
package com.ruoyi.kg;

import com.ruoyi.common.security.annotation.EnableCustomConfig;
import com.ruoyi.common.security.annotation.EnableRyFeignClients;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

/**
* 项目管理模块
*
* @author fans
*/
@EnableCustomConfig
@EnableRyFeignClients
@SpringBootApplication
@EnableScheduling
@EnableAsync
public class KnowledgeGraphApplication {
public static void main(String[] args) {
SpringApplication.run(KnowledgeGraphApplication.class, args);
System.out.println("(♥◠‿◠)ノ゙ 知识图谱启动成功 ლ(´ڡ`ლ)゙ \n" +
" .-------. ____ __ \n" +
" | _ _ \\ \\ \\ / / \n" +
" | ( ' ) | \\ _. / ' \n" +
" |(_ o _) / _( )_ .' \n" +
" | (_,_).' __ ___(_ o _)' \n" +
" | |\\ \\ | || |(_,_)' \n" +
" | | \\ `' /| `-' / \n" +
" | | \\ / \\ / \n" +
" ''-' `'-' `-..-' ");
}
}

+ 27
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/config/Neo4jConfig.java View File

@@ -0,0 +1,27 @@
package com.ruoyi.kg.config;

import org.neo4j.cypherdsl.core.renderer.Dialect;
import org.neo4j.driver.Driver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.core.Neo4jClient;


@Configuration
//@EnableNeo4jRepositories("com.ruoyi.platform.service")
public class Neo4jConfig {

@Autowired
private Driver driver;

@Bean
public Neo4jClient neo4jClient() {
return Neo4jClient.create(driver);
}
@Bean
org.neo4j.cypherdsl.core.renderer.Configuration cypherDslConfiguration() {
return org.neo4j.cypherdsl.core.renderer.Configuration.newConfig()
.withDialect(Dialect.NEO4J_5).build();
}
}

+ 17
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/config/WebSocketConfig.java View File

@@ -0,0 +1,17 @@
package com.ruoyi.kg.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

@Configuration
public class WebSocketConfig {
/**
* 注入 ServerEndpointExporter,
* 这个 bean 会自动注册使用了 @ServerEndpoint 注解声明的 WebSocket endpoint
*/
@Bean
public ServerEndpointExporter serverEndpointExporter() {
return new ServerEndpointExporter();
}
}

+ 94
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgEntityController.java View File

@@ -0,0 +1,94 @@
package com.ruoyi.kg.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.kg.domain.KgEntityInfo;
import com.ruoyi.kg.service.KgEntityInfoService;
import com.ruoyi.system.api.domain.SysDictData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
* 知识图谱实体管理
*/
@RestController
@RequestMapping("/kg/entity")
public class KgEntityController extends BaseController {

@Autowired
private KgEntityInfoService kgEntityInfoService;

/**
* 新增实体
*
* @param entityInfo
* @return
*/
@PostMapping()
public R<String> createEntity(@Validated @RequestBody KgEntityInfo entityInfo) {
kgEntityInfoService.insertEntity(entityInfo);
return R.ok();
}

/**
* 修改实体
*
* @param entityInfo
* @return
*/
@PutMapping
public R<String> updateEntity(@Validated @RequestBody KgEntityInfo entityInfo) {
kgEntityInfoService.updateEntity(entityInfo);
return R.ok();
}

/**
* 实体列表
* @return
*/
@GetMapping("/list")
public TableDataInfo getEntities(@RequestBody KgEntityInfo entityInfo) {
startPage();
List<KgEntityInfo> ontologies = kgEntityInfoService.getEntities(entityInfo);
return getDataTable(ontologies);
}

/**
* 实体详情
* @param id
* @return
*/
@GetMapping("/{id}")
public R<KgEntityInfo> getEntity(@PathVariable Long id) {
return R.ok(kgEntityInfoService.getEntity(id));
}

/**
* 删除实体
* @param id
* @return
*/
@DeleteMapping("/{id}")
public R<String> deleteEntityById(@PathVariable Long id) {
kgEntityInfoService.deleteEntityById(id);
return R.ok();
}

/**
* 实体导出
* @param response
* @param id
*/
@GetMapping("/export/{id}")
public void export(HttpServletResponse response,@PathVariable Long id) {
KgEntityInfo Entity = kgEntityInfoService.getEntity(id);
ExcelUtil<SysDictData> util = new ExcelUtil<SysDictData>(SysDictData.class);
util.exportExcel(response, null, "实体数据");
}
}

+ 93
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgEntityPropertiesController.java View File

@@ -0,0 +1,93 @@
package com.ruoyi.kg.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.kg.domain.KgEntityProperty;
import com.ruoyi.kg.service.KgEntityPropertiesService;
import com.ruoyi.system.api.domain.SysDictData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 知识图谱实体属性管理
*/
@RestController
@RequestMapping("/kg/entityProperties")
public class KgEntityPropertiesController extends BaseController {

@Autowired
private KgEntityPropertiesService kgEntityPropertiesService;

/**
* 新增实体属性
*
* @param entityProperties
* @return
*/
@PostMapping()
public R<String> createEntityProperty(@Validated @RequestBody KgEntityProperty entityProperties) {
kgEntityPropertiesService.insertEntityProperties(entityProperties);
return R.ok();
}

/**
* 修改实体属性
*
* @param KgEntityProperty
* @return
*/
@PutMapping
public R<String> updateEntityProperty(@Validated @RequestBody KgEntityProperty KgEntityProperty) {
kgEntityPropertiesService.updateEntityProperties(KgEntityProperty);
return R.ok();
}

/**
* 实体属性列表
* @return
*/
@GetMapping("/list")
public TableDataInfo getEntityProperties(@RequestBody KgEntityProperty KgEntityProperty) {
startPage();
List<KgEntityProperty> ontologies = kgEntityPropertiesService.getEntityProperties(KgEntityProperty);
return getDataTable(ontologies);
}

/**
* 实体属性详情
* @param id
* @return
*/
@GetMapping("/{id}")
public R<KgEntityProperty> getEntityProperty(@PathVariable Long id) {
return R.ok(kgEntityPropertiesService.getEntityProperty(id));
}

/**
* 删除实体属性
* @param id
* @return
*/
@DeleteMapping("/{id}")
public R<String> deleteEntityPropertyById(@PathVariable Long id) {
kgEntityPropertiesService.deleteEntityPropertyById(id);
return R.ok();
}

/**
* 实体属性导出
* @param response
* @param id
*/
@GetMapping("/export/{id}")
public void export(HttpServletResponse response,@PathVariable Long id) {
KgEntityProperty EntityProperty = kgEntityPropertiesService.getEntityProperty(id);
ExcelUtil<SysDictData> util = new ExcelUtil<SysDictData>(SysDictData.class);
util.exportExcel(response, null, "实体属性数据");
}
}

+ 94
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgEntityRelationsController.java View File

@@ -0,0 +1,94 @@
package com.ruoyi.kg.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.kg.domain.KgEntityRelation;
import com.ruoyi.kg.service.KgEntityRelationsService;
import com.ruoyi.system.api.domain.SysDictData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
* 知识图谱实体关系管理
*/
@RestController
@RequestMapping("/kg/entityRelations")
public class KgEntityRelationsController extends BaseController {

@Autowired
private KgEntityRelationsService kgEntityRelationsService;

/**
* 新增实体关系
*
* @param entityRelations
* @return
*/
@PostMapping()
public R<String> createEntityRelations(@Validated @RequestBody KgEntityRelation entityRelations) {
kgEntityRelationsService.insertEntityRelation(entityRelations);
return R.ok();
}

/**
* 修改实体关系
*
* @param entityRelations
* @return
*/
@PutMapping
public R<String> updateEntityRelations(@Validated @RequestBody KgEntityRelation entityRelations) {
kgEntityRelationsService.updateEntityRelation(entityRelations);
return R.ok();
}

/**
* 实体关系列表
* @return
*/
@GetMapping("/list")
public TableDataInfo getEntityRelations(@RequestBody KgEntityRelation entityRelation) {
startPage();
List<KgEntityRelation> entityRelations = kgEntityRelationsService.getEntityRelations(entityRelation);
return getDataTable(entityRelations);
}

/**
* 实体关系详情
* @param id
* @return
*/
@GetMapping("/{id}")
public R<KgEntityRelation> getEntityRelations(@PathVariable Long id) {
return R.ok(kgEntityRelationsService.getEntityRelations(id));
}

/**
* 删除实体关系
* @param id
* @return
*/
@DeleteMapping("/{id}")
public R<String> deleteEntityRelationById(@PathVariable Long id) {
kgEntityRelationsService.deleteEntityRelationById(id);
return R.ok();
}

/**
* 实体关系导出
* @param response
* @param id
*/
@GetMapping("/export/{id}")
public void export(HttpServletResponse response,@PathVariable Long id) {
KgEntityRelation entityRelations = kgEntityRelationsService.getEntityRelations(id);
ExcelUtil<SysDictData> util = new ExcelUtil<SysDictData>(SysDictData.class);
util.exportExcel(response, null, "实体关系数据");
}
}

+ 85
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgInfoController.java View File

@@ -0,0 +1,85 @@
package com.ruoyi.kg.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.kg.domain.KgInfo;
import com.ruoyi.kg.domain.KgInfoPageVo;
import com.ruoyi.kg.domain.dto.KgInfoIdDTO;
import com.ruoyi.kg.service.KgInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* 知识图谱列表管理
*/
@RestController
@RequestMapping("/kg")
public class KgInfoController extends BaseController {

@Autowired
private KgInfoService kgInfoService;

/**
* 新增图谱
*
* @param kgInfo
* @return
*/
@PostMapping()
public R<String> createKgInfo(@Validated @RequestBody KgInfo kgInfo) {
kgInfoService.insertKgInfo(kgInfo);
return R.ok();
}

/**
* 修改图谱
*
* @param kgInfo
* @return
*/
@PutMapping
public R<String> updateKgInfo(@Validated @RequestBody KgInfo kgInfo) {
kgInfoService.updateKgInfo(kgInfo);
return R.ok();
}

/**
* 图谱列表
*
* @return
*/
@GetMapping("/list")
public TableDataInfo getAllKgInfos() {
startPage();
List<KgInfoPageVo> kgInfo = kgInfoService.getAllKgInfos();
return getDataTable(kgInfo);
}

/**
* 图谱详情
*
* @param kgInfoIdDTO
* @return
*/
@GetMapping
public R<KgInfo> getKgInfo(KgInfoIdDTO kgInfoIdDTO) {
return R.ok(kgInfoService.getKgInfo(kgInfoIdDTO));
}

/**
* 删除图谱
*
* @param id
* @return
*/
@DeleteMapping("/{id}")
public R<String> deleteKgInfoById(@PathVariable Long id) {
kgInfoService.deleteKgInfoById(id);
return R.ok();
}

}

+ 145
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgOntologyInfoController.java View File

@@ -0,0 +1,145 @@
package com.ruoyi.kg.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.kg.domain.KgOntologyInfo;
import com.ruoyi.kg.domain.dto.GraphData;
import com.ruoyi.kg.domain.dto.KgOntologyInfoPageDTO;
import com.ruoyi.kg.domain.dto.KgOntologyNameAndIdDTO;
import com.ruoyi.kg.domain.dto.KgOntologyUpdateDTO;
import com.ruoyi.kg.service.KgOntologyInfoService;
import com.ruoyi.system.api.domain.SysDictData;
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.HttpServletResponse;
import java.util.List;

/**
* 知识图谱主体管理
*/
@RestController
@RequestMapping("/kg/ontology")
public class KgOntologyInfoController extends BaseController {

@Autowired
private KgOntologyInfoService kgOntologyInfoService;

/**
* 新增主体
*
* @param ontology
* @return
*/
@PostMapping()
public R<String> createOntology(@Validated @RequestBody KgOntologyInfo ontology) {
kgOntologyInfoService.insertOntology(ontology);
return R.ok("新增成功");
}

/**
* 修改主体信息
*
* @param ontology
* @return
*/
@PutMapping("/info")
public R<String> updateInfo(@Validated @RequestBody KgOntologyUpdateDTO ontology) {
kgOntologyInfoService.updateOntology(ontology);
return R.ok("修改成功");
}

/**
* 主体列表
* @return
*/
@PostMapping("/list")
public TableDataInfo getOntologies(@RequestBody KgOntologyInfoPageDTO ontology) {
startPage();
List<KgOntologyInfo> ontologies = kgOntologyInfoService.getOntologies(ontology);
return getDataTable(ontologies);
}

/**
* 新增图谱时关联主体内容
* @return
*/
@GetMapping("/getBasicInfo")
public R<List<KgOntologyNameAndIdDTO>> getNameAndIds() {
return R.ok(kgOntologyInfoService.getNameAndIds());
}

/**
* 主体详情
* @param id
* @return
*/
@GetMapping("/{id}")
public R<KgOntologyUpdateDTO> getOntology(@PathVariable Long id) {
return R.ok(kgOntologyInfoService.getOntology(id));
}

/**
* 删除主体
* @param id
* @return
*/
@DeleteMapping("/{id}")
public R<String> deleteById(@PathVariable Long id) {
kgOntologyInfoService.deleteOntologyById(id);
return R.ok("删除成功");
}

/**
* 删除主体
* @param ids
* @return
*/
@DeleteMapping("/batch")
public R<String> batchDelete(@RequestParam(value = "ids") List<Long> ids) {
kgOntologyInfoService.batchDelete(ids);
return R.ok("批量删除成功");
}

/**
* 保存图谱
* @param graphData
* @return
*/
@PutMapping("/saveGraph")
public R<String> saveGraph(@RequestBody GraphData graphData) {
kgOntologyInfoService.saveGraph(graphData);
return R.ok("保存成功");
}

/**
* 主体导出
* @param response
* @param id
*/
@GetMapping("/export/{id}")
public void export(HttpServletResponse response,@PathVariable Long id) {
KgOntologyUpdateDTO ontology = kgOntologyInfoService.getOntology(id);
ExcelUtil<SysDictData> util = new ExcelUtil<SysDictData>(SysDictData.class);
util.exportExcel(response, null, "主体数据");
}

/**
* 主体导入
* @param file
* @param updateSupport
*/
@PostMapping("/import")
public R<String> importOntology(MultipartFile file, boolean updateSupport) throws Exception {
ExcelUtil<KgOntologyInfo> util = new ExcelUtil<>(KgOntologyInfo.class);
List<KgOntologyInfo> ontologyList = util.importExcel(file.getInputStream());
String operName = SecurityUtils.getUsername();
return R.ok(kgOntologyInfoService.importOntology(ontologyList, updateSupport, operName));

}
}

+ 134
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgVersionController.java View File

@@ -0,0 +1,134 @@
package com.ruoyi.kg.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.kg.domain.KnowledgeGraphVersion;
import com.ruoyi.kg.domain.dto.KgInfoIdDTO;
import com.ruoyi.kg.domain.dto.KgVersionInsertDTO;
import com.ruoyi.kg.service.KgVersionService;
import com.ruoyi.system.api.domain.SysDictData;
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.HttpServletResponse;
import java.util.List;

/**
* 知识图谱版本管理
*/
@RestController
@RequestMapping("/kg/version")
public class KgVersionController extends BaseController {

@Autowired
private KgVersionService kgVersionService;

/**
* 图谱版本列表
*
* @param kgInfoIdDTO
* @return
*/
@GetMapping("/list")
public TableDataInfo versionList(KgInfoIdDTO kgInfoIdDTO) {
startPage();
List<KnowledgeGraphVersion> kgInfo = kgVersionService.versionList(kgInfoIdDTO);
return getDataTable(kgInfo);
}

/**
* 图谱版本导出
*
* @param response
* @param kgInfoIdDTO
*/
@GetMapping("/export")
public void versionExport(HttpServletResponse response, KgInfoIdDTO kgInfoIdDTO) {
// KgInfo KgInfo = kgVersionService.getKgInfo(kgInfoIdDTO);
ExcelUtil<SysDictData> util = new ExcelUtil<SysDictData>(SysDictData.class);
util.exportExcel(response, null, "图谱数据");
}

/**
* 图谱版本导入
*
* @param file
*/
@PostMapping("/upload")
public R<String> uploadCsv(@RequestParam("file") MultipartFile file) {
if (file == null || file.isEmpty()) {
throw new IllegalArgumentException("文件不能为空");
}

if (!file.getOriginalFilename().endsWith(".csv")) {
throw new IllegalArgumentException("仅支持 CSV 文件");
}

try {
return R.ok(kgVersionService.uploadCsv(file));
} catch (Exception e) {
e.printStackTrace();
return R.fail();
}
}

/**
* 图谱版本新增
*
* @param kgVersionInsertDTO
*/
@PostMapping
public R<String> insert(@RequestBody @Validated KgVersionInsertDTO kgVersionInsertDTO) {
kgVersionService.insert(kgVersionInsertDTO);
return R.ok();
}


/**
* 图谱版本全量更新
*
* @param kgInfoIdDTO 版本id
*/
@PostMapping("/fullUpdate")
public R<String> fullUpdate(@RequestBody @Validated KgInfoIdDTO kgInfoIdDTO) {
kgVersionService.fullUpdate(kgInfoIdDTO.getId());
return R.ok("操作成功");
}

/**
* 图谱版本增量更新
*
* @param kgInfoIdDTO
*/
@PostMapping("/incrementalUpdate")
public R<String> incrementalUpdate(@RequestBody @Validated KgInfoIdDTO kgInfoIdDTO) {
kgVersionService.incrementalUpdate(kgInfoIdDTO.getId());
return R.ok("操作成功");
}

/**
* 图谱版本回退
*
* @param kgInfoIdDTO
*/
@PostMapping("/rollback")
public R<String> rollback(@RequestBody @Validated KgInfoIdDTO kgInfoIdDTO) {
kgVersionService.rollback(kgInfoIdDTO.getId());
return R.ok("操作成功");
}

/**
* 图谱版本删除
*
* @param versionId
*/
@DeleteMapping("/{versionId}")
public R<String> delete(@PathVariable Long versionId) {
kgVersionService.delete(versionId);
return R.ok("操作成功");
}
}

+ 37
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/CsvParser.java View File

@@ -0,0 +1,37 @@
package com.ruoyi.kg.domain;

import cn.hutool.core.collection.CollectionUtil;
import com.opencsv.CSVReader;
import com.opencsv.exceptions.CsvException;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class CsvParser {

public static List<Map<String, String>> parseCsvToMap(InputStream inputStream) throws IOException, CsvException {
try (CSVReader reader = new CSVReader(new InputStreamReader(inputStream))) {
List<String[]> rows = reader.readAll();
if (CollectionUtil.isEmpty(rows) || rows.size() <= 1) {
return new ArrayList<>();
}
String[] headers = rows.get(0); // 第一行为表头
List<String[]> data = rows.subList(1, rows.size()); // 剩余行为数据

return data.stream()
.map(row -> {
Map<String, String> map = new HashMap<>();
for (int i = 0; i < headers.length; i++) {
map.put(headers[i], row[i]);
}
return map;
}).collect(Collectors.toList());
}
}
}

+ 23
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/CsvToMap.java View File

@@ -0,0 +1,23 @@
package com.ruoyi.kg.domain;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class CsvToMap {

public static List<Map<String, String>> convertToMap(List<String[]> csvData) {
String[] headers = csvData.get(0); // 第一行为表头
List<String[]> rows = csvData.subList(1, csvData.size()); // 剩余行为数据

return rows.stream()
.map(row -> {
Map<String, String> map = new HashMap<>();
for (int i = 0; i < headers.length; i++) {
map.put(headers[i], row[i]);
}
return map;
}).collect(Collectors.toList());
}
}

+ 31
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/FriendsWith.java View File

@@ -0,0 +1,31 @@
package com.ruoyi.kg.domain;
import lombok.Data;
import org.springframework.data.neo4j.core.schema.RelationshipId;
import org.springframework.data.neo4j.core.schema.RelationshipProperties;
import org.springframework.data.neo4j.core.schema.TargetNode;

@Data
@RelationshipProperties
public class FriendsWith {

@RelationshipId
private Long id;

@TargetNode
private Person person;

private String relationType; // 动态关系类型
private String since;

private String transactionId;

private Integer version;

// 构造函数、Getter 和 Setter
public FriendsWith(Person person, String since,Integer version,String transactionId) {
this.person = person;
this.since = since;
this.version = version;
this.transactionId = transactionId;
}
}

+ 84
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgEntityInfo.java View File

@@ -0,0 +1,84 @@
package com.ruoyi.kg.domain;

import lombok.Data;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;

/**
* kg_entity_info
*/
@Data
public class KgEntityInfo implements Serializable {
/**
* 实体主键
*/
private Long id;

/**
* 实体名称
*/
@NotNull(message = "实体名称不能为空")
private String name;

/**
* 实体描述
*/
private String description;

/**
* 背景色
*/
private String bkColor;

/**
* 横坐标
*/
@NotNull(message = "横坐标不能为空")
private Integer displayX;

/**
* 纵坐标
*/
@NotNull(message = "纵坐标不能为空")
private Integer displayY;

/**
* 图标路径
*/
private String icon;

/**
* 主体主键
*/
@NotNull(message = "主体主键不能为空")
private Long ontologyId;

/**
* 创建时间
*/
private Date createTime;

/**
* 更新时间
*/
private Date updateTime;

/**
* 删除标志,0表示未删除,1表示已删除
*/
private String delFlag;

/**
* 创建人
*/
private String createBy;

/**
* 更新人
*/
private String updateBy;

private static final long serialVersionUID = 1L;
}

+ 68
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgEntityProperty.java View File

@@ -0,0 +1,68 @@
package com.ruoyi.kg.domain;

import lombok.Data;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;

/**
* kg_entity_properties
*/
@Data
public class KgEntityProperty implements Serializable {
/**
* 属性主键
*/
private Long id;

/**
* 属性名
*/
@NotNull(message = "属性名不能为空")
private String name;

/**
* 属性类型(String/Integer等)
*/
@NotNull(message = "属性类型不能为空")
private String type;

/**
* 关联实体信息
*/
private Long entityId;

/**
* '是否多值(0否/1是)
*/
@NotNull(message = "是否多值不能为空")
private Boolean isMultivalued;

/**
* 创建时间
*/
private Date createTime;

/**
* 更新时间
*/
private Date updateTime;

/**
* 删除标志,0表示未删除,1表示已删除
*/
private String delFlag;

/**
* 创建人
*/
private String createBy;

/**
* 更新人
*/
private String updateBy;

private static final long serialVersionUID = 1L;
}

+ 73
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgEntityRelation.java View File

@@ -0,0 +1,73 @@
package com.ruoyi.kg.domain;

import lombok.Data;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;

/**
* kg_entity_relations
*/
@Data
public class KgEntityRelation implements Serializable {
/**
* 关系主键
*/
private String id;

/**
* 关系名称
*/
@NotNull(message = "属性名不能为空")
private String name;

/**
* 终点属性名
*/
private String target;

/**
* 终点实体ID
*/
@NotNull(message = "终点实体ID不能为空")
private Long targetId;

/**
* 起点实体ID
*/
@NotNull(message = "起点实体ID不能为空")
private Long sourceId;

/**
* 关联实体ID
*/
private Long entityId;

/**
* 创建时间
*/
private Date createTime;

/**
* 更新时间
*/
private Date updateTime;

/**
* 删除标志,0表示未删除,1表示已删除
*/
private String delFlag;

/**
* 创建人
*/
private String createBy;

/**
* 更新人
*/
private String updateBy;

private static final long serialVersionUID = 1L;
}

+ 83
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgInfo.java View File

@@ -0,0 +1,83 @@
package com.ruoyi.kg.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
* 知识图谱信息表
* kg_info
*/
@Data
public class KgInfo implements Serializable {
/**
* ID
*/
private Long id;

/**
* 版本
*/
private String version;

/**
* 图谱名称
*/
private String name;

/**
* 本体ID
*/
private Long ontologyId;

/**
* neo4j数据库名称
*/
private String dbName;

/**
* 状态(0正常 1停用)
*/
private String status;

/**
* 创建者
*/
private String createBy;

/**
* 创建时间
*/
private Date createTime;

/**
* 更新者
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private String updateBy;

/**
* 更新时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;

/**
* 备注
*/
private String remark;

/**
* 规格
*/
private String spec;

/**
* 删除标志(2删除,0未删除)
*/
private String delFlag;

private static final long serialVersionUID = 1L;
}

+ 93
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgInfoPageVo.java View File

@@ -0,0 +1,93 @@
package com.ruoyi.kg.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
* 知识图谱信息表
* kg_info
*/
@Data
public class KgInfoPageVo implements Serializable {
/**
* ID
*/
private Long id;

/**
* 版本
*/
private String version;

/**
* 图谱名称
*/
private String name;

/**
* 本体ID
*/
private Long ontologyId;

/**
* neo4j数据库名称
*/
private String dbName;

/**
* 状态(0正常 1停用)
*/
private String status;

/**
* 创建者
*/
private String createBy;

/**
* 创建时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;

/**
* 更新者
*/
private String updateBy;

/**
* 更新时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;

/**
* 备注
*/
private String remark;

/**
* 规格
*/
private String spec;

/**
* 删除标志(2删除,0未删除)
*/
private String delFlag;

/**
* 关系数
*/
private Integer relationCount;

/**
* 实体数
*/
private Integer entityCount;

private static final long serialVersionUID = 1L;
}

+ 72
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgOntologyInfo.java View File

@@ -0,0 +1,72 @@
package com.ruoyi.kg.domain;

import lombok.Data;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;

/**
* kg_ontology_info
*/
@Data
public class KgOntologyInfo implements Serializable {
/**
* 主体主键
*/
private Long id;

/**
* 主体名称
*/
@NotNull(message = "主体名称不能为空")
private String name;

/**
* 主体描述
*/
@NotNull(message = "主体描述不能为空")
private String description;

/**
* 图信息
*/
private String dag;

/**
* 概念个数
*/
private Integer conceptsCount;

/**
* 关系个数
*/
private Integer relationsCount;

/**
* 创建时间
*/
private Date createTime;

/**
* 更新时间
*/
private Date updateTime;

/**
* 创建人
*/
private String createBy;

/**
* 更新人
*/
private String updateBy;

/**
* 删除标志,0表示未删除,1表示已删除
*/
private Boolean delFlag;

private static final long serialVersionUID = 1L;
}

+ 37
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KnowledgeGraph.java View File

@@ -0,0 +1,37 @@
package com.ruoyi.kg.domain;

import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
* (KnowledgeGraph)实体类
*
* @author makejava
* @since 2025-03-11 14:52:09
*/
@Data
public class KnowledgeGraph implements Serializable {
private static final long serialVersionUID = 783648356146355028L;

private Long id;

private String kgName;

private String kgDesc;

private Integer kgNoumenon;

private Date createTime;

private String createBy;

private Date updateTime;

private String updateBy;

private Integer state;

}


+ 14
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KnowledgeGraphLabel.java View File

@@ -0,0 +1,14 @@
package com.ruoyi.kg.domain;

import lombok.Data;
import org.springframework.data.neo4j.core.schema.GeneratedValue;
import org.springframework.data.neo4j.core.schema.Id;

@Data
public class KnowledgeGraphLabel {
@Id
@GeneratedValue
private Long id;
private String graphName;

}

+ 54
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KnowledgeGraphVersion.java View File

@@ -0,0 +1,54 @@
package com.ruoyi.kg.domain;

import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
* (KnowledgeGraphVersion)实体类
*
* @author makejava
* @since 2025-03-11 14:52:10
*/
@Data
public class KnowledgeGraphVersion implements Serializable {
private static final long serialVersionUID = -60506903543301209L;

private Long id;

private String name;

private Integer version;

private String transactionId;

private String content;

private String kgId;

private Integer status;

private Integer updateMethod;

/**
* 概念个数
*/
private Integer conceptsCount;

/**
* 关系个数
*/
private Integer relationsCount;

private Date updateTime;

private Date createTime;

private String createBy;

private String updateBy;

private Integer state;
}


+ 38
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/Person.java View File

@@ -0,0 +1,38 @@
package com.ruoyi.kg.domain;

import lombok.Data;
import org.springframework.data.neo4j.core.schema.GeneratedValue;
import org.springframework.data.neo4j.core.schema.Id;
import org.springframework.data.neo4j.core.schema.Node;
import org.springframework.data.neo4j.core.schema.Relationship;

import java.util.List;

@Node
@Data
public class Person {

@Id
@GeneratedValue
private Long id;

private String name;

private String age;

private String transactionId;

private Integer version;

@Relationship(type = "RELATED_TO", direction = Relationship.Direction.OUTGOING)
private List<FriendsWith> relations;

// 构造函数、Getter 和 Setter
public Person(String name, String age,List<FriendsWith> relations,Integer version,String transactionId) {
this.name = name;
this.age = age;
this.relations = relations;
this.version = version;
this.transactionId = transactionId;
}
}

+ 15
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/GraphData.java View File

@@ -0,0 +1,15 @@
package com.ruoyi.kg.domain.dto;

import lombok.Data;

import java.util.List;
import java.util.Map;

@Data
public class GraphData {
private List<KgEntityInfoDTO> nodes;
private List<KgEntityRelationDTO> edges;
private List<Map<String, Object>> combos;


}

+ 77
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgEntityInfoDTO.java View File

@@ -0,0 +1,77 @@
package com.ruoyi.kg.domain.dto;

import com.ruoyi.kg.domain.KgEntityProperty;
import lombok.Data;
import org.springframework.data.neo4j.core.schema.Id;
import org.springframework.data.neo4j.core.schema.Node;
import org.springframework.data.neo4j.core.schema.Relationship;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* kg_entity_info
*/
@Data
@Node("KgEntity")
public class KgEntityInfoDTO{

/**
* 实体主键
*/
@Id
private Long id;

/**
* 实体名称
*/
private String label;

/**
* 实体描述
*/
private String description;

/**
* 背景色
*/
private String bkColor;

/**
* 图标路径
*/
private String icon;

/**
* 横坐标
*/
private Integer x;

/**
* 纵坐标
*/
private Integer y;

/**
* 属性集合
*/
private List<KgEntityProperty> properties;

/**
* 关系集合
*/
@Relationship(type = "CONNECTS_TO", direction = Relationship.Direction.OUTGOING)
private List<KgEntityRelationDTO> relations = new ArrayList<>();

private String type;

private Map<String,Object> labelCfg;

private Map<String,Object> style;

private Integer depth;

private String name;

}

+ 72
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgEntityRelationDTO.java View File

@@ -0,0 +1,72 @@
package com.ruoyi.kg.domain.dto;

import lombok.Data;
import org.springframework.data.neo4j.core.schema.Property;
import org.springframework.data.neo4j.core.schema.RelationshipId;
import org.springframework.data.neo4j.core.schema.RelationshipProperties;
import org.springframework.data.neo4j.core.schema.TargetNode;

import java.util.List;
import java.util.Map;

/**
* kg_entity_relations
*/
@Data
@RelationshipProperties
public class KgEntityRelationDTO {

/**
* 关系主键
*/
@RelationshipId
private Long id;

/**
* 起点节点id
*/
private Long target;

/**
* 终点节点id
*/
private Long source;

/**
* 关系名
*/
private String name;

/**
* 关联实体ID
*/
private Long entityId;

/**
* 终点实体ID
*/
@TargetNode
private KgEntityInfoDTO targetEntity;

private Map<String, Object> labelCfg;

private Map<String, Object> style;

private Map<String, Object> startPoint;

private Map<String, Object> endPoint;

private Integer sourceAnchor;

private Integer targetAnchor;

@Property("type")
private String type;

private List<Float> curvePosition;

private List<Float> minCurveOffset;

private Integer depth;

}

+ 30
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgInfoIdDTO.java View File

@@ -0,0 +1,30 @@
package com.ruoyi.kg.domain.dto;

import lombok.Data;

import javax.validation.constraints.NotNull;

@Data
public class KgInfoIdDTO {

/**
* ID
*/
@NotNull
private Long id;

/**
* 名字
*/
private String name;

/**
* 版本
*/
private String version;

/**
* 状态
*/
private String status;
}

+ 26
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgInfoPageDTO.java View File

@@ -0,0 +1,26 @@
package com.ruoyi.kg.domain.dto;

import lombok.Data;

@Data
public class KgInfoPageDTO {

/**
* ID
*/
private Long id;

/**
* 搜索关键词
*/
private String searchKey;

/**
* 状态
*/
private String status;

private Integer current;

private Integer pageSize;
}

+ 30
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgOntologyInfoPageDTO.java View File

@@ -0,0 +1,30 @@
package com.ruoyi.kg.domain.dto;
import lombok.Data;

import javax.validation.constraints.NotNull;

/**
* kg_ontology_info
*/
@Data
public class KgOntologyInfoPageDTO {

/**
* 主体名称
*/
private String name;

/**
* 每页大小
*/
@NotNull(message = "每页大小不能为空")
private Integer pageSize;

/**
* 页码
*/
@NotNull(message = "页码不能为空")
private Integer pageNum;


}

+ 19
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgOntologyNameAndIdDTO.java View File

@@ -0,0 +1,19 @@
package com.ruoyi.kg.domain.dto;

import lombok.Data;

import javax.validation.constraints.NotNull;

@Data
public class KgOntologyNameAndIdDTO {
/**
* 主体主键
*/
private Long id;

/**
* 主体名称
*/
@NotNull(message = "主体名称不能为空")
private String name;
}

+ 20
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgOntologyUpdateDTO.java View File

@@ -0,0 +1,20 @@
package com.ruoyi.kg.domain.dto;

import com.ruoyi.kg.domain.KgOntologyInfo;
import lombok.Data;

import java.util.List;

/**
* kg_ontology_info
*/
@Data
public class KgOntologyUpdateDTO extends KgOntologyInfo {

/**
* 实体集合
*/
private List<KgEntityInfoDTO> concepts;


}

+ 21
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgVersionInsertDTO.java View File

@@ -0,0 +1,21 @@
package com.ruoyi.kg.domain.dto;

import lombok.Data;

import javax.validation.constraints.NotNull;

@Data
public class KgVersionInsertDTO {

/**
* 文件路径
*/
@NotNull
private String path;

/**
* kgId
*/
@NotNull
private String kgId;
}

+ 28
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KgEntityInfoMapper.java View File

@@ -0,0 +1,28 @@
package com.ruoyi.kg.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.kg.domain.dto.KgEntityInfoDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import com.ruoyi.kg.domain.KgEntityInfo;

import java.util.List;

@Mapper
public interface KgEntityInfoMapper extends BaseMapper<KgEntityInfo> {
int deleteByPrimaryKey(@Param("id") Long id);

int insert(KgEntityInfo record);

int insertSelective(KgEntityInfo record);

KgEntityInfo selectByPrimaryKey(@Param("id") Long id);

int updateByPrimaryKeySelective(KgEntityInfo record);

int updateByPrimaryKey(KgEntityInfo record);

List<KgEntityInfo> selectList(KgEntityInfo record);

List<KgEntityInfoDTO> selectListByOntologyId(KgEntityInfo kgEntityInfo);
}

+ 27
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KgEntityPropertiesMapper.java View File

@@ -0,0 +1,27 @@
package com.ruoyi.kg.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.kg.domain.KgEntityProperty;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface KgEntityPropertiesMapper extends BaseMapper<KgEntityProperty> {
int deleteByPrimaryKey(@Param("id") Long id);

int insert(KgEntityProperty record);

int insertSelective(KgEntityProperty record);

KgEntityProperty selectByPrimaryKey(@Param("id") Long id);

int updateByPrimaryKeySelective(KgEntityProperty record);

int updateByPrimaryKey(KgEntityProperty record);

List<KgEntityProperty> selectList(KgEntityProperty record);

List<KgEntityProperty> selectListByEntityIds( List<Long> entityIds);
}

+ 27
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KgEntityRelationsMapper.java View File

@@ -0,0 +1,27 @@
package com.ruoyi.kg.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.kg.domain.dto.KgEntityRelationDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import com.ruoyi.kg.domain.KgEntityRelation;
import java.util.List;

@Mapper
public interface KgEntityRelationsMapper extends BaseMapper<KgEntityRelation> {
int deleteByPrimaryKey(@Param("id") Long id);

int insert(KgEntityRelation record);

int insertSelective(KgEntityRelation record);

KgEntityRelation selectByPrimaryKey(@Param("id") Long id);

int updateByPrimaryKeySelective(KgEntityRelation record);

int updateByPrimaryKey(KgEntityRelation record);

List<KgEntityRelation> selectList(KgEntityRelation record);

List<KgEntityRelationDTO> selectListByEntityIds(@Param("list") List<Long> ids);
}

+ 26
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KgInfoMapper.java View File

@@ -0,0 +1,26 @@
package com.ruoyi.kg.mapper;
import com.ruoyi.kg.domain.KgInfo;
import com.ruoyi.kg.domain.KgInfoPageVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import com.ruoyi.kg.domain.dto.KgInfoIdDTO;
import java.util.List;

@Mapper
public interface KgInfoMapper {
int deleteByPrimaryKey(@Param("id") Long id);

int insert(KgInfo record);

int insertSelective(KgInfo record);

List<KgInfo> selectByPrimaryKey(KgInfoIdDTO kgInfoIdDTO);

List<KgInfoPageVo> selectALl();

KgInfo queryInfoByPrimaryKey(KgInfoIdDTO kgInfoIdDTO);

int updateByPrimaryKeySelective(KgInfo record);

int updateByPrimaryKey(KgInfo record);
}

+ 41
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KgOntologyInfoMapper.java View File

@@ -0,0 +1,41 @@
package com.ruoyi.kg.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.kg.domain.KgOntologyInfo;
import com.ruoyi.kg.domain.dto.KgOntologyInfoPageDTO;
import com.ruoyi.kg.domain.dto.KgOntologyNameAndIdDTO;
import com.ruoyi.kg.domain.dto.KgOntologyUpdateDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
* @author Administrator
* @description 针对表【kg_ontology_info】的数据库操作Mapper
* @createDate 2025-02-13 14:40:46
* @Entity ontology.domain.KgOntologyInfo
*/
@Mapper
public interface KgOntologyInfoMapper extends BaseMapper<KgOntologyInfo> {

KgOntologyUpdateDTO selectByPrimaryKey(@Param("id") Long id);

void updateByPrimaryKeySelective(KgOntologyInfo kgOntologyInfo);

void insertSelective(KgOntologyInfo kgOntologyInfo);

void deleteByPrimaryKey(@Param("id") Long id);

void deleteByIds(List<Long> ids);

List<KgOntologyInfo> selectList(KgOntologyInfoPageDTO ontology);


List<KgOntologyNameAndIdDTO> getNameAndIds();
}





+ 86
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KnowledgeGraphDao.java View File

@@ -0,0 +1,86 @@
package com.ruoyi.kg.mapper;

import com.ruoyi.kg.domain.KnowledgeGraph;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Pageable;

import java.util.List;

/**
* (KnowledgeGraph)表数据库访问层
*
* @author makejava
* @since 2025-03-11 14:52:09
*/
public interface KnowledgeGraphDao {

/**
* 通过ID查询单条数据
*
* @param id 主键
* @return 实例对象
*/
@Mapper
KnowledgeGraph queryById(Long id);

/**
* 查询指定行数据
*
* @param knowledgeGraph 查询条件
* @param pageable 分页对象
* @return 对象列表
*/
List<KnowledgeGraph> queryAllByLimit(KnowledgeGraph knowledgeGraph, @Param("pageable") Pageable pageable);

/**
* 统计总行数
*
* @param knowledgeGraph 查询条件
* @return 总行数
*/
long count(KnowledgeGraph knowledgeGraph);

/**
* 新增数据
*
* @param knowledgeGraph 实例对象
* @return 影响行数
*/
int insert(KnowledgeGraph knowledgeGraph);

/**
* 批量新增数据(MyBatis原生foreach方法)
*
* @param entities List<KnowledgeGraph> 实例对象列表
* @return 影响行数
*/
int insertBatch(@Param("entities") List<KnowledgeGraph> entities);

/**
* 批量新增或按主键更新数据(MyBatis原生foreach方法)
*
* @param entities List<KnowledgeGraph> 实例对象列表
* @return 影响行数
* @
*/
int insertOrUpdateBatch(@Param("entities") List<KnowledgeGraph> entities);

/**
* 修改数据
*
* @param knowledgeGraph 实例对象
* @return 影响行数
*/
int update(KnowledgeGraph knowledgeGraph);

/**
* 通过主键删除数据
*
* @param id 主键
* @return 影响行数
*/
int deleteById(Integer id);

}


+ 99
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KnowledgeGraphVersionDao.java View File

@@ -0,0 +1,99 @@
package com.ruoyi.kg.mapper;

import com.ruoyi.kg.domain.KnowledgeGraphVersion;
import com.ruoyi.kg.domain.dto.KgInfoIdDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Pageable;

import java.util.List;

/**
* (KnowledgeGraphVersion)表数据库访问层
*
* @author makejava
* @since 2025-03-11 14:52:09
*/
@Mapper
public interface KnowledgeGraphVersionDao {

/**
* 通过ID查询单条数据
*
* @param id 主键
* @return 实例对象
*/
KnowledgeGraphVersion queryById(Long id);

/**
* 查询指定行数据
*
* @param knowledgeGraphVersion 查询条件
* @param pageable 分页对象
* @return 对象列表
*/
List<KnowledgeGraphVersion> queryAllByLimit(KnowledgeGraphVersion knowledgeGraphVersion, @Param("pageable") Pageable pageable);

/**
* 查询指定行数据
*
* @param kgInfoIdDTO 查询条件
* @return 对象列表
*/
List<KnowledgeGraphVersion> queryAll(KgInfoIdDTO kgInfoIdDTO);

/**
* 统计总行数
*
* @param knowledgeGraphVersion 查询条件
* @return 总行数
*/
long count(KnowledgeGraphVersion knowledgeGraphVersion);

/**
* 新增数据
*
* @param knowledgeGraphVersion 实例对象
* @return 影响行数
*/
int insert(KnowledgeGraphVersion knowledgeGraphVersion);

/**
* 批量新增数据(MyBatis原生foreach方法)
*
* @param entities List<KnowledgeGraphVersion> 实例对象列表
* @return 影响行数
*/
int insertBatch(@Param("entities") List<KnowledgeGraphVersion> entities);

/**
* 批量新增或按主键更新数据(MyBatis原生foreach方法)
*
* @param entities List<KnowledgeGraphVersion> 实例对象列表
* @return 影响行数
* @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常,请自行校验入参
*/
int insertOrUpdateBatch(@Param("entities") List<KnowledgeGraphVersion> entities);

/**
* 修改数据
*
* @param knowledgeGraphVersion 实例对象
* @return 影响行数
*/
int update(KnowledgeGraphVersion knowledgeGraphVersion);

/**
* 通过主键删除数据
*
* @param id 主键
* @return 影响行数
*/
int deleteById(Long id);

Integer queryMaxVersion(String kgId);

KnowledgeGraphVersion onlineFind();

}


+ 26
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgEntityInfoService.java View File

@@ -0,0 +1,26 @@
package com.ruoyi.kg.service;

import com.ruoyi.kg.domain.KgEntityInfo;
import com.ruoyi.kg.domain.dto.KgEntityInfoDTO;

import java.util.List;

/**
* @author Administrator
* @description 针对表【kg_entity_info】的数据库操作Service
* @createDate 2025-02-13 15:58:02
*/
public interface KgEntityInfoService {

void insertEntity(KgEntityInfo entityInfo);

void updateEntity(KgEntityInfo entityInfo);

List<KgEntityInfo> getEntities(KgEntityInfo entityInfo);

List<KgEntityInfoDTO> getEntitiesByOntologyId(Long ontologyId);

KgEntityInfo getEntity(Long id);

void deleteEntityById(Long id);
}

+ 26
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgEntityPropertiesService.java View File

@@ -0,0 +1,26 @@
package com.ruoyi.kg.service;

import com.ruoyi.kg.domain.KgEntityProperty;
import java.util.List;

/**
* @author Administrator
* @description 针对表【kg_entity_properties】的数据库操作Service
* @createDate 2025-02-13 15:58:38
*/
public interface KgEntityPropertiesService {

void insertEntityProperties(KgEntityProperty entityProperty);

void updateEntityProperties(KgEntityProperty entityProperty);

void batchUpdateByEntityId(Long entityId,List<KgEntityProperty> entityProperties);

List<KgEntityProperty> getEntityProperties(KgEntityProperty entityProperty);

List<KgEntityProperty> getEntityPropertiesByEntityIds(List<Long> ids);

KgEntityProperty getEntityProperty(Long id);

void deleteEntityPropertyById(Long id);
}

+ 28
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgEntityRelationsService.java View File

@@ -0,0 +1,28 @@
package com.ruoyi.kg.service;

import java.util.List;

import com.ruoyi.kg.domain.KgEntityRelation;
import com.ruoyi.kg.domain.dto.KgEntityRelationDTO;

/**
* @author Administrator
* @description 针对表【kg_entity_relations】的数据库操作Service
* @createDate 2025-02-13 15:58:49
*/
public interface KgEntityRelationsService {

void insertEntityRelation(KgEntityRelation entityRelation);

void updateEntityRelation(KgEntityRelation entityRelation);

void batchUpdateByEntityId(Long entityId,List<KgEntityRelation> entityRelations);

List<KgEntityRelation> getEntityRelations(KgEntityRelation entityRelations);

List<KgEntityRelationDTO> getEntityRelationsByEntityIds(List<Long> ids);

KgEntityRelation getEntityRelations(Long id);

void deleteEntityRelationById(Long id);
}

+ 7
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgEntityRepository.java View File

@@ -0,0 +1,7 @@
package com.ruoyi.kg.service;

import org.springframework.data.neo4j.repository.Neo4jRepository;
import com.ruoyi.kg.domain.dto.KgEntityInfoDTO;

public interface KgEntityRepository extends Neo4jRepository<KgEntityInfoDTO, Long> {
}

+ 20
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgInfoService.java View File

@@ -0,0 +1,20 @@
package com.ruoyi.kg.service;

import com.ruoyi.kg.domain.KgInfo;
import com.ruoyi.kg.domain.KgInfoPageVo;
import com.ruoyi.kg.domain.dto.KgInfoIdDTO;

import java.util.List;

public interface KgInfoService {

void insertKgInfo(KgInfo KgInfo);

void updateKgInfo(KgInfo KgInfo);

List<KgInfoPageVo> getAllKgInfos();

KgInfo getKgInfo(KgInfoIdDTO kgInfoIdDTO);

void deleteKgInfoById(Long id);
}

+ 34
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgOntologyInfoService.java View File

@@ -0,0 +1,34 @@
package com.ruoyi.kg.service;

import com.ruoyi.kg.domain.KgOntologyInfo;
import com.ruoyi.kg.domain.dto.GraphData;
import com.ruoyi.kg.domain.dto.KgOntologyInfoPageDTO;
import com.ruoyi.kg.domain.dto.KgOntologyNameAndIdDTO;
import com.ruoyi.kg.domain.dto.KgOntologyUpdateDTO;
import java.util.List;

/**
* @author Administrator
* @description 针对表【kg_ontology_info】的数据库操作Service
* @createDate 2025-02-13 14:40:46
*/
public interface KgOntologyInfoService {

void insertOntology(KgOntologyInfo ontology);

void updateOntology(KgOntologyUpdateDTO ontology);

List<KgOntologyInfo> getOntologies(KgOntologyInfoPageDTO ontology);

KgOntologyUpdateDTO getOntology(Long id);

void deleteOntologyById(Long id);

void batchDelete(List<Long> ids);

void saveGraph(GraphData graphData);

String importOntology(List<KgOntologyInfo> ontologyList, boolean updateSupport, String operName);

List<KgOntologyNameAndIdDTO> getNameAndIds();
}

+ 26
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgVersionService.java View File

@@ -0,0 +1,26 @@
package com.ruoyi.kg.service;

import com.ruoyi.kg.domain.dto.KgInfoIdDTO;
import com.ruoyi.kg.domain.dto.KgVersionInsertDTO;
import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.kg.domain.KnowledgeGraphVersion;

import java.util.List;


public interface KgVersionService {

List<KnowledgeGraphVersion> versionList(KgInfoIdDTO kgInfoIdDTO);

String uploadCsv(MultipartFile file) throws Exception;

void fullUpdate(Long id);

void incrementalUpdate(Long id);

void rollback(Long versionId);

void delete(Long versionId);

void insert(KgVersionInsertDTO kgVersionInsertDTO );
}

+ 18
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/MinioService.java View File

@@ -0,0 +1,18 @@
package com.ruoyi.kg.service;

import org.springframework.core.io.InputStreamResource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.util.Map;

public interface MinioService {

ResponseEntity<InputStreamResource> downloadFile(String bucketName , String path) throws Exception;

ResponseEntity<InputStreamResource> downloadZipFile(String bucketName , String path);

Map<String, String> uploadFile(String bucketName, String objectName, MultipartFile file ) throws Exception;
void uploaInputStream(String bucketName, String objectName, InputStream inputStream ) throws Exception;
}

+ 7
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/PersonRepository.java View File

@@ -0,0 +1,7 @@
package com.ruoyi.kg.service;

import com.ruoyi.kg.domain.Person;
import org.springframework.data.neo4j.repository.Neo4jRepository;

public interface PersonRepository extends Neo4jRepository<Person, Long> {
}

+ 90
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgEntityInfoServiceImpl.java View File

@@ -0,0 +1,90 @@
package com.ruoyi.kg.service.impl;

import com.ruoyi.kg.domain.KgEntityInfo;
import com.ruoyi.kg.domain.KgEntityProperty;
import com.ruoyi.kg.domain.dto.KgEntityInfoDTO;
import com.ruoyi.kg.domain.dto.KgEntityRelationDTO;
import com.ruoyi.kg.mapper.KgEntityInfoMapper;
import com.ruoyi.kg.service.KgEntityInfoService;
import com.ruoyi.kg.service.KgEntityPropertiesService;
import com.ruoyi.kg.service.KgEntityRelationsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @author Administrator
* @description 针对表【kg_entity_info】的数据库操作Service实现
* @createDate 2025-02-13 15:58:02
*/
@Service
public class KgEntityInfoServiceImpl implements KgEntityInfoService {

@Autowired
private KgEntityInfoMapper kgEntityInfoMapper;

@Autowired
private KgEntityPropertiesService kgEntityPropertiesService;

@Autowired
private KgEntityRelationsService kgEntityRelationsService;

@Override
public void insertEntity(KgEntityInfo entityInfo) {
kgEntityInfoMapper.insertSelective(entityInfo);
}

@Override
public void updateEntity(KgEntityInfo entityInfo) {
kgEntityInfoMapper.updateByPrimaryKey(entityInfo);
}

@Override
public List<KgEntityInfo> getEntities(KgEntityInfo entityInfo) {
return kgEntityInfoMapper.selectList(entityInfo);
}

@Override
public List<KgEntityInfoDTO> getEntitiesByOntologyId(Long ontologyId) {
KgEntityInfo kgEntityInfo = new KgEntityInfo();
kgEntityInfo.setOntologyId(ontologyId);
//获取所有实体集合
List<KgEntityInfoDTO> kgEntityInfos = kgEntityInfoMapper.selectListByOntologyId(kgEntityInfo);
List<Long> entityIds = kgEntityInfos.stream()
.map(KgEntityInfoDTO::getId)
.collect(Collectors.toList());
List<KgEntityProperty> entityPropertyList = kgEntityPropertiesService.getEntityPropertiesByEntityIds(entityIds);
List<KgEntityRelationDTO> entityRelationList = kgEntityRelationsService.getEntityRelationsByEntityIds(entityIds);

// 按实体ID分组
Map<Long, List<KgEntityProperty>> propertiesMap = entityPropertyList.stream()
.collect(Collectors.groupingBy(KgEntityProperty::getEntityId));
// 按实体ID分组
Map<Long, List<KgEntityRelationDTO>> relationsMap = entityRelationList.stream()
.collect(Collectors.groupingBy(KgEntityRelationDTO::getEntityId));

kgEntityInfos.forEach(item -> {
item.setProperties(propertiesMap.getOrDefault(item.getId(), Collections.emptyList()));
item.setRelations(relationsMap.getOrDefault(item.getId(), Collections.emptyList()));
});
return kgEntityInfos;
}

@Override
public KgEntityInfo getEntity(Long id) {
return kgEntityInfoMapper.selectByPrimaryKey(id);
}

@Override
public void deleteEntityById(Long id) {
kgEntityInfoMapper.deleteByPrimaryKey(id);
}
}





+ 73
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgEntityPropertiesServiceImpl.java View File

@@ -0,0 +1,73 @@
package com.ruoyi.kg.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.kg.domain.KgEntityProperty;
import com.ruoyi.kg.mapper.KgEntityPropertiesMapper;
import com.ruoyi.kg.service.KgEntityPropertiesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collections;
import java.util.List;

/**
* @author Administrator
* @description 针对表【kg_entity_properties】的数据库操作Service实现
* @createDate 2025-02-13 15:58:38
*/
@Service
public class KgEntityPropertiesServiceImpl implements KgEntityPropertiesService {
@Autowired
private KgEntityPropertiesMapper kgEntityPropertiesMapper;

@Override
public void insertEntityProperties(KgEntityProperty entityProperty) {
kgEntityPropertiesMapper.insertSelective(entityProperty);
}

@Override
public void updateEntityProperties(KgEntityProperty entityProperty) {
kgEntityPropertiesMapper.updateByPrimaryKey(entityProperty);
}

@Override
@Transactional
public void batchUpdateByEntityId(Long entityId, List<KgEntityProperty> entityProperties) {
entityProperties.forEach(item -> {
if (ObjectUtil.isNull(item.getId())) {
insertEntityProperties(item);
} else {
item.setEntityId(entityId);
updateEntityProperties(item);
}
});
}

@Override
public List<KgEntityProperty> getEntityProperties(KgEntityProperty entityProperty) {
return kgEntityPropertiesMapper.selectList(entityProperty);
}

@Override
public List<KgEntityProperty> getEntityPropertiesByEntityIds(List<Long> ids) {
if (CollectionUtil.isEmpty(ids)){
return Collections.emptyList();
}
return kgEntityPropertiesMapper.selectListByEntityIds(ids);
}

@Override
public KgEntityProperty getEntityProperty(Long id) {
return kgEntityPropertiesMapper.selectByPrimaryKey(id);
}

@Override
public void deleteEntityPropertyById(Long id) {
kgEntityPropertiesMapper.deleteByPrimaryKey(id);
}
}





+ 74
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgEntityRelationsServiceImpl.java View File

@@ -0,0 +1,74 @@
package com.ruoyi.kg.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.kg.domain.KgEntityRelation;
import com.ruoyi.kg.domain.dto.KgEntityRelationDTO;
import com.ruoyi.kg.mapper.KgEntityRelationsMapper;
import com.ruoyi.kg.service.KgEntityRelationsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Collections;
import java.util.List;

/**
* @author Administrator
* @description 针对表【kg_entity_relations】的数据库操作Service实现
* @createDate 2025-02-13 15:58:49
*/
@Service
public class KgEntityRelationsServiceImpl implements KgEntityRelationsService {
@Autowired
private KgEntityRelationsMapper kgEntityRelationsMapper;

@Override
public void insertEntityRelation(KgEntityRelation entityRelation) {
kgEntityRelationsMapper.insertSelective(entityRelation);
}

@Override
public void updateEntityRelation(KgEntityRelation entityRelation) {
kgEntityRelationsMapper.updateByPrimaryKey(entityRelation);
}

@Override
@Transactional
public void batchUpdateByEntityId(Long entityId, List<KgEntityRelation> entityRelations) {
entityRelations.forEach(item -> {
if (ObjectUtil.isNull(item.getId())) {
insertEntityRelation(item);
} else {
item.setEntityId(entityId);
updateEntityRelation(item);
}
});
}

@Override
public List<KgEntityRelation> getEntityRelations(KgEntityRelation entityRelations) {
return kgEntityRelationsMapper.selectList(entityRelations);
}

@Override
public List<KgEntityRelationDTO> getEntityRelationsByEntityIds(List<Long> ids) {
if (CollectionUtil.isEmpty(ids)){
return Collections.emptyList();
}
return kgEntityRelationsMapper.selectListByEntityIds(ids);
}

@Override
public KgEntityRelation getEntityRelations(Long id) {
return kgEntityRelationsMapper.selectByPrimaryKey(id);
}

@Override
public void deleteEntityRelationById(Long id) {
kgEntityRelationsMapper.deleteByPrimaryKey(id);
}
}





+ 50
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgInfoServiceImpl.java View File

@@ -0,0 +1,50 @@
package com.ruoyi.kg.service.impl;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.ruoyi.kg.domain.KgInfo;
import com.ruoyi.kg.domain.KgInfoPageVo;
import com.ruoyi.kg.domain.dto.KgInfoIdDTO;
import com.ruoyi.kg.mapper.KgInfoMapper;
import com.ruoyi.kg.service.KgInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class KgInfoServiceImpl implements KgInfoService {

@Autowired
private KgInfoMapper kgInfoMapper;

@Override
public void insertKgInfo(KgInfo KgInfo) {
KgInfo.setVersion("1");
DateTime date = DateUtil.date();
KgInfo.setCreateTime(date);
KgInfo.setUpdateTime(date);
kgInfoMapper.insertSelective(KgInfo);
}

@Override
public void updateKgInfo(KgInfo KgInfo) {
kgInfoMapper.updateByPrimaryKeySelective(KgInfo);
}

@Override
public List<KgInfoPageVo> getAllKgInfos() {
List<KgInfoPageVo> kgInfos = kgInfoMapper.selectALl();
return kgInfos;
}

@Override
public KgInfo getKgInfo(KgInfoIdDTO kgInfoIdDTO) {
return kgInfoMapper.queryInfoByPrimaryKey(kgInfoIdDTO);
}

@Override
public void deleteKgInfoById(Long id) {
kgInfoMapper.deleteByPrimaryKey(id);
}

}

+ 121
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgOntologyInfoServiceImpl.java View File

@@ -0,0 +1,121 @@
package com.ruoyi.kg.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONUtil;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.kg.domain.KgOntologyInfo;
import com.ruoyi.kg.domain.dto.*;
import com.ruoyi.kg.mapper.KgOntologyInfoMapper;
import com.ruoyi.kg.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author Administrator
* @description 针对表【kg_ontology_info】的数据库操作Service实现
* @createDate 2025-02-13 14:40:46
*/
@Service
public class KgOntologyInfoServiceImpl implements KgOntologyInfoService {
@Autowired
private KgOntologyInfoMapper kgOntologyInfoMapper;

@Autowired
private KgEntityInfoService kgEntityInfoService;

@Autowired
private KgEntityPropertiesService kgEntityPropertiesService;

@Autowired
private KgEntityRelationsService kgEntityRelationsService;

@Autowired
private KgEntityRepository graphNodeRepository;

@Override
public void insertOntology(KgOntologyInfo ontology) {
kgOntologyInfoMapper.insertSelective(ontology);
}

@Override
public void updateOntology(KgOntologyUpdateDTO ontology) {
String dag = ontology.getDag();
if (StringUtils.isNotEmpty(dag)) {
GraphData graphData = jsonToBean(dag);
ontology.setConceptsCount(CollectionUtil.isEmpty(graphData.getNodes()) ? 0 : graphData.getNodes().size());
ontology.setRelationsCount(CollectionUtil.isEmpty(graphData.getEdges()) ? 0 : graphData.getNodes().size());
}
kgOntologyInfoMapper.updateByPrimaryKeySelective(ontology);
}

@Override
public List<KgOntologyInfo> getOntologies(KgOntologyInfoPageDTO ontology) {
return kgOntologyInfoMapper.selectList(ontology);
}

@Override
public KgOntologyUpdateDTO getOntology(Long id) {
return kgOntologyInfoMapper.selectByPrimaryKey(id);
}

@Override
public void deleteOntologyById(Long id) {
kgOntologyInfoMapper.deleteByPrimaryKey(id);
}

@Override
@Transactional
public void batchDelete(List<Long> ids) {
kgOntologyInfoMapper.deleteByIds(ids);
}

@Override
public String importOntology(List<KgOntologyInfo> ontologyList, boolean updateSupport, String operName) {
return null;
}


@Override
@Transactional
public void saveGraph(GraphData graphData) {
// 存储节点
Map<Long, KgEntityInfoDTO> nodeMap = new HashMap<>();
for (KgEntityInfoDTO kgEntityInfoDTO : graphData.getNodes()) {
nodeMap.put(kgEntityInfoDTO.getId(), kgEntityInfoDTO);
graphNodeRepository.save(kgEntityInfoDTO);
}

// 存储关系
for (KgEntityRelationDTO kgEntityRelationDTO : graphData.getEdges()) {
KgEntityInfoDTO sourceNode = nodeMap.get(kgEntityRelationDTO.getSource());
KgEntityInfoDTO targetNode = nodeMap.get(kgEntityRelationDTO.getTarget());

if (sourceNode != null && targetNode != null) {
kgEntityRelationDTO.setTargetEntity(targetNode);
sourceNode.getRelations().add(kgEntityRelationDTO);
graphNodeRepository.save(sourceNode);
}
}
}

@Override
public List<KgOntologyNameAndIdDTO> getNameAndIds() {
return kgOntologyInfoMapper.getNameAndIds();
}

private GraphData jsonToBean(String dag) {
try {
return JSONUtil.toBean(dag, GraphData.class);
} catch (Exception e) {
return new GraphData();
}
}
}





+ 228
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgVersionServiceImpl.java View File

@@ -0,0 +1,228 @@
package com.ruoyi.kg.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.common.core.enums.KgStatus;
import com.ruoyi.common.core.enums.KgUpdateMethod;
import com.ruoyi.kg.domain.CsvParser;
import com.ruoyi.kg.domain.KnowledgeGraphVersion;
import com.ruoyi.kg.domain.Person;
import com.ruoyi.kg.domain.dto.KgInfoIdDTO;
import com.ruoyi.kg.domain.dto.KgVersionInsertDTO;
import com.ruoyi.kg.mapper.KnowledgeGraphVersionDao;
import com.ruoyi.kg.service.KgVersionService;
import com.ruoyi.kg.service.MinioService;
import com.ruoyi.kg.service.PersonRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.CRC32;

import com.ruoyi.kg.domain.FriendsWith;

@Service
public class KgVersionServiceImpl implements KgVersionService {

@Autowired
private KnowledgeGraphVersionDao knowledgeGraphVersionDao;

@Autowired
private PersonRepository personRepository;

@Autowired
private MinioService minioService;

@Value("${minio.bucketName}")
public String bucketName;

private static final Logger log = LoggerFactory.getLogger(KgVersionServiceImpl.class);

@Override
public List<KnowledgeGraphVersion> versionList(KgInfoIdDTO kgInfoIdDTO) {
return knowledgeGraphVersionDao.queryAll(kgInfoIdDTO);
}

@Override
public void insert(KgVersionInsertDTO kgVersionInsertDTO) {
String path = kgVersionInsertDTO.getPath();
String kgId = kgVersionInsertDTO.getKgId();
KnowledgeGraphVersion knowledgeGraphVersion = new KnowledgeGraphVersion();
knowledgeGraphVersion.setKgId(kgId);
knowledgeGraphVersion.setVersion(maxVersion(kgId));
knowledgeGraphVersion.setName(path.replaceAll(".*/([^/]+)$", "$1"));
knowledgeGraphVersion.setTransactionId(IdUtil.simpleUUID());
knowledgeGraphVersion.setStatus(KgStatus.OFFLINE.getCode());
knowledgeGraphVersion.setContent(path);
knowledgeGraphVersion.setUpdateMethod(KgUpdateMethod.PENDING_UPDATE.getCode());
knowledgeGraphVersionDao.insert(knowledgeGraphVersion);
}

@Override
public String uploadCsv(MultipartFile file) throws Exception {
String path = "/knowledge-graph/" + DateUtil.now() + "/" + file.getOriginalFilename();
minioService.uploadFile(bucketName, path, file);
return path;
}

@Override
@Transactional
public void fullUpdate(Long id) {
KnowledgeGraphVersion currentVersion = knowledgeGraphVersionDao.queryById(id);
String transactionId = currentVersion.getTransactionId();
Integer version = currentVersion.getVersion();
KnowledgeGraphVersion onlineVersion = knowledgeGraphVersionDao.onlineFind();
if (ObjectUtil.isNotNull(onlineVersion)) {
//旧版在线变离线
changeStatus(onlineVersion.getId(), KgStatus.OFFLINE.getCode(), null);
}
//当前版本变在线
changeStatus(currentVersion.getId(), KgStatus.ONLINE.getCode(), KgUpdateMethod.FULL_UPDATE.getCode());
//解析表格数据保存到neo4j
saveToNeo4j(currentVersion.getContent(), version, transactionId);
}

@Override
@Transactional
public void incrementalUpdate(Long id) {
//当前版本
KnowledgeGraphVersion currentVersion = knowledgeGraphVersionDao.queryById(id);
Integer version = currentVersion.getVersion();
String transactionId = currentVersion.getTransactionId();
// 找出在线的版本
KnowledgeGraphVersion onlineVersion = knowledgeGraphVersionDao.onlineFind();
if (ObjectUtil.isNotNull(onlineVersion) && ObjectUtil.isNotEmpty(onlineVersion.getTransactionId())
&& ObjectUtil.isNotNull(onlineVersion.getVersion())) {
// 存在在线的版本,则取在线版本的version和transactionId
transactionId = onlineVersion.getTransactionId();
version = onlineVersion.getVersion();
//当前版本更新方式改为增量更新
currentVersion.setUpdateMethod(KgUpdateMethod.INCREMENTAL_UPDATE.getCode());
currentVersion.setVersion(onlineVersion.getVersion());
knowledgeGraphVersionDao.update(currentVersion);
}else {
//当前版本为在线版本
changeStatus(currentVersion.getId(), KgStatus.ONLINE.getCode(), KgUpdateMethod.INCREMENTAL_UPDATE.getCode());
}
//解析表格数据保存到neo4j
saveToNeo4j(currentVersion.getContent(), version, transactionId);
}

@Override
@Transactional
public void rollback(Long versionId) {
//在线的版本置为离线
KnowledgeGraphVersion onlineVersion = knowledgeGraphVersionDao.onlineFind();
changeStatus(onlineVersion.getId(), KgStatus.OFFLINE.getCode(),null);
//该版本置为在线
changeStatus(versionId,KgStatus.ONLINE.getCode(),null);
}

@Override
@Transactional
public void delete(Long versionId) {
knowledgeGraphVersionDao.deleteById(versionId);
}

/**
* 状态切换
*
* @param id
* @param status
* @param updateMethod
*/
private void changeStatus(Long id, Integer status, Integer updateMethod) {
KnowledgeGraphVersion knowledgeGraphVersion = new KnowledgeGraphVersion();
knowledgeGraphVersion.setId(id);
knowledgeGraphVersion.setStatus(status);
knowledgeGraphVersion.setUpdateMethod(updateMethod);
knowledgeGraphVersionDao.update(knowledgeGraphVersion);
}

/**
* 从minio中获取数据
*
* @param path
* @return
*/
private List<Map<String, String>> queryCsvDataFromMinio(String path) {
List<Map<String, String>> csvData;
try {
ResponseEntity<InputStreamResource> inputStreamResourceResponseEntity = minioService.downloadFile(bucketName, path);
InputStreamResource body = inputStreamResourceResponseEntity.getBody();
InputStream inputStream = body.getInputStream();
csvData = CsvParser.parseCsvToMap(inputStream);
} catch (Exception e) {
csvData = new ArrayList<>();
}
return csvData;
}

/**
* 解析表格数据保存到neo4j
*/
private void saveToNeo4j(String content, int version, String transactionId) {
List<Map<String, String>> csvData = queryCsvDataFromMinio(content);
if (CollectionUtil.isEmpty(csvData)) {
return;
}
Map<String, Person> personMap = new HashMap<>();
// 把当前内容合并到在线版本
csvData.forEach(item -> {
String name = item.get("name");
String age = item.get("age");
String relationType = item.get("relation_type");
String relatedPerson = item.get("friends_with");
String since = item.get("since");

// 创建或获取 Person 节点
Person person = personMap.computeIfAbsent(name, k -> new Person(name, age, new ArrayList<>(), version, transactionId));

// 如果存在关系,则创建关系
if (relationType != null && relatedPerson != null) {
Person related = personMap.computeIfAbsent(relatedPerson, k -> new Person(relatedPerson, "0", new ArrayList<>(), version, transactionId));
FriendsWith relation = new FriendsWith(related, since, version, transactionId);
relation.setRelationType(relationType); // 动态设置关系类型
person.getRelations().add(relation);
}
// 保存 Person 节点
personRepository.save(person);
});
}

/**
* 根据名称和事务id生成实体和关系的唯一id
*
* @param input
* @return
*/
private Long createUUID(String input) {
CRC32 crc32 = new CRC32();
crc32.update(input.getBytes());
return crc32.getValue();
}

/**
* 下一个升级的版本
*
* @param kgId
* @return
*/
private int maxVersion(String kgId) {
Integer maxVersion = knowledgeGraphVersionDao.queryMaxVersion(kgId);
return ObjectUtil.isNull(maxVersion) ? 1 : ++maxVersion;
}

}

+ 101
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/MinioServiceImpl.java View File

@@ -0,0 +1,101 @@
package com.ruoyi.kg.service.impl;

import com.ruoyi.kg.service.MinioService;
import com.ruoyi.kg.utils.FileUtil;
import com.ruoyi.kg.utils.MinioUtil;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;

@Service
public class MinioServiceImpl implements MinioService {

private final MinioUtil minioUtil;

public MinioServiceImpl(MinioUtil minioUtil) {
this.minioUtil = minioUtil;
}

@Override
public ResponseEntity<InputStreamResource> downloadFile(String bucketName , String url) throws Exception {
try {
// 使用ByteArrayOutputStream来捕获下载的数据
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
minioUtil.downloadObject(bucketName, url, outputStream);

ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
InputStreamResource resource = new InputStreamResource(inputStream);

return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + extractFileName(url) + "\"")
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.body(resource);
} catch (Exception e) {
e.printStackTrace();
throw new Exception("下载文件错误");
}
}

private String extractFileName(String urlStr) {
return urlStr.substring(urlStr.lastIndexOf('/') + 1);
}


@Override
public ResponseEntity<InputStreamResource> downloadZipFile(String bucketName,String path) {
try {
// 使用ByteArrayOutputStream来捕获下载的数据
InputStream inputStream = minioUtil.downloadAndZip(bucketName, path);
Path p = Paths.get(path);
String fileName = p.getFileName().toString()+".zip";
InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\"")
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.body(inputStreamResource);

} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}

@Override
public Map<String, String> uploadFile(String bucketName, String objectName, MultipartFile file ) throws Exception {
if (file.isEmpty()) {
throw new Exception("文件为空,无法上传");
}
// 获取文件大小并转换为可读形式
long sizeInBytes = file.getSize();
String formattedSize = FileUtil.formatFileSize(sizeInBytes); // 格式化文件大小
Map<String, String> result = new HashMap<>();
// 上传文件到MinIO并将记录新增到数据库中
try (InputStream inputStream = file.getInputStream()){
minioUtil.uploadObject(bucketName, objectName, inputStream);
result.put("fileName", file.getOriginalFilename());
int lastIndex = objectName.lastIndexOf('/');
String url = objectName.substring(0, lastIndex);
result.put("url", url); // objectName根据实际情况定义
result.put("fileSize", formattedSize);
} catch (Exception e) {
throw new Exception("上传文件失败: " + e.getMessage(), e);
}
return result;
}

@Override
public void uploaInputStream(String bucketName, String objectName, InputStream inputStream ) throws Exception {
minioUtil.uploadObject(bucketName, objectName, inputStream);
}
}

+ 641
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/utils/DVCUtils.java View File

@@ -0,0 +1,641 @@
package com.ruoyi.kg.utils;

import org.eclipse.jgit.api.*;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.eclipse.jgit.transport.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.*;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

@Component
public class DVCUtils {
private static final ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
private static final Logger log = LoggerFactory.getLogger(DVCUtils.class);
private static final ExecutorCompletionService<Void> completionService = new ExecutorCompletionService<>(executorService);
@Value("${proxy.useProxy:false}")
private boolean useProxy;

@Value("${proxy.host}")
private String host;

@Value("${proxy.port}")
private Integer port;
private class ProxyConfigCallback implements TransportConfigCallback {
@Override
public void configure(Transport transport) {
if (useProxy) {
System.setProperty("http.proxyHost", host);
System.setProperty("http.proxyPort", String.valueOf(port));
System.setProperty("https.proxyHost", host);
System.setProperty("https.proxyPort", String.valueOf(port));
log.info("Proxy configured: {}:{}", host, port);
}
}
}

private static void runCommand(String command, String workingDir) throws Exception {
ProcessBuilder processBuilder = new ProcessBuilder(command.split(" "));
processBuilder.directory(new File(workingDir));
Process process = processBuilder.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
log.info(line);
}
int exitCode = process.waitFor();
if (exitCode != 0) {
throw new Exception("Command failed with exit code " + exitCode);
}
}

public void moveFiles(String sourcePath, String targetPath) throws Exception {
Path sourceDir = Paths.get(sourcePath);
Path targetDir = Paths.get(targetPath);

if (!Files.exists(targetDir)) {
Files.createDirectories(targetDir);
}

Files.move(sourceDir, targetDir, StandardCopyOption.REPLACE_EXISTING);
}

public void deleteDirectory(String dirPath) throws IOException {
Path directory = Paths.get(dirPath);

// 检查是否目录存在
if (Files.exists(directory)) {
// 使用Files.walk来删除目录及其内容
Files.walk(directory)
.filter(path -> !path.equals(directory))
.sorted(Comparator.reverseOrder()) // 先删除子文件夹,再删除父文件夹
.forEach(this::deletePath);
}
}

private void deletePath(Path path) {
try {
Files.deleteIfExists(path);
} catch (IOException e) {
log.error("Unable to delete: " + path + " " + e.getMessage());
}
}

public void gitClone(String localPath, String repoUrl, String branch, String username, String password) throws GitAPIException {
CloneCommand cloneCommand = Git.cloneRepository()
.setURI(repoUrl)
.setBranch(branch)
.setDirectory(new File(localPath))
.setTransportConfigCallback(new ProxyConfigCallback())
.setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password));

cloneCommand.call();
}

public void gitClone(String localPath, String repoUrl, String username, String password) throws GitAPIException {
CloneCommand cloneCommand = Git.cloneRepository()
.setURI(repoUrl)
.setDirectory(new File(localPath))
.setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password));

cloneCommand.call();
}


public void gitAdd(String localPath, String filePath) throws IOException, GitAPIException {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(new File(localPath, ".git"))
.readEnvironment()
.findGitDir()
.build();

try (Git git = new Git(repository)) {
AddCommand addCommand = git.add();
addCommand.addFilepattern(filePath).call();
}
}

public void gitCommit(String localPath, String commitMessage) throws IOException, GitAPIException {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(new File(localPath, ".git"))
.readEnvironment()
.findGitDir()
.build();

try (Git git = new Git(repository)) {
// 添加所有文件
AddCommand addCommand = git.add();
addCommand.addFilepattern(".").call();

// 提交更改
CommitCommand commitCommand = git.commit();
commitCommand.setMessage(commitMessage).call();
}
}

public void gitPush(String localPath, String username, String password) throws IOException, GitAPIException {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(new File(localPath, ".git"))
.readEnvironment()
.findGitDir()
.build();

try (Git git = new Git(repository)) {
CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(username, password);
PushCommand pushCommand = git.push();
pushCommand.setCredentialsProvider(credentialsProvider)
.setTransportConfigCallback(new ProxyConfigCallback())
.setForce(true)
.call();
}
}


/**
* 更新本地仓库中的所有分支
*
* @param localPath 本地仓库路径
* @param username 远程仓库用户名
* @param password 远程仓库密码
*/
public void updateAllBranches(String localPath, String username, String password) {
try (Git git = Git.open(new File(localPath))) {
// 设置凭证,用于远程仓库的认证
UsernamePasswordCredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(username, password);

// 获取远程分支列表
List<Ref> remoteBranches = git.branchList().setListMode(ListBranchCommand.ListMode.REMOTE).call();

// 遍历远程分支并更新本地对应的分支
for (Ref remoteBranch : remoteBranches) {
// 获取分支名称,去掉前缀 "refs/remotes/origin/"
String branchName = remoteBranch.getName().replace("refs/remotes/origin/", "");
log.info("Updating branch: " + branchName);

// 检查本地是否存在该分支,如果不存在则创建
if (!branchExistsLocally(git, branchName)) {
git.branchCreate().setName(branchName).setStartPoint("origin/" + branchName).call();
}

// 切换到对应的分支
git.checkout().setName(branchName).call();

// 拉取远程分支的最新内容
PullCommand pull = git.pull().setRemoteBranchName(branchName).setCredentialsProvider(credentialsProvider);
pull.call();
}

log.info("All branches updated successfully.");

} catch (IOException | GitAPIException e) {
log.error("Error occurred while updating all branches", e);
}
}

/**
* 更新本地仓库中的指定分支
*
* @param localPath 本地仓库路径
* @param username 远程仓库用户名
* @param password 远程仓库密码
* @param branchName 需要更新的分支名称
*/
public void updateBranch(String localPath, String username, String password, String branchName) {
try (Git git = Git.open(new File(localPath))) {
// 设置凭证,用于远程仓库的认证
UsernamePasswordCredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(username, password);

// 检查本地是否存在该分支,如果不存在则创建
if (!branchExistsLocally(git, branchName)) {
git.branchCreate().setName(branchName).setStartPoint("origin/" + branchName).call();
}

// 切换到对应的分支
git.checkout().setName(branchName).call();

// 拉取远程分支的最新内容
PullCommand pull = git.pull().setRemoteBranchName(branchName).setCredentialsProvider(credentialsProvider);
pull.call();

log.info("Branch " + branchName + " updated successfully.");

} catch (IOException | GitAPIException e) {
log.error("Error occurred while updating branche", e);
}
}


/**
* 创建本地分支
*
* @param localPath 本地仓库路径
* @param branchName 要创建的分支名称
*/
public void createLocalBranch(String localPath, String branchName) {
try (Git git = Git.open(new File(localPath))) {
// 创建本地分支
git.branchCreate().setName(branchName).call();
log.info("本地分支 " + branchName + " 创建成功。");

} catch (IOException | GitAPIException e) {
log.error("Error occurred while creating local branch", e);
}
}
/**
* 删除本地分支
*
* @param localPath 本地仓库路径
* @param branchName 要删除的分支名称
*/
public void deleteLocalBranch(String localPath, String branchName) throws IOException, GitAPIException {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(new File(localPath + "/.git"))
.readEnvironment()
.findGitDir()
.build();

try (Git git = new Git(repository)) {
// 获取所有本地分支
for (Ref ref : git.branchList().call()) {
String refName = ref.getName();
if (refName.endsWith("/" + branchName)) {
// 删除本地分支
git.branchDelete().setBranchNames(refName).setForce(true).call();
log.info("Deleted branch: " + branchName);
return;
}
}
log.info("Branch not found: " + branchName);
}
}

/**
* 基于 master 创建本地分支
*
* @param localPath 本地仓库路径
* @param branchName 要创建的分支名称
*/
public void createLocalBranchBasedOnMaster(String localPath, String branchName) {
try (Git git = Git.open(new File(localPath))) {
// 切换到 master 分支
git.checkout()
.setCreateBranch(true)
.setName(branchName)
.setStartPoint("origin/master")
.call();
log.info("基于 master 的远程分支 " + branchName + " 创建成功。");
} catch (IOException | GitAPIException e) {
log.error("Exception occurred while creating local branch based on master", e);
}
}

/**
* 将本地分支推送到远程仓库
*
* @param localPath 本地仓库路径
* @param username 远程仓库用户名
* @param password 远程仓库密码
* @param branchName 要推送的分支名称
*/
public void pushLocalBranchToRemote(String localPath, String username, String password, String branchName) {
try (Git git = Git.open(new File(localPath))) {
// 设置凭证,用于远程仓库的认证
UsernamePasswordCredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(username, password);

// 切换到要推送的分支
git.checkout().setName(branchName).call();

// 添加所有更改到暂存区
git.add().addFilepattern(".").call();

// 提交更改
git.commit().setMessage("commit from ci4s").call();

// 推送本地分支到远程仓库
git.push()
.setRemote("origin")
.add(branchName)
.setCredentialsProvider(credentialsProvider)
.call();

log.info("本地分支 " + branchName + " 推送成功。");

} catch (IOException | GitAPIException e) {
log.error("Error occurred while pushing local branch to remote", e);
}
}

/**
* 将本地分支推送到远程(新增远程分支)
*
* @param localPath 本地仓库路径
* @param username 用户名
* @param password 密码
* @param branchName 要推送的分支名称
* @throws IOException 如果仓库路径无效
* @throws GitAPIException 如果Git操作失败
*/
public void pushNewBranchToRemote(String localPath, String username, String password, String branchName) throws IOException, GitAPIException {
try (Git git = Git.open(new File(localPath))) {
// 设置凭证,用于远程仓库的认证
UsernamePasswordCredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(username, password);

// 切换到要推送的分支,确保分支已存在,并且切换至该分支
git.checkout().setName(branchName).call();

// 创建一个新的 RefSpec
RefSpec refSpec = new RefSpec(branchName + ":" + branchName);

// 添加所有更改到暂存区
git.add().addFilepattern(".").call();

// 提交更改
git.commit().setMessage("commit from ci4s").call();
// 推送本地分支到远程端(如果远程无该分支,则新增)
Iterable<PushResult> pushResults = git.push()
.setRemote("origin")
.setRefSpecs(refSpec)
.setCredentialsProvider(credentialsProvider)
.setTransportConfigCallback(new ProxyConfigCallback())
.call();

// 打印结果
pushResults.forEach(pr -> log.info(pr.getMessages()));

log.info("分支 " + branchName + " 已成功推送到远程仓库。");
}
}

/**
* 检查本地是否存在指定分支
*
* @param git Git 实例
* @param branchName 分支名称
* @return 如果本地存在该分支返回 true,否则返回 false
*/
private static boolean branchExistsLocally(Git git, String branchName) throws GitAPIException {
List<Ref> localBranches = git.branchList().call();
for (Ref localBranch : localBranches) {
if (localBranch.getName().endsWith("/" + branchName)) {
return true;
}
}
return false;
}

public void refreshRemoteBranches(String localPath, String username, String password, String branch) throws Exception {
try (Repository repository = new FileRepositoryBuilder()
.setGitDir(new File(localPath + "/.git"))
.readEnvironment()
.findGitDir()
.build()) {

Git git = new Git(repository);

// 检查仓库状态
if (repository.getRepositoryState().equals(RepositoryState.MERGING) ||
repository.getRepositoryState().equals(RepositoryState.MERGING_RESOLVED)) {
log.info("Repository is in a merging state, please resolve conflicts manually.");
return;
}

// 设置凭证提供者
UsernamePasswordCredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(username, password);

// 获取远程分支
FetchResult fetchResult = git.fetch()
.setRemote("origin")
.setCredentialsProvider(credentialsProvider)
.setTransportConfigCallback(new ProxyConfigCallback()) // 设置代理
.call();

// 打印获取的远程分支
Collection<Ref> fetchedRefs = fetchResult.getAdvertisedRefs();
for (Ref ref : fetchedRefs) {
log.info("Fetched branch: " + ref.getName());
}

// 更新本地分支信息
git.branchList()
.setListMode(ListBranchCommand.ListMode.REMOTE)
.call()
.forEach(ref -> {
String fullBranchName = ref.getName();
String branchName = fullBranchName.replace("refs/remotes/origin/", "");
try {
completionService.submit(() -> {
try {
processBranch(git, repository, credentialsProvider, fullBranchName, branchName);
} catch (Exception e) {
log.error("Failed to process branch: " + branchName, e);
}
return null;
});
} catch (Exception e) {
log.error("Task submission rejected", e);
}
});

executorService.shutdown();
try {
executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException e) {
log.error("Executor service interrupted", e);
}
log.info("远程分支刷新到本地完成。");
} catch (Exception e) {
log.error("Error occurred while refreshing remote branches ", e);
}

// 切换分支
gitCheckoutBranch(localPath, branch);
dvcPull(localPath);
dvcCheckout(localPath);
}

private void processBranch(Git git, Repository repository, UsernamePasswordCredentialsProvider credentialsProvider, String fullBranchName, String branchName) throws Exception {
// 检查本地分支是否存在
Ref localRef = repository.findRef("refs/heads/" + branchName);
if (localRef != null) {
// 如果存在,检查是否已经关联到远程分支
if (!isBranchUpstreamSet(repository, branchName)) {
// 如果没有关联,设置上游分支
git.branchCreate()
.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM)
.setStartPoint(fullBranchName)
.setName(branchName)
.call();
}
} else {
// 如果不存在,创建本地分支并设置上游分支
git.branchCreate()
.setName(branchName)
.setStartPoint(fullBranchName)
.call();
// 设置上游分支
git.branchCreate()
.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.SET_UPSTREAM)
.setStartPoint(fullBranchName)
.setName(branchName)
.call();
}
// 执行 git pull
PullCommand pullCommand = git.pull()
.setTransportConfigCallback(new ProxyConfigCallback())
.setCredentialsProvider(credentialsProvider);
pullCommand.call();
}

/**
* 检查本地分支是否已经关联到远程分支
*
* @param repository 仓库对象
* @param branchName 分支名称
* @return 如果已经关联,返回 true;否则返回 false
*/
private static boolean isBranchUpstreamSet(Repository repository, String branchName) {
try {
org.eclipse.jgit.lib.Config config = repository.getConfig();
String upstreamBranch = config.getString("branch", branchName, "merge");
return upstreamBranch != null && !upstreamBranch.isEmpty();
} catch (Exception e) {
log.error("Failed to check upstream for branch: " + branchName, e);
return false;
}
}




public void gitFetch(String localPath, String username, String password) throws IOException, GitAPIException {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(new File(localPath, ".git"))
.readEnvironment()
.findGitDir()
.build();

try (Git git = new Git(repository)) {
CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(username, password);
FetchCommand fetchCommand = git.fetch();
fetchCommand.setCredentialsProvider(credentialsProvider).call();
}
}

//强制切换分支
public void gitCheckoutBranch(String localPath, String branchName) throws IOException, GitAPIException {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(new File(localPath, ".git"))
.readEnvironment()
.findGitDir()
.build();

try (Git git = new Git(repository)) {
CheckoutCommand checkoutCommand = git.checkout();
checkoutCommand.setName(branchName).setForce(true).call();
}
}

public void gitPull(String localPath, String username, String password) throws IOException, GitAPIException {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.setGitDir(new File(localPath, ".git"))
.readEnvironment()
.findGitDir()
.build();

try (Git git = new Git(repository)) {
CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(username, password);
PullCommand pullCommand = git.pull();
pullCommand.setCredentialsProvider(credentialsProvider).call();
}
}

public void dvcInit(String localPath) throws Exception {
String command = "dvc init";
runCommand(command, localPath);
}

public void dvcAdd(String localPath, String filePath) throws Exception {
String command = "dvc add " + filePath;
runCommand(command, localPath);
}

public void dvcRemoteAdd(String localPath, String s3RemoteUrl) throws Exception {
String command = "dvc remote add -d myremote s3://" + s3RemoteUrl;
runCommand(command, localPath);
}

public void dvcConfigS3Credentials(String localPath, String endpointurl) throws Exception {
String command = "dvc remote modify myremote endpointurl " + endpointurl;
runCommand(command, localPath);
}

public void dvcConfigS3Credentials2(String localPath, String accessKeyId) throws Exception {
String command = "dvc remote modify myremote access_key_id " + accessKeyId;
runCommand(command, localPath);
}

public void dvcConfigS3Credentials3(String localPath, String secretAccessKey) throws Exception {
String command = "dvc remote modify myremote secret_access_key " + secretAccessKey;
runCommand(command, localPath);
}

public void dvcPush(String localPath) throws Exception {
String command = "dvc push -v";
runCommand(command, localPath);
}

// 强制刷新 dvcPull 方法
public void dvcPull(String localPath) throws Exception {
String command = "dvc pull -v --force";
runCommand(command, localPath);
}


// 方法
public void dvcCheckout(String localPath) throws Exception {
String command = "dvc checkout -v --force";
runCommand(command, localPath);
}


/**
* 切换到指定分支并执行git pull,然后获取data文件夹下所有文件的路径、名称和大小
*
* @param localPath 本地路径
* @param repoFolder 仓库文件夹名称
* @param branch 分支名称
* @return 包含文件路径、名称和大小的List<Map<String, Object>>
*/
public List<Map<String, Object>> getFileDetailsAfterGitPull(String localPath, String repoFolder, String branch, String filePath, String username, String password) {
try {
//刷新
refreshRemoteBranches(localPath + "/" + repoFolder + "/" + branch, username, password, branch);
// 读取data文件夹中的文件列表
String path = localPath + "/" + repoFolder + "/" + branch + "/" + filePath;

return FileUtil.getFiles(path);

} catch (Exception e) {
log.error("Error occurred while getting file details after git pull", e);
}
return new ArrayList<>();
}
}

+ 189
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/utils/FileUtil.java View File

@@ -0,0 +1,189 @@
package com.ruoyi.kg.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.web.multipart.MultipartFile;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class FileUtil {

private static final Logger log = LoggerFactory.getLogger(DVCUtils.class);

// 格式化文件大小为可读的字符串表示
public static String formatFileSize(long sizeInBytes) {
// 检查文件大小是否为负数
if (sizeInBytes < 0) {
throw new IllegalArgumentException("File size cannot be negative.");
}

// 如果文件大小小于1KB,直接返回字节数
if (sizeInBytes < 1024) {
return sizeInBytes + " B";
}
// 如果文件大小小于1MB,转换为KB并返回
else if (sizeInBytes < 1024 * 1024) {
double sizeInKB = sizeInBytes / 1024.0;
return String.format("%.2f KB", sizeInKB);
}
// 如果文件大小小于1GB,转换为MB并返回
else if (sizeInBytes < 1024 * 1024 * 1024) {
double sizeInMB = sizeInBytes / (1024.0 * 1024);
return String.format("%.2f MB", sizeInMB);
}
// 如果文件大小大于或等于1GB,转换为GB并返回
else {
double sizeInGB = sizeInBytes / (1024.0 * 1024 * 1024);
return String.format("%.2f GB", sizeInGB);
}
}

/**
* 检查指定路径的文件夹是否存在
*
* @param localPath 本地路径
* @return 如果文件夹存在返回true,否则返回false
*/
public static boolean checkDirectoryExists(String localPath) {
File directory = new File(localPath);
return directory.exists() && directory.isDirectory();
}


public static long getFolderSize(File folder) {
long size = 0;
File[] files = folder.listFiles(); // 获取文件夹下所有文件和子目录

if (files != null) {
for (File file : files) {
if (file.isFile()) {
// 如果是文件,则累加其大小
size += file.length();
} else if (file.isDirectory()) {
// 如果是子目录,则递归计算其大小
size += getFolderSize(file);
}
}
}
return size;
}

public static List<Map<String, Object>> getFiles(String path) {
List<Map<String, Object>> fileInfoList = new ArrayList<>();

Path dataPath = Paths.get(path);
File[] files = dataPath.toFile().listFiles();
try {
if (files != null) {
for (File file : files) {
if (file.isFile()) {
long size = Files.size(file.toPath());
String absoluteFilePath = file.getAbsolutePath();
String fileName = file.getName();

Map<String, Object> fileDetails = new HashMap<>();
fileDetails.put("size", size);
fileDetails.put("filePath", absoluteFilePath);
fileDetails.put("fileName", fileName);

fileInfoList.add(fileDetails);
}
}
}
} catch (Exception e) {
log.error("Error occurred while getting file details after git pull", e);
}
return fileInfoList;
}

public static void renameFile(String oldPath ,String newPath){
File oldFolder = new File(oldPath);

// 新文件夹路径
File newFolder = new File(newPath);

// 重命名文件夹
boolean renamed = oldFolder.renameTo(newFolder);
}

public static MultipartFile[] toMultipartFiles(InputStream inputStream, String fileName) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(baos);
ZipEntry zipEntry = new ZipEntry(fileName);
zos.putNextEntry(zipEntry);

byte[] bytes = new byte[1024];
int length;
while ((length = inputStream.read(bytes)) >= 0) {
zos.write(bytes, 0, length);
}

zos.closeEntry();
zos.close();
inputStream.close();

ByteArrayResource resource = new ByteArrayResource(baos.toByteArray());
return new MultipartFile[]{new CustomMultipartFile(resource, fileName)};
}

private static class CustomMultipartFile implements MultipartFile {

private final ByteArrayResource resource;
private final String fileName;

CustomMultipartFile(ByteArrayResource resource, String fileName) {
this.resource = resource;
this.fileName = fileName;
}

@Override
public String getName() {
return fileName;
}

@Override
public String getOriginalFilename() {
return fileName;
}

@Override
public String getContentType() {
return "application/zip";
}

@Override
public boolean isEmpty() {
return resource.contentLength() == 0;
}

@Override
public long getSize() {
return resource.contentLength();
}

@Override
public byte[] getBytes() throws IOException {
return resource.getByteArray();
}

@Override
public InputStream getInputStream() throws IOException {
return new ByteArrayInputStream(resource.getByteArray());
}

@Override
public void transferTo(File dest) throws IOException, IllegalStateException {
resource.getByteArray();
}
}
}

+ 457
- 0
ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/utils/MinioUtil.java View File

@@ -0,0 +1,457 @@
package com.ruoyi.kg.utils;


import io.minio.*;
import io.minio.errors.MinioException;
import io.minio.messages.DeleteObject;
import io.minio.messages.Item;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.*;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

@Slf4j
@Component
public class MinioUtil {

private static MinioClient minioClient;

@Value("${git.localPath}")
String localPath;
@Value("${minio.endpointIp}")
String minioEndpoint;

@Autowired
public MinioUtil(@Value("${minio.endpoint}") String minioEndpoint, @Value("${minio.accessKey}") String minioAccessKey, @Value("${minio.secretKey}") String minioSecretKey) {
this.minioClient = MinioClient.builder()
.endpoint(minioEndpoint)
.credentials(minioAccessKey, minioSecretKey)
.build();
}

public void createBucket(String bucketName) throws Exception {
if (!minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build())) {
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
}
}

public void removeBucket(String bucketName) throws Exception {
minioClient.removeBucket(RemoveBucketArgs.builder().bucket(bucketName).build());
}

/**
* 验证bucketName是否存在
*
* @return boolean true:存在
*/
public boolean bucketExists(String bucketName)
throws Exception {
return minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
}

/**
* 判断文件是否存在
*
* @param bucketName 存储桶
* @param objectName 对象
* @return true:存在
*/
public boolean doesObjectExist(String bucketName, String objectName) {
boolean exist = true;
try {
minioClient.statObject(StatObjectArgs.builder().bucket(bucketName).object(objectName).build());
} catch (Exception e) {
exist = false;
}
return exist;
}

/**
* 判断文件夹是否存在
*
* @param bucketName 存储桶
* @param objectName 文件夹名称(去掉/)
* @return true:存在
*/
public boolean doesFolderExist(String bucketName, String objectName) {
boolean exist = false;
try {
Iterable<Result<Item>> results = minioClient.listObjects(
ListObjectsArgs.builder().bucket(bucketName).prefix(objectName).recursive(false).build());
for (Result<Item> result : results) {
Item item = result.get();
if (item.isDir() && objectName.equals(item.objectName())) {
exist = true;
}
}
} catch (Exception e) {
exist = false;
}
return exist;
}

/**
* 根据文件前置查询文件
*
* @param bucketName bucket名称
* @param prefix 前缀
* @param recursive 是否递归查询
* @return MinioItem 列表
*/
public List<Item> getAllObjectsByPrefix(String bucketName, String prefix, boolean recursive) throws Exception {
List<Item> list = new ArrayList<>();
Iterable<Result<Item>> objectsIterator = minioClient.listObjects(
ListObjectsArgs.
builder().
bucket(bucketName).
prefix(prefix).
recursive(recursive).
build());
if (objectsIterator != null) {
for (Result<Item> o : objectsIterator) {
Item item = o.get();
list.add(item);
}
}
return list;
}


public void uploadObject(String bucketName, String objectName, InputStream stream) throws Exception {
long size = stream.available();
minioClient.putObject(
PutObjectArgs.builder()
.bucket(bucketName)
.object(objectName)
.stream(stream, size, -1)
.build()
);
}

/**
* 通过MultipartFile,上传文件
*
* @param bucketName 存储桶
* @param file 文件
* @param objectName 对象名
* @param contentType 文件类型
*/
public static ObjectWriteResponse putObject(String bucketName, MultipartFile file, String objectName, String contentType) throws Exception {
InputStream inputStream = file.getInputStream();
return minioClient.putObject(
PutObjectArgs.builder().bucket(bucketName).object(objectName).contentType(contentType)
.stream(inputStream, inputStream.available(), -1).build());
}

/**
* 通过MultipartFile,上传文件
*
* @param bucketName 存储桶
* @param file 文件
* @param objectName 对象名
*/
public static ObjectWriteResponse putObject(String bucketName, MultipartFile file, String objectName) throws Exception {
InputStream inputStream = file.getInputStream();
return minioClient.putObject(
PutObjectArgs.builder().bucket(bucketName).object(objectName)
.stream(inputStream, inputStream.available(), -1).build());
}


public void downloadObject(String bucketName, String objectName, OutputStream stream) throws Exception {
try (InputStream inStream = minioClient.getObject(GetObjectArgs.builder().bucket(bucketName).object(objectName).build())) {
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = inStream.read(buffer)) != -1) {
stream.write(buffer, 0, bytesRead);
}
}
}

/**
* 创建文件夹或目录
*
* @param bucketName 存储桶
* @param objectName 目录路径
*/
public ObjectWriteResponse putDirObject(String bucketName, String objectName) throws Exception {
return minioClient.putObject(
PutObjectArgs.builder().bucket(bucketName).object(objectName).stream(
new ByteArrayInputStream(new byte[]{}), 0, -1).build());
}

/**
* 拷贝文件
*
* @param bucketName bucket名称
* @param objectName 文件名称
* @param srcBucketName 目标bucket名称
* @param srcObjectName 目标文件名称
*/
public ObjectWriteResponse copyObject(String bucketName, String objectName,
String srcBucketName, String srcObjectName) throws Exception {
return minioClient.copyObject(
CopyObjectArgs.builder()
.source(CopySource.builder().bucket(bucketName).object(objectName).build())
.bucket(srcBucketName)
.object(srcObjectName)
.build());
}


/**
* 递归拷贝
*
* @param sourceBucketName 源bucket名称
* @param sourceKeyPrefix 源目录路径
* @param targetBucketName 目标bucket名称
* @param targetKeyPrefix 目标目录名称
*/
public void copyDirectory(String sourceBucketName, String sourceKeyPrefix,
String targetBucketName, String targetKeyPrefix) throws Exception {
// 列出所有源目录下的对象
Iterable<Result<Item>> results = minioClient.listObjects(ListObjectsArgs.builder()
.bucket(sourceBucketName)
.prefix(sourceKeyPrefix)
.recursive(true)
.build());

for (Result<Item> result : results) {
Item item = result.get();
String sourceKey = item.objectName(); //文件的原始完整路径
String targetKey = targetKeyPrefix + sourceKey.substring(sourceKeyPrefix.length());

// 拷贝每个对象到目标路径
minioClient.copyObject(CopyObjectArgs.builder()
.bucket(targetBucketName)
.object(targetKey)
.source(CopySource.builder()
.bucket(sourceBucketName)
.object(sourceKey)
.build())
.build());
}
}


/**
* 获取文件流
*
* @param bucketName bucket名称
* @param objectName 文件名称
* @return 二进制流
*/
public static InputStream getObject(String bucketName, String objectName) throws Exception {
return minioClient.getObject(GetObjectArgs.builder().bucket(bucketName).object(objectName).build());
}

/**
* 断点下载
*
* @param bucketName bucket名称
* @param objectName 文件名称
* @param offset 起始字节的位置
* @param length 要读取的长度
* @return 流
*/
public InputStream getObject(String bucketName, String objectName, long offset, long length)
throws Exception {
return minioClient.getObject(GetObjectArgs.builder().bucket(bucketName).object(objectName).offset(offset).length(length).build());
}


public void downloadFiles(String bucketName, String root_path, String targetPath) throws Exception {
ListObjectsArgs listObjectsArgs = ListObjectsArgs.builder().bucket(bucketName).prefix(root_path).build();
findAndSaveFile(listObjectsArgs, bucketName, targetPath);
}

private void findAndSaveFile(ListObjectsArgs listObjectsArgs, String bucketName, String targetPath) throws Exception {
// List all objects in the bucket
Iterable<Result<Item>> results = minioClient.listObjects(listObjectsArgs);
for (Result<Item> result : results) {
Item item = result.get();
if (item.isDir()) {
System.out.println("文件夹:" + URLDecoder.decode(item.objectName(), "UTF-8"));//输出日志
ListObjectsArgs args = ListObjectsArgs.builder().bucket(bucketName).prefix(item.objectName()).build();
findAndSaveFile(args, bucketName, targetPath);
} else {
GetObjectArgs getObjectArgs = GetObjectArgs.builder().bucket(bucketName).object(URLDecoder.decode(item.objectName())).build();
String objectName = URLDecoder.decode(item.objectName(), "UTF-8");
// Create a local file with the same name as the object
Path fileName = Paths.get(objectName).getFileName();
String targetFile = targetPath + "/" + fileName.toString();
File file = new File(targetFile);
// Create parent directories if needed
file.getParentFile().mkdirs();
// Get the object as an input stream
try (InputStream stream = minioClient.getObject(getObjectArgs)) {
// Copy the input stream to the file
FileUtils.copyInputStreamToFile(stream, file);
}
System.out.printf("文件:%s 下载成功!\n", URLDecoder.decode(item.objectName()));//输出日志
}
}
}

public List<Map> listFilesInDirectory(String bucketName, String prefix) throws Exception {
List<Map> fileInfoList = new ArrayList<>();
Iterable<Result<Item>> results = minioClient.listObjects(
ListObjectsArgs.builder()
.prefix(prefix)
.bucket(bucketName)
.build());

for (Result<Item> result : results) {
Item item = result.get();
String fullPath = item.objectName();
Path path = Paths.get(fullPath);

String fileName = path.getFileName().toString();
long fileSize = item.size();
String formattedSize = FileUtil.formatFileSize(fileSize); // 格式化文件大小
Map map = new HashMap<>();
map.put("name", fileName);
map.put("size", formattedSize);
fileInfoList.add(map);
}

return fileInfoList;
}


public List<Map> listRayFilesInDirectory(String bucketName, String prefix) throws Exception {
List<Map> fileInfoList = new ArrayList<>();
Iterable<Result<Item>> results = minioClient.listObjects(
ListObjectsArgs.builder()
.prefix(prefix)
.bucket(bucketName)
.build());

for (Result<Item> result : results) {
Item item = result.get();
String fullPath = item.objectName();
Path path = Paths.get(fullPath);

String fileName = path.getFileName().toString();
long fileSize = item.size();
String formattedSize = FileUtil.formatFileSize(fileSize); // 格式化文件大小
Map map = new HashMap<>();
map.put("name", fileName);
map.put("size", formattedSize);

if ((fileName.startsWith("run") || fileName.startsWith("checkpoint")) && fileSize == 0) {
map.put("isDirectory", true);
map.put("children", listRayFilesInDirectory(bucketName, fullPath));
} else {
map.put("isFile", true);
}
map.put("url", bucketName + "/" + fullPath);
fileInfoList.add(map);
}

return fileInfoList;
}

/**
* 删除文件
*
* @param bucketName bucket名称
* @param objectName 文件名称
*/
public static void removeObject(String bucketName, String objectName) throws Exception {
minioClient.removeObject(RemoveObjectArgs.builder().bucket(bucketName).object(objectName).build());
}


/**
* 批量删除文件
*
* @param bucketName bucket
* @param keys 需要删除的文件列表
*/
public static void removeObjects(String bucketName, List<String> keys) {
List<DeleteObject> objects = new LinkedList<>();
keys.forEach(s -> {
objects.add(new DeleteObject(s));
try {
removeObject(bucketName, s);
} catch (Exception e) {
System.err.println("批量删除失败!");
}
});
}


public String readObjectAsString(String bucketName, String objectName) throws Exception {
try (InputStream inputStream = minioClient.getObject(
GetObjectArgs.builder()
.bucket(bucketName)
.object(objectName)
.build())) {
byte[] buffer = new byte[1024];
int bytesRead;
StringBuilder content = new StringBuilder();

while ((bytesRead = inputStream.read(buffer)) != -1) {
content.append(new String(buffer, 0, bytesRead, StandardCharsets.UTF_8));
}

return content.toString();
}
}

/**
* Downloads files and folders from the specified bucket and path, and creates a zip archive.
*
* @param bucketName The name of the bucket.
* @param path The path within the bucket.
* @return InputStream containing the zip archive.
* @throws MinioException If an error occurs while communicating with Minio.
* @throws IOException If an I/O error occurs during zip creation.
*/
public InputStream downloadAndZip(String bucketName, String path) throws Exception {
try (ByteArrayOutputStream zipOutputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(zipOutputStream)) {

Iterable<Result<Item>> results = minioClient.listObjects(
ListObjectsArgs.builder().bucket(bucketName).prefix(path).recursive(true).build());

for (Result<Item> result : results) {
Item item = result.get();
String objectName = item.objectName();
if (!objectName.contains(".git")) {
InputStream objectStream = minioClient.getObject(
GetObjectArgs.builder().bucket(bucketName).object(objectName).build());


// Create a zip entry for each object
ZipEntry zipEntry = new ZipEntry(objectName);
zip.putNextEntry(zipEntry);

// Write object data to zip stream
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = objectStream.read(buffer)) != -1) {
zip.write(buffer, 0, bytesRead);
}
zip.closeEntry();
objectStream.close();
}
}

zip.finish();
return new ByteArrayInputStream(zipOutputStream.toByteArray());
}
}
}

+ 8
- 0
ruoyi-modules/knowledge-graph/src/main/resources/banner.txt View File

@@ -0,0 +1,8 @@
Spring Boot Version: ${spring-boot.version}
Spring Application Name: ${spring.application.name}
__ _ _ _ __ _ _ __
_ __ __ _ _ _ __ _ / _` | ___ _ __ ___ _ _ | |_ ___ | '_ \ | | __ _ | |_ / _| ___ _ _ _ __
| ' \ / _` | | ' \ / _` | \__, | / -_) | ' \ / -_) | ' \ | _| |___| | .__/ | | / _` | | _| | _| / _ \ | '_| | ' \
|_|_|_| \__,_| |_||_| \__,_| |___/ \___| |_|_|_| \___| |_||_| _\__| _____ |_|__ _|_|_ \__,_| _\__| _|_|_ \___/ _|_|_ |_|_|_|
_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_| |_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|
"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'

+ 27
- 0
ruoyi-modules/knowledge-graph/src/main/resources/bootstrap-prod.yml View File

@@ -0,0 +1,27 @@
# Tomcat
server:
port: 9216

# Spring
spring:
application:
# 应用名称
name: knowledge-graph
config:
activate:
# 环境配置
on-profile:
prod
cloud:
nacos:
discovery:
# 服务注册地址
server-addr: ${nacos_ip}:${nacos_port}
config:
# 配置中心地址
server-addr: ${nacos_ip}:${nacos_port}
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

+ 38
- 0
ruoyi-modules/knowledge-graph/src/main/resources/bootstrap.yml View File

@@ -0,0 +1,38 @@
# Tomcat
server:
port: 9216

# Spring
spring:
application:
# 应用名称
name: knowledge-graph
profiles:
# 环境配置
active: dev
cloud:
nacos:
discovery:
# 服务注册地址
namespace: ${NACOS_NAMESPACE:public}
server-addr: ${NACOS_ADDR:127.0.0.1:8848}
username: nacos
password: ${NACOS_PWD:h1n2x3j4y5@}
retry:
enabled: true
config:
namespace: ${NACOS_NAMESPACE:public}
username: nacos
password: ${NACOS_PWD:h1n2x3j4y5@}
# 配置中心地址
server-addr: ${NACOS_ADDR:127.0.0.1:8848}
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- data-id: application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
group: DEFAULT_GROUP
refresh: true
- data-id: knowledge-graph-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
group: DEFAULT_GROUP
refresh: true

+ 13
- 0
ruoyi-modules/knowledge-graph/src/main/resources/k8sconfig/clusterrolebinding.yaml View File

@@ -0,0 +1,13 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: admin-service-account-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-service-account
namespace: default


+ 93
- 0
ruoyi-modules/knowledge-graph/src/main/resources/logback.xml View File

@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- 日志存放路径 -->
<property name="log.path" value="logs/knowledge-graph" />
<!-- 日志输出格式 -->
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />

<!-- 控制台输出 -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
</appender>

<!-- 系统日志输出 -->
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/sys-info.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/sys-info.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>INFO</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>

<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/sys-error.log</file>
<!-- 循环政策:基于时间创建日志文件 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 日志文件名格式 -->
<fileNamePattern>${log.path}/sys-error.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!-- 过滤的级别 -->
<level>ERROR</level>
<!-- 匹配时的操作:接收(记录) -->
<onMatch>ACCEPT</onMatch>
<!-- 不匹配时的操作:拒绝(不记录) -->
<onMismatch>DENY</onMismatch>
</filter>
</appender>

<!-- 用户访问日志输出 -->
<appender name="sys-user" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/sys-user.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 按天回滚 daily -->
<fileNamePattern>${log.path}/sys-user.%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 日志最大的历史 60天 -->
<maxHistory>60</maxHistory>
</rollingPolicy>
<encoder>
<pattern>${log.pattern}</pattern>
</encoder>
</appender>

<!-- 系统模块日志级别控制 -->
<logger name="com.ruoyi" level="info" />
<!-- Spring日志级别控制 -->
<logger name="org.springframework" level="warn" />

<root level="info">
<appender-ref ref="console" />
</root>

<!--系统操作日志-->
<root level="info">
<appender-ref ref="file_info" />
<appender-ref ref="file_error" />
</root>

<!--系统用户操作日志-->
<logger name="sys-user" level="info">
<appender-ref ref="sys-user"/>
</logger>
</configuration>

+ 201
- 0
ruoyi-modules/knowledge-graph/src/main/resources/mapper/KgEntityInfoMapper.xml View File

@@ -0,0 +1,201 @@
<?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.ruoyi.kg.mapper.KgEntityInfoMapper">
<resultMap id="BaseResultMap" type="com.ruoyi.kg.domain.KgEntityInfo">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="description" jdbcType="VARCHAR" property="description" />
<result column="bk_color" jdbcType="VARCHAR" property="bkColor" />
<result column="display_x" jdbcType="INTEGER" property="displayX" />
<result column="display_y" jdbcType="INTEGER" property="displayY" />
<result column="icon" jdbcType="VARCHAR" property="icon" />
<result column="ontology_id" jdbcType="INTEGER" property="ontologyId" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="del_flag" jdbcType="CHAR" property="delFlag" />
<result column="create_by" jdbcType="VARCHAR" property="createBy" />
<result column="update_by" jdbcType="VARCHAR" property="updateBy" />
</resultMap>
<sql id="Base_Column_List">
id, `name`, description, bk_color, display_x, display_y, icon, ontology_id, create_time,
update_time, del_flag, create_by, update_by
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from kg_entity_info
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from kg_entity_info
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.ruoyi.kg.domain.KgEntityInfo" useGeneratedKeys="true">
insert into kg_entity_info (`name`, description, bk_color,
display_x, display_y, icon,
ontology_id, create_time, update_time,
del_flag, create_by, update_by
)
values (#{name,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, #{bkColor,jdbcType=VARCHAR},
#{displayX,jdbcType=INTEGER}, #{displayY,jdbcType=INTEGER}, #{icon,jdbcType=VARCHAR},
#{ontologyId,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP},
#{delFlag,jdbcType=CHAR}, #{createBy,jdbcType=VARCHAR}, #{updateBy,jdbcType=VARCHAR}
)
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.ruoyi.kg.domain.KgEntityInfo" useGeneratedKeys="true">
insert into kg_entity_info
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="name != null">
`name`,
</if>
<if test="description != null">
description,
</if>
<if test="bkColor != null">
bk_color,
</if>
<if test="displayX != null">
display_x,
</if>
<if test="displayY != null">
display_y,
</if>
<if test="icon != null">
icon,
</if>
<if test="ontologyId != null">
ontology_id,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="delFlag != null">
del_flag,
</if>
<if test="createBy != null">
create_by,
</if>
<if test="updateBy != null">
update_by,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="description != null">
#{description,jdbcType=VARCHAR},
</if>
<if test="bkColor != null">
#{bkColor,jdbcType=VARCHAR},
</if>
<if test="displayX != null">
#{displayX,jdbcType=INTEGER},
</if>
<if test="displayY != null">
#{displayY,jdbcType=INTEGER},
</if>
<if test="icon != null">
#{icon,jdbcType=VARCHAR},
</if>
<if test="ontologyId != null">
#{ontologyId,jdbcType=INTEGER},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="delFlag != null">
#{delFlag,jdbcType=CHAR},
</if>
<if test="createBy != null">
#{createBy,jdbcType=VARCHAR},
</if>
<if test="updateBy != null">
#{updateBy,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.ruoyi.kg.domain.KgEntityInfo">
update kg_entity_info
<set>
<if test="name != null">
`name` = #{name,jdbcType=VARCHAR},
</if>
<if test="description != null">
description = #{description,jdbcType=VARCHAR},
</if>
<if test="bkColor != null">
bk_color = #{bkColor,jdbcType=VARCHAR},
</if>
<if test="displayX != null">
display_x = #{displayX,jdbcType=INTEGER},
</if>
<if test="displayY != null">
display_y = #{displayY,jdbcType=INTEGER},
</if>
<if test="icon != null">
icon = #{icon,jdbcType=VARCHAR},
</if>
<if test="ontologyId != null">
ontology_id = #{ontologyId,jdbcType=INTEGER},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="delFlag != null">
del_flag = #{delFlag,jdbcType=CHAR},
</if>
<if test="createBy != null">
create_by = #{createBy,jdbcType=VARCHAR},
</if>
<if test="updateBy != null">
update_by = #{updateBy,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.ruoyi.kg.domain.KgEntityInfo">
update kg_entity_info
set `name` = #{name,jdbcType=VARCHAR},
description = #{description,jdbcType=VARCHAR},
bk_color = #{bkColor,jdbcType=VARCHAR},
display_x = #{displayX,jdbcType=INTEGER},
display_y = #{displayY,jdbcType=INTEGER},
icon = #{icon,jdbcType=VARCHAR},
ontology_id = #{ontologyId,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP},
del_flag = #{delFlag,jdbcType=CHAR},
create_by = #{createBy,jdbcType=VARCHAR},
update_by = #{updateBy,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>

<select id="selectList" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from kg_entity_info
where
<if test="name != null and name != ''">
`name` = #{name}
</if>
order by update_time desc
</select>

<select id="selectListByOntologyId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from kg_entity_info
where
ontology_id = #{ontologyId}
</select>
</mapper>

+ 171
- 0
ruoyi-modules/knowledge-graph/src/main/resources/mapper/KgEntityPropertiesMapper.xml View File

@@ -0,0 +1,171 @@
<?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.ruoyi.kg.mapper.KgEntityPropertiesMapper">
<resultMap id="BaseResultMap" type="com.ruoyi.kg.domain.KgEntityProperty">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="type" jdbcType="VARCHAR" property="type" />
<result column="entity_id" jdbcType="INTEGER" property="entityId" />
<result column="is_multivalued" jdbcType="BOOLEAN" property="isMultivalued" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="del_flag" jdbcType="CHAR" property="delFlag" />
<result column="create_by" jdbcType="VARCHAR" property="createBy" />
<result column="update_by" jdbcType="VARCHAR" property="updateBy" />
</resultMap>
<sql id="Base_Column_List">
id, `name`, `type`, entity_id, is_multivalued, create_time, update_time, del_flag,
create_by, update_by
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from kg_entity_properties
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from kg_entity_properties
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.ruoyi.kg.domain.KgEntityProperty" useGeneratedKeys="true">
insert into kg_entity_properties (`name`, `type`, entity_id,
is_multivalued, create_time, update_time,
del_flag, create_by, update_by
)
values (#{name,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR}, #{entityId,jdbcType=INTEGER},
#{isMultivalued,jdbcType=BOOLEAN}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP},
#{delFlag,jdbcType=CHAR}, #{createBy,jdbcType=VARCHAR}, #{updateBy,jdbcType=VARCHAR}
)
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.ruoyi.kg.domain.KgEntityProperty" useGeneratedKeys="true">
insert into kg_entity_properties
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="name != null">
`name`,
</if>
<if test="type != null">
`type`,
</if>
<if test="entityId != null">
entity_id,
</if>
<if test="isMultivalued != null">
is_multivalued,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="delFlag != null">
del_flag,
</if>
<if test="createBy != null">
create_by,
</if>
<if test="updateBy != null">
update_by,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="type != null">
#{type,jdbcType=VARCHAR},
</if>
<if test="entityId != null">
#{entityId,jdbcType=INTEGER},
</if>
<if test="isMultivalued != null">
#{isMultivalued,jdbcType=BOOLEAN},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="delFlag != null">
#{delFlag,jdbcType=CHAR},
</if>
<if test="createBy != null">
#{createBy,jdbcType=VARCHAR},
</if>
<if test="updateBy != null">
#{updateBy,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.ruoyi.kg.domain.KgEntityProperty">
update kg_entity_properties
<set>
<if test="name != null">
`name` = #{name,jdbcType=VARCHAR},
</if>
<if test="type != null">
`type` = #{type,jdbcType=VARCHAR},
</if>
<if test="entityId != null">
entity_id = #{entityId,jdbcType=INTEGER},
</if>
<if test="isMultivalued != null">
is_multivalued = #{isMultivalued,jdbcType=BOOLEAN},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="delFlag != null">
del_flag = #{delFlag,jdbcType=CHAR},
</if>
<if test="createBy != null">
create_by = #{createBy,jdbcType=VARCHAR},
</if>
<if test="updateBy != null">
update_by = #{updateBy,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.ruoyi.kg.domain.KgEntityProperty">
update kg_entity_properties
set `name` = #{name,jdbcType=VARCHAR},
`type` = #{type,jdbcType=VARCHAR},
entity_id = #{entityId,jdbcType=INTEGER},
is_multivalued = #{isMultivalued,jdbcType=BOOLEAN},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP},
del_flag = #{delFlag,jdbcType=CHAR},
create_by = #{createBy,jdbcType=VARCHAR},
update_by = #{updateBy,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>

<select id="selectList" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from kg_entity_properties
where
<if test="name != null and name != ''">
`name` = #{name}
</if>
<if test="name != null and name != ''">
and entity_id = #{entityId}
</if>
order by update_time desc
</select>

<select id="selectListByEntityIds" parameterType="list" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from kg_entity_properties
where entity_id in
<foreach collection="list" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</select>
</mapper>

+ 182
- 0
ruoyi-modules/knowledge-graph/src/main/resources/mapper/KgEntityRelationsMapper.xml View File

@@ -0,0 +1,182 @@
<?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.ruoyi.kg.mapper.KgEntityRelationsMapper">
<resultMap id="BaseResultMap" type="com.ruoyi.kg.domain.KgEntityRelation">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="target" jdbcType="VARCHAR" property="target" />
<result column="target_id" jdbcType="INTEGER" property="targetId" />
<result column="source_id" jdbcType="INTEGER" property="sourceId" />
<result column="entity_id" jdbcType="INTEGER" property="entityId" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="del_flag" jdbcType="CHAR" property="delFlag" />
<result column="create_by" jdbcType="VARCHAR" property="createBy" />
<result column="update_by" jdbcType="VARCHAR" property="updateBy" />
</resultMap>
<sql id="Base_Column_List">
id, `name`, target, target_id, source_id, entity_id, create_time, update_time, del_flag, create_by,
update_by
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from kg_entity_relations
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from kg_entity_relations
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.ruoyi.kg.domain.KgEntityRelation" useGeneratedKeys="true">
insert into kg_entity_relations (`name`, target, target_id,
source_id,entity_id, create_time, update_time,
del_flag, create_by, update_by
)
values (#{name,jdbcType=VARCHAR}, #{target,jdbcType=VARCHAR}, #{targetId,jdbcType=INTEGER},
#{sourceId,jdbcType=INTEGER},#{entityId,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP},
#{delFlag,jdbcType=CHAR}, #{createBy,jdbcType=VARCHAR}, #{updateBy,jdbcType=VARCHAR}
)
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.ruoyi.kg.domain.KgEntityRelation" useGeneratedKeys="true">
insert into kg_entity_relations
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="name != null">
`name`,
</if>
<if test="target != null">
target,
</if>
<if test="targetId != null">
target_id,
</if>
<if test="sourceId != null">
source_id,
</if>
<if test="entityId != null">
entity_id,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="delFlag != null">
del_flag,
</if>
<if test="createBy != null">
create_by,
</if>
<if test="updateBy != null">
update_by,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="target != null">
#{target,jdbcType=VARCHAR},
</if>
<if test="targetId != null">
#{targetId,jdbcType=INTEGER},
</if>
<if test="sourceId != null">
#{sourceId,jdbcType=INTEGER},
</if>
<if test="entityId != null">
#{entityId,jdbcType=INTEGER},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="delFlag != null">
#{delFlag,jdbcType=CHAR},
</if>
<if test="createBy != null">
#{createBy,jdbcType=VARCHAR},
</if>
<if test="updateBy != null">
#{updateBy,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.ruoyi.kg.domain.KgEntityRelation">
update kg_entity_relations
<set>
<if test="name != null">
`name` = #{name,jdbcType=VARCHAR},
</if>
<if test="target != null">
target = #{target,jdbcType=VARCHAR},
</if>
<if test="targetId != null">
target_id = #{targetId,jdbcType=INTEGER},
</if>
<if test="sourceId != null">
source_id = #{sourceId,jdbcType=INTEGER},
</if>
<if test="entityId != null">
entity_id = #{entityId,jdbcType=INTEGER},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="delFlag != null">
del_flag = #{delFlag,jdbcType=CHAR},
</if>
<if test="createBy != null">
create_by = #{createBy,jdbcType=VARCHAR},
</if>
<if test="updateBy != null">
update_by = #{updateBy,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.ruoyi.kg.domain.KgEntityRelation">
update kg_entity_relations
set `name` = #{name,jdbcType=VARCHAR},
target = #{target,jdbcType=VARCHAR},
target_id = #{targetId,jdbcType=INTEGER},
source_id = #{sourceId,jdbcType=INTEGER},
entity_id = #{entityId,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP},
del_flag = #{delFlag,jdbcType=CHAR},
create_by = #{createBy,jdbcType=VARCHAR},
update_by = #{updateBy,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>

<select id="selectList" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from kg_entity_relations
where
<if test="name != null and name != ''">
`name` = #{name}
</if>
<if test="name != null and name != ''">
and entity_id = #{entityId}
</if>
order by update_time desc
</select>

<select id="selectListByEntityIds" parameterType="list" resultType="com.ruoyi.kg.domain.dto.KgEntityRelationDTO">
select
<include refid="Base_Column_List" />
from kg_entity_relations
where entity_id IN
<foreach item="id" index="index" collection="list" open="(" separator="," close=")">
#{id}
</foreach>
</select>
</mapper>

+ 188
- 0
ruoyi-modules/knowledge-graph/src/main/resources/mapper/KgInfoMapper.xml View File

@@ -0,0 +1,188 @@
<?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.ruoyi.kg.mapper.KgInfoMapper">
<resultMap id="BaseResultMap" type="com.ruoyi.kg.domain.KgInfo">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="version" jdbcType="VARCHAR" property="version" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="ontology_id" jdbcType="BIGINT" property="ontologyId" />
<result column="db_name" jdbcType="VARCHAR" property="dbName" />
<result column="status" jdbcType="CHAR" property="status" />
<result column="create_by" jdbcType="VARCHAR" property="createBy" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_by" jdbcType="VARCHAR" property="updateBy" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="remark" jdbcType="VARCHAR" property="remark" />
<result column="spec" jdbcType="VARCHAR" property="spec" />
<result column="del_flag" jdbcType="CHAR" property="delFlag" />
</resultMap>

<sql id="Base_Column_List">
id, version, `name`, ontology_id, db_name, `status`, create_by, create_time, update_by,
update_time, remark, spec,del_flag
</sql>

<select id="selectByPrimaryKey" parameterType="com.ruoyi.kg.domain.dto.KgInfoIdDTO" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from kg_info
where id = #{id,jdbcType=BIGINT}
</select>

<select id="selectALl" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from kg_info
order by update_time desc
</select>

<select id="queryInfoByPrimaryKey" parameterType="com.ruoyi.kg.domain.dto.KgInfoIdDTO" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from kg_info
where id = #{id,jdbcType=BIGINT} and version=#{version,jdbcType=VARCHAR}
</select>

<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from kg_info
where id = #{id,jdbcType=BIGINT}
</delete>

<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.ruoyi.kg.domain.KgInfo" useGeneratedKeys="true">
insert into kg_info (version, `name`, ontology_id,
db_name, `status`, create_by,
create_time, update_by, update_time,
remark, del_flag)
values (#{version,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{ontologyId,jdbcType=BIGINT},
#{dbName,jdbcType=VARCHAR}, #{status,jdbcType=CHAR}, #{createBy,jdbcType=VARCHAR},
#{createTime,jdbcType=TIMESTAMP}, #{updateBy,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP},
#{remark,jdbcType=VARCHAR}, #{delFlag,jdbcType=CHAR})
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.ruoyi.kg.domain.KgInfo" useGeneratedKeys="true">
insert into kg_info
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="version != null">
version,
</if>
<if test="name != null">
`name`,
</if>
<if test="ontologyId != null">
ontology_id,
</if>
<if test="dbName != null">
db_name,
</if>
<if test="status != null">
`status`,
</if>
<if test="createBy != null">
create_by,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateBy != null">
update_by,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="remark != null">
remark,
</if>
<if test="delFlag != null">
del_flag,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="version != null">
#{version,jdbcType=VARCHAR},
</if>
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="ontologyId != null">
#{ontologyId,jdbcType=BIGINT},
</if>
<if test="dbName != null">
#{dbName,jdbcType=VARCHAR},
</if>
<if test="status != null">
#{status,jdbcType=CHAR},
</if>
<if test="createBy != null">
#{createBy,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateBy != null">
#{updateBy,jdbcType=VARCHAR},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="remark != null">
#{remark,jdbcType=VARCHAR},
</if>
<if test="delFlag != null">
#{delFlag,jdbcType=CHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.ruoyi.kg.domain.KgInfo">
update kg_info
<set>
<if test="version != null">
version = #{version,jdbcType=VARCHAR},
</if>
<if test="name != null">
`name` = #{name,jdbcType=VARCHAR},
</if>
<if test="ontologyId != null">
ontology_id = #{ontologyId,jdbcType=BIGINT},
</if>
<if test="dbName != null">
db_name = #{dbName,jdbcType=VARCHAR},
</if>
<if test="status != null">
`status` = #{status,jdbcType=CHAR},
</if>
<if test="createBy != null">
create_by = #{createBy,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateBy != null">
update_by = #{updateBy,jdbcType=VARCHAR},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="remark != null">
remark = #{remark,jdbcType=VARCHAR},
</if>
<if test="delFlag != null">
del_flag = #{delFlag,jdbcType=CHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.ruoyi.kg.domain.KgInfo">
update kg_info
set version = #{version,jdbcType=VARCHAR},
`name` = #{name,jdbcType=VARCHAR},
ontology_id = #{ontologyId,jdbcType=BIGINT},
db_name = #{dbName,jdbcType=VARCHAR},
`status` = #{status,jdbcType=CHAR},
create_by = #{createBy,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_by = #{updateBy,jdbcType=VARCHAR},
update_time = #{updateTime,jdbcType=TIMESTAMP},
remark = #{remark,jdbcType=VARCHAR},
del_flag = #{delFlag,jdbcType=CHAR}
where id = #{id,jdbcType=BIGINT}
</update>
</mapper>

+ 178
- 0
ruoyi-modules/knowledge-graph/src/main/resources/mapper/KgOntologyInfoMapper.xml View File

@@ -0,0 +1,178 @@
<?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.ruoyi.kg.mapper.KgOntologyInfoMapper">
<resultMap id="BaseResultMap" type="com.ruoyi.kg.domain.KgOntologyInfo">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="description" jdbcType="VARCHAR" property="description" />
<result column="concepts_count" jdbcType="INTEGER" property="conceptsCount" />
<result column="relations_count" jdbcType="INTEGER" property="relationsCount" />
<result column="dag" jdbcType="VARCHAR" property="dag" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
<result column="create_by" jdbcType="VARCHAR" property="createBy" />
<result column="update_by" jdbcType="VARCHAR" property="updateBy" />
<result column="del_flag" jdbcType="BOOLEAN" property="delFlag" />
</resultMap>
<sql id="Base_Column_List">
id, `name`, description, concepts_count, relations_count,dag, create_time, update_time,
create_by, update_by, del_flag
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultType="com.ruoyi.kg.domain.dto.KgOntologyUpdateDTO">
select
<include refid="Base_Column_List" />
from kg_ontology_info
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from kg_ontology_info
where id = #{id,jdbcType=INTEGER}
</delete>
<delete id="deleteByIds" parameterType="java.lang.Long">
delete from kg_ontology_info
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.ruoyi.kg.domain.KgOntologyInfo" useGeneratedKeys="true">
insert into kg_ontology_info (`name`, description, concepts_count,
relations_count,dag, create_time, update_time,
create_by, update_by, del_flag
)
values (#{name,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, #{conceptsCount,jdbcType=INTEGER},
#{relationsCount,jdbcType=INTEGER},#{dag,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP},
#{createBy,jdbcType=VARCHAR}, #{updateBy,jdbcType=VARCHAR}, #{delFlag,jdbcType=BOOLEAN}
)
</insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.ruoyi.kg.domain.KgOntologyInfo" useGeneratedKeys="true">
insert into kg_ontology_info
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="name != null">
`name`,
</if>
<if test="description != null">
description,
</if>
<if test="conceptsCount != null">
concepts_count,
</if>
<if test="relationsCount != null">
relations_count,
</if>
<if test="dag != null">
dag,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
<if test="createBy != null">
create_by,
</if>
<if test="updateBy != null">
update_by,
</if>
<if test="delFlag != null">
del_flag,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="description != null">
#{description,jdbcType=VARCHAR},
</if>
<if test="conceptsCount != null">
#{conceptsCount,jdbcType=INTEGER},
</if>
<if test="relationsCount != null">
#{relationsCount,jdbcType=INTEGER},
</if>
<if test="dag != null">
#{dag,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="createBy != null">
#{createBy,jdbcType=VARCHAR},
</if>
<if test="updateBy != null">
#{updateBy,jdbcType=VARCHAR},
</if>
<if test="delFlag != null">
#{delFlag,jdbcType=BOOLEAN},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.ruoyi.kg.domain.KgOntologyInfo">
update kg_ontology_info
<set>
<if test="name != null">
`name` = #{name,jdbcType=VARCHAR},
</if>
<if test="description != null">
description = #{description,jdbcType=VARCHAR},
</if>
<if test="conceptsCount != null">
concepts_count = #{conceptsCount,jdbcType=INTEGER},
</if>
<if test="relationsCount != null">
relations_count = #{relationsCount,jdbcType=INTEGER},
</if>
<if test="dag != null">
dag = #{dag,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=TIMESTAMP},
</if>
<if test="createBy != null">
create_by = #{createBy,jdbcType=VARCHAR},
</if>
<if test="updateBy != null">
update_by = #{updateBy,jdbcType=VARCHAR},
</if>
<if test="delFlag != null">
del_flag = #{delFlag,jdbcType=BOOLEAN},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.ruoyi.kg.domain.KgOntologyInfo">
update kg_ontology_info
set `name` = #{name,jdbcType=VARCHAR},
description = #{description,jdbcType=VARCHAR},
concepts_count = #{conceptsCount,jdbcType=INTEGER},
relations_count = #{relationsCount,jdbcType=INTEGER},
dag = #{dag,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = #{updateTime,jdbcType=TIMESTAMP},
create_by = #{createBy,jdbcType=VARCHAR},
update_by = #{updateBy,jdbcType=VARCHAR},
del_flag = #{delFlag,jdbcType=BOOLEAN}
where id = #{id,jdbcType=INTEGER}
</update>

<select id="selectList" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from kg_ontology_info
<!-- where-->
<!-- <if test="name != null and name != ''">-->
<!-- `name` = #{name}-->
<!-- </if>-->
<!-- order by update_time desc-->
</select>
<select id="getNameAndIds" resultType="com.ruoyi.kg.domain.dto.KgOntologyNameAndIdDTO">
select
id,name
from kg_ontology_info
</select>
</mapper>

+ 162
- 0
ruoyi-modules/knowledge-graph/src/main/resources/mapper/KnowledgeGraphDao.xml View File

@@ -0,0 +1,162 @@
<?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.ruoyi.kg.mapper.KnowledgeGraphDao">

<resultMap type="com.ruoyi.kg.domain.KnowledgeGraph" id="KnowledgeGraphMap">
<result property="id" column="id" jdbcType="INTEGER"/>
<result property="kgName" column="kg_name" jdbcType="VARCHAR"/>
<result property="kgDesc" column="kg_desc" jdbcType="VARCHAR"/>
<result property="kgNoumenon" column="kg_noumenon" jdbcType="INTEGER"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="createBy" column="create_by" jdbcType="VARCHAR"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
<result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
<result property="state" column="state" jdbcType="INTEGER"/>
</resultMap>

<!--查询单个-->
<select id="queryById" resultMap="KnowledgeGraphMap">
select id,kg_name,kg_desc,kg_noumenon,create_time,create_by,update_time,update_by,state
from knowledge_graph
where id = #{id}
</select>

<!--查询指定行数据-->
<select id="queryAllByLimit" resultMap="KnowledgeGraphMap">
select
idkg_namekg_desckg_noumenoncreate_timecreate_byupdate_timeupdate_bystate
from knowledge_graph
<where>
<if test="id != null">
and id = #{id}
</if>
<if test="kgName != null and kgName != ''">
and kg_name = #{kgName}
</if>
<if test="kgDesc != null and kgDesc != ''">
and kg_desc = #{kgDesc}
</if>
<if test="kgNoumenon != null">
and kg_noumenon = #{kgNoumenon}
</if>
<if test="createTime != null">
and create_time = #{createTime}
</if>
<if test="createBy != null and createBy != ''">
and create_by = #{createBy}
</if>
<if test="updateTime != null">
and update_time = #{updateTime}
</if>
<if test="updateBy != null and updateBy != ''">
and update_by = #{updateBy}
</if>
<if test="state != null">
and state = #{state}
</if>
</where>
limit #{pageable.offset}, #{pageable.pageSize}
</select>

<!--统计总行数-->
<select id="count" resultType="java.lang.Long">
select count(1)
from knowledge_graph
<where>
<if test="id != null">
and id = #{id}
</if>
<if test="kgName != null and kgName != ''">
and kg_name = #{kgName}
</if>
<if test="kgDesc != null and kgDesc != ''">
and kg_desc = #{kgDesc}
</if>
<if test="kgNoumenon != null">
and kg_noumenon = #{kgNoumenon}
</if>
<if test="createTime != null">
and create_time = #{createTime}
</if>
<if test="createBy != null and createBy != ''">
and create_by = #{createBy}
</if>
<if test="updateTime != null">
and update_time = #{updateTime}
</if>
<if test="updateBy != null and updateBy != ''">
and update_by = #{updateBy}
</if>
<if test="state != null">
and state = #{state}
</if>
</where>
</select>

<!--新增所有列-->
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
insert into knowledge_graph(kg_namekg_desckg_noumenoncreate_timecreate_byupdate_timeupdate_bystate)
values (#{kgName}#{kgDesc}#{kgNoumenon}#{createTime}#{createBy}#{updateTime}#{updateBy}#{state})
</insert>

<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
insert into knowledge_graph(kg_namekg_desckg_noumenoncreate_timecreate_byupdate_timeupdate_bystate)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.kgName}#{entity.kgDesc}#{entity.kgNoumenon}#{entity.createTime}#{entity.createBy}#{entity.updateTime}#{entity.updateBy}#{entity.state})
</foreach>
</insert>

<insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
insert into knowledge_graph(kg_namekg_desckg_noumenoncreate_timecreate_byupdate_timeupdate_bystate)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.kgName}#{entity.kgDesc}#{entity.kgNoumenon}#{entity.createTime}#{entity.createBy}#{entity.updateTime}#{entity.updateBy}#{entity.state})
</foreach>
on duplicate key update
kg_name = values(kg_name)kg_desc = values(kg_desc)kg_noumenon = values(kg_noumenon)create_time =
values(create_time)create_by = values(create_by)update_time = values(update_time)update_by =
values(update_by)state = values(state)
</insert>

<!--通过主键修改数据-->
<update id="update">
update knowledge_graph
<set>
<if test="kgName != null and kgName != ''">
kg_name = #{kgName},
</if>
<if test="kgDesc != null and kgDesc != ''">
kg_desc = #{kgDesc},
</if>
<if test="kgNoumenon != null">
kg_noumenon = #{kgNoumenon},
</if>
<if test="createTime != null">
create_time = #{createTime},
</if>
<if test="createBy != null and createBy != ''">
create_by = #{createBy},
</if>
<if test="updateTime != null">
update_time = #{updateTime},
</if>
<if test="updateBy != null and updateBy != ''">
update_by = #{updateBy},
</if>
<if test="state != null">
state = #{state},
</if>
</set>
where id = #{id}
</update>

<!--通过主键删除-->
<delete id="deleteById">
delete
from knowledge_graph
where id = #{id}
</delete>

</mapper>


+ 227
- 0
ruoyi-modules/knowledge-graph/src/main/resources/mapper/KnowledgeGraphVersionDao.xml View File

@@ -0,0 +1,227 @@
<?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.ruoyi.kg.mapper.KnowledgeGraphVersionDao">

<resultMap type="com.ruoyi.kg.domain.KnowledgeGraphVersion" id="KnowledgeGraphVersionMap">
<result property="id" column="id" jdbcType="INTEGER"/>
<result property="name" column="name" jdbcType="VARCHAR"/>
<result property="version" column="version" jdbcType="INTEGER"/>
<result property="transactionId" column="transaction_id" jdbcType="VARCHAR"/>
<result property="content" column="content" jdbcType="VARCHAR"/>
<result property="kgId" column="kg_id" jdbcType="VARCHAR"/>
<result property="status" column="status" jdbcType="INTEGER"/>
<result property="updateMethod" column="update_method" jdbcType="INTEGER"/>
<result property="conceptsCount" column="concepts_count" jdbcType="INTEGER"/>
<result property="relationsCount" column="relations_count" jdbcType="INTEGER"/>
<result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
<result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
<result property="createBy" column="create_by" jdbcType="VARCHAR"/>
<result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
<result property="state" column="state" jdbcType="INTEGER"/>
</resultMap>

<sql id="selectVersionVo">
select id,name,content,version,transaction_id,kg_id,status,update_method,concepts_count,relations_count,update_time,create_time,create_by,update_by,state
from knowledge_graph_version
</sql>

<!--查询单个-->
<select id="queryById" resultMap="KnowledgeGraphVersionMap">
<include refid="selectVersionVo"/>
where id = #{id}
</select>

<!--查询指定行数据-->
<select id="queryAllByLimit" resultMap="KnowledgeGraphVersionMap">
<include refid="selectVersionVo"/>
<where>
<if test="id != null">
and id = #{id}
</if>
<if test="version != null and version != ''">
and version = #{version}
</if>
<if test="transactionId != null and transactionId != ''">
and transaction_id = #{transactionId}
</if>
<if test="kgId != null">
and kg_id = #{kgId}
</if>
<if test="status != null and status != ''">
and status = #{status}
</if>
<if test="updateMethod != null">
and update_method = #{updateMethod}
</if>
<if test="conceptsCount != null">
and concepts_count = #{conceptsCount}
</if>
<if test="relationsCount != null">
and relations_count = #{relationsCount}
</if>
<if test="updateTime != null">
and update_time = #{updateTime}
</if>
<if test="createTime != null">
and create_time = #{createTime}
</if>
<if test="createBy != null and createBy != ''">
and create_by = #{createBy}
</if>
<if test="updateBy != null and updateBy != ''">
and update_by = #{updateBy}
</if>
<if test="state != null">
and state = #{state}
</if>
</where>
limit #{pageable.offset}, #{pageable.pageSize}
</select>
<select id="queryAll" resultMap="KnowledgeGraphVersionMap">
<include refid="selectVersionVo"/>
<where>
<if test="name != null">
and `name` = #{name}
</if>
<if test="status != null and status != ''">
and status = #{status}
</if>
<if test="id != null and id != ''">
and kg_id = #{id}
</if>
</where>
</select>

<!--统计总行数-->
<select id="count" resultType="java.lang.Long">
select count(1)
from knowledge_graph_version
<where>
<if test="id != null">
and id = #{id}
</if>
<if test="version != null and version != ''">
and version = #{version}
</if>
<if test="kgId != null">
and kg_id = #{kgId}
</if>
<if test="status != null and status != ''">
and status = #{status}
</if>
<if test="updateMethod != null">
and update_method = #{updateMethod}
</if>
<if test="conceptsCount != null">
and concepts_count = #{conceptsCount}
</if>
<if test="relationsCount != null">
and relations_count = #{relationsCount}
</if>
<if test="updateTime != null">
and update_time = #{updateTime}
</if>
<if test="createTime != null">
and create_time = #{createTime}
</if>
<if test="createBy != null and createBy != ''">
and create_by = #{createBy}
</if>
<if test="updateBy != null and updateBy != ''">
and update_by = #{updateBy}
</if>
<if test="state != null">
and state = #{state}
</if>
</where>
</select>

<!--新增所有列-->
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
insert into knowledge_graph_version(name,content,version,transaction_id,kg_id,status,update_method,concepts_count,relations_count,update_time,create_time,create_by,update_by,state)
values (#{name},#{content},#{version},#{transactionId},#{kgId},#{status},#{updateMethod},#{conceptsCount},#{relationsCount},#{updateTime},#{createTime},#{createBy},#{updateBy},#{state})
</insert>

<insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
insert into
knowledge_graph_version(name,content,version,transaction_id,kg_id,status,update_method,concepts_count,relations_count,update_time,create_time,create_by,update_by,state)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.name},#{entity.content},#{entity.version},#{entity.transactionId},#{entity.kgId},#{entity.status},#{entity.updateMethod},#{entity.conceptsCount},#{entity.relationsCount},#{entity.updateTime},#{entity.createTime},#{entity.createBy},#{entity.updateBy},#{entity.state})
</foreach>
</insert>

<insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
insert into
knowledge_graph_version(name,content,version,transaction_id,kg_id,status,update_method,concepts_count,relations_count,update_time,create_time,create_by,update_by,state)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.name},#{entity.version},#{entity.kgId},#{entity.status},#{entity.updateMethod},#{entity.entityNum},#{entity.updateTime},#{entity.createTime},#{entity.createBy},#{entity.updateBy},#{entity.state})
</foreach>
on duplicate key update
version = values(version)kg_id = values(kg_id)status = values(status)update_method =
values(update_method)entityNum = values(entityNum)update_time = values(update_time)create_time =
values(create_time)create_by = values(create_by)update_by = values(update_by)state = values(state)
</insert>

<!--通过主键修改数据-->
<update id="update">
update knowledge_graph_version
<set>
<if test="version != null">
version = #{version},
</if>
<if test="name != null and version != ''">
`name` = #{name},
</if>
<if test="kgId != null">
kg_id = #{kgId},
</if>
<if test="status != null">
status = #{status},
</if>
<if test="updateMethod != null">
update_method = #{updateMethod},
</if>
<if test="conceptsCount != null">
and concepts_count = #{conceptsCount}
</if>
<if test="relationsCount != null">
and relations_count = #{relationsCount}
</if>
<if test="updateTime != null">
update_time = #{updateTime},
</if>
<if test="createTime != null">
create_time = #{createTime},
</if>
<if test="createBy != null and createBy != ''">
create_by = #{createBy},
</if>
<if test="updateBy != null and updateBy != ''">
update_by = #{updateBy},
</if>
<if test="state != null">
`state` = #{state},
</if>
</set>
where id = #{id}
</update>

<!--通过主键删除-->
<delete id="deleteById">
delete
from knowledge_graph_version
where id = #{id}
</delete>

<select id="queryMaxVersion" resultType="java.lang.Integer">
select max(version) from knowledge_graph_version where kg_id=#{kgId};
</select>

<select id="onlineFind" resultMap="KnowledgeGraphVersionMap">
<include refid="selectVersionVo"/>
where status=1;
</select>
</mapper>


+ 29
- 1
ruoyi-modules/management-platform/pom.xml View File

@@ -178,7 +178,16 @@
<artifactId>client-java-api</artifactId>
<version>12.0.1</version>
</dependency>

<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>5.7.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.9.0</version>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
@@ -248,6 +257,25 @@
<artifactId>hutool-all</artifactId>
<version>5.8.5</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>
<dependency>
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>4.0.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>


+ 28
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/config/Neo4jConfig.java View File

@@ -0,0 +1,28 @@
package com.ruoyi.platform.config;

import org.neo4j.cypherdsl.core.renderer.Dialect;
import org.neo4j.driver.Driver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.core.Neo4jClient;
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;


@Configuration
//@EnableNeo4jRepositories("com.ruoyi.platform.service")
public class Neo4jConfig {

@Autowired
private Driver driver;

@Bean
public Neo4jClient neo4jClient() {
return Neo4jClient.create(driver);
}
@Bean
org.neo4j.cypherdsl.core.renderer.Configuration cypherDslConfiguration() {
return org.neo4j.cypherdsl.core.renderer.Configuration.newConfig()
.withDialect(Dialect.NEO4J_5).build();
}
}

+ 94
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/kg/KgEntityController.java View File

@@ -0,0 +1,94 @@
package com.ruoyi.platform.controller.kg;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.platform.domain.kg.KgEntityInfo;
import com.ruoyi.platform.service.KgEntityInfoService;
import com.ruoyi.system.api.domain.SysDictData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
* 知识图谱实体管理
*/
@RestController
@RequestMapping("/kg/entity")
public class KgEntityController extends BaseController {

@Autowired
private KgEntityInfoService kgEntityInfoService;

/**
* 新增实体
*
* @param entityInfo
* @return
*/
@PostMapping()
public R<String> createEntity(@Validated @RequestBody KgEntityInfo entityInfo) {
kgEntityInfoService.insertEntity(entityInfo);
return R.ok();
}

/**
* 修改实体
*
* @param entityInfo
* @return
*/
@PutMapping
public R<String> updateEntity(@Validated @RequestBody KgEntityInfo entityInfo) {
kgEntityInfoService.updateEntity(entityInfo);
return R.ok();
}

/**
* 实体列表
* @return
*/
@GetMapping("/list")
public TableDataInfo getEntities(@RequestBody KgEntityInfo entityInfo) {
startPage();
List<KgEntityInfo> ontologies = kgEntityInfoService.getEntities(entityInfo);
return getDataTable(ontologies);
}

/**
* 实体详情
* @param id
* @return
*/
@GetMapping("/{id}")
public R<KgEntityInfo> getEntity(@PathVariable Long id) {
return R.ok(kgEntityInfoService.getEntity(id));
}

/**
* 删除实体
* @param id
* @return
*/
@DeleteMapping("/{id}")
public R<String> deleteEntityById(@PathVariable Long id) {
kgEntityInfoService.deleteEntityById(id);
return R.ok();
}

/**
* 实体导出
* @param response
* @param id
*/
@GetMapping("/export/{id}")
public void export(HttpServletResponse response,@PathVariable Long id) {
KgEntityInfo Entity = kgEntityInfoService.getEntity(id);
ExcelUtil<SysDictData> util = new ExcelUtil<SysDictData>(SysDictData.class);
util.exportExcel(response, null, "实体数据");
}
}

+ 93
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/kg/KgEntityPropertiesController.java View File

@@ -0,0 +1,93 @@
package com.ruoyi.platform.controller.kg;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.platform.domain.kg.KgEntityProperty;
import com.ruoyi.platform.service.KgEntityPropertiesService;
import com.ruoyi.system.api.domain.SysDictData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 知识图谱实体属性管理
*/
@RestController
@RequestMapping("/kg/entityProperties")
public class KgEntityPropertiesController extends BaseController {

@Autowired
private KgEntityPropertiesService kgEntityPropertiesService;

/**
* 新增实体属性
*
* @param entityProperties
* @return
*/
@PostMapping()
public R<String> createEntityProperty(@Validated @RequestBody KgEntityProperty entityProperties) {
kgEntityPropertiesService.insertEntityProperties(entityProperties);
return R.ok();
}

/**
* 修改实体属性
*
* @param KgEntityProperty
* @return
*/
@PutMapping
public R<String> updateEntityProperty(@Validated @RequestBody KgEntityProperty KgEntityProperty) {
kgEntityPropertiesService.updateEntityProperties(KgEntityProperty);
return R.ok();
}

/**
* 实体属性列表
* @return
*/
@GetMapping("/list")
public TableDataInfo getEntityProperties(@RequestBody KgEntityProperty KgEntityProperty) {
startPage();
List<KgEntityProperty> ontologies = kgEntityPropertiesService.getEntityProperties(KgEntityProperty);
return getDataTable(ontologies);
}

/**
* 实体属性详情
* @param id
* @return
*/
@GetMapping("/{id}")
public R<KgEntityProperty> getEntityProperty(@PathVariable Long id) {
return R.ok(kgEntityPropertiesService.getEntityProperty(id));
}

/**
* 删除实体属性
* @param id
* @return
*/
@DeleteMapping("/{id}")
public R<String> deleteEntityPropertyById(@PathVariable Long id) {
kgEntityPropertiesService.deleteEntityPropertyById(id);
return R.ok();
}

/**
* 实体属性导出
* @param response
* @param id
*/
@GetMapping("/export/{id}")
public void export(HttpServletResponse response,@PathVariable Long id) {
KgEntityProperty EntityProperty = kgEntityPropertiesService.getEntityProperty(id);
ExcelUtil<SysDictData> util = new ExcelUtil<SysDictData>(SysDictData.class);
util.exportExcel(response, null, "实体属性数据");
}
}

+ 94
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/kg/KgEntityRelationsController.java View File

@@ -0,0 +1,94 @@
package com.ruoyi.platform.controller.kg;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.platform.domain.kg.KgEntityRelation;
import com.ruoyi.platform.service.KgEntityRelationsService;
import com.ruoyi.system.api.domain.SysDictData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
* 知识图谱实体关系管理
*/
@RestController
@RequestMapping("/kg/entityRelations")
public class KgEntityRelationsController extends BaseController {

@Autowired
private KgEntityRelationsService kgEntityRelationsService;

/**
* 新增实体关系
*
* @param entityRelations
* @return
*/
@PostMapping()
public R<String> createEntityRelations(@Validated @RequestBody KgEntityRelation entityRelations) {
kgEntityRelationsService.insertEntityRelation(entityRelations);
return R.ok();
}

/**
* 修改实体关系
*
* @param entityRelations
* @return
*/
@PutMapping
public R<String> updateEntityRelations(@Validated @RequestBody KgEntityRelation entityRelations) {
kgEntityRelationsService.updateEntityRelation(entityRelations);
return R.ok();
}

/**
* 实体关系列表
* @return
*/
@GetMapping("/list")
public TableDataInfo getEntityRelations(@RequestBody KgEntityRelation entityRelation) {
startPage();
List<KgEntityRelation> entityRelations = kgEntityRelationsService.getEntityRelations(entityRelation);
return getDataTable(entityRelations);
}

/**
* 实体关系详情
* @param id
* @return
*/
@GetMapping("/{id}")
public R<KgEntityRelation> getEntityRelations(@PathVariable Long id) {
return R.ok(kgEntityRelationsService.getEntityRelations(id));
}

/**
* 删除实体关系
* @param id
* @return
*/
@DeleteMapping("/{id}")
public R<String> deleteEntityRelationById(@PathVariable Long id) {
kgEntityRelationsService.deleteEntityRelationById(id);
return R.ok();
}

/**
* 实体关系导出
* @param response
* @param id
*/
@GetMapping("/export/{id}")
public void export(HttpServletResponse response,@PathVariable Long id) {
KgEntityRelation entityRelations = kgEntityRelationsService.getEntityRelations(id);
ExcelUtil<SysDictData> util = new ExcelUtil<SysDictData>(SysDictData.class);
util.exportExcel(response, null, "实体关系数据");
}
}

+ 90
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/kg/KgInfoController.java View File

@@ -0,0 +1,90 @@
package com.ruoyi.platform.controller.kg;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.platform.domain.kg.KgInfo;
import com.ruoyi.platform.domain.kg.KgInfoPageVo;
import com.ruoyi.platform.domain.kg.KnowledgeGraphVersion;
import com.ruoyi.platform.domain.kg.dto.KgInfoIdDTO;
import com.ruoyi.platform.service.KgInfoService;
import com.ruoyi.system.api.domain.SysDictData;
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.HttpServletResponse;
import java.util.List;

/**
* 知识图谱列表管理
*/
@RestController
@RequestMapping("/kg")
public class KgInfoController extends BaseController {

@Autowired
private KgInfoService kgInfoService;

/**
* 新增图谱
*
* @param kgInfo
* @return
*/
@PostMapping()
public R<String> createKgInfo(@Validated @RequestBody KgInfo kgInfo) {
kgInfoService.insertKgInfo(kgInfo);
return R.ok();
}

/**
* 修改图谱
*
* @param kgInfo
* @return
*/
@PutMapping
public R<String> updateKgInfo(@Validated @RequestBody KgInfo kgInfo) {
kgInfoService.updateKgInfo(kgInfo);
return R.ok();
}

/**
* 图谱列表
*
* @return
*/
@GetMapping("/list")
public TableDataInfo getAllKgInfos() {
startPage();
List<KgInfoPageVo> kgInfo = kgInfoService.getAllKgInfos();
return getDataTable(kgInfo);
}

/**
* 图谱详情
*
* @param kgInfoIdDTO
* @return
*/
@GetMapping
public R<KgInfo> getKgInfo(KgInfoIdDTO kgInfoIdDTO) {
return R.ok(kgInfoService.getKgInfo(kgInfoIdDTO));
}

/**
* 删除图谱
*
* @param id
* @return
*/
@DeleteMapping("/{id}")
public R<String> deleteKgInfoById(@PathVariable Long id) {
kgInfoService.deleteKgInfoById(id);
return R.ok();
}

}

+ 145
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/kg/KgOntologyInfoController.java View File

@@ -0,0 +1,145 @@
package com.ruoyi.platform.controller.kg;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.platform.domain.kg.KgOntologyInfo;
import com.ruoyi.platform.domain.kg.dto.GraphData;
import com.ruoyi.platform.domain.kg.dto.KgOntologyInfoPageDTO;
import com.ruoyi.platform.domain.kg.dto.KgOntologyNameAndIdDTO;
import com.ruoyi.platform.domain.kg.dto.KgOntologyUpdateDTO;
import com.ruoyi.platform.service.KgOntologyInfoService;
import com.ruoyi.system.api.domain.SysDictData;
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.HttpServletResponse;
import java.util.List;

/**
* 知识图谱主体管理
*/
@RestController
@RequestMapping("/kg/ontology")
public class KgOntologyInfoController extends BaseController {

@Autowired
private KgOntologyInfoService kgOntologyInfoService;

/**
* 新增主体
*
* @param ontology
* @return
*/
@PostMapping()
public R<String> createOntology(@Validated @RequestBody KgOntologyInfo ontology) {
kgOntologyInfoService.insertOntology(ontology);
return R.ok("新增成功");
}

/**
* 修改主体信息
*
* @param ontology
* @return
*/
@PutMapping("/info")
public R<String> updateInfo(@Validated @RequestBody KgOntologyUpdateDTO ontology) {
kgOntologyInfoService.updateOntology(ontology);
return R.ok("修改成功");
}

/**
* 主体列表
* @return
*/
@PostMapping("/list")
public TableDataInfo getOntologies(@RequestBody KgOntologyInfoPageDTO ontology) {
startPage();
List<KgOntologyInfo> ontologies = kgOntologyInfoService.getOntologies(ontology);
return getDataTable(ontologies);
}

/**
* 新增图谱时关联主体内容
* @return
*/
@GetMapping("/getBasicInfo")
public R<List<KgOntologyNameAndIdDTO>> getNameAndIds() {
return R.ok(kgOntologyInfoService.getNameAndIds());
}

/**
* 主体详情
* @param id
* @return
*/
@GetMapping("/{id}")
public R<KgOntologyUpdateDTO> getOntology(@PathVariable Long id) {
return R.ok(kgOntologyInfoService.getOntology(id));
}

/**
* 删除主体
* @param id
* @return
*/
@DeleteMapping("/{id}")
public R<String> deleteById(@PathVariable Long id) {
kgOntologyInfoService.deleteOntologyById(id);
return R.ok("删除成功");
}

/**
* 删除主体
* @param ids
* @return
*/
@DeleteMapping("/batch")
public R<String> batchDelete(@RequestParam(value = "ids") List<Long> ids) {
kgOntologyInfoService.batchDelete(ids);
return R.ok("批量删除成功");
}

/**
* 保存图谱
* @param graphData
* @return
*/
@PutMapping("/saveGraph")
public R<String> saveGraph(@RequestBody GraphData graphData) {
kgOntologyInfoService.saveGraph(graphData);
return R.ok("保存成功");
}

/**
* 主体导出
* @param response
* @param id
*/
@GetMapping("/export/{id}")
public void export(HttpServletResponse response,@PathVariable Long id) {
KgOntologyUpdateDTO ontology = kgOntologyInfoService.getOntology(id);
ExcelUtil<SysDictData> util = new ExcelUtil<SysDictData>(SysDictData.class);
util.exportExcel(response, null, "主体数据");
}

/**
* 主体导入
* @param file
* @param updateSupport
*/
@PostMapping("/import")
public R<String> importOntology(MultipartFile file, boolean updateSupport) throws Exception {
ExcelUtil<KgOntologyInfo> util = new ExcelUtil<>(KgOntologyInfo.class);
List<KgOntologyInfo> ontologyList = util.importExcel(file.getInputStream());
String operName = SecurityUtils.getUsername();
return R.ok(kgOntologyInfoService.importOntology(ontologyList, updateSupport, operName));

}
}

+ 134
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/kg/KgVersionController.java View File

@@ -0,0 +1,134 @@
package com.ruoyi.platform.controller.kg;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.platform.domain.kg.KnowledgeGraphVersion;
import com.ruoyi.platform.domain.kg.dto.KgInfoIdDTO;
import com.ruoyi.platform.domain.kg.dto.KgVersionInsertDTO;
import com.ruoyi.platform.service.KgVersionService;
import com.ruoyi.system.api.domain.SysDictData;
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.HttpServletResponse;
import java.util.List;

/**
* 知识图谱版本管理
*/
@RestController
@RequestMapping("/kg/version")
public class KgVersionController extends BaseController {

@Autowired
private KgVersionService kgVersionService;

/**
* 图谱版本列表
*
* @param kgInfoIdDTO
* @return
*/
@GetMapping("/list")
public TableDataInfo versionList(KgInfoIdDTO kgInfoIdDTO) {
startPage();
List<KnowledgeGraphVersion> kgInfo = kgVersionService.versionList(kgInfoIdDTO);
return getDataTable(kgInfo);
}

/**
* 图谱版本导出
*
* @param response
* @param kgInfoIdDTO
*/
@GetMapping("/export")
public void versionExport(HttpServletResponse response, KgInfoIdDTO kgInfoIdDTO) {
// KgInfo KgInfo = kgVersionService.getKgInfo(kgInfoIdDTO);
ExcelUtil<SysDictData> util = new ExcelUtil<SysDictData>(SysDictData.class);
util.exportExcel(response, null, "图谱数据");
}

/**
* 图谱版本导入
*
* @param file
*/
@PostMapping("/upload")
public R<String> uploadCsv(@RequestParam("file") MultipartFile file) {
if (file == null || file.isEmpty()) {
throw new IllegalArgumentException("文件不能为空");
}

if (!file.getOriginalFilename().endsWith(".csv")) {
throw new IllegalArgumentException("仅支持 CSV 文件");
}

try {
return R.ok(kgVersionService.uploadCsv(file));
} catch (Exception e) {
e.printStackTrace();
return R.fail();
}
}

/**
* 图谱版本新增
*
* @param kgVersionInsertDTO
*/
@PostMapping
public R<String> insert(@RequestBody @Validated KgVersionInsertDTO kgVersionInsertDTO) {
kgVersionService.insert(kgVersionInsertDTO);
return R.ok();
}


/**
* 图谱版本全量更新
*
* @param kgInfoIdDTO 版本id
*/
@PostMapping("/fullUpdate")
public R<String> fullUpdate(@RequestBody @Validated KgInfoIdDTO kgInfoIdDTO) {
kgVersionService.fullUpdate(kgInfoIdDTO.getId());
return R.ok("操作成功");
}

/**
* 图谱版本增量更新
*
* @param kgInfoIdDTO
*/
@PostMapping("/incrementalUpdate")
public R<String> incrementalUpdate(@RequestBody @Validated KgInfoIdDTO kgInfoIdDTO) {
kgVersionService.incrementalUpdate(kgInfoIdDTO.getId());
return R.ok("操作成功");
}

/**
* 图谱版本回退
*
* @param kgInfoIdDTO
*/
@PostMapping("/rollback")
public R<String> rollback(@RequestBody @Validated KgInfoIdDTO kgInfoIdDTO) {
kgVersionService.rollback(kgInfoIdDTO.getId());
return R.ok("操作成功");
}

/**
* 图谱版本删除
*
* @param versionId
*/
@DeleteMapping("/{versionId}")
public R<String> delete(@PathVariable Long versionId) {
kgVersionService.delete(versionId);
return R.ok("操作成功");
}
}

+ 126
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/kg/KnowledgeGraphController.java View File

@@ -0,0 +1,126 @@
package com.ruoyi.platform.controller.kg;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.platform.domain.kg.KnowledgeGraph;
import com.ruoyi.platform.domain.kg.KnowledgeGraphVersion;
import com.ruoyi.platform.service.kg.KnowledgeGraphService;
import com.ruoyi.platform.service.kg.KnowledgeGraphVersionService;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
* (KnowledgeGraph)表控制层
*
* @author makejava
* @since 2025-03-11 14:52:09
*/
@RestController
@RequestMapping("knowledgeGraph")
public class KnowledgeGraphController {
@Autowired
private Environment env;
/**
* 服务对象
*/
@Autowired
private KnowledgeGraphService knowledgeGraphService;

@Autowired
private KnowledgeGraphVersionService knowledgeGraphVersionService;

/**
* 分页查询
*
* @param knowledgeGraph 筛选条件
* @param pageRequest 分页对象
* @return 查询结果
*/
@GetMapping
public AjaxResult queryByPage(KnowledgeGraph knowledgeGraph, PageRequest pageRequest) {
return AjaxResult.success(this.knowledgeGraphService.queryByPage(knowledgeGraph, pageRequest));
}

/**
* 通过主键查询单条数据
*
* @param id 主键
* @return 单条数据
*/
@GetMapping("{id}")
public AjaxResult queryById(@PathVariable("id") Long id) {
return AjaxResult.success(this.knowledgeGraphService.queryById(id));
}

/**
* 新增数据
*
* @param knowledgeGraph 实体
* @return 新增结果
*/
@PostMapping
public AjaxResult add(KnowledgeGraph knowledgeGraph) throws Exception {
return AjaxResult.success(this.knowledgeGraphService.insert(knowledgeGraph));
}

/**
* 编辑数据
*
* @param knowledgeGraph 实体
* @return 编辑结果
*/
@PutMapping
public AjaxResult edit(KnowledgeGraph knowledgeGraph) {
return AjaxResult.success(this.knowledgeGraphService.update(knowledgeGraph));
}

/**
* 删除数据
*
* @param id 主键
* @return 删除是否成功
*/
@DeleteMapping
public AjaxResult deleteById(Integer id) {
return AjaxResult.success(this.knowledgeGraphService.deleteById(id));
}


// @PostMapping("/upload")
// public AjaxResult uploadFile(@RequestParam("file") MultipartFile file,
// @RequestParam("knowledgeGraphId") Long knowledgeGraphId,
// @RequestParam("version") Integer version) {
// KnowledgeGraph knowledgeGraph = knowledgeGraphService.queryById(knowledgeGraphId);
// KnowledgeGraphVersion knowledgeGraphVersion = new KnowledgeGraphVersion();
// knowledgeGraphVersion.setKgId(knowledgeGraphId);
// knowledgeGraphVersion.setVersion(version);
// knowledgeGraphVersionService.insert(knowledgeGraphVersion);
//
//
// // 构建文件存储路径
// String baseDir = env.getProperty("file.upload.base.dir", "/data/knowledgegraph");
// LoginUser loginUser = SecurityUtils.getLoginUser();
// Path filePath = Paths.get(baseDir, loginUser.getUsername(), knowledgeGraph.getKgName(), version, file.getOriginalFilename());
//
// try {
// // 确保路径存在,如果不存在则创建
// Files.createDirectories(filePath.getParent());
// // 保存文件
// file.transferTo(filePath.toFile());
// } catch (IOException e) {
// return AjaxResult.error("文件上传失败: " + e.getMessage());
// }
//
// return AjaxResult.success("文件上传成功,存储路径为: " + filePath.toString());
// }
}


+ 93
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/kg/KnowledgeGraphVersionController.java View File

@@ -0,0 +1,93 @@
package com.ruoyi.platform.controller.kg;

import com.ruoyi.platform.domain.kg.KnowledgeGraphVersion;
import com.ruoyi.platform.service.kg.KnowledgeGraphVersionService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
* (KnowledgeGraphVersion)表控制层
*
* @author makejava
* @since 2025-03-11 14:52:09
*/
@RestController
@RequestMapping("knowledgeGraphVersion")
public class KnowledgeGraphVersionController {
/**
* 服务对象
*/
@Resource
private KnowledgeGraphVersionService knowledgeGraphVersionService;

/**
* 分页查询
*
* @param knowledgeGraphVersion 筛选条件
* @param pageRequest 分页对象
* @return 查询结果
*/
@GetMapping
public ResponseEntity<Page<KnowledgeGraphVersion>> queryByPage(KnowledgeGraphVersion knowledgeGraphVersion, PageRequest pageRequest) {
return ResponseEntity.ok(this.knowledgeGraphVersionService.queryByPage(knowledgeGraphVersion, pageRequest));
}

/**
* 通过主键查询单条数据
*
* @param id 主键
* @return 单条数据
*/
@GetMapping("{id}")
public ResponseEntity<KnowledgeGraphVersion> queryById(@PathVariable("id") Long id) {
return ResponseEntity.ok(this.knowledgeGraphVersionService.queryById(id));
}

/**
* 新增数据
*
* @param knowledgeGraphVersion 实体
* @return 新增结果
*/
@PostMapping
public ResponseEntity<KnowledgeGraphVersion> add(KnowledgeGraphVersion knowledgeGraphVersion) {
return ResponseEntity.ok(this.knowledgeGraphVersionService.insert(knowledgeGraphVersion));
}

/**
* 编辑数据
*
* @param knowledgeGraphVersion 实体
* @return 编辑结果
*/
@PutMapping
public ResponseEntity<KnowledgeGraphVersion> edit(KnowledgeGraphVersion knowledgeGraphVersion) {
return ResponseEntity.ok(this.knowledgeGraphVersionService.update(knowledgeGraphVersion));
}

/**
* 删除数据
*
* @param id 主键
* @return 删除是否成功
*/
@DeleteMapping
public ResponseEntity<Boolean> deleteById(Long id) {
return ResponseEntity.ok(this.knowledgeGraphVersionService.deleteById(id));
}

/**
* 增量更新数据
*/
@GetMapping("/incrementalUpdate")
public ResponseEntity<Boolean> incrementalUpdate(Long id) {

return ResponseEntity.ok(this.knowledgeGraphVersionService.incrementalUpdate(id));
}

}


+ 124
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/kg/MatKGController.java View File

@@ -0,0 +1,124 @@
package com.ruoyi.platform.controller.kg;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.platform.utils.ExcelReaderInputStream;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Map;

@RestController
@RequestMapping("/kg")
public class MatKGController {

@PostMapping("/uploadOntology")
public R<String> uploadOntology(@RequestParam("file") MultipartFile file,
@RequestParam("param") String param) {
if (file.isEmpty()) {
return R.fail("文件为空");
}

try {
// 直接读取文件内容为字符串
String jsonContent = new String(file.getBytes(), StandardCharsets.UTF_8);

return R.ok();
} catch (Exception e) {
return R.fail("文件处理失败: " + e.getMessage());
}
}

@PostMapping("/uploadKGData")
public R<String> uploadKGData(@RequestParam("file") MultipartFile file,
@RequestParam("id") String id) {
if (file.isEmpty()) {
return R.fail("文件为空");
}
// 检查文件类型
String contentType = file.getContentType();
String fileName = file.getOriginalFilename();
if (!isValidFileType(contentType, fileName)) {
return R.fail("不支持的文件格式。请上传CSV、XLSX或JSON文件。");
}

try {
// 创建目标文件
InputStream inputStream = file.getInputStream();

// 处理文件和参数
processJsonFile(inputStream, id);

return R.ok();
} catch (Exception e) {
return R.fail("文件处理失败: " + e.getMessage());
}
}

private void processJsonFile(InputStream inputStream, String id) {
ExcelReaderInputStream<Map> reader = new ExcelReaderInputStream<>(inputStream,Map.class,data->{
//todo some logic
});

// 读取Excel文件
reader.read();
}

@PostMapping("/uploadKGData2")
public R<String> uploadKGData2(@RequestParam("file") MultipartFile file,
@RequestParam("param") String param) {
if (file.isEmpty()) {
return R.fail("文件为空");
}
// 检查文件类型
String contentType = file.getContentType();
String fileName = file.getOriginalFilename();
if (!isValidFileType(contentType, fileName)) {
return R.fail("不支持的文件格式。请上传CSV、XLSX或JSON文件。");
}

try {
// 创建目标文件
File targetFile = new File("uploadDir", file.getOriginalFilename());
// 确保目录存在
if (!targetFile.getParentFile().exists()) {
targetFile.getParentFile().mkdirs();
}
// 将文件写入目标路径
file.transferTo(targetFile);

// 处理文件和参数
// processJsonFile(targetFile, param);

return R.ok("文件上传并处理成功,参数: " + param);
} catch (Exception e) {
return R.fail("文件处理失败: " + e.getMessage());
}
}

private boolean isValidFileType(String contentType, String fileName) {
// 检查文件扩展名
String extension = getFileExtension(fileName);

// 检查MIME类型
if ("application/json".equals(contentType) || "text/csv".equals(contentType) || "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet".equals(contentType)) {
return true;
}

// 检查文件扩展名
return "csv".equalsIgnoreCase(extension) || "xlsx".equalsIgnoreCase(extension) || "json".equalsIgnoreCase(extension);
}

private String getFileExtension(String fileName) {
if (fileName != null && fileName.contains(".")) {
return fileName.substring(fileName.lastIndexOf('.') + 1);
}
return "";
}

}

+ 37
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/CsvParser.java View File

@@ -0,0 +1,37 @@
package com.ruoyi.platform.domain;

import cn.hutool.core.collection.CollectionUtil;
import com.opencsv.CSVReader;
import com.opencsv.exceptions.CsvException;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class CsvParser {

public static List<Map<String, String>> parseCsvToMap(InputStream inputStream) throws IOException, CsvException {
try (CSVReader reader = new CSVReader(new InputStreamReader(inputStream))) {
List<String[]> rows = reader.readAll();
if (CollectionUtil.isEmpty(rows) || rows.size() <= 1) {
return new ArrayList<>();
}
String[] headers = rows.get(0); // 第一行为表头
List<String[]> data = rows.subList(1, rows.size()); // 剩余行为数据

return data.stream()
.map(row -> {
Map<String, String> map = new HashMap<>();
for (int i = 0; i < headers.length; i++) {
map.put(headers[i], row[i]);
}
return map;
}).collect(Collectors.toList());
}
}
}

+ 23
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/CsvToMap.java View File

@@ -0,0 +1,23 @@
package com.ruoyi.platform.domain;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class CsvToMap {

public static List<Map<String, String>> convertToMap(List<String[]> csvData) {
String[] headers = csvData.get(0); // 第一行为表头
List<String[]> rows = csvData.subList(1, csvData.size()); // 剩余行为数据

return rows.stream()
.map(row -> {
Map<String, String> map = new HashMap<>();
for (int i = 0; i < headers.length; i++) {
map.put(headers[i], row[i]);
}
return map;
}).collect(Collectors.toList());
}
}

+ 84
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/kg/KgEntityInfo.java View File

@@ -0,0 +1,84 @@
package com.ruoyi.platform.domain.kg;

import java.io.Serializable;
import java.util.Date;
import lombok.Data;

import javax.validation.constraints.NotNull;

/**
* kg_entity_info
*/
@Data
public class KgEntityInfo implements Serializable {
/**
* 实体主键
*/
private Long id;

/**
* 实体名称
*/
@NotNull(message = "实体名称不能为空")
private String name;

/**
* 实体描述
*/
private String description;

/**
* 背景色
*/
private String bkColor;

/**
* 横坐标
*/
@NotNull(message = "横坐标不能为空")
private Integer displayX;

/**
* 纵坐标
*/
@NotNull(message = "纵坐标不能为空")
private Integer displayY;

/**
* 图标路径
*/
private String icon;

/**
* 主体主键
*/
@NotNull(message = "主体主键不能为空")
private Long ontologyId;

/**
* 创建时间
*/
private Date createTime;

/**
* 更新时间
*/
private Date updateTime;

/**
* 删除标志,0表示未删除,1表示已删除
*/
private String delFlag;

/**
* 创建人
*/
private String createBy;

/**
* 更新人
*/
private String updateBy;

private static final long serialVersionUID = 1L;
}

+ 68
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/kg/KgEntityProperty.java View File

@@ -0,0 +1,68 @@
package com.ruoyi.platform.domain.kg;

import java.io.Serializable;
import java.util.Date;
import lombok.Data;

import javax.validation.constraints.NotNull;

/**
* kg_entity_properties
*/
@Data
public class KgEntityProperty implements Serializable {
/**
* 属性主键
*/
private Long id;

/**
* 属性名
*/
@NotNull(message = "属性名不能为空")
private String name;

/**
* 属性类型(String/Integer等)
*/
@NotNull(message = "属性类型不能为空")
private String type;

/**
* 关联实体信息
*/
private Long entityId;

/**
* '是否多值(0否/1是)
*/
@NotNull(message = "是否多值不能为空")
private Boolean isMultivalued;

/**
* 创建时间
*/
private Date createTime;

/**
* 更新时间
*/
private Date updateTime;

/**
* 删除标志,0表示未删除,1表示已删除
*/
private String delFlag;

/**
* 创建人
*/
private String createBy;

/**
* 更新人
*/
private String updateBy;

private static final long serialVersionUID = 1L;
}

+ 73
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/kg/KgEntityRelation.java View File

@@ -0,0 +1,73 @@
package com.ruoyi.platform.domain.kg;

import java.io.Serializable;
import java.util.Date;
import lombok.Data;

import javax.validation.constraints.NotNull;

/**
* kg_entity_relations
*/
@Data
public class KgEntityRelation implements Serializable {
/**
* 关系主键
*/
private String id;

/**
* 关系名称
*/
@NotNull(message = "属性名不能为空")
private String name;

/**
* 终点属性名
*/
private String target;

/**
* 终点实体ID
*/
@NotNull(message = "终点实体ID不能为空")
private Long targetId;

/**
* 起点实体ID
*/
@NotNull(message = "起点实体ID不能为空")
private Long sourceId;

/**
* 关联实体ID
*/
private Long entityId;

/**
* 创建时间
*/
private Date createTime;

/**
* 更新时间
*/
private Date updateTime;

/**
* 删除标志,0表示未删除,1表示已删除
*/
private String delFlag;

/**
* 创建人
*/
private String createBy;

/**
* 更新人
*/
private String updateBy;

private static final long serialVersionUID = 1L;
}

+ 83
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/kg/KgInfo.java View File

@@ -0,0 +1,83 @@
package com.ruoyi.platform.domain.kg;

import java.io.Serializable;
import java.util.Date;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

/**
* 知识图谱信息表
* kg_info
*/
@Data
public class KgInfo implements Serializable {
/**
* ID
*/
private Long id;

/**
* 版本
*/
private String version;

/**
* 图谱名称
*/
private String name;

/**
* 本体ID
*/
private Long ontologyId;

/**
* neo4j数据库名称
*/
private String dbName;

/**
* 状态(0正常 1停用)
*/
private String status;

/**
* 创建者
*/
private String createBy;

/**
* 创建时间
*/
private Date createTime;

/**
* 更新者
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private String updateBy;

/**
* 更新时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;

/**
* 备注
*/
private String remark;

/**
* 规格
*/
private String spec;

/**
* 删除标志(2删除,0未删除)
*/
private String delFlag;

private static final long serialVersionUID = 1L;
}

+ 93
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/kg/KgInfoPageVo.java View File

@@ -0,0 +1,93 @@
package com.ruoyi.platform.domain.kg;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
* 知识图谱信息表
* kg_info
*/
@Data
public class KgInfoPageVo implements Serializable {
/**
* ID
*/
private Long id;

/**
* 版本
*/
private String version;

/**
* 图谱名称
*/
private String name;

/**
* 本体ID
*/
private Long ontologyId;

/**
* neo4j数据库名称
*/
private String dbName;

/**
* 状态(0正常 1停用)
*/
private String status;

/**
* 创建者
*/
private String createBy;

/**
* 创建时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime;

/**
* 更新者
*/
private String updateBy;

/**
* 更新时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date updateTime;

/**
* 备注
*/
private String remark;

/**
* 规格
*/
private String spec;

/**
* 删除标志(2删除,0未删除)
*/
private String delFlag;

/**
* 关系数
*/
private Integer relationCount;

/**
* 实体数
*/
private Integer entityCount;

private static final long serialVersionUID = 1L;
}

+ 72
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/kg/KgOntologyInfo.java View File

@@ -0,0 +1,72 @@
package com.ruoyi.platform.domain.kg;

import java.io.Serializable;
import java.util.Date;
import lombok.Data;

import javax.validation.constraints.NotNull;

/**
* kg_ontology_info
*/
@Data
public class KgOntologyInfo implements Serializable {
/**
* 主体主键
*/
private Long id;

/**
* 主体名称
*/
@NotNull(message = "主体名称不能为空")
private String name;

/**
* 主体描述
*/
@NotNull(message = "主体描述不能为空")
private String description;

/**
* 图信息
*/
private String dag;

/**
* 概念个数
*/
private Integer conceptsCount;

/**
* 关系个数
*/
private Integer relationsCount;

/**
* 创建时间
*/
private Date createTime;

/**
* 更新时间
*/
private Date updateTime;

/**
* 创建人
*/
private String createBy;

/**
* 更新人
*/
private String updateBy;

/**
* 删除标志,0表示未删除,1表示已删除
*/
private Boolean delFlag;

private static final long serialVersionUID = 1L;
}

+ 37
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/kg/KnowledgeGraph.java View File

@@ -0,0 +1,37 @@
package com.ruoyi.platform.domain.kg;

import lombok.Data;

import java.util.Date;
import java.io.Serializable;

/**
* (KnowledgeGraph)实体类
*
* @author makejava
* @since 2025-03-11 14:52:09
*/
@Data
public class KnowledgeGraph implements Serializable {
private static final long serialVersionUID = 783648356146355028L;

private Long id;

private String kgName;

private String kgDesc;

private Integer kgNoumenon;

private Date createTime;

private String createBy;

private Date updateTime;

private String updateBy;

private Integer state;

}


+ 14
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/kg/KnowledgeGraphLabel.java View File

@@ -0,0 +1,14 @@
package com.ruoyi.platform.domain.kg;

import lombok.Data;
import org.springframework.data.neo4j.core.schema.GeneratedValue;
import org.springframework.data.neo4j.core.schema.Id;

@Data
public class KnowledgeGraphLabel {
@Id
@GeneratedValue
private Long id;
private String graphName;

}

+ 54
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/kg/KnowledgeGraphVersion.java View File

@@ -0,0 +1,54 @@
package com.ruoyi.platform.domain.kg;

import lombok.Data;

import java.util.Date;
import java.io.Serializable;

/**
* (KnowledgeGraphVersion)实体类
*
* @author makejava
* @since 2025-03-11 14:52:10
*/
@Data
public class KnowledgeGraphVersion implements Serializable {
private static final long serialVersionUID = -60506903543301209L;

private Long id;

private String name;

private Integer version;

private String transactionId;

private String content;

private String kgId;

private Integer status;

private Integer updateMethod;

/**
* 概念个数
*/
private Integer conceptsCount;

/**
* 关系个数
*/
private Integer relationsCount;

private Date updateTime;

private Date createTime;

private String createBy;

private String updateBy;

private Integer state;
}


+ 15
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/kg/dto/GraphData.java View File

@@ -0,0 +1,15 @@
package com.ruoyi.platform.domain.kg.dto;

import lombok.Data;

import java.util.List;
import java.util.Map;

@Data
public class GraphData {
private List<KgEntityInfoDTO> nodes;
private List<KgEntityRelationDTO> edges;
private List<Map<String, Object>> combos;


}

+ 74
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/kg/dto/KgEntityInfoDTO.java View File

@@ -0,0 +1,74 @@
package com.ruoyi.platform.domain.kg.dto;

import com.ruoyi.platform.domain.kg.KgEntityProperty;
import lombok.Data;
import org.springframework.data.neo4j.core.schema.Id;
import org.springframework.data.neo4j.core.schema.Node;
import org.springframework.data.neo4j.core.schema.Relationship;
import java.util.*;

/**
* kg_entity_info
*/
@Data
@Node("KgEntity")
public class KgEntityInfoDTO{

/**
* 实体主键
*/
@Id
private Long id;

/**
* 实体名称
*/
private String label;

/**
* 实体描述
*/
private String description;

/**
* 背景色
*/
private String bkColor;

/**
* 图标路径
*/
private String icon;

/**
* 横坐标
*/
private Integer x;

/**
* 纵坐标
*/
private Integer y;

/**
* 属性集合
*/
private List<KgEntityProperty> properties;

/**
* 关系集合
*/
@Relationship(type = "CONNECTS_TO", direction = Relationship.Direction.OUTGOING)
private List<KgEntityRelationDTO> relations = new ArrayList<>();

private String type;

private Map<String,Object> labelCfg;

private Map<String,Object> style;

private Integer depth;

private String name;

}

+ 70
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/kg/dto/KgEntityRelationDTO.java View File

@@ -0,0 +1,70 @@
package com.ruoyi.platform.domain.kg.dto;

import com.ruoyi.platform.domain.kg.KgEntityRelation;
import lombok.Data;
import org.springframework.data.neo4j.core.schema.*;

import java.util.List;
import java.util.Map;

/**
* kg_entity_relations
*/
@Data
@RelationshipProperties
public class KgEntityRelationDTO {

/**
* 关系主键
*/
@RelationshipId
private Long id;

/**
* 起点节点id
*/
private Long target;

/**
* 终点节点id
*/
private Long source;

/**
* 关系名
*/
private String name;

/**
* 关联实体ID
*/
private Long entityId;

/**
* 终点实体ID
*/
@TargetNode
private KgEntityInfoDTO targetEntity;

private Map<String, Object> labelCfg;

private Map<String, Object> style;

private Map<String, Object> startPoint;

private Map<String, Object> endPoint;

private Integer sourceAnchor;

private Integer targetAnchor;

@Property("type")
private String type;

private List<Float> curvePosition;

private List<Float> minCurveOffset;

private Integer depth;

}

+ 30
- 0
ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/domain/kg/dto/KgInfoIdDTO.java View File

@@ -0,0 +1,30 @@
package com.ruoyi.platform.domain.kg.dto;

import lombok.Data;

import javax.validation.constraints.NotNull;

@Data
public class KgInfoIdDTO {

/**
* ID
*/
@NotNull
private Long id;

/**
* 名字
*/
private String name;

/**
* 版本
*/
private String version;

/**
* 状态
*/
private String status;
}

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save