New file |
| | |
| | | package com.data.history;
|
| | |
|
| | | import java.sql.ResultSet;
|
| | | import java.sql.SQLException;
|
| | | import java.util.Date;
|
| | |
|
| | | import com.base.Com;
|
| | | import com.data.Central_RT_Data;
|
| | | import com.data.Central_ST_Data;
|
| | | import com.sql.MysqlConnPool;
|
| | | import com.sql.Sql_Mysql;
|
| | |
|
| | | public class Central_Data_RealRecord_Thread_SQL {
|
| | |
|
| | | /**
|
| | | * 创建历史实时表 db_3.5mw_motor.tb_central_monitor_sys_rt_
|
| | | * @param pool
|
| | | * @param dev_id
|
| | | * @param time
|
| | | */
|
| | | public static void createTb_Central_Monitor_Sys_Rt_RealData(MysqlConnPool pool,int dev_id,Date time) {
|
| | | String sql_str = "CREATE TABLE IF NOT EXISTS "+Sql_Mysql.Tb_Central_Monitor_Sys_Rt_RealData+dev_id+"_"+Com.getDateTimeFormat(time, Com.DTF_Y_M_D)+" (" + |
| | | " num bigint(20) NOT NULL AUTO_INCREMENT," + |
| | | " dev_id int(11) NOT NULL DEFAULT '0' COMMENT '设备id'," + |
| | | " record_time datetime NOT NULL DEFAULT '2000-01-01 00:00:00' COMMENT '更新时间'," + |
| | | " switch_close int(11) NOT NULL DEFAULT '0' COMMENT '开关合闸状态'," + |
| | | " switch_open int(11) NOT NULL DEFAULT '0' COMMENT '开关分闸状态'," + |
| | | " switch_fault int(11) NOT NULL DEFAULT '0' COMMENT '开关故障状态'," + |
| | | " panel_vol float(11,0) NOT NULL DEFAULT '0' COMMENT '进线屏电压'," + |
| | | " 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_record_time (record_time) USING BTREE" + |
| | | ") 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();
|
| | | }
|
| | | }
|
| | | |
| | | /**
|
| | | * 创建历史实时表 db_3.5mw_motor.tb_central_monitor_sys_rt_
|
| | | * @param pool
|
| | | * @param dev_id
|
| | | * @param time
|
| | | */
|
| | | public static void createTb_Central_Monitor_Sys_St_RealData(MysqlConnPool pool,int dev_id,Date time) {
|
| | | String sql_str = "CREATE TABLE IF NOT EXISTS "+Sql_Mysql.Tb_Central_Monitor_Sys_St_RealData+dev_id+"_"+Com.getDateTimeFormat(time, Com.DTF_Y_M_D)+" (" + |
| | | " num bigint(20) NOT NULL AUTO_INCREMENT," + |
| | | " dev_id int(11) NOT NULL DEFAULT '0' COMMENT '设备id'," + |
| | | " record_time datetime NOT NULL DEFAULT '2000-01-01 00:00:00' COMMENT '更新时间'," + |
| | | " switch_close_1st_2500A int(11) NOT NULL DEFAULT '0' COMMENT '1号2500A进线屏开关合闸状态'," + |
| | | " switch_open_1st_2500A int(11) NOT NULL DEFAULT '0' COMMENT '1号2500A进线屏开关分闸状态'," + |
| | | " switch_fault_1st_2500A int(11) NOT NULL DEFAULT '0' COMMENT '1号2500A进线屏开关故障状态'," + |
| | | " switch_close_2st_2500A int(11) NOT NULL DEFAULT '0' COMMENT '2号2500A进线屏开关合闸状态'," + |
| | | " switch_open_2st_2500A int(11) NOT NULL DEFAULT '0' COMMENT '2号2500A进线屏开关分闸状态'," + |
| | | " switch_fault_2st_2500A int(11) NOT NULL DEFAULT '0' COMMENT '2号2500A进线屏开关故障状态'," + |
| | | " switch_close_bus_screen int(11) NOT NULL DEFAULT '0' COMMENT '母联屏合闸状态'," + |
| | | " switch_open_bus_screen int(11) NOT NULL DEFAULT '0' COMMENT '母联屏分闸状态'," + |
| | | " switch_fault_bus_screen int(11) NOT NULL DEFAULT '0' COMMENT '母联屏开关故障'," + |
| | | " switch_close_1st_2500A_load int(11) NOT NULL DEFAULT '0' COMMENT '1号2500A负载屏开关合闸状态'," + |
| | | " switch_open_1st_2500A_load int(11) NOT NULL DEFAULT '0' COMMENT '1号2500A负载屏开关分闸状态'," + |
| | | " switch_fault_1st_2500A_load int(11) NOT NULL DEFAULT '0' COMMENT '1号2500A负载屏开关故障状态'," + |
| | | " 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负载屏开关分闸状态'," + |
| | | " switch_fault_2st_2500A_load int(11) NOT NULL DEFAULT '0' COMMENT '2号2500A负载屏开关故障状态'," + |
| | | " curr_a float NOT NULL DEFAULT '0' COMMENT 'A排电流'," + |
| | | " vol_a float NOT NULL DEFAULT '0' COMMENT 'A排电压'," + |
| | | " curr_b float NOT NULL DEFAULT '0' COMMENT 'B排电流'," + |
| | | " 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_record_time (record_time) USING BTREE" + |
| | | ") 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();
|
| | | }
|
| | | }
|
| | | |
| | | /**
|
| | | * 插入直流主配电板历史实时信息
|
| | | * @param pool
|
| | | * @param rtdata
|
| | | * @param time
|
| | | */
|
| | | public static void insertTb_Central_Monitor_Sys_St_RealData(MysqlConnPool pool,Central_ST_Data stdata,Date time) {
|
| | | String sql_str = " insert into " + Sql_Mysql.Tb_Central_Monitor_Sys_St_RealData+stdata.getDev_id()+"_"+Com.getDateTimeFormat(time, Com.DTF_Y_M_D)+"(dev_id,record_time,switch_close_1st_2500A,switch_open_1st_2500A,switch_fault_1st_2500A,switch_close_2st_2500A,switch_open_2st_2500A,switch_fault_2st_2500A,switch_close_bus_screen,switch_open_bus_screen,switch_fault_bus_screen,switch_close_1st_2500A_load,switch_open_1st_2500A_load,switch_fault_1st_2500A_load,switch_close_2st_2500A_load,switch_open_2st_2500A_load,switch_fault_2st_2500A_load,curr_a,vol_a,curr_b,vol_b) "
|
| | | + " values("
|
| | | + ""+stdata.getDev_id()
|
| | | + ",'"+Com.getDateTimeFormat(time, Com.DTF_YMDhms)
|
| | | + "',"+stdata.getSwitch_close_1st_2500A()
|
| | | + ","+stdata.getSwitch_open_1st_2500A()
|
| | | + ","+stdata.getSwitch_fault_1st_2500A()
|
| | | + ","+stdata.getSwitch_close_2st_2500A()
|
| | | + ","+stdata.getSwitch_open_2st_2500A()
|
| | | + ","+stdata.getSwitch_fault_2st_2500A()
|
| | | + ","+stdata.getSwitch_close_bus_screen()
|
| | | + ","+stdata.getSwitch_open_bus_screen()
|
| | | + ","+stdata.getSwitch_fault_bus_screen()
|
| | | + ","+stdata.getSwitch_close_1st_2500A_load()
|
| | | + ","+stdata.getSwitch_open_1st_2500A_load()
|
| | | + ","+stdata.getSwitch_fault_1st_2500A_load()
|
| | | + ","+stdata.getSwitch_close_2st_2500A_load()
|
| | | + ","+stdata.getSwitch_open_2st_2500A_load()
|
| | | + ","+stdata.getSwitch_fault_2st_2500A_load()
|
| | | + ","+stdata.getCurr_a()
|
| | | + ","+stdata.getVol_a()
|
| | | + ","+stdata.getCurr_b()
|
| | | + ","+stdata.getVol_b()
|
| | | + ")";
|
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
| | | try {
|
| | | sql.sqlMysqlExecute(sql_str);
|
| | | } catch (SQLException e) {
|
| | | e.printStackTrace();
|
| | | } finally {
|
| | | sql.close_con();
|
| | | }
|
| | | }
|
| | | |
| | | /**
|
| | | * 插入进出线屏历史实时信息
|
| | | * @param pool
|
| | | * @param rtdata
|
| | | * @param time
|
| | | */
|
| | | public static void insertTb_Central_Monitor_Sys_Rt_RealData(MysqlConnPool pool,Central_RT_Data rtdata,Date time) {
|
| | | String sql_str = " insert into " + Sql_Mysql.Tb_Central_Monitor_Sys_Rt_RealData+rtdata.getDev_id()+"_"+Com.getDateTimeFormat(time, Com.DTF_Y_M_D)+"(dev_id,record_time,switch_close,switch_open,switch_fault,panel_vol,panel_curr) "
|
| | | + " values("+rtdata.getDev_id()+""
|
| | | + ",'"+Com.getDateTimeFormat(time, Com.DTF_YMDhms)+"'"
|
| | | + ","+rtdata.getSwitch_close()+""
|
| | | + ","+rtdata.getSwitch_open()+""
|
| | | + ","+rtdata.getSwitch_fault()+""
|
| | | + ","+rtdata.getPanel_vol()+""
|
| | | + ","+rtdata.getPanel_curr()+""
|
| | | + ")";
|
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
| | | try {
|
| | | sql.sqlMysqlExecute(sql_str);
|
| | | } catch (SQLException e) {
|
| | | e.printStackTrace();
|
| | | } finally {
|
| | | sql.close_con();
|
| | | }
|
| | | }
|
| | | |
| | | /**
|
| | | * 删除创建时间超时的历史实时记录表
|
| | | * @param conn_pool
|
| | | * @param deldate |
| | | */
|
| | | public static void deleteHistoryData(MysqlConnPool conn_pool,Date deldate) {
|
| | | String sql_select_strs = " select TABLE_NAME,UPDATE_TIME,CREATE_TIME " + |
| | | " from information_schema.tables " + |
| | | " where table_schema='db_watersystem' " + |
| | | " AND TABLE_NAME like 'tb_central_monitor_sys_%' " + |
| | | " AND CREATE_TIME <= '"+Com.getDateTimeFormat(deldate, Com.DTF_YMDhms)+"';" ;
|
| | | String sql_delete_strs = " DROP TABLE IF EXISTS ";
|
| | | Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
| | | ResultSet res = null;
|
| | | int count = 0;
|
| | | res = sql.sqlMysqlQuery(sql_select_strs);
|
| | | try {
|
| | | while(res.next()) {
|
| | | if(count > 0) {
|
| | | sql_delete_strs += ",";
|
| | | }
|
| | | sql_delete_strs += "db_watersystem." + res.getString("TABLE_NAME");
|
| | | System.out.println("删除: "+res.getString("TABLE_NAME")+"\t at "+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
|
| | | count++;
|
| | | }
|
| | | if(count >0) {
|
| | | sql.sqlMysqlExecute(sql_delete_strs);
|
| | | }
|
| | | } catch (SQLException e) {
|
| | | e.printStackTrace();
|
| | | } finally {
|
| | | if(res != null) {
|
| | | try {
|
| | | res.close();
|
| | | } catch (SQLException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | sql.close_con();
|
| | | }
|
| | | }
|
| | | }
|