From 6b1b6b46fad3c7357706670994e1a23620d6c5c3 Mon Sep 17 00:00:00 2001
From: whyclj <1525436766@qq.com>
Date: 星期六, 05 十二月 2020 16:58:49 +0800
Subject: [PATCH] 添加数据读取

---
 Central_Monitor/src/com/data/Comm/Central_DataParsing_Thread_SQL.java |  188 +++++++++++++++++++++++++++--------------------
 1 files changed, 108 insertions(+), 80 deletions(-)

diff --git a/Central_Monitor/src/com/data/Comm/Central_DataParsing_Thread_SQL.java b/Central_Monitor/src/com/data/Comm/Central_DataParsing_Thread_SQL.java
index dc38ef1..aec9fb2 100644
--- a/Central_Monitor/src/com/data/Comm/Central_DataParsing_Thread_SQL.java
+++ b/Central_Monitor/src/com/data/Comm/Central_DataParsing_Thread_SQL.java
@@ -1,114 +1,142 @@
 package com.data.Comm;
 
+import java.sql.ResultSet;
 import java.sql.SQLException;
-
+import java.util.Date;
+import java.util.List;
+import com.base.Com;
+import com.data.Central_RT_Data;
+import com.data.Central_ST_Data;
+import com.data.Motor_inf;
 import com.sql.MysqlConnPool;
 import com.sql.Sql_Mysql;
 
 public class Central_DataParsing_Thread_SQL {
 
-	
-	public static void init(MysqlConnPool pool) {
-		CreateTb_Central_Monitor_Sys_StTable(pool);
-		
-		CreateTb_Central_Monitor_Sys_RtTable(pool);
-		
-		CreateTb_Central_Monitor_Sys_ControlTable(pool);
-	}
-	
-	
 	/**
-	 * 创建tb_central_monitor_sys_st表
+	 * 	加载集中监控平台设备设备信息
 	 * @param pool
+	 * @param motors
 	 */
-	public static void CreateTb_Central_Monitor_Sys_StTable(MysqlConnPool pool) {
-		String sql_str = "CREATE TABLE IF NOT EXISTS "+Sql_Mysql.Tb_Central_Monitor_Sys_St+" (" + 
-				"  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)" + 
-				") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
+	public static void loadDeviceData(MysqlConnPool pool,List<Motor_inf> motors) {
+		String sql_str = " SELECT * FROM " + Sql_Mysql.Tb_MW_Motor_inf + " WHERE sys_id = 100001";
 		Sql_Mysql sql = new Sql_Mysql(pool.getConn());
+		ResultSet res = null;
 		try {
-			sql.sqlMysqlExecute(sql_str);
+			res = sql.sqlMysqlQuery(sql_str);
+			while(res.next()) {
+				Motor_inf motor = new Motor_inf(res.getInt("dev_id"));
+				motor.setDev_ip(res.getString("dev_ip"));
+				motor.setDev_name(res.getString("dev_name"));
+				motor.setSys_id(res.getInt("sys_id"));
+				motor.setSys_name(res.getString("sys_name"));
+				motor.setNote(res.getString("note"));
+				motors.add(motor);
+			}
 		} catch (SQLException e) {
-			sql.logger.error(e.toString(), e);
+			sql.logger.error(e.toString(),e);
+		} finally {
+			if(null != res) {
+				try {
+					res.close();
+				} catch (SQLException e) {
+					sql.logger.error(e.toString(),e);
+				}
+			}
+			sql.close_con();
 		}
 	}
 	
 	/**
-	 * 创建tb_central_monitor_sys_rt表
+	 * 	插入或更新直流主配信息
 	 * @param pool
+	 * @param stdata
 	 */
-	public static void CreateTb_Central_Monitor_Sys_RtTable(MysqlConnPool pool) {
-		String sql_str = "CREATE TABLE IF NOT EXISTS "+Sql_Mysql.Tb_Central_Monitor_Sys_Rt+" (" + 
-				"  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)" + 
-				") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
+	public static void insertOrUpdateTb_Central_Monitor_Sys_St(MysqlConnPool pool,Central_ST_Data stdata) {
+		String sql_str_sel = " select dev_id from " + Sql_Mysql.Tb_Central_Monitor_Sys_St + " where dev_id = " + stdata.getDev_id();
+		String sql_str_ins = " intsert into " + Sql_Mysql.Tb_Central_Monitor_Sys_St + "(dev_id) values("+stdata.getDev_id()+")";
+		String sql_str_upd = " update " + Sql_Mysql.Tb_Central_Monitor_Sys_St + ""
+				+ " SET record_time '" + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms)
+				+ "',switch_close_1st_2500A = " + stdata.getSwitch_close_1st_2500A()
+				+ ",switch_open_1st_2500A = " + stdata.getSwitch_open_1st_2500A()
+				+ ",switch_fault_1st_2500A = " + stdata.getSwitch_fault_1st_2500A()
+				+ ",switch_close_2st_2500A = " + stdata.getSwitch_close_2st_2500A()
+				+ ",switch_open_2st_2500A = " + stdata.getSwitch_open_2st_2500A()
+				+ ",switch_fault_2st_2500A = " + stdata.getSwitch_fault_2st_2500A()
+				+ ",switch_close_bus_screen = " + stdata.getSwitch_close_bus_screen()
+				+ ",switch_open_bus_screen = " + stdata.getSwitch_open_bus_screen()
+				+ ",switch_fault_bus_screen = " + stdata.getSwitch_fault_bus_screen()
+				+ ",switch_close_1st_2500A_load = " + stdata.getSwitch_close_1st_2500A_load()
+				+ ",switch_open_1st_2500A_load = " + stdata.getSwitch_open_1st_2500A_load()
+				+ ",switch_fault_1st_2500A_load = " + stdata.getSwitch_fault_1st_2500A_load()
+				+ ",switch_close_2st_2500A_load = " + stdata.getSwitch_close_2st_2500A_load()
+				+ ",switch_open_2st_2500A_load = " + stdata.getSwitch_open_2st_2500A_load()
+				+ ",switch_fault_2st_2500A_load = " + stdata.getSwitch_fault_2st_2500A_load()
+				+ ",curr_a = " + stdata.getCurr_a()
+				+ ",vol_a = " + stdata.getVol_a()
+				+ ",curr_b = " + stdata.getCurr_b()
+				+ ",vol_b = " + stdata.getVol_b()
+				+ " Where dev_id = " + stdata.getDev_id();
 		Sql_Mysql sql = new Sql_Mysql(pool.getConn());
+		ResultSet res = null;
 		try {
-			sql.sqlMysqlExecute(sql_str);
-		} catch (SQLException e) {
-			sql.logger.error(e.toString(), e);
+			res = sql.sqlMysqlQuery(sql_str_sel);
+			if(res.next()) {
+				sql.sqlMysqlExecute(sql_str_upd);
+			}else {
+				sql.sqlMysqlExecute(sql_str_ins);
+			}
+		} catch (Exception e) {
+			sql.logger.error(e.toString(),e);
+		} finally {
+			if(null != res) {
+				try {
+					res.close();
+				} catch (SQLException e) {
+					sql.logger.error(e.toString(),e);
+				}
+			}
+			sql.close_con();
 		}
 	}
 	
 	/**
-	 * 创建tb_central_monitor_sys_control表
+	 * 	插入或更新进出线屏信息
 	 * @param pool
+	 * @param rtdata
 	 */
-	public static void CreateTb_Central_Monitor_Sys_ControlTable(MysqlConnPool pool) {
-		String sql_str = "CREATE TABLE IF NOT EXISTS "+Sql_Mysql.Tb_Central_Monitor_Sys_Control+" (" + 
-				"  num bigint(20) NOT NULL," + 
-				"  dev_id int(11) NOT NULL DEFAULT '0' COMMENT '设备id'," + 
-				"  op_cmd int(11) NOT NULL DEFAULT '0' 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_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_close_bus_screen int(11) NOT NULL DEFAULT '0' COMMENT '母联屏开关合闸'," + 
-				"  switch_open_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_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)" + 
-				") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
+	public static void insertOrUpdateTb_Central_Monitor_Sys_Rt(MysqlConnPool pool,Central_RT_Data rtdata) {
+		String sql_str_sel = " select dev_id from " + Sql_Mysql.Tb_Central_Monitor_Sys_Rt + " where dev_id = " + rtdata.getDev_id();
+		String sql_str_ins = " intsert into " + Sql_Mysql.Tb_Central_Monitor_Sys_Rt + "(dev_id) values("+rtdata.getDev_id()+")";
+		String sql_str_upd = " update " + Sql_Mysql.Tb_Central_Monitor_Sys_Rt + ""
+				+ " SET record_time '" + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms)
+				+ "',switch_close = " + rtdata.getSwitch_close()
+				+ ",switch_open = " + rtdata.getSwitch_open()
+				+ ",switch_fault = " + rtdata.getSwitch_fault()
+				+ ",panel_vol = " + rtdata.getPanel_vol()
+				+ ",panel_curr = " + rtdata.getPanel_curr()
+				+ " Where dev_id = " + rtdata.getDev_id();
 		Sql_Mysql sql = new Sql_Mysql(pool.getConn());
+		ResultSet res = null;
 		try {
-			sql.sqlMysqlExecute(sql_str);
-		} catch (SQLException e) {
-			sql.logger.error(e.toString(), e);
+			res = sql.sqlMysqlQuery(sql_str_sel);
+			if(res.next()) {
+				sql.sqlMysqlExecute(sql_str_upd);
+			}else {
+				sql.sqlMysqlExecute(sql_str_ins);
+			}
+		} catch (Exception e) {
+			sql.logger.error(e.toString(),e);
+		} finally {
+			if(null != res) {
+				try {
+					res.close();
+				} catch (SQLException e) {
+					sql.logger.error(e.toString(),e);
+				}
+			}
+			sql.close_con();
 		}
 	}
-	
 	
 }

--
Gitblit v1.9.1