package com.ycl.task;
|
|
import com.ycl.common.constant.GlobalQueue;
|
import com.ycl.entity.video.VideoAlarmReport;
|
import com.ycl.entity.video.VideoPoint;
|
import com.ycl.service.caseHandler.IViolationsService;
|
import com.ycl.service.oss.OssService;
|
import com.ycl.service.video.IVideoAlarmReportService;
|
import com.ycl.service.video.impl.IVideoPointService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.io.ByteArrayInputStream;
|
import java.io.InputStream;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
@Component
|
public class SynchronizeDHAlarm {
|
|
@Autowired
|
private OssService ossService;
|
|
@Autowired
|
private IVideoPointService videoPointService;
|
|
@Autowired
|
private IVideoAlarmReportService videoAlarmReportService;
|
|
@Autowired
|
private IViolationsService violationsService;
|
|
@Scheduled(cron = "0 */1 * * * ?")
|
@Transactional(rollbackFor = Exception.class)
|
public void scheduledTask() {
|
|
while (GlobalQueue.size() > 0) {
|
try {
|
VideoAlarmReport videoAlarmReport = GlobalQueue.dequeue();
|
|
List<VideoAlarmReport> list = videoAlarmReportService.findByChannelAndAlarmNameAndTime(videoAlarmReport.getChannel(), videoAlarmReport.getAlarmName(), videoAlarmReport.getAlarmTime());
|
if (list.size() == 0) {
|
System.out.println("----------------开始保存报警信息:" + videoAlarmReport.getAlarmName());
|
VideoPoint videoPoint = videoPointService.getByChannelId(Integer.parseInt(videoAlarmReport.getChannel()));
|
|
if (videoPoint != null) {
|
videoAlarmReport.setPlatResourceId(videoPoint.getPlatResourceId());
|
}
|
if (videoAlarmReport.getPicByte() != null) {
|
String extension = "jpg";
|
InputStream inputStream = new ByteArrayInputStream(videoAlarmReport.getPicByte());
|
String picData = ossService.uploadImages(inputStream, extension,0);
|
|
videoAlarmReport.setPicData(picData);
|
}
|
videoAlarmReportService.save(videoAlarmReport);
|
|
List<VideoAlarmReport> videoAlarmReports = new ArrayList<>();
|
videoAlarmReports.add(videoAlarmReport);
|
violationsService.saveFromVideo(videoAlarmReports);
|
|
}
|
} catch (Exception ex) {
|
System.out.println("------------保存报警信息异常:");
|
|
}
|
}
|
}
|
}
|