|  | @@ -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,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.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;
 | 
	
	
		
			
				|  | @@ -24,6 +26,7 @@ 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;
 | 
	
	
		
			
				|  | @@ -58,6 +61,8 @@ public class VideoIntegrityCheckServiceImpl extends ServiceImpl<VideoIntegrityCh
 | 
	
		
			
				|  |  |      @Resource
 | 
	
		
			
				|  |  |      IVideoDaysCheckService videoDaysCheckService;
 | 
	
		
			
				|  |  |      @Resource
 | 
	
		
			
				|  |  | +    MediatorVideoIntegrityCheckLogService integrityCheckLogService;
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  |      IIotDeviceService iIotDeviceService;
 | 
	
		
			
				|  |  |      @Resource
 | 
	
		
			
				|  |  |      IIotDvrChannelService dvrChannelService;
 | 
	
	
		
			
				|  | @@ -89,15 +94,14 @@ 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());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          //获取监控主机
 | 
	
	
		
			
				|  | @@ -131,10 +135,27 @@ public class VideoIntegrityCheckServiceImpl extends ServiceImpl<VideoIntegrityCh
 | 
	
		
			
				|  |  |          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;
 | 
	
	
		
			
				|  | @@ -186,12 +207,11 @@ public class VideoIntegrityCheckServiceImpl extends ServiceImpl<VideoIntegrityCh
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @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);
 | 
	
		
			
				|  |  |      }
 |