|
|
@@ -1,23 +1,33 @@
|
|
|
package com.xunmei.iot.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.date.DateField;
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.xunmei.common.core.constant.CacheConstants;
|
|
|
import com.xunmei.common.core.constant.SecurityConstants;
|
|
|
+import com.xunmei.common.core.domain.iot.domain.IotDvrHardDiskDetectionLog;
|
|
|
import com.xunmei.common.core.domain.iot.domain.IotSensor;
|
|
|
import com.xunmei.common.core.domain.mediator.domain.IotAlarmData;
|
|
|
+import com.xunmei.common.core.domain.video.MediatorVideoIntegrityCheckLog;
|
|
|
import com.xunmei.common.core.enums.CategoryDataEnum;
|
|
|
import com.xunmei.common.core.enums.iot.SensorType;
|
|
|
import com.xunmei.common.core.exception.ServiceException;
|
|
|
import com.xunmei.common.core.thread.ThreadPoolConfig;
|
|
|
+import com.xunmei.common.core.utils.DateUtils;
|
|
|
import com.xunmei.common.redis.utils.RedisUtils;
|
|
|
import com.xunmei.common.security.utils.SecurityUtils;
|
|
|
import com.xunmei.iot.mapper.IotBoardMapper;
|
|
|
-import com.xunmei.iot.mapper.VideoIntegrityCheckMapper;
|
|
|
+import com.xunmei.iot.mapper.IotDvrChannelMapper;
|
|
|
+import com.xunmei.iot.mapper.IotDvrDiskMapper;
|
|
|
+import com.xunmei.iot.mapper.IotDvrHardDiskDetectionLogMapper;
|
|
|
import com.xunmei.iot.service.IIotCommonSensorService;
|
|
|
import com.xunmei.iot.service.IotAlarmDataService;
|
|
|
import com.xunmei.iot.service.IotBoardService;
|
|
|
+import com.xunmei.iot.service.VideoDiagnosisService;
|
|
|
import com.xunmei.iot.vo.alarmData.AppAlarmDataPageVo;
|
|
|
import com.xunmei.iot.vo.board.IotBoardOverviewItemVo;
|
|
|
import com.xunmei.iot.vo.board.IotBoardOverviewVo;
|
|
|
@@ -48,6 +58,10 @@ public class IotBoardServiceImpl implements IotBoardService {
|
|
|
|
|
|
@Autowired
|
|
|
IotBoardMapper iotBoardMapper;
|
|
|
+ @Autowired
|
|
|
+ IotDvrChannelMapper dvrChannelMapper;
|
|
|
+ @Autowired
|
|
|
+ VideoDiagnosisService videoDiagnosisService;
|
|
|
|
|
|
@Autowired
|
|
|
@Qualifier(ThreadPoolConfig.SOC_EXECUTOR)
|
|
|
@@ -59,7 +73,9 @@ public class IotBoardServiceImpl implements IotBoardService {
|
|
|
IotAlarmDataService alarmDataService;
|
|
|
|
|
|
@Resource
|
|
|
- VideoIntegrityCheckMapper videoIntegrityCheckMapper;
|
|
|
+ IotDvrHardDiskDetectionLogMapper dvrHardDiskDetectionLogMapper;
|
|
|
+ @Resource
|
|
|
+ IotDvrDiskMapper iotDvrDiskMapper;
|
|
|
|
|
|
private final Long TIMEOUT = 3L;
|
|
|
|
|
|
@@ -281,6 +297,8 @@ public class IotBoardServiceImpl implements IotBoardService {
|
|
|
final String MAP_VALUE = "nums";
|
|
|
final String DEVICE_TYPE = "deviceType";
|
|
|
final String CATEGORY_ID = "categoryId";
|
|
|
+ Date now = new Date();
|
|
|
+ final Integer channelDataOffsetDay = 30;
|
|
|
SysUser sysUser = SecurityUtils.getLoginUser().getSysUser();
|
|
|
|
|
|
List<SysOrgVO> cacheList = RedisUtils.getCacheList(CacheConstants.ORG_CACHE_LIST_KEY);
|
|
|
@@ -350,10 +368,8 @@ public class IotBoardServiceImpl implements IotBoardService {
|
|
|
}
|
|
|
totalData.setSensorDetails(sensorDataList);
|
|
|
//录像文件自检
|
|
|
- List<Map<String, String>> videoCheckSelfMap = iotBoardMapper.selectVideoCheckSelf(orgPath, new Date());
|
|
|
- IotBoardTotalData.VideoInspection videoInspection = new IotBoardTotalData.VideoInspection();
|
|
|
- videoCheckSelfMap.stream().filter(m -> ObjectUtil.equal("video", m.get(DEVICE_TYPE))).findAny().ifPresent(m -> videoInspection.setLostRate(m.get(MAP_VALUE) + "%"));
|
|
|
- videoCheckSelfMap.stream().filter(m -> ObjectUtil.equal("disk", m.get(DEVICE_TYPE))).findAny().ifPresent(m -> videoInspection.setHardDiskExceptionRate(m.get(MAP_VALUE) + "%"));
|
|
|
+ this.selectVideoCheckSelf(orgVO, now, totalData, channelDataOffsetDay);
|
|
|
+
|
|
|
|
|
|
//录像天数存储
|
|
|
List<Map<String, String>> videoCheckMap = iotBoardMapper.selectVideoDaysStorage(orgPath, new Date());
|
|
|
@@ -363,8 +379,100 @@ public class IotBoardServiceImpl implements IotBoardService {
|
|
|
}
|
|
|
IotBoardTotalData.RecordingStorage storage = new IotBoardTotalData.RecordingStorage();
|
|
|
storage.setHashmap(hashMap);
|
|
|
+
|
|
|
+ IotBoardTotalData.VideoDiagnostic videoDiagnostic = videoDiagnosisService.selectVideoDiagnostic(orgPath, now, channelDataOffsetDay);
|
|
|
+ totalData.setVideoDiagnostic(videoDiagnostic);
|
|
|
+
|
|
|
return totalData;
|
|
|
}
|
|
|
|
|
|
+ private void selectVideoCheckSelf(SysOrgVO org, Date now, IotBoardTotalData totalData, Integer channelDataOffsetDay) {
|
|
|
+ // 通道数*丢失天数 / 通道数*计算时长(天)=录像文件丢失率
|
|
|
+ IotBoardTotalData.VideoInspection videoInspection = new IotBoardTotalData.VideoInspection();
|
|
|
+ totalData.setVideoInspection(videoInspection);
|
|
|
+ //获取查询时间范围的最小值
|
|
|
+ DateTime offsetDay = DateUtil.offsetDay(now, -channelDataOffsetDay);
|
|
|
+ //查询历史上报的录像完整性数据
|
|
|
+ List<MediatorVideoIntegrityCheckLog> videoIntegrityCheckLogs = iotBoardMapper.selectVideoCheckSelf(org.getPath(), DateUtil.format(offsetDay, "yyyy-MM-dd"), DateUtil.format(now, "yyyy-MM-dd"));
|
|
|
+ if (ObjectUtil.isEmpty(videoIntegrityCheckLogs)) {
|
|
|
+ videoInspection.setLostRate("-");
|
|
|
+ }
|
|
|
+ //获取通道数量
|
|
|
+ Integer channelNums = dvrChannelMapper.selectChannelCount(org.getPath());
|
|
|
+ //通道数量*需要计算的丢失天数=计算分母
|
|
|
+ int total = channelNums * channelDataOffsetDay;
|
|
|
+ //根据主机code和通道code分组
|
|
|
+ Map<String, List<MediatorVideoIntegrityCheckLog>> listMap = videoIntegrityCheckLogs.stream().collect(Collectors.groupingBy(m -> m.getEquipmentCode() + "_" + m.getChannelCode()));
|
|
|
+ //获取时间范围的每一天时间
|
|
|
+ List<DateTime> timeList = DateUtil.rangeToList(offsetDay, now, DateField.DAY_OF_YEAR);
|
|
|
+
|
|
|
+ //计算丢失天数
|
|
|
+ int lostTotal = 0;
|
|
|
+ for (Map.Entry<String, List<MediatorVideoIntegrityCheckLog>> listEntry : listMap.entrySet()) {
|
|
|
+ List<MediatorVideoIntegrityCheckLog> list = listEntry.getValue();
|
|
|
+ //每个通道丢失的时间,未上报也计为丢失
|
|
|
+ long count = list.stream().filter(r -> !timeList.contains(new DateTime(DateUtils.toDate(r.getRecordDate()))) || r.getLoseDuration() != 0).count();
|
|
|
+ lostTotal += (int) count;
|
|
|
+ }
|
|
|
+ //计算录像文件丢失率
|
|
|
+ if (total == 0) {
|
|
|
+ videoInspection.setLostRate("-");
|
|
|
+ } else {
|
|
|
+ videoInspection.setLostRate(String.format("%.2f", (lostTotal * 100.0 / total)) + "%");
|
|
|
+ }
|
|
|
+
|
|
|
+ //硬盘异常率
|
|
|
+ //获取硬盘数量
|
|
|
+ int diskNum = iotDvrDiskMapper.selectDiskCount(org.getPath());
|
|
|
+ //获取历史上报的硬盘数据
|
|
|
+ List<IotDvrHardDiskDetectionLog> logList = dvrHardDiskDetectionLogMapper.selectData(org.getPath(), DateUtil.format(offsetDay, "yyyy-MM-dd"), DateUtil.format(now, "yyyy-MM-dd"));
|
|
|
+
|
|
|
+ if (ObjectUtil.isEmpty(logList)) {
|
|
|
+ videoInspection.setHardDiskExceptionRate("-");
|
|
|
+ }
|
|
|
+
|
|
|
+ int diskTotal = diskNum * channelDataOffsetDay;
|
|
|
+ //硬盘正常数量
|
|
|
+ int diskExitTotal = 0;
|
|
|
+ //把硬盘检测数据根据主机code分组
|
|
|
+ Map<String, List<IotDvrHardDiskDetectionLog>> diskListmap = logList.stream().collect(Collectors.groupingBy(IotDvrHardDiskDetectionLog::getEquipmentCode));
|
|
|
+ for (Map.Entry<String, List<IotDvrHardDiskDetectionLog>> listEntry : diskListmap.entrySet()) {
|
|
|
+
|
|
|
+ //拿到每个主机下上报的硬盘检测数据
|
|
|
+ List<IotDvrHardDiskDetectionLog> detectionLogs = listEntry.getValue();
|
|
|
+
|
|
|
+ //循环每一天
|
|
|
+ for (DateTime time : timeList) {
|
|
|
+
|
|
|
+ //判断当天是否上报
|
|
|
+ Optional<IotDvrHardDiskDetectionLog> first = detectionLogs.stream().filter(r -> DateUtils.isSameDay(time, DateUtils.toDate(r.getCreateTime()))).findFirst();
|
|
|
+ if (!first.isPresent()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ IotDvrHardDiskDetectionLog detectionLog = first.get();
|
|
|
+ String detailInfo = detectionLog.getDetailInfo();
|
|
|
+ if (ObjectUtil.isEmpty(detailInfo)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //获取上报数据详情
|
|
|
+ List<Map> maps = JSON.parseArray(detailInfo, Map.class);
|
|
|
+
|
|
|
+ //统计上报数据中正常的硬盘数量
|
|
|
+ long count = maps.stream().filter(d -> ObjectUtil.equal(d.get("state").toString(), "0")).count();
|
|
|
+ //硬盘正常数量累加
|
|
|
+ diskExitTotal += (int) count;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (diskTotal == 0) {
|
|
|
+ videoInspection.setHardDiskExceptionRate("-");
|
|
|
+ } else {
|
|
|
+ //用计算分母减去正常硬盘数量=异常硬盘数; 用异常硬盘数/计算分母得到异常率
|
|
|
+ videoInspection.setHardDiskExceptionRate(String.format("%.2f", ((diskTotal - diskExitTotal) * 100.0 / diskTotal)) + "%");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|