|
@@ -0,0 +1,164 @@
|
|
|
+package com.ebei.screen.common.util;
|
|
|
+
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.ebei.screen.common.constants.EbaSystemConstants;
|
|
|
+import com.ebei.screen.common.constants.EnergyPlatformConstants;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.text.MessageFormat;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 能耗平台大屏工具类
|
|
|
+ *
|
|
|
+ * @author Levi.u
|
|
|
+ * @date 2021/1/15 11:35
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+public class EnergyUtils {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取拼接后的url地址
|
|
|
+ *
|
|
|
+ * @param url 原地址
|
|
|
+ * @param objs 按照顺序输入任意多个参数
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private static String getUrl(String url, Object... objs) {
|
|
|
+ return MessageFormat.format(url, objs);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 1、用户登录
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String coreConnectToken() {
|
|
|
+ String param = JSON.toJSONString(Levi.by("clientId", EbaSystemConstants.cliendId).set("clientSecret", EbaSystemConstants.clientSecret));
|
|
|
+ String result = HttpRequest.post(EnergyPlatformConstants.coreConnectToken)
|
|
|
+ .header("content-type", "application/x-www-form-urlencoded")
|
|
|
+ .body("username=" + EnergyPlatformConstants.username
|
|
|
+ + "&password=" + EnergyPlatformConstants.password
|
|
|
+ + "&scope=" + EnergyPlatformConstants.scope
|
|
|
+ + "&grant_type=" + EnergyPlatformConstants.grant_type
|
|
|
+ + "&client_id=" + EnergyPlatformConstants.client_id
|
|
|
+ + "&client_secret=" + EnergyPlatformConstants.client_secret)
|
|
|
+ .execute().body();
|
|
|
+ log.info("######### 1、用户登录:{} 参数:{}", result, param);
|
|
|
+ JSONObject obj = JSON.parseObject(result);
|
|
|
+ return obj.getString("token_type") + " " + obj.getString("access_token");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 2、获取当前用户名下盒子列表
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static List<Map> apiClientBoxGrouped() {
|
|
|
+ String result = HttpRequest.get(EnergyPlatformConstants.apiClientBoxGrouped)
|
|
|
+ .header("Authorization", coreConnectToken())
|
|
|
+ .execute().body();
|
|
|
+ log.info("######### 2、获取当前用户名下盒子列表:{}", result);
|
|
|
+ return LeviUtils.getJsonFieldMany(result, null, Map.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 3、根据boxNo获取单个盒子
|
|
|
+ *
|
|
|
+ * @param boxNo 盒子编码
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static Map apiClientBoxRegBoxNo(String boxNo) {
|
|
|
+ String result = HttpRequest.get(getUrl(EnergyPlatformConstants.apiClientBoxRegBoxNo, boxNo))
|
|
|
+ .header("Authorization", coreConnectToken())
|
|
|
+ .execute().body();
|
|
|
+ log.info("######### 3、根据boxNo获取单个盒子:{}", result);
|
|
|
+ return LeviUtils.getJsonFieldOne(result, null, Map.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 4、根据boxId获取监控点分组
|
|
|
+ *
|
|
|
+ * @param boxId 盒子ID
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static List<Map> v2BoxDmonGroups(String boxId) {
|
|
|
+ String result = HttpRequest.get(getUrl(EnergyPlatformConstants.v2BoxDmonGroups, boxId))
|
|
|
+ .header("Authorization", coreConnectToken())
|
|
|
+ .execute().body();
|
|
|
+ log.info("######### 4、根据boxId获取监控点分组:{}", result);
|
|
|
+ return LeviUtils.getJsonFieldMany(result, null, Map.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 5、根据boxNo获取监控点分组
|
|
|
+ *
|
|
|
+ * @param boxNo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static List<Map> V2BoxDmonGroupsBoxNo(String boxNo) {
|
|
|
+ String result = HttpRequest.get(getUrl(EnergyPlatformConstants.V2BoxDmonGroupsBoxNo, boxNo))
|
|
|
+ .header("Authorization", coreConnectToken())
|
|
|
+ .execute().body();
|
|
|
+ log.info("######### 5、根据boxNo获取监控点分组:{}", result);
|
|
|
+ return LeviUtils.getJsonFieldMany(result, null, Map.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 6、根据boxId和分组id获取监控点
|
|
|
+ *
|
|
|
+ * @param boxId
|
|
|
+ * @param groupId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static List<Map> v2BoxDmonGroupDmon(String boxId, String groupId) {
|
|
|
+ String result = HttpRequest.get(getUrl(EnergyPlatformConstants.v2BoxDmonGroupDmon, boxId, groupId))
|
|
|
+ .header("Authorization", coreConnectToken())
|
|
|
+ .execute().body();
|
|
|
+ log.info("######### 6、根据boxId和分组id获取监控点:{}", result);
|
|
|
+ return LeviUtils.getJsonFieldMany(result, null, Map.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 7、根据boxId和监控点id集合获取部分监控点
|
|
|
+ *
|
|
|
+ * @param boxId
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static List<Map> v2BoxDmonGet(String boxId, String id) {
|
|
|
+ String param = JSON.toJSONString(Arrays.asList(id));
|
|
|
+ String result = HttpRequest.post(getUrl(EnergyPlatformConstants.v2BoxDmonGet, boxId))
|
|
|
+ .header("Authorization", coreConnectToken())
|
|
|
+ .header("content-type", "application/json")
|
|
|
+ .body(param)
|
|
|
+ .execute().body();
|
|
|
+ log.info("######### 7、根据boxId和监控点id集合获取部分监控点:{} 参数:{}", result, param);
|
|
|
+ return LeviUtils.getJsonFieldMany(result, null, Map.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 8、根据boxNo和监控点id集合获取部分监控点
|
|
|
+ *
|
|
|
+ * @param boxNo
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static List<Map> v2BoxDmonGetBoxNo(String boxNo, String id) {
|
|
|
+ String param = JSON.toJSONString(Arrays.asList(id));
|
|
|
+ String result = HttpRequest.post(getUrl(EnergyPlatformConstants.v2BoxDmonGetBoxNo, boxNo))
|
|
|
+ .header("Authorization", coreConnectToken())
|
|
|
+ .header("content-type", "application/json")
|
|
|
+ .body(param)
|
|
|
+ .execute().body();
|
|
|
+ log.info("######### 8、根据boxNo和监控点id集合获取部分监控点:{} 参数:{}", result, param);
|
|
|
+ return LeviUtils.getJsonFieldMany(result, null, Map.class);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|