Jelajahi Sumber

Merge remote-tracking branch 'origin/master' into master

# Conflicts:
#	ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/RestApi.java
lirong 3 tahun lalu
induk
melakukan
64cd8be8f4

+ 33 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/GlobalCorsConfig.java

@@ -0,0 +1,33 @@
+package com.persagy.ibms.data.sdk.service;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.cors.CorsConfiguration;
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
+import org.springframework.web.filter.CorsFilter;
+
+@Configuration
+public class GlobalCorsConfig {
+	@Bean
+	public CorsFilter corsFilter() {
+		// 1.添加CORS配置信息
+		CorsConfiguration config = new CorsConfiguration();
+		// 放行哪些原始域
+		config.addAllowedOrigin("*");
+		// 是否发送Cookie信息
+		config.setAllowCredentials(true);
+		// 放行哪些原始域(请求方式)
+		config.addAllowedMethod("*");
+		// 放行哪些原始域(头部信息)
+		config.addAllowedHeader("*");
+		// 暴露哪些头部信息(因为跨域访问默认不能获取全部头部信息)
+		// config.addExposedHeader("*");
+
+		// 2.添加映射路径
+		UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
+		configSource.registerCorsConfiguration("/**", config);
+
+		// 3.返回新的CorsFilter.
+		return new CorsFilter(configSource);
+	}
+}

+ 19 - 4
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/service/rest/RestApi.java

@@ -1,13 +1,22 @@
 package com.persagy.ibms.data.sdk.service.rest;
 
-import com.alibaba.fastjson.JSONObject;
+import javax.servlet.http.HttpServletRequest;
+
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.persagy.ibms.data.sdk.util.ToolUtil;
 import com.persagy.ibms.data.sdk.websocket.AlarmWebSocketClient;
 import com.persagy.ibms.data.sdk.websocket.IOTWebSocketClient;
+
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.web.bind.annotation.*;
-
-import javax.servlet.http.HttpServletRequest;
 
 @ApiOperation(value = "采集/控制接口")
 @RestController
@@ -58,6 +67,12 @@ public class RestApi {
 		return result;
 	}
 
+	@PostMapping(path = { "/tool" }, produces = "application/json;charset=UTF-8")
+	public String tool(@RequestBody String param) {
+		String result = ToolUtil.tool(param);
+		return result;
+	}
+
 	@PostMapping(path = { "/desc" }, produces = "application/json;charset=UTF-8")
 	public String desc(@RequestBody String param) {
 		String result = RestUtil.desc(param);

+ 1 - 1
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/BKDRHash.java

@@ -8,6 +8,6 @@ public class BKDRHash {
 		for (int i = 0; i != str.length(); ++i) {
 			hash = seed * hash + str.charAt(i);
 		}
-		return hash;
+		return hash >= 00 ? hash : 0 - hash;
 	}
 }

+ 10 - 9
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/ComputeUtil.java

@@ -48,6 +48,7 @@ public class ComputeUtil {
 			Repository.relationArrayDic = RepositoryBase.instance.relationArrayDic;
 			Repository.id2object = RepositoryBase.instance.id2object;
 			Repository.id2sdv = RepositoryBase.instance.id2sdv;
+			Repository.IBMSArrayDic = RepositoryBase.instance.IBMSArrayDic;
 		}
 
 		log.warn("LoadConfig");
@@ -138,18 +139,18 @@ public class ComputeUtil {
 				}
 			}
 		}
-		log.debug("****************");
+		log.info("****************");
 		for (SceneProperty spInner : spList) {
 			// 打印路径
 			{
 				String path = getPropertyPath(Repository, spInner);
-				log.debug("getPropertyBefore:" + path);
+				log.info("getPropertyBefore:" + path);
 			}
 			{
 				List<SceneProperty> beforeList = CheckUtil.getPropertyBefore(Repository, spInner);
 				Repository.beforeDic.put(spInner, beforeList);
 				for (SceneProperty spInner2 : beforeList) {
-					log.debug(getPropertyPath(Repository, spInner2));
+					log.info(getPropertyPath(Repository, spInner2));
 				}
 			}
 		}
@@ -183,19 +184,19 @@ public class ComputeUtil {
 				processedDic.put(spInner, true);
 			}
 		}
-		log.debug("****************************************************************");
+		log.info("****************************************************************");
 		for (List<SceneProperty> spInnerList : spListList) {
-			log.debug("********************************");
+			log.info("********************************");
 			for (SceneProperty spInner2 : spInnerList) {
 				Repository.property2lock.put(spInner2, new ReentrantLock(true));
-				log.debug(getPropertyPath(Repository, spInner2));
+				log.info(getPropertyPath(Repository, spInner2));
 				if (!Repository.property2SDV.containsKey(spInner2)) {
 					Repository.property2SDV.put(spInner2, new ArrayList<SceneDataValue>());
 				}
 			}
-			log.debug("********************************");
+			log.info("********************************");
 		}
-		log.debug("****************************************************************");
+		log.info("****************************************************************");
 
 		return spListList;
 	}
@@ -333,7 +334,7 @@ public class ComputeUtil {
 						}
 						sb.append(ss.propertyName);
 					}
-					log.debug("computeOnce:" + sb.toString());
+					log.info("computeOnce:" + sb.toString());
 					// if (sb.toString().equals("基础对象-设备-清单")) {
 					// System.out.println();
 					// }

+ 4 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/QueryUtil.java

@@ -551,6 +551,10 @@ public class QueryUtil {
 					result = new SceneDataSet(isSingleValueSet);
 					result.setRowChange(false);
 				}
+			} else if (Source.equals("ibms")) {
+				String product = (descSet.get("product")).toString();
+				String type = (descSet.get("type")).toString();
+				result = Repository.IBMSArrayDic.get(product).get(type);
 			} else if (Source.equals("alarm")) {
 				result = RepositoryBase.alarmArray;
 			} else if (Source.equals("ref")) {

+ 28 - 19
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/RWDLoadUtil.java

@@ -1,6 +1,7 @@
 package com.persagy.ibms.data.sdk.util;
 
 import java.io.File;
+import java.io.FileFilter;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -65,7 +66,7 @@ public class RWDLoadUtil {
 			for (File file : files) {
 				int index_ = file.getName().indexOf('.');
 				String code = file.getName().substring(0, index_);
-				log.debug(infoPath + Constant.getSeperator() + "" + file.getName());
+				log.info(infoPath + Constant.getSeperator() + "" + file.getName());
 				try {
 					JSONArray array = FastJsonReaderUtil.Instance().ReadJSONArray(new File(infoPath + Constant.getSeperator() + "" + file.getName()));
 					if (code.equals("OTSECB")) {
@@ -101,7 +102,7 @@ public class RWDLoadUtil {
 				int index_ = file.getName().indexOf('.');
 				String code = file.getName().substring(0, index_);
 				String className = Repository.classCode2NameMap.get(code);
-				log.debug(objectPath + Constant.getSeperator() + "" + file.getName());
+				log.info(objectPath + Constant.getSeperator() + "" + file.getName());
 				JSONArray array = FastJsonReaderUtil.Instance().ReadJSONArray(new File(objectPath + Constant.getSeperator() + "" + file.getName()));
 				if (code.equals("OTSECB")) {
 					for (int ii = 0; ii < array.size(); ii++) {
@@ -191,7 +192,7 @@ public class RWDLoadUtil {
 				for (File file : files) {
 					int index_ = file.getName().indexOf('.');
 					String code = file.getName().substring(0, index_);
-					log.debug(relationPath + Constant.getSeperator() + "" + dir.getName() + Constant.getSeperator() + file.getName());
+					log.info(relationPath + Constant.getSeperator() + "" + dir.getName() + Constant.getSeperator() + file.getName());
 					JSONArray array = FastJsonReaderUtil.Instance().ReadJSONArray(
 							new File(relationPath + Constant.getSeperator() + "" + dir.getName() + Constant.getSeperator() + file.getName()));
 					SceneDataSet SceneDataSet = new SceneDataSet(false);
@@ -470,23 +471,31 @@ public class RWDLoadUtil {
 
 	public static void LoadIBMSPhysicalWorld(Repository Repository) throws Exception {
 		String validPath = Constant.getLatestPath(Constant.ibms_physical_world, true);
-		String infoPath = validPath + Constant.getSeperator() + "NightscapeLighting";
-		Map<String, SceneDataSet> infoArrayDic = new HashMap<String, SceneDataSet>();
-		File root = new File(infoPath);
-		File[] files = root.listFiles();
-		for (File file : files) {
-			int index_ = file.getName().indexOf('.');
-			String code = file.getName().substring(0, index_);
-			log.debug(infoPath + Constant.getSeperator() + "" + file.getName());
-			try {
-				JSONArray array = FastJsonReaderUtil.Instance().ReadJSONArray(new File(infoPath + Constant.getSeperator() + "" + file.getName()));
-				SceneDataSet SceneDataSet = new SceneDataSet(false);
-				SceneDataSet.set = RWDUtil.array2SDOList(array);
-				infoArrayDic.put(code, SceneDataSet);
-			} catch (Exception e) {
-				log.warn(e.getMessage(), e);
+		File[] dirs = (new File(validPath)).listFiles(new FileFilter() {
+			@Override
+			public boolean accept(File pathname) {
+				return pathname.isDirectory();
+			}
+		});
+		for (File dir : dirs) {
+			String product = dir.getName();
+			Map<String, SceneDataSet> infoArrayDic = new HashMap<String, SceneDataSet>();
+			File[] files = dir.listFiles();
+			for (File file : files) {
+				int index_ = file.getName().indexOf('.');
+				String code = file.getName().substring(0, index_);
+				String infoPath = validPath + Constant.getSeperator() + product;
+				log.info(infoPath + Constant.getSeperator() + file.getName());
+				try {
+					JSONArray array = FastJsonReaderUtil.Instance().ReadJSONArray(new File(infoPath + Constant.getSeperator() + file.getName()));
+					SceneDataSet SceneDataSet = new SceneDataSet(false);
+					SceneDataSet.set = RWDUtil.array2SDOList(array);
+					infoArrayDic.put(code, SceneDataSet);
+				} catch (Exception e) {
+					log.warn(e.getMessage(), e);
+				}
 			}
+			Repository.IBMSArrayDic.put(product, infoArrayDic);
 		}
-		Repository.IBMSArrayDic.put("NightscapeLighting", infoArrayDic);
 	}
 }

+ 177 - 0
ibms-data-sdk/src/main/java/com/persagy/ibms/data/sdk/util/ToolUtil.java

@@ -0,0 +1,177 @@
+package com.persagy.ibms.data.sdk.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.persagy.ibms.data.sdk.service.rest.RestUtil;
+
+public class ToolUtil {
+
+	public static String tool(String param) {
+		String result = null;
+		JSONObject paramObject = JSON.parseObject(param);
+		String type = (String) paramObject.get("type");
+		if (type.equals("NightscapeLighting")) {
+			result = Lighting(false);
+		} else if (type.equals("PublicLighting")) {
+			result = Lighting(true);
+		}
+		return result;
+	}
+
+	private static String Lighting(boolean is_public) {
+		Map<String, JSONObject> floorMap = new HashMap<String, JSONObject>();
+		JSONArray floorArray = getArray_object("floor", null);
+		for (int i = 0; i < floorArray.size(); i++) {
+			JSONObject item = (JSONObject) floorArray.get(i);
+			String id = (String) item.get("id");
+			floorMap.put(id, item);
+		}
+
+		JSONArray louceng = getArray_relation("MechInArch", "Eq2Fl");
+		Map<String, String> SELTCC2floor = new HashMap<String, String>();
+		for (int i = 0; i < louceng.size(); i++) {
+			JSONObject item = (JSONObject) louceng.get(i);
+			String objFrom = item.getString("objFrom");
+			String objTo = item.getString("objTo");
+			SELTCC2floor.put(objFrom, objTo);
+		}
+
+		JSONArray kongzhi = getArray_relation("MechCtrl", "EqCtrl");
+		Map<String, String> SELTCC2SELTCU = new HashMap<String, String>();
+		for (int i = 0; i < kongzhi.size(); i++) {
+			JSONObject item = (JSONObject) kongzhi.get(i);
+			String objFrom = item.getString("objFrom");
+			String objTo = item.getString("objTo");
+			SELTCC2SELTCU.put(objTo, objFrom);
+		}
+
+		JSONArray gongdian = getArray_relation("MechPower", "EqNormal");
+		Map<String, String> SELTCU2SETDLS = new HashMap<String, String>();
+		for (int i = 0; i < gongdian.size(); i++) {
+			JSONObject item = (JSONObject) gongdian.get(i);
+			String objFrom = item.getString("objFrom");
+			String objTo = item.getString("objTo");
+			SELTCU2SETDLS.put(objTo, objFrom);
+		}
+
+		JSONArray suozai = getArray_relation("MechInArch", "Eq2Sp");
+		Map<String, String> SETDLS2GeneralZone = new HashMap<String, String>();
+		for (int i = 0; i < suozai.size(); i++) {
+			JSONObject item = (JSONObject) suozai.get(i);
+			String objFrom = item.getString("objFrom");
+			String objTo = item.getString("objTo");
+			SETDLS2GeneralZone.put(objFrom, objTo);
+		}
+
+		String[] levels = { "楼体照明", "楼体照明", "景观照明", "景观照明", "标识照明", "标识照明" };
+		String[] types = { "A", "B", "A", "B", "A", "B" };
+		JSONArray result = new JSONArray();
+		for (String SELTCC : SELTCC2SELTCU.keySet()) {
+			if (!SELTCC2SELTCU.containsKey(SELTCC)) {
+				continue;
+			}
+			String SELTCU = SELTCC2SELTCU.get(SELTCC);
+			if (!SELTCU2SETDLS.containsKey(SELTCU)) {
+				continue;
+			}
+			String SETDLS = SELTCU2SETDLS.get(SELTCU);
+
+			String GeneralZone = null;
+			if (SETDLS != null && SETDLS2GeneralZone.containsKey(SETDLS)) {
+				GeneralZone = SETDLS2GeneralZone.get(SETDLS);
+			}
+
+			int index = BKDRHash.getHashCode(SELTCC) % levels.length;
+			JSONObject item = new JSONObject();
+			item.put("回路编号", SELTCC);
+			item.put("模块编号", SELTCU);
+			item.put("配电箱编号", SETDLS);
+			item.put("电井编号", GeneralZone);
+			item.put("类型", types[index]);
+			if (is_public) {
+				String floor = SELTCC2floor.get(SELTCC);
+				if (floor != null) {
+					item.put("楼层", floor);
+					item.put("二级编组", levels[index] + "-" + floorMap.get(floor).get("localId") + "-" + types[index]);
+					item.put("一级编组", levels[index]);
+					result.add(item);
+				}
+			} else {
+				item.put("二级编组", levels[index] + "-" + types[index]);
+				item.put("一级编组", levels[index]);
+				result.add(item);
+			}
+		}
+
+		// JSONArray huilu = getArray_object("equipment", "SELTCC");
+		// JSONArray mokuai = getArray_object("equipment", "SELTCU");
+		// JSONArray peidianxiang = getArray_object("equipment", "SETDLS");
+		// JSONArray dianjing = getArray_object("space", "GeneralZone");
+
+		return FastJsonUtil.toFormatString(result);
+	}
+
+	public static JSONArray getArray_relation(String graphCode, String relCode) {
+		JSONObject Target = generateTarget_relation(graphCode, relCode);
+		JSONObject param = new JSONObject();
+		param.put("Target", Target);
+		param.put("Criteria", new JSONObject());
+		param.put("QueryType", "select");
+		String queryResult = RestUtil.query(param.toJSONString());
+		JSONArray resultArray = JSON.parseArray(queryResult);
+		return resultArray;
+	}
+
+	public static JSONArray getArray_object(String objType, String classCode) {
+		JSONObject Target = generateTarget_object(objType, classCode);
+		JSONArray ReturnColumns = generateReturnColumns();
+		JSONObject Criteria = generateCriteria();
+		JSONObject param = new JSONObject();
+		param.put("Target", Target);
+		param.put("ReturnColumns", ReturnColumns);
+		param.put("Criteria", Criteria);
+		param.put("QueryType", "select");
+		String queryResult = RestUtil.query(param.toJSONString());
+		JSONArray resultArray = JSON.parseArray(queryResult);
+		return resultArray;
+	}
+
+	private static JSONObject generateCriteria() {
+		JSONObject result = new JSONObject();
+		result.put("valid", 1L);
+		return result;
+	}
+
+	private static JSONArray generateReturnColumns() {
+		JSONArray result = new JSONArray();
+		result.add("id");
+		result.add("localId");
+		result.add("localName");
+		result.add("classCode");
+		return result;
+	}
+
+	private static JSONObject generateTarget_object(String objType, String classCode) {
+		JSONObject result = new JSONObject();
+		result.put("Source", "rwd");
+		result.put("rwd", "object");
+		result.put("objType", objType);
+		if (classCode != null) {
+			result.put("classCode", classCode);
+		}
+		return result;
+	}
+
+	private static JSONObject generateTarget_relation(String graphCode, String relCode) {
+		JSONObject result = new JSONObject();
+		result.put("Source", "rwd");
+		result.put("rwd", "relation");
+		result.put("graphCode", graphCode);
+		result.put("relCode", relCode);
+		return result;
+	}
+}