| | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.moral.api.entity.HistorySecondUav; |
| | | import com.moral.api.mapper.HistorySecondUavMapper; |
| | | import com.moral.api.pojo.dto.uav.UAVGteForDTO; |
| | |
| | | import io.swagger.annotations.Api; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.web.bind.annotation.CrossOrigin; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | |
| | | import java.awt.geom.Point2D; |
| | | import java.text.DecimalFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @ClassName UAVController |
| | |
| | | return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(),vo); |
| | | } |
| | | |
| | | @RequestMapping("test") |
| | | public ResultMessage test(){ |
| | | @PostMapping("test") |
| | | public ResultMessage test(@RequestBody Map<String, Object> params){ |
| | | //判断是否缺少参数 |
| | | if (!params.containsKey("mac") || !params.containsKey("batch") || !params.containsKey("height")|| !params.containsKey("uvasize")) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | String uvasize = params.get("uvasize").toString(); |
| | | int size = Integer.parseInt(uvasize); |
| | | //纬度 |
| | | ArrayList<Double> flyLatList = new ArrayList<>(); |
| | | //经度 |
| | | ArrayList<Double> flyLonList = new ArrayList<>(); |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | String mac ="p5dnd7a0243592"; |
| | | String time1 ="2023-05-14 10:40:00"; |
| | | String time2 ="2023-05-14 11:10:00"; |
| | | map.put("mac",mac); |
| | | map.put("time1",time1); |
| | | map.put("time2",time2); |
| | | // List<UAVResultDTO> uavResultDTOS = historySecondUavMapper.reList(map); |
| | | QueryWrapper<HistorySecondUav> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.select("value"); |
| | | queryWrapper.eq("mac",mac); |
| | | queryWrapper.between("time",time1,time2); |
| | | List<HistorySecondUav> historySecondUavs = historySecondUavMapper.selectList(queryWrapper); |
| | | for (HistorySecondUav historySecondUav : historySecondUavs) { |
| | | String value = historySecondUav.getValue(); |
| | | Map map1 = JSON.parseObject(value, Map.class); |
| | | flyLatList.add(Double.parseDouble(map1.get("flylat").toString())); |
| | | flyLonList.add(Double.parseDouble(map1.get("flylon").toString())); |
| | | |
| | | List<HistorySecondUav> historySecondUavs = historySecondUavMapper.reList(params); |
| | | if (ObjectUtils.isEmpty(historySecondUavs)){ |
| | | return new ResultMessage(ResponseCodeEnum.TARGET_IS_NULL,"null"); |
| | | } |
| | | Double maxLat = Collections.max(flyLatList); |
| | | Double maxLon = Collections.max(flyLonList); |
| | | Double minLat = Collections.min(flyLatList); |
| | | Double minLon = Collections.min(flyLonList); |
| | | |
| | | //大四边形右下 |
| | | String leftTop = minLat +";"+ maxLon; |
| | | //右上 |
| | |
| | | //左下2 |
| | | String[] zuoxia = calLocationByDistanceAndLocationAndDirection(180, minLon, maxLat, 50); |
| | | |
| | | for (int i = 0; i <distance1 ; i+=60) { |
| | | for (int i = 0; i <distance2 ; i+=size) { |
| | | UAVGteForDTO dto1 = new UAVGteForDTO(); |
| | | String[] strings2 = calLocationByDistanceAndLocationAndDirection(90, minLon, maxLat, i); |
| | | String[] strings3 = calLocationByDistanceAndLocationAndDirection(90, Double.parseDouble(youshang[0].toString()), Double.parseDouble(youshang[1].toString()), i); |
| | |
| | | dto1.setRightBottom(strings4); |
| | | dto1.setLeftBottom(strings5); |
| | | list.add(dto1); |
| | | for (int j = 0; j < distance2; j+=60) { |
| | | for (int j = 0; j < distance1; j+=size) { |
| | | UAVGteForDTO dto2 = new UAVGteForDTO(); |
| | | String[] strings6 = calLocationByDistanceAndLocationAndDirection(180, Double.parseDouble(strings2[0].toString()), Double.parseDouble(strings2[1].toString()), j); |
| | | String[] strings7 = calLocationByDistanceAndLocationAndDirection(180, Double.parseDouble(strings3[0].toString()), Double.parseDouble(strings3[1].toString()), j); |
| | |
| | | } |
| | | } |
| | | } |
| | | ArrayList<UAVResultDTO> uavResultDTOS1 = new ArrayList<>(); |
| | | for (UAVGteForDTO uavGteForDTO : list) { |
| | | ArrayList<String[]> doubleArrayList = new ArrayList<>(); |
| | | doubleArrayList.add(uavGteForDTO.getLeftTop()); |
| | | doubleArrayList.add(uavGteForDTO.getLeftBottom()); |
| | | doubleArrayList.add(uavGteForDTO.getRightTop()); |
| | | doubleArrayList.add(uavGteForDTO.getRightBottom()); |
| | | UAVResultDTO result = getResult(doubleArrayList); |
| | | uavResultDTOS1.add(result); |
| | | } |
| | | if (uavResultDTOS1!=null){ |
| | | return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(),uavResultDTOS1); |
| | | |
| | | } |
| | | |
| | | // ArrayList<List<String>> lists = new ArrayList<>(); |
| | | HashMap<String,List<String>> rsMap = new HashMap<>(); |
| | | // HashMap<String,List<Map<String,Object>>> rsMap1 = new HashMap<>(); |
| | | List<String> stringList = new ArrayList<>(); |
| | | for (UAVGteForDTO uavGteForDTO : list) { |
| | | ArrayList<String> list1 = new ArrayList<>(); |
| | | ArrayList<String[]> doubleArrayList = new ArrayList<>(); |
| | |
| | | doubleArrayList.add(uavGteForDTO.getLeftBottom()); |
| | | doubleArrayList.add(uavGteForDTO.getRightTop()); |
| | | doubleArrayList.add(uavGteForDTO.getRightBottom()); |
| | | String[] leftTops = uavGteForDTO.getLeftTop(); |
| | | String[] rightBottoms = uavGteForDTO.getRightBottom(); |
| | | Double x1 = Double.parseDouble(leftTops[0]); |
| | | Double x2 = Double.parseDouble(rightBottoms[0]); |
| | | Double y1 = Double.parseDouble(leftTops[1]); |
| | | Double y2 = Double.parseDouble(rightBottoms[1]); |
| | | //获取区域对象 |
| | | for (HistorySecondUav historySecondUav : historySecondUavs) { |
| | | for (int i = 0; i < historySecondUavs.size(); i++) { |
| | | HistorySecondUav historySecondUav = historySecondUavs.get(i); |
| | | String value = historySecondUav.getValue(); |
| | | Map map1 = JSON.parseObject(value, Map.class); |
| | | String flylat = map1.get("flylat").toString(); |
| | | String flylon = map1.get("flylon").toString(); |
| | | //判断点是否在区域内 |
| | | boolean flag = isInPolygon(flylon,flylat,doubleArrayList); |
| | | boolean flag = isInPolygon(flylon,flylat,x1,x2,y1,y2); |
| | | if (flag){ |
| | | |
| | | list1.add(historySecondUav.getValue()); |
| | | String time = DateUtils.dateToDateString(historySecondUav.getTime()); |
| | | //historySecondUavs.remove(i); |
| | | if(!stringList.contains(time)){ |
| | | list1.add(historySecondUav.getValue()); |
| | | stringList.add(time); |
| | | } |
| | | } |
| | | } |
| | | // lists.add(list1); |
| | | // String result = getResult(doubleArrayList); |
| | | // rsMap.put(result,list1); |
| | | //获取中心点坐标 |
| | | String result = getResult(doubleArrayList); |
| | | rsMap.put(result,list1); |
| | | } |
| | | |
| | | |
| | | //计算区域类所有因子的平均数 |
| | | ArrayList<UAVResultDTO> uavResultDTOS = new ArrayList<>(); |
| | | Set<String> strings = rsMap.keySet(); |
| | | for (String string : strings) { |
| | | UAVResultDTO dto = new UAVResultDTO(); |
| | | List<String> list1 = rsMap.get(string); |
| | | if (ObjectUtils.isEmpty(list1)){ |
| | | continue; |
| | | } |
| | | ArrayList<Double> TVOCArrayList = new ArrayList<>(); |
| | | ArrayList<Double> PM10ArrayList = new ArrayList<>(); |
| | | ArrayList<Double> PM25ArrayList = new ArrayList<>(); |
| | |
| | | ArrayList<Double> COArrayList = new ArrayList<>(); |
| | | ArrayList<Double> WDArrayList = new ArrayList<>(); |
| | | ArrayList<Double> SHArrayList = new ArrayList<>(); |
| | | ArrayList<Double> O3ArrayList = new ArrayList<>(); |
| | | for (String s : list1) { |
| | | JSONObject jsonObject = JSON.parseObject(s); |
| | | //tvoc |
| | | String a99054 = jsonObject.get("a99054").toString(); |
| | | Object a99054 = jsonObject.get("a99054"); |
| | | if (!Objects.isNull(a99054)){ |
| | | TVOCArrayList.add(Double.parseDouble(a99054.toString())); |
| | | } |
| | | //pm2.5 |
| | | String a34004 = jsonObject.get("a34004").toString(); |
| | | Object a34004 = jsonObject.get("a34004"); |
| | | if (!Objects.isNull(a34004)){ |
| | | PM25ArrayList.add(Double.parseDouble(a34004.toString())); |
| | | } |
| | | //二氧化硫 |
| | | String a21026 = jsonObject.get("a21026").toString(); |
| | | ///二氧化氮 |
| | | String a21004 = jsonObject.get("a21004").toString(); |
| | | // //气压 |
| | | // String a01006 = jsonObject.get("a01006").toString(); |
| | | // if (a01006!=null){ |
| | | // QYArrayList.add(Double.parseDouble(a01006)); |
| | | // } |
| | | //pm10 |
| | | String a34002 = jsonObject.get("a34002").toString(); |
| | | //co |
| | | String a21005 = jsonObject.get("a21005").toString(); |
| | | //湿度 |
| | | // String a01002 = jsonObject.get("a01002").toString(); |
| | | //温度 |
| | | // String a01001 = jsonObject.get("a01001").toString(); |
| | | TVOCArrayList.add(Double.parseDouble(a99054)); |
| | | PM10ArrayList.add(Double.parseDouble(a34002)); |
| | | PM25ArrayList.add(Double.parseDouble(a34004)); |
| | | SOArrayList.add(Double.parseDouble(a21026)); |
| | | NOArrayList.add(Double.parseDouble(a21004)); |
| | | COArrayList.add(Double.parseDouble(a21005)); |
| | | Object a21026 = jsonObject.get("a21026"); |
| | | if (!Objects.isNull(a21026)){ |
| | | SOArrayList.add(Double.parseDouble(a21026.toString())); |
| | | } |
| | | |
| | | // WDArrayList.add(Double.parseDouble(a01001)); |
| | | // SHArrayList.add(Double.parseDouble(a01002)); |
| | | //二氧化氮 |
| | | Object a21004 = jsonObject.get("a21004"); |
| | | if (!Objects.isNull(a21004)){ |
| | | NOArrayList.add(Double.parseDouble(a21004.toString())); |
| | | } |
| | | |
| | | //气压 |
| | | Object a01006 = jsonObject.get("a01006"); |
| | | if (!Objects.isNull(a01006)){ |
| | | QYArrayList.add(Double.parseDouble(a01006.toString())); |
| | | } |
| | | //pm10 |
| | | Object a34002 = jsonObject.get("a34002"); |
| | | if (!Objects.isNull(a34002)){ |
| | | PM10ArrayList.add(Double.parseDouble(a34002.toString())); |
| | | } |
| | | //co |
| | | Object a21005 = jsonObject.get("a21005"); |
| | | if (!Objects.isNull(a21005)){ |
| | | COArrayList.add(Double.parseDouble(a21005.toString())); |
| | | } |
| | | //湿度 |
| | | Object a01002 = jsonObject.get("a01002"); |
| | | if (!Objects.isNull(a01002)){ |
| | | QYArrayList.add(Double.parseDouble(a01002.toString())); |
| | | } |
| | | //温度 |
| | | Object a01001 = jsonObject.get("a01001"); |
| | | if (!Objects.isNull(a01001)){ |
| | | QYArrayList.add(Double.parseDouble(a01001.toString())); |
| | | } |
| | | //臭氧 |
| | | Object a05024 = jsonObject.get("a05024"); |
| | | if (!Objects.isNull(a05024)){ |
| | | O3ArrayList.add(Double.parseDouble(a05024.toString())); |
| | | } |
| | | |
| | | } |
| | | double WDDouble =0.0; |
| | | double SHDouble =0.0; |
| | | double QYDouble =0.0; |
| | | double CODouble =0.0; |
| | | double TVODouble =0.0; |
| | | double PM10Double =0.0; |
| | | double PM25Double =0.0; |
| | | double SODouble =0.0; |
| | | double NODouble =0.0; |
| | | double O3Double =0.0; |
| | | if (COArrayList.size()>0){ |
| | | CODouble = COArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble(); |
| | | } |
| | | if (TVOCArrayList.size()>0){ |
| | | TVODouble = TVOCArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble(); |
| | | } |
| | | if (PM10ArrayList.size()>0){ |
| | | PM10Double = PM10ArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble(); |
| | | } |
| | | if (PM25ArrayList.size()>0){ |
| | | PM25Double = PM25ArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble(); |
| | | } |
| | | if (SOArrayList.size()>0){ |
| | | SODouble = SOArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble(); |
| | | } |
| | | if (NOArrayList.size()>0){ |
| | | NODouble = NOArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble(); |
| | | } |
| | | if (WDArrayList.size()>0){ |
| | | WDDouble = WDArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble(); |
| | | } |
| | | if (SHArrayList.size()>0){ |
| | | SHDouble = SHArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble(); |
| | | } |
| | | if (QYArrayList.size()>0){ |
| | | QYDouble = QYArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble(); |
| | | } |
| | | if (O3ArrayList.size()>0){ |
| | | O3Double = O3ArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble(); |
| | | } |
| | | |
| | | double asDouble = COArrayList.stream().mapToInt(Double::intValue).average().getAsDouble(); |
| | | |
| | | // dto.setCoAvg(CODouble); |
| | | // dto.setNO2Avg(NODouble); |
| | | // dto.setO3Avg(O3Double); |
| | | // dto.setTVOCAvg(TVODouble); |
| | | // dto.setPM10Avg(PM10Double); |
| | | // dto.setPM25Avg(PM25Double); |
| | | // dto.setSO2Avg(SODouble); |
| | | // dto.setWDAvg(WDDouble); |
| | | // dto.setSHAvg(SHDouble); |
| | | // dto.setQYAvg(QYDouble); |
| | | dto.setA21005(CODouble); |
| | | dto.setA21004(NODouble); |
| | | dto.setA05024(O3Double); |
| | | dto.setA99054(TVODouble); |
| | | dto.setA34002(PM10Double); |
| | | dto.setA34004(PM25Double); |
| | | dto.setA21026(SODouble); |
| | | dto.setA01001(WDDouble); |
| | | dto.setA01002(SHDouble); |
| | | dto.setA01006(QYDouble); |
| | | String[] s = string.split("_"); |
| | | dto.setFlyLat(Double.parseDouble(s[1])); |
| | | dto.setFlyLon(Double.parseDouble(s[0])); |
| | | uavResultDTOS.add(dto); |
| | | } |
| | | |
| | | |
| | | return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(),null); |
| | | return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(),uavResultDTOS); |
| | | } |
| | | |
| | | |
| | |
| | | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | //处理查询业务 |
| | | List<UAVQueryTimeSlotDTO> dtos = historySecondUavService.queryTimeSlot(form); |
| | | if (ObjectUtils.isEmpty(dtos)){ |
| | | return new ResultMessage(ResponseCodeEnum.TARGET_IS_NULL,null); |
| | | } |
| | | //封装vo层 |
| | | UAVQueryTimeSlotVOs vo = UAVQueryTimeSlotVOs.convert(dtos); |
| | | |
| | | //返回数据 |
| | | return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(),vo); |
| | | } |
| | |
| | | return s; |
| | | } |
| | | |
| | | |
| | | public static UAVResultDTO getResult(ArrayList<String[]> doubleArrayList){ |
| | | UAVResultDTO uavResultDTO = new UAVResultDTO(); |
| | | //获取中心点 |
| | | public static String getResult(ArrayList<String[]> doubleArrayList){ |
| | | // UAVResultDTO uavResultDTO = new UAVResultDTO(); |
| | | int total = doubleArrayList.size(); |
| | | double X = 0, Y = 0, Z = 0; |
| | | for (int i = 0; i < total; i++) { |
| | |
| | | double Lon = Math.atan2(Y, X); |
| | | double Hyp = Math.sqrt(X * X + Y * Y); |
| | | double Lat = Math.atan2(Z, Hyp); |
| | | |
| | | double rsLon = Lon * 180 / Math.PI; |
| | | double rsLat = Lat * 180 / Math.PI; |
| | | // uavResultDTO.setFlyLon(rsLon); |
| | | // uavResultDTO.setFlyLat(rsLat); |
| | | |
| | | return rsLon+"_"+rsLat; |
| | | // return uavResultDTO; |
| | | } |
| | | |
| | | |
| | | //获取中心点 |
| | | public static UAVResultDTO getResults(ArrayList<String[]> doubleArrayList){ |
| | | UAVResultDTO uavResultDTO = new UAVResultDTO(); |
| | | int total = doubleArrayList.size(); |
| | | double X = 0, Y = 0, Z = 0; |
| | | for (int i = 0; i < total; i++) { |
| | | double lat, lon, x, y, z; |
| | | String[] strings = doubleArrayList.get(i); |
| | | lon = Double.parseDouble(strings[0]) * Math.PI / 180; |
| | | lat = Double.parseDouble(strings[1]) * Math.PI / 180; |
| | | x = Math.cos(lat) * Math.cos(lon); |
| | | y = Math.cos(lat) * Math.sin(lon); |
| | | z = Math.sin(lat); |
| | | X += x; |
| | | Y += y; |
| | | Z += z; |
| | | } |
| | | X = X / total; |
| | | Y = Y / total; |
| | | Z = Z / total; |
| | | double Lon = Math.atan2(Y, X); |
| | | double Hyp = Math.sqrt(X * X + Y * Y); |
| | | double Lat = Math.atan2(Z, Hyp); |
| | | |
| | | double rsLon = Lon * 180 / Math.PI; |
| | | double rsLat = Lat * 180 / Math.PI; |
| | |
| | | double p_x =Double.parseDouble(X); |
| | | double p_y =Double.parseDouble(Y); |
| | | Point2D.Double point = new Point2D.Double(p_x, p_y); |
| | | |
| | | List<Point2D.Double> pointList= new ArrayList<Point2D.Double>(); |
| | | |
| | | for (String[] strings : doubleArrayList) { |
| | | double polygonPoint_x=Double.parseDouble(strings[0]); |
| | | double polygonPoint_y=Double.parseDouble(strings[1]); |
| | |
| | | |
| | | } |
| | | |
| | | public final static double x_pi = 3.14159265358979324 * 3000.0 / 180.0; |
| | | public boolean isInPolygon(String X,String Y,double x1,double x2,double y1,double y2){ |
| | | boolean result = false; |
| | | double x =Double.parseDouble(X); |
| | | double y =Double.parseDouble(Y); |
| | | if(x >= Math.min(x1, x2) && x <= Math.max(x1, x2) ){ |
| | | if(y >= Math.min(y1, y2) && y <= Math.max(y1, y2)){ |
| | | result = true; |
| | | } |
| | | } |
| | | return result; |
| | | |
| | | /** |
| | | * 高德坐标转百度坐标 |
| | | * |
| | | * @param gd_lon 经度 |
| | | * @param gd_lat 纬度 |
| | | * @return |
| | | */ |
| | | public static Map<String, String> gd2bd(String gd_lon, String gd_lat) { |
| | | double longitude = Double.parseDouble(gd_lon); |
| | | double latitude = Double.parseDouble(gd_lat); |
| | | Map<String, String> data = new HashMap<>(); |
| | | double x = longitude, y = latitude; |
| | | double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi); |
| | | double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi); |
| | | double bd_lon = z * Math.cos(theta) + 0.0065; |
| | | double bd_lat = z * Math.sin(theta) + 0.006; |
| | | data.put("lon", String.valueOf(bd_lon)); |
| | | data.put("lat", String.valueOf(bd_lat)); |
| | | return data; |
| | | } |
| | | |
| | | } |