FBS9600通信程序,带了均衡电压版本
Administrator
2021-08-12 8467d3be4ce3be340d36f45c83d370def9e7e50f
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package com.data.upload;
 
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
 
import com.base.Com;
import com.data.csv.CsvData;
import com.sql.MysqlConnPool;
import com.sql.Sql_Mysql;
 
public class ResDataUpload_SQL {
    
    public static int checkDataOk(MysqlConnPool conn_pool, int bg_id, CsvData res_data) {
        int data_reason_type = 0;
        
        Calendar mcld = Calendar.getInstance();
        mcld.setTime(res_data.m_TestTime);
        
        if(false == res_data.m_DataOk) {
            data_reason_type = 7;
        }
        
        int batt_cap = 0;
        int mon_count = 0;
        float mon_vol = 0;
        if(0 == data_reason_type) {
            //******************************************************************//
            if(CsvData.DevType_CSV == res_data.m_DevType) {
                res_data.m_STDAH = batt_cap;
            }
            
            String sql_bginf = "SELECT DISTINCT MonCapStd,MonCount,MonVolStd FROM " 
                                + Sql_Mysql.BattInf_Table + " WHERE BattGroupId=" + bg_id;
            String sql_str = "SELECT DISTINCT test_record_count FROM " + Sql_Mysql.BattResDataInf_Table
                                + " WHERE BattGroupId=" + bg_id 
                                + " AND test_starttime='" + Com.getDateTimeFormat(mcld.getTime(), Com.DTF_YMDhms) + "'";
            
            Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
            try {
                ResultSet res = sql.sqlMysqlQuery(sql_bginf);
                if(res.next()) {
                    batt_cap = (int) (res.getFloat("MonCapStd"));
                    mon_count = res.getInt("MonCount");
                    mon_vol = res.getFloat("MonVolStd");
                }
                
                res = sql.sqlMysqlQuery(sql_str);
                if(res.next()) {
                    data_reason_type = 1;
                }
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } finally {
                sql.close_con();
            }
            //******************************************************************//
            if(bg_id < 1) {
                data_reason_type = 6;
            } else if(mon_count != res_data.m_BattSum) {
                data_reason_type = 3;
            } else if((int)(mon_vol*10) != (int)(res_data.m_MonomerVol*10)) {
                data_reason_type = 4;
            } else {
                if((res_data.m_STDAH > 0) && (res_data.m_STDAH != batt_cap)) {
                    data_reason_type = 2;
                }
            }
        }
        
        return data_reason_type;
    }
    
    public static boolean insertResData(MysqlConnPool conn_pool, int bg_id, int uid, CsvData csv_data)
    {
        boolean upload_res = false;
        
        Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
        int testRecordCount = sql.getBattTestRecordCountNew(bg_id, Sql_Mysql.BattResDataInf_Table);
        Calendar ald = Calendar.getInstance();
        ald.setTime(csv_data.m_TestTime);
        String tb_name = "`db_batt_testdata`.`tb_BattResData_" + bg_id + "` ";
        try {
            //if(true == progress_event.ProgressIsRunning)
            {
                String sql_str0 = "CREATE TABLE IF NOT EXISTS " + tb_name + " "
                        + " ( `num` BIGINT NOT NULL AUTO_INCREMENT, "
                        + "`BattGroupId` INT NOT NULL DEFAULT 0, "
                        + "`test_record_count` INT NOT NULL DEFAULT 0, "
                        + "`test_type` INT NOT NULL DEFAULT 0, "
                        + "`data_new` BOOLEAN NOT NULL DEFAULT false, "
                        + "`data_available` BOOLEAN NOT NULL DEFAULT false, "
                        + "`test_starttime` DATETIME NOT NULL DEFAULT '1982-01-01 00:00:00', "
                        + "`group_vol` FLOAT NOT NULL DEFAULT 0, "
                        + "`test_curr` FLOAT NOT NULL DEFAULT 0, "
                        + "`mon_num` INT NOT NULL DEFAULT 0, "
                        + "`mon_vol` FLOAT NOT NULL DEFAULT 0, "
                        + "`mon_tmp` FLOAT NOT NULL DEFAULT 0, "
                        + "`mon_res` FLOAT NOT NULL DEFAULT 0, "
                        + "`mon_ser` FLOAT NOT NULL DEFAULT 0, "
                        + "`conn_res` FLOAT NOT NULL DEFAULT 0, "
                        + "INDEX index_test_record_count (`test_record_count`), "
                        + "PRIMARY KEY (`num`));";
                sql.sqlMysqlExecute(sql_str0);
                
                ArrayList<String> al_sql_str = new ArrayList<String>();
                String sql_str1 = "INSERT INTO " + tb_name + " "
                                    + " (BattGroupId, "
                                    + "test_record_count, "
                                    + "test_type, "
                                    + "data_new, "
                                    + "data_available, "
                                    + "test_starttime, "
                                    + "group_vol, "
                                    + "test_curr, "
                                    + "mon_num, "
                                    + "mon_vol,"
                                    + "mon_tmp,"
                                    + "mon_res,"
                                    + "mon_ser,"
                                    + "conn_res)"
                                    + " VALUES ";
                    for(int n=0; n<csv_data.m_BattSum; n++)
                    {
                        if(n > 0)
                            sql_str1 += ", ";
                        
                        sql_str1 = sql_str1
                                    + "("
                                    + bg_id + ", "
                                    + testRecordCount + ", "
                                    + csv_data.m_TestType + ", "
                                    + true + ", "
                                    + true + ", "
                                    + "'" + Com.getDateTimeFormat(csv_data.m_TestTime, Com.DTF_YMDhms) + "', "
                                    + csv_data.m_GroupVol + ", "
                                    + csv_data.m_TestCurr + ", "
                                    + ((n+1)*10 + 1) + ", "
                                    + csv_data.MonomerVol[n] + ","
                                    + csv_data.MonomerTmp[n] + ","
                                    + csv_data.MonomerRes[n] + ","
                                    + csv_data.MonomerSer[n] + ","
                                    + csv_data.MonomerConn[n]
                                    + ")";
                    }
                al_sql_str.add(sql_str1);
                    
                String sql_str2 = "INSERT INTO " + Sql_Mysql.BattResDataInf_Table
                                + " (BattGroupId, "
                                + "test_record_count, "
                                + "test_type, "
                                + "data_new, "
                                + "data_available, "
                                + "test_starttime, "
                                + "test_devtype, "
                                + "record_time, "
                                + "group_vol, "
                                + "test_curr, "
                                + "upload_usr_id, "
                                + "upload_client_type) "
                                + " VALUES "
                                + "("+ bg_id + ", "
                                + testRecordCount + ", "
                                + csv_data.m_TestType + ", "
                                + true + ", "
                                + true + ", "
                                + "'" + Com.getDateTimeFormat(ald.getTime(), Com.DTF_YMDhms) + "', "
                                + csv_data.m_DevType + ", "
                                + "'" + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms) + "', "
                                + csv_data.m_GroupVol + ", "
                                + csv_data.m_TestCurr + ", "
                                + uid + ", "
                                + Com.UploadData_ClientType_CS_SVR + ") ";
                if(1 == testRecordCount) {
                    sql_str2 = "UPDATE " + Sql_Mysql.BattResDataInf_Table + " SET "
                            + "test_type=" + csv_data.m_TestType + ", "
                            + "data_new=" + true + ", "
                            + "data_available=" + true + ", "
                            + "test_starttime='" + Com.getDateTimeFormat(ald.getTime(), Com.DTF_YMDhms) + "', "
                            + "test_devtype=" + csv_data.m_DevType + ", "
                            + "record_time='" + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms) + "', "
                            + "group_vol=" + csv_data.m_GroupVol + ", "
                            + "test_curr=" + csv_data.m_TestCurr + ", "
                            + "upload_usr_id=" + uid + ", "
                            + "upload_client_type=" + Com.UploadData_ClientType_CS_SVR + " "
                            + " WHERE BattGroupId=" + bg_id
                            + " AND test_record_count=" + testRecordCount;
                }
                al_sql_str.add(sql_str2);
                upload_res = sql.makeManualCommit(al_sql_str);
            }
        } catch (Exception e) {
            e.printStackTrace();
            upload_res = false;
        } finally {
            sql.close_con();
        }
        
        return upload_res;
    }
}