zhaoyk 3 år sedan
förälder
incheckning
49c520312a

+ 13 - 32
src/main/java/com/persagy/bdtp/adm/service/impl/SyncOldAdmImpl.java

@@ -22,6 +22,7 @@ import com.persagy.bdtp.adm.service.CallException;
 import com.persagy.bdtp.adm.service.IAdmObjectService;
 import com.persagy.bdtp.adm.service.IQueryFromOldAdm;
 import com.persagy.bdtp.adm.service.ISyncOldAdm;
+import com.persagy.bdtp.adm.util.GeomUtil;
 import com.persagy.dmp.common.constant.ResponseCode;
 import com.persagy.dmp.common.constant.ValidEnum;
 import com.persagy.dmp.common.exception.BusinessException;
@@ -39,6 +40,7 @@ import java.io.IOException;
 import java.lang.reflect.Field;
 import java.util.*;
 import java.util.List;
+import java.util.stream.Collectors;
 
 @Service
 public class SyncOldAdmImpl implements ISyncOldAdm {
@@ -55,15 +57,16 @@ public class SyncOldAdmImpl implements ISyncOldAdm {
 	@Autowired
 	private AdmJobSpaceMapper jobSpaceMapper;
 
-	private static GeometryFactory geometryFactory = new GeometryFactory();
-
 	@Override
 	@Transactional(rollbackFor = Exception.class)
 	public Map<String, Object> syncData(String groupCode, String projectId) {
 		String token = queryOldAdm.login();
 		if(StrUtil.isNotBlank(token)){
 			List<OBuilding> bdList = queryOldAdm.queryBdAnFl(token, groupCode, projectId);
+
 			List<OSpace> spList = queryOldAdm.querySpace(token, groupCode, projectId);
+			spList = spList.stream().filter(space -> GeomUtil.checkPolygon(space.getOutline())).collect(Collectors.toList());
+
 			List<OEquip> eqList  = queryOldAdm.queryEquip(token, groupCode, projectId);
 
 			List<AdmObject> bdObjs = new ArrayList<>(bdList.size());
@@ -363,7 +366,8 @@ public class SyncOldAdmImpl implements ISyncOldAdm {
 			else if("OtherZone".equals(zone))
 				otherList.add(sp);
 		}
-		map.put(floorId, otherList.size() > 0 ? otherList : generalList);
+		if(floorId != null)
+			map.put(floorId, otherList.size() > 0 ? otherList : generalList);
 
 		List<AdmJobSpace> toCreate = new ArrayList<>();
 		List<AdmJobSpace> toModify = new ArrayList<>();
@@ -449,15 +453,18 @@ public class SyncOldAdmImpl implements ISyncOldAdm {
 	}
 
 	private AdmJobSpace matchByOutline(HashMap<String, AdmJobSpace> jobMap, AdmObject space){
+		if(jobMap.size() == 0)
+			return null;
+
 		ArrayNode o1 = (ArrayNode) space.getInfo("outline");
 		if(!isValidOutline(o1))
 			return null;
 
-		Polygon[] ps = getPolygon(o1);
+		Polygon[] ps = GeomUtil.getPolygon(o1);
 		Map.Entry<String, AdmJobSpace> target = null;
 		for(Map.Entry<String, AdmJobSpace> entry : jobMap.entrySet()){
 			ArrayNode o2 = entry.getValue().getOutline();
-			if(isValidOutline(o2) && polygonsMatch(ps, getPolygon(o2))){
+			if(isValidOutline(o2) && polygonsMatch(ps, GeomUtil.getPolygon(o2))){
 				target = entry;
 				break;
 			}
@@ -474,35 +481,9 @@ public class SyncOldAdmImpl implements ISyncOldAdm {
 	 * TODO 区分覆盖等情况
 	 */
 	private boolean outlineMatch(ArrayNode o1, ArrayNode o2){
-		return polygonsMatch(getPolygon(o1), getPolygon(o2));
-	}
-
-	private Polygon[] getPolygon(ArrayNode arrayNode){
-		Polygon[] ps = new Polygon[arrayNode.size()];
-		for (int i = 0; i < ps.length; i++) {
-			ArrayNode arr = (ArrayNode) arrayNode.get(i);
-			ArrayNode shellArrNode = (ArrayNode) arr.get(0);
-			LinearRing shell = geometryFactory.createLinearRing(buildCoords(shellArrNode));
-			LinearRing[] holes = null;
-			if(arr.size() > 1) {
-				holes = new LinearRing[arr.size() - 1];
-				for (int n = 1; n < arr.size(); n++) {
-					holes[n - 1] = geometryFactory.createLinearRing(buildCoords((ArrayNode) arr.get(n)));
-				}
-			}
-			ps[i] = geometryFactory.createPolygon(shell, holes);
-		}
-		return ps;
+		return polygonsMatch(GeomUtil.getPolygon(o1), GeomUtil.getPolygon(o2));
 	}
 
-	private Coordinate[] buildCoords(ArrayNode arrayNode){
-		Coordinate[] coords = new Coordinate[arrayNode.size()];
-		for (int i = 0; i < arrayNode.size(); i++) {
-			JsonNode pointNode = arrayNode.get(i);
-			coords[i] = new Coordinate(pointNode.get("x").asDouble(), pointNode.get("y").asDouble());
-		}
-		return coords;
-	}
 
 	/**
 	 * 轮廓匹配判断

+ 84 - 0
src/main/java/com/persagy/bdtp/adm/util/GeomUtil.java

@@ -0,0 +1,84 @@
+package com.persagy.bdtp.adm.util;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.map.CaseInsensitiveMap;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import org.locationtech.jts.geom.Coordinate;
+import org.locationtech.jts.geom.GeometryFactory;
+import org.locationtech.jts.geom.LinearRing;
+import org.locationtech.jts.geom.Polygon;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class GeomUtil {
+
+	private static GeometryFactory geometryFactory = new GeometryFactory();
+
+	public static Polygon[] getPolygon(ArrayNode arrayNode){
+		Polygon[] ps = new Polygon[arrayNode.size()];
+		for (int i = 0; i < ps.length; i++) {
+			ArrayNode arr = (ArrayNode) arrayNode.get(i);
+			ArrayNode shellArrNode = (ArrayNode) arr.get(0);
+			LinearRing shell = geometryFactory.createLinearRing(buildCoords(shellArrNode));
+			LinearRing[] holes = null;
+			if(arr.size() > 1) {
+				holes = new LinearRing[arr.size() - 1];
+				for (int n = 1; n < arr.size(); n++) {
+					holes[n - 1] = geometryFactory.createLinearRing(buildCoords((ArrayNode) arr.get(n)));
+				}
+			}
+			ps[i] = geometryFactory.createPolygon(shell, holes);
+		}
+		return ps;
+	}
+
+	private static Coordinate[] buildCoords(ArrayNode arrayNode){
+		Coordinate[] coords = new Coordinate[arrayNode.size()];
+		for (int i = 0; i < arrayNode.size(); i++) {
+			JsonNode pointNode = arrayNode.get(i);
+			coords[i] = new Coordinate(pointNode.get("x").asDouble(), pointNode.get("y").asDouble());
+		}
+		return coords;
+	}
+
+	public static boolean checkPolygon(ArrayList<ArrayList<ArrayList<CaseInsensitiveMap>>> outline){
+		if(CollUtil.isEmpty(outline))
+			return false;
+
+		try {
+			Polygon[] ps = new Polygon[outline.size()];
+			for (int i = 0; i < ps.length; i++) {
+				List space = (List) outline.get(i);
+				if(CollUtil.isEmpty(space))
+					return false;
+
+				List<Map> shellList = (List) space.get(0);
+				LinearRing shell = geometryFactory.createLinearRing(buildCoords(shellList));
+				LinearRing[] holes = null;
+				if(space.size() > 1) {
+					holes = new LinearRing[space.size() - 1];
+					for (int n = 1; n < space.size(); n++) {
+						holes[n - 1] = geometryFactory.createLinearRing(buildCoords((List<Map>) space.get(n)));
+					}
+				}
+				ps[i] = geometryFactory.createPolygon(shell, holes);
+			}
+		} catch (Exception e) {
+			return false;
+		}
+		return true;
+	}
+
+	private static Coordinate[] buildCoords(List<Map> list){
+		Coordinate[] coords = new Coordinate[list.size()];
+		for (int i = 0; i < list.size(); i++) {
+			Map point = list.get(i);
+			coords[i] = new Coordinate((Double) point.get("x"), (Double)point.get("y"));
+		}
+		return coords;
+	}
+
+}

+ 3 - 3
src/test/java/com/persagy/bdtp/adm/test/AdmApplicationTests.java

@@ -58,7 +58,7 @@ public class AdmApplicationTests {
 	@Test
 	//@Transactional
 	public void testInfosCfg(){
-		String type = "se";
+		String type = "ac";
 
 		List<AdmComponent> compList = componentMapper.selectList(null);
 		HashMap<String, List<AdmComponent>> compMap = new HashMap<>();
@@ -89,7 +89,7 @@ public class AdmApplicationTests {
 	private AdmRelsConfigMapper relsConfigMapper;
 	@Test
 	public void testRelsCfg(){
-		String type = "se";
+		String type = "ac";
 		relsConfigMapper.delete(new QueryWrapper<AdmRelsConfig>().eq("flag", type));
 		List<AdmRelsConfig> list = new RelCfgs().read(type);
 		for(AdmRelsConfig item : list) {
@@ -102,7 +102,7 @@ public class AdmApplicationTests {
 	private AdmPipeConfigMapper pipeConfigMapper;
 	@Test
 	public void testPipeCfg(){
-		String type = "ff";
+		String type = "ac";
 		pipeConfigMapper.delete(new QueryWrapper<AdmPipeConfig>().eq("flag", type));
 		List<AdmPipeConfig> list = new PipeCfgs().read(type);
 		for(AdmPipeConfig item : list) {

+ 15 - 3
src/test/java/com/persagy/bdtp/adm/test/data/InfosCfgs.java

@@ -15,7 +15,7 @@ import java.util.regex.Pattern;
 public class InfosCfgs {
 
     public static void main(String[] args) throws Exception {
-        new InfosCfgs().read("ff");
+        new InfosCfgs().read("se");
     }
 
     private ObjectMapper objectMapper = new ObjectMapper();;
@@ -61,7 +61,7 @@ public class InfosCfgs {
             eq.setId(IdUtil.simpleUUID());
             eqList.add(eq);
             eq.setName(arr[3 - preS]);
-            eq.setClassCode(major + arr[4 - preS]);
+            eq.setClassCode(arr[4 - preS]);
             eq.setMajorCode(major);
             eq.setSystemCode(eq.getClassCode().substring(0, 4));
             eq.setObjType("equipment");
@@ -74,6 +74,11 @@ public class InfosCfgs {
         eq.getInfos().add(info);
 
         info.group = group;
+
+        //debug
+        if(6 - preS < 0 || 6 - preS >= arr.length)
+            System.out.println();
+
         info.label = arr[6 - preS];
         info.code = arr[7 - preS];
         if(isCode(info.label)){
@@ -81,6 +86,11 @@ public class InfosCfgs {
             info.label = info.code;
             info.code = tmp;
         }
+
+        //debug
+        if(8 - preS >= arr.length)
+            System.out.println();
+
         info.dataType = getDataType(arr[8 - preS]);
         String optionsStr = null;
         if(arr.length > 9 - preS) {
@@ -89,7 +99,9 @@ public class InfosCfgs {
                 optionsStr = left.trim();
             else {
                 String[] arr1 = left.split("\\s", 1);
-                info.dataType = getDataType(arr1[0]);
+                info.unit = arr1[0];
+                if(StrUtil.isNotBlank(info.unit) && info.unit.indexOf('%') >= 0)
+                    info.unit = info.unit.replace("%", "");
                 if(arr1.length > 1)
                     optionsStr = arr1[1];
             }

+ 20 - 3
src/test/java/com/persagy/bdtp/adm/test/data/PipeCfgs.java

@@ -14,13 +14,15 @@ import java.util.List;
 public class PipeCfgs {
 
     public static void main(String[] args) throws Exception {
-        new PipeCfgs().read("ff");
+        new PipeCfgs().read("ac");
     }
 
     private ObjectMapper objectMapper = new ObjectMapper();;
     private List<AdmPipeConfig> list = new ArrayList<>();
     private AdmPipeConfig cfg;
     private String classCodeFrom;
+    private String pipeClassCode;
+    private String pipeSubType;
     private String major;
 
 
@@ -58,9 +60,24 @@ public class PipeCfgs {
         cfg = new AdmPipeConfig();
         cfg.setId(IdUtil.simpleUUID());
         cfg.setClassCodeFrom(classCodeFrom);
-        cfg.setPipeType(getPipeClassCode(arr[4 - preS]));
-        cfg.setPipeSubType(arr[5 - preS]);
+
+        //debug
+        if(7 - preS >= arr.length)
+            System.out.println();
+
+        if (preS <= 4)
+            pipeClassCode = getPipeClassCode(arr[4 - preS]);
+        if (preS <= 5)
+            pipeSubType = arr[5 - preS];
+
+        cfg.setPipeType(pipeClassCode);
+        cfg.setPipeSubType(pipeSubType);
         cfg.setClassCodeTo(arr[7 - preS]);
+
+        //debug
+        if(8 - preS >= arr.length)
+            System.out.println();
+
         cfg.setPipeDirection(getDirection(arr[8 - preS]));
 
         list.add(cfg);

+ 1 - 1
src/test/java/com/persagy/bdtp/adm/test/data/RelCfgs.java

@@ -15,7 +15,7 @@ import java.util.Map;
 public class RelCfgs {
 
     public static void main(String[] args) throws Exception {
-        new RelCfgs().read("se");
+        new RelCfgs().read("ac");
     }
 
     private ObjectMapper objectMapper = new ObjectMapper();;