You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
2.4 KiB
85 lines
2.4 KiB
using HybirdFrameworkCore.Entity;
|
|
using log4net;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using Service.Execute.Model;
|
|
|
|
namespace Service.Execute.Api;
|
|
/// <summary>
|
|
/// chargeApi
|
|
/// </summary>
|
|
public class ChargeApi
|
|
{
|
|
private static readonly ILog Log = LogManager.GetLogger("ChargeApi");
|
|
|
|
private static readonly string BASE_URL = "http://localhost:5035";
|
|
|
|
private static readonly HttpClient _httpClient = new HttpClient()
|
|
{
|
|
Timeout = TimeSpan.FromSeconds(60)
|
|
};
|
|
|
|
public static async Task<bool> StopCharge(string binNo)
|
|
{
|
|
Log.Info($" ChargeApi StopCharge binNo={binNo}");
|
|
string url = BASE_URL + "/api/Charge/StopChargeByBinNo/" + binNo;
|
|
try
|
|
{
|
|
string s = await _httpClient.GetStringAsync(url);
|
|
if (!String.IsNullOrWhiteSpace(s))
|
|
{
|
|
Result<bool>? succ = JsonConvert.DeserializeObject<Result<bool>>(s);
|
|
Log.Info($" ChargeApi StopCharge binNo={binNo} resp={succ.IsSuccess}");
|
|
|
|
if (succ.IsSuccess)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error($" ChargeApi StopCharge binNo={binNo} ,e={e}");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 辅源
|
|
/// </summary>
|
|
/// <param name="binNo">充电机编号</param>
|
|
/// <param name="openFlag">辅源1开2关</param>
|
|
/// <returns></returns>
|
|
public static async Task<bool> SendAuxiliaryPower(string binNo, byte openFlag)
|
|
{
|
|
Log.Info($" ChargeApi AuxiliarySource binNo={binNo} openFlag={openFlag}");
|
|
string url = BASE_URL + $"/api/Charge/SendAuxiliaryPower?binNo={binNo}&openFlag={openFlag}";
|
|
try
|
|
{
|
|
string s = await _httpClient.GetStringAsync(url);
|
|
if (!String.IsNullOrWhiteSpace(s))
|
|
{
|
|
Result<bool>? succ = JsonConvert.DeserializeObject<Result<bool>>(s);
|
|
Log.Info($" ChargeApi StopCharge binNo={binNo} resp={succ.IsSuccess}");
|
|
|
|
if (succ.IsSuccess)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error($" ChargeApi StopCharge binNo={binNo} ,e={e}");
|
|
return false;
|
|
}
|
|
}
|
|
} |