/*
package com.zksy.environment.config;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import rk.netDevice.sdk.p2.*;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.io.IOException;
import java.text.SimpleDateFormat;

@Component  // 关键：Spring会自动扫描并实例化该组件
public class RSServerConfig {

    private RSServer rsServer;

    // 应用启动时初始化
    @PostConstruct  // 当Bean初始化完成后自动调用
    public void initialize() throws IOException {
        // 初始化服务器
        rsServer = RSServer.Initiate(9801);

        // 添加数据监听器（保持原有逻辑不变）
        rsServer.addDataListener(new IDataListener() {
            @Override
            public void receiveTimmingAck(TimmingAck data) {
                System.out.println("校时应答->设备编号:" + data.getDeviceId()
                        + "\t执行结果：" + data.getStatus());
            }

            @Override
            public void receiveTelecontrolAck(TelecontrolAck data) {
                System.out.println("遥控应答->设备编号:" + data.getDeviceId()
                        + "\t继电器编号:" + data.getRelayId() + "\t执行结果:"
                        + data.getStatus());
            }

            @Override
            public void receiveStoreData(StoreData data) {
                for (NodeData nd : data.getNodeList()) {
                    SimpleDateFormat sdf = new SimpleDateFormat("yy-MM-dd HH:mm:ss");
                    String str = sdf.format(nd.getRecordTime());
                    System.out.println("存储数据->设备地址:" + data.getDeviceId()
                            + "\t节点:" + nd.getNodeId() + "\t温度:" + nd.getTem()
                            + "\t湿度:" + nd.getHum() + "\t存储时间:" + str);
                }
            }

            @Override
            public void receiveRealtimeData(RealTimeData data) {
                for (NodeData nd : data.getNodeList()) {
                    System.out.println("实时数据->设备地址:" + data.getDeviceId()
                            + "\t节点:" + nd.getNodeId() + "\t温度:" + nd.getTem()
                            + "\t湿度:" + nd.getHum() + "\t经度:" + nd.getLng()
                            + "\t纬度:" + nd.getLat() + "\t坐标类型:"
                            + data.getCoordinateType() + "\t继电器状态:"
                            + data.getRelayStatus() + "\t悬浮物:" + nd.getFloatValue());
                }
            }

            @Override
            public void receiveLoginData(LoginData data) {
                System.out.println("登录->设备地址:" + data.getDeviceId());
            }

            @Override
            public void receiveParamIds(ParamIdsData data) {
                String str = "设备参数编号列表->设备编号：" + data.getDeviceId()
                        + "\t参数总数量：" + data.getTotalCount() + "\t本帧参数数量："
                        + data.getCount() + "\r\n";
                for (int paramId : data.getPararmIdList()) {
                    str += paramId + ",";
                }
                System.out.println(str);
            }

            @Override
            public void receiveParam(ParamData data) {
                String str = "设备参数->设备编号：" + data.getDeviceId() + "\r\n";
                for (ParamItem pararm : data.getParameterList()) {
                    str += "参数编号：" + pararm.getParamId()
                            + "\t参数描述：" + pararm.getDescription()
                            + "\t参数值：" + (pararm.getValueDescription() == null ?
                            pararm.getValue() : pararm.getValueDescription().get(pararm.getValue())) + "\r\n";
                }
                System.out.println(str);
            }

            @Override
            public void receiveWriteParamAck(WriteParamAck data) {
                String str = "下载设备参数->设备编号：" + data.getDeviceId()
                        + "\t参数数量：" + data.getCount() + "\t"
                        + (data.isSuccess() ? "下载成功" : "下载失败");
                System.out.println(str);
            }

            @Override
            public void receiveTransDataAck(TransDataAck data) {
                String str = "数据透传->设备编号：" + data.getDeviceId()
                        + "\t响应结果：" + data.getData() + "\r\n字节数：" + data.getTransDataLen();
                System.out.println(str);
            }

            @Override
            public void receiveHeartbeatData(HeartbeatData heartbeatData) {
                // 心跳数据处理逻辑（如需要）
            }
        });

        // 调用异步方法启动服务器
        startServer();
    }

    // 标记为异步方法，由Spring异步执行
    @Async
    public void startServer() {
        try {
            if (rsServer != null) {
                rsServer.start();
                System.out.println("RSServer已异步启动成功");
            }
        } catch (Exception e) {
            System.err.println("RSServer启动失败: " + e.getMessage());
            e.printStackTrace();
        }
    }

    // 应用关闭时执行
    @PreDestroy  // 应用关闭时自动调用
    public void shutdown() {
        if (rsServer != null) {
            try {
                rsServer.stop();
                System.out.println("RSServer已成功停止");
            } catch (Exception e) {
                System.err.println("RSServer停止过程中发生异常: " + e.getMessage());
            }
        }
    }
}
*/
