| @@ -6,6 +6,7 @@ import com.ruoyi.common.core.web.controller.BaseController; | |||
| import com.ruoyi.common.core.web.page.TableDataInfo; | |||
| import com.ruoyi.common.security.utils.SecurityUtils; | |||
| import com.ruoyi.platform.domain.kg.KgOntologyInfo; | |||
| import com.ruoyi.platform.domain.kg.dto.GraphData; | |||
| import com.ruoyi.platform.domain.kg.dto.KgOntologyInfoPageDTO; | |||
| import com.ruoyi.platform.domain.kg.dto.KgOntologyNameAndIdDTO; | |||
| import com.ruoyi.platform.domain.kg.dto.KgOntologyUpdateDTO; | |||
| @@ -105,6 +106,17 @@ public class KgOntologyInfoController extends BaseController { | |||
| return R.ok("批量删除成功"); | |||
| } | |||
| /** | |||
| * 保存图谱 | |||
| * @param graphData | |||
| * @return | |||
| */ | |||
| @PutMapping("/saveGraph") | |||
| public R<String> saveGraph(@RequestBody GraphData graphData) { | |||
| kgOntologyInfoService.saveGraph(graphData); | |||
| return R.ok("保存成功"); | |||
| } | |||
| /** | |||
| * 主体导出 | |||
| * @param response | |||
| @@ -1,15 +1,10 @@ | |||
| package com.ruoyi.platform.domain.kg.dto; | |||
| import com.ruoyi.platform.domain.kg.KgEntityInfo; | |||
| import com.ruoyi.platform.domain.kg.KgEntityProperty; | |||
| import com.ruoyi.platform.domain.kg.KgEntityRelation; | |||
| 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 javax.validation.constraints.NotNull; | |||
| import java.util.*; | |||
| /** | |||
| @@ -25,15 +20,10 @@ public class KgEntityInfoDTO{ | |||
| @Id | |||
| private Long id; | |||
| /** | |||
| * 实体名称 | |||
| */ | |||
| private String label; | |||
| private String type; | |||
| private Map<String,Object> labelCfg; | |||
| private Map<String,Object> style; | |||
| private Integer x; | |||
| private Integer y; | |||
| private Integer depth; | |||
| private String name; | |||
| /** | |||
| * 实体描述 | |||
| @@ -50,6 +40,16 @@ public class KgEntityInfoDTO{ | |||
| */ | |||
| private String icon; | |||
| /** | |||
| * 横坐标 | |||
| */ | |||
| private Integer x; | |||
| /** | |||
| * 纵坐标 | |||
| */ | |||
| private Integer y; | |||
| /** | |||
| * 属性集合 | |||
| */ | |||
| @@ -61,4 +61,14 @@ public class KgEntityInfoDTO{ | |||
| @Relationship(type = "CONNECTS_TO", direction = Relationship.Direction.OUTGOING) | |||
| private List<KgEntityRelationDTO> relations = new ArrayList<>(); | |||
| private String type; | |||
| private Map<String,Object> labelCfg; | |||
| private Map<String,Object> style; | |||
| private Integer depth; | |||
| private String name; | |||
| } | |||
| @@ -2,10 +2,7 @@ package com.ruoyi.platform.domain.kg.dto; | |||
| import com.ruoyi.platform.domain.kg.KgEntityRelation; | |||
| import lombok.Data; | |||
| import org.springframework.data.neo4j.core.schema.Id; | |||
| 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 org.springframework.data.neo4j.core.schema.*; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| @@ -14,25 +11,30 @@ import java.util.Map; | |||
| * kg_entity_relations | |||
| */ | |||
| @Data | |||
| //@RelationshipProperties | |||
| @RelationshipProperties | |||
| public class KgEntityRelationDTO { | |||
| // @Id | |||
| private String id; | |||
| /** | |||
| * 关系主键 | |||
| */ | |||
| @RelationshipId | |||
| private Long id; | |||
| private String target; | |||
| private String source; | |||
| private Map<String, Object> labelCfg; | |||
| private Map<String, Object> style; | |||
| private Map<String, Object> startPoint; | |||
| private Map<String, Object> endPoint; | |||
| private Integer sourceAnchor; | |||
| private Integer targetAnchor; | |||
| private String type; | |||
| private List<Float> curvePosition; | |||
| private List<Float> minCurveOffset; | |||
| private Integer depth; | |||
| /** | |||
| * 起点节点id | |||
| */ | |||
| private Long target; | |||
| /** | |||
| * 终点节点id | |||
| */ | |||
| private Long source; | |||
| /** | |||
| * 关系名 | |||
| */ | |||
| private String name; | |||
| /** | |||
| * 关联实体ID | |||
| */ | |||
| @@ -44,10 +46,25 @@ public class KgEntityRelationDTO { | |||
| @TargetNode | |||
| private KgEntityInfoDTO targetEntity; | |||
| public KgEntityRelationDTO() { | |||
| } | |||
| private Map<String, Object> labelCfg; | |||
| private Map<String, Object> style; | |||
| private Map<String, Object> startPoint; | |||
| private Map<String, Object> endPoint; | |||
| private Integer sourceAnchor; | |||
| private Integer targetAnchor; | |||
| @Property("type") | |||
| private String type; | |||
| private List<Float> curvePosition; | |||
| private List<Float> minCurveOffset; | |||
| private Integer depth; | |||
| public KgEntityRelationDTO(String id) { | |||
| this.id = id; | |||
| } | |||
| } | |||
| @@ -3,5 +3,5 @@ package com.ruoyi.platform.service; | |||
| import com.ruoyi.platform.domain.kg.dto.KgEntityInfoDTO; | |||
| import org.springframework.data.neo4j.repository.Neo4jRepository; | |||
| public interface KgEntityRepository extends Neo4jRepository<KgEntityInfoDTO, String> { | |||
| public interface KgEntityRepository extends Neo4jRepository<KgEntityInfoDTO, Long> { | |||
| } | |||
| @@ -1,26 +1,20 @@ | |||
| package com.ruoyi.platform.service.impl; | |||
| import cn.hutool.core.collection.CollectionUtil; | |||
| import cn.hutool.core.map.MapUtil; | |||
| import cn.hutool.json.JSON; | |||
| import cn.hutool.json.JSONUtil; | |||
| import com.ruoyi.common.core.utils.StringUtils; | |||
| import com.ruoyi.platform.domain.kg.KgEntityProperty; | |||
| import com.ruoyi.platform.domain.kg.KgEntityRelation; | |||
| import com.ruoyi.platform.domain.kg.KgOntologyInfo; | |||
| import com.ruoyi.platform.domain.kg.dto.*; | |||
| import com.ruoyi.platform.mapper.kg.KgOntologyInfoMapper; | |||
| import com.ruoyi.platform.service.*; | |||
| import com.ruoyi.platform.utils.JsonUtils; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| import java.io.IOException; | |||
| import java.util.Collections; | |||
| import java.util.HashMap; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| import java.util.stream.Collectors; | |||
| /** | |||
| * @author Administrator | |||
| @@ -54,8 +48,8 @@ public class KgOntologyInfoServiceImpl implements KgOntologyInfoService { | |||
| 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()); | |||
| ontology.setConceptsCount(CollectionUtil.isEmpty(graphData.getNodes()) ? 0 : graphData.getNodes().size()); | |||
| ontology.setRelationsCount(CollectionUtil.isEmpty(graphData.getEdges()) ? 0 : graphData.getNodes().size()); | |||
| } | |||
| kgOntologyInfoMapper.updateByPrimaryKeySelective(ontology); | |||
| } | |||
| @@ -88,6 +82,7 @@ public class KgOntologyInfoServiceImpl implements KgOntologyInfoService { | |||
| @Override | |||
| @Transactional | |||
| public void saveGraph(GraphData graphData) { | |||
| // 存储节点 | |||
| Map<Long, KgEntityInfoDTO> nodeMap = new HashMap<>(); | |||