whyclxw
3 天以前 ee84ce011eb1c528920c2d2057f1c7c93b45cccc
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
package com.whyc.service;
 
import com.whyc.constant.BattAlarmIdEnum;
import com.whyc.dto.NameValueIntDto;
import com.whyc.dto.Response;
import com.whyc.factory.ThreadPoolExecutorFactory;
import com.whyc.pojo.db_alarm.BattalarmData;
import com.whyc.pojo.db_ram_db.DeviceState;
import com.whyc.pojo.db_station.BattInf;
import com.whyc.pojo.db_station.StationInf;
import com.whyc.pojo.db_user.BaojigroupPower;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.stream.Collectors;
 
@Service
public class MonitorService {
 
    @Autowired
    private LeaderHomeService leaderHomeService;
 
    @Autowired
    private StationInfService stationInfService;
 
    @Autowired
    private PowerInfService powerInfService;
 
    @Autowired
    private BattInfService battInfService;
 
    @Autowired
    private PwrdevAlarmService powerAlarmService;
 
    @Autowired
    private DevalarmDataService devAlarmDataService;
 
    @Autowired
    private BattalarmDataService battAlarmDataService;
 
    @Autowired
    private DeviceStateService deviceStateService;
 
 
    @Autowired
    private BaoJiGroupPowerService baoJiGroupPowerService;
 
 
    public Response getAll(Integer userId) {
        Response response = new Response();
        Map<String,Object> map = new HashMap<>();
 
        CountDownLatch latch = new CountDownLatch(9);
        ThreadPoolExecutor poolExecutor = ThreadPoolExecutorFactory.getPoolExecutor();
 
        //TODO 交流告警统计 待明确告警分类
        poolExecutor.execute(() -> {
            //acAlarmStatistics(userId, map);
            latch.countDown();
        });
 
        //资产信息统计
        poolExecutor.execute(() -> {
            assetsInfoStatistics(userId, map);
            latch.countDown();
        });
 
        //蓄电池核容信息统计
        poolExecutor.execute(() -> {
            leaderHomeService.testDataInfoStatistics(userId, map);
            latch.countDown();
        });
 
        //电池品牌信息统计
        poolExecutor.execute(() -> {
            leaderHomeService.batteryInfoStatistics(userId, map);
            latch.countDown();
        });
 
        //电源品牌信息统计
        poolExecutor.execute(() -> {
            leaderHomeService.powerInfoStatistics(userId, map);
            latch.countDown();
        });
 
        //TODO 电源告警信息统计 待明确告警分类
        poolExecutor.execute(() -> {
            //powerAlarmStatistics(userId, map);
            latch.countDown();
        });
 
        //单节蓄电池告警统计
        poolExecutor.execute(() -> {
            battMonAlarmStatistics(userId, map);
            latch.countDown();
        });
 
        //设备实时状态统计
        poolExecutor.execute(() -> {
            deviceStatusStatistics(userId, map);
            latch.countDown();
        });
 
        //班组统计 及 告警统计
        poolExecutor.execute(() -> {
            baoJiAndAlarmStatistics(userId, map);
            latch.countDown();
        });
 
        return response;
    }
 
    private void baoJiAndAlarmStatistics(Integer userId, Map<String, Object> map) {
        List<NameValueIntDto> baoJiGroupStationDtoList = new ArrayList<>();
        //获取管理的所有班组和站点
        List<BaojigroupPower> baoJiGroupStationList =baoJiGroupPowerService.getListByUserId(userId);
        Map<String, List<BaojigroupPower>> baoJiGroupStationMap = baoJiGroupStationList.stream().collect(Collectors.groupingBy(BaojigroupPower::getBaoJiGroupName));
        baoJiGroupStationMap.forEach((baoJiGroupName, stationList) -> {
            NameValueIntDto baoJiGroupStationDto = new NameValueIntDto();
            baoJiGroupStationDto.setName(baoJiGroupName);
            baoJiGroupStationDto.setValue(stationList.size());
            baoJiGroupStationDtoList.add(baoJiGroupStationDto);
        });
        map.put("baoJiStationStatistics", baoJiGroupStationDtoList);
 
 
        List<NameValueIntDto> alarmStatisticsList = new ArrayList<>();
        long powerAlarmCount = powerAlarmService.getListByUserId(userId, 1).stream().count();
        long devAlarmCount = devAlarmDataService.getListByUserId(userId, 1).stream().count();
        long battAlarmCount = battAlarmDataService.getListByUserId(userId, 1).stream().count();
        NameValueIntDto powerAlarmDto = new NameValueIntDto("电源监测", (int) powerAlarmCount);
        alarmStatisticsList.add(powerAlarmDto);
        NameValueIntDto devAlarmDto = new NameValueIntDto("设备监测", (int) devAlarmCount);
        alarmStatisticsList.add(devAlarmDto);
        NameValueIntDto battAlarmDto = new NameValueIntDto("电池监测", (int) battAlarmCount);
        alarmStatisticsList.add(battAlarmDto);
        map.put("alarmStatistics", alarmStatisticsList);
 
 
    }
 
    private void deviceStatusStatistics(Integer userId, Map<String, Object> map) {
        List<DeviceState> deviceStateList =deviceStateService.getListByUserId(userId);
        long chargeCount = deviceStateList.stream().filter(deviceState -> deviceState.getDevWorkstate() == 0).count();
        long hrChargeCount = deviceStateList.stream().filter(deviceState -> deviceState.getDevWorkstate() == 1).count();
        long hrDischargeCount = deviceStateList.stream().filter(deviceState -> deviceState.getDevWorkstate() == 2).count();
        long powerOffDischargeCount = deviceStateList.stream().filter(deviceState -> deviceState.getDevWorkstate() == 3).count();
        long resTestCount = deviceStateList.stream().filter(deviceState -> deviceState.getDevWorkstate() == 4).count();
 
        List<NameValueIntDto> nameValueList = new ArrayList<>();
 
        NameValueIntDto chargeCountDto = new NameValueIntDto("直连充电", (int) chargeCount);
        nameValueList.add(chargeCountDto);
        NameValueIntDto hrChargeCountDto = new NameValueIntDto("核容充电", (int) hrChargeCount);
        nameValueList.add(hrChargeCountDto);
        NameValueIntDto hrDischargeCountDto = new NameValueIntDto("核容放电", (int) hrDischargeCount);
        nameValueList.add(hrDischargeCountDto);
        NameValueIntDto powerOffDischargeCountDto = new NameValueIntDto("停电放电", (int) powerOffDischargeCount);
        nameValueList.add(powerOffDischargeCountDto);
        NameValueIntDto resTestCountDto = new NameValueIntDto("内阻测试", (int) resTestCount);
        nameValueList.add(resTestCountDto);
 
        map.put("deviceStatusStatistics", nameValueList);
 
    }
 
    private void battMonAlarmStatistics(Integer userId, Map<String, Object> map) {
        List<NameValueIntDto> nameValueList = new ArrayList<>();
 
        List<BattalarmData> battAlarmDataList = battAlarmDataService.getMonAlarm(userId);
        //获取电压异常告警
        List<BattalarmData> monVolAlarmList = battAlarmDataList.stream()
                .filter(alarm -> alarm.getAlmId().intValue() == BattAlarmIdEnum.ALARM_119005.getStateId()).collect(Collectors.toList());
        Map<String, List<BattalarmData>> monVolAlarmMap = monVolAlarmList.stream().collect(
                Collectors.groupingBy(alarm -> alarm.getBattgroupId() + "_" + alarm.getMonNum()));
        nameValueList.add(new NameValueIntDto("电压", monVolAlarmMap.size()));
 
        //获取内阻异常告警
        List<BattalarmData> monResAlarmList = battAlarmDataList.stream()
                .filter(alarm -> alarm.getAlmId().intValue() == BattAlarmIdEnum.ALARM_119007.getStateId()).collect(Collectors.toList());
        Map<String, List<BattalarmData>> monResAlarmMap = monResAlarmList.stream().collect(
                Collectors.groupingBy(alarm -> alarm.getBattgroupId() + "_" + alarm.getMonNum()));
        nameValueList.add(new NameValueIntDto("内阻", monResAlarmMap.size()));
 
 
        //获取温度异常告警
        List<BattalarmData> monTmpAlarmList = battAlarmDataList.stream()
                .filter(alarm -> alarm.getAlmId().intValue() == BattAlarmIdEnum.ALARM_119006.getStateId()).collect(Collectors.toList());
        Map<String, List<BattalarmData>> monTmpAlarmMap = monTmpAlarmList.stream().collect(
                Collectors.groupingBy(alarm -> alarm.getBattgroupId() + "_" + alarm.getMonNum()));
        nameValueList.add(new NameValueIntDto("温度", monTmpAlarmMap.size()));
 
        map.put("battMonAlarmStatistics", nameValueList);
    }
 
    private void assetsInfoStatistics(Integer userId, Map<String, Object> map) {
        List<NameValueIntDto> nameValueList = new ArrayList<>();
        List<StationInf> stationInfList =stationInfService.getListByUserId(userId);
        int stationCount = stationInfList.size();
        NameValueIntDto stationCountDto = new NameValueIntDto();
        stationCountDto.setName("站点数量");
        stationCountDto.setValue(stationCount);
 
        int powerCount = powerInfService.getListByUserId(userId).size();
        NameValueIntDto powerCountDto = new NameValueIntDto();
        powerCountDto.setName("电源数量");
        powerCountDto.setValue(powerCount);
 
        List<BattInf> battInfList = battInfService.getListByUserId(userId);
        int battCount = battInfList.size();
        Map<Integer, List<BattInf>> devIdMap = battInfList.stream().collect(Collectors.groupingBy(BattInf::getDevId));
        NameValueIntDto devCountDto = new NameValueIntDto();
        devCountDto.setName("设备数量");
        devCountDto.setValue(devIdMap.size());
 
        NameValueIntDto battCountDto = new NameValueIntDto();
        battCountDto.setName("电池数量");
        battCountDto.setValue(battCount);
 
        nameValueList.add(stationCountDto);
        nameValueList.add(powerCountDto);
        nameValueList.add(devCountDto);
        nameValueList.add(battCountDto);
        map.put("assetsInfoStatistics", nameValueList);
 
    }
}