From 4dbd3ce69274c1b48ed569c4e23de63b9f9586b8 Mon Sep 17 00:00:00 2001 From: whyclj <1525436766@qq.com> Date: 星期四, 20 八月 2020 14:57:46 +0800 Subject: [PATCH] 添加历史上实时数据记录线程以及修复数据更新缓慢bug --- ElectricalSystem_MonitorServer_4KW/src/com/electrical/FourKW/Electrical_Task_SQL.java | 98 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 96 insertions(+), 2 deletions(-) diff --git a/ElectricalSystem_MonitorServer_4KW/src/com/electrical/FourKW/Electrical_Task_SQL.java b/ElectricalSystem_MonitorServer_4KW/src/com/electrical/FourKW/Electrical_Task_SQL.java index f0383a4..0884757 100644 --- a/ElectricalSystem_MonitorServer_4KW/src/com/electrical/FourKW/Electrical_Task_SQL.java +++ b/ElectricalSystem_MonitorServer_4KW/src/com/electrical/FourKW/Electrical_Task_SQL.java @@ -3,9 +3,11 @@ import java.security.interfaces.RSAKey; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.Date; import java.util.Iterator; import java.util.List; +import com.base.Com; import com.mysql.jdbc.EscapeTokenizer; import com.sql.MysqlConnPool; import com.sql.Sql_Mysql; @@ -431,8 +433,8 @@ } //插入或更新电源实时信息表 public static void replace_Electric_Rt(MysqlConnPool pool,Electric_Rt ert) { - String sql_str = " replace into "+ Sql_Mysql.Tb_Electric_Rt +"(electric_id,upsetcurr,upsetvol,convolcontrol,concurrcontrol,othermodes,parallelmodes,startposition,stopposition,resetposition,fanstart,fanstop,dcvol,dccurr,controlangle,loopflag,remoteflag,orderflag,consvolcurrflag,powerstartflag,workmodelflag) " - + " values("+ert.electric_id+","+ert.upsetcurr+","+ert.upsetvol+","+ert.convolcontrol+","+ert.concurrcontrol+","+ert.othermodes+","+ert.parallelmodes+","+ert.startposition+","+ert.stopposition+","+ert.resetposition+","+ert.fanstart+","+ert.fanstop+","+ert.dcvol+","+ert.dccurr+","+ert.controlangle+","+ert.loopflag+","+ert.remoteflag+","+ert.orderflag+","+ert.consvolcurrflag+","+ert.powerstartflag+","+ert.workmodelflag+")"; + String sql_str = " replace into "+ Sql_Mysql.Tb_Electric_Rt +"(electric_id,upsetcurr,upsetvol,convolcontrol,concurrcontrol,othermodes,parallelmodes,startposition,stopposition,resetposition,fanstart,fanstop,dcvol,dccurr,controlangle,loopflag,remoteflag,orderflag,consvolcurrflag,powerstartflag,workmodelflag,switchon_1,switchoff_1,switchon_2,switchoff_2) " + + " values("+ert.electric_id+","+ert.upsetcurr+","+ert.upsetvol+","+ert.convolcontrol+","+ert.concurrcontrol+","+ert.othermodes+","+ert.parallelmodes+","+ert.startposition+","+ert.stopposition+","+ert.resetposition+","+ert.fanstart+","+ert.fanstop+","+ert.dcvol+","+ert.dccurr+","+ert.controlangle+","+ert.loopflag+","+ert.remoteflag+","+ert.orderflag+","+ert.consvolcurrflag+","+ert.powerstartflag+","+ert.workmodelflag+","+ert.switchon_1+","+ert.switchoff_1+","+ert.switchon_2+","+ert.switchoff_2+")"; Sql_Mysql sql = new Sql_Mysql(pool.getConn()); try { sql.sqlMysqlExecute(sql_str); @@ -616,4 +618,96 @@ sql.close_con(); } } + + /** + * 创建历史实时数据表 + * @param pool + * @param electric_id + */ + public static void createTb_Electric_Readhist_DataTable(MysqlConnPool pool,int electric_id) { + String sql_str = "CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Tb_Electric_Readhist_Data + electric_id + " (" + + " num bigint(20) NOT NULL AUTO_INCREMENT," + + " electric_id int(11) NOT NULL DEFAULT '0' COMMENT '电源id'," + + " record_time datetime NOT NULL DEFAULT '2000-01-01 00:00:00' COMMENT '记录时间'," + + " dcvol float NOT NULL DEFAULT '0' COMMENT '直流电压'," + + " dccurr float NOT NULL DEFAULT '0' COMMENT '直流电流'," + + " controlangle int(11) NOT NULL DEFAULT '0' COMMENT '控制角'," + + " note varchar(255) NOT NULL DEFAULT '' COMMENT '备用'," + + " PRIMARY KEY (num)" + + ") ENGINE=InnoDB AUTO_INCREMENT=1 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(); + } + } + + /** + * 读取当前设备的状态信息 + */ + public static void queryElectric_RtById(Electric_Rt rt,MysqlConnPool pool) { + String sql_str = " SELECT * FROM db_electricsystem.tb_electric_rt WHERE electric_id = " + rt.electric_id; + Sql_Mysql sql = new Sql_Mysql(pool.getConn()); + ResultSet res = null; + try { + res = sql.sqlMysqlQuery(sql_str); + while(res.next()) { + rt.upsetcurr = res.getFloat("upsetcurr"); //上位机设定电流 + rt.upsetvol = res.getFloat("upsetvol"); //上位机设定电压 + rt.convolcontrol = res.getInt("convolcontrol"); //恒压控制 + rt.concurrcontrol = res.getInt("concurrcontrol"); //恒流控制 + rt.othermodes = res.getInt("othermodes"); //其他模式运行 + rt.parallelmodes = res.getInt("parallelmodes"); //并联稳压运行 + rt.startposition = res.getInt("startposition"); //启动位 + rt.stopposition = res.getInt("stopposition"); //停止位 + rt.resetposition = res.getInt("resetposition"); //复位 + rt.fanstart = res.getInt("fanstart"); //风机启动 + rt.fanstop = res.getInt("fanstop"); //风机停止 + rt.dcvol = res.getFloat("dcvol"); //直流电压 + rt.dccurr = res.getFloat("dccurr"); //直流电流 + rt.controlangle = res.getInt("controlangle"); //控制角 + rt.loopflag = res.getInt("loopflag"); //开闭环标志位【0开环;1闭环】 + rt.remoteflag = res.getInt("remoteflag"); //就地远程标志位【0远程;1就地】 + rt.orderflag = res.getInt("orderflag"); //正序逆序标志位【0正序;1逆序】 + rt.consvolcurrflag = res.getInt("consvolcurrflag"); //恒压横流标志位【0恒压;1恒流】 + rt.powerstartflag = res.getInt("powerstartflag"); //电源启动标志位【0停止;1启动】 + rt.workmodelflag = res.getInt("workmodelflag"); //工作模式标志位【0其他模式;1并联稳压】 + rt.switchon_1 = res.getInt("switchon_1"); //开关1 + rt.switchoff_1 = res.getInt("switchoff_1"); //开关1 + rt.switchon_2 = res.getInt("switchon_2"); //开关2 + rt.switchoff_2 = res.getInt("switchoff_2"); //开关2 + } + } catch (SQLException e) { + e.printStackTrace(); + } finally { + if(res != null) { + try { + res.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + sql.close_con(); + } + } + } + + /** + * 记录历史实时数据 + * @param pool + * @param rt + */ + public static void recordHistoryData(MysqlConnPool pool, Electric_Rt rt) { + String sql_str = " INSERT INTO " + Sql_Mysql.Tb_Electric_Readhist_Data + rt.electric_id + "(electric_id,record_time,dcvol,dccurr,controlangle) VALUES("+rt.electric_id+",'"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms)+"',"+rt.dcvol+","+rt.dccurr+","+rt.controlangle+");"; + Sql_Mysql sql = new Sql_Mysql(pool.getConn()); + try { + sql.sqlMysqlExecute(sql_str); + } catch (SQLException e) { + e.printStackTrace(); + } finally { + sql.close_con(); + } + } } -- Gitblit v1.9.1