whyclj
2020-12-05 6b1b6b46fad3c7357706670994e1a23620d6c5c3
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
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 {
 
    /**
     *     ¼ÓÔØ¼¯ÖÐ¼à¿ØÆ½Ì¨É豸É豸ÐÅÏ¢
     * @param pool
     * @param motors
     */
    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 {
            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);
        } finally {
            if(null != res) {
                try {
                    res.close();
                } catch (SQLException e) {
                    sql.logger.error(e.toString(),e);
                }
            }
            sql.close_con();
        }
    }
    
    /**
     *     ²åÈë»ò¸üÐÂÖ±Á÷Ö÷ÅäÐÅÏ¢
     * @param pool
     * @param stdata
     */
    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 {
            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();
        }
    }
    
    /**
     *     ²åÈë»ò¸üнø³öÏ߯ÁÐÅÏ¢
     * @param pool
     * @param rtdata
     */
    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 {
            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();
        }
    }
    
}