Util.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using BHJD.DEMdll.Public;
  2. using Newtonsoft.Json;
  3. namespace SimulationCommon;
  4. public class Util
  5. {
  6. public static string serverIp = "10.130.100.5";
  7. public static string baseURl = $"http://{serverIp}:7785//";
  8. public static Fuel GetFuel(string fName, string fType, string fState, string fTemperature, string fHeight, string fWeight)
  9. {
  10. Console.WriteLine($"fName:{fName},fType:{fType},fState:{fState},fTemperature:{fTemperature},fHeight:{fHeight},fWeight:{fWeight}");
  11. IHttpHelper.HttpCmd cmd = new IHttpHelper.HttpCmd
  12. {
  13. m_RequestType = IHttpHelper.HttpRequestType.POST,
  14. m_Addr = $"{baseURl}rescue-platform-service/api/v1/tbTables/queryOilConsumeInfo",
  15. };
  16. HttpHelper m_HttpHelper = new HttpHelper();
  17. string json = JsonConvert.SerializeObject(new
  18. {
  19. fname = fName, ftype = fType, fstate = fState, ftemperature = fTemperature, fheight = fHeight,
  20. fweight = fWeight
  21. });
  22. Fuel fuel = null;
  23. try
  24. {
  25. string response = m_HttpHelper.HttpPost(cmd, json);
  26. var fuelDb = JsonConvert.DeserializeObject<FuelDB>(response);
  27. if (fuelDb.data.Count > 0)
  28. fuel = fuelDb.data[0];
  29. else
  30. {
  31. //Console.WriteLine($"没有找到【{json}】对应的油耗信息");
  32. }
  33. }
  34. catch (Exception e)
  35. {
  36. //Console.WriteLine($"没有找到【{json}】对应的油耗信息");
  37. }
  38. return fuel;
  39. }
  40. /// <summary>
  41. /// 获取当前位置的温度
  42. /// </summary>
  43. /// <param name="varName"></param>
  44. /// <param name="lon"></param>
  45. /// <param name="lat"></param>
  46. /// <param name="data"></param>
  47. /// <returns></returns>
  48. public static double GetTemperature(double lon, double lat)
  49. {
  50. IHttpHelper.HttpCmd cmd = new IHttpHelper.HttpCmd
  51. {
  52. m_RequestType = IHttpHelper.HttpRequestType.GET,
  53. m_Addr = $"{baseURl}rescue-platform-service/api/v1/attribute/getInfos",
  54. m_Args = new List<string> { "varName","centerLon","centerLat","weather_date" }
  55. };
  56. HttpHelper m_HttpHelper = new HttpHelper();
  57. string response = m_HttpHelper.Request(cmd, new List<string> { "t2m",lon.ToString(),lat.ToString(),"2024-01-01 12:00:00" });
  58. var temp = JsonConvert.DeserializeObject<Temperature>(response);
  59. Console.WriteLine(response);
  60. return temp.value - 273;
  61. }
  62. }