|
|
@@ -11,6 +11,7 @@ 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.enums.iot.VideoIntegrityStatus;
|
|
|
import com.xunmei.common.core.utils.DateUtils;
|
|
|
import com.xunmei.mediator.api.mapper.VideoIntegrityCheckMapper;
|
|
|
import com.xunmei.mediator.api.service.*;
|
|
|
@@ -26,7 +27,15 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
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>
|
|
|
@@ -52,6 +61,7 @@ public class VideoIntegrityCheckServiceImpl extends ServiceImpl<VideoIntegrityCh
|
|
|
IIotDeviceService iIotDeviceService;
|
|
|
@Resource
|
|
|
IIotDvrChannelService dvrChannelService;
|
|
|
+
|
|
|
@Override
|
|
|
public ReceiveErrorDto saveData(VideoIntegrityCheckDto videoIntegrityCheckDto, String msgId, String branchId) {
|
|
|
String msg = this.checkParam(videoIntegrityCheckDto);
|
|
|
@@ -60,7 +70,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 +81,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, "通道/设备不存在");
|
|
|
@@ -85,10 +95,13 @@ public class VideoIntegrityCheckServiceImpl extends ServiceImpl<VideoIntegrityCh
|
|
|
MediatorVideoIntegrityCheck videoIntegrityCheck = new MediatorVideoIntegrityCheck();
|
|
|
if (old != null) {
|
|
|
videoIntegrityCheck = old;
|
|
|
+ videoIntegrityCheck.setUpdateTime(new Date());
|
|
|
+ } else {
|
|
|
+ videoIntegrityCheck.setCreateTime(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 +119,40 @@ 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);
|
|
|
|
|
|
return ReceiveErrorDto.success();
|
|
|
}
|
|
|
|
|
|
+ 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,10 +177,10 @@ 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();
|
|
|
|
|
|
}
|
|
|
|