|
|
|
@ -113,7 +113,8 @@ namespace Aucma.Scada.Business
|
|
|
|
|
_recordProductfinishService = registerServices.GetService<IRecordProductfinishService>();
|
|
|
|
|
|
|
|
|
|
assemblyPlanBusiness.NextPassExecutePlanInfoEvent += PlanHandle;
|
|
|
|
|
taskHandleBusiness.OutStoreFinsihEvent += TaskFeedback;
|
|
|
|
|
taskHandleBusiness.OutStoreAnswerEvent += OutStoreAnswer;
|
|
|
|
|
taskHandleBusiness.OutStoreFinsihEvent += OutStoreFinish;
|
|
|
|
|
StartPassDown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -305,25 +306,125 @@ namespace Aucma.Scada.Business
|
|
|
|
|
|
|
|
|
|
private int taskAmount = 2;
|
|
|
|
|
|
|
|
|
|
private SemaphoreSlim shellSemaphore = new SemaphoreSlim(0);
|
|
|
|
|
|
|
|
|
|
private SemaphoreSlim linerSemaphore = new SemaphoreSlim(0);
|
|
|
|
|
|
|
|
|
|
private void StartPassDown()
|
|
|
|
|
{
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
PassDownTaskInfo();
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
PassDownShellTask();
|
|
|
|
|
Thread.Sleep(2000);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
PassDownLinerTask();
|
|
|
|
|
Thread.Sleep(2000);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 下传箱壳出库任务至PLC
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void PassDownShellTask()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//获取箱壳出库任务
|
|
|
|
|
RealTaskInfo taskInfo = _taskInfoService.GetTaskInfoByStoreCode(appConfig.shellStoreCode, appConfig.outstoreTaskType);
|
|
|
|
|
|
|
|
|
|
if(taskInfo != null)
|
|
|
|
|
{
|
|
|
|
|
PrintLogInfoMessage($"下发箱壳出库任务:{taskInfo.taskCode};仓库{taskInfo.storeCode};货道:{taskInfo.spaceCode}");
|
|
|
|
|
|
|
|
|
|
if (taskHandleBusiness.SendShellTask_OutStore(taskInfo))
|
|
|
|
|
{
|
|
|
|
|
PrintLogInfoMessage($"箱壳出库任务:{taskInfo.taskCode};下发成功,等待PLC执行反馈");
|
|
|
|
|
|
|
|
|
|
shellSemaphore.Wait(); //一直堵塞直到信号量释放
|
|
|
|
|
|
|
|
|
|
PrintLogInfoMessage($"箱壳入库任务:{taskInfo.taskCode};开始执行");
|
|
|
|
|
|
|
|
|
|
taskInfo.taskStatus = 2;
|
|
|
|
|
|
|
|
|
|
_taskInfoService.UpdateTaskInfo(taskInfo);
|
|
|
|
|
|
|
|
|
|
RefreshScanMateriaCodeEvent?.Invoke(taskInfo.materialCode, taskInfo.materialType, taskInfo.spaceName, taskInfo.storeCode);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PrintLogInfoMessage($"箱壳出库任务:{taskInfo.taskCode};下发失败,请排除PLC连接");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PrintLogInfoMessage("未获取到需要下发的箱壳出库任务");
|
|
|
|
|
}
|
|
|
|
|
}catch(Exception ex)
|
|
|
|
|
{
|
|
|
|
|
PrintLogErrorMessage("下传箱壳出库任务逻辑处理异常", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 依次获取内胆任务队列进行下发
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void PassDownLinerTask()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
RealTaskInfo taskInfo = _taskInfoService.GetTaskInfoByStoreCode(appConfig.linerStoreCode, appConfig.outstoreTaskType);
|
|
|
|
|
if (taskInfo != null)
|
|
|
|
|
{
|
|
|
|
|
PrintLogInfoMessage($"下发内胆出库任务:{taskInfo.taskCode};仓库{taskInfo.storeCode};货道:{taskInfo.spaceCode}");
|
|
|
|
|
|
|
|
|
|
if (taskHandleBusiness.SendLinerTask_OutStore(taskInfo))
|
|
|
|
|
{
|
|
|
|
|
PrintLogInfoMessage($"内胆出库任务:{taskInfo.taskCode};下发成功,等待PLC执行反馈");
|
|
|
|
|
|
|
|
|
|
linerSemaphore.Wait(); //一直堵塞直到信号量释放
|
|
|
|
|
|
|
|
|
|
PrintLogInfoMessage($"内胆出库任务:{taskInfo.taskCode};开始执行");
|
|
|
|
|
|
|
|
|
|
taskInfo.taskStatus = 2;
|
|
|
|
|
|
|
|
|
|
_taskInfoService.UpdateTaskInfo(taskInfo);
|
|
|
|
|
|
|
|
|
|
RefreshScanMateriaCodeEvent?.Invoke(taskInfo.materialCode, taskInfo.materialType, taskInfo.spaceName, taskInfo.storeCode);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PrintLogInfoMessage($"内胆出库任务:{taskInfo.taskCode};下发失败,请排除PLC连接");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PrintLogInfoMessage("未获取到需要下发的内胆出库任务");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
PrintLogErrorMessage("下传内胆出库任务逻辑处理异常", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 原任务下发逻辑 Delete By wenjy 2023-11-09 10:20:00 箱壳、内胆任务改为分别下发处理,PLC应答后继续下发新任务
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 依次获取任务队列进行下发
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="source"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void PassDownTaskInfo()
|
|
|
|
|
/*private void PassDownTaskInfo()
|
|
|
|
|
{
|
|
|
|
|
string shellCode = string.Empty;
|
|
|
|
|
string linerCode = string.Empty;
|
|
|
|
@ -375,31 +476,22 @@ namespace Aucma.Scada.Business
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_taskInfoService.UpdateTaskInfo(item);
|
|
|
|
|
RefreshScanMateriaCodeEvent?.Invoke(item.materialCode, item.materialType, item.spaceName, item.storeCode);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (iFlag == taskInfoList.Count)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
//if (semaphore.Wait(TimeSpan.FromSeconds(20)))
|
|
|
|
|
//{
|
|
|
|
|
// // 收到反馈
|
|
|
|
|
// PrintLogInfoMessage("收到反馈,继续执行");
|
|
|
|
|
//}
|
|
|
|
|
//else
|
|
|
|
|
//{
|
|
|
|
|
// PrintLogInfoMessage("超时未反馈");
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
semaphore.Wait(); //一直堵塞直到信号量释放
|
|
|
|
|
|
|
|
|
|
PrintLogInfoMessage($"出库任务:{taskCode};执行完成,绑定箱壳条码:{shellCode};内胆条码:{linerCode}");
|
|
|
|
|
//PrintLogInfoMessage($"出库任务:{taskCode};应答成功,继续下发新任务");
|
|
|
|
|
|
|
|
|
|
var item = taskInfoList.First();
|
|
|
|
|
RefreshScanMateriaCodeEvent?.Invoke(item.materialCode, item.materialType, item.spaceName, item.storeCode);
|
|
|
|
|
|
|
|
|
|
UpdatePlanInfo(executePlanCode);
|
|
|
|
|
//UpdatePlanInfo(executePlanCode);
|
|
|
|
|
|
|
|
|
|
RefreshStoreStockEvent?.Invoke();
|
|
|
|
|
//RefreshStoreStockEvent?.Invoke();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -410,19 +502,19 @@ namespace Aucma.Scada.Business
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Thread.Sleep(3000);
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取待执行的出库任务
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private List<RealTaskInfo> GetAwaitSendTask()
|
|
|
|
|
/*private List<RealTaskInfo> GetAwaitSendTask()
|
|
|
|
|
{
|
|
|
|
|
List<RealTaskInfo> taskInfos = new List<RealTaskInfo>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
RealTaskInfo shellTaskInfo = _taskInfoService.GetTaskInfoByStoreCode(appConfig.shellStoreCode, 2);
|
|
|
|
|
RealTaskInfo shellTaskInfo = _taskInfoService.GetTaskInfoByStoreCode(appConfig.shellStoreCode, appConfig.outstoreTaskType);
|
|
|
|
|
|
|
|
|
|
if (shellTaskInfo != null)
|
|
|
|
|
{
|
|
|
|
@ -433,7 +525,7 @@ namespace Aucma.Scada.Business
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
RealTaskInfo linerInfo = _taskInfoService.GetTaskInfoByStoreCode(appConfig.linerStoreCode, 2);
|
|
|
|
|
RealTaskInfo linerInfo = _taskInfoService.GetTaskInfoByStoreCode(appConfig.linerStoreCode, appConfig.outstoreTaskType);
|
|
|
|
|
if (linerInfo != null) taskInfos.Add(linerInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -448,51 +540,56 @@ namespace Aucma.Scada.Business
|
|
|
|
|
PrintLogErrorMessage("获取待执行的出库任务异常", ex);
|
|
|
|
|
}
|
|
|
|
|
return taskInfos;
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region PLC应答反馈
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// PLC任务执行反馈
|
|
|
|
|
/// 出库应答
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="storeCode"></param>
|
|
|
|
|
/// <param name="taskCode"></param>
|
|
|
|
|
private void TaskFeedback(string storeCode, string taskCode)
|
|
|
|
|
private void OutStoreAnswer(string storeCode, string taskCode)
|
|
|
|
|
{
|
|
|
|
|
if (storeCode == appConfig.shellStoreCode)
|
|
|
|
|
{
|
|
|
|
|
ShellTaskFeedback(taskCode);
|
|
|
|
|
//Interlocked.Increment(ref completedTasks);
|
|
|
|
|
|
|
|
|
|
//CheckCompletedTasks();
|
|
|
|
|
|
|
|
|
|
PrintLogInfoMessage("箱壳应答成功,自动释放信号量,进行下发新任务");
|
|
|
|
|
|
|
|
|
|
shellSemaphore.Release();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
LinerTaskFeedback(taskCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//Interlocked.Increment(ref completedTasks);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 箱壳执行反馈
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void ShellTaskFeedback(string taskCode)
|
|
|
|
|
{
|
|
|
|
|
Interlocked.Increment(ref completedTasks);
|
|
|
|
|
//CheckCompletedTasks();
|
|
|
|
|
|
|
|
|
|
CheckCompletedTasks();
|
|
|
|
|
PrintLogInfoMessage("内胆应答成功,自动释放信号量,进行下发新任务");
|
|
|
|
|
|
|
|
|
|
PrintLogInfoMessage("箱壳执行完成,自动释放信号量");
|
|
|
|
|
|
|
|
|
|
OutStoreFinish(taskCode, appConfig.shellStoreCode);
|
|
|
|
|
linerSemaphore.Release();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 内胆执行反馈
|
|
|
|
|
/// 出库完成
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void LinerTaskFeedback(string taskCode)
|
|
|
|
|
/// <param name="storeCode"></param>
|
|
|
|
|
/// <param name="taskCode"></param>
|
|
|
|
|
private void OutStoreFinish(string storeCode, string taskCode)
|
|
|
|
|
{
|
|
|
|
|
Interlocked.Increment(ref completedTasks);
|
|
|
|
|
|
|
|
|
|
CheckCompletedTasks();
|
|
|
|
|
|
|
|
|
|
PrintLogInfoMessage("内胆执行完成,自动释放信号量");
|
|
|
|
|
|
|
|
|
|
OutStoreFinish(taskCode, appConfig.linerStoreCode);
|
|
|
|
|
if (storeCode == appConfig.shellStoreCode)
|
|
|
|
|
{
|
|
|
|
|
PrintLogInfoMessage($"箱壳任务:{taskCode};执行完成");
|
|
|
|
|
OutStoreFinishHandle(taskCode, appConfig.shellStoreCode);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PrintLogInfoMessage($"内胆任务:{taskCode};执行完成");
|
|
|
|
|
OutStoreFinishHandle(taskCode, appConfig.linerStoreCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -508,15 +605,13 @@ namespace Aucma.Scada.Business
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 出库完成
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="storeCode"></param>
|
|
|
|
|
/// <param name="spaceCode"></param>
|
|
|
|
|
/// <param name="materialType"></param>
|
|
|
|
|
private void OutStoreFinish(string taskCode, string storeCode)
|
|
|
|
|
private void OutStoreFinishHandle(string taskCode, string storeCode)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
@ -524,11 +619,12 @@ namespace Aucma.Scada.Business
|
|
|
|
|
if (taskInfo != null)
|
|
|
|
|
{
|
|
|
|
|
var spaceInfo = _spaceInfoService.GetSpaceInfoBySpaceCode(taskInfo.storeCode, taskInfo.spaceCode);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (spaceInfo != null)
|
|
|
|
|
{
|
|
|
|
|
taskHandleBusiness.WritePlc(spaceInfo.storeCode, spaceInfo.spaceCode);
|
|
|
|
|
//读取PLC获取货道信息:存放数量、在途数量
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spaceInfo.spaceStock -= 1;
|
|
|
|
|
spaceInfo.outRouteAmount -= 1;
|
|
|
|
|
|
|
|
|
@ -557,6 +653,12 @@ namespace Aucma.Scada.Business
|
|
|
|
|
_recordOutStoreService.InsertReocrdOutStoreService(recordOutstore);
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//更新计划信息
|
|
|
|
|
UpdatePlanInfo(taskInfo.planCode);
|
|
|
|
|
|
|
|
|
|
RefreshStoreStockEvent?.Invoke();
|
|
|
|
|
|
|
|
|
|
//清除任务信息
|
|
|
|
|
_taskInfoService.DeleteTaskInfo(taskCode, storeCode);
|
|
|
|
|
|
|
|
|
@ -700,27 +802,6 @@ namespace Aucma.Scada.Business
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 日志输出,界面刷新同时记录文件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message"></param>
|
|
|
|
|
private void PrintLogInfoMessage(string message)
|
|
|
|
|
{
|
|
|
|
|
RefreshLogMessageEvent?.Invoke(message);
|
|
|
|
|
logHelper.Info(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 异常日志输出
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message"></param>
|
|
|
|
|
/// <param name="ex"></param>
|
|
|
|
|
private void PrintLogErrorMessage(string message, Exception ex = null)
|
|
|
|
|
{
|
|
|
|
|
RefreshLogMessageEvent?.Invoke(message);
|
|
|
|
|
logHelper.Error(message, ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 手动释放信号量
|
|
|
|
|
/// </summary>
|
|
|
|
@ -751,6 +832,7 @@ namespace Aucma.Scada.Business
|
|
|
|
|
return materialName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region 通过PLC读取货道信息
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 通过PLC读取货道信息(在库数量、货道状态)
|
|
|
|
|
/// </summary>
|
|
|
|
@ -763,7 +845,7 @@ namespace Aucma.Scada.Business
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
List<BaseSpaceInfo> info = _spaceInfoService.GetBaseSpaceInfosByMaterialType(storeCode, materialType);
|
|
|
|
|
List<BaseSpaceInfo> info = _spaceInfoService.OutStoreGetSpaceInfoByMaterialCode(storeCode, materialType);
|
|
|
|
|
|
|
|
|
|
if (info != null)
|
|
|
|
|
{
|
|
|
|
@ -775,9 +857,21 @@ namespace Aucma.Scada.Business
|
|
|
|
|
item.spaceStock = spaceInfo.spaceStock;
|
|
|
|
|
item.onRouteAmount = spaceInfo.onRouteAmount;
|
|
|
|
|
item.spaceStatus = spaceInfo.spaceStatus;
|
|
|
|
|
PrintLogInfoMessage($"通过PLC读取货道信息,货道:{spaceInfo.spaceName};在库数量:{item.spaceStock};货道状态:{item.spaceStatus}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = info.Where(x => x.spaceStatus == 1 && x.spaceStock > 0).OrderBy(x => x.spaceStock).OrderBy(x => x.spaceCode).First();
|
|
|
|
|
//result = info.Where(x => x.spaceStatus == 1 && x.spaceStock > 0).OrderBy(x => x.spaceStock).OrderBy(x => x.spaceCode).First();
|
|
|
|
|
|
|
|
|
|
var list = info.Where(x => x.spaceStatus == 1 && x.spaceStock > 0).ToList();
|
|
|
|
|
|
|
|
|
|
if(list.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
result = info.OrderBy(x => x.spaceStock).OrderBy(x => x.spaceCode).First();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PrintLogInfoMessage("未获取到匹配的货道,请排查货道库存及货道状态是否可用");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -789,5 +883,29 @@ namespace Aucma.Scada.Business
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 日志输出
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 日志输出,界面刷新同时记录文件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message"></param>
|
|
|
|
|
private void PrintLogInfoMessage(string message)
|
|
|
|
|
{
|
|
|
|
|
RefreshLogMessageEvent?.Invoke(message);
|
|
|
|
|
logHelper.Info(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 异常日志输出
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="message"></param>
|
|
|
|
|
/// <param name="ex"></param>
|
|
|
|
|
private void PrintLogErrorMessage(string message, Exception ex = null)
|
|
|
|
|
{
|
|
|
|
|
RefreshLogMessageEvent?.Invoke(message);
|
|
|
|
|
logHelper.Error(message, ex);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|