using System.Runtime.CompilerServices; using System.Text.Json.Nodes; using KYFramework; using KYFramework.Network; using Model; using SimulationCommon; using SimulationSingleServer.Utils; namespace SimulationServer.Utils; public class Util { public static double GetDistance(double lon1, double lon2, double lat1, double lat2) { double R = 6371; // 地球的半径(公里) double dLat = (lat2 - lat1) * Math.PI / 180.0; double dLon = (lon2 - lon1) * Math.PI / 180.0; double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) + Math.Cos(lat1 * Math.PI / 180.0) * Math.Cos(lat2 * Math.PI / 180.0) * Math.Sin(dLon / 2) * Math.Sin(dLon / 2); double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)); double distance = R * c; return distance; } /// /// 根据 shape 解析出 经纬度 /// /// /// public static double[] Checkout(string shape) { string s = shape.Replace("POINT(", "").Replace(")", ""); string[] tmps = s.Split(" "); double[] result = new double[tmps.Length]; for (int i = 0; i < tmps.Length; i++) { result[i] = double.Parse(tmps[i]); } return result; } public static AircraftDB GetAircraftDefine(string aircraftType, string aircraftSubType, string aircraftID) { string content = HttpManager.Get(HttpInterface.aircraft, new List { "fType","fSubtype","fName","limit" }, new List { aircraftType,aircraftSubType,aircraftID,"1" }); //Log.Debug($"Type = {aircraftType}, SubType = {aircraftSubType}, ID = {aircraftID}"); var define = JsonHelper.FromJson(content); if (define.zs.Count == 0) { //Log.Debug($"没有找到对应 [{aircraftID}] 的飞机信息"); return new AircraftDB(); } return define.zs[0]; } // 医疗 public static string GetYL(string id) { string content = HttpManager.Get(HttpInterface.yl, new List { "fSubtypeId","recordId" // "fScene","fName","fSubtypeId","limit" }, new List { "136",id //"航空医疗","","136","10" }); //Console.WriteLine("YL:" + content); var yl = JsonHelper.FromJson(content); string result = string.Empty; for (int i = 0; i < yl.data.Length; i++) { //Console.WriteLine(yl.data[i].fValue); result += yl.data[i].fValue; if (i != yl.data.Length - 1) result += "-"; } return result; } public static Weather GetWeather(string province_name, string city_name, string data) { string content = HttpManager.Get(HttpInterface.weather, new List { "province_name","city_name","weather_date" }, new List { province_name,city_name,data }); var weather = JsonHelper.FromJson(content); var result = JsonHelper.FromJson(weather.data).result; return result; } public static double GetSlope(double lon, double lat, int gridCount) { string content = HttpManager.Get(HttpInterface.slope, new List { "lon","lat","gridCount" }, new List { lon.ToString(),lat.ToString(),gridCount.ToString() }); var slope = JsonHelper.FromJson(content); return Math.Atan(Math.Abs(slope.average.s1)) * (180.0 / Math.PI); } /// /// 获取当前位置的温度 /// /// /// /// /// /// public static double GetTemperature(double lon, double lat) { string content = HttpManager.Get(HttpInterface.temperature, new List { "varName","centerLon","centerLat","weather_date" }, new List { "t2m",lon.ToString(),lat.ToString(),"2024-01-01 12:00:00" }); var temp = JsonHelper.FromJson(content); return temp.vale - 273; } // public static Fuel GetFuel(string fName, string fType, string fState, string fTemperature, string fHeight, string fWeight) { string content = HttpManager.Get(HttpInterface.fuel, new List { "fname","ftype","fstate","ftemperature","fheight","fweight" }, new List { fName,fType,fState,fTemperature,fHeight,fWeight }); var fuel = JsonHelper.FromJson(content); return fuel.data[0]; } public static EntitySheetReportValue GetSheetReportValue(string name, Dictionary>> report) { EntitySheetReportValue aircraftValue = new EntitySheetReportValue(); aircraftValue.Name = name; //每架飞机的所有sheet foreach (var kv1 in report) { SheetReportValue sheetValue = new SheetReportValue(); sheetValue.Name = kv1.Key; aircraftValue.SheetReportValueArr.Add(sheetValue); //每个sheet的所有数据 foreach (var kv2 in kv1.Value) { ReportValue reportValue = new ReportValue(); reportValue.Name = kv2.Key; reportValue.Value = kv2.Value.First(); sheetValue.ValueArr.Add(reportValue); } } return aircraftValue; } }