Browse Source

能耗大屏8个接口

Levi.u 4 years ago
parent
commit
28d2eaceeb

+ 106 - 0
src/main/java/com/ebei/screen/common/constants/EnergyPlatformConstants.java

@@ -0,0 +1,106 @@
+package com.ebei.screen.common.constants;
+
+/**
+ * EBA接口信息
+ *
+ * @author Levi.u
+ * @date 2021/1/15 11:42
+ */
+public interface EnergyPlatformConstants {
+
+    /**
+     * F+Gateway客户端账号
+     */
+    String username = "dengcl";
+
+    /**
+     * F+Gateway客户端密码
+     */
+    String password = "api123456";
+
+    /**
+     * 开发者账号
+     */
+    String client_id = "fcs2";
+
+    /**
+     * 开发者密码
+     */
+    String client_secret = "f9d8941667ea19b6b27eb706636580a8";
+
+    /**
+     * 未知参数
+     */
+    String scope = "openid offline_access fbox email profile";
+
+    /**
+     * 未知参数
+     */
+    String grant_type = "password";
+
+    /**
+     * 登录服务器
+     */
+    String idServer = "http://account.link-cloud.com/";
+
+    /**
+     * 主应用服务器
+     */
+    String appServer = "http://app.link-cloud.com/";
+
+    /**
+     * 历史记录服务器
+     */
+    String hsServer = "http://hs.link-cloud.com/api/";
+
+    /**
+     * 通讯服务器(boxRegs下box下的cs中的apiBaseUrl)
+     */
+    String apiBaseUrl = "http://cs.link-cloud.com/api/";
+
+    /**
+     * signalR服务(boxRegs下box下的cs中的signalRUrl)
+     */
+    String signalRUrl = "http://cs.link-cloud.com/push/";
+
+    /**
+     * 1、用户登录
+     */
+    String coreConnectToken = idServer + "core/connect/token";
+
+    /**
+     * 2、获取当前用户名下盒子列表
+     */
+    String apiClientBoxGrouped = appServer + "api/client/box/grouped";
+
+    /**
+     * 3、根据boxNo获取单个盒子 [boxNo:盒子编码]
+     */
+    String apiClientBoxRegBoxNo = appServer + "api/client/box/reg/boxno/{0}";
+
+    /**
+     * 4、根据boxId获取监控点分组 [boxId:盒子ID]
+     */
+    String v2BoxDmonGroups = apiBaseUrl + "v2/box/{0}/dmon/groups";
+
+    /**
+     * 5、根据boxNo获取监控点分组 [boxNo:盒子编码]
+     */
+    String V2BoxDmonGroupsBoxNo = apiBaseUrl + "v2/box/dmon/groups?boxNo={0}";
+
+    /**
+     * 6、根据boxId和分组id获取监控点 [boxId:盒子ID,groupId:监控点分组ID]
+     */
+    String v2BoxDmonGroupDmon = apiBaseUrl + "v2/box/{0}/dmongroup/{1}/dmon";
+
+    /**
+     * 7、根据boxId和监控点id集合获取部分监控点 [boxId:盒子ID]
+     */
+    String v2BoxDmonGet = apiBaseUrl + "v2/box/{0}/dmon/get";
+
+    /**
+     * 8、根据boxNo和监控点id集合获取部分监控点 [boxNo:盒子编码]
+     */
+    String v2BoxDmonGetBoxNo = apiBaseUrl + "v2/box/dmon/get?boxNo={0}";
+
+}

+ 0 - 9
src/main/java/com/ebei/screen/common/util/EbaUtils.java

@@ -4,8 +4,6 @@ import cn.hutool.http.HttpRequest;
 import com.alibaba.fastjson.JSON;
 import com.ebei.screen.common.constants.EbaSystemConstants;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.mongodb.core.MongoTemplate;
 import org.springframework.stereotype.Component;
 
 import java.util.List;
@@ -23,13 +21,6 @@ public class EbaUtils {
 
     private static Integer SUCCESS_CODE = 200;
 
-    private static MongoTemplate mongoTemplate;
-
-    @Autowired
-    public void setMongoTemplate(MongoTemplate mongoTemplate) {
-        EbaUtils.mongoTemplate = mongoTemplate;
-    }
-
     /**
      * 判断执行结果是否成功
      *

+ 164 - 0
src/main/java/com/ebei/screen/common/util/EnergyUtils.java

@@ -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);
+    }
+
+}