From ca25ba854842035cf3e902190cad435148574169 Mon Sep 17 00:00:00 2001
From: Administrator <1525436766@qq.com>
Date: 星期四, 08 四月 2021 10:49:36 +0800
Subject: [PATCH] 大功率整流电源添加通讯状态更新

---
 Rectifier_power_4MW/src/com/data/comm/Rectifier_power_SQL.java |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/Rectifier_power_4MW/src/com/data/comm/Rectifier_power_SQL.java b/Rectifier_power_4MW/src/com/data/comm/Rectifier_power_SQL.java
index b87fe4b..8598d0a 100644
--- a/Rectifier_power_4MW/src/com/data/comm/Rectifier_power_SQL.java
+++ b/Rectifier_power_4MW/src/com/data/comm/Rectifier_power_SQL.java
@@ -26,6 +26,56 @@
 		CreateTB_rectifier_power_control(pool);
 		
 	}
+	
+	/**
+	 *	插入或更新设备通讯状态
+	 * @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();
+		}
+	}
+	
 	//创建4MW大功率整流电源控制表
     private static void CreateTB_rectifier_power_control(MysqlConnPool pool) {
     	String sql_str = "CREATE TABLE IF NOT EXISTS "+Sql_Mysql.TB_RECTIFIER_POWER_CONTROL+" (" + 

--
Gitblit v1.9.1