From d73558a28b0246e3ca0197c81c5fde1732456196 Mon Sep 17 00:00:00 2001
From: Administrator <1525436766@qq.com>
Date: 星期四, 08 四月 2021 10:37:38 +0800
Subject: [PATCH] 集中监控系统通讯程序添加设备通讯正常故障字段信息记录

---
 Central_Monitor/src/com/data/Comm/Central_DataParsing_Thread_SQL.java |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 50 insertions(+), 0 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 289fb3c..0dc9d4b 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
@@ -13,6 +13,56 @@
 import com.sql.Sql_Mysql;
 
 public class Central_DataParsing_Thread_SQL {
+	
+	/**
+	 *	插入或更新设备通讯状态
+	 * @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();
+		}
+	}
+	
 
 	/**
 	 * 	加载集中监控平台设备设备信息

--
Gitblit v1.9.1