whycxzp
2025-06-09 7fe1ea37e4044eb61374a51c5a2fe1ecf9e834be
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
package com.whyc.service;
 
import com.whyc.dto.DevA200AlarmDto;
import com.whyc.mapper.CallBack;
import com.whyc.pojo.db_alarm.DevLithiumAlarmDataYear;
import com.whyc.pojo.db_lithium_testdata.BattLithiumTestData;
import com.whyc.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
 
@Service
public class SubTablePageInfoService {
    @Autowired
    private MybatisSqlExecuteService sqlExecuteService;
    //获取设备某次记录详细的单体放电过程
    public List<BattLithiumTestData> getTdataById(Integer devId, Integer testRecordCount) {
        String sql="select  * from db_batt_testdata.tb_batttestdata_" +devId
                +" where need_test=1 and test_record_count="+testRecordCount+" ";
        sql+="  ORDER BY record_num asc ";
        List list = sqlExecuteService.executeQuery_call(sql, new CallBack() {
            @Override
            public List getResults(ResultSet rs) throws SQLException {
                List<BattLithiumTestData> list=new ArrayList<>();
                while (rs.next()){
                    BattLithiumTestData tdata=new BattLithiumTestData();
                    tdata.setNum(rs.getInt("num"));
                    tdata.setDevId(rs.getInt("dev_id"));
                    tdata.setBattIdx(rs.getInt("batt_idx"));
                    tdata.setTestRecordCount(rs.getInt("test_record_count"));
                    tdata.setTestType(rs.getInt("test_type"));
                    tdata.setRecordNum(rs.getInt("record_num"));
                    tdata.setTestStarttime(rs.getTimestamp("test_starttime"));
                    tdata.setRecordTime(rs.getTimestamp("record_time"));
                    tdata.setTestTimelong(rs.getInt("test_timelong"));
                    tdata.setGroupVol(rs.getDouble("group_vol"));
                    tdata.setTestCurr(rs.getDouble("test_curr"));
                    tdata.setTestCap(rs.getDouble("test_cap"));
                    tdata.setMonNum(rs.getInt("mon_num"));
                    tdata.setMonVol(rs.getDouble("mon_vol"));
                    tdata.setMonTmp(rs.getDouble("mon_tmp"));
                    tdata.setMonCurr(rs.getDouble("mon_curr"));
                    tdata.setMonCap(rs.getDouble("mon_cap"));
                    tdata.setMonWh(rs.getDouble("mon_wh"));
                    tdata.setMonState(rs.getString("mon_state"));
                    tdata.setMonFault(rs.getString("mon_fault"));
                    tdata.setNeedTest(rs.getInt("need_test"));
                    list.add(tdata);
                }
                return list;
            }
        });
        return list;
    }
 
    //获取设备某次记录详细的单体放电过程
    public List<BattLithiumTestData> getTdataByIdWithListA200(Integer devId, Integer testRecordCount) {
        String sql="select  * from db_lithium_testdata.tb_batttestdata_" +devId
                +" where need_test=1 and test_record_count="+testRecordCount+" ";
        sql+="  ORDER BY record_num asc ";
        List list = sqlExecuteService.executeQuery_call(sql, new CallBack() {
            @Override
            public List getResults(ResultSet rs) throws SQLException {
                List list=new ArrayList<>();
                List<Float> monVols=null;
                List<Integer> monNums=null;
                BattLithiumTestData tdata=null;
                int num=0;
                try {
                    while (rs.next()){
                        int monNum=rs.getInt("mon_num");
                        float monvol=rs.getFloat("mon_vol");
                        int recordNum=rs.getInt("record_num");
                        if(num!=recordNum){
                            if(num!=0){
                                tdata.setMonVols(monVols);
                                tdata.setMonNums(monNums);
                                list.add(tdata);
                            }
                            tdata=new BattLithiumTestData();
                            monVols=new ArrayList<>();
                            monNums=new ArrayList<>();
                            tdata.setDevId(rs.getInt("dev_id"));
                            tdata.setBattIdx(rs.getInt("batt_idx"));
                            tdata.setTestRecordCount(rs.getInt("test_record_count"));
                            tdata.setTestType(rs.getInt("test_type"));
                            tdata.setRecordNum(recordNum);
                            tdata.setTestStarttime(rs.getTimestamp("test_starttime"));
                            tdata.setRecordTime(rs.getTimestamp("record_time"));
                            tdata.setTestTimelong(rs.getInt("test_timelong"));
                            tdata.setGroupVol(rs.getDouble("group_vol"));
                            tdata.setTestCurr(rs.getDouble("test_curr"));
                            tdata.setTestCap(rs.getDouble("test_cap"));
                            tdata.setNeedTest(rs.getInt("need_test"));
                            tdata.setMaxTemp(rs.getFloat("max_temp"));
                            tdata.setMinTemp(rs.getFloat("min_temp"));
                            num=recordNum;
                        }
                        monVols.add(monvol);
                        monNums.add(monNum);
                    }
                    tdata.setMonVols(monVols);
                    tdata.setMonNums(monNums);
                    list.add(tdata);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
                return list;
            }
        });
        return list;
    }
    //查询DevAlm历史告警数量
    public int getCountForDevAlm(DevA200AlarmDto dto) {
        String sql="select  count(distinct num) as number from db_alarm." +dto.getTableName()
                +" where 1=1 ";
 
        if(dto.getStartTime()!=null){
            sql+=" and alm_starttime  >='"+ ThreadLocalUtil.format(dto.getStartTime(),1)+"' ";
        }
        if(dto.getEndTime()!=null){
            sql+=" and alm_endtime  <='"+ThreadLocalUtil.format(dto.getEndTime(),1)+"' ";
        }
        if(dto.getDevType()!=null){
           sql+=" and  FLOOR(dev_id/100000000)="+dto.getDevType();
        }
        if(dto.getDevId()!=null){
            sql+=" and  dev_id="+dto.getDevId();
        }
        if(dto.getAlmId()!=null){
            sql+=" and alm_id="+dto.getAlmId();
        }
        sql+=" and dev_id in (" +
                "            SELECT distinct dev_id from db_user.tb_battgroup_baojigroup,db_user.tb_battgroup_usr" +
                "            where tb_battgroup_baojigroup.baoji_group_id=tb_battgroup_usr.baoji_group_id" +
                "           and uid="+dto.getUid()+
                ")";
        sql+="  order by alm_starttime desc ";
        List list = sqlExecuteService.executeQuery_call(sql, new CallBack() {
            @Override
            public List getResults(ResultSet rs) throws SQLException {
                LinkedList<Object> temp = new LinkedList<>();
                try {
                    while (rs.next())
                        temp.add(rs.getInt("number"));
                } catch (SQLException e) {
                    e.printStackTrace();
                }
                return temp;
            }
        });
        int num =0;
        if(list!=null){
            num= (int) list.get(0);
        }
        return num;
    }
    //查询devalm历史告警
    public List getListDevAlm(DevA200AlarmDto dto){
        String sql="select  * from db_alarm." +dto.getTableName()
                +" where 1=1 ";
 
        if(dto.getStartTime()!=null){
            sql+=" and alm_starttime  >='"+ ThreadLocalUtil.format(dto.getStartTime(),1)+"' ";
        }
        if(dto.getEndTime()!=null){
            sql+=" and alm_endtime  <='"+ThreadLocalUtil.format(dto.getEndTime(),1)+"' ";
        }
        if(dto.getDevType()!=null){
            sql+=" and  FLOOR(dev_id/100000000)="+dto.getDevType();
        }
        if(dto.getDevId()!=null){
            sql+=" and  dev_id="+dto.getDevId();
        }
        if(dto.getAlmId()!=null){
            sql+=" and alm_id="+dto.getAlmId();
        }
        sql+=" and dev_id in (" +
                "            SELECT distinct dev_id from db_user.tb_battgroup_baojigroup,db_user.tb_battgroup_usr" +
                "           where tb_battgroup_baojigroup.baoji_group_id=tb_battgroup_usr.baoji_group_id" +
                "           and uid="+dto.getUid()+
                ")";
        sql+="  ORDER BY alm_starttime desc  limit "+dto.getLimitStart()+","+dto.getLimitEnd()+" ";
        List list = sqlExecuteService.executeQuery_call(sql, new CallBack() {
            @Override
            public List getResults(ResultSet rs) throws SQLException {
                List<DevLithiumAlarmDataYear> list=new ArrayList<>();
                while (rs.next()){
                    DevLithiumAlarmDataYear dataYear=new DevLithiumAlarmDataYear();
                    dataYear.setNum(rs.getInt("num"));
                    dataYear.setDevId(rs.getInt("dev_id"));
                    dataYear.setAlmId(rs.getInt("alm_id"));
                    dataYear.setAlmSignalId(rs.getInt("alm_signal_id"));
                    dataYear.setAlmStarttime(rs.getTimestamp("alm_starttime"));
                    dataYear.setAlmValue(rs.getFloat("alm_value"));
                    dataYear.setAlmIsConfirmed(rs.getInt("alm_is_confirmed"));
                    dataYear.setConfirmedUid(rs.getInt("confirmed_uid"));
                    dataYear.setConfirmedTime(rs.getTimestamp("confirmed_time"));
                    dataYear.setAlmEndtime(rs.getTimestamp("alm_endtime"));
                    dataYear.setAlmClearedType(rs.getInt("alm_cleared_type"));
                    list.add(dataYear);
                }
                return list;
            }
        });
        return list;
    }
 
 
    public List<BattLithiumTestData> getTdataByIdWithListActm(Integer devId, Integer testRecordCount) {
        String sql="select  * from db_batt_testdata.tb_batttestdata_" +devId
                +" where need_test=1 and test_record_count="+testRecordCount+" ";
        sql+="  ORDER BY record_num asc ";
        List list = sqlExecuteService.executeQuery_call(sql, new CallBack() {
            @Override
            public List getResults(ResultSet rs) throws SQLException {
                List list=new ArrayList<>();
                List<Float> monVols=null;
                List<Float> monCurrs=null;
                List<Float> monCaps=null;
                List<Float> monWhs=null;
                List<Integer> monNums=null;
                BattLithiumTestData tdata=null;
                int num=0;
                try {
                    while (rs.next()){
                        int monNum=rs.getInt("mon_num");
                        float monvol=rs.getFloat("mon_vol");
                        float monCurr=rs.getFloat("mon_curr");
                        float monCap=rs.getFloat("mon_cap");
                        float monWh=rs.getFloat("mon_wh");
                        int recordNum=rs.getInt("record_num");
 
                        if(num!=recordNum){
                            if(num!=0){
                                tdata.setMonVols(monVols);
                                tdata.setMonNums(monNums);
                                tdata.setMonCurrs(monCurrs);
                                tdata.setMonCaps(monCaps);
                                tdata.setMonWhs(monWhs);
                                list.add(tdata);
                            }
                            tdata=new BattLithiumTestData();
                            monVols=new ArrayList<>();
                            monNums=new ArrayList<>();
                            monCurrs=new ArrayList<>();
                            monCaps=new ArrayList<>();
                            monWhs=new ArrayList<>();
                            tdata.setDevId(rs.getInt("dev_id"));
                            tdata.setBattIdx(rs.getInt("batt_idx"));
                            tdata.setTestRecordCount(rs.getInt("test_record_count"));
                            tdata.setTestType(rs.getInt("test_type"));
                            tdata.setRecordNum(recordNum);
                            tdata.setTestStarttime(rs.getTimestamp("test_starttime"));
                            tdata.setRecordTime(rs.getTimestamp("record_time"));
                            tdata.setTestTimelong(rs.getInt("test_timelong"));
                            tdata.setGroupVol(rs.getDouble("group_vol"));
                            tdata.setTestCurr(rs.getDouble("test_curr"));
                            tdata.setTestCap(rs.getDouble("test_cap"));
                            tdata.setNeedTest(rs.getInt("need_test"));
                            tdata.setMonTmp(rs.getDouble("mon_tmp"));
                            num=recordNum;
                        }
                        monVols.add(monvol);
                        monNums.add(monNum);
                        monCurrs.add(monCurr);
                        monCaps.add(monCap);
                        monWhs.add(monWh);
                    }
 
                    tdata.setMonVols(monVols);
                    tdata.setMonNums(monNums);
                    tdata.setMonCurrs(monCurrs);
                    tdata.setMonCaps(monCaps);
                    tdata.setMonWhs(monWhs);
                    list.add(tdata);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
                return list;
            }
        });
        return list;
    }
}