package com.njcn.roma.client;

import cn.hutool.core.date.DatePattern;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.huawei.it.eip.ump.client.consumer.ConsumeStatus;
import com.huawei.it.eip.ump.client.consumer.Consumer;
import com.huawei.it.eip.ump.client.listener.MessageListener;
import com.huawei.it.eip.ump.common.exception.UmpException;
import com.huawei.it.eip.ump.common.message.Message;
import com.njcn.roma.pojo.MessageBodyDTO;
import com.njcn.roma.server.WebSocketServer;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * roma
 * 客户端用于订阅主题消费数据
 * @author cdf
 * @date 2024/6/20
 */

@RestController
@RequiredArgsConstructor
public class ClientHandler extends Thread {

    private final WebSocketServer webSocketServer;

    //@Autowired
    //private JdbcTemplate jdbcTemplate;


    private Consumer consumer;


    @Override
    public void run() {
        if (consumer == null) {
            System.out.println("first join ++++++++++++++++++++++++++++++ roma client");
            consumer = new Consumer();
            consumer.setUmpNamesrvUrls("25.36.190.3:19776;25.36.190.4:19776"); // 设置统一消息
            //平台的服务器地址
            consumer.setAppId("X_DNZLXT"); // 设置客户端账号
            consumer.setAppSecret("IoKU7u47seGwzO4CqGmCaQ=="); // 设置客户端密钥
            consumer.setTopic("T_DNZLXT");// 设置 Topic Name
            consumer.setTags("*"); // 设置订阅消息的标签，可以指定消
            //费某一类型的消息，默认*表示消费所有类型的消息
            consumer.setEncryptTransport(false);// 设置是否需要加密传输
            consumer.subscribe(new MessageListener() {
                public ConsumeStatus consume(Message message) {
                    // 消费消息的业务逻辑
                    try {
                        System.out.println("收到新的一轮数据：******************");
                        String topicMsg = new String(message.getBody(), "UTF-8");
                        String devId = message.getProperties().get("deviceIdentifier");
                        System.out.println("Receive>>>>>>>>>>>>: " + topicMsg);
                        JSONObject jsonObject = JSONObject.parseObject(topicMsg);
                        jsonObject.put("customDevId", devId);

                        String time = jsonObject.get("time").toString();
                        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmssX");

                        ZonedDateTime dateTime = ZonedDateTime.parse(time, formatter);
                        String tenTime = dateTime.format(DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN));
                        jsonObject.put("time", tenTime);
                        String temJson = jsonObject.toJSONString();
                        webSocketServer.sendSocketMessageToAll(temJson);
                        //System.out.println("插入数据："+ret);
                        try {
                           // int ret = jdbcTemplate.update("INSERT INTO `pms_history_data` (`time`, `dev_id`, `content`) VALUES (?, ?, ?);", new Object[]{tenTime, devId, temJson});
                        }catch (Exception e){
                            System.out.println("执行sql语句错误"+e.getMessage());
                        }
                    } catch (Exception e) {
                        System.out.println("帮忙拍个照这个是接收消息的报错------------------------------------------------------------");
                        e.printStackTrace();
                    }
                    // 正常接收到消息后，请务必返回 CONSUME_SUCCESS，只有在业务处理失败才返回RECONSUME_LATER
                    return ConsumeStatus.CONSUME_SUCCESS;
                }
            });
            try {
                consumer.start();
            } catch (Exception e) {
                System.out.println("join error >>>>>>>>>>>>>>>>>>> roma client start error");
                consumer = null;
                e.printStackTrace();
            }
            // 启动消费者，建议在应用程序关闭时执行
            //consumer.shutdown();
            //关闭此消费者。
        }
    }


    /**
     * 解析模板
     */
    public void praTemplate(){





        String template = "[{\"datatype\":\"string\",\"description\":\"数据时间\",\"method\":\"R\",\"name\":\"time\",\"unit\":\"\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"string\",\"description\":\"数据类型\",\"method\":\"R\",\"name\":\"DataType\",\"unit\":\"\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"数据标记\",\"method\":\"R\",\"name\":\"DataTag\",\"unit\":\"\",\"enumlist\":[],\"max\":\"1\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"频率\",\"method\":\"R\",\"name\":\"Freq\",\"unit\":\"Hz\",\"enumlist\":[],\"max\":\"60\",\"min\":\"40\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"频率偏差\",\"method\":\"R\",\"name\":\"FreqDev\",\"unit\":\"Hz\",\"enumlist\":[],\"max\":\"10\",\"min\":\"-10\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电流总有效值\",\"method\":\"R\",\"name\":\"A_phsA\",\"unit\":\"A\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电流总有效值\",\"method\":\"R\",\"name\":\"A_phsB\",\"unit\":\"A\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电流总有效值\",\"method\":\"R\",\"name\":\"A_phsC\",\"unit\":\"A\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压总有效值\",\"method\":\"R\",\"name\":\"PhV_phsA\",\"unit\":\"V\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压总有效值\",\"method\":\"R\",\"name\":\"PhV_phsB\",\"unit\":\"V\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压总有效值\",\"method\":\"R\",\"name\":\"PhV_phsC\",\"unit\":\"V\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"AB线电压总有效值\",\"method\":\"R\",\"name\":\"PPV_phsAB\",\"unit\":\"V\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"BC线电压总有效值\",\"method\":\"R\",\"name\":\"PPV_phsBC\",\"unit\":\"V\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"CA线电压总有效值\",\"method\":\"R\",\"name\":\"PPV_phsCA\",\"unit\":\"V\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压偏差\",\"method\":\"R\",\"name\":\"PhVDev_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压偏差\",\"method\":\"R\",\"name\":\"PhVDev_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压偏差\",\"method\":\"R\",\"name\":\"PhVDev_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"三相总有功功率\",\"method\":\"R\",\"name\":\"TotW\",\"unit\":\"kW\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"-65536\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"三相总无功功率\",\"method\":\"R\",\"name\":\"TotVar\",\"unit\":\"kVar\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"-65536\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"三相总视在功率\",\"method\":\"R\",\"name\":\"TotVA\",\"unit\":\"kVA\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"-65536\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"三相功率因数\",\"method\":\"R\",\"name\":\"TotPF\",\"unit\":\"\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"电压正序分量\",\"method\":\"R\",\"name\":\"SeqV_C1\",\"unit\":\"V\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"电压负序分量\",\"method\":\"R\",\"name\":\"SeqV_C2\",\"unit\":\"V\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"电压零序分量\",\"method\":\"R\",\"name\":\"SeqV_C0\",\"unit\":\"V\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"电压负序不平衡度\",\"method\":\"R\",\"name\":\"ImbNgV\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"电压零序不平衡度\",\"method\":\"R\",\"name\":\"ImbZroV\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压基波有效值\",\"method\":\"R\",\"name\":\"HFundPhV_phsA\",\"unit\":\"V\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压基波有效值\",\"method\":\"R\",\"name\":\"HFundPhV_phsB\",\"unit\":\"V\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压基波有效值\",\"method\":\"R\",\"name\":\"HFundPhV_phsC\",\"unit\":\"V\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压谐波总畸变率\",\"method\":\"R\",\"name\":\"ThdPhV_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压谐波总畸变率\",\"method\":\"R\",\"name\":\"ThdPhV_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压谐波总畸变率\",\"method\":\"R\",\"name\":\"ThdPhV_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压2次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H2_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压3次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H3_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压4次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H4_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压5次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H5_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压6次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H6_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压7次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H7_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压8次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H8_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压9次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H9_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压10次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H10_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压11次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H11_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压12次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H12_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压13次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H13_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压14次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H14_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压15次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H15_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压16次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H16_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压17次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H17_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压18次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H18_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压19次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H19_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压20次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H20_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压21次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H21_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压22次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H22_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压23次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H23_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压24次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H24_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压25次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H25_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压2次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H2_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压3次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H3_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压4次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H4_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压5次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H5_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压6次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H6_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压7次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H7_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压8次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H8_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压9次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H9_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压10次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H10_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压11次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H11_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压12次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H12_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压13次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H13_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压14次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H14_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压15次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H15_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压16次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H16_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压17次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H17_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压18次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H18_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压19次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H19_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压20次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H20_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压21次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H21_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压22次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H22_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压23次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H23_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压24次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H24_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压25次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H25_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压2次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H2_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压3次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H3_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压4次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H4_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压5次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H5_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压6次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H6_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压7次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H7_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压8次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H8_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压9次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H9_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压10次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H10_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压11次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H11_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压12次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H12_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压13次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H13_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压14次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H14_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压15次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H15_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压16次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H16_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压17次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H17_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压18次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H18_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压19次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H19_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压20次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H20_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压21次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H21_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压22次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H22_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压23次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H23_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压24次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H24_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压25次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H25_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相短时闪变\",\"method\":\"R\",\"name\":\"PstPhV_phsA\",\"unit\":\"\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相短时闪变\",\"method\":\"R\",\"name\":\"PstPhV_phsB\",\"unit\":\"\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相短时闪变\",\"method\":\"R\",\"name\":\"PstPhV_phsC\",\"unit\":\"\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相长时闪变\",\"method\":\"R\",\"name\":\"PltPhV_phsA\",\"unit\":\"\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相长时闪变\",\"method\":\"R\",\"name\":\"PltPhV_phsB\",\"unit\":\"\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相长时闪变\",\"method\":\"R\",\"name\":\"PltPhV_phsC\",\"unit\":\"\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1}]";
        JSONArray jsonArray = JSONArray.parseArray(template);


        System.out.println("解析结束");

    }


    ExecutorService executor = Executors.newFixedThreadPool(10); // 假设使用10个线程的线程池

    // 消息消费回调
    void onMessageReceived(Message message) {
        // 将消息处理逻辑封装为Runnable任务
        Runnable task = () -> {
            try {
                // 处理消息
                processMessage(message);
            } catch (Exception e) {
                // 处理异常
                handleError(e);
            }
        };

        // 提交任务到线程池
        executor.submit(task);
    }

    void processMessage(Message message) {
        // 实际的消息处理逻辑
    }

    void handleError(Exception e) {
        // 错误处理逻辑
    }










}
