//package com.beanit.test;
|
//
|
//import com.alibaba.fastjson.JSON;
|
//import com.beanit.openiec61850.*;
|
//import com.beanit.rabbitmq.Producer;
|
//import com.beanit.socket.Client;
|
//import com.beanit.test.utils.*;
|
//import com.beanit.test.view.MyTableRenderer;
|
//import org.slf4j.Logger;
|
//import org.slf4j.LoggerFactory;
|
//import sun.misc.BASE64Encoder;
|
//
|
//import javax.swing.*;
|
//import javax.swing.event.TableModelEvent;
|
//import javax.swing.event.TableModelListener;
|
//import javax.swing.table.DefaultTableModel;
|
//import java.awt.*;
|
//import java.awt.event.ActionEvent;
|
//import java.awt.event.ActionListener;
|
//import java.awt.event.WindowAdapter;
|
//import java.awt.event.WindowEvent;
|
//import java.io.IOException;
|
//import java.net.InetAddress;
|
//import java.net.UnknownHostException;
|
//import java.util.*;
|
//import java.util.List;
|
//import java.util.Timer;
|
////电科院送检测试类
|
///**
|
// * @author LiBiChao
|
// * @create 2019-08-06
|
// * @update 2020-10-20
|
// */
|
//public class MyClient {
|
//
|
// private static final Logger logger = LoggerFactory.getLogger(MyClient.class);
|
//
|
// private Producer producer;
|
//
|
// private JTable mainTable;
|
// private DefaultTableModel tableModel;
|
// private String[] columnTitles = { "变电站", "IP地址", "端口", "上次采集时间"};
|
// private JScrollPane jsPane;
|
// private Thread threads[];
|
// private Timer timers[];
|
// private Timer monitorTimer;
|
// private Timer wakeUpTimer;
|
// private Timer networkReviewTimer;
|
// private JLabel labelTips;
|
// private JTextField txtCollectDelay;
|
// private JTextField txtSubstationDelay;
|
// private JTextField txtSubstationList;
|
// private JRadioButton radioCollectData = new JRadioButton("是");
|
// private JRadioButton radioNotCollectData = new JRadioButton("否");
|
// private JRadioButton radioCollectFile = new JRadioButton("是");
|
// private JRadioButton radioNotCollectFile = new JRadioButton("否");
|
// private JRadioButton radioDeleteRemote = new JRadioButton("是");
|
// private JRadioButton radioNotDeleteRemote = new JRadioButton("否");
|
// private boolean isCollectRemoteData = true;
|
// private boolean isCollectRemoteFile = false;
|
// private boolean isDeleteRemoteFile = false;
|
// private static int CollectIntervalTimes = 1000 * 60 * 60 * 2; //同一站点采集两个小时
|
// private static int SubstaionIntervalTimes = 1000 * 60 * 3; //站点间采集间隔3分钟
|
// private JButton btnSetting;
|
// private JButton btnStart;
|
// private JButton btnDetail;
|
// private boolean isRunning = false;
|
//
|
// private static String sendMessageMethod = "mq"; //可选mq和areaIII
|
// private static Client client;
|
//
|
// public void ClientMain(){
|
//
|
// logger.debug("ClientMain init...");
|
//
|
// JFrame frm = new JFrame();
|
// frm.setLocation(100, 100);
|
// frm.setSize(680, 610);
|
// //frm.setBounds(100, 100, 300, 300); // 功能与上面相同
|
// frm.setTitle("云南电网变电在线监测采集系统 -【二区主站】");
|
// Container c = frm.getContentPane(); // frm中包含一个内容窗格, 需要获取内容窗格,再设置背景颜色,直接设置frm的背景颜色会被内容窗格挡住
|
// c.setBackground(new Color(230, 230, 230));
|
// frm.setLayout(null); // 如过不设置为null默认,按钮会充满整个内容框,挡住背景颜色
|
//
|
// //配置信息-采集间隔
|
// JLabel labelCollect = new JLabel("采集间隔:");
|
// labelCollect.setLocation(50, 10);
|
// labelCollect.setSize(70, 25);
|
// frm.add(labelCollect);
|
// txtCollectDelay = new JTextField();
|
// txtCollectDelay.setLocation(120, 10);
|
// txtCollectDelay.setSize(50, 25);
|
// txtCollectDelay.setText("120");
|
// txtCollectDelay.setEditable(false);
|
// frm.add(txtCollectDelay);
|
// JLabel collectUnit = new JLabel("分钟");
|
// collectUnit.setLocation(170, 10);
|
// collectUnit.setSize(80, 25);
|
// frm.add(collectUnit);
|
// //配置信息-站点间隔
|
// JLabel labelSubstation = new JLabel("站点间隔:");
|
// labelSubstation.setLocation(220, 10);
|
// labelSubstation.setSize(70, 25);
|
// frm.add(labelSubstation);
|
// txtSubstationDelay = new JTextField();
|
// txtSubstationDelay.setLocation(290, 10);
|
// txtSubstationDelay.setSize(50, 25);
|
// txtSubstationDelay.setText("5");
|
// txtSubstationDelay.setEditable(false);
|
// frm.add(txtSubstationDelay);
|
// JLabel substationUnit = new JLabel("分钟");
|
// substationUnit.setLocation(340, 10);
|
// substationUnit.setSize(80, 25);
|
// frm.add(substationUnit);
|
// //配置信息-采集列表
|
// JLabel labelSubstationList = new JLabel("列表配置:");
|
// labelSubstationList.setLocation(390, 10);
|
// labelSubstationList.setSize(70, 25);
|
// frm.add(labelSubstationList);
|
// txtSubstationList = new JTextField();
|
// txtSubstationList.setLocation(460, 10);
|
// txtSubstationList.setSize(120, 25);
|
// txtSubstationList.setText("substation_list.txt");
|
// txtSubstationList.setEditable(false);
|
// frm.add(txtSubstationList);
|
// //配置信息-采集数据
|
// JLabel labelCollectData = new JLabel("采集数据:");
|
// labelCollectData.setLocation(50, 40);
|
// labelCollectData.setSize(70, 25);
|
// frm.add(labelCollectData);
|
// ButtonGroup collectDataBtnGroup = new ButtonGroup();
|
// collectDataBtnGroup.add(radioCollectData);
|
// radioCollectData.setLocation(120, 40);
|
// radioCollectData.setSize(40, 25);
|
// radioCollectData.setSelected(true);
|
// radioCollectData.setEnabled(false);
|
// frm.add(radioCollectData);
|
// collectDataBtnGroup.add(radioNotCollectData);
|
// radioNotCollectData.setLocation(160, 40);
|
// radioNotCollectData.setSize(40, 25);
|
// radioNotCollectData.setEnabled(false);
|
// frm.add(radioNotCollectData);
|
// //配置信息-采集文件
|
// JLabel labelCollectFile = new JLabel("采集谱图:");
|
// labelCollectFile.setLocation(220, 40);
|
// labelCollectFile.setSize(70, 25);
|
// frm.add(labelCollectFile);
|
// ButtonGroup collectFileBtnGroup = new ButtonGroup();
|
// collectFileBtnGroup.add(radioCollectFile);
|
// radioCollectFile.setLocation(290, 40);
|
// radioCollectFile.setSize(40, 25);
|
// radioCollectFile.setEnabled(false);
|
// frm.add(radioCollectFile);
|
// collectFileBtnGroup.add(radioNotCollectFile);
|
// radioNotCollectFile.setLocation(330, 40);
|
// radioNotCollectFile.setSize(40, 25);
|
// radioNotCollectFile.setSelected(true);
|
// radioNotCollectFile.setEnabled(false);
|
// frm.add(radioNotCollectFile);
|
// //配置信息-删除远端文件
|
// JLabel labelDeleteRemote = new JLabel("采完删除:");
|
// labelDeleteRemote.setLocation(390, 40);
|
// labelDeleteRemote.setSize(70, 25);
|
// frm.add(labelDeleteRemote);
|
// ButtonGroup deleteBtnGroup = new ButtonGroup();
|
// deleteBtnGroup.add(radioDeleteRemote);
|
// radioDeleteRemote.setLocation(460, 40);
|
// radioDeleteRemote.setSize(40, 25);
|
// radioDeleteRemote.setEnabled(false);
|
// frm.add(radioDeleteRemote);
|
// deleteBtnGroup.add(radioNotDeleteRemote);
|
// radioNotDeleteRemote.setLocation(500, 40);
|
// radioNotDeleteRemote.setSize(40, 25);
|
// radioNotDeleteRemote.setSelected(true);
|
// radioNotDeleteRemote.setEnabled(false);
|
// frm.add(radioNotDeleteRemote);
|
//
|
// //配置按钮
|
// btnSetting = new JButton("配置");
|
// btnSetting.setLocation(550, 80);
|
// btnSetting.setSize(90, 30);
|
// btnSetting.setBackground(new Color(224, 234, 244));
|
// btnSetting.addActionListener(new ActionListener() {
|
// @Override
|
// public void actionPerformed(ActionEvent e) {
|
// //logger.debug(e.getActionCommand());
|
// if(isRunning){
|
// //logger.debug("请先停止采集再进行配置!#_#");
|
// labelTips("请先停止采集再进行配置!", "warning");
|
// return;
|
// }
|
// if(txtCollectDelay.isEditable()){
|
// int intCollectIntervalMinute = Integer.valueOf(txtCollectDelay.getText());
|
// CollectIntervalTimes = intCollectIntervalMinute * 60 * 1000;
|
// int intSubstationIntervalMinute = Integer.valueOf(txtSubstationDelay.getText());
|
// SubstaionIntervalTimes = intSubstationIntervalMinute * 60 * 1000;
|
// if(radioCollectData.isSelected()){
|
// isCollectRemoteData = true;
|
// }else {
|
// isCollectRemoteData = false;
|
// }
|
// if(radioCollectFile.isSelected()){
|
// isCollectRemoteFile = true;
|
// }else {
|
// isCollectRemoteFile = false;
|
// }
|
// if(radioDeleteRemote.isSelected()){
|
// isDeleteRemoteFile = true;
|
// }else{
|
// isDeleteRemoteFile = false;
|
// }
|
// txtCollectDelay.setEditable(false);
|
// txtSubstationDelay.setEditable(false);
|
// txtSubstationList.setEditable(false);
|
// radioCollectData.setEnabled(false);
|
// radioNotCollectData.setEnabled(false);
|
// radioCollectFile.setEnabled(false);
|
// radioNotCollectFile.setEnabled(false);
|
// radioDeleteRemote.setEnabled(false);
|
// radioNotDeleteRemote.setEnabled(false);
|
// //重新加载站点列表
|
// dataLoad();
|
// btnSetting.setText("配置");
|
// labelTips("配置保存成功!", "");
|
// }else {
|
// txtCollectDelay.setEditable(true);
|
// txtSubstationDelay.setEditable(true);
|
// txtSubstationList.setEditable(true);
|
// radioCollectData.setEnabled(true);
|
// radioNotCollectData.setEnabled(true);
|
// radioCollectFile.setEnabled(true);
|
// radioNotCollectFile.setEnabled(true);
|
// radioDeleteRemote.setEnabled(true);
|
// radioNotDeleteRemote.setEnabled(true);
|
// btnSetting.setText("保存");
|
// txtCollectDelay.requestFocus();
|
// labelTips("编辑配置...", "");
|
// }
|
// }
|
// });
|
// frm.add(btnSetting);
|
// //采集详情
|
// btnDetail = new JButton("采集详情");
|
// btnDetail.setLocation(150, 80);
|
// btnDetail.setSize(90, 30);
|
// btnDetail.setBackground(new Color(224, 234, 244));
|
// btnDetail.addActionListener(new ActionListener() {
|
// @Override
|
// public void actionPerformed(ActionEvent e) {
|
// logger.debug(e.getActionCommand());
|
// int rowIndex = mainTable.getSelectedRow();
|
// if(rowIndex < 0){
|
// //logger.debug("未选择站点!#_#");
|
// labelTips("未选择站点!", "warning");
|
// return;
|
// }
|
// MyClientGui myClientGui = new MyClientGui();
|
// myClientGui.setIpTextField(tableModel.getValueAt(rowIndex, 1).toString());
|
// myClientGui.setPortTextField(tableModel.getValueAt(rowIndex, 2).toString());
|
// //myClientGui.dispose();
|
// }
|
// });
|
// frm.add(btnDetail);
|
//
|
// //确定按钮
|
// btnStart = new JButton("开始采集");
|
// btnStart.setLocation(50, 80);
|
// btnStart.setSize(90, 30);
|
// btnStart.setBackground(new Color(224, 234, 244));
|
// btnStart.addActionListener(new ActionListener() {
|
// @Override
|
// public void actionPerformed(ActionEvent e) {
|
// if(tableModel.getRowCount() <= 0){
|
// //logger.warn("采集列表为空!");
|
// labelTips("采集列表为空!", "warning");
|
// return;
|
// }
|
// if(txtCollectDelay.isEditable()){
|
// //logger.warn("请先保存配置!");
|
// labelTips("请先保存配置!", "warning");
|
// return;
|
// }
|
//
|
// if (ConfigUtil.isNetworkReview){
|
// if (!isRunning) {
|
// startNetworkReview();
|
// isRunning = true;
|
// btnStart.setText("停止检查");
|
// }else{
|
// networkReviewTimer.cancel();
|
// isRunning = false;
|
// btnStart.setText("开始检查");
|
// }
|
// return;
|
// }
|
//
|
// if(!isRunning) {
|
// //启动状态监视器
|
// monitorSchedule();
|
// //重连定时器
|
// wakeUpSchedule();
|
// isRunning = true;
|
// btnStart.setText("停止采集");
|
// collectStart();
|
// }else{
|
// collectStop();
|
// //停止监视器
|
// monitorTimer.cancel();
|
// logger.debug("状态监视器已停止。");
|
// //停止重连器
|
// wakeUpTimer.cancel();
|
// logger.debug("重连定时器已停止。");
|
// isRunning = false;
|
// btnStart.setText("开始采集");
|
// }
|
// }
|
// });
|
// frm.add(btnStart);
|
// //站点增加按钮
|
// JButton btnAddRow = new JButton("增加站点");
|
// btnAddRow.setLocation(250, 80);
|
// btnAddRow.setSize(90, 30);
|
// btnAddRow.setBackground(new Color(224, 234, 244));
|
// btnAddRow.addActionListener(new ActionListener() {
|
// @Override
|
// public void actionPerformed(ActionEvent e) {
|
// if(isRunning){
|
// logger.warn("采集中不能增加站点!");
|
// return;
|
// }
|
// //tableModel.setRowCount(tableModel.getDataVector().size() + 1);
|
// tableModel.setRowCount(tableModel.getRowCount() + 1);
|
// tableModel.setValueAt("null", tableModel.getRowCount() - 1, 0);
|
// mainTable.changeSelection(tableModel.getRowCount() - 1, 0, true, false);
|
// }
|
// });
|
// frm.add(btnAddRow);
|
//
|
// //删除增加按钮
|
// JButton btnDelRow = new JButton("删除站点");
|
// btnDelRow.setLocation(350, 80);
|
// btnDelRow.setSize(90, 30);
|
// btnDelRow.setBackground(new Color(224, 234, 244));
|
// btnDelRow.addActionListener(new ActionListener() {
|
// @Override
|
// public void actionPerformed(ActionEvent e) {
|
// if(isRunning){
|
// logger.warn("采集中不能删除站点!");
|
// labelTips("采集中不能删除站点!", "warning");
|
// return;
|
// }
|
// int rowIndex = mainTable.getSelectedRow();
|
// if(rowIndex < 0){
|
// logger.debug("未选择站点!#_#");
|
// labelTips("未选择站点#_#!", "warning");
|
// return;
|
// }
|
// boolean flag = ConfigUtil.delSubstation(txtSubstationList.getText(), rowIndex);
|
// if (flag) {
|
// tableModel.removeRow(rowIndex);
|
// }
|
// logger.debug("--------------- 删除:" + flag + "--------------------");
|
// }
|
// });
|
// frm.add(btnDelRow);
|
//
|
// //JTable
|
// tableModel = new DefaultTableModel(columnTitles, 0);
|
// tableModel.addTableModelListener(new TableModelListener() {
|
// @Override
|
// public void tableChanged(TableModelEvent e) {
|
//
|
// if(e.getType() == TableModelEvent.UPDATE){
|
// if(e.getLastRow() >= 0){
|
// int rowIndex = e.getLastRow();
|
// int colIndex = e.getColumn();
|
// String strValue = tableModel.getValueAt(rowIndex, colIndex).toString();
|
// //System.out.println(" setSubstationValue: [" + rowIndex + ", " + colIndex + "]=>" + strValue);
|
// boolean flag = ConfigUtil.setSubstationValue(txtSubstationList.getText(), rowIndex, colIndex, strValue);
|
// //System.out.println(flag + " setSubstationValue: [" + rowIndex + ", " + colIndex + "]=>" + strValue);
|
// }
|
// }
|
// }
|
// });
|
//
|
// mainTable = new JTable(tableModel);
|
// //mainTable.getColumnModel().getColumn(1).setCellEditor(new MyRender());//设置编辑器
|
// //mainTable.getColumnModel().getColumn(1).setCellRenderer(new MyRender() );
|
// jsPane = new JScrollPane(mainTable);
|
// jsPane.setSize(600, 400);
|
// jsPane.setLocation(30, 130);
|
// frm.add(jsPane);
|
// mainTable.setDefaultRenderer(Object.class, new MyTableRenderer());
|
//
|
// //底部提示信息
|
// JLabel labelTipsTitle = new JLabel("提示信息:");
|
// labelTipsTitle.setLocation(50, 530);
|
// labelTipsTitle.setSize(70, 25);
|
// frm.add(labelTipsTitle);
|
// labelTips = new JLabel("welcome!");
|
// labelTips.setLocation(120, 530);
|
// labelTips.setSize(500, 25);
|
// frm.add(labelTips);
|
//
|
// dataLoad();
|
//
|
// //frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
// frm.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
// frm.addWindowListener(new WindowAdapter() {
|
// @Override
|
// public void windowClosing(WindowEvent e) {
|
// super.windowClosing(e);
|
// int result = JOptionPane.showConfirmDialog(null, "确认退出?", "确认",JOptionPane.OK_CANCEL_OPTION,JOptionPane.INFORMATION_MESSAGE);
|
// if (result == JOptionPane.OK_OPTION) {
|
// // 退出
|
// System.exit(0);
|
// }
|
// }
|
// });
|
//
|
// if (ConfigUtil.isNetworkReview){
|
// btnStart.setText("开始检查");
|
// btnAddRow.setEnabled(false);
|
// btnDelRow.setEnabled(false);
|
// btnDetail.setEnabled(false);
|
// btnSetting.setEnabled(false);
|
// }
|
//
|
// frm.setVisible(true);
|
//
|
// // 三区服务连接
|
// //client = new Client();
|
// //client.init();
|
// //client.conn();
|
//
|
//
|
// //初始化消息队列
|
// if(ConfigUtil.isDebug){
|
// return;
|
// }
|
// try {
|
// producer = new Producer("ztjc");
|
// logger.debug("消息队列初始化完成!^_^");
|
// } catch (IOException e) {
|
// System.out.println("消息队列初始化失败!@_@");
|
// e.printStackTrace();
|
// }
|
// }
|
//
|
// /**
|
// * 状态监视器
|
// */
|
// private void monitorSchedule(){
|
// monitorTimer = new Timer();
|
// monitorTimer.schedule(new TimerTask() {
|
// @Override
|
// public void run() {
|
// //刷新mainTabled的数据状态,可发送心跳
|
// //System.out.print("*");
|
// int rowIndex = mainTable.getSelectedRow();
|
// int colIndex = mainTable.getSelectedColumn();
|
// //logger.debug(rowIndex + " - " + colIndex);
|
// mainTable.changeSelection(rowIndex, colIndex, true, false);
|
// mainTable.changeSelection(rowIndex, colIndex, true, false);
|
// }
|
// }, 1000, 3000);
|
// logger.debug("状态监视器已启动。");
|
// }
|
//
|
// /**
|
// * 定时唤醒任务
|
// */
|
// private void wakeUpSchedule(){
|
// wakeUpTimer = new Timer();
|
// int substationCount = mainTable.getRowCount();
|
// long startTime = substationCount * SubstaionIntervalTimes;
|
// wakeUpTimer.schedule(new TimerTask() {
|
// @Override
|
// public void run() {
|
// logger.debug("重连定时器开始执行...");
|
// for (int i = 0; i < substationCount; i++){
|
// String name = tableModel.getValueAt(i,0).toString();
|
// String ip = tableModel.getValueAt(i,1).toString();
|
// int port = Integer.valueOf(tableModel.getValueAt(i,2).toString());
|
// String lastTime = tableModel.getValueAt(i,3).toString();
|
// if(lastTime != null && lastTime.length() == 19){
|
// long millisTime = SimpleUtils.DateTimeToMillisTime(lastTime);
|
// if((System.currentTimeMillis() - 3 * 60 * 60 * 1000) > millisTime){
|
// logger.debug("重连定时器【" + (i + 1) + " - " + name + "】 开始连接至变电站 => " + ip + ":" + port
|
// + " [" + SimpleUtils.CurrentDateTime() + "]");
|
// collectToSubstation(ip, port, i);
|
// }else{
|
// continue;
|
// }
|
// }else{
|
// logger.debug("重连定时器【" + (i + 1) + " - " + name + "】 开始连接至变电站 => " + ip + ":" + port
|
// + " [" + SimpleUtils.CurrentDateTime() + "]");
|
// collectToSubstation(ip, port, i);
|
// }
|
// }
|
// }
|
// }, startTime, 5 * 60 * 1000);
|
// logger.debug("重连定时器" + Math.floor((startTime/60)/1000) + "分钟后启动。");
|
// }
|
//
|
// protected void collectToSubstation(String ip, int port, int rowIndex){
|
// String subStationName = mainTable.getValueAt(rowIndex, 0).toString();
|
// ClientSap clientSap = new ClientSap();
|
// //clientSap.setMaxMmsPduSize(6500000);
|
// //logger.debug("MaxMmsPduSize: " + clientSap.getMaxMmsPduSize());
|
// InetAddress address;
|
// try {
|
// address = InetAddress.getByName(ip);
|
// } catch (UnknownHostException e1) {
|
// logger.error("【" + subStationName + "】 IP地址错误: " + "ip Address ERROR" );
|
// labelTips("【" + subStationName + "】 IP地址错误!", "error");
|
// e1.printStackTrace();
|
// return;
|
// }
|
// try {
|
// if (port < 1 || port > 0xFFFF) {
|
// throw new NumberFormatException("端口超出范围: " + "port must be in range [1, 65535]");
|
// }
|
// } catch (NumberFormatException e) {
|
// logger.error("【" + subStationName + "】 端口异常: " + "port ERROR");
|
// labelTips("【" + subStationName + "】 端口异常!", "error");
|
// e.printStackTrace();
|
// return;
|
// }
|
//
|
// //clientSap.setTSelLocal(settingsFrame.getTselLocal());
|
// //clientSap.setTSelRemote(settingsFrame.getTselRemote());
|
//
|
// ClientAssociation association;
|
// try {
|
// association = clientSap.associate(address, port, null, null);
|
// } catch (IOException e) {
|
// logger.debug("【" + subStationName + "】 连接失败: " + e.getMessage());
|
// labelTips("【" + subStationName + "】 连接失败!", "error");
|
//// if(ConfigUtil.isNetworkReview) {
|
//// checkNet(ip, port);
|
//// }
|
// sendErrorLog(subStationName, ip, e.getMessage());
|
// checkNet(subStationName, ip, port);
|
// return;
|
// }
|
//
|
// //数据读取
|
// if(isCollectRemoteData) {
|
// boolean flag = readData(association, ip, subStationName);
|
// if(flag){
|
// String strDate = SimpleUtils.CurrentDateTime();
|
// tableModel.setValueAt(strDate, rowIndex, 3);
|
// boolean flag2 = ConfigUtil.setSubstationValue(txtSubstationList.getText(), rowIndex, 3, strDate);
|
// logger.debug("【" + subStationName + "】 本次采集任务完成!");
|
// labelTips("【" + subStationName + "】 完成一次采集任务!", "");
|
// }else{
|
// logger.debug("【" + subStationName + "】 本次采集任务结束,但存在异常*_*!");
|
// labelTips("【" + subStationName + "】 采集任务结束,存在异常!", "error");
|
// checkNet(subStationName, ip, port);
|
// }
|
// }
|
//
|
// if(!isCollectRemoteFile){
|
// association.disconnect();
|
// association.close();
|
// //logger.debug(association.isOpen() + "");
|
// return;
|
// }
|
// //文件读取
|
// String dirName = "";
|
// List fileList = null;
|
// try {
|
// fileList = association.getFileDirectory(dirName);
|
// } catch (ServiceError serviceError) {
|
// serviceError.printStackTrace();
|
// } catch (IOException e) {
|
// e.printStackTrace();
|
// }
|
// for(int i = 0; i < fileList.size(); i++){
|
// FileInformation remoteFile = (FileInformation)fileList.get(i);
|
// String fileName = remoteFile.getFilename();
|
// if(fileName.contains("COMTRADE")){
|
// dirName = fileName;
|
// try {
|
// fileList = association.getFileDirectory(dirName);
|
// } catch (ServiceError serviceError) {
|
// serviceError.printStackTrace();
|
// } catch (IOException e) {
|
// e.printStackTrace();
|
// }
|
// break;
|
// }
|
// }
|
// if(fileList == null){
|
// logger.debug("【" + subStationName + "】 远程文件目录读取失败");
|
// labelTips("【" + subStationName + "】 远程文件目录读取失败!", "error");
|
// }
|
// //定义文件临时存储目录
|
// final String tempSavePath = "temp/tempSavePath/" + ip;
|
// FileOption.creatDir(tempSavePath); //创建目录
|
// //定义文件采集日志目录
|
// final String tempLogFile = "log.txt";
|
// String lastLog = FileOption.readFileLastLine(tempSavePath, tempLogFile);
|
// if(!FileOption.fileExist(tempSavePath + "/" + tempLogFile)){
|
// FileOption.createFile(tempSavePath, tempLogFile); //创建文件
|
// lastLog = "[sendCount:0, deleteCount:0]-Time " + "2019-09-01 00:00:00";
|
// FileOption.writeFile(lastLog, tempSavePath, tempLogFile);
|
// }
|
// logger.debug("【" + subStationName + "】 读取上次谱图采集日志: " + lastLog);
|
// logger.debug("【" + subStationName + "】 读取远程文件数量: " + fileList.size());
|
// labelTips("【" + subStationName + "】 读取远程文件数量: " + fileList.size(), "");
|
// int sendCount = 0;
|
// List<String> deleteList = new ArrayList();
|
// for(int i = 0; i < fileList.size(); i++){
|
// //if(i > 2) continue;
|
// //限制单次采集不超过5000个文件
|
// if(sendCount >= 5000){
|
// continue;
|
// }
|
// sendCount ++;
|
// FileInformation remoteFile = (FileInformation)fileList.get(i);
|
//// long fileMillisTime = remoteFile.getLastModified().getTimeInMillis();
|
//// //文件时间小于上次采集的时间则忽略
|
//// if(fileMillisTime < startDate){
|
//// continue;
|
//// }
|
// final String fileName = remoteFile.getFilename();
|
// //清理已存在的临时文件
|
// FileOption.deleteFile(tempSavePath, fileName);
|
// logger.debug("\n开始采集文件:" + System.currentTimeMillis() + " => file-" + (i + 1) + ": " + fileName
|
// + " Size: " + remoteFile.getFileSize());
|
// try {
|
// association.getFile(fileName, new GetFileListener() {
|
// @Override
|
// public boolean dataReceived(byte[] fileData, boolean moreFollows) {
|
// //logger.debug("开始写入临时文件前时间:" + System.currentTimeMillis());
|
// boolean isSaved = FileOption.writeBinaryFile(tempSavePath, fileName, fileData, true);
|
// //logger.debug("完成写入临时文件后时间:" + System.currentTimeMillis());
|
// //logger.debug(tempSavePath + fileName + " save: " + isSaved);
|
// //logger.debug("moreFollows:" + moreFollows);
|
// while (moreFollows){
|
// return true;
|
// }
|
// //文件传输完成,打包文件
|
// //logger.debug("单个文件传输完成时间:" + System.currentTimeMillis());
|
// String strData = getFileCompressBase64(tempSavePath, fileName);
|
// //logger.debug("生成数据时间:" + System.currentTimeMillis());
|
// //logger.debug("temp file temp saved: " + fileName);
|
// //打包完成,删除文件
|
// boolean deleteFlag = FileOption.deleteFile(tempSavePath, fileName);
|
// //boolean deleteFlag = false;
|
// if(!deleteFlag){
|
// logger.debug("temp file delete: " + "failure");
|
// }
|
// boolean complete = sendFileDate(ip, fileName, strData);
|
// if(complete){
|
// deleteList.add(fileName);
|
// }
|
// return false;
|
// }
|
// });
|
// } catch (ServiceError serviceError) {
|
// serviceError.printStackTrace();
|
// } catch (IOException e) {
|
// e.printStackTrace();
|
// }
|
// }
|
// //记录执行日志
|
// String newLogStr = "\n" + "[sendCount:" + sendCount + ", deleteCount:" + deleteList.size() + "]-Time "
|
// + SimpleUtils.MillisToDateTime(System.currentTimeMillis());
|
// //更新采集时间
|
// String strDate = SimpleUtils.CurrentDateTime();
|
// tableModel.setValueAt(strDate, rowIndex, 3);
|
// //记录采集日志
|
// FileOption.writeFile(newLogStr, tempSavePath, tempLogFile, true);
|
// logger.debug("【" + subStationName + "】 谱图采集完成!");
|
// labelTips("【" + subStationName + "】 本次谱图采集完成!", "");
|
// if(!isDeleteRemoteFile){
|
// association.disconnect();
|
// association.close();
|
// return;
|
// }
|
// //删除远程文件
|
// for(int i = 0; i < deleteList.size(); i++){
|
// try {
|
// association.deleteFile(deleteList.get(i));
|
// logger.debug("remote file delete: " + deleteList.get(i));
|
// } catch (ServiceError serviceError) {
|
// serviceError.printStackTrace();
|
// logger.debug("remote file delete: " + "failure");
|
// } catch (IOException e) {
|
// e.printStackTrace();
|
// logger.debug("remote file delete: " + "failure");
|
// }
|
// }
|
// logger.debug("【" + subStationName + "】 远程谱图文件删除完成!");
|
// association.disconnect();
|
// association.close();
|
// //logger.debug(association.isOpen() + "");
|
// //logger.debug("恭喜你!本次采集完成了!!!");
|
// }
|
//
|
// private boolean readData(ClientAssociation association, String ipAddress, String subStationName){
|
// ServerModel serverModel;
|
// try {
|
// logger.debug("【" + subStationName + "】 开始读取数据模型...");
|
// labelTips("【" + subStationName + "】 开始读取数据模型...", "");
|
// serverModel = association.retrieveModel();
|
// logger.debug("【" + subStationName + "】 数据模型读取成功^_^");
|
// logger.debug("【" + subStationName + "】 开始采集数据...");
|
// labelTips("【" + subStationName + "】 开始采集数据^_^...", "");
|
// association.getAllDataValues();
|
//
|
// for(ModelNode modelNodeLD : serverModel.getChildren()) {
|
// LogicalDevice logicalDevice = (LogicalDevice)modelNodeLD;
|
// if (logicalDevice.getReference().toString().contains("_LD0")) {//过滤综合数据处理单元LD0
|
// continue;
|
// }
|
// for (ModelNode modelNodeLN : logicalDevice.getChildren()) {
|
// LogicalNode logicalNode = (LogicalNode)modelNodeLN;
|
// int start = logicalNode.getReference().toString().indexOf('/');
|
// String lnReference = logicalNode.getReference().toString().substring(start);
|
// if(lnReference.contains("LLN0")// 综合数据处理单元LD下面LLN0
|
// | lnReference.contains("GGIO")// 综合数据处理单元LD下面GGIO
|
// | lnReference.contains("LPHD")// 综合数据处理单元LD下面LPHD
|
// | lnReference.contains("RDRE")) {// 综合数据处理单元LD下面RDRE
|
// continue;
|
// }
|
//
|
// logger.debug(logicalNode.getName());
|
// List<String> doKeyList = new ArrayList<>();
|
// for (ModelNode modelNodeDO : logicalNode.getChildren()) {
|
// if (!doKeyList.contains(modelNodeDO.getName())) {
|
// doKeyList.add(modelNodeDO.getName());
|
// } else {
|
// continue;
|
// }
|
// }
|
//
|
// if(!doKeyList.contains("NamPlt")){
|
// String errorMsg = "【" + subStationName + "】 " + logicalNode.getReference().toString() + "配置文件铭牌定义错误";
|
// logger.error(logicalNode.getReference().toString() + " not contain NamPlt!!!!");
|
// labelTips(errorMsg, "error");
|
// sendErrorLog(subStationName, ipAddress, errorMsg);
|
// continue;
|
// }
|
// doKeyList.remove("NamPlt");
|
//
|
// //Map<String, Object> mapId = new HashMap<>();
|
// ModelNode modelNodeId = logicalNode.getChild("NamPlt", Fc.DC);
|
// Map<String, Object> mapId = getChildrenData(modelNodeId);
|
// String strNamPltValue = ((Map<String, Object>)mapId.get("dU")).get("value").toString();
|
// //byte[] byteNamPltValue = strNamPltValue.getBytes();
|
// //String packageType = "Linux";
|
// //packageType = "Windows";
|
// //if(packageType.equals("Windows")){
|
// //strNamPltValue = new String(byteNamPltValue, "UTF-8");
|
// //}
|
// String[] strNamPltValues = strNamPltValue.split("\\|");
|
// //logger.debug("" + NamPltValues.length);
|
//
|
// if(strNamPltValues.length < 5){
|
// String errorMsg = "【" + subStationName + "】 NamPlt:dU=>" + strNamPltValue + " ;描述错误!";
|
// logger.error(errorMsg);
|
// labelTips("【" + subStationName + "】 配置文件铭牌dU值定义错误", "error");
|
// sendErrorLog(subStationName, ipAddress, errorMsg);
|
// //continue;
|
// }
|
// //logger.debug(strNamPltValues[4].length() + "");
|
// if(strNamPltValues.length >= 5 && strNamPltValues[4].length() < 2){
|
// String errorMsg = "【" + subStationName + "】 NamPlt:dU=>" + strNamPltValue + " ;相位描述不完整!";
|
// logger.error(errorMsg);
|
// labelTips("【" + subStationName + "】 配置文件铭牌dU值相位描述不完整", "error");
|
// sendErrorLog(subStationName, ipAddress, errorMsg);
|
// //continue;
|
// }
|
// //logger.debug(JSON.toJSONString(mapId));
|
// logger.debug("【" + subStationName + "】 ------ [" + strNamPltValue + "] " + logicalNode.getReference().toString() + " 开始打包发送数据: " + doKeyList.size() +" 条 ------");
|
// for (String doKey : doKeyList){
|
// Map<String, Object> mapDo = new HashMap<>();
|
// for (Fc fc: SimpleUtils.FcList()){
|
// ModelNode modelNodeDo = logicalNode.getChild(doKey, fc);
|
// if(modelNodeDo == null){
|
// continue;
|
// }
|
// Map<String, Object> mapDataChildren = getChildrenData(modelNodeDo);
|
// if(mapDataChildren.get("t") != null){
|
// Map<String, Object> mapDataTime = (HashMap)mapDataChildren.get("t");
|
// long dataTime = SimpleUtils.DateTimeToMillisTime(mapDataTime.get("value").toString(), "yyyyMMddHHmmss");
|
// if(System.currentTimeMillis() - dataTime > 2 * 24 * 60 * 60 * 1000){
|
// //logger.debug(mapDataTime.get("value").toString());
|
// sendErrorLog(subStationName, ipAddress, logicalNode.getChild(doKey).getReference().toString() + ":" + mapDataTime.get("value").toString());
|
// }
|
// }
|
// mapDo.put(fc.toString(), getChildrenData(modelNodeDo));
|
// }
|
// mapDo.put("ID", mapId);
|
// Map<String, Object> mapData = new HashMap<>();
|
// mapData.put("type", "GC");
|
// if (ConfigUtil.isDebug) {
|
// logger.debug(doKey);
|
// logger.debug(logicalNode.getChild(doKey).getReference().toString());
|
// }
|
// mapData.put(ipAddress + "$" + logicalNode.getChild(doKey).getReference().toString(), mapDo);
|
// String data = JSON.toJSONString(mapData);
|
// //logger.debug(data);
|
// sendDataToMQ(data);
|
// //sendDataToIII(data);
|
// System.out.println(data);
|
// }
|
// }
|
// }
|
// } catch (ServiceError e) {
|
// System.out.println("Service Error requesting model." + e.getMessage());
|
// String errorMsg = "Service Error requesting model." + e.getMessage().toString();
|
// sendErrorLog(subStationName, ipAddress, errorMsg);
|
// association.close();
|
// return false;
|
// } catch (IOException e) {
|
// System.out.println("Fatal IOException requesting model." + e.getMessage());
|
// String errorMsg = "Fatal IOException requesting model." + e.getMessage().toString();
|
// sendErrorLog(subStationName, ipAddress, errorMsg);
|
// return false;
|
// }
|
//
|
// //ServerModelParser parser = new ServerModelParser(serverModel);
|
// return true;
|
// }
|
//
|
// private Map<String, Object> getChildrenData(ModelNode modelNode){
|
// //logger.debug(modelNode.getName());
|
// Map<String, Object> mapData = new HashMap<>();
|
// if(modelNode.getChildren() == null){
|
// try{
|
// mapData = getBasicData(modelNode);
|
// }catch (Exception e){
|
// logger.error("数据解析出错!");
|
// e.printStackTrace();
|
// }
|
// return mapData;
|
// }
|
// for (ModelNode modelNodeChild : modelNode.getChildren()) {
|
// mapData.put(modelNodeChild.getName(), getChildrenData(modelNodeChild));
|
// }
|
// return mapData;
|
// }
|
//
|
// private Map<String, Object> getBasicData(ModelNode modelNode){
|
// Map<String, Object> map = new HashMap<>();
|
// BasicDataAttribute dataAttribute = (BasicDataAttribute)modelNode;
|
// String dataReference = dataAttribute.getReference().toString();
|
// map.put("basicType", dataAttribute.getBasicType().toString());
|
// map.put("dchg", dataAttribute.getDchg());
|
// map.put("qchg", dataAttribute.getQchg());
|
// map.put("dupd", dataAttribute.getDupd());
|
// //logger.debug((dataAttribute).toString());
|
//// if((dataReference.length() + 2) == dataAttribute.toString().length()){
|
//// map.put("value", null);
|
//// return map;
|
//// }
|
// switch (dataAttribute.getBasicType()) {
|
// case BOOLEAN:
|
// map.put("value", ((BdaBoolean)dataAttribute).getValue());
|
// break;
|
// case ENTRY_TIME:
|
// map.put("value", SimpleUtils.DataTimeParse(((BdaEntryTime)dataAttribute).getValueString()));
|
// break;
|
// case FLOAT32:
|
// map.put("value", ((BdaFloat32)dataAttribute).getFloat().toString());
|
// break;
|
// case FLOAT64:
|
// map.put("value", ((BdaFloat64)dataAttribute).getDouble().toString());
|
// break;
|
// case INT16:
|
// map.put("value", ((BdaInt16)dataAttribute).getValue());
|
// break;
|
// case INT16U:
|
// map.put("value", ((BdaInt16U)dataAttribute).getValue());
|
// break;
|
// case INT32:
|
// map.put("value", ((BdaInt32)dataAttribute).getValue());
|
// break;
|
// case INT32U:
|
// map.put("value", ((BdaInt32U)dataAttribute).getValue());
|
// break;
|
// case INT64:
|
// map.put("value", ((BdaInt64)dataAttribute).getValue());
|
// break;
|
// case INT8:
|
// map.put("value", ((BdaInt8)dataAttribute).getValue());
|
// break;
|
// case INT8U:
|
// map.put("value", ((BdaInt8U)dataAttribute).getValue());
|
// break;
|
// case OCTET_STRING:
|
// map.put("maxLength", ((BdaOctetString)dataAttribute).getMaxLength());
|
// map.put("value", new String(((BdaOctetString)dataAttribute).getValue()));
|
// break;
|
// case TIMESTAMP:
|
// map.put("value", SimpleUtils.DataTimeParse(((BdaTimestamp)dataAttribute).getValueString()));
|
// break;
|
// case UNICODE_STRING:
|
// //logger.debug(((BdaUnicodeString)dataAttribute).toString());
|
// //logger.debug(new String(((BdaUnicodeString)dataAttribute).getValue()));
|
// map.put("maxLength", ((BdaUnicodeString)dataAttribute).getMaxLength());
|
// map.put("value", new String(((BdaUnicodeString)dataAttribute).getValue()));
|
// break;
|
// case VISIBLE_STRING:
|
// map.put("maxLength", ((BdaVisibleString)dataAttribute).getMaxLength());
|
// map.put("value", new String(((BdaVisibleString)dataAttribute).getValue()));
|
// break;
|
// case CHECK:
|
// map.put("maxNumBits", ((BdaCheck)dataAttribute).getMaxNumBits());
|
// map.put("value", ((BdaCheck)dataAttribute).getValueString());
|
// break;
|
// case DOUBLE_BIT_POS:
|
// map.put("maxNumBits", ((BdaOptFlds)dataAttribute).getMaxNumBits());
|
// map.put("value", ((BdaDoubleBitPos)dataAttribute).getDoubleBitPos().toString());
|
// break;
|
// case OPTFLDS:
|
// map.put("maxNumBits", ((BdaOptFlds)dataAttribute).getMaxNumBits());
|
// map.put("value", ((BdaOptFlds)dataAttribute).getValueString());
|
// break;
|
// case QUALITY:
|
// //logger.debug(((BdaQuality)dataAttribute).toString());
|
// //logger.debug(((BdaQuality)dataAttribute).getValue().toString());
|
// //logger.debug(((BdaQuality)dataAttribute).getValidity().toString());
|
// //logger.debug(((BdaQuality)dataAttribute).getValidity().getIntValue() + "");
|
// map.put("maxNumBits", ((BdaQuality)dataAttribute).getMaxNumBits());
|
// if((dataReference.length() + 2) == dataAttribute.toString().length()) {
|
// map.put("value", BdaQuality.Validity.GOOD);
|
// break;
|
// }
|
// map.put("value", ((BdaQuality)dataAttribute).getValidity().toString());
|
// break;
|
// case REASON_FOR_INCLUSION:
|
// map.put("maxNumBits", ((BdaReasonForInclusion)dataAttribute).getMaxNumBits());
|
// map.put("value", ((BdaReasonForInclusion)dataAttribute).getValueString());
|
// break;
|
// case TAP_COMMAND:
|
// map.put("maxNumBits", ((BdaTapCommand)dataAttribute).getMaxNumBits());
|
// map.put("value", ((BdaTapCommand)dataAttribute).getTapCommand().toString());
|
// break;
|
// case TRIGGER_CONDITIONS:
|
// map.put("maxNumBits", ((BdaTriggerConditions)dataAttribute).getMaxNumBits());
|
// map.put("value", ((BdaTriggerConditions)dataAttribute).getValueString());
|
// break;
|
// default:
|
// logger.debug("BasicType " + dataAttribute.getBasicType() + " unknown");
|
// //map.put("value", ((BdaEntryTime)dataAttribute).getValue());
|
// //throw new IllegalArgumentException("BasicType " + dataAttribute.getBasicType() + " unknown");
|
// }
|
// return map;
|
// }
|
//
|
// private boolean sendDataToMQ(String data){
|
// if (ConfigUtil.isDebug) {
|
// logger.debug("发送数据:" + data);
|
// }
|
// if(producer == null){
|
// if(!ConfigUtil.isDebug) {
|
// //logger.error("消息队列初始化未完成");
|
// }
|
// return false;
|
// }
|
// try {
|
// producer.sendMessage(data);
|
// } catch (IOException e) {
|
// e.printStackTrace();
|
// return false;
|
// }
|
// return true;
|
// }
|
//
|
// private boolean sendDataToIII(String data){
|
// // 检查/唤醒连接
|
// client.conn();
|
// try {
|
// System.out.println("try socket client send");
|
// client.sendData(data);
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// return false;
|
// }
|
// return true;
|
// }
|
//
|
// private boolean sendErrorLog(String substationName, String ipAddress, String data){
|
// Map<String, Object> errorMsgMap = new HashMap<>();
|
// if(ipAddress == null || ipAddress.length() < 7){
|
// return false;
|
// }
|
// errorMsgMap.put("type", "ERR_MSG");
|
// errorMsgMap.put("name", substationName);
|
// errorMsgMap.put("ip", ipAddress);
|
// errorMsgMap.put("data", data);
|
// errorMsgMap.put("datetime", SimpleUtils.CurrentDateTime());
|
// sendDataToMQ(JSON.toJSONString(errorMsgMap));
|
// return true;
|
// }
|
//
|
// private boolean sendFileDate(String ip, String fileName, String fileData) {
|
// //logger.debug(fileName);
|
// Map<String, Object> mapData = new HashMap<>();
|
// mapData.put("type", "WF");//type目前有GC、ZT、ZH,增加一个WF标记为谱图
|
// Map<String, Object> mapSubData = new HashMap<>();
|
// Map<String, Object> mapSubSubData = new HashMap<>();
|
// mapSubSubData.put("fileName", FileOption.trimPath(fileName));
|
// mapSubData.put("ID", mapSubSubData);
|
// mapSubData.put("FD", fileData);
|
// //mapData.put(ip + "$" + "BSCYB01HNZF2_ZT2202/PTRSIML1" + "." + "WaveFileNum", mapSubData);
|
// mapData.put(ip + "$" + "WaveFileNum", mapSubData);
|
// String data = JSON.toJSONString(mapData);
|
// //logger.debug(jsonObject.toString());
|
// return sendDataToMQ(data);
|
// }
|
//
|
// /**
|
// * 读取文件进行压缩并编码
|
// * @param filePath
|
// * @param fileName
|
// * @return
|
// */
|
// private String getFileCompressBase64(String filePath, String fileName) {
|
// byte[] fileBytes = FileOption.readFileByByte(filePath, fileName);
|
// //logger.debug("二进制长度 = " + fileBytes.length);
|
// //压缩
|
// //logger.debug("压缩前时间:" + System.currentTimeMillis());
|
// byte[] compressBytes = GZIPUtils.compress(fileBytes);
|
// //logger.debug("压缩后时间:" + System.currentTimeMillis());
|
// //logger.debug("二进制压缩后长度 = " + compressBytes.length);
|
// //编码
|
// final BASE64Encoder encoder = new BASE64Encoder();
|
// //logger.debug("编码前时间:" + System.currentTimeMillis());
|
// final String encodedStr = encoder.encode(compressBytes);
|
// //logger.debug("编码后时间:" + System.currentTimeMillis());
|
// //logger.debug("编码后字符串长度 = " + encodedStr.length());
|
// return encodedStr;
|
// }
|
//
|
// protected void collectStart() {
|
// threads = new Thread[tableModel.getRowCount()];
|
// timers = new Timer[tableModel.getRowCount()];
|
// logger.debug("初始化 " + tableModel.getRowCount() + " 个站点!");
|
// for(int i = 0; i < tableModel.getRowCount(); i++){
|
//// if(i != 0){
|
//// continue;
|
//// }
|
// final String name = tableModel.getValueAt(i,0).toString();
|
// final String ip = tableModel.getValueAt(i,1).toString();
|
// final int port = Integer.valueOf(tableModel.getValueAt(i,2).toString());
|
// final int threadIndex = i;
|
// threads[i] = new Thread(new Runnable() {
|
// @Override
|
// public void run() {
|
// timers[threadIndex] = new Timer();
|
//
|
// TimerTask timerTask = new TimerTask() {
|
// @Override
|
// public void run() {
|
// logger.debug("定时任务【" + (threadIndex + 1) + " - " + name + "】 开始连接至变电站 => " + ip + ":" + port
|
// + " [" + SimpleUtils.CurrentDateTime() + "]");
|
// collectToSubstation(ip, port, threadIndex);
|
// }
|
// };
|
// timers[threadIndex].schedule(timerTask, threadIndex * SubstaionIntervalTimes, CollectIntervalTimes);
|
// }
|
// });
|
// threads[i].start();
|
// }
|
// }
|
//
|
// protected void collectStop(){
|
// for(int i = 0; i < timers.length; i++){
|
// //logger.debug(threads[i].isAlive() + "");
|
// timers[i].cancel();
|
// }
|
// logger.debug("停止 " + timers.length + " 个采集任务!");
|
// labelTips("停止 " + timers.length + " 个采集任务!", "");
|
// }
|
//
|
// protected void dataLoad(){
|
// tableModel.setDataVector(ConfigUtil.readSubstation(txtSubstationList.getText()), columnTitles);
|
// //logger.debug("-- 站点列表加载完成 --");
|
// labelTips("站点列表加载完成^_^!", "");
|
// }
|
//
|
// private void labelTips(String msg, String msgType){
|
// msg = msg + "[" + SimpleUtils.CurrentDateTime() + "]";
|
// switch (msgType){
|
// case "error":
|
// labelTips.setText(msg);
|
// labelTips.setForeground(Color.RED);
|
// break;
|
// case "warning":
|
// labelTips.setText(msg);
|
// labelTips.setForeground(Color.PINK);
|
// break;
|
// default:
|
// labelTips.setText(msg);
|
// labelTips.setForeground(Color.BLACK);
|
// }
|
// }
|
//
|
// public void checkNet(String substationName, String ipAddress, int port){
|
// Map<String, Object> networkMsg = new HashMap<>();
|
// boolean pingResult = NetworkUtils.pingByLinuxCmd(ipAddress, 5 * 1000);
|
// boolean telnetResult = NetworkUtils.telnet(ipAddress, port, 5 * 1000);
|
// networkMsg.put("type", "NET");
|
// networkMsg.put("name", substationName);
|
// networkMsg.put("ip", ipAddress);
|
// networkMsg.put("port", 102);
|
// networkMsg.put("ping", pingResult);
|
// networkMsg.put("telnet", telnetResult);
|
// networkMsg.put("datetime", SimpleUtils.CurrentDateTime());
|
// sendDataToMQ(JSON.toJSONString(networkMsg));
|
// }
|
//
|
// public void startNetworkReview(){
|
// networkReviewTimer = new Timer();
|
// networkReviewTimer.schedule(new TimerTask() {
|
// @Override
|
// public void run() {
|
// logger.debug("开始检测网络...");
|
// String ipListFileStr = FileOption.readFileByString("myconfig/ip_list.txt", "UTF-8");
|
// String newIpListFileStr = "";
|
// String[] ipList = ipListFileStr.split("\n");
|
// for (String ip: ipList) {
|
// logger.debug(ip);
|
// Map<String, Object> networkMsg = new HashMap<>();
|
// if(ip == null || ip.length() < 7){
|
// continue;
|
// }
|
// String[] ipInfo = ip.split("-");
|
// if(ipInfo[1] == null){
|
// continue;
|
// }
|
// boolean pingResult = NetworkUtils.pingByLinuxCmd(ipInfo[1], 5 * 1000);
|
// boolean telnetResult = NetworkUtils.telnet(ipInfo[1], 102, 5 * 1000);
|
// //newIpListFileStr += ipInfo[0] + "-" + ipInfo[1] + "-" + pingResult + "-" + telnetResult + "-" + SimpleUtils.CurrentDateTime() + "\n";
|
// newIpListFileStr += ipInfo[1] + "-" + pingResult + "-" + telnetResult + "-" + SimpleUtils.CurrentDateTime() + "\n";
|
// networkMsg.put("type", "NET");
|
// networkMsg.put("name", ipInfo[0]);
|
// networkMsg.put("ip", ipInfo[1]);
|
// networkMsg.put("port", 102);
|
// networkMsg.put("ping", pingResult);
|
// networkMsg.put("telnet", telnetResult);
|
// networkMsg.put("datetime", SimpleUtils.CurrentDateTime());
|
// sendDataToMQ(JSON.toJSONString(networkMsg));
|
// logger.debug(JSON.toJSONString(networkMsg));
|
// FileOption.writeFile(newIpListFileStr, "myconfig", "ip_list_result.txt");
|
// }
|
// //FileOption.writeFile(newIpListFileStr, "myconfig", "ip_list_result.txt");
|
// logger.debug("检测完成!");
|
// }
|
// }, 1000, 10 * 60 * 1000);
|
// }
|
//
|
// public static void main(String[] args) {
|
//
|
// logger.debug("System starting...");
|
// MyClient clientGui = new MyClient();
|
// clientGui.ClientMain();
|
// }
|
//}
|