whycxzp
2023-03-08 dcf0b3fa409e7d4fb4276ea4c44b040ace8928f3
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
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.mapper.*;
import com.whyc.pojo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
 
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;
 
    //插入站点
    public Response insertStation(StationInf stationInf) {
        int flag = mapper.insert(stationInf);
        return new Response().set(1, flag > 0, "插入站点");
    }
 
    //查询所有的站点
    public Response searchStationAll(int pageCurr, int pageSize) {
        PageHelper.startPage(pageCurr, pageSize);
        List<StationInf> list = mapper.selectList(null);
        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) {
        List<StationInf> list = mapper.getSystemAll(userId);
        for (StationInf inf : list) {
            String stationId = inf.getStationId();
            //查询机房下最大的单体电压和单体
            BattRtdata maxData = rtdataMapper.maxData(stationId);
            inf.setMaxVol(maxData.getMonVol());
            inf.setMaxNum(maxData.getMonNum());
            //查询机房下最低的单体电压和单体
            BattRtdata minData = rtdataMapper.minData(stationId);
            inf.setMinVol(maxData.getMonVol());
            inf.setMinNum(maxData.getMonNum());
            //查询实时告警总数
            int battAlm = battAlmMapper.getbattAlm(stationId);
            inf.setBattAlm(battAlm);
            int devAlm = devAlmMapper.getdevAlm(stationId);
            inf.setDevAlm(devAlm);
            int pwrAlm = pwrAlmMapper.getpwrAlm(stationId);
            inf.setPwrAlm(pwrAlm);
            inf.setAlarmNum(battAlm + devAlm + pwrAlm);
        }
        return new Response().setII(1, list.size() > 0, list, "站点实时数据推送");
    }
 
    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, Integer> 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());
            return new Response().setII(1,true,stationInfoMap,null);
        }catch (Exception e){
            return new Response().set(1,false,"发生异常:"+e.getCause());
        }
    }
 
    //运维层首页:站点实时数据推送
    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) {
            //查询机房下最大的单体电压和单体
            BattRtdata maxData = rtdataMapper.maxData(stationId);
            inf.setMaxVol(maxData.getMonVol());
            inf.setMaxNum(maxData.getMonNum());
            //查询机房下最低的单体电压和单体
            BattRtdata minData = rtdataMapper.minData(stationId);
            inf.setMinVol(maxData.getMonVol());
            inf.setMinNum(maxData.getMonNum());
            //查询实时告警总数
            int battAlm = battAlmMapper.getbattAlm(stationId);
            inf.setBattAlm(battAlm);
            int devAlm = devAlmMapper.getdevAlm(stationId);
            inf.setDevAlm(devAlm);
            int pwrAlm = pwrAlmMapper.getpwrAlm(stationId);
            inf.setPwrAlm(pwrAlm);
            inf.setAlarmNum(battAlm + devAlm + 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);
            //站点统计
 
            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) {
            if (inf.getRtlist() != null && inf.getRtlist().size() > 0) {
                for (int i = 0; i < inf.getRtlist().size(); i++) {
                    //判断是否落后
                    int battGroupId = inf.getRtlist().get(i).getBattGroupId();
                    int badbattFlag = badMapper.judgeBatt(battGroupId);
                    inf.getRtlist().get(i).setBadbattFlag(badbattFlag);
                }
            }
            //查询停电续航时间
            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, "指定站点详情");
        }
    }
}