using Furion;
|
using Furion.TaskScheduler;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Threading.Tasks;
|
using WIDESEA_Common;
|
using WIDESEA_Common.DBNames;
|
using WIDESEA_Core;
|
using WIDESEA_Core.SqlSuger;
|
using WIDESEA_Core.Utilities;
|
using WIDESEA_Entity;
|
using WIDESEA_Entity.DomainModels;
|
using WIDESEA_WCS.WCSClient;
|
|
namespace WIDESEA_WCS
|
{
|
public class JobWorker : ISpareTimeWorker
|
{
|
private bool _taskScheduler = true;
|
|
public static List<dt_equipmentinfo> equipmentinfos = new List<dt_equipmentinfo>();
|
public static List<Cache> caches = new List<Cache>();
|
public static List<Cache> ZcachesList = new List<Cache>();
|
public static List<Cache> FcachesList = new List<Cache>();
|
|
/// <summary>
|
/// 服务重启
|
/// </summary>
|
/// <param name="timer"></param>
|
/// <param name="count"></param>
|
|
[SpareTime(1000, "StartServer", DoOnce = false, StartNow = true, ExecuteType = SpareTimeExecuteTypes.Serial)]
|
public async Task StartServer(SpareTimer timer, long count)
|
{
|
if (_taskScheduler)
|
{
|
//SpareTime.Cancel("StartServer");
|
WebResponseContent responseContent = WCSService.ConnectServer();
|
if (responseContent.Status)
|
{
|
if (WCSService.Clients.Count > 0)
|
{
|
_taskScheduler = false;
|
await Task.CompletedTask;
|
WriteLogHelper.WriteLog("服务开启", $"开启结果:{responseContent.Message} 开启时间:{DateTime.Now.ToString("F")},服务开启");
|
SpareTime.Cancel("StartServer");
|
}
|
}
|
else
|
{
|
WriteLogHelper.WriteLog("服务开启", $"开启结果:{responseContent.Message} 开启时间:{DateTime.Now.ToString("F")},服务开启");
|
}
|
}
|
}
|
|
/// <summary>
|
/// 每五秒执行
|
/// </summary>
|
/// <param name="timer"></param>
|
/// <param name="count"></param>
|
[SpareTime(5000, "jobName", StartNow = true, ExecuteType = SpareTimeExecuteTypes.Serial)]
|
public async void DoSomething(SpareTimer timer, long count)
|
{
|
PLCClient client = null;
|
caches = new List<Cache>();
|
|
List<Cache> cachess = new List<Cache>();
|
if (WCSService.Clients != null)
|
{
|
if (WCSService.Clients.Count > 0)
|
{
|
client = WCSService.Clients[0];
|
if (client.ConnectionMessage == "拆包间")
|
{
|
int x = client.PLCDBItems.Select(x => x.EquipNum).Select(int.Parse).ToList().Max();
|
for (int i = 1; i < x + 1; i++)
|
{
|
string state = client.ReadValue(AGVDBName.R_AGV_CacheState.ToString() + i, i.ToString()).ToString();
|
Cache cache = new Cache()
|
{
|
cacheNo = i,
|
cacheState = state == "1" ? "有货" : state == "2" ? "无货" : state == "3" ? "待料中" : state == "4" ? "上架中" : state == "5" ? "异常" : "无此缓存架",
|
cacheType = client.ReadValue(AGVDBName.R_AGV_CacheType.ToString() + i, i.ToString()).ToString(),
|
};
|
if (cache.cacheState != "无此缓存架")
|
{
|
caches.Add(cache);
|
}
|
if (cache.cacheState == "无货")
|
{
|
cachess.Add(cache);
|
}
|
}
|
//ChatHub chatHub = new ChatHub();
|
ChatHub chatHub = App.GetService<ChatHub>();
|
await chatHub.SendMessage("ReciveMessage", (caches));
|
await chatHub.SendMessage("SendError", (cachess));
|
}
|
else
|
{
|
SpareTime.Cancel("jobName");
|
}
|
}
|
}
|
}
|
|
/// <summary>
|
/// 每五秒执行 库存
|
/// </summary>
|
/// <param name="timer"></param>
|
/// <param name="count"></param>
|
[SpareTime(5000, "jobName1", StartNow = true, ExecuteType = SpareTimeExecuteTypes.Serial)]
|
public async void SendContainer(SpareTimer timer, long count)
|
{
|
PLCClient client = null;
|
List<Container> containers = new List<Container>();
|
|
if (WCSService.Clients != null)
|
{
|
if (WCSService.Clients.Count > 0)
|
{
|
client = WCSService.Clients[0];
|
if (client.ConnectionMessage == "拆包间")
|
{
|
containers = SqlSugarHelper.WCSDB.Queryable<Container>().ToList();
|
ChatHub chatHub = App.GetService<ChatHub>();
|
await chatHub.SendMessage("SendContainer", (containers));
|
}
|
else
|
{
|
SpareTime.Cancel("jobName1");
|
}
|
}
|
}
|
}
|
|
/// <summary>
|
/// 每五秒执行 投料间
|
/// </summary>
|
/// <param name="timer"></param>
|
/// <param name="count"></param>
|
[SpareTime(5000, "SendFeedingData", StartNow = true, ExecuteType = SpareTimeExecuteTypes.Serial)]
|
public async void SendFeedingData(SpareTimer timer, long count)
|
{
|
PLCClient client = null;
|
|
if (WCSService.Clients != null)
|
{
|
if (WCSService.Clients.Count > 0)
|
{
|
client = WCSService.Clients[0];
|
List<Cache> Zcachess = new List<Cache>();
|
List<Cache> Zcaches = new List<Cache>();
|
List<Cache> Fcachess = new List<Cache>();
|
List<Cache> Fcaches = new List<Cache>();
|
if (client.ConnectionMessage == "投料间")
|
{
|
ChatHub chatHub = App.GetService<ChatHub>();
|
int xz = client.PLCDBItems.Where(x => x.ItemName.Contains(AGVDBName.R_AGV_CacheStateZ.ToString())).Select(x => x.EquipNum).Select(int.Parse).ToList().Max();
|
int xf = client.PLCDBItems.Where(x => x.ItemName.Contains(AGVDBName.R_AGV_CacheStateF.ToString())).Select(x => x.EquipNum).Select(int.Parse).ToList().Max();
|
for (int i = 1; i < xz + 1; i++)
|
{
|
string state = client.ReadValue(AGVDBName.R_AGV_CacheStateZ.ToString() + i, i.ToString()).ToString();
|
Cache cache = new Cache()
|
{
|
cacheNo = i,
|
cacheState = state == "1" ? "有货" : state == "2" ? "无货" : state == "3" ? "待料中" : state == "4" ? "上架中" : state == "5" ? "异常" : "无此缓存架",
|
//cacheState = "无货",
|
cacheType = client.ReadValue(AGVDBName.R_AGV_CacheTypeZ.ToString() + i, i.ToString()).ToString(),
|
};
|
if (cache.cacheState != "无此缓存架")
|
{
|
Zcaches.Add(cache);
|
}
|
if (cache.cacheState == "无货")
|
{
|
Zcachess.Add(cache);
|
}
|
}
|
await chatHub.SendMessage("SendZFeedingData", Zcaches);
|
await chatHub.SendMessage("SendZError", Zcachess);
|
ZcachesList = Zcachess;
|
for (int i = 1; i < xf + 1; i++)
|
{
|
string state = client.ReadValue(AGVDBName.R_AGV_CacheStateF.ToString() + i, i.ToString()).ToString();
|
Cache cache = new Cache()
|
{
|
cacheNo = i,
|
cacheState = state == "1" ? "有货" : state == "2" ? "无货" : state == "3" ? "待料中" : state == "4" ? "上架中" : state == "5" ? "异常" : "无此缓存架",
|
cacheType = client.ReadValue(AGVDBName.R_AGV_CacheTypeF.ToString() + i, i.ToString()).ToString(),
|
};
|
if (cache.cacheState != "无此缓存架")
|
{
|
Fcaches.Add(cache);
|
}
|
if (cache.cacheState == "无货")
|
{
|
Fcachess.Add(cache);
|
}
|
}
|
await chatHub.SendMessage("SendFFeedingData", Fcaches);
|
await chatHub.SendMessage("SendFError", Fcachess);
|
FcachesList = Fcachess;
|
}
|
else
|
{
|
SpareTime.Cancel("SendFeedingData");
|
}
|
}
|
}
|
}
|
}
|
}
|