123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- //package com.huimv.eco.sgd;
- //
- //import cn.hutool.core.util.ObjectUtil;
- //import cn.hutool.json.JSONUtil;
- //import com.huimv.eco.sgd.entity.Item;
- //import com.huimv.eco.sgd.entity.Monitory;
- //import com.huimv.eco.sgd.entity.MonitoryGetArgs;
- //import com.huimv.eco.sgd.entity.MonitoryValue;
- //import com.huimv.eco.sgd.fbox.ConsoleLoggerFactory;
- //import com.huimv.eco.sgd.fbox.ServerCaller;
- //import com.huimv.eco.sgd.fbox.StaticCredentialProvider;
- //import com.huimv.eco.sgd.fbox.TokenManager;
- //import com.huimv.eco.sgd.fbox.models.BoxGroup;
- //import com.huimv.eco.sgd.fbox.models.BoxReg;
- //
- //import javax.sound.midi.Soundbank;
- //import java.io.IOException;
- //import java.util.ArrayList;
- //import java.util.HashMap;
- //import java.util.List;
- //import java.util.Map;
- //
- //public class Main {
- //// private static final long SLEEP_TIME = 1000;
- //
- //// public static void main(String[] args) throws IOException, InterruptedException {
- //// ConsoleLoggerFactory loggerFactory = new ConsoleLoggerFactory();
- //// // 指定连接服务器的凭据参数
- //// TokenManager tokenManager = new TokenManager(new StaticCredentialProvider(Global.clientId, Global.clientSecret, Global.username, Global.password), Global.idServerUrl, loggerFactory);
- //// ServerCaller appServer = new ServerCaller(tokenManager, Global.appServerApiUrl, Global.signalrClientId, loggerFactory);
- //// ServerCaller apiBaseServer = new ServerCaller(tokenManager, Global.apiBaserUrl, Global.signalrClientId, loggerFactory);
- //// Global.appServer = appServer;
- //// Global.apiBaseServer = apiBaseServer;
- ////
- //// BoxGroup[] boxGroups = appServer.executeGet("api/client/box/grouped", BoxGroup[].class);
- //// // 返回的是 盒子分组-盒子注册项(BoxReg) 的二层结构
- //// List<Map> list = new ArrayList();
- //// for (BoxGroup group : boxGroups) {
- //// //盒子
- //// for (BoxReg boxReg : group.boxRegs) {
- //// if (boxReg.alias.contains("环控")){
- //// Monitory[] monitories = apiBaseServer.executeGet("/v2/box/" + boxReg.boxUid + "/dmon/grouped", Monitory[].class);
- //// //每个监控点
- //// List<Map> groupnames = new ArrayList();
- //// for (Monitory monitory : monitories) {
- ////// System.out.println("监控点------------->" + monitory.toString());
- //// List names = new ArrayList();
- //// for (Item item : monitory.items) {
- //// String name = item.name;
- //// if ( monitory.name.contains("每个房间") && name != null ) {
- //// if (name.contains("平均温度") || name.contains("湿度") ||name.contains("日用水量") ||name.contains("月用水量") ) {
- //// names.add(name);
- //// }
- //// }
- ////
- //// }
- //// Map map = new HashMap();
- ////
- //// if (ObjectUtil.isNotEmpty(names)) {
- //// MonitoryValue[] monitoryValues = apiBaseServer.executePost("/v2/box/" + boxReg.boxUid + "/dmon/value/get", new MonitoryGetArgs(names, null, new ArrayList()), MonitoryValue[].class);
- //// StringBuilder str = new StringBuilder();
- //// for (MonitoryValue monitoryValue : monitoryValues) {
- //// if (ObjectUtil.isNotEmpty(monitory)) {
- //// str.append(JSONUtil.toJsonStr(monitoryValue));
- //// }
- ////
- //// }
- //// map.put("monitoryValues", str);
- //// map.put("grpName", monitory.name);
- ////// map.put("names",names);
- //// groupnames.add(map);
- //// }
- //// }
- ////
- //// if (ObjectUtil.isNotEmpty(groupnames)){
- //// Map map = new HashMap();
- //// map.put("name",boxReg.alias);
- //// map.put("groupnames",groupnames);
- ////
- //// list.add(map);
- //// }
- ////
- //// }
- //// }
- //// }
- ////
- //// for (Map map : list) {
- //// System.out.println(map.get("name")+"----->"+map.get("groupnames"));
- //// }
- ////
- ////
- //// }
- //
- //
- //
- //
- // private static final long SLEEP_TIME = 3000;
- // public static void main(String[] args) {
- //
- // ConsoleLoggerFactory loggerFactory = new ConsoleLoggerFactory();
- //
- // // 指定连接服务器的凭据参数
- // TokenManager tokenManager = new TokenManager(new StaticCredentialProvider(Global.clientId, Global.clientSecret, Global.username, Global.password), Global.idServerUrl, loggerFactory);
- //
- // ServerCaller commServer = new ServerCaller(tokenManager, Global.commServerApiUrl, Global.signalrClientId, loggerFactory);
- // ServerCaller appServer = new ServerCaller(tokenManager, Global.appServerApiUrl, Global.signalrClientId, loggerFactory);
- // ServerCaller hdataServer = new ServerCaller(tokenManager, Global.hdataServerApiUrl, Global.signalrClientId, loggerFactory);
- //
- // Global.commServer = commServer;
- // Global.appServer = appServer;
- // Global.hdataServer = hdataServer;
- //
- // //建立signalr实例,signalr为单例模式
- // FBoxSignalRConnection fboxSignalR = new FBoxSignalRConnection(Global.commServerSignalRUrl, Global.signalrClientId, tokenManager, Global.proxy, loggerFactory);
- //
- // // 连接SignalR推送通道
- // fboxSignalR.start();
- //// fboxSignalR.onHubProxyCreated();
- // // signalr连上后,请看src/main/java/FBoxSignalRConnection.java 接受推送数据的回调类。
- //
- // System.out.println("Box list:");
- //// try {
- ////以下为调接口示例,可忽略,若使用,参数请根据文档填写自己的账号下的参数
- //
- // // 获取盒子列表接口示例,可忽略
- // try {
- // BoxGroup[] boxGroups = Global.appServer.executeGet("api/client/box/grouped", BoxGroup[].class);
- // // 返回的是 盒子分组-盒子注册项(BoxReg) 的二层结构
- //// for (BoxGroup group : boxGroups) {
- //// for (BoxReg boxReg : group.boxRegs) {
- //// System.out.printf("\t%s\t%s\t%s\n", boxReg.alias, boxReg.box.boxNo, boxReg.box.boxType);
- //// }
- //// }
- //// commServer.executePost("box/300220120152/dmon/start", Object.class);
- // for (BoxGroup boxGroup : boxGroups) {
- // for (BoxReg boxReg : boxGroup.boxRegs) {
- // commServer.executePost("box/" + boxReg.boxUid +"/dmon/start", Object.class);
- // Thread.sleep(1000);
- //
- // }
- // }
- // } catch (Exception e) {
- // e.printStackTrace();
- // }
- //// try {
- //// JsonObject jsonObject = commServer.executePost("dmon/222171502968050130/start", JsonObject.class);
- //// } catch (IOException e) {
- //// System.out.println("调用失败!");
- //// e.printStackTrace();
- //// }
- //
- //// try {
- //// commServer.executePost("box/-6025651360718913057/dmon/start", Object.class);
- //// } catch (Exception e) {
- //// System.out.println("500");
- //// e.printStackTrace();
- //// }
- // System.out.println("测试");
- //
- //
- //
- //
- // // 获取按通道的数据接口示例 (数组第1维是固定两个元素时间和值,第2维是单个通道的所有数据,第3维是请求的每个通道)
- //// Object[][][] result =
- ////// String result =
- //// Global.hdataServer.executePost(String.format("v2/hdata/get"),
- //// new GetByChannelHdataArgs(channelIds, new Date().getTime() - 7 * 86400000, new Date().getTime(), -100, 3),
- ////// String.class);
- //// Object[][][].class);
- ////
- //// System.out.println(result);
- ////
- //// SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyyMMdd");
- ////
- //// for (int i = 0; i < result.length; i++) {
- //// Object[][] channel = result[i];
- //// System.out.print("Channel " + channelNames.get(i));
- //// for (Object[] datum : channel) {
- //// System.out.printf("(%s: %s)", dateFormatter.format(new Date(Math.round((double) datum[0]))), datum[1]);
- //// }
- //// System.out.println();
- //// }
- ////
- //// //获取按行的数据接口示例(每行固定有通道个数个数据,如果这行的时间某些通道没有值,则为null)
- //// ByRowHdata result2 =
- ////// String result2 =
- //// Global.hdataServer.executePost(String.format("v2/hdata/get"),
- //// new GetByRowHdataArgs(channelIds, new Date().getTime() - 7 * 86400000, new Date().getTime(), -100, 3),
- ////// String.class);
- //// ByRowHdata.class);
- ////// System.out.println(result2);
- ////
- //// for (ByRowHdataRow row : result2.rows) {
- //// System.out.print(dateFormatter.format(row.getTime()) + ": ");
- //// Object[] c = row.c;
- //// for (int i = 0; i < c.length; i++) {
- //// Object value = c[i];
- //// if (i == 0) {
- //// System.out.printf("%s", value);
- //// } else {
- //// System.out.printf(",%s", value);
- //// }
- //// }
- //// System.out.println();
- //// }
- //
- //
- //// } catch (IOException e) {
- //// e.printStackTrace();
- //// }
- ////
- ////
- //// Scanner s = new Scanner(System.in);
- //// s.nextLine();
- // }
- //
- //
- //}
|