|
@@ -2,19 +2,27 @@ package com.usky.sas.service.impl;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
+import com.usky.common.core.bean.CommonPage;
|
|
|
import com.usky.sas.domain.SasCollectionEvent;
|
|
import com.usky.sas.domain.SasCollectionEvent;
|
|
|
import com.usky.sas.domain.SasDevice;
|
|
import com.usky.sas.domain.SasDevice;
|
|
|
|
|
+import com.usky.sas.domain.SasSnapEvent;
|
|
|
import com.usky.sas.mapper.SasCollectionEventMapper;
|
|
import com.usky.sas.mapper.SasCollectionEventMapper;
|
|
|
import com.usky.sas.mapper.SasDeviceMapper;
|
|
import com.usky.sas.mapper.SasDeviceMapper;
|
|
|
|
|
+import com.usky.sas.mapper.SasSnapEventMapper;
|
|
|
import com.usky.sas.service.SasHomepageService;
|
|
import com.usky.sas.service.SasHomepageService;
|
|
|
|
|
+import com.usky.sas.service.SasIntelligentService;
|
|
|
import com.usky.sas.service.vo.HomepageInfoResponse;
|
|
import com.usky.sas.service.vo.HomepageInfoResponse;
|
|
|
|
|
+import com.usky.sas.service.vo.IntelligentEventItem;
|
|
|
|
|
+import com.usky.sas.service.vo.IntelligentEventPageRequest;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.LocalTime;
|
|
import java.time.LocalTime;
|
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
import java.time.temporal.ChronoUnit;
|
|
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
@@ -27,6 +35,12 @@ public class SasHomepageServiceImpl implements SasHomepageService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private SasCollectionEventMapper sasCollectionEventMapper;
|
|
private SasCollectionEventMapper sasCollectionEventMapper;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private SasSnapEventMapper sasSnapEventMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private SasIntelligentService sasIntelligentService;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public HomepageInfoResponse getHomepageInfo() {
|
|
public HomepageInfoResponse getHomepageInfo() {
|
|
|
List<SasDevice> devices = sasDeviceMapper.selectList(Wrappers.lambdaQuery());
|
|
List<SasDevice> devices = sasDeviceMapper.selectList(Wrappers.lambdaQuery());
|
|
@@ -49,9 +63,29 @@ public class SasHomepageServiceImpl implements SasHomepageService {
|
|
|
stat.setAlarmEvents(todayEvents);
|
|
stat.setAlarmEvents(todayEvents);
|
|
|
|
|
|
|
|
resp.setStatistics(stat);
|
|
resp.setStatistics(stat);
|
|
|
|
|
+
|
|
|
|
|
+ // 左下角:服务器信息与资源使用情况
|
|
|
|
|
+ resp.setServerInfo(buildServerInfo());
|
|
|
|
|
+
|
|
|
return resp;
|
|
return resp;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private HomepageInfoResponse.ServerInfo buildServerInfo() {
|
|
|
|
|
+ Runtime runtime = Runtime.getRuntime();
|
|
|
|
|
+ long maxMemory = runtime.maxMemory();
|
|
|
|
|
+ long totalMemory = runtime.totalMemory();
|
|
|
|
|
+ long freeMemory = runtime.freeMemory();
|
|
|
|
|
+ long usedMemory = totalMemory - freeMemory;
|
|
|
|
|
+
|
|
|
|
|
+ HomepageInfoResponse.ServerInfo serverInfo = new HomepageInfoResponse.ServerInfo();
|
|
|
|
|
+ serverInfo.setMemoryMaxMb(maxMemory == Long.MAX_VALUE ? null : maxMemory / (1024 * 1024));
|
|
|
|
|
+ serverInfo.setMemoryUsedMb(usedMemory / (1024 * 1024));
|
|
|
|
|
+ serverInfo.setMemoryFreeMb(freeMemory / (1024 * 1024));
|
|
|
|
|
+ serverInfo.setAvailableProcessors(runtime.availableProcessors());
|
|
|
|
|
+ serverInfo.setServerTime(LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
|
|
|
|
|
+ return serverInfo;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private HomepageInfoResponse.CameraItem toCameraItem(SasDevice d) {
|
|
private HomepageInfoResponse.CameraItem toCameraItem(SasDevice d) {
|
|
|
HomepageInfoResponse.CameraItem c = new HomepageInfoResponse.CameraItem();
|
|
HomepageInfoResponse.CameraItem c = new HomepageInfoResponse.CameraItem();
|
|
|
c.setId(d.getId());
|
|
c.setId(d.getId());
|
|
@@ -72,5 +106,55 @@ public class SasHomepageServiceImpl implements SasHomepageService {
|
|
|
long seconds = ChronoUnit.SECONDS.between(d.getTriggerTime(), LocalDateTime.now());
|
|
long seconds = ChronoUnit.SECONDS.between(d.getTriggerTime(), LocalDateTime.now());
|
|
|
return seconds <= 60;
|
|
return seconds <= 60;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public CommonPage<IntelligentEventItem> getEventList(IntelligentEventPageRequest request) {
|
|
|
|
|
+ return sasIntelligentService.queryEvents(request);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<IntelligentEventItem> getRealtimeNotificationEvents() {
|
|
|
|
|
+ LambdaQueryWrapper<SasSnapEvent> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapper.eq(SasSnapEvent::getNotify, true);
|
|
|
|
|
+ wrapper.orderByDesc(SasSnapEvent::getTriggerTime);
|
|
|
|
|
+ wrapper.last("LIMIT 20");
|
|
|
|
|
+ List<SasSnapEvent> list = sasSnapEventMapper.selectList(wrapper);
|
|
|
|
|
+ if (list == null) {
|
|
|
|
|
+ return Collections.emptyList();
|
|
|
|
|
+ }
|
|
|
|
|
+ return list.stream().map(this::snapToEventItem).collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public CommonPage<IntelligentEventItem> getAlertHistory(HomepageAlertHistoryRequest request) {
|
|
|
|
|
+ if (!"snap".equals(request.getEventType())) {
|
|
|
|
|
+ return new CommonPage<>(Collections.emptyList(), 0L, request.getPage().longValue(), request.getPageSize().longValue());
|
|
|
|
|
+ }
|
|
|
|
|
+ com.baomidou.mybatisplus.extension.plugins.pagination.Page<SasSnapEvent> page =
|
|
|
|
|
+ new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(request.getPage(), request.getPageSize());
|
|
|
|
|
+ LambdaQueryWrapper<SasSnapEvent> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapper.eq(SasSnapEvent::getNotify, true);
|
|
|
|
|
+ wrapper.orderByDesc(SasSnapEvent::getTriggerTime);
|
|
|
|
|
+ page = sasSnapEventMapper.selectPage(page, wrapper);
|
|
|
|
|
+ List<IntelligentEventItem> list = (page.getRecords() == null ? Collections.emptyList() : page.getRecords())
|
|
|
|
|
+ .stream().map(this::snapToEventItem).collect(Collectors.toList());
|
|
|
|
|
+ return new CommonPage<>(list, page.getTotal(), page.getCurrent(), page.getSize());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private IntelligentEventItem snapToEventItem(SasSnapEvent e) {
|
|
|
|
|
+ IntelligentEventItem item = new IntelligentEventItem();
|
|
|
|
|
+ item.setEventId(e.getEventId());
|
|
|
|
|
+ item.setDeviceId(e.getDeviceId());
|
|
|
|
|
+ item.setChannel(e.getChannel());
|
|
|
|
|
+ item.setTriggerTime(e.getTriggerTime());
|
|
|
|
|
+ item.setEventCode(e.getEventCode());
|
|
|
|
|
+ item.setScenePicId(e.getScenePicId());
|
|
|
|
|
+ item.setEventPicId(e.getEventPicId());
|
|
|
|
|
+ item.setSimilarity(e.getSimilarity());
|
|
|
|
|
+ item.setPersonCode(e.getPersonCode());
|
|
|
|
|
+ item.setNotify(e.getNotify());
|
|
|
|
|
+ item.setScene(e.getScene());
|
|
|
|
|
+ return item;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|