123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- package com.keystar.plane.inspection.service.impl;
- import com.drew.imaging.jpeg.JpegProcessingException;
- import com.fasterxml.jackson.core.JsonProcessingException;
- import com.fasterxml.jackson.databind.ObjectMapper;
- import com.keystar.plane.inspection.bo.Location;
- import com.keystar.plane.inspection.bo.PhotoBo;
- import com.keystar.plane.inspection.bo.PhotoMqttMessageBo;
- import com.keystar.plane.inspection.bo.PvNameBo;
- import com.keystar.plane.inspection.constant.LocationConstant;
- import com.keystar.plane.inspection.dao.PhotoMessageVo;
- import com.keystar.plane.inspection.dao.PhotoResultVo;
- import com.keystar.plane.inspection.dao.PlanePhotoVo;
- import com.keystar.plane.inspection.entity.PhotoResultEntity;
- import com.keystar.plane.inspection.entity.PlanePhotoEntity;
- import com.keystar.plane.inspection.mapper.PhotoResultMapper;
- import com.keystar.plane.inspection.mapper.PlanePhotoMapper;
- import com.keystar.plane.inspection.service.PhotoService;
- import com.keystar.plane.inspection.service.PlanePhotoService;
- import com.keystar.plane.inspection.utils.FileUtil;
- import com.keystar.plane.inspection.utils.GisCheckUtils;
- import com.keystar.plane.inspection.utils.PhotoUtils;
- import lombok.extern.slf4j.Slf4j;
- import org.eclipse.paho.client.mqttv3.MqttAsyncClient;
- import org.eclipse.paho.client.mqttv3.MqttException;
- import org.eclipse.paho.client.mqttv3.MqttMessage;
- import org.junit.jupiter.params.shadow.com.univocity.parsers.conversions.LowerCaseConversion;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.util.ResourceUtils;
- import javax.annotation.Resource;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- @Slf4j
- @Service
- public class PhotoServiceImpl implements PhotoService {
- // @Autowired
- // MqttAsyncClient mqttAsyncClient;
- // private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
- @Resource
- PlanePhotoMapper planePhotoMapper;
- @Resource
- PhotoResultMapper photoResultMapper;
- @Autowired
- PlanePhotoService planePhotoService;
- @Override
- public PlanePhotoVo queryPhoto(String filePath) throws IOException, JpegProcessingException {
- PlanePhotoVo planePhotoVo = new PlanePhotoVo();
- // file = ResourceUtils.getFile("classpath:1114_THRM.JPG");
- File file = new File(filePath);
- // 获取图片中的信息
- PhotoMessageVo photoMessage = PhotoUtils.getPhotoMessage(file.getPath());
- // 根据图片信息,获取图片四个角的经纬度,判断图片在哪个光伏区
- List<Location> degrees = PhotoUtils.getDegrees(photoMessage);
- Location location = new Location();
- location.setLat(photoMessage.getLatitude());
- location.setLon(photoMessage.getLongitude());
- for ( Map.Entry<String, List<Location>> pzMap : LocationConstant.PZLocation.entrySet()){
- List<Location> value = pzMap.getValue();
- // 判断第一个多边形是否全部在第二个多边形内
- // if (GisCheckUtils.isPolygonAllInPolygon(degrees, value)){
- // planePhotoVo.setPZName(pzMap.getKey());
- // }
- // 判断第一个多边形是否存在一个点在第二个多边形内
- // if (GisCheckUtils.isPolygonInPolygon(degrees, value)){
- // planePhotoVo.setPZName(pzMap.getKey());
- // }
- // 当图片与光伏区的重合面积大于图片本身面积的百分之80才判断图片属于这个光伏区
- double photoArea = GisCheckUtils.planarPolygonAreaMeters(degrees);
- if (GisCheckUtils.CoincidentArea(degrees, value) >= photoArea * 0.6){
- planePhotoVo.setPZName(pzMap.getKey());
- }
- }
- // 查出图片中包含哪些光伏板
- if (planePhotoVo.getPZName() != null){
- String pzName = planePhotoVo.getPZName();
- Map<String, List<Location>> stringListMap = LocationConstant.PVLocation.get(pzName.split("FZ")[1]);
- List<String> pvNameList = new ArrayList<>();
- for (Map.Entry<String, List<Location>> pvMap : stringListMap.entrySet()){
- // 判断第一个多边形是否存在一个点在第二个多边形内
- // if (GisCheckUtils.isPolygonInPolygon(pvMap.getValue(), degrees)){
- // pvNameList.add(pvMap.getKey());
- // }
- // 判断第一个多边形是否全部在第二个多边形内
- // if (GisCheckUtils.isPolygonAllInPolygon(pvMap.getValue(), degrees)){
- // pvNameList.add(pvMap.getKey());
- // }
- // 当图片与的支架重合面积大于支架本身面积的百分之80才判断这个支架属于这个图片
- double pvArea = GisCheckUtils.planarPolygonAreaMeters(pvMap.getValue());
- if (GisCheckUtils.CoincidentArea(degrees, pvMap.getValue()) >= pvArea * 0.6){
- pvNameList.add(pvMap.getKey());
- }
- }
- planePhotoVo.setPVNames(pvNameList);
- }
- return planePhotoVo;
- }
- /**
- * 通过组串名字获取对应的图片和识别结果
- **/
- @Override
- public PhotoResultVo getPhotoMsg(PvNameBo pvNameBo) {
- // 获取这个组串最新的图片
- List<PhotoBo> photoBoList = planePhotoService.queryPhotoByPvName(pvNameBo);
- // 获取这个组串的图片总数
- PvNameBo nameBo = new PvNameBo();
- nameBo.setPvName(pvNameBo.getPvName());
- List<PlanePhotoEntity> photoEntityList = planePhotoMapper.getPhotoBo(nameBo);
- PhotoResultVo photoResultVo = new PhotoResultVo();
- photoResultVo.setTotal(photoEntityList.size());
- // 根据图片id查询识别结果
- List<PhotoBo> photoBos = new ArrayList<>();
- for (PhotoBo photoBo : photoBoList){
- Long id = photoBo.getId();
- List<PhotoResultEntity> photoResultEntities = photoResultMapper.queryResultByPhotoId(id);
- photoBo.setResults(photoResultEntities);
- photoBos.add(photoBo);
- }
- photoResultVo.setData(photoBos);
- return photoResultVo;
- }
- }
|