PhotoServiceImpl.java 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package com.keystar.plane.inspection.service.impl;
  2. import com.drew.imaging.jpeg.JpegProcessingException;
  3. import com.fasterxml.jackson.core.JsonProcessingException;
  4. import com.fasterxml.jackson.databind.ObjectMapper;
  5. import com.keystar.plane.inspection.bo.Location;
  6. import com.keystar.plane.inspection.bo.PhotoBo;
  7. import com.keystar.plane.inspection.bo.PhotoMqttMessageBo;
  8. import com.keystar.plane.inspection.bo.PvNameBo;
  9. import com.keystar.plane.inspection.constant.LocationConstant;
  10. import com.keystar.plane.inspection.dao.PhotoMessageVo;
  11. import com.keystar.plane.inspection.dao.PhotoResultVo;
  12. import com.keystar.plane.inspection.dao.PlanePhotoVo;
  13. import com.keystar.plane.inspection.entity.PhotoResultEntity;
  14. import com.keystar.plane.inspection.entity.PlanePhotoEntity;
  15. import com.keystar.plane.inspection.mapper.PhotoResultMapper;
  16. import com.keystar.plane.inspection.mapper.PlanePhotoMapper;
  17. import com.keystar.plane.inspection.service.PhotoService;
  18. import com.keystar.plane.inspection.service.PlanePhotoService;
  19. import com.keystar.plane.inspection.utils.FileUtil;
  20. import com.keystar.plane.inspection.utils.GisCheckUtils;
  21. import com.keystar.plane.inspection.utils.PhotoUtils;
  22. import lombok.extern.slf4j.Slf4j;
  23. import org.eclipse.paho.client.mqttv3.MqttAsyncClient;
  24. import org.eclipse.paho.client.mqttv3.MqttException;
  25. import org.eclipse.paho.client.mqttv3.MqttMessage;
  26. import org.junit.jupiter.params.shadow.com.univocity.parsers.conversions.LowerCaseConversion;
  27. import org.springframework.beans.factory.annotation.Autowired;
  28. import org.springframework.stereotype.Service;
  29. import org.springframework.util.ResourceUtils;
  30. import javax.annotation.Resource;
  31. import java.io.File;
  32. import java.io.FileNotFoundException;
  33. import java.io.IOException;
  34. import java.util.ArrayList;
  35. import java.util.List;
  36. import java.util.Map;
  37. @Slf4j
  38. @Service
  39. public class PhotoServiceImpl implements PhotoService {
  40. // @Autowired
  41. // MqttAsyncClient mqttAsyncClient;
  42. // private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
  43. @Resource
  44. PlanePhotoMapper planePhotoMapper;
  45. @Resource
  46. PhotoResultMapper photoResultMapper;
  47. @Autowired
  48. PlanePhotoService planePhotoService;
  49. @Override
  50. public PlanePhotoVo queryPhoto(String filePath) throws IOException, JpegProcessingException {
  51. PlanePhotoVo planePhotoVo = new PlanePhotoVo();
  52. // file = ResourceUtils.getFile("classpath:1114_THRM.JPG");
  53. File file = new File(filePath);
  54. // 获取图片中的信息
  55. PhotoMessageVo photoMessage = PhotoUtils.getPhotoMessage(file.getPath());
  56. // 根据图片信息,获取图片四个角的经纬度,判断图片在哪个光伏区
  57. List<Location> degrees = PhotoUtils.getDegrees(photoMessage);
  58. Location location = new Location();
  59. location.setLat(photoMessage.getLatitude());
  60. location.setLon(photoMessage.getLongitude());
  61. for ( Map.Entry<String, List<Location>> pzMap : LocationConstant.PZLocation.entrySet()){
  62. List<Location> value = pzMap.getValue();
  63. // 判断第一个多边形是否全部在第二个多边形内
  64. // if (GisCheckUtils.isPolygonAllInPolygon(degrees, value)){
  65. // planePhotoVo.setPZName(pzMap.getKey());
  66. // }
  67. // 判断第一个多边形是否存在一个点在第二个多边形内
  68. // if (GisCheckUtils.isPolygonInPolygon(degrees, value)){
  69. // planePhotoVo.setPZName(pzMap.getKey());
  70. // }
  71. // 当图片与光伏区的重合面积大于图片本身面积的百分之80才判断图片属于这个光伏区
  72. double photoArea = GisCheckUtils.planarPolygonAreaMeters(degrees);
  73. if (GisCheckUtils.CoincidentArea(degrees, value) >= photoArea * 0.6){
  74. planePhotoVo.setPZName(pzMap.getKey());
  75. }
  76. }
  77. // 查出图片中包含哪些光伏板
  78. if (planePhotoVo.getPZName() != null){
  79. String pzName = planePhotoVo.getPZName();
  80. Map<String, List<Location>> stringListMap = LocationConstant.PVLocation.get(pzName.split("FZ")[1]);
  81. List<String> pvNameList = new ArrayList<>();
  82. for (Map.Entry<String, List<Location>> pvMap : stringListMap.entrySet()){
  83. // 判断第一个多边形是否存在一个点在第二个多边形内
  84. // if (GisCheckUtils.isPolygonInPolygon(pvMap.getValue(), degrees)){
  85. // pvNameList.add(pvMap.getKey());
  86. // }
  87. // 判断第一个多边形是否全部在第二个多边形内
  88. // if (GisCheckUtils.isPolygonAllInPolygon(pvMap.getValue(), degrees)){
  89. // pvNameList.add(pvMap.getKey());
  90. // }
  91. // 当图片与的支架重合面积大于支架本身面积的百分之80才判断这个支架属于这个图片
  92. double pvArea = GisCheckUtils.planarPolygonAreaMeters(pvMap.getValue());
  93. if (GisCheckUtils.CoincidentArea(degrees, pvMap.getValue()) >= pvArea * 0.6){
  94. pvNameList.add(pvMap.getKey());
  95. }
  96. }
  97. planePhotoVo.setPVNames(pvNameList);
  98. }
  99. return planePhotoVo;
  100. }
  101. /**
  102. * 通过组串名字获取对应的图片和识别结果
  103. **/
  104. @Override
  105. public PhotoResultVo getPhotoMsg(PvNameBo pvNameBo) {
  106. // 获取这个组串最新的图片
  107. List<PhotoBo> photoBoList = planePhotoService.queryPhotoByPvName(pvNameBo);
  108. // 获取这个组串的图片总数
  109. PvNameBo nameBo = new PvNameBo();
  110. nameBo.setPvName(pvNameBo.getPvName());
  111. List<PlanePhotoEntity> photoEntityList = planePhotoMapper.getPhotoBo(nameBo);
  112. PhotoResultVo photoResultVo = new PhotoResultVo();
  113. photoResultVo.setTotal(photoEntityList.size());
  114. // 根据图片id查询识别结果
  115. List<PhotoBo> photoBos = new ArrayList<>();
  116. for (PhotoBo photoBo : photoBoList){
  117. Long id = photoBo.getId();
  118. List<PhotoResultEntity> photoResultEntities = photoResultMapper.queryResultByPhotoId(id);
  119. photoBo.setResults(photoResultEntities);
  120. photoBos.add(photoBo);
  121. }
  122. photoResultVo.setData(photoBos);
  123. return photoResultVo;
  124. }
  125. }