Administrator
2021-04-08 d73558a28b0246e3ca0197c81c5fde1732456196
集中监控系统通讯程序添加设备通讯正常故障字段信息记录
5个文件已修改
1个文件已添加
107 ■■■■ 已修改文件
Central_Monitor/central_monitor_logs/info-20201229-1.log.gz 补丁 | 查看 | 原始文档 | blame | 历史
Central_Monitor/src/com/data/Comm/Central_DataParsing_Thread_SQL.java 50 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Central_Monitor/src/com/data/Comm/Central_Data_SocketClient_Thread.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Central_Monitor/src/com/data/Comm/Central_Data_Task_SQL.java 49 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Central_Monitor/src/com/modbus/data/MyModbusMaster.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Central_Monitor/src/com/sql/Sql_Mysql.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Central_Monitor/central_monitor_logs/info-20201229-1.log.gz
Binary files differ
Central_Monitor/src/com/data/Comm/Central_DataParsing_Thread_SQL.java
@@ -13,6 +13,56 @@
import com.sql.Sql_Mysql;
public class Central_DataParsing_Thread_SQL {
    /**
     *    插入或更新设备通讯状态
     * @param pool
     * @param motor
     */
    public static void insertOrUpdateTb_Device_StateTable(MysqlConnPool pool,Motor_inf motor) {
        String sql_str_sel = " Select dev_id from " + Sql_Mysql.Tb_Device_State + " Where dev_id = " + motor.getDev_id();
        String sql_str_upd = " UPDATE " + Sql_Mysql.Tb_Device_State + " SET comm_status = " + motor.conn_state + " WHERE dev_id = " + motor.getDev_id();
        String sql_str_ins = " INSERT INTO "+Sql_Mysql.Tb_Device_State+"(dev_id,comm_status) VALUES("+motor.getDev_id()+","+motor.conn_state+");";
        ResultSet res = null;
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            res = sql.sqlMysqlQuery(sql_str_sel);
            if(res.next()) {
                sql.sqlMysqlExecute(sql_str_upd);
            }else {
                sql.sqlMysqlExecute(sql_str_ins);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            if(null != res) {
                try {
                    res.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            sql.close_con();
        }
    }
    /**
     * 更新设备的通讯状态
     * @param pool
     * @param motor
     */
    public static void updateTb_Device_StateTable(MysqlConnPool pool,Motor_inf motor) {
        String sql_str = " UPDATE "+Sql_Mysql.Tb_Device_State+" SET comm_status = "+motor.conn_state+",record_time='"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms)+"' WHERE dev_id = "+motor.getDev_id();
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute(sql_str);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    /**
     *     加载集中监控平台设备设备信息
Central_Monitor/src/com/data/Comm/Central_Data_SocketClient_Thread.java
@@ -28,6 +28,7 @@
    @Override
    public void run() {
        int run_count = 0;
        Central_DataParsing_Thread_SQL.insertOrUpdateTb_Device_StateTable(pool, motor);
        while(true) {
            try { 
                if(run_count % 2 == 0) {
@@ -48,8 +49,11 @@
                    
                    Central_DataParsing_Thread_SQL.updateTb_Central_Monitor_Sys_Control(pool,motor.control);            
                }
                motor.conn_state = master.getConnectState();
                if(run_count%5 == 0) {
                    Central_DataParsing_Thread_SQL.updateTb_Device_StateTable(pool, motor);
                }
                if(run_count > 999909) {
                    run_count = 0;
                }
Central_Monitor/src/com/data/Comm/Central_Data_Task_SQL.java
@@ -20,6 +20,8 @@
        CreateTb_Central_Monitor_Sys_RtTable(pool);
        
        CreateTb_Central_Monitor_Sys_ControlTable(pool);
        CreateTb_Device_StateTable(pool);
    }
    
    /**
@@ -58,15 +60,15 @@
     */
    public static void CreateTb_MW_Motor_inf(MysqlConnPool pool) {
        String sql_str = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Tb_MW_Motor_inf + " (" + 
                "  `num` bigint(20) NOT NULL AUTO_INCREMENT," +
                "  `sys_id` int(11) NOT NULL DEFAULT '100001' COMMENT 'ϵͳid'," +
                "  `sys_name` varchar(32) NOT NULL DEFAULT '' COMMENT '系统名称'," +
                "  `dev_id` int(11) NOT NULL DEFAULT '10001' COMMENT '设备id'," +
                "  `dev_name` varchar(32) NOT NULL DEFAULT '' COMMENT '设备名称'," +
                "  `dev_ip` varchar(32) NOT NULL DEFAULT '' COMMENT '设备ip'," +
                "  `note` varchar(32) NOT NULL DEFAULT '' COMMENT '备用'," +
                "  PRIMARY KEY (`num`)," +
                "  UNIQUE KEY `index_dev_id` (`dev_id`) USING BTREE" +
                "  num bigint(20) NOT NULL AUTO_INCREMENT," +
                "  sys_id int(11) NOT NULL DEFAULT '100001' COMMENT 'ϵͳid'," +
                "  sys_name varchar(32) NOT NULL DEFAULT '' COMMENT '系统名称'," +
                "  dev_id int(11) NOT NULL DEFAULT '10001' COMMENT '设备id'," +
                "  dev_name varchar(32) NOT NULL DEFAULT '' COMMENT '设备名称'," +
                "  dev_ip varchar(32) NOT NULL DEFAULT '' COMMENT '设备ip'," +
                "  note varchar(32) NOT NULL DEFAULT '' COMMENT '备用'," +
                "  PRIMARY KEY (num)," +
                "  UNIQUE KEY index_dev_id (dev_id) USING BTREE" +
                ") ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8; ";
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        ResultSet res = null;
@@ -133,6 +135,29 @@
    
    
    /**
     *     创建Tb_Device_State表
     * @param pool
     */
    public static void CreateTb_Device_StateTable(MysqlConnPool pool) {
        String sql_str = "CREATE TABLE IF NOT EXISTS "+Sql_Mysql.Tb_Device_State+" (" +
                "  num bigint(20) NOT NULL AUTO_INCREMENT," +
                "  dev_id int(11) NOT NULL DEFAULT '10001' COMMENT '设备id'," +
                "  record_time datetime NOT NULL DEFAULT '2000-01-01 00:00:00' COMMENT '记录时间'," +
                "  comm_status int(11) NOT NULL DEFAULT '0' COMMENT '通讯状态(0:通讯故障;1:通讯正常)'," +
                "  note varchar(64) NOT NULL DEFAULT ''," +
                "  PRIMARY KEY (num)" +
                ") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute(sql_str);
        } catch (SQLException e) {
            sql.logger.error(e.toString(), e);
        } finally {
            sql.close_con();
        }
    }
    /**
     *     创建tb_central_monitor_sys_st表
     * @param pool
     */
@@ -162,7 +187,7 @@
                "  vol_b float NOT NULL DEFAULT '0' COMMENT 'B排电压'," + 
                "  note varchar(255) NOT NULL DEFAULT '' COMMENT '备用'," + 
                "  PRIMARY KEY (num)," + 
                "  KEY `index_dev_id` (`dev_id`) USING BTREE" +
                "  KEY index_dev_id (dev_id) USING BTREE" +
                ") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
@@ -190,7 +215,7 @@
                "  panel_curr float(11,0) NOT NULL DEFAULT '0' COMMENT '进线屏电流'," + 
                "  note varchar(255) NOT NULL DEFAULT '0' COMMENT '备用'," + 
                "  PRIMARY KEY (num)," + 
                "  KEY `index_dev_id` (`dev_id`) USING BTREE" +
                "  KEY index_dev_id (dev_id) USING BTREE" +
                ") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
@@ -222,7 +247,7 @@
                "  switch_close_2st_2500A_load int(11) NOT NULL DEFAULT '0' COMMENT '2号2500A负载屏开关合闸'," + 
                "  switch_open_2st_2500A_load int(11) NOT NULL DEFAULT '0' COMMENT '2号2500A负载屏开关分闸'," + 
                "  PRIMARY KEY (num)," + 
                "  KEY `index_dev_id` (`dev_id`) USING BTREE" +
                "  KEY index_dev_id (dev_id) USING BTREE" +
                ") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
Central_Monitor/src/com/modbus/data/MyModbusMaster.java
@@ -91,6 +91,7 @@
        
    }
    
    //获取当前通讯状态
    public int getConnectState() {
        if(this.totalerr < LOSE_CONNECT_COUNT) {
            return 1;
Central_Monitor/src/com/sql/Sql_Mysql.java
@@ -205,6 +205,7 @@
    public final static String Tb_Central_Monitor_Sys_St = DB_MW_Motor + ".tb_central_monitor_sys_st";                
    public final static String Tb_Central_Monitor_Sys_Rt = DB_MW_Motor + ".tb_central_monitor_sys_rt";
    public final static String Tb_Central_Monitor_Sys_Control = DB_MW_Motor + ".tb_central_monitor_sys_control";
    public final static String Tb_Device_State = DB_MW_Motor + ".tb_device_state";                                        //设备连接状态
    //--------------------------------------------------------------------------------------------//
    public final static String Tb_Central_Monitor_Sys_St_RealData = DB_MW_Motor_History + ".tb_central_monitor_sys_st_";                
    public final static String Tb_Central_Monitor_Sys_Rt_RealData = DB_MW_Motor_History + ".tb_central_monitor_sys_rt_";