| | |
| | | package com.ycl.task; |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ycl.common.constant.GlobalQueue; |
| | | import com.ycl.entity.video.VideoAlarmReport; |
| | | import com.ycl.entity.video.VideoPoint; |
| | | import com.ycl.service.caseHandler.IBaseCaseService; |
| | | import com.ycl.service.caseHandler.IViolationsService; |
| | | import com.ycl.service.oss.OssService; |
| | | import com.ycl.service.resources.IImageResourcesService; |
| | | import com.ycl.service.video.IVideoAlarmReportService; |
| | | import com.ycl.service.video.impl.IVideoPointService; |
| | | import com.ycl.vo.casePool.BaseCaseVO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.InputStream; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | |
| | | |
| | | @Autowired |
| | | private IViolationsService violationsService; |
| | | |
| | | @Autowired |
| | | private IBaseCaseService baseCaseService; |
| | | |
| | | @Autowired |
| | | private IImageResourcesService imageService; |
| | | |
| | | @Scheduled(cron = "0 */1 * * * ?") |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | if (videoAlarmReport.getPicByte() != null) { |
| | | String extension = "jpg"; |
| | | InputStream inputStream = new ByteArrayInputStream(videoAlarmReport.getPicByte()); |
| | | String picData = ossService.uploadImages(inputStream, extension,0); |
| | | String picData = ossService.uploadImages(inputStream, extension, 0); |
| | | |
| | | videoAlarmReport.setPicData(picData); |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | @Scheduled(cron = "0 0 16 * * ?") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void deleteAlarmTask() { |
| | | System.out.println("----------------执行清除数据任务:"); |
| | | int i = 1; |
| | | while (true) { |
| | | String beginTime = "2020-01-01 00:00:00"; |
| | | String endTime = LocalDateTime.now().plusDays(-3).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
| | | Page<BaseCaseVO> page = baseCaseService.selectVideoInspection(i, 10, null, null, beginTime, endTime, null); |
| | | |
| | | System.out.println("----------------清除数据任务总条数:" + page.getTotal()); |
| | | if (page.getRecords().size() > 0) { |
| | | page.getRecords().forEach(baseCaseVO -> { |
| | | String picData = baseCaseVO.getPicData(); |
| | | String[] urls = picData.split(","); |
| | | for (String url : urls) { |
| | | ossService.deleteImages(url); |
| | | } |
| | | baseCaseService.removeById(baseCaseVO.getBaseId()); |
| | | imageService.removeById(baseCaseVO.getImageId()); |
| | | |
| | | System.out.println("----------------清除数据数据成功,id:" + baseCaseVO.getBaseId()); |
| | | }); |
| | | } else { |
| | | break; |
| | | } |
| | | i++; |
| | | } |
| | | } |
| | | } |