package com.hxzkappboot.controller; import com.hxzkappboot.pojo.GpsGuiJi; import com.hxzkappboot.pojo.TbMarsHomeset; import com.hxzkappboot.service.GpsGuiJiService; import com.hxzkappboot.service.TbMarsHomesetService; import com.hxzkappboot.util.GnssToXY; import com.hxzkappboot.util.R; import com.hxzkappboot.util.StatusCode; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.Duration; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; @RestController //@RequestMapping("/") public class GpsGuiJiController { private Integer tps = 0; @Autowired GpsGuiJiService gpsGuiJiService; @Autowired TbMarsHomesetService marsHomeSetService; // @Autowired // SettingService settingService; // @GetMapping("findGuiJiTrack") // result> findshishigaojing(Integer page, Integer limit){ // LocalDate currentDate = LocalDate.now(); // DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd"); // String formattedDate = currentDate.format(formatter); // PageInfo cz= gpsGuiJiService.findAll(page,limit,formattedDate); // return resultutil.returnSuccess(cz.getTotal(), cz.getList()); // } @GetMapping({"/api/wx/findBaiDuGuiJi"}) R findBaiDuGuiJi(String tagid, String start, String end, String layer) throws ParseException { String output = tagid.toUpperCase();//将小写字母转成大写字母 R response ; response = new R(StatusCode.Success); new ArrayList(); List gui; if (layer.equals("默认地图")) { gui = this.gpsGuiJiService.findGuiJi(output, start, end); } else { gui = this.gpsGuiJiService.findGuiJiFloor(output, start, end, layer); } List disTime = this.marsHomeSetService.findDistanceAndTime(); Integer distance = Integer.valueOf(((TbMarsHomeset)disTime.get(0)).getDistance()); response.setData(this.addHashMap(gui, distance * 100, Integer.parseInt(((TbMarsHomeset)disTime.get(0)).getTime()))); return response; } public String gettime(){ Date now = new Date(); // 创建日期格式化对象,设置格式为 "yyyy-MM-dd HH:mm" SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); // 格式化日期对象,输出字符串结果 String formattedDate = sdf.format(now); return formattedDate; } public static double[] gpstodu(String gps_weidu, String gps_jingdu) { double[] a = new double[]{0.0, 0.0}; String weidu = todufen(gps_weidu.substring(0, 2), gps_weidu.substring(2, 4), gps_weidu.substring(4)); String jingdu = todufen(gps_jingdu.substring(0, 3), gps_jingdu.substring(3, 5), gps_jingdu.substring(5)); a[0] = Double.parseDouble(weidu); a[1] = Double.parseDouble(jingdu); return a; } private Map> addHashMap(List list, int pointDis, int timeC) { String latPast = ""; String lonPast = ""; String timePast = ""; Map> map = new HashMap(); List vector = null; int key = 0; int i = 0; String time; for(Iterator var11 = list.iterator(); var11.hasNext(); timePast = time) { GpsGuiJi info = (GpsGuiJi)var11.next(); String lat = info.getGpsWeidu(); String lon = info.getGspJingdu(); time = info.getAddtime(); if (latPast.length() > 0 && timePast.length() > 0) { int distance = GnssToXY.distance(lon, lat, lonPast, latPast); long cha = calculateTimeDifferenceInSeconds(timePast, time); if (distance < pointDis && cha < (long)timeC) { vector.add(info); } else if (cha > (long)timeC) { vector = new ArrayList(); map.put(key, vector); vector.add(info); ++key; } else if (distance > pointDis && cha < (long)timeC) { vector = new ArrayList(); map.put(key, vector); vector.add(info); ++key; } } else { vector = new ArrayList(); vector.add(info); map.put(key, vector); ++key; } latPast = lat; lonPast = lon; } return map; } public static long calculateTimeDifferenceInSeconds(String timeStr1, String timeStr2) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); LocalDateTime time1 = LocalDateTime.parse(timeStr1, formatter); LocalDateTime time2 = LocalDateTime.parse(timeStr2, formatter); Duration duration = Duration.between(time1, time2); return duration.getSeconds(); } public static String todufen(String Du, String Fen, String Miao) { Float strDu = Float.valueOf(Du); Float strFen = Float.valueOf(Fen) / 60.0F; Float strMiao = Float.valueOf(Miao) / 60.0F; Float dufenmiao = strDu + strFen + strMiao; String format = String.format("%.6f", dufenmiao); return format; } // public void Languages(){ // List setting = settingService.FindSetting(); // if (setting.get(0).getLanguages().equals("0")){ // tps = 0; // } // if (setting.get(0).getLanguages().equals("2")){ // tps = 2; // } // } }