Util.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 = Math.Floor(double.Parse(fTemperature)).ToString(), 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, string date)
  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(),date });
  58. var temp = JsonConvert.DeserializeObject<Temperature>(response);
  59. Console.WriteLine(response);
  60. if (temp.code != 200)
  61. {
  62. temp.value = 20 + 273.15;
  63. }
  64. return temp.value - 273.15;
  65. }
  66. }