New file |
| | |
| | | package com.dev.base.data;
|
| | |
|
| | | import java.sql.ResultSet;
|
| | | import java.sql.SQLException;
|
| | | import java.util.Date;
|
| | |
|
| | | import com.base.Com;
|
| | | import com.sql.MysqlConnPool;
|
| | | import com.sql.Sql_Mysql;
|
| | |
|
| | | public class Dynamicload_Task_SQL {
|
| | |
|
| | | /**
|
| | | * 创建指定时间的历史实时数据库表
|
| | | * @param pool
|
| | | * @param dev_id
|
| | | * @param now
|
| | | */
|
| | | public static void createTb_Dynamicload_realdata(MysqlConnPool pool, int dev_id, Date now) {
|
| | | String sql_str = "CREATE TABLE IF NOT EXISTS "+Sql_Mysql.Tb_Dynamicload_RealData+dev_id+"_"+Com.getDateTimeFormat(now, Com.DTF_Y_M_D)+" (" + |
| | | " num int(11) NOT NULL AUTO_INCREMENT COMMENT '主键'," + |
| | | " dev_id int(11) NOT NULL DEFAULT '1' COMMENT '设备id'," + |
| | | " record_time datetime NOT NULL DEFAULT '2000-01-01 00:00:00'," + |
| | | " FZ_b1 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ按钮1'," + |
| | | " FZ_b2 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ按钮2'," + |
| | | " FZ_b3 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ按钮3'," + |
| | | " FZ_b4 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ按钮4'," + |
| | | " FZ_b5 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ按钮5'," + |
| | | " FZ_b6 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ按钮6'," + |
| | | " FZ_b7 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ按钮7'," + |
| | | " FZ_b8 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ按钮8'," + |
| | | " FZ_b9 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ按钮9'," + |
| | | " FZ_b10 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ按钮10'," + |
| | | " FZ_b11 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ按钮11'," + |
| | | " FZ_fw1 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ反馈按钮1'," + |
| | | " FZ_fw2 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ反馈按钮2'," + |
| | | " FZ_fw3 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ反馈按钮3'," + |
| | | " FZ_fw4 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ反馈按钮4'," + |
| | | " FZ_fw5 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ反馈按钮5'," + |
| | | " FZ_fw6 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ反馈按钮6'," + |
| | | " FZ_fw7 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ反馈按钮7'," + |
| | | " FZ_fw8 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ反馈按钮8'," + |
| | | " FZ_fw9 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ反馈按钮9'," + |
| | | " FZ_fw10 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ反馈按钮10'," + |
| | | " FZ_fw11 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ反馈按钮11'," + |
| | | " FZ_ex1 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ输出按钮1'," + |
| | | " FZ_ex2 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ输出按钮2'," + |
| | | " FZ_ex3 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ输出按钮3'," + |
| | | " FZ_ex4 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ输出按钮4'," + |
| | | " FZ_ex5 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ输出按钮5'," + |
| | | " FZ_ex6 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ输出按钮6'," + |
| | | " FZ_ex7 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ输出按钮7'," + |
| | | " FZ_ex8 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ输出按钮8'," + |
| | | " FZ_ex9 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ输出按钮9'," + |
| | | " FZ_ex10 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ输出按钮10'," + |
| | | " FZ_ex11 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ输出按钮11'," + |
| | | " start_auto int(11) NOT NULL DEFAULT '1' COMMENT '启动自动加载'," + |
| | | " stop_auto int(11) NOT NULL DEFAULT '1' COMMENT '停止自动加载'," + |
| | | " sudden_crease int(11) NOT NULL DEFAULT '1' COMMENT '突加突卸'," + |
| | | " all_open int(11) NOT NULL DEFAULT '1' COMMENT '全部分闸'," + |
| | | " actual_set_power float NOT NULL DEFAULT '1' COMMENT '实际设定功率'," + |
| | | " output_power float NOT NULL DEFAULT '1' COMMENT '已输出功率'," + |
| | | " set_power float NOT NULL DEFAULT '1' COMMENT '设定功率'," + |
| | | " interval_time float NOT NULL DEFAULT '1' COMMENT '间隔时间s'," + |
| | | " actual_curr float NOT NULL DEFAULT '1' COMMENT '实际电流'," + |
| | | " actual_mov float NOT NULL DEFAULT '1' COMMENT '实际电压'," + |
| | | " switch_on int(11) NOT NULL DEFAULT '1' COMMENT '是否合闸'," + |
| | | " FZ_autostate1 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ自动状态1'," + |
| | | " FZ_autostate2 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ自动状态2'," + |
| | | " FZ_autostate3 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ自动状态3'," + |
| | | " FZ_autostate4 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ自动状态4'," + |
| | | " FZ_autostate5 int(11) NOT NULL DEFAULT '1' COMMENT 'FZ自动状态5'," + |
| | | " react_overtem int(11) NOT NULL DEFAULT '1' COMMENT '电抗超温'," + |
| | | " water_overtem int(11) NOT NULL DEFAULT '1' COMMENT '冷却水超温'," + |
| | | " water_level_low int(11) NOT NULL DEFAULT '1' COMMENT '冷却水液位低'," + |
| | | " water_pressure_high int(11) NOT NULL DEFAULT '1' COMMENT '冷却水压高'," + |
| | | " local_control int(11) NOT NULL DEFAULT '1' COMMENT '就地控制'," + |
| | | " back_control int(11) NOT NULL DEFAULT '1' COMMENT '后台控制'," + |
| | | " central_control int(11) NOT NULL DEFAULT '1' COMMENT '中控控制'," + |
| | | " switch_state int(11) NOT NULL DEFAULT '1' COMMENT '开关柜状态'," + |
| | | " inter_volume_M200 int(11) NOT NULL DEFAULT '1' COMMENT '中间量M200'," + |
| | | " fan_button int(11) NOT NULL DEFAULT '1' COMMENT '风机按钮'," + |
| | | " fan_output int(11) NOT NULL DEFAULT '1' COMMENT '风机输出'," + |
| | | " allow_close int(11) NOT NULL DEFAULT '0' COMMENT '是否允许合闸'," + |
| | | " note varchar(255) NOT NULL DEFAULT ''," + |
| | | " PRIMARY KEY (num)," + |
| | | " KEY dev_id_key (dev_id)," + |
| | | " 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) {
|
| | | 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_dynamicsystem' " + |
| | | " AND TABLE_NAME like 'tb_dynamicload_realdata_%' " + |
| | | " 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_dynamicsystem." + 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();
|
| | | }
|
| | | }
|
| | | |
| | | /**
|
| | | * |
| | | * @param pool
|
| | | * @param dinf
|
| | | * @param now
|
| | | */
|
| | | public static void insertTb_dynamicload_realdata(MysqlConnPool pool, Dynamicload_inf dinf, Date now) {
|
| | | Dynamicload_button btn = dinf.button;
|
| | | Dynamicload_state state = dinf.state;
|
| | | String sql_str = "INSERT INTO " + Sql_Mysql.Tb_Dynamicload_RealData+dinf.dev_id+"_"+Com.getDateTimeFormat(now, Com.DTF_Y_M_D) +
|
| | | "(dev_id,record_time,FZ_b1,FZ_b2,FZ_b3,FZ_b4,FZ_b5,FZ_b6,FZ_b7,FZ_b8,FZ_b9,FZ_b10,FZ_b11,FZ_fw1,FZ_fw2,FZ_fw3,FZ_fw4,FZ_fw5,FZ_fw6,FZ_fw7,FZ_fw8,FZ_fw9,FZ_fw10,FZ_fw11,FZ_ex1,FZ_ex2,FZ_ex3,FZ_ex4,FZ_ex5,FZ_ex6,FZ_ex7,FZ_ex8,FZ_ex9,FZ_ex10,FZ_ex11,start_auto,stop_auto,sudden_crease,all_open,actual_set_power,output_power,set_power,interval_time,actual_curr,actual_mov,switch_on,FZ_autostate1,FZ_autostate2,FZ_autostate3,FZ_autostate4,FZ_autostate5,react_overtem,water_overtem,water_level_low,water_pressure_high,local_control,back_control,central_control,switch_state,inter_volume_M200,fan_button,fan_output,allow_close) " + |
| | | "VALUES("+dinf.dev_id+",'"+Com.getDateTimeFormat(now, Com.DTF_YMDhms)+"',"+btn.FZ_b1+","+btn.FZ_b2+","+btn.FZ_b3+","+btn.FZ_b4+","+btn.FZ_b5+","+btn.FZ_b6+","+btn.FZ_b7+","+btn.FZ_b8+","+btn.FZ_b9+","+btn.FZ_b10+","+btn.FZ_b11+","+btn.FZ_fw1+","+btn.FZ_fw2+","+btn.FZ_fw3+","+btn.FZ_fw4+","+btn.FZ_fw5+","+btn.FZ_fw6+","+btn.FZ_fw7+","+btn.FZ_fw8+","+btn.FZ_fw9+","+btn.FZ_fw10+","+btn.FZ_fw11+","+btn.FZ_ex1+","+btn.FZ_ex2+","+btn.FZ_ex3+","+btn.FZ_ex4+","+btn.FZ_ex5+","+btn.FZ_ex6+","+btn.FZ_ex7+","+btn.FZ_ex8+","+btn.FZ_ex9+","+btn.FZ_ex10+","+btn.FZ_ex11+","+state.start_auto+","+state.stop_auto+","+state.sudden_crease+","+state.all_open+","+state.actual_set_power+","+state.output_power+","+state.set_power+","+state.interval_time+","+state.actual_curr+","+state.actual_mov+","+state.switch_on+","+state.FZ_autostate1+","+state.FZ_autostate2+","+state.FZ_autostate3+","+state.FZ_autostate4+","+state.FZ_autostate5+","+state.react_overtem+","+state.water_overtem+","+state.water_level_low+","+state.water_pressure_high+","+state.local_control+","+state.back_control+","+state.central_control+","+state.switch_state+","+state.inter_volume_M200+","+state.fan_button+","+state.fan_output+","+state.allow_close+");";
|
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
| | | try {
|
| | | sql.sqlMysqlExecute(sql_str);
|
| | | } catch (SQLException e) {
|
| | | e.printStackTrace();
|
| | | } finally {
|
| | | sql.close_con();
|
| | | }
|
| | | }
|
| | | }
|