|
|
@@ -1,7 +1,12 @@
|
|
|
package com.hfln.portal.infrastructure.gateway.impl;
|
|
|
|
|
|
+import com.hfln.portal.common.dto.data.event.EventStatDto;
|
|
|
+import com.hfln.portal.common.dto.data.stat.MonitorAnalyseDTO;
|
|
|
import com.hfln.portal.common.dto.data.stat.ScreenStatsV2DTO;
|
|
|
+import com.hfln.portal.common.request.event.EventStatParams;
|
|
|
import com.hfln.portal.domain.gateway.WebStatsV2Gateway;
|
|
|
+import com.hfln.portal.infrastructure.po.EventList;
|
|
|
+import com.hfln.portal.infrastructure.po.Events;
|
|
|
import com.hfln.portal.infrastructure.service.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -9,6 +14,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
@@ -17,7 +23,6 @@ import java.util.Map;
|
|
|
@Service
|
|
|
public class WebStatsV2GatewayImpl implements WebStatsV2Gateway {
|
|
|
|
|
|
-
|
|
|
@Autowired
|
|
|
private DevInfoService devInfoService;
|
|
|
|
|
|
@@ -30,6 +35,12 @@ public class WebStatsV2GatewayImpl implements WebStatsV2Gateway {
|
|
|
@Autowired
|
|
|
private AdminUserService adminuserService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private EventsService eventsService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EventListService eventListService;
|
|
|
+
|
|
|
@Override
|
|
|
public ScreenStatsV2DTO queryScreenV2() {
|
|
|
ScreenStatsV2DTO res = new ScreenStatsV2DTO();
|
|
|
@@ -86,6 +97,104 @@ public class WebStatsV2GatewayImpl implements WebStatsV2Gateway {
|
|
|
res.setUserDistributionList(userDistributionList);
|
|
|
return res;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<EventStatDto> alarmEventsQuery(EventStatParams params) {
|
|
|
+
|
|
|
+ List<EventStatDto> res = new ArrayList<>();
|
|
|
+ // 查询 跌倒事件
|
|
|
+ List<EventList> eventLists = eventListService.queryList(params);
|
|
|
+ if (!CollectionUtils.isEmpty(eventLists)) {
|
|
|
+ List<EventStatDto> res1 = new ArrayList<>();
|
|
|
+ eventLists.forEach(events -> {
|
|
|
+ EventStatDto eventStatDto = new EventStatDto();
|
|
|
+ eventStatDto.setEventName(null);
|
|
|
+ eventStatDto.setDevId(events.getDevId());
|
|
|
+ eventStatDto.setDevName(null);
|
|
|
+ eventStatDto.setEventType("fall");
|
|
|
+ eventStatDto.setIsHandle(events.getIsHandle());
|
|
|
+ eventStatDto.setUpdateTime(events.getUpdateTime());
|
|
|
+ res1.add(eventStatDto);
|
|
|
+ });
|
|
|
+ devInfoService.fillDevNamesByDevId(res1, EventStatDto::getDevId, EventStatDto::setDevName, EventStatDto::setClientId);
|
|
|
+ res.addAll(res1);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询 告警事件
|
|
|
+ List<Events> eventsList = eventsService.queryList(params);
|
|
|
+ if (!CollectionUtils.isEmpty(eventsList)) {
|
|
|
+ List<EventStatDto> res2 = new ArrayList<>();
|
|
|
+ eventsList.forEach(events -> {
|
|
|
+ EventStatDto eventStatDto = new EventStatDto();
|
|
|
+ eventStatDto.setEventName(null);
|
|
|
+ eventStatDto.setClientId(events.getClientId());
|
|
|
+ eventStatDto.setDevName(null);
|
|
|
+ eventStatDto.setEventType("alarm");
|
|
|
+ eventStatDto.setIsHandle(events.getIsHandle());
|
|
|
+ eventStatDto.setUpdateTime(events.getUpdateTime());
|
|
|
+ res2.add(eventStatDto);
|
|
|
+ });
|
|
|
+ devInfoService.fillDevNames(res2, EventStatDto::getClientId, EventStatDto::setDevName);
|
|
|
+ res.addAll(res2);
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public MonitorAnalyseDTO monitorAnalyse() {
|
|
|
+
|
|
|
+ MonitorAnalyseDTO res = new MonitorAnalyseDTO();
|
|
|
+ res.setQuarterStatInfos(new ArrayList<>());
|
|
|
+ // 跌倒事件统计
|
|
|
+
|
|
|
+ int year = LocalDate.now().getYear();
|
|
|
+ // 第一季度
|
|
|
+ LocalDate startDate = LocalDate.of(year, 1, 1);
|
|
|
+ LocalDate endDate = LocalDate.of(year, 3, 31).plusDays(1);
|
|
|
+ res.getQuarterStatInfos().add(queryQuarterStatInfo(startDate, endDate, year + "第一季度"));
|
|
|
+
|
|
|
+ // 第二季度
|
|
|
+ startDate = LocalDate.of(year, 4, 1);
|
|
|
+ endDate = LocalDate.of(year, 6, 30).plusDays(1);
|
|
|
+ res.getQuarterStatInfos().add(queryQuarterStatInfo(startDate, endDate, year + "第二季度"));
|
|
|
+
|
|
|
+ // 第三季度
|
|
|
+ startDate = LocalDate.of(year, 7, 1);
|
|
|
+ endDate = LocalDate.of(year, 9, 30).plusDays(1);
|
|
|
+ res.getQuarterStatInfos().add(queryQuarterStatInfo(startDate, endDate, year + "第三季度"));
|
|
|
+
|
|
|
+ // 第四季度
|
|
|
+ startDate = LocalDate.of(year, 10, 1);
|
|
|
+ endDate = LocalDate.of(year, 12, 31).plusDays(1);
|
|
|
+ res.getQuarterStatInfos().add(queryQuarterStatInfo(startDate, endDate, year + "第四季度"));
|
|
|
+
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ private MonitorAnalyseDTO.QuarterStatInfo queryQuarterStatInfo(LocalDate startDate, LocalDate endDate, String quarter) {
|
|
|
+
|
|
|
+ MonitorAnalyseDTO.QuarterStatInfo firstQuarter = new MonitorAnalyseDTO.QuarterStatInfo();
|
|
|
+ firstQuarter.setQuarter(quarter);
|
|
|
+ firstQuarter.setEventStats(new ArrayList<>());
|
|
|
+ // 跌倒事件统计
|
|
|
+ MonitorAnalyseDTO.EventStat fallEventStat = new MonitorAnalyseDTO.EventStat();
|
|
|
+ fallEventStat.setEventType("fall");
|
|
|
+ Map<String, BigDecimal> eventListMap = eventListService.queryByQuarter(startDate, endDate);
|
|
|
+ if (!CollectionUtils.isEmpty(eventListMap)) {
|
|
|
+ fallEventStat.setCount(eventListMap.get("fallingCount") == null ? 0 : eventListMap.get("fallingCount").intValue());
|
|
|
+ if (fallEventStat.getCount() > 0) {
|
|
|
+ fallEventStat.setHandleRate(eventListMap.get("handleCount") == null ? 0.00 : (eventListMap.get("handleCount").divide(eventListMap.get("fallingCount"), 4 ,BigDecimal.ROUND_HALF_UP)).doubleValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ firstQuarter.getEventStats().add(fallEventStat);
|
|
|
+ // 告警事件统计
|
|
|
+ MonitorAnalyseDTO.EventStat alarmEventStat = new MonitorAnalyseDTO.EventStat();
|
|
|
+ alarmEventStat.setEventType("alarm");
|
|
|
+ Long alarmCount = eventsService.queryByQuarter(startDate, endDate);
|
|
|
+ alarmEventStat.setCount(alarmCount == null ? 0 : alarmCount.intValue());
|
|
|
+ firstQuarter.getEventStats().add(alarmEventStat);
|
|
|
+ return firstQuarter;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|