소스 검색

已有关系进行查询

DESKTOP-2K9OVK9\siwei 4 달 전
부모
커밋
cd098f7742

+ 7 - 3
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/controller/dimentity/DimEntityController.java

@@ -9,13 +9,12 @@ import com.onemap.common.core.web.domain.RequestResult;
 import com.onemap.common.core.web.page.TableDataInfo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.neo4j.core.Neo4jClient;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 
 @RestController
 @RequestMapping("dimentity")
@@ -48,6 +47,11 @@ public class DimEntityController extends BaseController {
         return RequestResult.success(dimEntityService.queryEntityRelationshipToNeo4j(entityid));
     }
 
+    @PostMapping("/entity/relationship/filter")
+    public RequestResult queryEntityRelationshipFilter(@RequestBody Map map) {
+        return RequestResult.success(dimEntityService.queryEntityRelationshipFilter(map));
+    }
+
     @GetMapping("/entity/color")
     public RequestResult queryEntityColor() {
         return RequestResult.success(dimEntityService.queryEntityColor());

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

@@ -29,5 +29,7 @@ public interface DimEntityService {
 
     Map<String, Object> queryEntityRelationshipToNeo4j(String entityid);
 
+    Map<String, Object> queryEntityRelationshipFilter(Map map);
+
     List<Map> queryEntityColor();
 }

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

@@ -6,6 +6,7 @@ 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 com.onemap.common.core.web.domain.RequestResult;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.neo4j.core.Neo4jClient;
 import org.springframework.stereotype.Service;
@@ -276,4 +277,100 @@ public class DimEntityServiceImpl implements DimEntityService {
         return retList;
     }
 
+    @Override
+    public Map<String, Object> queryEntityRelationshipFilter(Map map) {
+        String query_data = (String) map.get("query_data");
+        String query_links = (String) map.get("query_links");
+        List<Map> data = (List<Map>) map.get("data");
+        List<Map> links = (List<Map>) map.get("links");
+
+        Map<String, Map> d0_all_data = new HashMap<>();
+        Map<String, Map> d0_all_links = new HashMap<>();
+        for (Map obj_v : data) {
+            String entityid = (String) obj_v.get("entityid");
+            d0_all_data.put(entityid, obj_v);
+        }
+
+        for (Map obj_v : links) {
+            String value = (String) obj_v.get("value");
+            String source = (String) obj_v.get("source");
+            String target = (String) obj_v.get("target");
+            d0_all_links.put(value + "@@" + source + "@@" + target, obj_v);
+        }
+
+        Map<String, Object> retData = new HashMap<>();
+        List<Map> retDataList = new ArrayList<>();
+        Set<String> retDataSet = new HashSet<>();
+        List<Map> retLinksList = new ArrayList<>();
+        if (StringUtils.isNotEmpty(query_data) && StringUtils.isNotEmpty(query_links)) {
+            for (String v0_key : d0_all_links.keySet()) {
+                String[] v0_keys = v0_key.split("@@");
+                if (v0_keys[0].equals(query_links)) {
+                    String source = v0_keys[1];
+                    String target = v0_keys[2];
+                    Map sourceData = d0_all_data.get(source);
+                    if (sourceData != null) {
+                        String entityid = (String) sourceData.get("entityid");
+                        String entityname = (String) sourceData.get("entityname");
+                        if (entityid.contains(query_data) || entityname.contains(query_data)) {
+                            retLinksList.add(d0_all_links.get(v0_key));
+                            continue;
+                        }
+                    }
+                    Map targetData = d0_all_data.get(target);
+                    if (targetData != null) {
+                        String entityid = (String) targetData.get("entityid");
+                        String entityname = (String) targetData.get("entityname");
+                        if (entityid.contains(query_data) || entityname.contains(query_data)) {
+                            retLinksList.add(d0_all_links.get(v0_key));
+                        }
+                    }
+                }
+            }
+        } else if (StringUtils.isNotEmpty(query_links)) {
+            for (String v0_key : d0_all_links.keySet()) {
+                String[] v0_keys = v0_key.split("@@");
+                if (v0_keys[0].equals(query_links)) {
+                    retLinksList.add(d0_all_links.get(v0_key));
+                }
+            }
+        } else if (StringUtils.isNotEmpty(query_data)) {
+            Set<String> d1_all_data = new HashSet<>();
+            for (Map sourceData : data) {
+                String entityid = (String) sourceData.get("entityid");
+                String entityname = (String) sourceData.get("entityname");
+                if (entityid.contains(query_data) || entityname.contains(query_data)) {
+                    d1_all_data.add(entityid);
+                }
+            }
+            for (Map obj_v : links) {
+                String source = (String) obj_v.get("source");
+                String target = (String) obj_v.get("target");
+                if (d1_all_data.contains(source) || d1_all_data.contains(target)) {
+                    retLinksList.add(obj_v);
+                }
+            }
+        } else {
+            retData.put("data", data);
+            retData.put("links", links);
+            return RequestResult.success(retData);
+        }
+
+        for (Map obj_v : retLinksList) {
+            String source = (String) obj_v.get("source");
+            String target = (String) obj_v.get("target");
+            if (!retDataSet.contains(source)) {
+                retDataList.add(d0_all_data.get(source));
+            }
+            if (!retDataSet.contains(target)) {
+                retDataList.add(d0_all_data.get(target));
+            }
+            retDataSet.add(source);
+            retDataSet.add(target);
+        }
+        retData.put("data", retDataList);
+        retData.put("links", retLinksList);
+        return retData;
+    }
+
 }