12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using BHJD.DEMdll.Public;
- using Newtonsoft.Json;
- namespace SimulationCommon;
- public class Util
- {
- public static string serverIp = "10.130.100.5";
- public static string baseURl = $"http://{serverIp}:7785//";
-
- public static Fuel GetFuel(string fName, string fType, string fState, string fTemperature, string fHeight, string fWeight)
- {
- //Console.WriteLine($"fName:{fName},fType:{fType},fState:{fState},fTemperature:{fTemperature},fHeight:{fHeight},fWeight:{fWeight}");
- IHttpHelper.HttpCmd cmd = new IHttpHelper.HttpCmd
- {
- m_RequestType = IHttpHelper.HttpRequestType.POST,
- m_Addr = $"{baseURl}rescue-platform-service/api/v1/tbTables/queryOilConsumeInfo",
- };
- HttpHelper m_HttpHelper = new HttpHelper();
- string json = JsonConvert.SerializeObject(new
- {
- fname = fName, ftype = fType, fstate = fState, ftemperature = Math.Floor(double.Parse(fTemperature)).ToString(), fheight = fHeight,
- fweight = fWeight
- });
- Fuel fuel = null;
- try
- {
- string response = m_HttpHelper.HttpPost(cmd, json);
- var fuelDb = JsonConvert.DeserializeObject<FuelDB>(response);
- if (fuelDb.data.Count > 0)
- fuel = fuelDb.data[0];
- else
- {
- //Console.WriteLine($"没有找到【{json}】对应的油耗信息");
- }
- }
- catch (Exception e)
- {
- //Console.WriteLine($"没有找到【{json}】对应的油耗信息");
- }
- return fuel;
- }
-
- /// <summary>
- /// 获取当前位置的温度
- /// </summary>
- /// <param name="varName"></param>
- /// <param name="lon"></param>
- /// <param name="lat"></param>
- /// <param name="data"></param>
- /// <returns></returns>
- public static double GetTemperature(double lon, double lat, string date)
- {
- IHttpHelper.HttpCmd cmd = new IHttpHelper.HttpCmd
- {
- m_RequestType = IHttpHelper.HttpRequestType.GET,
- m_Addr = $"{baseURl}rescue-platform-service/api/v1/attribute/getInfos",
- m_Args = new List<string> { "varName","centerLon","centerLat","weather_date" }
- };
-
- HttpHelper m_HttpHelper = new HttpHelper();
- string response = m_HttpHelper.Request(cmd, new List<string> { "t2m",lon.ToString(),lat.ToString(),date });
- var temp = JsonConvert.DeserializeObject<Temperature>(response);
- Console.WriteLine(response);
- if (temp.code != 200)
- {
- temp.value = 20 + 273.15;
- }
- return temp.value - 273.15;
- }
- }
|