package com.yfyy.yingtan;

import com.alibaba.fastjson.JSONObject;
import com.yfyy.yingtan.bean.response.DevSubBean;
import com.yfyy.yingtan.subdata.MqttClientThread;
import com.yfyy.yingtan.util.DataUtil;
import org.eclipse.paho.client.mqttv3.MqttException;

import java.util.ArrayList;
import java.util.List;

/**
 * 订阅云飞的数据
 */
public class MainApplication {

    final static String zsDeviceName1 = "861551051613040";
//    final static String zsDeviceName2 = "861551051612711";
    final static String zsDeviceName2 = "864865060474468";
    final static String zsDeviceName3 = "861551051649044";
    final static String zsDeviceName4 = "861551051647956";
    final static String zsDeviceName5 = "861551056101819";
    final static String zsDeviceName6 = "861551051612760";
    final static String zsDeviceName7 = "861551051648814";
    final static String zsDeviceName8 = "861551051648921";
    final static String zsDeviceName9 = "861551051648186";
    final static String zsDeviceName10 = "861551051612844";
    final static String zsDeviceName11 = "861551051648533";
    final static String zsDeviceName12 = "861551051648590";
    final static String zsDeviceName13 = "861551051648749";
    final static String zsDeviceName14 = "861551051610442";
    final static String zsDeviceName15 = "861551051648327";
    final static String zsDeviceName16 = "861551056094311";
    final static String zsDeviceName17 = "861551051648103";
    final static String zsDeviceName18 = "861551051648863";
    final static String zsDeviceName19 = "861551051647964";
    final static String zsDeviceName20 = "861551051625556";
    final static String zsDeviceName21 = "861551051613560";
    final static String zsDeviceName22 = "861551056102015";
    final static String zsDeviceName23 = "861551051648848";
    final static String zsDeviceName24 = "862289058611654";
    final static String zsDeviceName25 = "861551051611580";

    final static String ldDeviceName1 = "861551055314793";
    final static String ldDeviceName2 = "861551056093743";
    final static String ldDeviceName3 = "861551055332910";
    final static String ldDeviceName4 = "861551056091986";
    final static String ldDeviceName5 = "861551056088214";
    final static String ldDeviceName6 = "861551055313266";
    final static String ldDeviceName7 = "861551056092349";
    final static String ldDeviceName8 = "861551056085889";
    final static String ldDeviceName9 = "861551055324479";
    final static String ldDeviceName10 = "861551056094774";
    final static String ldDeviceName11 = "861551056102361";
    final static String ldDeviceName12 = "861551056088347";
    final static String ldDeviceName13 = "861551055313977";
    final static String ldDeviceName14 = "861551055315105";
    final static String ldDeviceName15 = "861551056093545";
    final static String ldDeviceName16 = "861551055309264";
    final static String ldDeviceName17 = "861551055309249";
    final static String ldDeviceName18 = "861551056085996";
    final static String ldDeviceName19 = "861551055313290";
    final static String ldDeviceName20 = "861551055313407";

    public static final List<String> ZS_Device_Name_List = new ArrayList<>();
    public static final List<String> LD_Device_Name_List = new ArrayList<>();

    static {
        ZS_Device_Name_List.add(zsDeviceName1);
        ZS_Device_Name_List.add(zsDeviceName2);
        ZS_Device_Name_List.add(zsDeviceName3);
        ZS_Device_Name_List.add(zsDeviceName4);
        ZS_Device_Name_List.add(zsDeviceName5);
        ZS_Device_Name_List.add(zsDeviceName6);
        ZS_Device_Name_List.add(zsDeviceName7);
        ZS_Device_Name_List.add(zsDeviceName8);
        ZS_Device_Name_List.add(zsDeviceName9);
        ZS_Device_Name_List.add(zsDeviceName10);
        ZS_Device_Name_List.add(zsDeviceName11);
        ZS_Device_Name_List.add(zsDeviceName12);
        ZS_Device_Name_List.add(zsDeviceName13);
        ZS_Device_Name_List.add(zsDeviceName14);
        ZS_Device_Name_List.add(zsDeviceName15);
        ZS_Device_Name_List.add(zsDeviceName16);
        ZS_Device_Name_List.add(zsDeviceName17);
        ZS_Device_Name_List.add(zsDeviceName18);
        ZS_Device_Name_List.add(zsDeviceName19);
        ZS_Device_Name_List.add(zsDeviceName20);
        ZS_Device_Name_List.add(zsDeviceName21);
        ZS_Device_Name_List.add(zsDeviceName22);
        ZS_Device_Name_List.add(zsDeviceName23);
        ZS_Device_Name_List.add(zsDeviceName24);
        ZS_Device_Name_List.add(zsDeviceName25);

        LD_Device_Name_List.add(ldDeviceName1);
        LD_Device_Name_List.add(ldDeviceName2);
        LD_Device_Name_List.add(ldDeviceName3);
        LD_Device_Name_List.add(ldDeviceName4);
        LD_Device_Name_List.add(ldDeviceName5);
        LD_Device_Name_List.add(ldDeviceName6);
        LD_Device_Name_List.add(ldDeviceName7);
        LD_Device_Name_List.add(ldDeviceName8);
        LD_Device_Name_List.add(ldDeviceName9);
        LD_Device_Name_List.add(ldDeviceName10);
        LD_Device_Name_List.add(ldDeviceName11);
        LD_Device_Name_List.add(ldDeviceName12);
        LD_Device_Name_List.add(ldDeviceName13);
        LD_Device_Name_List.add(ldDeviceName14);
        LD_Device_Name_List.add(ldDeviceName15);
        LD_Device_Name_List.add(ldDeviceName16);
        LD_Device_Name_List.add(ldDeviceName17);
        LD_Device_Name_List.add(ldDeviceName18);
        LD_Device_Name_List.add(ldDeviceName19);
        LD_Device_Name_List.add(ldDeviceName20);
    }

    // 订阅云飞yf的数据
    public static void main(String[] args) throws MqttException {


        String HOST = "tcp://120.27.222.26:1883";
        for (String deviceName : ZS_Device_Name_List) {
            MqttClientThread mqttClientThread = new MqttClientThread(HOST,
                    "/yfkj/qxz/pub/" + deviceName,
                    "client" + deviceName);
            mqttClientThread.start();
        }
        for (String deviceName : LD_Device_Name_List) {
            MqttClientThread mqttClientThread = new MqttClientThread(HOST,
                    "/yfkj/qxz/pub/" + deviceName,
                    "client" + deviceName);
            mqttClientThread.start();
        }


        // 测试
//        String msgData = "{\"cmd\":\"terminalData\",\"ext\":{\"StationID\":\"861551055332910\",\"MonitorTime\":\"2022-07-26 20:12:59\",\"data\":[{\"eValue\":\"35.0\",\"eKey\":\"e1\",\"eName\":\"SoilTemperature\",\"eNum\":\"106\"},{\"eValue\":\"28.0\",\"eKey\":\"e2\",\"eName\":\"SoilHumidity\",\"eNum\":\"107\"},{\"eValue\":\"0.0\",\"eKey\":\"e3\",\"eName\":\"WindSpeed\",\"eNum\":\"108\"},{\"eValue\":\"284\",\"eKey\":\"e4\",\"eName\":\"WindDirection\",\"eNum\":\"109\"},{\"eValue\":\"0\",\"eKey\":\"e5\",\"eName\":\"illuminance\",\"eNum\":\"112\"},{\"eValue\":\"0.0\",\"eKey\":\"e6\",\"eName\":\"RainAdd\",\"eNum\":\"115\"},{\"eValue\":\"6.6\",\"eKey\":\"e7\",\"eName\":\"pH\",\"eNum\":\"147\"}]}}";
//        DevSubBean devSubBean = JSONObject.parseObject(msgData, DevSubBean.class);
//        DataUtil.handleAndReport(devSubBean);
    }



}
