Util.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 string 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. string result = string.Empty;
  70. for (int i = 0; i < yl.data.Length; i++)
  71. {
  72. //Console.WriteLine(yl.data[i].fValue);
  73. result += yl.data[i].fValue;
  74. if (i != yl.data.Length - 1)
  75. result += "-";
  76. }
  77. return result;
  78. }
  79. public static Weather GetWeather(string province_name, string city_name, string data)
  80. {
  81. string content = HttpManager.Get(HttpInterface.weather, new List<string>
  82. {
  83. "province_name","city_name","weather_date"
  84. }, new List<string>
  85. {
  86. province_name,city_name,data
  87. });
  88. var weather = JsonHelper.FromJson<WeatherDB>(content);
  89. var result = JsonHelper.FromJson<WeatherData>(weather.data).result;
  90. return result;
  91. }
  92. public static double GetSlope(double lon, double lat, int gridCount)
  93. {
  94. string content = HttpManager.Get(HttpInterface.slope, new List<string>
  95. {
  96. "lon","lat","gridCount"
  97. }, new List<string>
  98. {
  99. lon.ToString(),lat.ToString(),gridCount.ToString()
  100. });
  101. var slope = JsonHelper.FromJson<SlopeDb>(content);
  102. return Math.Atan(Math.Abs(slope.average.s1)) * (180.0 / Math.PI);
  103. }
  104. /// <summary>
  105. /// 获取当前位置的温度
  106. /// </summary>
  107. /// <param name="varName"></param>
  108. /// <param name="lon"></param>
  109. /// <param name="lat"></param>
  110. /// <param name="data"></param>
  111. /// <returns></returns>
  112. public static double GetTemperature(double lon, double lat)
  113. {
  114. string content = HttpManager.Get(HttpInterface.temperature, new List<string>
  115. {
  116. "varName","centerLon","centerLat","weather_date"
  117. }, new List<string>
  118. {
  119. "t2m",lon.ToString(),lat.ToString(),"2024-01-01 12:00:00"
  120. });
  121. var temp = JsonHelper.FromJson<Temperature>(content);
  122. return temp.vale - 273;
  123. }
  124. //
  125. public static Fuel GetFuel(string fName, string fType, string fState, string fTemperature, string fHeight, string fWeight)
  126. {
  127. string content = HttpManager.Get(HttpInterface.fuel, new List<string>
  128. {
  129. "fname","ftype","fstate","ftemperature","fheight","fweight"
  130. }, new List<string>
  131. {
  132. fName,fType,fState,fTemperature,fHeight,fWeight
  133. });
  134. var fuel = JsonHelper.FromJson<FuelDB>(content);
  135. return fuel.data[0];
  136. }
  137. public static EntitySheetReportValue GetSheetReportValue(string name, Dictionary<string, Dictionary<string, List<string>>> report)
  138. {
  139. EntitySheetReportValue aircraftValue = new EntitySheetReportValue();
  140. aircraftValue.Name = name;
  141. //每架飞机的所有sheet
  142. foreach (var kv1 in report)
  143. {
  144. SheetReportValue sheetValue = new SheetReportValue();
  145. sheetValue.Name = kv1.Key;
  146. aircraftValue.SheetReportValueArr.Add(sheetValue);
  147. //每个sheet的所有数据
  148. foreach (var kv2 in kv1.Value)
  149. {
  150. ReportValue reportValue = new ReportValue();
  151. reportValue.Name = kv2.Key;
  152. reportValue.Value = kv2.Value.First();
  153. sheetValue.ValueArr.Add(reportValue);
  154. }
  155. }
  156. return aircraftValue;
  157. }
  158. }