ソースを参照

Merge remote-tracking branch 'origin/master'

twzydn20000928 2 年 前
コミット
011f786d55

+ 2 - 1
kgraph-graph/src/main/java/com/kgraph/graph/neo4j/domain/Neo4jEntity.java

@@ -3,6 +3,7 @@ package com.kgraph.graph.neo4j.domain;
 import lombok.Data;
 import org.neo4j.ogm.annotation.*;
 
+import java.util.ArrayList;
 import java.util.List;
 
 @NodeEntity("Entity")
@@ -16,7 +17,7 @@ public class Neo4jEntity {
     @Property("name")
     private String name;
     @Labels()
-    private List<String> labels;
+    private List<String> labels = new ArrayList<>();
     @Property("content")
     private String content;
     @Property("attachmentUrl")

+ 3 - 1
kgraph-graph/src/main/java/com/kgraph/graph/neo4j/service/IKgService.java

@@ -1,8 +1,8 @@
 package com.kgraph.graph.neo4j.service;
 
 import com.kgraph.graph.neo4j.DTO.KgDTO;
-import com.kgraph.graph.neo4j.DTO.KgDocDTO;
 import com.kgraph.graph.neo4j.domain.Neo4jRelation;
+import com.kgraph.graph.suport.dto.BuildEntityRelationDTO;
 
 import java.util.List;
 
@@ -22,4 +22,6 @@ public interface IKgService {
     String analysis(String question);
 
     List<Neo4jRelation> getRelationByLikeName(String name, Integer type);
+
+    void buildEntityByClass(List<BuildEntityRelationDTO> bu1ildEntityRelationDTOList);
 }

+ 50 - 0
kgraph-graph/src/main/java/com/kgraph/graph/neo4j/service/impl/KgServiceImpl.java

@@ -8,6 +8,7 @@ import com.kgraph.graph.neo4j.domain.Neo4jRelation;
 import com.kgraph.graph.neo4j.mapper.EntityRepository;
 import com.kgraph.graph.neo4j.mapper.RelationRepository;
 import com.kgraph.graph.neo4j.service.IKgService;
+import com.kgraph.graph.suport.dto.BuildEntityRelationDTO;
 import com.kgraph.system.service.ISysDictDataService;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
@@ -71,6 +72,11 @@ public class KgServiceImpl implements IKgService {
         return false;
     }
 
+    private boolean relationExist(Neo4jEntity subEntity, Neo4jEntity objEntity, String relationName) {
+        Neo4jRelation relationDb = relationRepository.findRelation(subEntity.getId(), objEntity.getId(), relationName);
+        return relationDb != null;
+    }
+
     @Override
     public Iterable getAllEntityList() {
         return entityRepository.findAll();
@@ -208,4 +214,48 @@ public class KgServiceImpl implements IKgService {
         }
     }
 
+    @Override
+    public void buildEntityByClass(List<BuildEntityRelationDTO> bu1ildEntityRelationDTOList) {
+        bu1ildEntityRelationDTOList.forEach(buildEntityRelationDTO -> {
+            String subEntityName = buildEntityRelationDTO.getSubEntity();
+            Neo4jEntity subEntity = entityRepository.findByName(subEntityName);
+            String subClassName = buildEntityRelationDTO.getSubName();
+            // 如果实体不存在,新建实体
+            if (subEntity == null) {
+                subEntity = new Neo4jEntity();
+                subEntity.setName(subEntityName);
+                subEntity.getLabels().add(subClassName);
+                entityRepository.save(subEntity);
+                // 如果实体存在,实体类没有则添加实体类
+            } else if (!subEntity.getLabels().contains(subClassName)) {
+                subEntity.getLabels().add(subClassName);
+                entityRepository.save(subEntity);
+            }
+
+            String objEntityName = buildEntityRelationDTO.getObjEntity();
+            Neo4jEntity objEntity = entityRepository.findByName(objEntityName);
+            String objClassName = buildEntityRelationDTO.getObjName();
+            // 如果实体不存在,新建实体
+            if (objEntity == null) {
+                objEntity = new Neo4jEntity();
+                objEntity.setName(objEntityName);
+                objEntity.getLabels().add(objClassName);
+                entityRepository.save(objEntity);
+                // 如果实体存在,实体类没有则添加实体类
+            } else if (!objEntity.getLabels().contains(objClassName)) {
+                objEntity.getLabels().add(objClassName);
+                entityRepository.save(objEntity);
+            }
+
+            String relationName = buildEntityRelationDTO.getName();
+            if(!relationExist(subEntity,objEntity, relationName)){
+                Neo4jRelation relation = new Neo4jRelation();
+                relation.setName(relationName);
+                relation.setStartNode(subEntity);
+                relation.setEndNode(objEntity);
+                relationRepository.save(relation);
+            }
+        });
+    }
+
 }

+ 16 - 1
kgraph-graph/src/main/java/com/kgraph/graph/suport/dto/BuildEntityRelationDTO.java

@@ -9,9 +9,24 @@ public class BuildEntityRelationDTO {
     private Long startId;
     private Long endId;
     private Long subTaskId;
+    /**
+     * 关系类name
+      */
     String name;
+    /**
+     * 主体类name
+      */
     String subName;
+    /**
+     * 客体类name
+      */
     String objName;
-    String SubEntity;
+    /**
+     * 主体
+     */
+    String subEntity;
+    /**
+     * 客体
+     */
     String objEntity;
 }

+ 8 - 0
kgraph-graph/src/main/java/com/kgraph/graph/suport/service/impl/BuildEntityRelationServiceImpl.java

@@ -5,6 +5,7 @@ import java.util.List;
 import java.util.Map;
 
 import com.kgraph.common.utils.DateUtils;;
+import com.kgraph.graph.neo4j.service.IKgService;
 import com.kgraph.graph.suport.dto.BuildEntityRelationDTO;
 import com.kgraph.graph.suport.mapper.ExtractKnowledgeSubTaskMapper;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -28,6 +29,9 @@ public class BuildEntityRelationServiceImpl implements IBuildEntityRelationServi
     @Autowired
     private ExtractKnowledgeSubTaskMapper extractKnowledgeSubTaskMapper;
 
+    @Autowired
+    IKgService kgService;
+
     /**
      * 查询实体构建
      * 
@@ -132,6 +136,10 @@ public class BuildEntityRelationServiceImpl implements IBuildEntityRelationServi
         }
         // 更新子任务状态
         extractKnowledgeSubTaskMapper.updateSubTaskStatusById(id, "3", null, new Date());
+        // 更新任务状态
+        extractKnowledgeSubTaskMapper.updateTaskStatusBySubTaskId(id);
+
+        kgService.buildEntityByClass(bu1ildEntityRelationDTOList);
         return res;
     }
 }

+ 125 - 0
sql/update20230523.sql

@@ -1,5 +1,84 @@
 use kgraph;
 
+DROP TABLE
+IF
+	EXISTS entity_class;
+CREATE TABLE entity_class (
+	id BIGINT ( 20 ) NOT NULL auto_increment COMMENT '实体类ID',
+	`name` VARCHAR ( 255 ) NULL COMMENT '实体类名称',
+	`desc` VARCHAR ( 1023 ) NULL COMMENT '实体类描述',
+	back_ground_color VARCHAR ( 15 ) NULL COMMENT '实体类背景颜色',
+	create_by VARCHAR ( 64 ) NULL COMMENT '创建者',
+	create_time datetime NULL COMMENT '创建时间',
+	update_by VARCHAR ( 64 ) NULL COMMENT '更新者',
+	update_time datetime NULL COMMENT '更新时间',
+PRIMARY KEY ( id )
+) ENGINE = INNODB auto_increment = 1 COMMENT = '实体类';
+
+DROP TABLE
+IF
+	EXISTS entity_class_relation;
+CREATE TABLE entity_class_relation (
+	id BIGINT ( 20 ) NOT NULL auto_increment COMMENT '实体类关系ID',
+	`name` VARCHAR ( 255 ) NULL COMMENT '实体类关系名称',
+	`desc` VARCHAR ( 1023 ) NULL COMMENT '实体类关系描述',
+	back_ground_color VARCHAR ( 15 ) NULL COMMENT '实体类关系背景颜色',
+	start_id BIGINT ( 20 ) COMMENT '起点实体类id',
+	end_id BIGINT ( 20 ) COMMENT '起点实体类id',
+	create_by VARCHAR ( 64 ) NULL COMMENT '创建者',
+	create_time datetime NULL COMMENT '创建时间',
+	update_by VARCHAR ( 64 ) NULL COMMENT '更新者',
+	update_time datetime NULL COMMENT '更新时间',
+PRIMARY KEY ( id )
+) ENGINE = INNODB auto_increment = 1 COMMENT = '实体类关系';
+
+DROP TABLE
+IF
+	EXISTS t_build_entity_relation;
+CREATE TABLE t_build_entity_relation (
+	id BIGINT ( 20 ) NOT NULL auto_increment COMMENT '序号',
+	sub_task_id BIGINT ( 20 ) COMMENT '子任务id',
+	sub_entity_class_id BIGINT ( 20 ) COMMENT '主体实体类id',
+	obj_entity_class_id BIGINT ( 20 ) COMMENT '客体实体类id',
+	entity_class_rel_id BIGINT ( 20 ) COMMENT '实体类关系id',
+	sub_entity VARCHAR ( 511 ) COMMENT '主体',
+	obj_entity VARCHAR ( 511 ) COMMENT '客体',
+	create_by VARCHAR ( 64 ) DEFAULT '' COMMENT '创建者',
+	create_time datetime COMMENT '创建时间',
+	update_by VARCHAR ( 64 ) DEFAULT '' COMMENT '更新者',
+	update_time datetime COMMENT '更新时间',
+PRIMARY KEY ( id )
+) ENGINE = INNODB auto_increment = 1 COMMENT = '实体构建表';
+
+DROP TABLE
+IF
+	EXISTS t_build_flow;
+CREATE TABLE t_build_flow (
+	id BIGINT ( 20 ) NOT NULL auto_increment COMMENT '序号',
+	error_code VARCHAR ( 64 ) DEFAULT '' COMMENT '故障编码',
+	flow_encode VARCHAR ( 1023 ) DEFAULT '' COMMENT '流程数据',
+	flow_tree_json TINYTEXT COMMENT '流程树json',
+	create_by VARCHAR ( 64 ) DEFAULT '' COMMENT '创建者',
+	create_time datetime COMMENT '创建时间',
+	update_by VARCHAR ( 64 ) DEFAULT '' COMMENT '更新者',
+	update_time datetime COMMENT '更新时间',
+PRIMARY KEY ( id )
+) ENGINE = INNODB COMMENT = '构建流程';
+
+DROP TABLE
+IF
+	EXISTS t_question_record;
+CREATE TABLE t_question_record (
+	id BIGINT ( 20 ) NOT NULL auto_increment COMMENT '序号',
+	question VARCHAR ( 255 ) DEFAULT '' COMMENT '问题',
+	result VARCHAR ( 511 ) DEFAULT '' COMMENT '结果',
+	create_by VARCHAR ( 64 ) DEFAULT '' COMMENT '创建者',
+	create_time datetime COMMENT '创建时间',
+	update_by VARCHAR ( 64 ) DEFAULT '' COMMENT '更新者',
+	update_time datetime COMMENT '更新时间',
+PRIMARY KEY ( id )
+) ENGINE = INNODB COMMENT = '问答查询记录';
+
 -- 菜单 SQL
 insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
 values('实体类', '2066', '1', 'class', 'neo4j/class/index', 1, 0, 'C', '0', '0', 'neo4j:class:list', '#', 'admin', sysdate(), '', null, '实体类菜单');
@@ -46,4 +125,50 @@ values('实体类关系删除', @parentId, '4',  '#', '', 1, 0, 'F', '0', '0', '
 insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
 values('实体类关系导出', @parentId, '5',  '#', '', 1, 0, 'F', '0', '0', 'neo4j:class_relation:export',       '#', 'admin', sysdate(), '', null, '');
 
+-- 菜单 SQL
+insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
+values('构建流程', '2066', '1', 'flow', 'suport/flow/index', 1, 0, 'C', '0', '0', 'suport:flow:list', '#', 'admin', sysdate(), '', null, '构建流程菜单');
+
+-- 按钮父菜单ID
+SELECT @parentId := LAST_INSERT_ID();
+
+-- 菜单 SQL
+insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
+values('检查点管理', '2066', '1', 'piont', 'suport/piont/index', 1, 0, 'C', '0', '0', 'suport:piont:list', '#', 'admin', sysdate(), '', null, '检查点管理菜单');
+
+-- 按钮父菜单ID
+SELECT @parentId := LAST_INSERT_ID();
+
+-- 按钮 SQL
+insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
+values('检查点管理查询', @parentId, '1',  '#', '', 1, 0, 'F', '0', '0', 'suport:piont:query',        '#', 'admin', sysdate(), '', null, '');
+
+insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
+values('检查点管理新增', @parentId, '2',  '#', '', 1, 0, 'F', '0', '0', 'suport:piont:add',          '#', 'admin', sysdate(), '', null, '');
+
+insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
+values('检查点管理修改', @parentId, '3',  '#', '', 1, 0, 'F', '0', '0', 'suport:piont:edit',         '#', 'admin', sysdate(), '', null, '');
+
+insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
+values('检查点管理删除', @parentId, '4',  '#', '', 1, 0, 'F', '0', '0', 'suport:piont:remove',       '#', 'admin', sysdate(), '', null, '');
+
+insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
+values('检查点管理导出', @parentId, '5',  '#', '', 1, 0, 'F', '0', '0', 'suport:piont:export',       '#', 'admin', sysdate(), '', null, '');
+
+---- 按钮 SQL
+--insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
+--values('构建流程查询', @parentId, '1',  '#', '', 1, 0, 'F', '0', '0', 'suport:flow:query',        '#', 'admin', sysdate(), '', null, '');
+--
+--insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
+--values('构建流程新增', @parentId, '2',  '#', '', 1, 0, 'F', '0', '0', 'suport:flow:add',          '#', 'admin', sysdate(), '', null, '');
+--
+--insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
+--values('构建流程修改', @parentId, '3',  '#', '', 1, 0, 'F', '0', '0', 'suport:flow:edit',         '#', 'admin', sysdate(), '', null, '');
+--
+--insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
+--values('构建流程删除', @parentId, '4',  '#', '', 1, 0, 'F', '0', '0', 'suport:flow:remove',       '#', 'admin', sysdate(), '', null, '');
+--
+--insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
+--values('构建流程导出', @parentId, '5',  '#', '', 1, 0, 'F', '0', '0', 'suport:flow:export',       '#', 'admin', sysdate(), '', null, '');
+
 commit;