From 578faecf2a59d3062c96aed307b6df80c87a315d Mon Sep 17 00:00:00 2001
From: Administrator <1525436766@qq.com>
Date: 星期四, 25 三月 2021 14:44:53 +0800
Subject: [PATCH] 电机随机数据提交

---
 Demo_Manage_Simul/src/com/thread/devs/Manage_Simul_Motor_Thread_SQL.java |   66 +++++++++++++++++++++++++++++++-
 1 files changed, 63 insertions(+), 3 deletions(-)

diff --git a/Demo_Manage_Simul/src/com/thread/devs/Manage_Simul_Motor_Thread_SQL.java b/Demo_Manage_Simul/src/com/thread/devs/Manage_Simul_Motor_Thread_SQL.java
index 40b1161..d3740ba 100644
--- a/Demo_Manage_Simul/src/com/thread/devs/Manage_Simul_Motor_Thread_SQL.java
+++ b/Demo_Manage_Simul/src/com/thread/devs/Manage_Simul_Motor_Thread_SQL.java
@@ -1,17 +1,77 @@
 package com.thread.devs;
 
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import com.base.Com;
 import com.mode.Motor_State;
 import com.sql.MysqlConnPool;
 import com.sql.Sql_Mysql;
 
 public class Manage_Simul_Motor_Thread_SQL {
 
-	public static void insertMotor_State_Table(MysqlConnPool pool,Motor_State state) {
+	public static void insertOrUpdateMotor_State_Table(MysqlConnPool pool,Motor_State state) {
 		String sql_str = " SELECT device_id FROM "+Sql_Mysql.Tb_Motor_State_Table+" WHERE device_id = " + state.device_id;
 		String sql_str_ins = " INSERT INTO " + Sql_Mysql.Tb_Motor_State_Table +
 				"(device_id,record_time,motor_curr,motor_power,motor_speed,motor_vol,motor_out_tmp,motor_into_tmp,motor_torque,motor_state) " + 
-				"VALUES("+state.device_id+",'"+state.record_time+"',"+state.motor_curr+","+state.motor_power+","+state.motor_speed+","+state.motor_vol+","+state.motor_out_tmp+","+state.motor_into_tmp+","+state.motor_torque+","+state.motor_state+")";
-		
+				"VALUES("+state.device_id+",'"+Com.getDateTimeFormat(state.record_time, Com.DTF_YMDhms)+"',"+state.motor_curr+","+state.motor_power+","+state.motor_speed+","+state.motor_vol+","+state.motor_out_tmp+","+state.motor_into_tmp+","+state.motor_torque+","+state.motor_state+")";
+		String sql_str_upd = "UPDATE " + Sql_Mysql.Tb_Motor_State_Table +
+				" SET device_id="+state.device_id+""
+				+ ",record_time = '"+Com.getDateTimeFormat(state.record_time, Com.DTF_YMDhms)
+				+ "',motor_curr="+state.motor_curr
+				+ ",motor_power="+state.motor_power
+				+ ",motor_speed="+state.motor_speed
+				+ ",motor_vol="+state.motor_vol
+				+ ",motor_out_tmp="+state.motor_out_tmp
+				+ ",motor_into_tmp="+state.motor_into_tmp
+				+ ",motor_torque="+state.motor_torque
+				+ ",motor_state=" + state.motor_state+
+				" WHERE device_id = " + state.device_id;
+		ResultSet res = null;
+		Sql_Mysql sql = new Sql_Mysql(pool.getConn());
+		try {
+			res = sql.sqlMysqlQuery(sql_str);
+			if(res.next()) {
+				sql.sqlMysqlExecute(sql_str_upd);
+			}else {
+				sql.sqlMysqlExecute(sql_str_ins);
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+		} finally {
+			if(null != res) {
+				try {
+					res.close();
+				} catch (SQLException e) {
+					e.printStackTrace();
+				}
+			}
+			sql.close_con();
+		}
 	}
 	
+	
+	public static void updateMotor_State_Table(MysqlConnPool pool,Motor_State state) {
+		String sql_str_upd = "UPDATE " + Sql_Mysql.Tb_Motor_State_Table +
+				" SET device_id="+state.device_id+""
+				+ ",record_time = '"+Com.getDateTimeFormat(state.record_time, Com.DTF_YMDhms)
+				+ "',motor_curr="+state.motor_curr
+				+ ",motor_power="+state.motor_power
+				+ ",motor_speed="+state.motor_speed
+				+ ",motor_vol="+state.motor_vol
+				+ ",motor_out_tmp="+state.motor_out_tmp
+				+ ",motor_into_tmp="+state.motor_into_tmp
+				+ ",motor_torque="+state.motor_torque
+				+ ",motor_state=" + state.motor_state+
+				" WHERE device_id = " + state.device_id;
+		Sql_Mysql sql = new Sql_Mysql(pool.getConn());
+		try {
+			//System.out.println(sql_str_upd);
+			sql.sqlMysqlExecute(sql_str_upd);
+		} catch (Exception e) {
+			e.printStackTrace();
+		} finally {
+			sql.close_con();
+		}
+	}
 }

--
Gitblit v1.9.1