package com.fdkankan.scene.service.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.fdkankan.fyun.face.FYunFileServiceInterface; import com.fdkankan.model.constants.UploadFilePath; import com.fdkankan.scene.dto.GeoPoint; import com.fdkankan.scene.service.IVisionService; import com.fdkankan.scene.util.CoordinateUtil; import com.google.common.collect.Lists; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.*; import java.util.stream.Collectors; @Service @Slf4j public class VisionServiceImpl implements IVisionService { @Resource private FYunFileServiceInterface fYunFileService; @Override public List getPointLatAndLon(String num) { String visionTxt = fYunFileService.getFileContent(String.format(UploadFilePath.IMG_VIEW_PATH, num) + "vision.txt"); JSONObject visionJson = JSON.parseObject(visionTxt); if(!visionJson.containsKey("sweepLocations")){ return null; } JSONArray sweepLocations = visionJson.getJSONArray("sweepLocations"); List geoPoints = new ArrayList<>(); for (int i = 0; i < sweepLocations.size(); ++i) { JSONObject sweepItem = sweepLocations.getJSONObject(i); Long id = sweepItem.getLong("id"); Long uuid = sweepItem.getLong("uuid"); JSONObject ggaLocation = sweepItem.getJSONObject("ggaLocation"); GeoPoint geoPoint = new GeoPoint(); geoPoint.setId(id); geoPoint.setUuid(uuid); if (Objects.nonNull(ggaLocation) && StrUtil.isNotEmpty(ggaLocation.getString("lon")) && StrUtil.isNotEmpty(ggaLocation.getString("lat")) && StrUtil.isNotEmpty(ggaLocation.getString("alt"))) { Double[] ggaLocationGps = new Double[3]; if(Objects.nonNull(ggaLocation.getDouble("lon")) && Objects.nonNull(ggaLocation.getDouble("lat")) && Objects.nonNull(ggaLocation.getDouble("alt"))){ ggaLocationGps[0] = ggaLocation.getDouble("lon"); ggaLocationGps[1] = ggaLocation.getDouble("lat"); ggaLocationGps[2] = ggaLocation.getDouble("alt"); } geoPoint.setCoordinates(ggaLocationGps); geoPoint.setStatusIndicator(ggaLocation.getInteger("StatusIndicator")); } if (sweepItem.containsKey("puck")){ JSONObject puck = sweepItem.getJSONObject("puck"); Double[] floor_location = new Double[3]; floor_location[0] = puck.getDouble("x"); floor_location[1] = puck.getDouble("y"); floor_location[2] = puck.getDouble("z"); geoPoint.setLocation(floor_location); } geoPoints.add(geoPoint); } if (CollUtil.isNotEmpty(geoPoints) && geoPoints.size() >= 2) { Map res = new HashMap<>(); List statusFourPoints = geoPoints.stream().filter(item -> item.getStatusIndicator() == 4 || item.getStatusIndicator() == 100 || item.getStatusIndicator() == 104).collect(Collectors.toList()); if (statusFourPoints.size() >= 2) { CoordinateUtil.divide(0, statusFourPoints.size() - 1, statusFourPoints.toArray(new GeoPoint[0]), res); }else { return null ; } for (GeoPoint geoPoint : geoPoints) { if (res.containsKey("pointA")) { GeoPoint pointA = res.get("pointA"); if (geoPoint.getId()==pointA.getId()){ geoPoint.setPointA(true); } } if (res.containsKey("pointB")) { GeoPoint pointB = res.get("pointB"); if (geoPoint.getId()==pointB.getId()){ geoPoint.setPointB(true); } } } return geoPoints; } return null; } }