9度通讯程序适用于9度多组设备
whyclj
2020-09-15 687881fd4e407d4a2f3cb520a9d4d2748b21a848
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
package com.donghuan.c_interface;
 
import java.sql.SQLException;
 
import com.sql.MysqlConnPool;
import com.sql.Sql_Mysql;
 
public class CInterface_Thread_SQL {
    public static void createCInterfaceStateTableOnRam(MysqlConnPool con_pool, CInterfaceState al_state)
    {
        String str1 = "DROP TABLE IF EXISTS " + Sql_Mysql.CInterfaceState_Table;
        String str2 = "CREATE TABLE IF NOT EXISTS " + Sql_Mysql.CInterfaceState_Table
                    + " ( `num` BIGINT NOT NULL AUTO_INCREMENT, "
                    + "`BattGroupId` INT NOT NULL DEFAULT 0, "
                    + "`ComTxCount` INT NOT NULL DEFAULT 0, "
                    + "`ComRxCount` INT NOT NULL DEFAULT 0, "
                    + "`ComErrCount` INT NOT NULL DEFAULT 0, "
                    + "`ComErrType` INT NOT NULL DEFAULT 0, "
                    + " PRIMARY KEY (`num`) ) "
                    + " ENGINE=MEMORY DEFAULT CHARSET=utf8";
        String str3 = "INSERT INTO " + Sql_Mysql.CInterfaceState_Table
                    + " (BattGroupId) VALUES ";
                    for(int n=0; n<al_state.m_al_stat.size(); n++) {
                        if(n > 0) {
                            str3 += ",";
                        }
                        str3 += "(" + al_state.m_al_stat.get(n).bg_id + ")";
                    }
        Sql_Mysql sql = new Sql_Mysql(con_pool.getConn());
        try {
            sql.sqlMysqlExecute(str1);
            sql.sqlMysqlExecute(str2);
            sql.sqlMysqlExecute(str3);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        sql.close_con();
    }
    
    public static void updateCInterfaceStateTableOnRam(MysqlConnPool con_pool, CInterfaceState c_state)
    {
        String str = "UPDATE " + Sql_Mysql.CInterfaceState_Table
                + " SET ComTxCount = CASE BattGroupId ";
          for(int n=0; n<c_state.m_al_stat.size(); n++) {
              str += " WHEN " + c_state.m_al_stat.get(n).bg_id 
                      + " THEN " + c_state.m_al_stat.get(n).tx_count;
          }
          str += " END, ";
          
          str += " ComRxCount = CASE BattGroupId ";
          for(int n=0; n<c_state.m_al_stat.size(); n++) {
              str += " WHEN " + c_state.m_al_stat.get(n).bg_id 
                      + " THEN " + c_state.m_al_stat.get(n).rx_count;
          }
          str += " END, ";
          
          str += " ComErrCount = CASE BattGroupId ";
          for(int n=0; n<c_state.m_al_stat.size(); n++) {
              str += " WHEN " + c_state.m_al_stat.get(n).bg_id 
                      + " THEN " + c_state.m_al_stat.get(n).com_err_count;
          }
          str += " END ";
          str += " WHERE BattGroupId IN ("; 
        for(int n=0; n<c_state.m_al_stat.size(); n++) {
            if(n > 0) {
                str += ",";
            }
            str += c_state.m_al_stat.get(n).bg_id;
        }
        str += ")";
        
        
        Sql_Mysql sql = new Sql_Mysql(con_pool.getConn());
        try {
            sql.sqlMysqlExecute(str);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        sql.close_con();
    }
}