2024-07-01 16:52:48 +00:00
|
|
|
|
using CsharpHttpHelper;
|
|
|
|
|
using DeviceRepair.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
2024-07-08 02:44:57 +00:00
|
|
|
|
using DeviceRepair.Utils;
|
2024-07-01 16:52:48 +00:00
|
|
|
|
|
|
|
|
|
namespace DeviceRepairAndOptimization
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 后台任务调度
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class Scheduler
|
|
|
|
|
{
|
|
|
|
|
public delegate void CallBackEventHandler(string args, object value);
|
|
|
|
|
public event CallBackEventHandler CallBack;
|
|
|
|
|
HttpHelper http = new HttpHelper();
|
|
|
|
|
|
|
|
|
|
private static Scheduler scheduler;
|
|
|
|
|
public static Scheduler Instance
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (scheduler == null)
|
|
|
|
|
scheduler = new Scheduler();
|
|
|
|
|
return scheduler;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Dictionary<string, HttpItem> httpItems = new Dictionary<string, HttpItem>
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
"SchedulerPlanTips",new HttpItem { URL = $"http://{DeviceRepair.Utils.Config.Configurations.Properties.ServiceIP}/{DeviceRepair.Utils.Config.Configurations.Properties.ServiceName}/Api/Plan/SchedulerPlanTips"}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"CurrentYearPlanSchedule",new HttpItem { URL = $"http://{DeviceRepair.Utils.Config.Configurations.Properties.ServiceIP}/{DeviceRepair.Utils.Config.Configurations.Properties.ServiceName}/Api/Plan/GetCurrentYearPlanSchedule", ContentType = "application/json;charset=utf-8"}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 启动
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void Run()
|
|
|
|
|
{
|
|
|
|
|
foreach (HttpItem item in httpItems.Values)
|
|
|
|
|
{
|
|
|
|
|
item.Header.Add("auth", GlobalInfo.token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(DateTime.Now.ToLongTimeString());
|
|
|
|
|
GetSchedulerPlanTips();
|
|
|
|
|
GetCurrentYearPlanSchedule();
|
|
|
|
|
Task.Delay(3000).Wait();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取当年度 - 当月待保养计划 - 数量
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected void GetSchedulerPlanTips()
|
|
|
|
|
{
|
|
|
|
|
HttpResult Rtn = http.GetHtml(httpItems["SchedulerPlanTips"]);
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-07-08 02:44:57 +00:00
|
|
|
|
APIResponseData apiResponseData = Rtn.GetApiResponseData();
|
|
|
|
|
if (apiResponseData.IsSuccess)
|
2024-07-01 16:52:48 +00:00
|
|
|
|
{
|
|
|
|
|
CallBack?.Invoke("SchedulerPlanTips", apiResponseData.Data);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CallBack?.Invoke("SchedulerPlanTips", apiResponseData.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
CallBack?.Invoke("SchedulerPlanTips", HttpHelper.StripHTML(Rtn.Html));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void GetCurrentYearPlanSchedule()
|
|
|
|
|
{
|
|
|
|
|
HttpResult Rtn = http.GetHtml(httpItems["CurrentYearPlanSchedule"]);
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-07-08 02:44:57 +00:00
|
|
|
|
APIResponseData apiResponseData = Rtn.GetApiResponseData();
|
|
|
|
|
if (apiResponseData.IsSuccess)
|
2024-07-01 16:52:48 +00:00
|
|
|
|
{
|
2024-07-08 02:44:57 +00:00
|
|
|
|
object Value = apiResponseData.ToDeserializeObject<DeviceRepair.Models.Common.CurrentYearPlanSchedule>();
|
2024-07-01 16:52:48 +00:00
|
|
|
|
CallBack?.Invoke("CurrentYearPlanSchedule", Value);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CallBack?.Invoke("CurrentYearPlanSchedule", apiResponseData.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
CallBack?.Invoke("CurrentYearPlanSchedule", HttpHelper.StripHTML(Rtn.Html));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|