parent
bc715a35e4
commit
b5f2cd0a75
@ -0,0 +1,46 @@
|
||||
using HybirdFrameworkCore.Entity;
|
||||
using log4net;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Service.Execute.Model;
|
||||
|
||||
namespace Service.Execute.Api;
|
||||
|
||||
public class ChargeApi
|
||||
{
|
||||
private static readonly ILog Log = LogManager.GetLogger(typeof(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("StopCharge");
|
||||
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);
|
||||
if (succ.IsSuccess)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
using HybirdFrameworkCore.Autofac.Attribute;
|
||||
using log4net;
|
||||
using Service.Execute;
|
||||
using Service.Plc.Client;
|
||||
|
||||
namespace Service.Mgr;
|
||||
|
||||
[Scope("SingleInstance")]
|
||||
public class PlcTaskMgr
|
||||
{
|
||||
private static readonly ILog Log = LogManager.GetLogger(typeof(PlcTaskMgr));
|
||||
|
||||
|
||||
|
||||
public bool QueryPlcTask(int taskNo, int ingStatus, int exceptionStatus)
|
||||
{
|
||||
Log.Info($"PlcTaskMgr.QueryPlcTask taskNo={taskNo}");
|
||||
bool isSuccess = false;
|
||||
|
||||
InvokeStatus invokeStatus = Invoker.Invoke("QueryPlcTask", 1000, 5,
|
||||
() => isSuccess, () =>
|
||||
{
|
||||
var readPlcTaskStatus = PlcMgr.ReadPlcTaskStatus();
|
||||
if (ingStatus == readPlcTaskStatus)
|
||||
{
|
||||
}
|
||||
else if (exceptionStatus == readPlcTaskStatus)
|
||||
{
|
||||
Log.Info(
|
||||
$"PlcTaskMgr.QueryPlcTask taskNo={taskNo} execute fail readPlcTaskStatus={readPlcTaskStatus}");
|
||||
throw new Exception("PlcTaskMgr.QueryPlcTask readPlcTaskStatus=" + readPlcTaskStatus);
|
||||
}
|
||||
else if (9000 == readPlcTaskStatus)
|
||||
{
|
||||
isSuccess = true;
|
||||
}
|
||||
}, () => { Log.Info($"PlcTaskMgr.QueryPlcTask taskNo={taskNo} execute ing"); }, true, () => { }
|
||||
, 5, InvokeStatus.Exception);
|
||||
|
||||
if (InvokeStatus.Exception == invokeStatus)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in new issue