Util.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. using System.Runtime.CompilerServices;
  2. using System.Text.Json.Nodes;
  3. using KYFramework;
  4. using KYFramework.Network;
  5. using Model;
  6. using SimulationCommon;
  7. using SimulationSingleServer.Utils;
  8. namespace SimulationServer.Utils;
  9. public class Util
  10. {
  11. public static double GetDistance(double lon1, double lon2, double lat1, double lat2)
  12. {
  13. double R = 6371; // 地球的半径(公里)
  14. double dLat = (lat2 - lat1) * Math.PI / 180.0;
  15. double dLon = (lon2 - lon1) * Math.PI / 180.0;
  16. double a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) +
  17. Math.Cos(lat1 * Math.PI / 180.0) * Math.Cos(lat2 * Math.PI / 180.0) *
  18. Math.Sin(dLon / 2) * Math.Sin(dLon / 2);
  19. double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
  20. double distance = R * c;
  21. return distance;
  22. }
  23. /// <summary>
  24. /// 根据 shape 解析出 经纬度
  25. /// </summary>
  26. /// <param name="shape"></param>
  27. /// <returns></returns>
  28. public static double[] Checkout(string shape)
  29. {
  30. string s = shape.Replace("POINT(", "").Replace(")", "");
  31. string[] tmps = s.Split(" ");
  32. double[] result = new double[tmps.Length];
  33. for (int i = 0; i < tmps.Length; i++)
  34. {
  35. result[i] = double.Parse(tmps[i]);
  36. }
  37. return result;
  38. }
  39. public static AircraftDB GetAircraftDefine(string aircraftType, string aircraftSubType, string aircraftID)
  40. {
  41. string content = HttpManager.Get(HttpInterface.aircraft ,new List<string>
  42. {
  43. "fType","fSubtype","fName","limit"
  44. }, new List<string>
  45. {
  46. aircraftType,aircraftSubType,aircraftID,"1"
  47. });
  48. //Log.Debug($"Type = {aircraftType}, SubType = {aircraftSubType}, ID = {aircraftID}");
  49. var define = JsonHelper.FromJson<AircraftDefine>(content);
  50. if (define.zs.Count == 0)
  51. {
  52. //Log.Debug($"没有找到对应 [{aircraftID}] 的飞机信息");
  53. return new AircraftDB();
  54. }
  55. return define.zs[0];
  56. }
  57. // 医疗
  58. public static YLDBData GetYL(string id)
  59. {
  60. string content = HttpManager.Get(HttpInterface.yl, new List<string>
  61. {
  62. "fSubtypeId","recordId" // "fScene","fName","fSubtypeId","limit"
  63. }, new List<string>
  64. {
  65. "136",id //"航空医疗","","136","10"
  66. });
  67. Console.WriteLine("YL:" + content);
  68. var yl = JsonHelper.FromJson<YLDB>(content);
  69. var result = JsonHelper.FromJson<YLDBData>(yl.data);
  70. return result;
  71. }
  72. public static Weather GetWeather(string province_name, string city_name, string data)
  73. {
  74. string content = HttpManager.Get(HttpInterface.weather ,new List<string>
  75. {
  76. "province_name","city_name","weather_date"
  77. }, new List<string>
  78. {
  79. province_name,city_name,data
  80. });
  81. var weather = JsonHelper.FromJson<WeatherDB>(content);
  82. var result = JsonHelper.FromJson<WeatherData>(weather.data).result;
  83. return result;
  84. }
  85. public static double GetSlope(double lon, double lat, int gridCount)
  86. {
  87. string content = HttpManager.Get(HttpInterface.slope ,new List<string>
  88. {
  89. "lon","lat","gridCount"
  90. }, new List<string>
  91. {
  92. lon.ToString(),lat.ToString(),gridCount.ToString()
  93. });
  94. var slope = JsonHelper.FromJson<SlopeDb>(content);
  95. return Math.Atan(Math.Abs(slope.average.s1)) * (180.0 / Math.PI);
  96. }
  97. /// <summary>
  98. /// 获取当前位置的温度
  99. /// </summary>
  100. /// <param name="varName"></param>
  101. /// <param name="lon"></param>
  102. /// <param name="lat"></param>
  103. /// <param name="data"></param>
  104. /// <returns></returns>
  105. public static double GetTemperature(double lon, double lat)
  106. {
  107. string content = HttpManager.Get(HttpInterface.temperature ,new List<string>
  108. {
  109. "varName","centerLon","centerLat","weather_date"
  110. }, new List<string>
  111. {
  112. "t2m",lon.ToString(),lat.ToString(),"2024-01-01 12:00:00"
  113. });
  114. var temp = JsonHelper.FromJson<Temperature>(content);
  115. return temp.vale - 273;
  116. }
  117. //
  118. public static Fuel GetFuel(string fName, string fType, string fState, string fTemperature, string fHeight, string fWeight)
  119. {
  120. string content = HttpManager.Get(HttpInterface.fuel ,new List<string>
  121. {
  122. "fname","ftype","fstate","ftemperature","fheight","fweight"
  123. }, new List<string>
  124. {
  125. fName,fType,fState,fTemperature,fHeight,fWeight
  126. });
  127. var fuel = JsonHelper.FromJson<FuelDB>(content);
  128. return fuel.data[0];
  129. }
  130. public static EntitySheetReportValue GetSheetReportValue(string name,Dictionary<string, Dictionary<string, List<string>>> report)
  131. {
  132. EntitySheetReportValue aircraftValue = new EntitySheetReportValue();
  133. aircraftValue.Name = name;
  134. //每架飞机的所有sheet
  135. foreach (var kv1 in report)
  136. {
  137. SheetReportValue sheetValue = new SheetReportValue();
  138. sheetValue.Name = kv1.Key;
  139. aircraftValue.SheetReportValueArr.Add(sheetValue);
  140. //每个sheet的所有数据
  141. foreach (var kv2 in kv1.Value)
  142. {
  143. ReportValue reportValue = new ReportValue();
  144. reportValue.Name = kv2.Key;
  145. reportValue.Value = kv2.Value.First();
  146. sheetValue.ValueArr.Add(reportValue);
  147. }
  148. }
  149. return aircraftValue;
  150. }
  151. }