| | |
| | | package com.ycl.service.caseHandler.impl; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.BeanUtils; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.hikvision.artemis.sdk.util.HttpUtils; |
| | | import com.ycl.common.util.UtilNumber; |
| | | import com.ycl.dto.video.HKAlarmParam; |
| | | import com.ycl.entity.caseHandler.BaseCase; |
| | |
| | | import com.ycl.service.caseHandler.IBaseCaseService; |
| | | import com.ycl.service.caseHandler.IViolationsService; |
| | | import com.ycl.service.dict.IDataDictionaryService; |
| | | import com.ycl.service.oss.OssService; |
| | | import com.ycl.service.region.ISccgRegionService; |
| | | import com.ycl.service.resources.IImageResourcesService; |
| | | import com.ycl.service.video.IVideoAlarmReportService; |
| | | import com.ycl.service.video.impl.IVideoPointService; |
| | | import com.ycl.vo.cockpit.enforcementEvents.VideoAndAreaVO; |
| | | import net.coobird.thumbnailator.Thumbnails; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.net.HttpURLConnection; |
| | | import java.net.URL; |
| | | import java.time.Instant; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | |
| | | private IImageResourcesService imageResourcesService; |
| | | private ISccgRegionService regionService; |
| | | private IVideoAlarmReportService videoAlarmReportService; |
| | | @Autowired |
| | | private OssService ossService; |
| | | @Resource |
| | | BaseCaseMapper baseCaseMapper; |
| | | |
| | |
| | | |
| | | try { |
| | | ImageResources imageResources = new ImageResources(); |
| | | imageResources.setType("01"); |
| | | imageResources.setType("05"); |
| | | imageResources.setBelongToId(baseCase.getId()); |
| | | imageResources.setUrl(videoAlarmReport.getPicData()); |
| | | imageResources.setCreateTime(LocalDateTime.now()); |
| | | |
| | | ImageResources imageResources1 = new ImageResources(); |
| | | BeanUtil.copyProperties(imageResources, imageResources1); |
| | | imageResources1.setType("01"); |
| | | |
| | | imageResourcesService.save(imageResources1); |
| | | imageResourcesService.save(imageResources); |
| | | } catch (Exception ex) { |
| | | System.out.println("海康推送保存异常:" + ex.getMessage()); |
| | |
| | | |
| | | VideoAlarmReport videoAlarmReport = new VideoAlarmReport(); |
| | | videoAlarmReport.setPlatResourceId(alarmParam.getEventNumber()); |
| | | String img0 = ""; |
| | | if (imgs.length > 0) { |
| | | videoAlarmReport.setPicData(imgs[0]); |
| | | img0 = saveOSS(imgs[0]); |
| | | videoAlarmReport.setPicData(img0); |
| | | } |
| | | videoAlarmReport.setAlarmTime(alarmTime); |
| | | videoAlarmReport.setAlarmId(alarmParam.getEventId()); |
| | |
| | | try { |
| | | for (int i = 0; i < imgs.length; i++) { |
| | | ImageResources imageResources = new ImageResources(); |
| | | imageResources.setType("01"); |
| | | imageResources.setType("04"); |
| | | imageResources.setBelongToId(baseCase.getId()); |
| | | imageResources.setUrl(imgs[i]); |
| | | imageResources.setUrl(i == 0 ? img0 : saveOSS(imgs[i])); |
| | | imageResources.setCreateTime(LocalDateTime.now()); |
| | | imageResourcesService.save(imageResources); |
| | | |
| | | ImageResources imageResources1 = new ImageResources(); |
| | | BeanUtil.copyProperties(imageResources, imageResources1); |
| | | imageResources1.setType("01"); |
| | | |
| | | imageResourcesService.save(imageResources1); |
| | | imageResourcesService.save(imageResources); |
| | | } |
| | | } catch (Exception ex) { |
| | | |
| | |
| | | |
| | | } |
| | | |
| | | private String saveOSS(String hkUrl) { |
| | | InputStream inputStream = getImageStream(hkUrl); |
| | | if (inputStream != null) { |
| | | String picData = ossService.uploadImages(inputStream, ".png",0); |
| | | return picData; |
| | | } else return ""; |
| | | } |
| | | |
| | | private InputStream getImageStream(String url) { |
| | | try { |
| | | HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); |
| | | connection.setReadTimeout(5000); |
| | | connection.setConnectTimeout(5000); |
| | | connection.setRequestMethod("GET"); |
| | | if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) { |
| | | InputStream inputStream = connection.getInputStream(); |
| | | ByteArrayOutputStream outs = new ByteArrayOutputStream(); |
| | | Thumbnails.of(inputStream).scale(0.6).outputQuality(1).toOutputStream(outs); |
| | | InputStream ins = new ByteArrayInputStream(outs.toByteArray()); |
| | | return ins; |
| | | } |
| | | } catch (IOException e) { |
| | | System.out.println("获取网络图片出现异常,图片路径为:" + url); |
| | | |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public List<VideoAndAreaVO> selectType() { |
| | | return baseCaseMapper.selectType(); |