VisionServiceImpl.java 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package com.fdkankan.scene.service.impl;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.util.StrUtil;
  4. import com.alibaba.fastjson.JSON;
  5. import com.alibaba.fastjson.JSONArray;
  6. import com.alibaba.fastjson.JSONObject;
  7. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  8. import com.fdkankan.model.constants.UploadFilePath;
  9. import com.fdkankan.scene.dto.GeoPoint;
  10. import com.fdkankan.scene.service.IVisionService;
  11. import com.fdkankan.scene.util.CoordinateUtil;
  12. import com.google.common.collect.Lists;
  13. import lombok.extern.slf4j.Slf4j;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.stereotype.Service;
  16. import javax.annotation.Resource;
  17. import java.util.*;
  18. import java.util.stream.Collectors;
  19. @Service
  20. @Slf4j
  21. public class VisionServiceImpl implements IVisionService {
  22. @Resource
  23. private FYunFileServiceInterface fYunFileService;
  24. @Override
  25. public List<GeoPoint> getPointLatAndLon(String num) {
  26. String visionTxt = fYunFileService.getFileContent(String.format(UploadFilePath.IMG_VIEW_PATH, num) + "vision.txt");
  27. JSONObject visionJson = JSON.parseObject(visionTxt);
  28. if(!visionJson.containsKey("sweepLocations")){
  29. return null;
  30. }
  31. JSONArray sweepLocations = visionJson.getJSONArray("sweepLocations");
  32. List<GeoPoint> geoPoints = new ArrayList<>();
  33. for (int i = 0; i < sweepLocations.size(); ++i) {
  34. JSONObject sweepItem = sweepLocations.getJSONObject(i);
  35. Long id = sweepItem.getLong("id");
  36. Long uuid = sweepItem.getLong("uuid");
  37. JSONObject ggaLocation = sweepItem.getJSONObject("ggaLocation");
  38. GeoPoint geoPoint = new GeoPoint();
  39. geoPoint.setId(id);
  40. geoPoint.setUuid(uuid);
  41. if (Objects.nonNull(ggaLocation)
  42. && StrUtil.isNotEmpty(ggaLocation.getString("lon"))
  43. && StrUtil.isNotEmpty(ggaLocation.getString("lat"))
  44. && StrUtil.isNotEmpty(ggaLocation.getString("alt"))) {
  45. Double[] ggaLocationGps = new Double[3];
  46. if(Objects.nonNull(ggaLocation.getDouble("lon"))
  47. && Objects.nonNull(ggaLocation.getDouble("lat"))
  48. && Objects.nonNull(ggaLocation.getDouble("alt"))){
  49. ggaLocationGps[0] = ggaLocation.getDouble("lon");
  50. ggaLocationGps[1] = ggaLocation.getDouble("lat");
  51. ggaLocationGps[2] = ggaLocation.getDouble("alt");
  52. }
  53. geoPoint.setCoordinates(ggaLocationGps);
  54. geoPoint.setStatusIndicator(ggaLocation.getInteger("StatusIndicator"));
  55. }
  56. if (sweepItem.containsKey("puck")){
  57. JSONObject puck = sweepItem.getJSONObject("puck");
  58. Double[] floor_location = new Double[3];
  59. floor_location[0] = puck.getDouble("x");
  60. floor_location[1] = puck.getDouble("y");
  61. floor_location[2] = puck.getDouble("z");
  62. geoPoint.setLocation(floor_location);
  63. }
  64. geoPoints.add(geoPoint);
  65. }
  66. if (CollUtil.isNotEmpty(geoPoints) && geoPoints.size() >= 2) {
  67. Map<String, GeoPoint> res = new HashMap<>();
  68. List<GeoPoint> statusFourPoints = geoPoints.stream().filter(item -> item.getStatusIndicator() == 4 || item.getStatusIndicator() == 100 || item.getStatusIndicator() == 104).collect(Collectors.toList());
  69. if (statusFourPoints.size() >= 2) {
  70. CoordinateUtil.divide(0, statusFourPoints.size() - 1, statusFourPoints.toArray(new GeoPoint[0]), res);
  71. }else {
  72. return null ;
  73. }
  74. for (GeoPoint geoPoint : geoPoints) {
  75. if (res.containsKey("pointA")) {
  76. GeoPoint pointA = res.get("pointA");
  77. if (geoPoint.getId()==pointA.getId()){
  78. geoPoint.setPointA(true);
  79. }
  80. }
  81. if (res.containsKey("pointB")) {
  82. GeoPoint pointB = res.get("pointB");
  83. if (geoPoint.getId()==pointB.getId()){
  84. geoPoint.setPointB(true);
  85. }
  86. }
  87. }
  88. }
  89. return geoPoints;
  90. }
  91. }