Эх сурвалжийг харах

二维实体相关接口,图层树和实体结果

DESKTOP-2K9OVK9\siwei 6 сар өмнө
parent
commit
d871e598b4

+ 5 - 0
onemap-modules/onemap-apply/pom.xml

@@ -172,6 +172,11 @@
             <artifactId>metadata-extractor</artifactId>
             <version>2.18.0</version>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-neo4j</artifactId>
+<!--            <version>3.4.1</version>-->
+        </dependency>
     </dependencies>
 
     <build>

+ 74 - 0
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/controller/dimentity/DimEntityController.java

@@ -0,0 +1,74 @@
+package com.onemap.apply.controller.dimentity;
+
+import com.onemap.apply.domain.dimentity.DimEntityDto;
+import com.onemap.apply.mapper.dimentity.DimEntityReponsitory;
+import com.onemap.apply.service.dimentity.DimEntityService;
+import com.onemap.common.core.web.domain.RequestResult;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.neo4j.core.Neo4jClient;
+import org.springframework.data.neo4j.core.Neo4jTemplate;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Map;
+
+@RestController
+@RequestMapping("dimentity")
+public class DimEntityController {
+
+    @Autowired
+    private DimEntityReponsitory dimEntityReponsitory;
+    @Autowired
+    private Neo4jClient neo4jClient;
+    @Resource
+    private DimEntityService dimEntityService;
+
+    @GetMapping("/entity/code/table/tree")
+    public RequestResult queryEntityCodeTableTree() throws IOException {
+        return RequestResult.success(dimEntityService.queryEntityCodeTableTree());
+    }
+
+    @GetMapping("/entity/data")
+    public RequestResult queryEntityData(String entityid) throws IOException {
+        return RequestResult.success(dimEntityService.queryEntityData(entityid));
+    }
+
+
+//    @GetMapping("/test")
+//    public RequestResult test() throws IOException {
+////        List<DimEntityDto> dtoList = dimEntityReponsitory.findAll();
+////        MovieEntity movieEntity = new MovieEntity("电影名001", "电影名001");
+////        movieRepository.save(movieEntity);
+////        return RequestResult.success(movieRepository.findAll());
+//
+////        dimEntityReponsitory.findEntityRelationships3();
+////        DimEntityDto f = new DimEntityDto();
+////        f.setEntityid("MA1001NE103K1034230XXXXXXXXXXXXX2501010009");
+////        dimEntityReponsitory.findAll()
+//
+//
+//        DimEntityDto g = dimEntityReponsitory.findEntityRelationships4("MA1001NE103K1034230XXXXXXXXXXXXX2501010009");
+//        System.out.println(g);
+//
+////        dimEntityReponsitory.findEntityRelationships5("MA1001NE103K1034230XXXXXXXXXXXXX2501010009", "MA1001NE103K103423043622XXXXXXXX2301010018", "12");
+//
+////        String relationshipType="12";
+////        // 构建 Cypher 查询来创建关系
+////        String cypherQuery = "MATCH (a:Person {id: $personId1}), (b:Person {id: $personId2}) " +
+////                "CREATE (a)-[r:" + relationshipType + "]->(b) " +
+////                "RETURN r";
+//
+//        String cql = "match (a:Entity {entityid:'MA1001NE103K1034230XXXXXXXXXXXXX2501010009'}), (b:Entity {entityid:'MA1001NE103K103423043622XXXXXXXX2301010018'}) MERGE (a)-[r:关系]->(b)";
+//        neo4jClient.query(cql).run();
+//
+//        Collection<Map<String, Object>> all = neo4jClient
+//                .query("match (n:Entity{ entityid:'MA1001NE103K1034230XXXXXXXXXXXXX2501010009'}) <-[r]->(b:Entity)  return b.entityid, type(r)")
+//                .fetch().all();
+//        return RequestResult.success(all);
+//    }
+
+}

+ 36 - 0
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/domain/dimentity/DimEntityDto.java

@@ -0,0 +1,36 @@
+package com.onemap.apply.domain.dimentity;
+
+import org.springframework.data.neo4j.core.schema.Id;
+import org.springframework.data.neo4j.core.schema.Node;
+
+@Node("Entity")
+public class DimEntityDto {
+    @Id
+    private String entityid;
+
+    private String entilayer;
+
+    public String getEntityid() {
+        return entityid;
+    }
+
+    public void setEntityid(String entityid) {
+        this.entityid = entityid;
+    }
+
+    public String getEntilayer() {
+        return entilayer;
+    }
+
+    public void setEntilayer(String entilayer) {
+        this.entilayer = entilayer;
+    }
+
+    @Override
+    public String toString() {
+        return "DimEntityDto{" +
+                "entityid='" + entityid + '\'' +
+                ", entilayer='" + entilayer + '\'' +
+                '}';
+    }
+}

+ 23 - 0
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/domain/dimentity/DimEntityVo.java

@@ -0,0 +1,23 @@
+package com.onemap.apply.domain.dimentity;
+
+public class DimEntityVo {
+    private String a;
+
+    private String b;
+
+    public String getA() {
+        return a;
+    }
+
+    public void setA(String a) {
+        this.a = a;
+    }
+
+    public String getB() {
+        return b;
+    }
+
+    public void setB(String b) {
+        this.b = b;
+    }
+}

+ 52 - 0
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/domain/dimentity/EntityCodeTreeVo.java

@@ -0,0 +1,52 @@
+package com.onemap.apply.domain.dimentity;
+
+import java.util.List;
+
+public class EntityCodeTreeVo {
+
+    private List<EntityCodeTreeVo> children;
+    private String label; //显示名称
+    private String id;
+    private boolean disabled = true;
+    private Long count = 0L;
+
+    public String getLabel() {
+        return label;
+    }
+
+    public void setLabel(String label) {
+        this.label = label;
+    }
+
+    public List<EntityCodeTreeVo> getChildren() {
+        return children;
+    }
+
+    public void setChildren(List<EntityCodeTreeVo> children) {
+        this.children = children;
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public boolean isDisabled() {
+        return disabled;
+    }
+
+    public void setDisabled(boolean disabled) {
+        this.disabled = disabled;
+    }
+
+    public Long getCount() {
+        return count;
+    }
+
+    public void setCount(Long count) {
+        this.count = count;
+    }
+}

+ 34 - 0
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/domain/dimentity/EntityRelationshipDTO.java

@@ -0,0 +1,34 @@
+package com.onemap.apply.domain.dimentity;
+
+import org.dom4j.Entity;
+import org.neo4j.driver.types.Relationship;
+
+public class EntityRelationshipDTO {
+    private Entity entity;          // 原始 Entity 节点
+    private Relationship relationship;  // 关系
+    private Entity targetEntity;    // 目标 Entity 节点
+
+    public Relationship getRelationship() {
+        return relationship;
+    }
+
+    public void setRelationship(Relationship relationship) {
+        this.relationship = relationship;
+    }
+
+    public Entity getTargetEntity() {
+        return targetEntity;
+    }
+
+    public void setTargetEntity(Entity targetEntity) {
+        this.targetEntity = targetEntity;
+    }
+
+    public Entity getEntity() {
+        return entity;
+    }
+
+    public void setEntity(Entity entity) {
+        this.entity = entity;
+    }
+}

+ 23 - 0
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/domain/dimentity/EntityRelationshipVo.java

@@ -0,0 +1,23 @@
+package com.onemap.apply.domain.dimentity;
+
+public class EntityRelationshipVo {
+
+    private String tylayer; //图层表名
+    private String elementid; //关联数据
+
+    public String getElementid() {
+        return elementid;
+    }
+
+    public void setElementid(String elementid) {
+        this.elementid = elementid;
+    }
+
+    public String getTylayer() {
+        return tylayer;
+    }
+
+    public void setTylayer(String tylayer) {
+        this.tylayer = tylayer;
+    }
+}

+ 66 - 0
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/mapper/dimentity/DimEntityMapper.java

@@ -0,0 +1,66 @@
+package com.onemap.apply.mapper.dimentity;
+
+import com.onemap.apply.domain.dimentity.EntityCodeTreeVo;
+import com.onemap.apply.domain.dimentity.EntityRelationshipVo;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+import java.util.Map;
+
+public interface DimEntityMapper {
+
+    List<EntityCodeTreeVo> queryEntityCodeTable(@Param("code") String code, @Param("level") Integer level);
+
+    /**
+     * 根据实体分类,通過表名 ,获取个数
+     *
+     * @param code
+     * @param tablesName
+     * @return
+     */
+    Long queryEntityCodeTableCountByCode(@Param("code") String code, @Param("tables") List<String> tablesName);
+
+    /**
+     * 根据实体分类,通過表名 ,获取实体名称,用于树结构
+     *
+     * @param code
+     * @param tablesName
+     * @return
+     */
+    List<EntityCodeTreeVo> queryEntityCodeTableTreeDataByCode(@Param("code") String code, @Param("tables") List<String> tablesName);
+
+    /**
+     * 根据实地的空间身份编码EntityID 。在根据实体表,查询对应的实体图元关系表
+     *
+     * @param String
+     * @param tablesName
+     * @return
+     */
+    List<EntityRelationshipVo> queryEntityRelationshipDataByEntityId(@Param("EntityId") String EntityId, @Param("tables") List<String> tablesName);
+
+    Map<String, Object> queryEntityDataByEntityId(@Param("tylayer") String tylayer, @Param("elementid") String elementid);
+
+    /**
+     * 根据实体分类,通過视图获取表名
+     *
+     * @param viewName
+     * @param code
+     * @return
+     */
+    List<String> queryTablesNameByViewCode(@Param("viewName") String viewName, @Param("code") String code);
+
+    /**
+     * 查询schema 中表名包含name的table
+     * 查询方式(%name)
+     *
+     * @param schema
+     * @param name
+     * @return
+     */
+    List<String> querySchemaTableByName(@Param("schema") String schema, @Param("name") String name);
+
+    /**
+     * 创建实体表与实体编码表的视图,方便后期查询
+     */
+    int createEntityCodeTableDataViewByTableSql(@Param("viewSql") String viewSql, @Param("viewName") String viewName);
+}

+ 12 - 0
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/service/dimentity/DimEntityService.java

@@ -0,0 +1,12 @@
+package com.onemap.apply.service.dimentity;
+
+import com.onemap.apply.domain.dimentity.EntityCodeTreeVo;
+
+import java.util.List;
+import java.util.Map;
+
+public interface DimEntityService {
+    List<EntityCodeTreeVo> queryEntityCodeTableTree();
+
+    List<Map<String, Object>> queryEntityData(String entityid);
+}

+ 96 - 0
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/service/dimentity/impl/DimEntityServiceImpl.java

@@ -0,0 +1,96 @@
+package com.onemap.apply.service.dimentity.impl;
+
+import com.onemap.apply.domain.dimentity.EntityCodeTreeVo;
+import com.onemap.apply.domain.dimentity.EntityRelationshipVo;
+import com.onemap.apply.mapper.dimentity.DimEntityMapper;
+import com.onemap.apply.service.dimentity.DimEntityService;
+import com.onemap.common.core.utils.StringUtils;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+@Service
+public class DimEntityServiceImpl implements DimEntityService {
+    @Resource
+    private DimEntityMapper dimEntityMapper;
+
+    @Override
+    public List<EntityCodeTreeVo> queryEntityCodeTableTree() {
+        //创建视图
+        String viewTableName = StringUtils.getTemporaryTableName();
+        createView(viewTableName);
+        return queryEntityCodeTableTreeData(null, 1, viewTableName);
+    }
+
+    @Override
+    public List<Map<String, Object>> queryEntityData(String entityid) {
+        //获取所有的实体关系表
+        List<String> tablesList = dimEntityMapper.querySchemaTableByName("vector", "实体图元关联表");
+        if (tablesList == null || tablesList.size() == 0) {
+            return Collections.emptyList();
+        }
+        List<EntityRelationshipVo> relationshipVos = dimEntityMapper.queryEntityRelationshipDataByEntityId(entityid, tablesList);
+        if (relationshipVos == null || relationshipVos.size() == 0) {
+            return Collections.emptyList();
+        }
+        List<Map<String, Object>> ret = new ArrayList<Map<String, Object>>();
+        for (EntityRelationshipVo relationshipVo : relationshipVos) {
+            ret.add(dimEntityMapper.queryEntityDataByEntityId(relationshipVo.getTylayer(), relationshipVo.getElementid()));
+        }
+        return ret;
+    }
+
+    private void createView(String viewTableName) {
+        //判斷视图是否存在
+        List<String> viewsList = dimEntityMapper.querySchemaTableByName("vector", viewTableName);
+        //视图存在,不创建
+        if (viewsList != null && viewsList.size() > 0) {
+            return;
+        }
+
+        //获取所有的实体关系表
+        List<String> tablesList = dimEntityMapper.querySchemaTableByName("vector", "实体关系表");
+
+        //通过实体关系表,获取实体关系表中,所有映射的实体代理点。此处创建视图,视图将一个小时后删除
+        StringBuilder viewSql = new StringBuilder();
+        for (int i = 0; i < tablesList.size(); i++) {
+            if (i > 0) {
+                viewSql.append(" union all ");
+            }
+            String tableName = tablesList.get(i).trim();
+            String sql = "SELECT  entilayer  FROM vector.\"" + tableName + "\" x group by entilayer";
+            viewSql.append(sql);
+        }
+        dimEntityMapper.createEntityCodeTableDataViewByTableSql(viewSql.toString(), viewTableName);
+    }
+
+    private List<EntityCodeTreeVo> queryEntityCodeTableTreeData(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));
+            }
+        } 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));
+                }
+            }
+        }
+        return entityCodeTreeVos;
+    }
+
+}

+ 91 - 0
onemap-modules/onemap-apply/src/main/resources/mapper/postgresql/dimentity/DimEntityMapper.xml

@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="com.onemap.apply.mapper.dimentity.DimEntityMapper">
+
+    <!-- 可根据自己的需求,是否要使用 -->
+    <resultMap type="EntityCodeTreeVo" id="EntityCodeTreeVoResult">
+        <result property="id" column="id"/>
+        <result property="label" column="label"/>
+    </resultMap>
+
+    <!-- 可根据自己的需求,是否要使用 -->
+    <resultMap type="EntityRelationshipVo" id="EntityRelationshipVoResult">
+        <result property="tylayer" column="tylayer"/>
+        <result property="elementid" column="elementid"/>
+    </resultMap>
+
+
+
+    <select id="queryEntityCodeTable" parameterType="String" resultMap="EntityCodeTreeVoResult">
+        SELECT t1.id,t1.label from (
+        <choose>
+            <when test="level != null and level != '' and level ==2 ">
+                select twocode as id ,twocodename as label from base.t_entity_code_table where firstcode = #{code}
+            </when>
+            <when test="level != null and level != '' and level ==3 ">
+                select threecode as id ,threecodename as label from base.t_entity_code_table where twocode = #{code}
+            </when>
+            <when test="level != null and level != '' and level ==4 ">
+                select fourcode as id ,fourcodename as label from base.t_entity_code_table where threecode = #{code}
+            </when>
+            <otherwise>
+                select firstcode as id ,firstcodename as label from base.t_entity_code_table
+            </otherwise>
+        </choose>
+        )t1 group by t1.id,t1.label order by id asc
+    </select>
+
+    <select id="queryEntityCodeTableCountByCode" parameterType="String" resultType="Long">
+        select sum(gs) as count from (
+        <foreach item="item" index="index" collection="tables" separator="UNION ALL">
+            select count(*) as gs from vector.${item} where classid::varchar like concat(#{code},'%')
+        </foreach>
+        )v1
+    </select>
+
+    <select id="queryEntityCodeTableTreeDataByCode" parameterType="String" resultMap="EntityCodeTreeVoResult">
+        select * from (
+        <foreach item="item" index="index" collection="tables" separator="UNION ALL" >
+            select entityid as id, case when entityname = 'null' then entityid else  entityname end as label,
+            false disabled,0 as count
+            from vector.${item} where classid::varchar like concat(#{code},'%')
+        </foreach>
+        )v1
+    </select>
+
+    <select id="queryEntityRelationshipDataByEntityId" parameterType="String" resultMap="EntityRelationshipVoResult">
+        select * from (
+        <foreach item="item" index="index" collection="tables" separator="UNION ALL" >
+            select entityid,tylayer,elementid from vector.${item} where entityid = #{EntityId}
+        </foreach>
+        )v1
+    </select>
+
+    <select id="queryEntityDataByEntityId" parameterType="String" resultType="map">
+        select *,public.st_asewkt(geom) geomewkt from vector.${tylayer} where elementid = #{elementid}
+    </select>
+
+    <select id="queryTablesNameByViewCode" parameterType="String" resultType="String">
+        select v1.entilayer from (select  entilayer from vector.${viewName} where fourcode like concat(#{code},'%'))v1 group by v1.entilayer
+    </select>
+
+
+    <select id="querySchemaTableByName" parameterType="String" resultType="String">
+        select table_name
+        from (SELECT table_name FROM information_schema.tables WHERE table_schema = #{schema}) t1
+        where t1.table_name like concat('%', #{name})
+    </select>
+
+    <update id="createEntityCodeTableDataViewByTableSql" parameterType="String">
+        create
+        OR REPLACE view vector.${viewName} as
+        select v2.fourcode, v1.entilayer
+        from (SELECT x.entilayer
+              FROM (
+                       ${viewSql}
+                       ) x
+              group by entilayer) v1
+                 left join base.t_entity_code_table v2 on LOWER(v1.entilayer) like concat('%', LOWER(v2.entilayer))
+    </update>
+</mapper>