|
|
@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.xunmei.common.core.constant.Constants;
|
|
|
import com.xunmei.common.core.constant.SecurityConstants;
|
|
|
@@ -11,6 +12,8 @@ import com.xunmei.common.core.domain.iot.domain.IotDevice;
|
|
|
import com.xunmei.common.core.domain.iot.domain.IotDvrChannel;
|
|
|
import com.xunmei.common.core.domain.video.MediatorVideoDaysCheck;
|
|
|
import com.xunmei.common.core.domain.video.MediatorVideoIntegrityCheck;
|
|
|
+import com.xunmei.common.core.domain.video.MediatorVideoIntegrityCheckLog;
|
|
|
+import com.xunmei.common.core.enums.iot.VideoIntegrityStatus;
|
|
|
import com.xunmei.common.core.utils.DateUtils;
|
|
|
import com.xunmei.mediator.api.mapper.VideoIntegrityCheckMapper;
|
|
|
import com.xunmei.mediator.api.service.*;
|
|
|
@@ -23,10 +26,19 @@ import com.xunmei.system.api.RemoteOrgService;
|
|
|
import com.xunmei.system.api.domain.SysOrg;
|
|
|
import io.netty.util.internal.StringUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import static org.apache.tomcat.util.json.JSONParserConstants.ZERO;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
@@ -49,9 +61,12 @@ public class VideoIntegrityCheckServiceImpl extends ServiceImpl<VideoIntegrityCh
|
|
|
@Resource
|
|
|
IVideoDaysCheckService videoDaysCheckService;
|
|
|
@Resource
|
|
|
+ MediatorVideoIntegrityCheckLogService integrityCheckLogService;
|
|
|
+ @Resource
|
|
|
IIotDeviceService iIotDeviceService;
|
|
|
@Resource
|
|
|
IIotDvrChannelService dvrChannelService;
|
|
|
+
|
|
|
@Override
|
|
|
public ReceiveErrorDto saveData(VideoIntegrityCheckDto videoIntegrityCheckDto, String msgId, String branchId) {
|
|
|
String msg = this.checkParam(videoIntegrityCheckDto);
|
|
|
@@ -60,7 +75,7 @@ public class VideoIntegrityCheckServiceImpl extends ServiceImpl<VideoIntegrityCh
|
|
|
}
|
|
|
//与上次接收到的数据进行比较,如果相同则不进行处理
|
|
|
if (redisUtil.compareWithCache(videoIntegrityCheckDto)) {
|
|
|
- return ReceiveErrorDto.error(RedisKey.REPORT_DATA_REFUSE_MSG);
|
|
|
+ // return ReceiveErrorDto.error(RedisKey.REPORT_DATA_REFUSE_MSG);
|
|
|
}
|
|
|
|
|
|
String organizationGuid = videoIntegrityCheckDto.getOrganizationGuid();
|
|
|
@@ -71,7 +86,7 @@ public class VideoIntegrityCheckServiceImpl extends ServiceImpl<VideoIntegrityCh
|
|
|
northErrorService.saveError(error);
|
|
|
return ReceiveErrorDto.success();
|
|
|
}
|
|
|
- final IotDvrChannel channel = dvrChannelService.findChannel(videoIntegrityCheckDto.getChannelCode(), videoIntegrityCheckDto.getEquipmentCode(), org.getId());
|
|
|
+ final IotDvrChannel channel = dvrChannelService.findChannel(videoIntegrityCheckDto.getChannelCode(), videoIntegrityCheckDto.getEquipmentCode(), org.getId());
|
|
|
if (ObjectUtil.isNull(channel)) {
|
|
|
NorthError error = new NorthError(msgId, branchId, "/video/complete"
|
|
|
, videoIntegrityCheckDto, "通道/设备不存在");
|
|
|
@@ -79,16 +94,18 @@ public class VideoIntegrityCheckServiceImpl extends ServiceImpl<VideoIntegrityCh
|
|
|
return ReceiveErrorDto.success();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- final Date recordDate = DateUtil.parse(videoIntegrityCheckDto.getRecordDate());
|
|
|
- MediatorVideoIntegrityCheck old = this.findByOrgIdAndEquipmentCodeAndAndChannelCodeAndRecordDate(org.getId(), videoIntegrityCheckDto.getEquipmentCode(), videoIntegrityCheckDto.getChannelCode(), recordDate);
|
|
|
+ MediatorVideoIntegrityCheck old = this.findByOrgIdAndEquipmentCodeAndAndChannelCodeAndRecordDate(org.getId(), videoIntegrityCheckDto.getEquipmentCode(), videoIntegrityCheckDto.getChannelCode());
|
|
|
MediatorVideoIntegrityCheck videoIntegrityCheck = new MediatorVideoIntegrityCheck();
|
|
|
if (old != null) {
|
|
|
videoIntegrityCheck = old;
|
|
|
+ videoIntegrityCheck.setUpdateTime(new Date());
|
|
|
+ } else {
|
|
|
+ videoIntegrityCheck.setCreateTime(new Date());
|
|
|
+ videoIntegrityCheck.setUpdateTime(new Date());
|
|
|
}
|
|
|
|
|
|
//获取监控主机
|
|
|
- IotDevice hostDevice = iIotDeviceService.findByHostCode(videoIntegrityCheckDto.getEquipmentCode(),org.getId());
|
|
|
+ IotDevice hostDevice = iIotDeviceService.findByHostCode(videoIntegrityCheckDto.getEquipmentCode(), org.getId());
|
|
|
if (hostDevice != null) {
|
|
|
videoIntegrityCheck.setEquipmentName(hostDevice.getEquipmentName());
|
|
|
}
|
|
|
@@ -106,24 +123,57 @@ public class VideoIntegrityCheckServiceImpl extends ServiceImpl<VideoIntegrityCh
|
|
|
videoIntegrityCheck.setPlanDays(30);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- videoIntegrityCheck.setUpdateTime(new Date());
|
|
|
- videoIntegrityCheck.setDeviceName(channel.getChannelName());
|
|
|
videoIntegrityCheck.setChannelCode(videoIntegrityCheckDto.getChannelCode());
|
|
|
videoIntegrityCheck.setChannelName(videoIntegrityCheckDto.getChannelName());
|
|
|
videoIntegrityCheck.setCheckSpan(JSON.toJSONString(videoIntegrityCheckDto.getCheckSpan()));
|
|
|
videoIntegrityCheck.setEquipmentCode(videoIntegrityCheckDto.getEquipmentCode());
|
|
|
videoIntegrityCheck.setLoseSpan(JSON.toJSONString(videoIntegrityCheckDto.getLoseSpan()));
|
|
|
- videoIntegrityCheck.setRecordDate(DateUtils.toLocalDate(DateUtil.parse(videoIntegrityCheckDto.getRecordDate(), "yyyy-MM-dd")));
|
|
|
+ videoIntegrityCheck.setRecordDate(LocalDate.parse(videoIntegrityCheckDto.getRecordDate(), DateTimeFormatter.ISO_LOCAL_DATE));
|
|
|
videoIntegrityCheck.setOrgId(org.getId());
|
|
|
- videoIntegrityCheck.setOrgName(org.getName());
|
|
|
+ videoIntegrityCheck.setOrgName(org.getShortName());
|
|
|
videoIntegrityCheck.setOrgPath(org.getPath());
|
|
|
videoIntegrityCheck.setStatus(getStatus(videoIntegrityCheckDto));
|
|
|
+ videoIntegrityCheck.setLoseDuration(calculateLoseMinute(videoIntegrityCheck.getLoseSpan()));
|
|
|
this.saveOrUpdate(videoIntegrityCheck);
|
|
|
+ saveLog(videoIntegrityCheck);
|
|
|
|
|
|
return ReceiveErrorDto.success();
|
|
|
}
|
|
|
|
|
|
+ private void saveLog(MediatorVideoIntegrityCheck videoIntegrityCheck) {
|
|
|
+ MediatorVideoIntegrityCheckLog newLog = new MediatorVideoIntegrityCheckLog();
|
|
|
+ MediatorVideoIntegrityCheckLog logData = integrityCheckLogService.findByOrgIdAndEquipmentCodeAndChannelCode(videoIntegrityCheck.getOrgId(), videoIntegrityCheck.getEquipmentCode(), videoIntegrityCheck.getChannelCode(), videoIntegrityCheck.getRecordDate());
|
|
|
+
|
|
|
+ if (logData != null) {
|
|
|
+ BeanUtils.copyProperties(videoIntegrityCheck,logData,"id");
|
|
|
+ integrityCheckLogService.updateById(logData);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(videoIntegrityCheck,newLog);
|
|
|
+ newLog.setId(IdWorker.getId());
|
|
|
+ newLog.setVideoIntegrityCheckId(videoIntegrityCheck.getId());
|
|
|
+ integrityCheckLogService.save(newLog);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private Integer calculateLoseMinute(String loseSpan) {
|
|
|
+ if (ObjectUtil.isEmpty(loseSpan)) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ final List<Map> mapList = JSON.parseArray(loseSpan, Map.class);
|
|
|
+ int min = 0;
|
|
|
+ for (Map map : mapList) {
|
|
|
+ final String st = (String) map.get("st");
|
|
|
+ final String et = (String) map.get("et");
|
|
|
+ final LocalTime startTime = LocalTime.parse(st);
|
|
|
+ final LocalTime endTime = LocalTime.parse(et);
|
|
|
+ final long l = ChronoUnit.MINUTES.between(startTime, endTime);
|
|
|
+ min += l;
|
|
|
+
|
|
|
+ }
|
|
|
+ return min;
|
|
|
+ }
|
|
|
+
|
|
|
private String checkParam(VideoIntegrityCheckDto videoIntegrityCheckDto) {
|
|
|
if (StringUtils.isEmpty(videoIntegrityCheckDto.getOrganizationGuid())) {
|
|
|
return "organizationGuid 为空";
|
|
|
@@ -148,21 +198,20 @@ public class VideoIntegrityCheckServiceImpl extends ServiceImpl<VideoIntegrityCh
|
|
|
}
|
|
|
|
|
|
private Integer getStatus(VideoIntegrityCheckDto videoIntegrityCheckDto) {
|
|
|
- if (ObjectUtil.isEmpty(videoIntegrityCheckDto.getLoseSpan())) return 0;
|
|
|
+ if (ObjectUtil.isEmpty(videoIntegrityCheckDto.getLoseSpan())) return VideoIntegrityStatus.Full.getId();
|
|
|
String checkSpanStr = JSON.toJSONString(videoIntegrityCheckDto.getCheckSpan());
|
|
|
String loseSpanStr = JSON.toJSONString(videoIntegrityCheckDto.getLoseSpan());
|
|
|
- return checkSpanStr.equals(loseSpanStr) ? 2 : 1;
|
|
|
+ return checkSpanStr.equals(loseSpanStr) ? VideoIntegrityStatus.AllLoss.getId() : VideoIntegrityStatus.PartialLoss.getId();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public MediatorVideoIntegrityCheck findByOrgIdAndEquipmentCodeAndAndChannelCodeAndRecordDate(Long orgId, String equipmentCode, String channelCode, Date recordDate) {
|
|
|
+ public MediatorVideoIntegrityCheck findByOrgIdAndEquipmentCodeAndAndChannelCodeAndRecordDate(Long orgId, String equipmentCode, String channelCode) {
|
|
|
LambdaQueryWrapper<MediatorVideoIntegrityCheck> qw = new LambdaQueryWrapper<>();
|
|
|
qw.eq(MediatorVideoIntegrityCheck::getOrgId, orgId);
|
|
|
qw.eq(MediatorVideoIntegrityCheck::getEquipmentCode, equipmentCode);
|
|
|
qw.eq(MediatorVideoIntegrityCheck::getChannelCode, channelCode);
|
|
|
- qw.eq(MediatorVideoIntegrityCheck::getRecordDate, recordDate);
|
|
|
qw.last(Constants.LIMIT1);
|
|
|
return baseMapper.selectOne(qw);
|
|
|
}
|