New file |
| | |
| | | package com.ycl.task; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ycl.dto.video.Camera; |
| | | import com.ycl.dto.video.PageResult; |
| | | import com.ycl.entity.video.VideoPoint; |
| | | import com.ycl.service.video.impl.IVideoPointService; |
| | | import com.ycl.util.VideoUtil; |
| | | 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.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 同步海康视频 |
| | | */ |
| | | @Component |
| | | public class SynchronizeHKVideo { |
| | | |
| | | @Autowired |
| | | private IVideoPointService videoPointService; |
| | | @Autowired |
| | | private VideoUtil videoUtil; |
| | | |
| | | @Scheduled(cron = "0/1 * * * * ?") // 每秒执行 |
| | | // @Scheduled(cron = "0 0/1 * ?") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void scheduledTask() { |
| | | try { |
| | | findVideoList(1, 20); |
| | | } catch (Exception ex) { |
| | | |
| | | } |
| | | } |
| | | |
| | | private void findVideoList(Integer pageNo, Integer pageSize) throws Exception { |
| | | PageResult<Camera> pageResult = videoUtil.callPostCameras(pageNo, pageSize, "0"); |
| | | if (pageResult.getTotal() > 0) { |
| | | if (pageResult.getList().size() > 0) { |
| | | saveVideoFromCamera(pageResult.getList()); |
| | | |
| | | if (pageResult.getList().size() >= pageSize) { |
| | | findVideoList(pageNo + 1, pageSize); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void saveVideoFromCamera(List<Camera> list) { |
| | | |
| | | for (Camera c : list) { |
| | | LambdaQueryWrapper<VideoPoint> queryWrapper = new LambdaQueryWrapper<VideoPoint>() |
| | | .eq(VideoPoint::getPlatResourceId, c.getCameraIndexCode()); |
| | | List<VideoPoint> pointList = videoPointService.list(queryWrapper); |
| | | |
| | | if (pointList.size() == 0) { |
| | | VideoPoint videoPoint = new VideoPoint(); |
| | | videoPoint.setType(1); |
| | | videoPoint.setName(c.getName()); |
| | | videoPoint.setLatitude(Double.valueOf(c.getLatitude())); |
| | | videoPoint.setLongitude(Double.valueOf(c.getLatitude())); |
| | | videoPoint.setPlatResourceId(c.getCameraIndexCode()); |
| | | videoPoint.setCode(c.getDeviceIndexCode()); |
| | | videoPoint.setAddress(c.getInstallPlace()); |
| | | videoPoint.setEquipmentBrand("海康"); |
| | | videoPoint.setEquipmentModel(c.getCameraTypeName()); |
| | | |
| | | videoPointService.save(videoPoint); |
| | | } |
| | | } |
| | | } |
| | | } |