diff --git a/ruoyi-modules/knowledge-graph/pom.xml b/ruoyi-modules/knowledge-graph/pom.xml new file mode 100644 index 00000000..3645c51d --- /dev/null +++ b/ruoyi-modules/knowledge-graph/pom.xml @@ -0,0 +1,536 @@ + + + + + com.ruoyi + ruoyi-modules + 3.6.3 + + + knowledge-graph + 4.0.0 + + 知识图谱模块 + + + + 8 + 8 + UTF-8 + + + + + + com.alibaba + druid-spring-boot-starter + ${druid.version} + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-sentinel + + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + io.springfox + springfox-swagger-ui + ${swagger.fox.version} + + + + com.mysql + mysql-connector-j + + + + + com.ruoyi + ruoyi-common-datasource + + + + com.ruoyi + ruoyi-common-datasource + + + + + com.ruoyi + ruoyi-common-datascope + + + + + com.ruoyi + ruoyi-common-log + + + + + com.ruoyi + ruoyi-common-swagger + + + com.ruoyi + ruoyi-common-security + + + com.ruoyi + ruoyi-common-swagger + + + org.springframework.security + spring-security-core + + + com.ruoyi + ruoyi-common-log + + + com.ruoyi + ruoyi-common-core + + + org.projectlombok + lombok + + + + + org.projectlombok + lombok + + + org.apache.httpcomponents + httpclient + 4.5.5 + + + org.apache.httpcomponents + httpmime + 4.5 + + + + + org.apache.httpcomponents + httpcore + 4.4.13 + + + io.kubernetes + client-java + 17.0.0 + + + com.github.docker-java + docker-java + 3.2.13 + + + commons-beanutils + commons-beanutils + 1.9.4 + + + com.github.docker-java + docker-java-transport-httpclient5 + 3.2.13 + + + com.baomidou + mybatis-plus-annotation + 3.3.2 + + + com.baomidou + mybatis-plus-core + 3.3.2 + + + javax.persistence + persistence-api + 1.0.2 + + + io.kubernetes + client-java-api + 16.0.3 + compile + + + io.kubernetes + client-java-api + 12.0.1 + + + com.opencsv + opencsv + 5.7.1 + + + org.apache.commons + commons-csv + 1.9.0 + + + io.fabric8 + kubernetes-client + 4.11.1 + + + io.github.classgraph + classgraph + 4.8.83 + + + io.minio + minio + 8.2.2 + + + org.mlflow + mlflow-client + 1.28.0 + + + org.checkerframework + checker-qual + 3.19.0 + compile + + + com.jcraft + jsch + 0.1.55 + + + + org.springframework.boot + spring-boot-starter-websocket + + + org.json + json + 20210307 + + + org.apache.dubbo + dubbo + 3.0.8 + compile + + + commons-lang + commons-lang + 2.6 + compile + + + org.eclipse.jgit + org.eclipse.jgit + 5.13.0.202109080827-r + + + redis.clients + jedis + 3.6.0 + + + + cn.hutool + hutool-all + 5.8.5 + + + + org.springframework.boot + spring-boot-starter-data-neo4j + + + org.neo4j.driver + neo4j-java-driver + + + com.alibaba + easyexcel + 4.0.3 + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + + + \ No newline at end of file diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/KnowledgeGraphApplication.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/KnowledgeGraphApplication.java new file mode 100644 index 00000000..58aa8aa0 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/KnowledgeGraphApplication.java @@ -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" + + " ''-' `'-' `-..-' "); + } +} \ No newline at end of file diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/config/Neo4jConfig.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/config/Neo4jConfig.java new file mode 100644 index 00000000..a1b7655d --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/config/Neo4jConfig.java @@ -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(); + } +} \ No newline at end of file diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/config/WebSocketConfig.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/config/WebSocketConfig.java new file mode 100644 index 00000000..91ca1778 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/config/WebSocketConfig.java @@ -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(); + } +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgEntityController.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgEntityController.java new file mode 100644 index 00000000..07206d36 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgEntityController.java @@ -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 createEntity(@Validated @RequestBody KgEntityInfo entityInfo) { + kgEntityInfoService.insertEntity(entityInfo); + return R.ok(); + } + + /** + * 修改实体 + * + * @param entityInfo + * @return + */ + @PutMapping + public R updateEntity(@Validated @RequestBody KgEntityInfo entityInfo) { + kgEntityInfoService.updateEntity(entityInfo); + return R.ok(); + } + + /** + * 实体列表 + * @return + */ + @GetMapping("/list") + public TableDataInfo getEntities(@RequestBody KgEntityInfo entityInfo) { + startPage(); + List ontologies = kgEntityInfoService.getEntities(entityInfo); + return getDataTable(ontologies); + } + + /** + * 实体详情 + * @param id + * @return + */ + @GetMapping("/{id}") + public R getEntity(@PathVariable Long id) { + return R.ok(kgEntityInfoService.getEntity(id)); + } + + /** + * 删除实体 + * @param id + * @return + */ + @DeleteMapping("/{id}") + public R 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 util = new ExcelUtil(SysDictData.class); + util.exportExcel(response, null, "实体数据"); + } +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgEntityPropertiesController.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgEntityPropertiesController.java new file mode 100644 index 00000000..433c7734 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgEntityPropertiesController.java @@ -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 createEntityProperty(@Validated @RequestBody KgEntityProperty entityProperties) { + kgEntityPropertiesService.insertEntityProperties(entityProperties); + return R.ok(); + } + + /** + * 修改实体属性 + * + * @param KgEntityProperty + * @return + */ + @PutMapping + public R updateEntityProperty(@Validated @RequestBody KgEntityProperty KgEntityProperty) { + kgEntityPropertiesService.updateEntityProperties(KgEntityProperty); + return R.ok(); + } + + /** + * 实体属性列表 + * @return + */ + @GetMapping("/list") + public TableDataInfo getEntityProperties(@RequestBody KgEntityProperty KgEntityProperty) { + startPage(); + List ontologies = kgEntityPropertiesService.getEntityProperties(KgEntityProperty); + return getDataTable(ontologies); + } + + /** + * 实体属性详情 + * @param id + * @return + */ + @GetMapping("/{id}") + public R getEntityProperty(@PathVariable Long id) { + return R.ok(kgEntityPropertiesService.getEntityProperty(id)); + } + + /** + * 删除实体属性 + * @param id + * @return + */ + @DeleteMapping("/{id}") + public R 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 util = new ExcelUtil(SysDictData.class); + util.exportExcel(response, null, "实体属性数据"); + } +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgEntityRelationsController.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgEntityRelationsController.java new file mode 100644 index 00000000..6720ee66 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgEntityRelationsController.java @@ -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 createEntityRelations(@Validated @RequestBody KgEntityRelation entityRelations) { + kgEntityRelationsService.insertEntityRelation(entityRelations); + return R.ok(); + } + + /** + * 修改实体关系 + * + * @param entityRelations + * @return + */ + @PutMapping + public R updateEntityRelations(@Validated @RequestBody KgEntityRelation entityRelations) { + kgEntityRelationsService.updateEntityRelation(entityRelations); + return R.ok(); + } + + /** + * 实体关系列表 + * @return + */ + @GetMapping("/list") + public TableDataInfo getEntityRelations(@RequestBody KgEntityRelation entityRelation) { + startPage(); + List entityRelations = kgEntityRelationsService.getEntityRelations(entityRelation); + return getDataTable(entityRelations); + } + + /** + * 实体关系详情 + * @param id + * @return + */ + @GetMapping("/{id}") + public R getEntityRelations(@PathVariable Long id) { + return R.ok(kgEntityRelationsService.getEntityRelations(id)); + } + + /** + * 删除实体关系 + * @param id + * @return + */ + @DeleteMapping("/{id}") + public R 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 util = new ExcelUtil(SysDictData.class); + util.exportExcel(response, null, "实体关系数据"); + } +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgInfoController.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgInfoController.java new file mode 100644 index 00000000..128488a6 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgInfoController.java @@ -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 createKgInfo(@Validated @RequestBody KgInfo kgInfo) { + kgInfoService.insertKgInfo(kgInfo); + return R.ok(); + } + + /** + * 修改图谱 + * + * @param kgInfo + * @return + */ + @PutMapping + public R updateKgInfo(@Validated @RequestBody KgInfo kgInfo) { + kgInfoService.updateKgInfo(kgInfo); + return R.ok(); + } + + /** + * 图谱列表 + * + * @return + */ + @GetMapping("/list") + public TableDataInfo getAllKgInfos() { + startPage(); + List kgInfo = kgInfoService.getAllKgInfos(); + return getDataTable(kgInfo); + } + + /** + * 图谱详情 + * + * @param kgInfoIdDTO + * @return + */ + @GetMapping + public R getKgInfo(KgInfoIdDTO kgInfoIdDTO) { + return R.ok(kgInfoService.getKgInfo(kgInfoIdDTO)); + } + + /** + * 删除图谱 + * + * @param id + * @return + */ + @DeleteMapping("/{id}") + public R deleteKgInfoById(@PathVariable Long id) { + kgInfoService.deleteKgInfoById(id); + return R.ok(); + } + +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgOntologyInfoController.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgOntologyInfoController.java new file mode 100644 index 00000000..48274a11 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgOntologyInfoController.java @@ -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 createOntology(@Validated @RequestBody KgOntologyInfo ontology) { + kgOntologyInfoService.insertOntology(ontology); + return R.ok("新增成功"); + } + + /** + * 修改主体信息 + * + * @param ontology + * @return + */ + @PutMapping("/info") + public R updateInfo(@Validated @RequestBody KgOntologyUpdateDTO ontology) { + kgOntologyInfoService.updateOntology(ontology); + return R.ok("修改成功"); + } + + /** + * 主体列表 + * @return + */ + @PostMapping("/list") + public TableDataInfo getOntologies(@RequestBody KgOntologyInfoPageDTO ontology) { + startPage(); + List ontologies = kgOntologyInfoService.getOntologies(ontology); + return getDataTable(ontologies); + } + + /** + * 新增图谱时关联主体内容 + * @return + */ + @GetMapping("/getBasicInfo") + public R> getNameAndIds() { + return R.ok(kgOntologyInfoService.getNameAndIds()); + } + + /** + * 主体详情 + * @param id + * @return + */ + @GetMapping("/{id}") + public R getOntology(@PathVariable Long id) { + return R.ok(kgOntologyInfoService.getOntology(id)); + } + + /** + * 删除主体 + * @param id + * @return + */ + @DeleteMapping("/{id}") + public R deleteById(@PathVariable Long id) { + kgOntologyInfoService.deleteOntologyById(id); + return R.ok("删除成功"); + } + + /** + * 删除主体 + * @param ids + * @return + */ + @DeleteMapping("/batch") + public R batchDelete(@RequestParam(value = "ids") List ids) { + kgOntologyInfoService.batchDelete(ids); + return R.ok("批量删除成功"); + } + + /** + * 保存图谱 + * @param graphData + * @return + */ + @PutMapping("/saveGraph") + public R 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 util = new ExcelUtil(SysDictData.class); + util.exportExcel(response, null, "主体数据"); + } + + /** + * 主体导入 + * @param file + * @param updateSupport + */ + @PostMapping("/import") + public R importOntology(MultipartFile file, boolean updateSupport) throws Exception { + ExcelUtil util = new ExcelUtil<>(KgOntologyInfo.class); + List ontologyList = util.importExcel(file.getInputStream()); + String operName = SecurityUtils.getUsername(); + return R.ok(kgOntologyInfoService.importOntology(ontologyList, updateSupport, operName)); + + } +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgVersionController.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgVersionController.java new file mode 100644 index 00000000..4ded93ff --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/controller/KgVersionController.java @@ -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 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 util = new ExcelUtil(SysDictData.class); + util.exportExcel(response, null, "图谱数据"); + } + + /** + * 图谱版本导入 + * + * @param file + */ + @PostMapping("/upload") + public R 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 insert(@RequestBody @Validated KgVersionInsertDTO kgVersionInsertDTO) { + kgVersionService.insert(kgVersionInsertDTO); + return R.ok(); + } + + + /** + * 图谱版本全量更新 + * + * @param kgInfoIdDTO 版本id + */ + @PostMapping("/fullUpdate") + public R fullUpdate(@RequestBody @Validated KgInfoIdDTO kgInfoIdDTO) { + kgVersionService.fullUpdate(kgInfoIdDTO.getId()); + return R.ok("操作成功"); + } + + /** + * 图谱版本增量更新 + * + * @param kgInfoIdDTO + */ + @PostMapping("/incrementalUpdate") + public R incrementalUpdate(@RequestBody @Validated KgInfoIdDTO kgInfoIdDTO) { + kgVersionService.incrementalUpdate(kgInfoIdDTO.getId()); + return R.ok("操作成功"); + } + + /** + * 图谱版本回退 + * + * @param kgInfoIdDTO + */ + @PostMapping("/rollback") + public R rollback(@RequestBody @Validated KgInfoIdDTO kgInfoIdDTO) { + kgVersionService.rollback(kgInfoIdDTO.getId()); + return R.ok("操作成功"); + } + + /** + * 图谱版本删除 + * + * @param versionId + */ + @DeleteMapping("/{versionId}") + public R delete(@PathVariable Long versionId) { + kgVersionService.delete(versionId); + return R.ok("操作成功"); + } +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/CsvParser.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/CsvParser.java new file mode 100644 index 00000000..53db4090 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/CsvParser.java @@ -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> parseCsvToMap(InputStream inputStream) throws IOException, CsvException { + try (CSVReader reader = new CSVReader(new InputStreamReader(inputStream))) { + List rows = reader.readAll(); + if (CollectionUtil.isEmpty(rows) || rows.size() <= 1) { + return new ArrayList<>(); + } + String[] headers = rows.get(0); // 第一行为表头 + List data = rows.subList(1, rows.size()); // 剩余行为数据 + + return data.stream() + .map(row -> { + Map map = new HashMap<>(); + for (int i = 0; i < headers.length; i++) { + map.put(headers[i], row[i]); + } + return map; + }).collect(Collectors.toList()); + } + } +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/CsvToMap.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/CsvToMap.java new file mode 100644 index 00000000..8e906345 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/CsvToMap.java @@ -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> convertToMap(List csvData) { + String[] headers = csvData.get(0); // 第一行为表头 + List rows = csvData.subList(1, csvData.size()); // 剩余行为数据 + + return rows.stream() + .map(row -> { + Map map = new HashMap<>(); + for (int i = 0; i < headers.length; i++) { + map.put(headers[i], row[i]); + } + return map; + }).collect(Collectors.toList()); + } +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/FriendsWith.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/FriendsWith.java new file mode 100644 index 00000000..73f3801b --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/FriendsWith.java @@ -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; + } +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgEntityInfo.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgEntityInfo.java new file mode 100644 index 00000000..8d535d40 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgEntityInfo.java @@ -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; +} \ No newline at end of file diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgEntityProperty.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgEntityProperty.java new file mode 100644 index 00000000..f2032a9a --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgEntityProperty.java @@ -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; +} \ No newline at end of file diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgEntityRelation.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgEntityRelation.java new file mode 100644 index 00000000..fca1767b --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgEntityRelation.java @@ -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; +} \ No newline at end of file diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgInfo.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgInfo.java new file mode 100644 index 00000000..6b4ea00c --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgInfo.java @@ -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; +} \ No newline at end of file diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgInfoPageVo.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgInfoPageVo.java new file mode 100644 index 00000000..894c214b --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgInfoPageVo.java @@ -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; +} \ No newline at end of file diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgOntologyInfo.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgOntologyInfo.java new file mode 100644 index 00000000..36aea334 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KgOntologyInfo.java @@ -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; +} \ No newline at end of file diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KnowledgeGraph.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KnowledgeGraph.java new file mode 100644 index 00000000..dfb635b5 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KnowledgeGraph.java @@ -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; + +} + diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KnowledgeGraphLabel.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KnowledgeGraphLabel.java new file mode 100644 index 00000000..b18d1bf4 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KnowledgeGraphLabel.java @@ -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; + +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KnowledgeGraphVersion.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KnowledgeGraphVersion.java new file mode 100644 index 00000000..282a7745 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/KnowledgeGraphVersion.java @@ -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; +} + diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/Person.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/Person.java new file mode 100644 index 00000000..653420c2 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/Person.java @@ -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 relations; + + // 构造函数、Getter 和 Setter + public Person(String name, String age,List relations,Integer version,String transactionId) { + this.name = name; + this.age = age; + this.relations = relations; + this.version = version; + this.transactionId = transactionId; + } +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/GraphData.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/GraphData.java new file mode 100644 index 00000000..7869f1e8 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/GraphData.java @@ -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 nodes; + private List edges; + private List> combos; + + +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgEntityInfoDTO.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgEntityInfoDTO.java new file mode 100644 index 00000000..93ed4e87 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgEntityInfoDTO.java @@ -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 properties; + + /** + * 关系集合 + */ + @Relationship(type = "CONNECTS_TO", direction = Relationship.Direction.OUTGOING) + private List relations = new ArrayList<>(); + + private String type; + + private Map labelCfg; + + private Map style; + + private Integer depth; + + private String name; + +} \ No newline at end of file diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgEntityRelationDTO.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgEntityRelationDTO.java new file mode 100644 index 00000000..33f2b7f8 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgEntityRelationDTO.java @@ -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 labelCfg; + + private Map style; + + private Map startPoint; + + private Map endPoint; + + private Integer sourceAnchor; + + private Integer targetAnchor; + + @Property("type") + private String type; + + private List curvePosition; + + private List minCurveOffset; + + private Integer depth; + +} \ No newline at end of file diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgInfoIdDTO.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgInfoIdDTO.java new file mode 100644 index 00000000..31f23e0f --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgInfoIdDTO.java @@ -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; +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgInfoPageDTO.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgInfoPageDTO.java new file mode 100644 index 00000000..a0ab9f51 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgInfoPageDTO.java @@ -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; +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgOntologyInfoPageDTO.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgOntologyInfoPageDTO.java new file mode 100644 index 00000000..ff4d3faa --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgOntologyInfoPageDTO.java @@ -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; + + +} \ No newline at end of file diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgOntologyNameAndIdDTO.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgOntologyNameAndIdDTO.java new file mode 100644 index 00000000..cff47911 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgOntologyNameAndIdDTO.java @@ -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; +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgOntologyUpdateDTO.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgOntologyUpdateDTO.java new file mode 100644 index 00000000..08a72e9f --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgOntologyUpdateDTO.java @@ -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 concepts; + + +} \ No newline at end of file diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgVersionInsertDTO.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgVersionInsertDTO.java new file mode 100644 index 00000000..e11eecce --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/domain/dto/KgVersionInsertDTO.java @@ -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; +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KgEntityInfoMapper.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KgEntityInfoMapper.java new file mode 100644 index 00000000..25796b58 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KgEntityInfoMapper.java @@ -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 { + 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 selectList(KgEntityInfo record); + + List selectListByOntologyId(KgEntityInfo kgEntityInfo); +} \ No newline at end of file diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KgEntityPropertiesMapper.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KgEntityPropertiesMapper.java new file mode 100644 index 00000000..1bd3ae4d --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KgEntityPropertiesMapper.java @@ -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 { + 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 selectList(KgEntityProperty record); + + List selectListByEntityIds( List entityIds); +} \ No newline at end of file diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KgEntityRelationsMapper.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KgEntityRelationsMapper.java new file mode 100644 index 00000000..bb39d7a3 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KgEntityRelationsMapper.java @@ -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 { + 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 selectList(KgEntityRelation record); + + List selectListByEntityIds(@Param("list") List ids); +} \ No newline at end of file diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KgInfoMapper.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KgInfoMapper.java new file mode 100644 index 00000000..7b639c6b --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KgInfoMapper.java @@ -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 selectByPrimaryKey(KgInfoIdDTO kgInfoIdDTO); + + List selectALl(); + + KgInfo queryInfoByPrimaryKey(KgInfoIdDTO kgInfoIdDTO); + + int updateByPrimaryKeySelective(KgInfo record); + + int updateByPrimaryKey(KgInfo record); +} \ No newline at end of file diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KgOntologyInfoMapper.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KgOntologyInfoMapper.java new file mode 100644 index 00000000..4b9432d5 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KgOntologyInfoMapper.java @@ -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 { + + KgOntologyUpdateDTO selectByPrimaryKey(@Param("id") Long id); + + void updateByPrimaryKeySelective(KgOntologyInfo kgOntologyInfo); + + void insertSelective(KgOntologyInfo kgOntologyInfo); + + void deleteByPrimaryKey(@Param("id") Long id); + + void deleteByIds(List ids); + + List selectList(KgOntologyInfoPageDTO ontology); + + + List getNameAndIds(); +} + + + + diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KnowledgeGraphDao.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KnowledgeGraphDao.java new file mode 100644 index 00000000..f72bb111 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KnowledgeGraphDao.java @@ -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 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 实例对象列表 + * @return 影响行数 + */ + int insertBatch(@Param("entities") List entities); + + /** + * 批量新增或按主键更新数据(MyBatis原生foreach方法) + * + * @param entities List 实例对象列表 + * @return 影响行数 + * @ + */ + int insertOrUpdateBatch(@Param("entities") List entities); + + /** + * 修改数据 + * + * @param knowledgeGraph 实例对象 + * @return 影响行数 + */ + int update(KnowledgeGraph knowledgeGraph); + + /** + * 通过主键删除数据 + * + * @param id 主键 + * @return 影响行数 + */ + int deleteById(Integer id); + +} + diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KnowledgeGraphVersionDao.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KnowledgeGraphVersionDao.java new file mode 100644 index 00000000..8d50c4a7 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/mapper/KnowledgeGraphVersionDao.java @@ -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 queryAllByLimit(KnowledgeGraphVersion knowledgeGraphVersion, @Param("pageable") Pageable pageable); + + /** + * 查询指定行数据 + * + * @param kgInfoIdDTO 查询条件 + * @return 对象列表 + */ + List queryAll(KgInfoIdDTO kgInfoIdDTO); + + /** + * 统计总行数 + * + * @param knowledgeGraphVersion 查询条件 + * @return 总行数 + */ + long count(KnowledgeGraphVersion knowledgeGraphVersion); + + /** + * 新增数据 + * + * @param knowledgeGraphVersion 实例对象 + * @return 影响行数 + */ + int insert(KnowledgeGraphVersion knowledgeGraphVersion); + + /** + * 批量新增数据(MyBatis原生foreach方法) + * + * @param entities List 实例对象列表 + * @return 影响行数 + */ + int insertBatch(@Param("entities") List entities); + + /** + * 批量新增或按主键更新数据(MyBatis原生foreach方法) + * + * @param entities List 实例对象列表 + * @return 影响行数 + * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常,请自行校验入参 + */ + int insertOrUpdateBatch(@Param("entities") List entities); + + /** + * 修改数据 + * + * @param knowledgeGraphVersion 实例对象 + * @return 影响行数 + */ + int update(KnowledgeGraphVersion knowledgeGraphVersion); + + /** + * 通过主键删除数据 + * + * @param id 主键 + * @return 影响行数 + */ + int deleteById(Long id); + + Integer queryMaxVersion(String kgId); + + KnowledgeGraphVersion onlineFind(); + +} + diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgEntityInfoService.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgEntityInfoService.java new file mode 100644 index 00000000..6bd4630e --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgEntityInfoService.java @@ -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 getEntities(KgEntityInfo entityInfo); + + List getEntitiesByOntologyId(Long ontologyId); + + KgEntityInfo getEntity(Long id); + + void deleteEntityById(Long id); +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgEntityPropertiesService.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgEntityPropertiesService.java new file mode 100644 index 00000000..5f78e67c --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgEntityPropertiesService.java @@ -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 entityProperties); + + List getEntityProperties(KgEntityProperty entityProperty); + + List getEntityPropertiesByEntityIds(List ids); + + KgEntityProperty getEntityProperty(Long id); + + void deleteEntityPropertyById(Long id); +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgEntityRelationsService.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgEntityRelationsService.java new file mode 100644 index 00000000..ee981af3 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgEntityRelationsService.java @@ -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 entityRelations); + + List getEntityRelations(KgEntityRelation entityRelations); + + List getEntityRelationsByEntityIds(List ids); + + KgEntityRelation getEntityRelations(Long id); + + void deleteEntityRelationById(Long id); +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgEntityRepository.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgEntityRepository.java new file mode 100644 index 00000000..baa82594 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgEntityRepository.java @@ -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 { +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgInfoService.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgInfoService.java new file mode 100644 index 00000000..5f8e1f83 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgInfoService.java @@ -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 getAllKgInfos(); + + KgInfo getKgInfo(KgInfoIdDTO kgInfoIdDTO); + + void deleteKgInfoById(Long id); +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgOntologyInfoService.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgOntologyInfoService.java new file mode 100644 index 00000000..01f2060a --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgOntologyInfoService.java @@ -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 getOntologies(KgOntologyInfoPageDTO ontology); + + KgOntologyUpdateDTO getOntology(Long id); + + void deleteOntologyById(Long id); + + void batchDelete(List ids); + + void saveGraph(GraphData graphData); + + String importOntology(List ontologyList, boolean updateSupport, String operName); + + List getNameAndIds(); +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgVersionService.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgVersionService.java new file mode 100644 index 00000000..beb3f522 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/KgVersionService.java @@ -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 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 ); +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/MinioService.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/MinioService.java new file mode 100644 index 00000000..52e2edc4 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/MinioService.java @@ -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 downloadFile(String bucketName , String path) throws Exception; + + ResponseEntity downloadZipFile(String bucketName , String path); + + Map uploadFile(String bucketName, String objectName, MultipartFile file ) throws Exception; + void uploaInputStream(String bucketName, String objectName, InputStream inputStream ) throws Exception; +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/PersonRepository.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/PersonRepository.java new file mode 100644 index 00000000..07011a3c --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/PersonRepository.java @@ -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 { +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgEntityInfoServiceImpl.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgEntityInfoServiceImpl.java new file mode 100644 index 00000000..4390d5d8 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgEntityInfoServiceImpl.java @@ -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 getEntities(KgEntityInfo entityInfo) { + return kgEntityInfoMapper.selectList(entityInfo); + } + + @Override + public List getEntitiesByOntologyId(Long ontologyId) { + KgEntityInfo kgEntityInfo = new KgEntityInfo(); + kgEntityInfo.setOntologyId(ontologyId); + //获取所有实体集合 + List kgEntityInfos = kgEntityInfoMapper.selectListByOntologyId(kgEntityInfo); + List entityIds = kgEntityInfos.stream() + .map(KgEntityInfoDTO::getId) + .collect(Collectors.toList()); + List entityPropertyList = kgEntityPropertiesService.getEntityPropertiesByEntityIds(entityIds); + List entityRelationList = kgEntityRelationsService.getEntityRelationsByEntityIds(entityIds); + + // 按实体ID分组 + Map> propertiesMap = entityPropertyList.stream() + .collect(Collectors.groupingBy(KgEntityProperty::getEntityId)); + // 按实体ID分组 + Map> 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); + } +} + + + + diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgEntityPropertiesServiceImpl.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgEntityPropertiesServiceImpl.java new file mode 100644 index 00000000..c580650e --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgEntityPropertiesServiceImpl.java @@ -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 entityProperties) { + entityProperties.forEach(item -> { + if (ObjectUtil.isNull(item.getId())) { + insertEntityProperties(item); + } else { + item.setEntityId(entityId); + updateEntityProperties(item); + } + }); + } + + @Override + public List getEntityProperties(KgEntityProperty entityProperty) { + return kgEntityPropertiesMapper.selectList(entityProperty); + } + + @Override + public List getEntityPropertiesByEntityIds(List 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); + } +} + + + + diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgEntityRelationsServiceImpl.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgEntityRelationsServiceImpl.java new file mode 100644 index 00000000..9a098463 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgEntityRelationsServiceImpl.java @@ -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 entityRelations) { + entityRelations.forEach(item -> { + if (ObjectUtil.isNull(item.getId())) { + insertEntityRelation(item); + } else { + item.setEntityId(entityId); + updateEntityRelation(item); + } + }); + } + + @Override + public List getEntityRelations(KgEntityRelation entityRelations) { + return kgEntityRelationsMapper.selectList(entityRelations); + } + + @Override + public List getEntityRelationsByEntityIds(List 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); + } +} + + + + diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgInfoServiceImpl.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgInfoServiceImpl.java new file mode 100644 index 00000000..9c64cb05 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgInfoServiceImpl.java @@ -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 getAllKgInfos() { + List kgInfos = kgInfoMapper.selectALl(); + return kgInfos; + } + + @Override + public KgInfo getKgInfo(KgInfoIdDTO kgInfoIdDTO) { + return kgInfoMapper.queryInfoByPrimaryKey(kgInfoIdDTO); + } + + @Override + public void deleteKgInfoById(Long id) { + kgInfoMapper.deleteByPrimaryKey(id); + } + +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgOntologyInfoServiceImpl.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgOntologyInfoServiceImpl.java new file mode 100644 index 00000000..35e9f735 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgOntologyInfoServiceImpl.java @@ -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 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 ids) { + kgOntologyInfoMapper.deleteByIds(ids); + } + + @Override + public String importOntology(List ontologyList, boolean updateSupport, String operName) { + return null; + } + + + @Override + @Transactional + public void saveGraph(GraphData graphData) { + // 存储节点 + Map 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 getNameAndIds() { + return kgOntologyInfoMapper.getNameAndIds(); + } + + private GraphData jsonToBean(String dag) { + try { + return JSONUtil.toBean(dag, GraphData.class); + } catch (Exception e) { + return new GraphData(); + } + } +} + + + + diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgVersionServiceImpl.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgVersionServiceImpl.java new file mode 100644 index 00000000..f0c4f999 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/KgVersionServiceImpl.java @@ -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 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> queryCsvDataFromMinio(String path) { + List> csvData; + try { + ResponseEntity 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> csvData = queryCsvDataFromMinio(content); + if (CollectionUtil.isEmpty(csvData)) { + return; + } + Map 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; + } + +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/MinioServiceImpl.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/MinioServiceImpl.java new file mode 100644 index 00000000..556ddde5 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/service/impl/MinioServiceImpl.java @@ -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 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 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 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 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); + } +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/utils/DVCUtils.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/utils/DVCUtils.java new file mode 100644 index 00000000..9db2d92c --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/utils/DVCUtils.java @@ -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 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 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 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 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 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> + */ + public List> 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<>(); + } +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/utils/FileUtil.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/utils/FileUtil.java new file mode 100644 index 00000000..2109bce3 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/utils/FileUtil.java @@ -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> getFiles(String path) { + List> 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 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(); + } + } +} diff --git a/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/utils/MinioUtil.java b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/utils/MinioUtil.java new file mode 100644 index 00000000..6315bb6e --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/java/com/ruoyi/kg/utils/MinioUtil.java @@ -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> results = minioClient.listObjects( + ListObjectsArgs.builder().bucket(bucketName).prefix(objectName).recursive(false).build()); + for (Result 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 getAllObjectsByPrefix(String bucketName, String prefix, boolean recursive) throws Exception { + List list = new ArrayList<>(); + Iterable> objectsIterator = minioClient.listObjects( + ListObjectsArgs. + builder(). + bucket(bucketName). + prefix(prefix). + recursive(recursive). + build()); + if (objectsIterator != null) { + for (Result 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> results = minioClient.listObjects(ListObjectsArgs.builder() + .bucket(sourceBucketName) + .prefix(sourceKeyPrefix) + .recursive(true) + .build()); + + for (Result 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> results = minioClient.listObjects(listObjectsArgs); + for (Result 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 listFilesInDirectory(String bucketName, String prefix) throws Exception { + List fileInfoList = new ArrayList<>(); + Iterable> results = minioClient.listObjects( + ListObjectsArgs.builder() + .prefix(prefix) + .bucket(bucketName) + .build()); + + for (Result 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 listRayFilesInDirectory(String bucketName, String prefix) throws Exception { + List fileInfoList = new ArrayList<>(); + Iterable> results = minioClient.listObjects( + ListObjectsArgs.builder() + .prefix(prefix) + .bucket(bucketName) + .build()); + + for (Result 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 keys) { + List 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> results = minioClient.listObjects( + ListObjectsArgs.builder().bucket(bucketName).prefix(path).recursive(true).build()); + + for (Result 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()); + } + } +} \ No newline at end of file diff --git a/ruoyi-modules/knowledge-graph/src/main/resources/banner.txt b/ruoyi-modules/knowledge-graph/src/main/resources/banner.txt new file mode 100644 index 00000000..f26ba6c3 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/resources/banner.txt @@ -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-' diff --git a/ruoyi-modules/knowledge-graph/src/main/resources/bootstrap-prod.yml b/ruoyi-modules/knowledge-graph/src/main/resources/bootstrap-prod.yml new file mode 100644 index 00000000..d85762b7 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/resources/bootstrap-prod.yml @@ -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} diff --git a/ruoyi-modules/knowledge-graph/src/main/resources/bootstrap.yml b/ruoyi-modules/knowledge-graph/src/main/resources/bootstrap.yml new file mode 100644 index 00000000..ef628a59 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/resources/bootstrap.yml @@ -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 \ No newline at end of file diff --git a/ruoyi-modules/knowledge-graph/src/main/resources/k8sconfig/clusterrolebinding.yaml b/ruoyi-modules/knowledge-graph/src/main/resources/k8sconfig/clusterrolebinding.yaml new file mode 100644 index 00000000..1e76e022 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/resources/k8sconfig/clusterrolebinding.yaml @@ -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 + diff --git a/ruoyi-modules/knowledge-graph/src/main/resources/logback.xml b/ruoyi-modules/knowledge-graph/src/main/resources/logback.xml new file mode 100644 index 00000000..ccc5bb02 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/resources/logback.xml @@ -0,0 +1,93 @@ + + + + + + + + + + + ${log.pattern} + + + + + + ${log.path}/sys-info.log + + + + ${log.path}/sys-info.%d{yyyy-MM-dd}.log + + 60 + + + ${log.pattern} + + + + INFO + + ACCEPT + + DENY + + + + + ${log.path}/sys-error.log + + + + ${log.path}/sys-error.%d{yyyy-MM-dd}.log + + 60 + + + ${log.pattern} + + + + ERROR + + ACCEPT + + DENY + + + + + + ${log.path}/sys-user.log + + + ${log.path}/sys-user.%d{yyyy-MM-dd}.log + + 60 + + + ${log.pattern} + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ruoyi-modules/knowledge-graph/src/main/resources/mapper/KgEntityInfoMapper.xml b/ruoyi-modules/knowledge-graph/src/main/resources/mapper/KgEntityInfoMapper.xml new file mode 100644 index 00000000..d82a1e70 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/resources/mapper/KgEntityInfoMapper.xml @@ -0,0 +1,201 @@ + + + + + + + + + + + + + + + + + + + + id, `name`, description, bk_color, display_x, display_y, icon, ontology_id, create_time, + update_time, del_flag, create_by, update_by + + + + delete from kg_entity_info + where id = #{id,jdbcType=INTEGER} + + + 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 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, + + + + + #{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}, + + + + + update kg_entity_info + + + `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 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} + + + + + + \ No newline at end of file diff --git a/ruoyi-modules/knowledge-graph/src/main/resources/mapper/KgEntityPropertiesMapper.xml b/ruoyi-modules/knowledge-graph/src/main/resources/mapper/KgEntityPropertiesMapper.xml new file mode 100644 index 00000000..8c68bf04 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/resources/mapper/KgEntityPropertiesMapper.xml @@ -0,0 +1,171 @@ + + + + + + + + + + + + + + + + + id, `name`, `type`, entity_id, is_multivalued, create_time, update_time, del_flag, + create_by, update_by + + + + delete from kg_entity_properties + where id = #{id,jdbcType=INTEGER} + + + 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 into kg_entity_properties + + + `name`, + + + `type`, + + + entity_id, + + + is_multivalued, + + + create_time, + + + update_time, + + + del_flag, + + + create_by, + + + update_by, + + + + + #{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}, + + + + + update kg_entity_properties + + + `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 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} + + + + + + \ No newline at end of file diff --git a/ruoyi-modules/knowledge-graph/src/main/resources/mapper/KgEntityRelationsMapper.xml b/ruoyi-modules/knowledge-graph/src/main/resources/mapper/KgEntityRelationsMapper.xml new file mode 100644 index 00000000..2114ab11 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/resources/mapper/KgEntityRelationsMapper.xml @@ -0,0 +1,182 @@ + + + + + + + + + + + + + + + + + + id, `name`, target, target_id, source_id, entity_id, create_time, update_time, del_flag, create_by, + update_by + + + + delete from kg_entity_relations + where id = #{id,jdbcType=INTEGER} + + + 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 into kg_entity_relations + + + `name`, + + + target, + + + target_id, + + + source_id, + + + entity_id, + + + create_time, + + + update_time, + + + del_flag, + + + create_by, + + + update_by, + + + + + #{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}, + + + + + update kg_entity_relations + + + `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 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} + + + + + + \ No newline at end of file diff --git a/ruoyi-modules/knowledge-graph/src/main/resources/mapper/KgInfoMapper.xml b/ruoyi-modules/knowledge-graph/src/main/resources/mapper/KgInfoMapper.xml new file mode 100644 index 00000000..406f1364 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/resources/mapper/KgInfoMapper.xml @@ -0,0 +1,188 @@ + + + + + + + + + + + + + + + + + + + + + id, version, `name`, ontology_id, db_name, `status`, create_by, create_time, update_by, + update_time, remark, spec,del_flag + + + + + + + + + + delete from kg_info + where id = #{id,jdbcType=BIGINT} + + + + 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 into kg_info + + + version, + + + `name`, + + + ontology_id, + + + db_name, + + + `status`, + + + create_by, + + + create_time, + + + update_by, + + + update_time, + + + remark, + + + del_flag, + + + + + #{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}, + + + + + update kg_info + + + 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 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} + + \ No newline at end of file diff --git a/ruoyi-modules/knowledge-graph/src/main/resources/mapper/KgOntologyInfoMapper.xml b/ruoyi-modules/knowledge-graph/src/main/resources/mapper/KgOntologyInfoMapper.xml new file mode 100644 index 00000000..3728fc31 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/resources/mapper/KgOntologyInfoMapper.xml @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + + + id, `name`, description, concepts_count, relations_count,dag, create_time, update_time, + create_by, update_by, del_flag + + + + delete from kg_ontology_info + where id = #{id,jdbcType=INTEGER} + + + delete from kg_ontology_info + where id = #{id,jdbcType=INTEGER} + + + 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 into kg_ontology_info + + + `name`, + + + description, + + + concepts_count, + + + relations_count, + + + dag, + + + create_time, + + + update_time, + + + create_by, + + + update_by, + + + del_flag, + + + + + #{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}, + + + + + update kg_ontology_info + + + `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 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} + + + + + \ No newline at end of file diff --git a/ruoyi-modules/knowledge-graph/src/main/resources/mapper/KnowledgeGraphDao.xml b/ruoyi-modules/knowledge-graph/src/main/resources/mapper/KnowledgeGraphDao.xml new file mode 100644 index 00000000..f044cca3 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/resources/mapper/KnowledgeGraphDao.xml @@ -0,0 +1,162 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + insert into knowledge_graph(kg_namekg_desckg_noumenoncreate_timecreate_byupdate_timeupdate_bystate) + values (#{kgName}#{kgDesc}#{kgNoumenon}#{createTime}#{createBy}#{updateTime}#{updateBy}#{state}) + + + + insert into knowledge_graph(kg_namekg_desckg_noumenoncreate_timecreate_byupdate_timeupdate_bystate) + values + + (#{entity.kgName}#{entity.kgDesc}#{entity.kgNoumenon}#{entity.createTime}#{entity.createBy}#{entity.updateTime}#{entity.updateBy}#{entity.state}) + + + + + insert into knowledge_graph(kg_namekg_desckg_noumenoncreate_timecreate_byupdate_timeupdate_bystate) + values + + (#{entity.kgName}#{entity.kgDesc}#{entity.kgNoumenon}#{entity.createTime}#{entity.createBy}#{entity.updateTime}#{entity.updateBy}#{entity.state}) + + 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) + + + + + update knowledge_graph + + + kg_name = #{kgName}, + + + kg_desc = #{kgDesc}, + + + kg_noumenon = #{kgNoumenon}, + + + create_time = #{createTime}, + + + create_by = #{createBy}, + + + update_time = #{updateTime}, + + + update_by = #{updateBy}, + + + state = #{state}, + + + where id = #{id} + + + + + delete + from knowledge_graph + where id = #{id} + + + + diff --git a/ruoyi-modules/knowledge-graph/src/main/resources/mapper/KnowledgeGraphVersionDao.xml b/ruoyi-modules/knowledge-graph/src/main/resources/mapper/KnowledgeGraphVersionDao.xml new file mode 100644 index 00000000..807645c5 --- /dev/null +++ b/ruoyi-modules/knowledge-graph/src/main/resources/mapper/KnowledgeGraphVersionDao.xml @@ -0,0 +1,227 @@ + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + + + + + + + + + + + + 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 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 + + (#{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}) + + + + + 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 + + (#{entity.name},#{entity.version},#{entity.kgId},#{entity.status},#{entity.updateMethod},#{entity.entityNum},#{entity.updateTime},#{entity.createTime},#{entity.createBy},#{entity.updateBy},#{entity.state}) + + 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) + + + + + update knowledge_graph_version + + + version = #{version}, + + + `name` = #{name}, + + + kg_id = #{kgId}, + + + status = #{status}, + + + update_method = #{updateMethod}, + + + and concepts_count = #{conceptsCount} + + + and relations_count = #{relationsCount} + + + update_time = #{updateTime}, + + + create_time = #{createTime}, + + + create_by = #{createBy}, + + + update_by = #{updateBy}, + + + `state` = #{state}, + + + where id = #{id} + + + + + delete + from knowledge_graph_version + where id = #{id} + + + + + + + diff --git a/ruoyi-modules/pom.xml b/ruoyi-modules/pom.xml index fa38feed..f704b4d7 100644 --- a/ruoyi-modules/pom.xml +++ b/ruoyi-modules/pom.xml @@ -14,6 +14,7 @@ ruoyi-job ruoyi-file management-platform + knowledge-graph ruoyi-modules