| | |
| | | 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.entity.caseHandler.EventSource; |
| | | import com.ycl.entity.caseHandler.QuestionCategory; |
| | | import com.ycl.entity.caseHandler.Violations; |
| | | import com.ycl.entity.dict.DataDictionary; |
| | | import com.ycl.entity.region.SccgRegion; |
| | | import com.ycl.entity.resources.ImageResources; |
| | | import com.ycl.entity.video.VideoAlarmReport; |
| | | import com.ycl.entity.video.VideoPoint; |
| | | import com.ycl.enums.common.DictTypeEnum; |
| | |
| | | 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; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.List; |
| | | |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | private IVideoPointService videoPointService; |
| | | private IBaseCaseService baseCaseService; |
| | | private IDataDictionaryService dataDictionaryService; |
| | | |
| | | private IImageResourcesService imageResourcesService; |
| | | private ISccgRegionService regionService; |
| | | private IVideoAlarmReportService videoAlarmReportService; |
| | | @Autowired |
| | | private OssService ossService; |
| | | @Resource |
| | | BaseCaseMapper baseCaseMapper; |
| | | |
| | | @Autowired |
| | | UtilNumber utilNumber; |
| | | |
| | | @Autowired |
| | | public void setVideoPointService(IVideoPointService videoPointService) { |
| | |
| | | this.dataDictionaryService = dataDictionaryService; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setImageResourcesService(IImageResourcesService imageResourcesService) { |
| | | this.imageResourcesService = imageResourcesService; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setRegionService(ISccgRegionService regionService) { |
| | | this.regionService = regionService; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setVideoAlarmReportService(IVideoAlarmReportService videoAlarmReportService) { |
| | | this.videoAlarmReportService = videoAlarmReportService; |
| | | } |
| | | |
| | | @Override |
| | | public void saveFromVideo(List<VideoAlarmReport> videoAlarmReports) { |
| | | for (VideoAlarmReport videoAlarmReport : videoAlarmReports) { |
| | | VideoPoint videoPoint = null; |
| | | LambdaQueryWrapper<VideoPoint> queryWrapper = new LambdaQueryWrapper<VideoPoint>().eq(VideoPoint::getPlatResourceId, videoAlarmReport.getPlatResourceId()); |
| | | List<VideoPoint> pointList = videoPointService.list(queryWrapper); |
| | | if (pointList.size() > 0) { |
| | | videoPoint = pointList.get(0); |
| | | } |
| | | |
| | | BaseCase baseCase = BaseCase.builder().eventSource(EventSource.VIDEO.getCode()).category(QuestionCategory.VIOLATION.getCode()) |
| | | .createTime(LocalDateTime.now()).createUser(0L).state(1).alarmTime(videoAlarmReport.getAlarmTime()).build(); |
| | | .code(utilNumber.createCaseCode()).createTime(LocalDateTime.now()).createUser(0L).state(1).alarmTime(videoAlarmReport.getAlarmTime()).build(); |
| | | Violations violations = new Violations(); |
| | | VideoPoint videoPoint = videoPointService.getByCode(videoAlarmReport.getPlatResourceId()); |
| | | if (videoPoint != null) { |
| | | baseCase.setLatitude(videoPoint.getLatitude()); |
| | | baseCase.setLongitude(videoPoint.getLongitude()); |
| | |
| | | baseCase.setCommunityId(videoPoint.getCommunityId()); |
| | | baseCase.setSite(videoPoint.getAddress()); |
| | | baseCase.setGridId(videoPoint.getGridId()); |
| | | baseCase.setSite(videoPoint.getAddress()); |
| | | |
| | | baseCaseService.save(baseCase); |
| | | violations.setId(baseCase.getId()); |
| | |
| | | } |
| | | |
| | | baseMapper.insert(violations); |
| | | |
| | | try { |
| | | ImageResources imageResources = new ImageResources(); |
| | | 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()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void saveFromHKVideo(HKAlarmParam alarmParam) { |
| | | |
| | | SccgRegion region = regionService.getByCode(alarmParam.getPrefectureCodeIdaas()); |
| | | VideoPoint videoPoint = videoPointService.getByCode(alarmParam.getEventNumber()); |
| | | |
| | | List<DataDictionary> dataDictionaries = dataDictionaryService.queryByRemark(alarmParam.getSubject()); |
| | | DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | LocalDateTime alarmTime = LocalDateTime.parse(alarmParam.getIncidentDate(), df); |
| | | |
| | | BaseCase baseCase = BaseCase.builder().eventSource(1).category(QuestionCategory.VIOLATION.getCode()) |
| | | .code(utilNumber.createCaseCode()).createTime(LocalDateTime.now()).createUser(0L).state(1). |
| | | alarmTime(alarmTime).build(); |
| | | Violations violations = new Violations(); |
| | | |
| | | baseCase.setLatitude(alarmParam.getLatitude()); |
| | | baseCase.setLongitude(alarmParam.getLongitude()); |
| | | if (region != null) { |
| | | baseCase.setStreetId(region.getId().intValue()); |
| | | } |
| | | baseCase.setSite(alarmParam.getScene()); |
| | | |
| | | baseCaseService.save(baseCase); |
| | | violations.setId(baseCase.getId()); |
| | | |
| | | if (dataDictionaries.size() > 0) { |
| | | violations.setGradeId(dataDictionaries.get(0).getId()); |
| | | } |
| | | |
| | | violations.setDescription(alarmParam.getEventContent()); |
| | | violations.setInformant(alarmParam.getReportUserName()); |
| | | violations.setInformantPhoneCode(alarmParam.getContact()); |
| | | if (videoPoint != null) { |
| | | violations.setVideoPointId(videoPoint.getId()); |
| | | } |
| | | |
| | | String[] imgs = alarmParam.getFileUrl().split(","); |
| | | |
| | | VideoAlarmReport videoAlarmReport = new VideoAlarmReport(); |
| | | videoAlarmReport.setPlatResourceId(alarmParam.getEventNumber()); |
| | | String img0 = ""; |
| | | if (imgs.length > 0) { |
| | | img0 = saveOSS(imgs[0]); |
| | | videoAlarmReport.setPicData(img0); |
| | | } |
| | | videoAlarmReport.setAlarmTime(alarmTime); |
| | | videoAlarmReport.setAlarmId(alarmParam.getEventId()); |
| | | videoAlarmReport.setAlgoName(alarmParam.getContact()); |
| | | videoAlarmReport.setAlarmName(alarmParam.getSubject()); |
| | | videoAlarmReportService.save(videoAlarmReport); |
| | | |
| | | violations.setVideoAlarmReportId(videoAlarmReport.getId()); |
| | | baseMapper.insert(violations); |
| | | |
| | | try { |
| | | for (int i = 0; i < imgs.length; i++) { |
| | | ImageResources imageResources = new ImageResources(); |
| | | imageResources.setType("04"); |
| | | imageResources.setBelongToId(baseCase.getId()); |
| | | imageResources.setUrl(i == 0 ? img0 : saveOSS(imgs[i])); |
| | | imageResources.setCreateTime(LocalDateTime.now()); |
| | | |
| | | 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(); |
| | | } |