综合管理平台数据库数据模拟程序
Administrator
2021-03-25 578faecf2a59d3062c96aed307b6df80c87a315d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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 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+",'"+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();
        }
    }
}