Bläddra i källkod

知识库,有关实例,实例关系,图谱部分开发提交

zhangenzhi 1 år sedan
förälder
incheckning
76e2e88b2b

+ 36 - 0
src/main/java/com/pavis/backend/slim/project/system/controller/SysKgController.java

@@ -3,6 +3,8 @@ package com.pavis.backend.slim.project.system.controller;
 import com.pavis.backend.slim.framework.web.domain.AjaxResult;
 import com.pavis.backend.slim.project.system.domain.SysEntity;
 import com.pavis.backend.slim.project.system.domain.SysEntityAll;
+import com.pavis.backend.slim.project.system.domain.SysEntityInstance;
+import com.pavis.backend.slim.project.system.domain.SysEntityRelation;
 import com.pavis.backend.slim.project.system.domain.SysFile;
 import com.pavis.backend.slim.project.system.domain.SysKg;
 import com.pavis.backend.slim.project.system.domain.algorithm.AlgSpO;
@@ -159,4 +161,38 @@ public class SysKgController {
     public AjaxResult updateKg(@RequestBody SysKg sysKg){
         return AjaxResult.success(kgService.updateKg(sysKg));
     }
+
+
+    @ApiOperation("实例新增或更新")
+    @PostMapping("/insOrUpdEnIce")
+    public AjaxResult insOrUpdEnIce(@RequestBody SysEntityInstance sysEntityInstance){
+        return AjaxResult.success(kgService.insOrUpdEnIce(sysEntityInstance));
+    }
+
+    @ApiOperation("实例删除")
+    @PostMapping("/delEnIce")
+    public AjaxResult delEnIce(@RequestBody FileKey fileKey){
+        kgService.delEnIce(fileKey);
+        return AjaxResult.success();
+    }
+
+    @ApiOperation("删除实例关系")
+    @PostMapping("/delEntRlation")
+    public AjaxResult delEntRlation(@RequestBody FileKey fileKey){
+        kgService.delEntRlation(fileKey);
+        return AjaxResult.success();
+    }
+
+    @ApiOperation("查询实体关系下的实例关系")
+    @PostMapping("/selEntAndEntRela")
+    public AjaxResult selEntAndEntRela(@RequestBody FileKey fileKey){
+        return AjaxResult.success(kgService.selEntAndEntRela(fileKey));
+    }
+
+    @ApiOperation("新增或更新实例关系")
+    @PostMapping("/insOrUpdRelation")
+    public AjaxResult insOrUpdRelation(@RequestBody SysEntityRelation sysEntityRelation){
+        kgService.insOrUpdRelation(sysEntityRelation);
+        return AjaxResult.success();
+    }
 }

+ 12 - 0
src/main/java/com/pavis/backend/slim/project/system/domain/SysEntityInstance.java

@@ -50,6 +50,18 @@ public class SysEntityInstance extends BaseEntity {
      */
     private String kgId;
 
+    /**
+     * 属性集合
+     */
+    private String attributeAll;
+
+    public String getAttributeAll() {
+        return attributeAll;
+    }
+
+    public void setAttributeAll(String attributeAll) {
+        this.attributeAll = attributeAll;
+    }
 
     public String getKgId() {
         return kgId;

+ 18 - 0
src/main/java/com/pavis/backend/slim/project/system/domain/front/ClutterReturn.java

@@ -0,0 +1,18 @@
+package com.pavis.backend.slim.project.system.domain.front;
+
+
+import com.pavis.backend.slim.project.system.domain.SysEntityInstance;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+/**
+ * @Author
+ */
+public class ClutterReturn {
+
+    private List<SysEntityInstance> startList;
+
+    private List<SysEntityInstance> entList;
+}

+ 14 - 0
src/main/java/com/pavis/backend/slim/project/system/domain/front/FileKey.java

@@ -5,6 +5,8 @@ import io.swagger.annotations.ApiModelProperty;
 import io.swagger.annotations.ApiOperation;
 import lombok.Data;
 
+import java.util.List;
+
 @Data
 /**
  * 文件搜索类
@@ -49,4 +51,16 @@ public class FileKey extends SysFile {
     @ApiModelProperty("关键字")
     private String keyWord;
 
+    @ApiModelProperty("实例id的集合")
+    private List<String> enIceIds;
+
+    @ApiModelProperty("实例关系id的集合")
+    private List<String> enRelationIds;
+
+    @ApiModelProperty("起始实体")
+    private String start;
+
+    @ApiModelProperty("终点实体")
+    private String end;
+
 }

+ 35 - 0
src/main/java/com/pavis/backend/slim/project/system/service/SysKgService.java

@@ -5,8 +5,10 @@ import com.github.pagehelper.PageInfo;
 import com.pavis.backend.slim.project.system.domain.SysEntity;
 import com.pavis.backend.slim.project.system.domain.SysEntityAll;
 import com.pavis.backend.slim.project.system.domain.SysEntityInstance;
+import com.pavis.backend.slim.project.system.domain.SysEntityRelation;
 import com.pavis.backend.slim.project.system.domain.SysKg;
 import com.pavis.backend.slim.project.system.domain.algorithm.AlgSpO;
+import com.pavis.backend.slim.project.system.domain.front.ClutterReturn;
 import com.pavis.backend.slim.project.system.domain.front.FileKey;
 import com.pavis.backend.slim.project.system.domain.front.InKgParameter;
 import com.pavis.backend.slim.project.system.domain.front.KgReturn;
@@ -127,4 +129,37 @@ public interface SysKgService extends IService<SysKg> {
      * @return 图谱详情
      */
     SysKg updateKg(SysKg sysKg);
+
+    /**
+     * 实例新增或更新
+     * @param sysEntityInstance
+     * @return
+     */
+    SysEntityInstance insOrUpdEnIce(SysEntityInstance sysEntityInstance);
+
+    /**
+     * 实例新增或更新
+     * @param fileKey
+     * @return
+     */
+    void delEnIce(FileKey fileKey);
+
+    /**
+     * 删除实例关系
+     * @param fileKey
+     */
+    void delEntRlation(FileKey fileKey);
+
+    /**
+     * 查询实体关系下的实例关系
+     * @param fileKey
+     * @return
+     */
+    ClutterReturn selEntAndEntRela(FileKey fileKey);
+
+    /**
+     * 新增或更新实例关系
+     * @param sysEntityRelation
+     */
+    void insOrUpdRelation(SysEntityRelation sysEntityRelation);
 }

+ 124 - 8
src/main/java/com/pavis/backend/slim/project/system/service/impl/SysKgServiceImpl.java

@@ -22,6 +22,7 @@ import com.pavis.backend.slim.project.system.domain.SysKgEntity;
 import com.pavis.backend.slim.project.system.domain.SysKgRelation;
 import com.pavis.backend.slim.project.system.domain.SysRelation;
 import com.pavis.backend.slim.project.system.domain.algorithm.AlgSpO;
+import com.pavis.backend.slim.project.system.domain.front.ClutterReturn;
 import com.pavis.backend.slim.project.system.domain.front.FileKey;
 import com.pavis.backend.slim.project.system.domain.front.InKgParameter;
 import com.pavis.backend.slim.project.system.domain.front.KgReturn;
@@ -178,6 +179,8 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
     public void algorithm(AlgSpO algSpO) {
         log.info("算法传参map:{}", JSON.toJSONString(algSpO));
         // todo 先这么做,以后还需改动
+        sysEntityInstanceMapper.delete(new QueryWrapper<SysEntityInstance>().eq("kg_id", algSpO.getKgId()));
+        sysEntityRelationMapper.delete(new QueryWrapper<SysEntityRelation>().eq("kg_id", algSpO.getKgId()));
         Integer integer = 0;
         String oCopy = "";
         String sCopy = "";
@@ -185,7 +188,7 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
             for (Map map : algSpO.getSpo()) {
                 if (map.get("s") != null) {
                     // check库里是否存在此值
-                    String s = md5Check(MD5.create().digestHex16((String) map.get("s")));
+                    String s = md5Check(MD5.create().digestHex16((String) map.get("s")), algSpO.getKgId());
                     // 临时变量,将起点id赋值给sCopy,最后用于实例关系插入时使用
                     if (s.equals("false")) {
                         // 插入起始点实例
@@ -205,7 +208,7 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
                     }
                 }
                 if (map.get("o") != null) {
-                    String o = md5Check(MD5.create().digestHex16((String) map.get("o")));
+                    String o = md5Check(MD5.create().digestHex16((String) map.get("o")), algSpO.getKgId());
                     if (o.equals("false")) {
                         // 插入终点实例
                         SysEntityInstance sysEntityInstanceO = new SysEntityInstance();
@@ -228,7 +231,8 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
                     List<SysEntityRelation> list = sysEntityRelationMapper.selectList(new QueryWrapper<SysEntityRelation>()
                             .eq("kg_id", algSpO.getKgId())
                             .eq("start_id", sCopy)
-                            .eq("end_id", oCopy));
+                            .eq("end_id", oCopy)
+                    );
                     if (list.size() == Hodgepodge.NUMBER) {
                         // 插入实例关系
                         SysEntityRelation sysEntityRelation = new SysEntityRelation();
@@ -253,9 +257,11 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
      * @param instanceId 唯一id
      * @return 如果库里有值,直接将库里的值返回;如果没有,则返回false
      */
-    public String md5Check(String instanceId) {
+    public String md5Check(String instanceId, String kgId) {
         List<SysEntityInstance> listEIM = sysEntityInstanceMapper.selectList(new QueryWrapper<SysEntityInstance>()
-                .eq("instance_id", instanceId));
+                .eq("instance_id", instanceId)
+                .eq("kg_id", kgId)
+        );
         if (listEIM.size() > 0) {
             return listEIM.get(0).getInstanceId();
         } else {
@@ -608,7 +614,7 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
                     .like("end", keyEntityRelation.getKeyWord())
             ;
         }
-        // zez 根据实体名字查询实例关系
+        // zez 根据实体名字模糊查询实例关系
         if (Hodgepodge.ZERO_STR.equals(keyEntityRelation.getEntOrRel())) {
             if (keyEntityRelation.getEntityName() != null && !"".equals(keyEntityRelation.getEntityName())) {
                 queryWrap
@@ -622,11 +628,11 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
             }
         }
 
-        // zez 根据实体关系查询关系
+        // zez 根据实体关系模糊查询关系
         if (Hodgepodge.ONE_STR.equals(keyEntityRelation.getEntOrRel())) {
             if (keyEntityRelation.getEntityRelation() != null && !"".equals(keyEntityRelation.getEntityRelation())) {
                 queryWrap
-                        .eq("entity_relation", "-" + keyEntityRelation.getEntityRelation() + "-")
+                        .like("entity_relation", "-" + keyEntityRelation.getEntityRelation() + "-")
                         .eq("kg_id", keyEntityRelation.getKgId());
                 PageHelper.startPage(keyEntityRelation.getPageNum(), keyEntityRelation.getPageSize());
                 List<SysEntityRelation> sysEntityRelations = sysEntityRelationMapper.selectList(queryWrap);
@@ -674,4 +680,114 @@ public class SysKgServiceImpl extends ServiceImpl<SysKgMapper, SysKg> implements
         baseMapper.updateById(sysKg);
         return sysKg;
     }
+
+    @Override
+    public SysEntityInstance insOrUpdEnIce(SysEntityInstance sysEntityInstance) {
+        log.info("******接口(insOrUpdEnIce)--->入参(sysEntityInstance):{}", JSON.toJSONString(sysEntityInstance));
+        String s = md5Check(MD5.create().digestHex16(sysEntityInstance.getName()), sysEntityInstance.getKgId());
+        Long userId = SecurityUtils.getUserId();
+        if ("false".equals(s)) {
+            sysEntityInstance.setUserId(userId);
+            sysEntityInstance.setCreateBy(String.valueOf(userId));
+            sysEntityInstance.setCreateTime(new Date());
+            sysEntityInstance.setInstanceId(MD5.create().digestHex16(sysEntityInstance.getName()));
+            sysEntityInstanceMapper.insert(sysEntityInstance);
+        } else {
+            sysEntityInstance.setUpdateBy(String.valueOf(userId));
+            sysEntityInstance.setUpdateTime(new Date());
+            sysEntityInstanceMapper.update(sysEntityInstance, new UpdateWrapper<SysEntityInstance>()
+                    .eq("instance_id", sysEntityInstance.getInstanceId())
+                    .eq("kg_id", sysEntityInstance.getKgId())
+            );
+        }
+        return sysEntityInstance;
+    }
+
+
+    @Override
+    public void delEnIce(FileKey fileKey) {
+        log.info("*****接口(delEnIce)--->入参(fileKey):{}", JSON.toJSONString(fileKey));
+        if (fileKey.getEnIceIds().size() > 0 && fileKey.getKgId() != null) {
+            for (String id : fileKey.getEnIceIds()) {
+                //删除关于此点的所有关系 根据起点和终点去进行删除
+                sysEntityRelationMapper.delete(new QueryWrapper<SysEntityRelation>()
+                        .eq("kg_id", fileKey.getKgId())
+                        .eq("start_id", id)
+                );
+
+                sysEntityRelationMapper.delete(new QueryWrapper<SysEntityRelation>()
+                        .eq("kg_id", fileKey.getKgId())
+                        .eq("end_id", id)
+                );
+
+                sysEntityInstanceMapper.delete(new QueryWrapper<SysEntityInstance>()
+                        .eq("instance_id", id)
+                        .eq("kg_id", fileKey.getKgId())
+                );
+            }
+            log.info("******实体-删除成功******");
+        }
+    }
+
+    @Override
+    public void delEntRlation(FileKey fileKey) {
+        log.info("*****接口(delEntRlation)--->入参(fileKey):{}", JSON.toJSONString(fileKey));
+        if (fileKey.getEnRelationIds().size() > 0 && fileKey.getKgId() != null && !"".equals(fileKey.getKgId())) {
+            for (String id : fileKey.getEnRelationIds()) {
+                sysEntityRelationMapper.delete(new QueryWrapper<SysEntityRelation>()
+                        .eq("id", id)
+                        .eq("kg_id", fileKey.getKgId())
+                );
+            }
+            log.info("******实体关系-删除成功******");
+        }
+    }
+
+    @Override
+    public ClutterReturn selEntAndEntRela(FileKey fileKey) {
+        log.info("*****接口(selEntAndEntRela)--->入参(fileKey):{}", JSON.toJSONString(fileKey));
+        ClutterReturn clutterReturn = new ClutterReturn();
+        if (fileKey.getStart() != null && fileKey.getEnd() != null && !"".equals(fileKey.getStart()) && !"".equals(fileKey.getEnd()) && fileKey.getKgId() != null && !"".equals(fileKey.getKgId())) {
+            List<SysEntityInstance> startList = sysEntityInstanceMapper.selectList(new QueryWrapper<SysEntityInstance>()
+                    .eq("entity_name", fileKey.getStart())
+                    .eq("kg_id", fileKey.getKgId())
+            );
+            List<SysEntityInstance> endList = sysEntityInstanceMapper.selectList(new QueryWrapper<SysEntityInstance>()
+                    .eq("entity_name", fileKey.getEnd())
+                    .eq("kg_id", fileKey.getKgId())
+            );
+            clutterReturn.setEntList(endList);
+            clutterReturn.setStartList(startList);
+        }
+        log.info("*****接口(selEntAndEntRela)--->出参(clutterReturn):{}", JSON.toJSONString(clutterReturn));
+        return clutterReturn;
+    }
+
+    @Override
+    public void insOrUpdRelation(SysEntityRelation sysEntityRelation) {
+        log.info("*****接口(insOrUpdRelation)--->入参(sysEntityRelation):{}", JSON.toJSONString(sysEntityRelation));
+        // zez 获取登录人id
+        Long userId = SecurityUtils.getUserId();
+        // 效验一下,数据库中,是否存在。如果存在,则进行提醒,如果不存在,则新增
+        List<SysEntityRelation> sysEntityRelations = sysEntityRelationMapper.selectList(new QueryWrapper<SysEntityRelation>()
+                .eq("start", sysEntityRelation.getStart())
+                .eq("end", sysEntityRelation.getEnd())
+                .eq("relation",sysEntityRelation.getRelation())
+                .eq("kg_id",sysEntityRelation.getKgId())
+        );
+        if (sysEntityRelations.size() == 0) {
+            if (sysEntityRelation.getId() != null && !"".equals(sysEntityRelation.getId())) {
+                sysEntityRelation.setUpdateBy(String.valueOf(userId));
+                sysEntityRelation.setUpdateTime(new Date());
+                sysEntityRelationMapper.updateById(sysEntityRelation);
+            } else {
+                sysEntityRelation.setCreateBy(String.valueOf(userId));
+                sysEntityRelation.setCreateTime(new Date());
+                sysEntityRelation.setUserId(userId);
+                sysEntityRelationMapper.insert(sysEntityRelation);
+            }
+        } else {
+            throw new RuntimeException("数据库中已存在该关系,请重新填写!");
+        }
+    }
 }