添加项目文件。
This commit is contained in:
191
WPFWCSDemo/Schedules/CircleRGV/Update.cs
Normal file
191
WPFWCSDemo/Schedules/CircleRGV/Update.cs
Normal file
@@ -0,0 +1,191 @@
|
||||
using Quartz;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reactive.Concurrency;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WPFWCSDemo.Common;
|
||||
using WPFWCSDemo.Data;
|
||||
using WPFWCSDemo.Models.Devices.CircleRGV;
|
||||
using WPFWCSDemo.Models.Tables;
|
||||
using WPFWCSDemo.StateCode;
|
||||
using WPFWCSDemo.ViewModels;
|
||||
|
||||
namespace WPFWCSDemo.Schedules.CircleRGV
|
||||
{
|
||||
/// <summary>
|
||||
/// 更新任务调度
|
||||
/// </summary>
|
||||
public class Update
|
||||
{
|
||||
static int deviceCount = RGVStation.RGVCount;
|
||||
|
||||
/// <summary>
|
||||
/// 根据任务号获取正在执行任务环穿的编号
|
||||
/// </summary>
|
||||
public static Task UpdateDeviceNumber()
|
||||
{
|
||||
//根据任务号获取正在执行任务环穿的编号
|
||||
for (int j = 1; j <= deviceCount; j++)
|
||||
{
|
||||
using CircleRGVState? circleRGVState = CircleRGVsViewModel.GetCircleRGVState(j);
|
||||
|
||||
if (circleRGVState == null) continue;
|
||||
|
||||
//有【允许下发】则表示无任务小车---跳过
|
||||
if (circleRGVState.Read_Permission) continue;
|
||||
|
||||
using var context = new AppDbContext();
|
||||
|
||||
TaskRT? taskRT = context.Tasks.
|
||||
FirstOrDefault(t => t.TaskId == circleRGVState.Read_TaskNumber.ToString());
|
||||
|
||||
if (taskRT == null) continue;
|
||||
|
||||
taskRT.JobId = j.ToString();
|
||||
|
||||
context.SaveChanges();
|
||||
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据【执行阶段】实时更新环穿【调度状态】
|
||||
/// </summary>
|
||||
public static Task UpdateScheduleState()
|
||||
{
|
||||
for (int i = 1; i <= deviceCount; i++)
|
||||
{
|
||||
using CircleRGVState? circleRGVState = CircleRGVsViewModel.GetCircleRGVState(i);
|
||||
|
||||
if (circleRGVState == null) continue;
|
||||
|
||||
using var context = new AppDbContext();
|
||||
|
||||
//获取执行中的任务
|
||||
TaskRT? taskRT = context.Tasks
|
||||
.FirstOrDefault(t => t.TaskId == circleRGVState.Read_TaskNumber.ToString() && t.TaskState == TaskStateCode.Task_Running);
|
||||
|
||||
if (taskRT is null) continue;
|
||||
|
||||
//有【允许下发】
|
||||
//if (circleRGVState.Read_Permission) continue;
|
||||
|
||||
//无【允许下发】---表示小车有执行中的任务
|
||||
switch (circleRGVState.Read_Phase)
|
||||
{
|
||||
case 1:
|
||||
if (taskRT.ScheduleState == ScheduleStateCode.Trans_CircleRGV_Ready && !circleRGVState.Read_Permission)
|
||||
{
|
||||
taskRT.ScheduleState = ScheduleStateCode.Trans_CircleRGV_PickOnTheWay;
|
||||
|
||||
if (context.SaveChanges() == 1) Log.Information($"【WCS更新调度状态】任务号:{circleRGVState.Read_TaskNumber}--->取货途中");
|
||||
}
|
||||
continue;
|
||||
case 2:
|
||||
if (taskRT.ScheduleState != ScheduleStateCode.Trans_CircleRGV_Picking && !circleRGVState.Read_Permission)
|
||||
{
|
||||
taskRT.ScheduleState = ScheduleStateCode.Trans_CircleRGV_Picking;
|
||||
|
||||
if (context.SaveChanges() == 1) Log.Information($"【WCS更新调度状态】任务号:{circleRGVState.Read_TaskNumber}--->取货中");
|
||||
|
||||
//更新取货时间
|
||||
if (taskRT.TaskType == TaskType.Goods)
|
||||
{
|
||||
var loadedState = context.LoadedState
|
||||
.FirstOrDefault(s => s.Station.ToString() == taskRT.SourceLocation);
|
||||
|
||||
loadedState!.LoadingTime = DateTime.Now;
|
||||
}
|
||||
if (taskRT.TaskType == TaskType.Pallet)
|
||||
{
|
||||
var loadedState = context.LoadedState
|
||||
.FirstOrDefault(s => s.Station.ToString() == taskRT.TargetLocation);
|
||||
|
||||
loadedState!.LoadingTime = DateTime.Now;
|
||||
}
|
||||
|
||||
context.SaveChanges();
|
||||
}
|
||||
continue;
|
||||
case 3:
|
||||
if (taskRT.ScheduleState != ScheduleStateCode.Trans_CircleRGV_PutOnTheWay && !circleRGVState.Read_Permission)
|
||||
{
|
||||
taskRT.ScheduleState = ScheduleStateCode.Trans_CircleRGV_PutOnTheWay;
|
||||
taskRT.JobId = i.ToString();
|
||||
|
||||
if (context.SaveChanges() == 1) Log.Information($"【WCS更新调度状态】任务号:{circleRGVState.Read_TaskNumber}--->放货途中");
|
||||
|
||||
//更新取货时间
|
||||
if (taskRT.TaskType == TaskType.Goods)
|
||||
{
|
||||
var loadedState = context.LoadedState
|
||||
.FirstOrDefault(s => s.Station.ToString() == taskRT.SourceLocation);
|
||||
|
||||
loadedState!.LoadedTime = DateTime.Now;
|
||||
}
|
||||
if (taskRT.TaskType == TaskType.Pallet)
|
||||
{
|
||||
var loadedState = context.LoadedState
|
||||
.FirstOrDefault(s => s.Station.ToString() == taskRT.TargetLocation);
|
||||
|
||||
loadedState!.LoadedTime = DateTime.Now;
|
||||
}
|
||||
|
||||
context.SaveChanges();
|
||||
|
||||
}
|
||||
continue;
|
||||
case 4:
|
||||
if (taskRT.ScheduleState != ScheduleStateCode.Trans_CircleRGV_Putting && !circleRGVState.Read_Permission)
|
||||
{
|
||||
taskRT.ScheduleState = ScheduleStateCode.Trans_CircleRGV_Putting;
|
||||
|
||||
if (context.SaveChanges() == 1) Log.Information($"【WCS更新调度状态】任务号:{circleRGVState.Read_TaskNumber}--->放货中");
|
||||
|
||||
//更新取货时间
|
||||
if (taskRT.TaskType == TaskType.Goods)
|
||||
{
|
||||
var loadedState = context.LoadedState
|
||||
.FirstOrDefault(s => s.Station.ToString() == taskRT.SourceLocation);
|
||||
|
||||
loadedState!.PuttingTime = DateTime.Now;
|
||||
}
|
||||
if (taskRT.TaskType == TaskType.Pallet)
|
||||
{
|
||||
var loadedState = context.LoadedState
|
||||
.FirstOrDefault(s => s.Station.ToString() == taskRT.TargetLocation);
|
||||
|
||||
loadedState!.PuttingTime = DateTime.Now;
|
||||
}
|
||||
|
||||
context.SaveChanges();
|
||||
}
|
||||
continue;
|
||||
case 5:
|
||||
if (taskRT.ScheduleState != ScheduleStateCode.Trans_CircleRGV_Ready)
|
||||
{
|
||||
taskRT.ScheduleState = ScheduleStateCode.Trans_CircleRGV_Finish;
|
||||
|
||||
if (context.SaveChanges() == 1) Log.Information($"【WCS更新调度状态】任务号:{circleRGVState.Read_TaskNumber}--->放货完成");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user