lxw
2023-03-11 87ab97e38d72baa46536509095bb5588e044ea7b
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.Response;
import com.whyc.dto.result.SystemGrdoupBatt;
import com.whyc.mapper.*;
import com.whyc.pojo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
 
@Service
public class StationInfService {
    @Autowired(required = false)
    private StationInfMapper mapper;
 
    @Autowired(required = false)
    private BattRtdataMapper rtdataMapper;
 
    @Autowired(required = false)
    private BattRtstateMapper rtstateMapper;
 
    @Autowired(required = false)
    private PwrdevAcdcdataMapper acdcMapper;
 
    @Autowired(required = false)
    private BattalarmDataMapper battAlmMapper;
 
    @Autowired(required = false)
    private DevalarmDataMapper devAlmMapper;
 
    @Autowired(required = false)
    private PwrdevAlarmMapper pwrAlmMapper;
 
    @Autowired(required = false)
    private BadbattMonMapper badMapper;
 
    @Autowired(required = false)
    private BattEnduranceMapper endMapper;
    @Autowired
    @Lazy
    private BattInfService battInfService;
    @Autowired
    private Fbs9100StateService fbs9100StateService;
    @Autowired
    private BattalarmDataService battAlarmDataService;
    @Autowired
    private DevalarmDataService devAlarmDataService;
    @Autowired
    private PwrdevAlarmService powerAlarmService;
 
    @Resource
    BadbattMonMapper badbattMonMapper;
    @Resource
    AlarmParamMapper alarmParamMapper;
 
    //插入站点
    public Response insertStation(StationInf stationInf) {
        int flag = mapper.insert(stationInf);
        return new Response().set(1, flag > 0, "插入站点");
    }
 
    //查询所有的站点
    public Response searchStationAll(int pageCurr, int pageSize, String stationName1, String stationName2, String stationName5) {
        PageHelper.startPage(pageCurr, pageSize);
        QueryWrapper wrapper = new QueryWrapper();
        if (!(stationName1 == null || stationName1.isEmpty())) {
            wrapper.eq("stationName1", stationName1);
        }
        if (!(stationName2 == null || stationName2.isEmpty())) {
            wrapper.eq("stationName2", stationName2);
        }
        if (!(stationName5 == null || stationName5.isEmpty())) {
            wrapper.eq("stationName5", stationName5);
        }
        List<StationInf> list = mapper.selectList(wrapper);
        PageInfo pageInfo = new PageInfo(list);
        return new Response().setII(1, list.size() > 0, pageInfo, "查询站点");
    }
 
    //删除总站点
    public Response deleteStation(int num) {
        UpdateWrapper wrapper = new UpdateWrapper();
        wrapper.eq("num", num);
        int flag = mapper.delete(wrapper);
        return new Response().set(1, flag > 0, "插入站点");
    }
 
    //管理员首页:站点实时数据推送
    public Response getSystemAll(int userId) {
        try {
            Map<String, Object> map = new HashMap();
            //头部统计数据
            int stationNum = mapper.getStation(userId);
            map.put("stationNum", stationNum);
            //浮充/充电
            List<BattRtstate> stateList = rtstateMapper.getBattStateStatic(userId);
            Map<String, Integer> statemap = new HashMap();
            statemap.put("batt1", 0);
            statemap.put("batt2", 0);
            Map<Integer, List<BattRtstate>> battstateMap = stateList.stream().collect(Collectors.groupingBy(BattRtstate::getBattState));
            for (Integer state : battstateMap.keySet()) {
                if (state == 1 || state == 2) {
                    statemap.put("batt" + state, battstateMap.get(state).size());
                }
            }
            map.put("battState", statemap);
            //整流器故障/负载熔断
            List<PwrdevAcdcdata> acdcList = acdcMapper.getAcdcStatic(userId);
            Map<String, Integer> errmap = new HashMap();
            Map<Integer, List<PwrdevAcdcdata>> aderrMap = acdcList.stream().collect(Collectors.groupingBy(PwrdevAcdcdata::getAcdcErr));
            errmap.put("err0", 0);
            errmap.put("err1", 0);
            for (Integer acdcerr : aderrMap.keySet()) {
                errmap.put("err" + acdcerr, aderrMap.get(acdcerr).size());
            }
            map.put("errmap", errmap);
            Map<String, Integer> fusemap = new HashMap();
            fusemap.put("fuse0", 0);
            fusemap.put("fuse1", 0);
            Map<Integer, List<PwrdevAcdcdata>> adfuseMap = acdcList.stream().collect(Collectors.groupingBy(PwrdevAcdcdata::getIsLoaderFuse));
            for (Integer fuse : adfuseMap.keySet()) {
                fusemap.put("fuse" + fuse, adfuseMap.get(fuse).size());
            }
            map.put("fusemap", fusemap);
            List<StationInf> list = mapper.getSystemAll(userId);
            for (StationInf inf : list) {
                String stationId = inf.getStationId();
                //查询分组电池信息
                List<SystemGrdoupBatt> sgblist = rtstateMapper.selectSystemGrdoupBatt(stationId);
                for (int i = 0; i < sgblist.size(); i++) {
                    int battGroupId = sgblist.get(i).getBattGroupId();
                    //查询机房下最大的单体电压和单体
                    BattRtdata maxData = rtdataMapper.maxData(battGroupId);
                    sgblist.get(i).setMaxVol(maxData.getMonVol());
                    sgblist.get(i).setMaxNum(maxData.getMonNum());
                    //查询机房下最低的单体电压和单体
                    BattRtdata minData = rtdataMapper.minData(battGroupId);
                    sgblist.get(i).setMinVol(maxData.getMonVol());
                    sgblist.get(i).setMinNum(maxData.getMonNum());
                    //查询实时告警总数
                    int battAlm = battAlmMapper.getbattAlm(battGroupId);
                    sgblist.get(i).setBattAlm(battAlm);
                }
                inf.setSgbList(sgblist);
                int devAlm = devAlmMapper.getdevAlm(stationId);
                inf.setDevAlm(devAlm);
                int pwrAlm = pwrAlmMapper.getpwrAlm(stationId);
                inf.setPwrAlm(pwrAlm);
            }
            map.put("data", list);
            return new Response().setII(1, true, map, "站点实时数据推送");
        } catch (Exception e) {
            return new Response().set(1, false, "发生异常:" + e.getCause());
        }
    }
 
    public String getMaxStationId() {
        QueryWrapper<StationInf> query = Wrappers.query();
        query.select("stationId").orderByDesc("num").last(" limit 1");
        StationInf stationInf = mapper.selectOne(query);
        if (stationInf == null) {
            return "42000000";
        } else {
            return stationInf.getStationId();
        }
    }
 
    /**
     *
     * @param userId
     * @return
     *  站点数:
     *  110v/35v:
     *  节点站:
     *  普通站:
     *  停点站:    tb_fbs9100_state.dev_workstate=3
     *  核容放电站:tb_fbs9100_state.dev_workstate=2
     *  故障告警站:
     *  站点地图:
     */
    public Response getStationStatistic(int userId) {
        try {
            Map<String, Object> stationInfoMap = new HashMap<>();
            List<StationInf> stationInfList = mapper.getStationInfList(userId);
            //站点数
            stationInfoMap.put("stationCount", stationInfList.size());
            //110v/35v/...
            Map<String, List<StationInf>> stationTypeMap = stationInfList.stream().filter(stationInf -> !stationInf.getStationType().equals("")).collect(Collectors.groupingBy(StationInf::getStationType));
            Set<String> stationTypeSet = stationTypeMap.keySet();
            for (String stationType : stationTypeSet) {
                stationInfoMap.put(stationType, stationTypeMap.get(stationType).size());
            }
            //节点站和普通站
            List<Battinf> stationList = battInfService.getSateAnalysis(userId);
            Map<Integer, List<Battinf>> nodeStationMap = stationList.stream().collect(Collectors.groupingBy(Battinf::getNodeStation));
 
            stationInfoMap.put("nomalStation", nodeStationMap.get(0) == null ? 0 : nodeStationMap.get(0).size());
            stationInfoMap.put("nodeStation", nodeStationMap.get(1) == null ? 0 : nodeStationMap.get(1).size());
 
            //停电站和核容放电站
            List<Fbs9100State> stateList = fbs9100StateService.getStateList(userId);
            Map<Integer, List<Fbs9100State>> stateMap = stateList.stream().collect(Collectors.groupingBy(Fbs9100State::getDevWorkstate));
            stationInfoMap.put("checkCapDischarge", stateMap.get(2) == null ? 0 : stateMap.get(2).size());
            stationInfoMap.put("powerOff", stateMap.get(3) == null ? 0 : stateMap.get(3).size());
            //故障告警站: 电池/设备/电源告警
            List<Integer> battStationList = battAlarmDataService.getStationList(userId);
            List<Integer> devStationList = devAlarmDataService.getStationList(userId);
            List<Integer> powerStationList = powerAlarmService.getStationList(userId);
            List<Integer> stationIdList = new LinkedList<>(battStationList);
            for (Integer integer : devStationList) {
                if (!stationIdList.contains(integer)) {
                    stationIdList.add(integer);
                }
            }
            for (Integer integer : powerStationList) {
                if (!stationIdList.contains(integer)) {
                    stationIdList.add(integer);
                }
            }
            stationInfoMap.put("alarmStationCount", stationIdList.size());
            //站点地图
            List<StationInf> mapAndWorkStateList = getStationMapAndWorkState(userId);
            stationInfoMap.put("stationMap",mapAndWorkStateList);
            return new Response().setII(1,true,stationInfoMap,null);
        }catch (Exception e){
            return new Response().set(1,false,"发生异常:"+e.getCause());
        }
    }
 
    public List<StationInf> getStationMapAndWorkState(int userId) {
        return mapper.getStationMapAndWorkState(userId);
    }
 
    //运维层首页:站点实时数据推送
    public Object getDevOpAll(int userId) {
        try {
            Map<String, Object> map = new HashMap();
            //头部统计数据
            int stationNum = mapper.getStation(userId);
            map.put("stationNum", stationNum);
            //浮充/充电
            List<BattRtstate> stateList = rtstateMapper.getBattStateStatic(userId);
            Map<Integer, Integer> statemap = new HashMap();
            Map<Integer, List<BattRtstate>> battstateMap = stateList.stream().collect(Collectors.groupingBy(BattRtstate::getBattState));
            for (Integer state : battstateMap.keySet()) {
                statemap.put(state, battstateMap.get(state).size());
            }
            map.put("battState", statemap);
            //整流器故障/负载熔断
            List<PwrdevAcdcdata> acdcList = acdcMapper.getAcdcStatic(userId);
            Map<Integer, Integer> errmap = new HashMap();
            Map<Integer, List<PwrdevAcdcdata>> aderrMap = acdcList.stream().collect(Collectors.groupingBy(PwrdevAcdcdata::getAcdcErr));
            for (Integer acdcerr : aderrMap.keySet()) {
                errmap.put(acdcerr, aderrMap.get(acdcerr).size());
            }
            map.put("errmap", errmap);
            Map<Integer, Integer> fusemap = new HashMap();
            Map<Integer, List<PwrdevAcdcdata>> adfuseMap = acdcList.stream().collect(Collectors.groupingBy(PwrdevAcdcdata::getIsLoaderFuse));
            for (Integer fuse : adfuseMap.keySet()) {
                fusemap.put(fuse, adfuseMap.get(fuse).size());
            }
            map.put("fusemap", fusemap);
            //下面各个站点数据
            List<StationInf> list = mapper.getSystemAll(userId);
            map.put("data", list);
            return new Response().setII(1, true, map, "站点实时数据推送");
        } catch (Exception e) {
            return new Response().set(1, false, "发生异常:" + e.getCause());
        }
 
    }
 
    //总机房
    public int getStation(int userId) {
        return mapper.getStation(userId);
    }
 
    //监控层首页:站点实时数据推送
    public Object getMonitorAll(int userId) {
        return new Response().set(1, true, "站点实时数据推送");
    }
 
    //管理员首页:头部统计
    public Response getSystemSkipHead(int userId) {
        try {
            Map<String, Object> map = new HashMap();
            //头部统计数据
            int stationNum = mapper.getStation(userId);
            map.put("stationNum", stationNum);
            //浮充/充电
            List<BattRtstate> stateList = rtstateMapper.getBattStateStatic(userId);
            Map<Integer, Integer> statemap = new HashMap();
            Map<Integer, List<BattRtstate>> battstateMap = stateList.stream().collect(Collectors.groupingBy(BattRtstate::getBattState));
            for (Integer state : battstateMap.keySet()) {
                statemap.put(state, battstateMap.get(state).size());
            }
            map.put("battState", statemap);
            return new Response().setII(1, true, map, "管理员首页:头部统计");
        } catch (Exception e) {
            return new Response().set(1, false, "发生异常:" + e.getCause());
        }
    }
 
    //指定站点详情第一次跳转机房id为0:message
    public Response getSystemSkipStation(int userId, String stationId) {
        //查询指定机房信息
        StationInf inf = mapper.getSystemSkipStation(userId, stationId);
        if (inf != null) {
            //查询分组电池信息
            List<SystemGrdoupBatt> sgblist = rtstateMapper.selectSystemGrdoupBatt(stationId);
            for (int i = 0; i < sgblist.size(); i++) {
                int battGroupId = sgblist.get(i).getBattGroupId();
                //查询机房下最大的单体电压和单体
                BattRtdata maxData = rtdataMapper.maxData(battGroupId);
                sgblist.get(i).setMaxVol(maxData.getMonVol());
                sgblist.get(i).setMaxNum(maxData.getMonNum());
                //查询机房下最低的单体电压和单体
                BattRtdata minData = rtdataMapper.minData(battGroupId);
                sgblist.get(i).setMinVol(maxData.getMonVol());
                sgblist.get(i).setMinNum(maxData.getMonNum());
                //查询实时告警总数
                int battAlm = battAlmMapper.getbattAlm(battGroupId);
                sgblist.get(i).setBattAlm(battAlm);
            }
            inf.setSgbList(sgblist);
            int devAlm = devAlmMapper.getdevAlm(stationId);
            inf.setDevAlm(devAlm);
            int pwrAlm = pwrAlmMapper.getpwrAlm(stationId);
            inf.setPwrAlm(pwrAlm);
            return new Response().setII(1, true, inf, "指定站点详情");
        } else {
            return new Response().set(1, false, "指定站点详情");
        }
 
    }
 
    //运维层首页:头部统计
    public Response getDevOpSkipHead(int userId) {
        try {
            Map<String, Object> map = new HashMap();
          /*  //头部统计数据
            int stationNum = mapper.getStation(userId);
            map.put("stationNum", stationNum);*/
            //浮充/充电
            List<BattRtstate> stateList = rtstateMapper.getBattStateStatic(userId);
            Map<Integer, Integer> statemap = new HashMap();
            Map<Integer, List<BattRtstate>> battstateMap = stateList.stream().collect(Collectors.groupingBy(BattRtstate::getBattState));
            for (Integer state : battstateMap.keySet()) {
                statemap.put(state, battstateMap.get(state).size());
            }
            map.put("battState", statemap);
            //整流器故障/负载熔断
            List<PwrdevAcdcdata> acdcList = acdcMapper.getAcdcStatic(userId);
            Map<Integer, Integer> errmap = new HashMap();
            Map<Integer, List<PwrdevAcdcdata>> aderrMap = acdcList.stream().collect(Collectors.groupingBy(PwrdevAcdcdata::getAcdcErr));
            for (Integer acdcerr : aderrMap.keySet()) {
                errmap.put(acdcerr, aderrMap.get(acdcerr).size());
            }
            map.put("errmap", errmap);
            Map<Integer, Integer> fusemap = new HashMap();
            Map<Integer, List<PwrdevAcdcdata>> adfuseMap = acdcList.stream().collect(Collectors.groupingBy(PwrdevAcdcdata::getIsLoaderFuse));
            for (Integer fuse : adfuseMap.keySet()) {
                fusemap.put(fuse, adfuseMap.get(fuse).size());
            }
            map.put("fusemap", fusemap);
            //站点统计
            List<StationInf> stationInfList = mapper.getStationInfList(userId);
            //站点数
            map.put("stationCount", stationInfList.size());
            //110v/35v/...
            Map<String, List<StationInf>> stationTypeMap = stationInfList.stream().filter(stationInf -> !stationInf.getStationType().equals("")).collect(Collectors.groupingBy(StationInf::getStationType));
            Set<String> stationTypeSet = stationTypeMap.keySet();
            for (String stationType : stationTypeSet) {
                map.put(stationType, stationTypeMap.get(stationType).size());
            }
            //节点站和普通站
            List<Battinf> stationList = battInfService.getSateAnalysis(userId);
            Map<Integer, List<Battinf>> nodeStationMap = stationList.stream().collect(Collectors.groupingBy(Battinf::getNodeStation));
 
            map.put("nomalStation", nodeStationMap.get(0) == null ? 0 : nodeStationMap.get(0).size());
            map.put("nodeStation", nodeStationMap.get(1) == null ? 0 : nodeStationMap.get(1).size());
 
            //停电站和核容放电站
            List<Fbs9100State> f9100stateList = fbs9100StateService.getStateList(userId);
            Map<Integer, List<Fbs9100State>> stateMap = f9100stateList.stream().collect(Collectors.groupingBy(Fbs9100State::getDevWorkstate));
            map.put("checkCapDischarge", stateMap.get(2) == null ? 0 : stateMap.get(2).size());
            map.put("powerOff", stateMap.get(3) == null ? 0 : stateMap.get(3).size());
 
            //1.查询劣化(告警)和损坏(更换)的阈值
            QueryWrapper<AlarmParam> alarmWrapper = new QueryWrapper();
            alarmWrapper.and(wrapper -> {
                return wrapper.eq("alm_name", "Batt_Alarm_Type_CapAlarm").or().eq("alm_name", "Batt_Alarm_Type_CapChange");
            });
            alarmWrapper.orderByAsc("alm_id");
            List<AlarmParam> paramList = alarmParamMapper.selectList(alarmWrapper);
            float capAlarm = paramList.get(0).getAlmLowCoe();//劣化参数0.8
            float capChange = paramList.get(1).getAlmLowCoe();//损坏参数0.6
            //劣化数量(包含损坏)
            int alarmNum = badbattMonMapper.getQualityAnalysis(userId, capAlarm);
            //损坏数量
            int changeNum = badbattMonMapper.getQualityAnalysis(userId, capChange);
            map.put("alarmNum", (alarmNum - changeNum));
            map.put("changeNum", changeNum);
            return new Response().setII(1, true, map, "站点实时数据推送");
        } catch (Exception e) {
            return new Response().set(1, false, "发生异常:" + e.getCause());
        }
 
    }
 
    //指定站点详情第一次跳转机房id为0:message
    public Response getDevOpSkipStation(int userId, String stationId) {
        //查询指定机房信息
        StationInf inf = mapper.getSystemSkipStation(userId, stationId);
        if (inf != null) {
            //查询分组电池信息
            List<SystemGrdoupBatt> sgblist = rtstateMapper.selectSystemGrdoupBatt(stationId);
            if (sgblist != null && sgblist.size() > 0) {
                for (int i = 0; i < sgblist.size(); i++) {
                    //判断是否落后
                    int battGroupId = sgblist.get(i).getBattGroupId();
                    int badbattFlag = badMapper.judgeBatt(battGroupId);
                    sgblist.get(i).setBadbattFlag(badbattFlag);
                }
                inf.setSgbList(sgblist);
            }
            //查询停电续航时间
            QueryWrapper wrapper = new QueryWrapper();
            wrapper.eq("stationid", stationId);
            BattEndurance endurance = endMapper.selectOne(wrapper);
            if (endurance != null) {
                inf.setEndurance(endurance);
            }
            return new Response().setII(1, true, inf, "指定站点详情");
        } else {
            return new Response().set(1, false, "指定站点详情");
        }
    }
 
    //查询省
    public Response searchAllStationName1(int uId) {
        List<String> list = mapper.getStationName1ByUserId(uId);
        return new Response().set(1, list, "查询成功");
    }
 
    public Response searchAllStationName2(Integer uId, String stationName1) {
        List<String> list = mapper.getStationName2ByUseridAndSt1(uId, stationName1);
        return new Response().set(1, list, "查询成功");
    }
 
    public Response searchAllStationName5(Integer uId, String stationName1, String stationName2) {
        List<String> list = mapper.getStationName5ByUseridAndSt1AndSt2(stationName1, stationName2, uId);
        return new Response().set(1, list, "查询成功");
    }
}