|
|
@@ -1,10 +1,16 @@
|
|
|
package com.onemap.apply.service.dimentity.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
+import com.onemap.apply.domain.dimentity.DimEntityDto;
|
|
|
import com.onemap.apply.domain.dimentity.EntityCodeTreeVo;
|
|
|
+import com.onemap.apply.domain.dimentity.EntityRelationshipToNeo4jVo;
|
|
|
import com.onemap.apply.domain.dimentity.EntityRelationshipVo;
|
|
|
import com.onemap.apply.mapper.dimentity.DimEntityMapper;
|
|
|
+import com.onemap.apply.mapper.dimentity.DimEntityReponsitory;
|
|
|
import com.onemap.apply.service.dimentity.DimEntityService;
|
|
|
import com.onemap.common.core.utils.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.neo4j.core.Neo4jClient;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;;
|
|
|
@@ -14,6 +20,10 @@ import java.util.*;
|
|
|
public class DimEntityServiceImpl implements DimEntityService {
|
|
|
@Resource
|
|
|
private DimEntityMapper dimEntityMapper;
|
|
|
+ @Autowired
|
|
|
+ private Neo4jClient neo4jClient;
|
|
|
+ @Autowired
|
|
|
+ private DimEntityReponsitory dimEntityReponsitory;
|
|
|
|
|
|
@Override
|
|
|
public List<EntityCodeTreeVo> queryEntityCodeTableTree(String id) {
|
|
|
@@ -59,13 +69,16 @@ public class DimEntityServiceImpl implements DimEntityService {
|
|
|
result.put("info", d0_EntityData);
|
|
|
//查询空间详细数据
|
|
|
List<Map<String, Object>> geomList = new ArrayList<Map<String, Object>>();
|
|
|
- for (EntityRelationshipVo relationshipVo : relationshipVos) {
|
|
|
- geomList.add(dimEntityMapper.queryEntityGeomDataByEntityId(relationshipVo.getTylayer(), relationshipVo.getElementid()));
|
|
|
+ if (d0_EntityData != null) {
|
|
|
+ for (EntityRelationshipVo relationshipVo : relationshipVos) {
|
|
|
+ geomList.add(dimEntityMapper.queryEntityGeomDataByEntityId(relationshipVo.getTylayer(), relationshipVo.getElementid()));
|
|
|
+ }
|
|
|
}
|
|
|
result.put("geom", geomList);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private void createView(String viewTableName) {
|
|
|
//判斷视图是否存在
|
|
|
List<String> viewsList = dimEntityMapper.querySchemaTableByName("vector", viewTableName);
|
|
|
@@ -110,30 +123,146 @@ public class DimEntityServiceImpl implements DimEntityService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private List<EntityCodeTreeVo> queryEntityCodeTableTreeDatabak(String code, Integer level, String viewTableName) {
|
|
|
- Long count = 0L;
|
|
|
- List<EntityCodeTreeVo> entityCodeTreeVos = dimEntityMapper.queryEntityCodeTable(code, level);
|
|
|
- if (level < 4) {
|
|
|
- for (EntityCodeTreeVo entityCodeTreeVo : entityCodeTreeVos) {
|
|
|
- entityCodeTreeVo.setCount(0L);
|
|
|
- List<String> d0_tables = dimEntityMapper.queryTablesNameByViewCode(viewTableName, entityCodeTreeVo.getId());
|
|
|
- if (d0_tables.size() > 0) {
|
|
|
- entityCodeTreeVo.setCount(dimEntityMapper.queryEntityCodeTableCountByCode(entityCodeTreeVo.getId(), d0_tables));
|
|
|
- }
|
|
|
-// entityCodeTreeVo.setChildren(queryEntityCodeTableTreeData(entityCodeTreeVo.getId(), level + 1, viewTableName));
|
|
|
+ @Override
|
|
|
+ public void createEntityRelationshipToNeo4j(EntityRelationshipToNeo4jVo entityRelationshipToNeo4jVo) {
|
|
|
+ // String cql = "match (a:Entity {entityid:'MA1001NE103K1034230XXXXXXXXXXXXX2501010009'}), (b:Entity {entityid:'MA1001NE103K103423043622XXXXXXXX2301010018'}) MERGE (a)-[r:关系]->(b)";
|
|
|
+ String cql = "match " + "(a:Entity {entityid:'" + entityRelationshipToNeo4jVo.getEntityid() + "'})," + "(b:Entity {entityid:'" + entityRelationshipToNeo4jVo.getComentityid() + "'}) " + " MERGE (a)-[r:" + entityRelationshipToNeo4jVo.getComrelation() + "]->(b) ";
|
|
|
+ neo4jClient.query(cql).run();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public DimEntityDto addEntityToNeo4j(DimEntityDto dimEntityDto) {
|
|
|
+ return dimEntityReponsitory.save(dimEntityDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void removeAllEntityToNeo4j() {
|
|
|
+ dimEntityReponsitory.deleteAll();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void removeOneEntityToNeo4j(String entityid) {
|
|
|
+ dimEntityReponsitory.deleteById(entityid);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<DimEntityDto> addEntityListToNeo4j(List<DimEntityDto> dimEntityDtos) {
|
|
|
+ return dimEntityReponsitory.saveAll(dimEntityDtos);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> queryEntityRelationshipToNeo4j(String entityid) {
|
|
|
+ Map<String, Object> retMap = new HashMap<>();
|
|
|
+// String sql = "match (n:Entity{ entityid:'MA1001NE103K1034230XXXXXXXXXXXXX2501010009'}) <-[r]->(b:Entity) return b.entityid, type(r)";
|
|
|
+ String sql = "match (n:Entity{ entityid:'" + entityid + "'}) <-[r]->(b:Entity) " +
|
|
|
+ "return n.entityid as entityid, n.entilayer as entilayer, " +
|
|
|
+ " b.entityid as comentityid, b.entilayer as comilayer, " +
|
|
|
+ "type(r) as comrelation";
|
|
|
+ System.out.println("cql:" + sql);
|
|
|
+ Collection<Map<String, Object>> links = neo4jClient.query(sql).fetch().all();
|
|
|
+ if (links.isEmpty()) {
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+ retMap.put("links", links);
|
|
|
+
|
|
|
+ List<Map<String, Object>> dataList = new ArrayList<>();
|
|
|
+ Set<String> dataSet = new HashSet<>();
|
|
|
+ for (Map<String, Object> doMap : links) {
|
|
|
+ String comentityid = (String) doMap.get("comentityid");
|
|
|
+ if (!dataSet.contains(comentityid)) {
|
|
|
+ dataList.add(queryEntityData(comentityid));
|
|
|
+ dataSet.add(comentityid);
|
|
|
}
|
|
|
- } else {
|
|
|
- for (EntityCodeTreeVo entityCodeTreeVo : entityCodeTreeVos) {
|
|
|
- entityCodeTreeVo.setCount(0L);
|
|
|
- List<String> d0_tables = dimEntityMapper.queryTablesNameByViewCode(viewTableName, entityCodeTreeVo.getId());
|
|
|
- if (d0_tables.size() > 0) {
|
|
|
- entityCodeTreeVo.setCount(dimEntityMapper.queryEntityCodeTableCountByCode(entityCodeTreeVo.getId(), d0_tables));
|
|
|
-// entityCodeTreeVo.setChildren(dimEntityMapper.queryEntityCodeTableTreeDataByCode(entityCodeTreeVo.getId(), d0_tables));
|
|
|
-// entityCodeTreeVo.setCount((long) entityCodeTreeVo.getChildren().size());
|
|
|
+ }
|
|
|
+ retMap.put("data", dataList);
|
|
|
+ return retMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void TestToNe04j() {
|
|
|
+ System.out.println("TestToNe04j.............");
|
|
|
+ //创建视图
|
|
|
+// String viewTableName = StringUtils.getTemporaryTableName();
|
|
|
+ //添加测试数据
|
|
|
+// DimEntityDto dimEntityDto_do = new DimEntityDto();
|
|
|
+// dimEntityDto_do.setEntityid(viewTableName);
|
|
|
+// dimEntityDto_do.setEntilayer(viewTableName);
|
|
|
+// DimEntityDto dimEntityDto_d2 = addEntityToNeo4j(dimEntityDto_do);
|
|
|
+// System.out.println(dimEntityDto_d2.toString());
|
|
|
+
|
|
|
+ //删除单条数据
|
|
|
+// removeOneEntityToNeo4j("temporary_1735180866846_203031d59ffb4c178fb1c193b2585657");
|
|
|
+
|
|
|
+ //创建关系
|
|
|
+// String viewTableNamed1 = StringUtils.getTemporaryTableName();
|
|
|
+// DimEntityDto dimEntityDto_d1 = new DimEntityDto();
|
|
|
+// dimEntityDto_d1.setEntityid(viewTableNamed1);
|
|
|
+// dimEntityDto_d1.setEntilayer(viewTableNamed1);
|
|
|
+// DimEntityDto dimEntityDto_d2 = addEntityToNeo4j(dimEntityDto_d1);
|
|
|
+// System.out.println(dimEntityDto_d2.toString());
|
|
|
+// String viewTableNamed2 = StringUtils.getTemporaryTableName();
|
|
|
+// DimEntityDto dimEntityDto_d3 = new DimEntityDto();
|
|
|
+// dimEntityDto_d3.setEntityid(viewTableNamed2);
|
|
|
+// dimEntityDto_d3.setEntilayer(viewTableNamed2);
|
|
|
+// DimEntityDto dimEntityDto_d4 = addEntityToNeo4j(dimEntityDto_d3);
|
|
|
+// System.out.println(dimEntityDto_d4.toString());
|
|
|
+//
|
|
|
+// EntityRelationshipToNeo4jVo entityRelationshipToNeo4jVod5 = new EntityRelationshipToNeo4jVo();
|
|
|
+// entityRelationshipToNeo4jVod5.setEntilayer(dimEntityDto_d2.getEntilayer());
|
|
|
+// entityRelationshipToNeo4jVod5.setEntityid(dimEntityDto_d2.getEntityid());
|
|
|
+// entityRelationshipToNeo4jVod5.setComilayer(dimEntityDto_d4.getEntilayer());
|
|
|
+// entityRelationshipToNeo4jVod5.setComentityid(dimEntityDto_d4.getEntityid());
|
|
|
+// entityRelationshipToNeo4jVod5.setComrelation("正向");
|
|
|
+// createEntityRelationshipToNeo4j(entityRelationshipToNeo4jVod5);
|
|
|
+//
|
|
|
+// EntityRelationshipToNeo4jVo entityRelationshipToNeo4jVod6 = new EntityRelationshipToNeo4jVo();
|
|
|
+// entityRelationshipToNeo4jVod6.setEntilayer(dimEntityDto_d4.getEntilayer());
|
|
|
+// entityRelationshipToNeo4jVod6.setEntityid(dimEntityDto_d4.getEntityid());
|
|
|
+// entityRelationshipToNeo4jVod6.setComilayer(dimEntityDto_d2.getEntilayer());
|
|
|
+// entityRelationshipToNeo4jVod6.setComentityid(dimEntityDto_d2.getEntityid());
|
|
|
+// entityRelationshipToNeo4jVod6.setComrelation("反向");
|
|
|
+// createEntityRelationshipToNeo4j(entityRelationshipToNeo4jVod6);
|
|
|
+
|
|
|
+ //查询关系,并返回结果
|
|
|
+ // MA1001NE103K1034230XXXXXXXXXXXXX2501010009
|
|
|
+// Map<String, Object> RelationshipDatad0 = queryEntityRelationshipToNeo4j("MA1001NE103K1034230XXXXXXXXXXXXX2501010009");
|
|
|
+// System.out.println(JSON.toJSONString(RelationshipDatad0));
|
|
|
+
|
|
|
+ //清除所有
|
|
|
+// removeAllEntityToNeo4j();
|
|
|
+
|
|
|
+ //批量添加数据及关系
|
|
|
+ List<String> tablesListd0 = dimEntityMapper.querySchemaTableByName("vector", "实体关系表");
|
|
|
+ Set<String> tableSetd0 = new HashSet<>();
|
|
|
+ for (String tableName : tablesListd0) {
|
|
|
+ List<EntityRelationshipToNeo4jVo> list = dimEntityMapper.queryRelationshipDateByTableName(tableName);
|
|
|
+ for (EntityRelationshipToNeo4jVo entityRelationshipToNeo4jVo : list) {
|
|
|
+ String d0 = entityRelationshipToNeo4jVo.getComentityid();
|
|
|
+ String d1 = entityRelationshipToNeo4jVo.getComilayer();
|
|
|
+ if (!tableSetd0.contains(d0)) {
|
|
|
+ DimEntityDto dimEntityDto_d1 = new DimEntityDto();
|
|
|
+ dimEntityDto_d1.setEntityid(d0);
|
|
|
+ dimEntityDto_d1.setEntilayer(d1);
|
|
|
+ addEntityToNeo4j(dimEntityDto_d1);
|
|
|
+ tableSetd0.add(d0);
|
|
|
+ }
|
|
|
+
|
|
|
+ String d2 = entityRelationshipToNeo4jVo.getEntityid();
|
|
|
+ String d3 = entityRelationshipToNeo4jVo.getEntilayer();
|
|
|
+ if (!tableSetd0.contains(d2)) {
|
|
|
+ DimEntityDto dimEntityDto_d1 = new DimEntityDto();
|
|
|
+ dimEntityDto_d1.setEntityid(d2);
|
|
|
+ dimEntityDto_d1.setEntilayer(d3);
|
|
|
+ addEntityToNeo4j(dimEntityDto_d1);
|
|
|
+ tableSetd0.add(d2);
|
|
|
}
|
|
|
+ createEntityRelationshipToNeo4j(entityRelationshipToNeo4jVo);
|
|
|
}
|
|
|
}
|
|
|
- return entityCodeTreeVos;
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|