allen 2 年之前
父节点
当前提交
4b50f6b650

+ 2 - 0
kgraph-graph/src/main/java/com/kgraph/graph/neo4j/domain/Entity.java

@@ -13,6 +13,8 @@ public class Entity {
     @Id
     @GeneratedValue
     private Long id;
+    @Property("foreignId")
+    private String foreignId;
     @Property("code")
     private String code;
     @Property("name")

+ 2 - 0
kgraph-graph/src/main/java/com/kgraph/graph/neo4j/mapper/EntityRepository.java

@@ -33,4 +33,6 @@ public interface EntityRepository extends Neo4jRepository<Entity, Long> {
 
     @Query(value = "match (e:Entity{name: $0.name}) return e", countQuery = "match (e:Entity{name: $0.name}) return count(e)")
     Page<Entity> getPageListByName(EntityDTO dto, PageRequest page);
+
+    Entity findByForeignId(String foreignId);
 }

+ 2 - 0
kgraph-graph/src/main/java/com/kgraph/graph/neo4j/service/INeo4jEntityService.java

@@ -10,4 +10,6 @@ public interface INeo4jEntityService {
     Entity save(Entity entity);
     void delete(Long[] ids);
     Page<Entity> getPageList(EntityDTO dto);
+
+    Entity getByForeignId(String foreignId);
 }

+ 5 - 0
kgraph-graph/src/main/java/com/kgraph/graph/neo4j/service/impl/Neo4JNeo4jEntityServiceImpl.java

@@ -47,4 +47,9 @@ public class Neo4JNeo4jEntityServiceImpl implements INeo4jEntityService {
             return repository.getPageList(PageRequest.of(dto.getPageNum() - 1, dto.getPageSize()));
         }
     }
+
+    @Override
+    public Entity getByForeignId(String foreignId) {
+        return repository.findByForeignId(foreignId);
+    }
 }

+ 11 - 0
kgraph-graph/src/main/java/com/kgraph/graph/suport/domain/TBuildFlow.java

@@ -16,6 +16,9 @@ import com.kgraph.common.core.domain.BaseEntity;;
 public class TBuildFlow extends BaseEntity
 {
     private static final long serialVersionUID = 1L;
+    public static final String FID_KEY = "check_flow";
+    public static final String NAME_ENTITY_LABEL = "故障名称";
+    public static final String FLOW_ENTITY_LABEL = "故障流程";
 
     /** 序号 */
     private Long id;
@@ -39,4 +42,12 @@ public class TBuildFlow extends BaseEntity
     /** 流程树json */
     /*@Excel(name = "流程树json")*/
     private String flowTreeJson;
+
+    public String getForeignId() {
+        if (id != null) {
+            return FID_KEY + id;
+        } else {
+            return null;
+        }
+    }
 }

+ 14 - 0
kgraph-graph/src/main/java/com/kgraph/graph/suport/domain/TCheckPiont.java

@@ -14,6 +14,8 @@ import com.kgraph.common.core.domain.BaseEntity;;
 public class TCheckPiont extends BaseEntity
 {
     private static final long serialVersionUID = 1L;
+    public static final String FID_KEY = "check_point";
+    public static final String ENTITY_LABEL = "检查点";
 
     /** 序号 */
     private Long id;
@@ -26,6 +28,14 @@ public class TCheckPiont extends BaseEntity
     @Excel(name = "检查点")
     private String checkPiont;
 
+    public String getForeignId() {
+        if (id != null) {
+            return FID_KEY + id;
+        } else {
+            return null;
+        }
+    }
+
     public void setId(Long id) 
     {
         this.id = id;
@@ -66,4 +76,8 @@ public class TCheckPiont extends BaseEntity
             .append("updateTime", getUpdateTime())
             .toString();
     }
+
+    public static String getForeignIdById(Long id){
+        return FID_KEY + id;
+    }
 }

+ 53 - 16
kgraph-graph/src/main/java/com/kgraph/graph/suport/service/impl/TCheckPiontServiceImpl.java

@@ -1,13 +1,17 @@
 package com.kgraph.graph.suport.service.impl;
 
-import java.util.List;
-import com.kgraph.common.utils.DateUtils;;
-import com.kgraph.graph.suport.domain.TBuildFlow;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import com.kgraph.graph.suport.mapper.TCheckPiontMapper;
+import com.kgraph.common.utils.DateUtils;
+import com.kgraph.graph.neo4j.domain.Entity;
+import com.kgraph.graph.neo4j.service.INeo4jEntityService;
 import com.kgraph.graph.suport.domain.TCheckPiont;
+import com.kgraph.graph.suport.mapper.TCheckPiontMapper;
 import com.kgraph.graph.suport.service.ITCheckPiontService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+;
 
 /**
  * 检查点管理Service业务层处理
@@ -21,6 +25,9 @@ public class TCheckPiontServiceImpl implements ITCheckPiontService
     @Autowired
     private TCheckPiontMapper tCheckPiontMapper;
 
+    @Autowired
+    private INeo4jEntityService neo4jEntityService;
+
     /**
      * 查询检查点管理
      * 
@@ -48,27 +55,46 @@ public class TCheckPiontServiceImpl implements ITCheckPiontService
     /**
      * 新增检查点管理
      * 
-     * @param tCheckPiont 检查点管理
+     * @param checkPoint 检查点管理
      * @return 结果
      */
     @Override
-    public int insertTCheckPiont(TCheckPiont tCheckPiont)
+    public int insertTCheckPiont(TCheckPiont checkPoint)
     {
-        tCheckPiont.setCreateTime(DateUtils.getNowDate());
-        return tCheckPiontMapper.insertTCheckPiont(tCheckPiont);
+        checkPoint.setCreateTime(DateUtils.getNowDate());
+        int i = tCheckPiontMapper.insertTCheckPiont(checkPoint);
+//        saveEntity(checkPoint);
+        return i;
     }
 
     /**
      * 修改检查点管理
      * 
-     * @param tCheckPiont 检查点管理
+     * @param checkPoint 检查点管理
      * @return 结果
      */
     @Override
-    public int updateTCheckPiont(TCheckPiont tCheckPiont)
+    public int updateTCheckPiont(TCheckPiont checkPoint)
     {
-        tCheckPiont.setUpdateTime(DateUtils.getNowDate());
-        return tCheckPiontMapper.updateTCheckPiont(tCheckPiont);
+        checkPoint.setUpdateTime(DateUtils.getNowDate());
+        int i = tCheckPiontMapper.updateTCheckPiont(checkPoint);
+//        saveEntity(checkPoint);
+        return i;
+    }
+
+    private void saveEntity(TCheckPiont checkPoint) {
+        Entity entity = neo4jEntityService.getByForeignId(checkPoint.getForeignId());
+        if (entity == null) {
+            entity = new Entity();
+            entity.setForeignId(checkPoint.getForeignId());
+        }
+        List<String> labels = entity.getLabels();
+        if(!labels.contains(TCheckPiont.ENTITY_LABEL)){
+            entity.getLabels().add(TCheckPiont.ENTITY_LABEL);
+        }
+        entity.setCode(checkPoint.getCode());
+        entity.setName(checkPoint.getCheckPiont());
+        neo4jEntityService.save(entity);
     }
 
     /**
@@ -80,7 +106,14 @@ public class TCheckPiontServiceImpl implements ITCheckPiontService
     @Override
     public int deleteTCheckPiontByIds(Long[] ids)
     {
-        return tCheckPiontMapper.deleteTCheckPiontByIds(ids);
+        int i = tCheckPiontMapper.deleteTCheckPiontByIds(ids);
+//        List<Long> entityIdList = new ArrayList<>(ids.length);
+//        for(Long id : ids) {
+//            Entity entity = neo4jEntityService.getByForeignId(TCheckPiont.getForeignIdById(id));
+//            entityIdList.add(entity.getId());
+//        }
+//        neo4jEntityService.delete(entityIdList.toArray(new Long[]{}));
+        return i;
     }
 
     /**
@@ -92,7 +125,11 @@ public class TCheckPiontServiceImpl implements ITCheckPiontService
     @Override
     public int deleteTCheckPiontById(Long id)
     {
-        return tCheckPiontMapper.deleteTCheckPiontById(id);
+        int i = tCheckPiontMapper.deleteTCheckPiontById(id);
+//        Entity entity = neo4jEntityService.getByForeignId(TCheckPiont.getForeignIdById(id));
+//        Long entityId = entity.getId();
+//        neo4jEntityService.delete(new Long[]{entityId});
+        return i;
     }
 
     @Override