whycxzp
2021-03-13 fcdf8edb15271327988c9e52c25514c8b6eb5677
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
package com.whyc.service;
 
import com.whyc.constant.AlarmConstant;
import com.whyc.dto.BatteryAlarmDto;
import com.whyc.dto.Response;
import com.whyc.mapper.BatteryAlarmMapper;
import com.whyc.mapper.BatteryInfoMapper;
import com.whyc.mapper.Fbs9100StateMapper;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashMap;
import java.util.Map;
 
@Service
public class BatteryAlarmService {
 
    @Resource
    private BatteryAlarmMapper mapper;
 
    @Resource
    private Fbs9100StateMapper fbs9100StateMapper;
 
    @Resource
    private BatteryInfoMapper infoMapper;
 
    /**
     * 单体容量 monCapStd
     * alm_id
     * Alarm_CapAlarm =119010
     * @param userId
     * @return
     */
    public Response<Map> getMonCapacityLowAnalysis(int userId) {
        Response<Map> response = new Response();
        Map<String, Object> resultMap = new HashMap<>();
 
        try {
            //单体容量低告警数和对应的告警机房数
            BatteryAlarmDto batteryAlarmDto = mapper.getLowCapacityAlarms(userId,AlarmConstant.Alarm_IGNAL_ID_CapAlarmLow);
            int alarmNum = batteryAlarmDto.getNum();
            int stationNum = batteryAlarmDto.getStationNum();
            //总告警数
            Integer totalAlarmNum = mapper.getTotalAlarms(userId);
            //总机房数
            int totalStationNum = infoMapper.getStationCount(userId);
 
            //容量低告警占比
            double capLowRate = BigDecimal.valueOf(alarmNum).divide(BigDecimal.valueOf(totalAlarmNum), 2, RoundingMode.HALF_UP).doubleValue();
            String capLowRateStr = (int)(capLowRate*100)+"%";
            //容量低告警机房占比
            double capLowStationRate = BigDecimal.valueOf(stationNum).divide(BigDecimal.valueOf(totalStationNum), 2, RoundingMode.HALF_UP).doubleValue();
            String capLowStationRateStr = (int)(capLowStationRate*100)+"%";
 
            resultMap.put("告警数",alarmNum);
            resultMap.put("告警总数",totalAlarmNum);
            resultMap.put("告警占比",capLowRateStr);
 
            resultMap.put("告警机房数",alarmNum);
            resultMap.put("告警机房占比",capLowStationRateStr);
 
            response.set(1, resultMap);
        } catch (Exception e) {
            e.printStackTrace();
            return response.set(0);
        }
        return response;
    }
 
    /**
     * 在线电压和组端电压
     * alm_id 电池告警参数
     * Alarm_vol_Online =119001
     * Alarm_vol_Group =119002
     *
     * @param userId
     * @return
     */
    //TODO
    public Response<Map> getOnlineAndGroupVolAnalysis(int userId) {
//        select alm_signal_id,count(alm_signal_id) as num from db_alarm.tb_battalarm_data alarm where alm_id in (119001,119002,119003,119004)
        Response<Map> response = new Response();
        HashMap<String, Object> resultMap = new HashMap<>();
        Map<String, Integer> resMap = new HashMap<>();//内阻测试数量
        Map<String, Integer> errMap = new HashMap<>();//故障数量
 
        try {
            BatteryAlarmDto onlinebatteryAlarmDto = mapper.getOnlineAndGroupAlarms(AlarmConstant.Alarm_res_Monomer,AlarmConstant.ALM_SIGNAL_ID_OnlineVolHigh, userId);
            BatteryAlarmDto groupbatteryAlarmDto = mapper.getOnlineAndGroupAlarms(AlarmConstant.Alarm_vol_Group,AlarmConstant.ALM_SIGNAL_ID_OnlineVolHigh, userId);
 
            Integer highAlarmNum = onlinebatteryAlarmDto.getNum();
            Integer stationNum = onlinebatteryAlarmDto.getStationNum();
            resMap.put("高告警数量", 1);     //高告警数量    alm_signal_id:online 1 high; 2 low
 
            resMap.put("低告警数量", 1);     //低告警数量
            resMap.put("告警总数比例", 1);      //告警总数比例
 
            Integer totalAlarmNum = mapper.getTotalAlarms(userId);
            resMap.put("告警总数", totalAlarmNum);        //告警总数
 
            Integer totalAlarmRooms = mapper.getTotalAlarmRooms(userId);
            resMap.put("告警机房总数", 1);      //告警机房总数
 
            resMap.put("低告警机房数比例", 1);    //低告警机房数比例
            resultMap.put("内阻测试数量", resMap);
 
 
            errMap.put("高告警数量", 1);     //高告警数量
            errMap.put("低告警数量", 1);     //低告警数量
            errMap.put("告警总数比例", 1);      //告警总数比例
            errMap.put("告警总数", 1);        //告警总数
            errMap.put("告警机房总数", 1);      //告警机房总数
            errMap.put("低告警机房数比例", 1);    //低告警机房数比例
            resultMap.put("故障数量", errMap);
 
            response.setCode(1);
            response.setData(resultMap);
        } catch (Exception e) {
            e.printStackTrace();
            response.setCode(0);
            return response;
        }
 
        return response;
    }
 
 
    /**
     * BTS 设备状态
     *
     * @param userId
     * @return
     */
    //TODO
    public Response<Map> getBTSEquipStatus(int userId) {
 
        Response<Map> response = new Response();
        Map<String, Object> resultMap = new HashMap<>();
        try {
 
 
            int devId = 910000001;
            Integer herongNO = fbs9100StateMapper.getHeRongNO(devId, userId);    //dev_workstate 0 在线浮充; 2 核容测试; 4 内阻测试;
//            com.fgkj.dao.impl.ram.Fbs9100_stateImpl#seach6185Nuclear_cap 核容测试
//        Integer onlineFloatNO = fbs9100StateMapper.getOnlineFloatNO(devId,userId);
//        Integer chargeNO = fbs9100StateMapper.getChargeNO(devId,userId);
//        Integer resTestNO = fbs9100StateMapper.getResTestNO(devId,userId);
//        Integer errNO = fbs9100StateMapper.getErrNO(devId,userId);
            resultMap.put("核容数量", herongNO);    //核容数量
            resultMap.put("在线浮充数量", 1);    //在线浮充数量
            resultMap.put("充电数量", 1);    //充电数量
            resultMap.put("内阻测试数量", 1);    //内阻测试数量
            resultMap.put("故障数量", 1);    //故障数量
            response.setCode(1);
            response.setData(resultMap);
        } catch (Exception e) {
            e.printStackTrace();
            response.setCode(0);
            return response;
        }
        return response;
    }
 
 
    /**
     * 放电电流 Alarm_curr_Discharge =119004
     *  alm_signal_id 查询条件 ALM_SIGNAL_ID_DisChargeCurrLow
     * @param userId
     * @return
     */
    public Response<Map> getDischargeAnalysis(int userId) {
 
        Response<Map> response = new Response();
        Map<String, Object> resultMap = new HashMap<>();
 
        try {
            //放电电流低告警数和对应的告警机房数
            BatteryAlarmDto batteryAlarmDto = mapper.getLowDischargeAlarms(userId,AlarmConstant.ALM_SIGNAL_ID_DisChargeCurrLow);
            int disChargeAlarmNum = batteryAlarmDto.getNum();
            int disChargeStationNum = batteryAlarmDto.getStationNum();
 
            //总告警数
            Integer totalAlarmNum = mapper.getTotalAlarms(userId);
            //总机房数
            int totalStationNum = infoMapper.getStationCount(userId);
            //放电电流低告警占比
            double disChargeLowRate = BigDecimal.valueOf(disChargeAlarmNum).divide(BigDecimal.valueOf(totalAlarmNum), 2, RoundingMode.HALF_UP).doubleValue();
            String disChargeLowRateStr = (int)(disChargeLowRate*100)+"%";
            //放电电流低告警机房占比
            double disChargeLowStationRate = BigDecimal.valueOf(disChargeStationNum).divide(BigDecimal.valueOf(totalStationNum), 2, RoundingMode.HALF_UP).doubleValue();
            String disChargeLowStationRateStr = (int)(disChargeLowStationRate*100)+"%";
 
            resultMap.put("低告警数量", disChargeAlarmNum);     //低告警数量 alm_signal_id:DisChargeCurr 7 high; 8 low
            resultMap.put("告警机房总数", disChargeStationNum);      //告警机房总数
            resultMap.put("告警机房数比例", disChargeLowRateStr);    //告警机房数比例
            resultMap.put("告警总数", totalAlarmNum);        //告警总数
            resultMap.put("告警总数比例", disChargeLowStationRateStr);      //告警总数比例
            response.setCode(1);
            response.setData(resultMap);
        } catch (Exception e) {
            e.printStackTrace();
            return response.setCode(0);
        }
        return response;
    }
 
    /**
     * 放电和充电电流 高
     * alm_id 电池告警参数
     * @param userId
     * @return
     */
    //TODO
    public Response<Map> getChargeAnalysis(int userId) {
 
        Response<Map> response = new Response();
        HashMap<String, Object> resultMap = new HashMap<>();
        Map<String, Integer> disCharge = new HashMap<>();//放电电流  Alarm_curr_Discharge =119004
        Map<String, Integer> reCharge = new HashMap<>();//充电电流   Alarm_curr_Charge =119003
 
        disCharge.put("高告警数量", 1);     //高告警数量    alm_signal_id:ChargeCurrHigh 5 high; 6 low
        disCharge.put("告警总数", 1);        //告警总数
        disCharge.put("告警总数比例", 1);      //告警总数比例
        disCharge.put("告警机房总数", 1);      //告警机房总数
        disCharge.put("告警机房数比例", 1);    //告警机房数比例
        resultMap.put("disCharge", disCharge);
 
        reCharge.put("高告警数量", 1);     //高告警数量
        reCharge.put("告警总数", 1);        //告警总数
        reCharge.put("告警总数比例", 1);      //告警总数比例
        reCharge.put("告警机房总数", 1);      //告警机房总数
        reCharge.put("告警机房数比例", 1);    //告警机房数比例
        resultMap.put("reCharge", reCharge);
 
        response.setCode(1);
        response.setData(resultMap);
        return response;
    }
 
 
    /**
     * 单体电压、内阻和温度
     * alm_id 电池告警参数
     * 三个告警总数不同,带条件?电压、内阻、温度
     * @param userId
     * @return
     */
    public Response<Map> getMonVRTAnalysis(int userId) {
 
        Response<Map> response = new Response();
        HashMap<String, Object> resultMap = new HashMap<>();
        Map<String, Object> monVolMap = new HashMap<>();//单体电压  Alarm_vol_Monomer =119005;
        Map<String, Object> monResMap = new HashMap<>();//单体内阻  Alarm_res_Monomer =119007
        Map<String, Object> monTemMap = new HashMap<>();//单体温度  Alarm_tmp_Monomer =119006
 
        /*======单体电压======*/
 
        //高告警数量
        Integer volHighAlarmsNum = mapper.getAlarmHighLow(userId,AlarmConstant.ALM_SIGNAL_ID_MonVolHigh);
        //低告警数量
        Integer volLowAlarmsNum = mapper.getAlarmHighLow(userId,AlarmConstant.ALM_SIGNAL_ID_MonVolLow);
 
        //单体电压总告警数
        Integer volTotalAlarmNum = volHighAlarmsNum+volLowAlarmsNum;
 
        //告警总数
        Integer totalStationAlarmNum =mapper.getTotalAlarms(userId);
 
        //电压告警机房数
        int volTotalAlarmStations = mapper.getTotalAlarmStations(userId,AlarmConstant.Alarm_vol_Monomer);
 
        //总机房数
        int totalStationNum = infoMapper.getStationCount(userId);
 
        //电压告警占比
        double volRate = BigDecimal.valueOf(volTotalAlarmNum).divide(BigDecimal.valueOf(totalStationAlarmNum), 2, RoundingMode.HALF_UP).doubleValue();
        String volRateStr = (int)(volRate*100)+"%";
        //电压告警机房占比
        double volStationRate = BigDecimal.valueOf(volTotalAlarmStations).divide(BigDecimal.valueOf(totalStationNum), 2, RoundingMode.HALF_UP).doubleValue();
        String volStationRateStr = (int)(volStationRate*100)+"%";
 
 
        monVolMap.put("高告警数量", volHighAlarmsNum);     //高告警数量    alm_signal_id 9
        monVolMap.put("低告警数量", volLowAlarmsNum);     //低告警数量     alm_signal_id   10
        monVolMap.put("告警总数", volTotalAlarmNum);        //告警总数
        monVolMap.put("告警总数比例", volRateStr);      //告警总数比例
        monVolMap.put("告警机房总数", volTotalAlarmStations);      //告警机房总数
        monVolMap.put("告警机房数比例", volStationRateStr);    //告警机房数比例
        resultMap.put("单体电压", monVolMap);
 
 
 
        /*======单体内阻======*/
 
        //高告警数量
        Integer resHighAlarmsNum = mapper.getAlarmHighLow(userId,AlarmConstant.ALM_SIGNAL_ID_MonResHigh);
        //低告警数量
        Integer resLowAlarmsNum = mapper.getAlarmHighLow(userId,AlarmConstant.ALM_SIGNAL_ID_MonResLow);
 
        //单体内阻总告警数
        Integer resTotalAlarmNum = resHighAlarmsNum+resLowAlarmsNum;
 
        //内阻告警机房数
        int resTotalAlarmStations = mapper.getTotalAlarmStations(userId,AlarmConstant.Alarm_res_Monomer);
 
        //内阻告警占比
        double resRate = BigDecimal.valueOf(resTotalAlarmNum).divide(BigDecimal.valueOf(totalStationAlarmNum), 2, RoundingMode.HALF_UP).doubleValue();
        String resRateStr = (int)(resRate*100)+"%";
        //内阻告警机房占比
        double resStationRate = BigDecimal.valueOf(resTotalAlarmStations).divide(BigDecimal.valueOf(totalStationNum), 2, RoundingMode.HALF_UP).doubleValue();
        String resStationRateStr = (int)(resStationRate*100)+"%";
 
        monResMap.put("高告警数量", resHighAlarmsNum);     //高告警数量    alm_signal_id 13
        monResMap.put("低告警数量", resLowAlarmsNum);     //低告警数量     alm_signal_id 14
        monResMap.put("告警总数", resTotalAlarmNum);        //告警总数
        monResMap.put("告警总数比例", resRateStr);      //告警总数比例
        monResMap.put("告警机房总数", resTotalAlarmStations);      //告警机房总数
        monResMap.put("告警机房数比例", resStationRateStr);    //告警机房数比例
        resultMap.put("单体内阻", monResMap);
 
        /*======单体温度======*/
 
        //高告警数量
        Integer tempHighAlarmsNum = mapper.getAlarmHighLow(userId,AlarmConstant.ALM_SIGNAL_ID_MonTmpHigh);
        //低告警数量
        Integer tempLowAlarmsNum = mapper.getAlarmHighLow(userId,AlarmConstant.ALM_SIGNAL_ID_MonTmpLow);
 
        //单体温度总告警数
        Integer tempTotalAlarmNum = tempHighAlarmsNum+tempLowAlarmsNum;
 
        //温度告警机房数
        int tempTotalAlarmStations = mapper.getTotalAlarmStations(userId,AlarmConstant.Alarm_tmp_Monomer);
 
        //温度告警占比
        double tempRate = BigDecimal.valueOf(tempTotalAlarmNum).divide(BigDecimal.valueOf(totalStationAlarmNum), 2, RoundingMode.HALF_UP).doubleValue();
        String tempRateStr = (int)(tempRate*100)+"%";
        //温度告警机房占比
        double tempStationRate = BigDecimal.valueOf(tempTotalAlarmStations).divide(BigDecimal.valueOf(totalStationNum), 2, RoundingMode.HALF_UP).doubleValue();
        String tempStationRateStr = (int)(tempStationRate*100)+"%";
 
        monTemMap.put("高告警数量", tempHighAlarmsNum);     //高告警数量    alm_signal_id 13
        monTemMap.put("低告警数量", tempLowAlarmsNum);     //低告警数量     alm_signal_id 14
        monTemMap.put("告警总数", tempTotalAlarmNum);        //告警总数
        monTemMap.put("告警总数比例", tempRateStr);      //告警总数比例
        monTemMap.put("告警机房总数", tempTotalAlarmStations);      //告警机房总数
        monTemMap.put("告警机房数比例", tempStationRateStr);    //告警机房数比例
        resultMap.put("单体温度", monTemMap);
 
        response.setCode(1);
        response.setData(resultMap);
        return response;
    }
 
}