添加项目文件。
This commit is contained in:
439
WPFWCSDemo/Schedules/CircleRGV/Check.cs
Normal file
439
WPFWCSDemo/Schedules/CircleRGV/Check.cs
Normal file
@@ -0,0 +1,439 @@
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
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.Utilities;
|
||||
using WPFWCSDemo.ViewModels;
|
||||
|
||||
namespace WPFWCSDemo.Schedules.CircleRGV
|
||||
{
|
||||
/// <summary>
|
||||
/// 任务校验
|
||||
/// </summary>
|
||||
public class Check
|
||||
{
|
||||
static int deviceCount = RGVStation.RGVCount;
|
||||
|
||||
/// <summary>
|
||||
/// 生成【空托】任务条件校验
|
||||
/// </summary>
|
||||
/// <param name="sourceLocation">源站点(可表示某条输送线)</param>
|
||||
/// <param name="targetLocation">目标站点(可表示某条输送线)</param>
|
||||
/// <param name="isNotException">输送口是否正常 true-系统正常 false-系统异常</param>
|
||||
/// <returns>是否满足生成任务条件 true-可生成 false-禁止生成</returns>
|
||||
public static bool CanTaskGenerated(int sourceLocation, int targetLocation, bool isNotException)
|
||||
{
|
||||
//校验---源站点请求
|
||||
if (QueryForIsRequestReset(sourceLocation, 3)) return false;
|
||||
|
||||
//校验---目标站点请求
|
||||
if (QueryForIsRequestReset(targetLocation, 3)) return false;
|
||||
|
||||
//校验---系统异常
|
||||
if (!isNotException) return false;
|
||||
|
||||
//校验---同输送口相邻任务生成时间间隔过短
|
||||
if (!CheckSendTaskTimeInterval(targetLocation, 999)) return false;
|
||||
|
||||
//校验---如果已经存在处于【取货阶段】的某个【空托】任务
|
||||
//由于【空托任务】输送线的源站点唯一,因此必须等待该任务取货完成才能生成新的【空托】任务
|
||||
if (!IsPalletConvHasGettingTask()) return false;
|
||||
|
||||
//校验---当前输送线存在【空托】任务
|
||||
if (!GetRGVTaskForPalletsIsExist(targetLocation)) return false;
|
||||
|
||||
//校验5.当前同一【目标站点】是否已经生成任务
|
||||
if (!CheckSendTaskIsRepeat(sourceLocation, TaskType.Pallet)) return false;
|
||||
|
||||
//校验---上位是否手动禁止生成
|
||||
if (LineTaskForPermission(targetLocation) == 0) return false;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 生成【实垛】任务校验条件
|
||||
/// </summary>
|
||||
/// <param name="sourceLocation">源站点(可表示某条输送线)</param>
|
||||
/// <param name="isNotException">输送口是否正常 true-系统正常 false-系统异常</param>
|
||||
/// <returns>是否满足生成任务条件 true-可生成 false-禁止生成</returns>
|
||||
public static bool CanTaskGenerated(int sourceLocation, bool isNotException)
|
||||
{
|
||||
|
||||
//校验0 放货口无允许
|
||||
//2025.9新增
|
||||
//1003-1009输送口校验
|
||||
if (sourceLocation == RGVStation.LineM_Goods_In)
|
||||
{
|
||||
if (QueryForIsRequestReset(RGVStation.LineToWarehouse1_Out, 3)) return false;
|
||||
}
|
||||
//2025.9新增
|
||||
//1005-1010输送口校验
|
||||
if (sourceLocation == RGVStation.LineL_Goods_In)
|
||||
{
|
||||
if (QueryForIsRequestReset(RGVStation.LineToWarehouse2_Out, 3)) return false;
|
||||
}
|
||||
|
||||
//校验1.输送口无请求
|
||||
if (QueryForIsRequestReset(sourceLocation, 3)) return false;
|
||||
|
||||
//校验2.输送口系统异常
|
||||
if (!isNotException) return false;
|
||||
|
||||
//校验3.同输送口相邻任务生成时间间隔过短
|
||||
if (!CheckSendTaskTimeInterval(sourceLocation)) return false;
|
||||
|
||||
//校验4.当前输送线存在取货阶段的任务
|
||||
if (!GetRGVTaskForGoodsIsExist(sourceLocation)) return false;
|
||||
|
||||
//校验5.当前同一【源站点】是否已经生成【取货阶段】任务
|
||||
if (!CheckSendTaskIsRepeat(sourceLocation, TaskType.Goods)) return false;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 防错机制【用于避免请求延迟的重复下发】--- 检测上一条【实垛】任务放货时间与当前时间是否相差x秒以上
|
||||
/// </summary>
|
||||
/// <param name="location">站点</param>
|
||||
/// <returns> true-相差大于x秒 false-相差小于x秒</returns>
|
||||
public static bool CheckSendTaskTimeInterval(int location)
|
||||
{
|
||||
int diff = -15;
|
||||
|
||||
using var context = new AppDbContext();
|
||||
|
||||
var loadedState = context
|
||||
.Set<LoadedState>()
|
||||
.Where(t => t.Station == location)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (DateTime.Now.AddSeconds(diff) >= loadedState!.LoadingTime)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 防错机制【用于避免请求延迟的重复下发】--- 检测上一条【空托】任务放货时间(完成时间)与当前时间是否相差x秒以上
|
||||
/// </summary>
|
||||
/// <param name="location">站点</param>
|
||||
/// <returns> true-相差大于x秒 false-相差小于x秒</returns>
|
||||
public static bool CheckSendTaskTimeInterval(int location, int num)
|
||||
{
|
||||
int diff = -30;
|
||||
|
||||
using var context = new AppDbContext();
|
||||
|
||||
var loadedState = context
|
||||
.Set<LoadedState>()
|
||||
.Where(t => t.Station == location)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (DateTime.Now.AddSeconds(diff) >= loadedState!.PuttingTime)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 防错机制【重复下发】--- 检测已经生成但未下发的任务是否存在
|
||||
/// </summary>
|
||||
/// <param name="sourceLocation">源站点</param>
|
||||
/// <returns> true-同目标站点生成任务时间间隔合法 false-时间间隔过短</returns>
|
||||
public static bool CheckSendTaskIsRepeat(int location, int type)
|
||||
{
|
||||
using var context = new AppDbContext();
|
||||
|
||||
//实垛
|
||||
if (type == TaskType.Goods)
|
||||
{
|
||||
//生成的上一条【实垛】任务且同一个源站点 ---> 查找符合条件的记录
|
||||
var count = context
|
||||
.Set<TaskRT>()
|
||||
.Where(t => t.SourceLocation == location.ToString() && (t.ScheduleState==ScheduleStateCode.Trans_CircleRGV_Ready || t.ScheduleState == ScheduleStateCode.Trans_CircleRGV_Picking))
|
||||
.Count();
|
||||
|
||||
if (count < 1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//空托
|
||||
if (type == TaskType.Pallet)
|
||||
{
|
||||
//生成的上一条【空托】任务且同一个目标站点 ---> 查找符合条件的记录
|
||||
var count1 = context
|
||||
.Set<TaskRT>()
|
||||
.Where(t => t.TargetLocation == location.ToString())
|
||||
.Count();
|
||||
|
||||
if (count1 < 1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 计算某个输送口请求的值的和---用于确定该输送口在一定时间内请求是否已经复位
|
||||
/// 用于避免信号也许存在的不稳定(跳变)的情况
|
||||
/// </summary>
|
||||
/// <param name="Location">源站点/目标站点---表示对应列</param>
|
||||
/// <param name="count">计算的时间间隔(单位:秒)</param>
|
||||
/// <returns>true-无请求---已复位 false-请求存在-未复位</returns>
|
||||
public static bool QueryForIsRequestReset(int location, int count)
|
||||
{
|
||||
var context = new AppDbContext();
|
||||
|
||||
string s = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
|
||||
|
||||
var timeIsExist = context.ConvRequest
|
||||
.Where(a => a.Time == s)
|
||||
.Count();
|
||||
|
||||
if (timeIsExist == 0) { return false; }
|
||||
|
||||
string line = "";
|
||||
|
||||
switch (location)
|
||||
{
|
||||
case RGVStation.LineH_Goods_In:
|
||||
line = "Conv_Goods_In_1001";
|
||||
break;
|
||||
case RGVStation.LineM_Goods_In:
|
||||
line = "Conv_Goods_In_1003";
|
||||
break;
|
||||
case RGVStation.LineL_Goods_In:
|
||||
line = "Conv_Goods_In_1005";
|
||||
break;
|
||||
case RGVStation.LineG1_Goods_In:
|
||||
line = "Conv_Goods_In_1007";
|
||||
break;
|
||||
case RGVStation.LineG2_Goods_In:
|
||||
line = "Conv_Goods_In_1008";
|
||||
break;
|
||||
|
||||
|
||||
case RGVStation.LineGH_Pallets_In:
|
||||
line = "Conv_Pallets_In_1013";
|
||||
break;
|
||||
case RGVStation.LineH_Pallets_Out:
|
||||
line = "Conv_Pallets_Out_1002";
|
||||
break;
|
||||
case RGVStation.LineG_Pallets_Out:
|
||||
line = "Conv_Pallets_Out_1004";
|
||||
break;
|
||||
case RGVStation.LineLM_Pallets_Out:
|
||||
line = "Conv_Pallets_Out_1006";
|
||||
break;
|
||||
|
||||
case RGVStation.LineToWarehouse1_Out:
|
||||
line = "Conv_Goods_Out_1009";
|
||||
break;
|
||||
case RGVStation.LineToWarehouse2_Out:
|
||||
line = "Conv_Goods_Out_1010";
|
||||
break;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(line))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//获取当前时间节点前x行请求记录值
|
||||
using DataTable? dt = SqlHelper.ExecuteTable($"SELECT TOP {count} * FROM CONVREQUEST ORDER BY [time] DESC");
|
||||
|
||||
//无结果则返回
|
||||
if (dt is null || dt.Rows.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int sum = 0;
|
||||
|
||||
//计算源站点对应某列3行请求(允许)值的和
|
||||
for (int i = 0; i < dt.Rows.Count; i++)
|
||||
{
|
||||
sum += (int)dt.Rows[i][line];
|
||||
}
|
||||
|
||||
if (sum == 0)
|
||||
{
|
||||
//为0---无请求
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//不等于0,请求存在或存在值跳变情况
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 手动禁止某条输送线下发任务(根据名称)
|
||||
/// </summary>
|
||||
/// <param name="name">输送线名称</param>
|
||||
/// <returns>0-禁止 1-允许</returns>
|
||||
public static int LineTaskForPermission(string name)
|
||||
{
|
||||
using var context = new AppDbContext();
|
||||
|
||||
var lineState = context.LineState
|
||||
.Where(p => p.Name == name)
|
||||
.Select(p => p.IsEnable)
|
||||
.FirstOrDefault();
|
||||
|
||||
return lineState;
|
||||
}
|
||||
/// <summary>
|
||||
/// 手动禁止某条输送线下发任务(根据目标站)
|
||||
/// </summary>
|
||||
/// <param name="source">源站点</param>
|
||||
/// <returns>0-禁止 1-允许</returns>
|
||||
public static int LineTaskForPermission(int target)
|
||||
{
|
||||
using var context = new AppDbContext();
|
||||
|
||||
var lineState = context.LineState
|
||||
.Where(p => p.Target == target)
|
||||
.Select(p => p.IsEnable)
|
||||
.FirstOrDefault();
|
||||
|
||||
return lineState;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 遍历环穿是否有某条输送线正在执行的(栈板)任务---即只要有该输送口的任务则不能生成新任务
|
||||
/// 判断条件 1.站点 2.执行阶段 3.允许下发
|
||||
/// (该方法会直接读取小车参数)
|
||||
/// </summary>
|
||||
/// <param name="sourceLocation">源站点(1至2位编号)</param>
|
||||
/// <returns>false-存在执行中的任务的设备 true-无在执行任务的设备</returns>
|
||||
public static bool GetRGVTaskForPalletsIsExist(int targetLocation)
|
||||
{
|
||||
List<CircleRGVState>? states = CircleRGVsViewModel.GetAllCircleRGVState();
|
||||
|
||||
if (states is null) return false;
|
||||
|
||||
//检查是否有符合条件的小车,如果有则标
|
||||
//【源站点】匹配
|
||||
// 任务处于【取货阶段】
|
||||
// 无【允许下发】---表示小车在工作中
|
||||
var count = states
|
||||
.Where(a => a.Read_TargetLocation == (targetLocation - 1000).ToString() && !a.Read_Permission)
|
||||
.Count();
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//无满足条件的小车则表示所有设备无此任务
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 遍历环穿是否有某条输送线正在执行的(实垛)任务---某站点输送线存在【取货阶段】任务时不能生成新任务
|
||||
/// 判断条件:
|
||||
/// 1.站点匹配
|
||||
/// 2.执行阶段--->取货阶段
|
||||
/// 3.允许下发
|
||||
/// (该方法会直接从地面站读取小车参数)
|
||||
/// </summary>
|
||||
/// <param name="sourceLocation">源站点(1至2位编号)</param>
|
||||
/// <returns>false-存在执行任务的设备(不能下发) true-无执行中的任务的设备(可下发)</returns>
|
||||
public static bool GetRGVTaskForGoodsIsExist(int sourceLocation)
|
||||
{
|
||||
List<CircleRGVState> states = CircleRGVsViewModel.GetAllCircleRGVState();
|
||||
|
||||
if (states is null) return false;
|
||||
|
||||
//检查是否有符合条件的小车,如果有则标
|
||||
//【源站点】匹配
|
||||
// 任务处于【取货阶段】
|
||||
// 无【允许下发】---表示小车在工作中
|
||||
var count = states
|
||||
.Where(a => a.Read_SourceLocation == (sourceLocation - 1000).ToString() && a.Read_Phase < 3 && a.Read_Phase > 0 && !a.Read_Permission)
|
||||
.Count();
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//无满足条件的小车则表示所有设备无此任务
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否存在已经生成的处于【取货阶段】的【栈板】任务 --- 源站点每次请求仅生成一条任务
|
||||
/// </summary>
|
||||
/// <returns>true-无符合条件的任务(即可生成新任务) false-存在符合条件的任务</returns>
|
||||
public static bool IsPalletConvHasGettingTask()
|
||||
{
|
||||
var context = new AppDbContext();
|
||||
|
||||
var count =context.Tasks
|
||||
.Where(a=>a.SourceLocation == RGVStation.LineGH_Pallets_In.ToString() &&
|
||||
(a.ScheduleState == ScheduleStateCode.Trans_CircleRGV_Ready ||
|
||||
a.ScheduleState == ScheduleStateCode.Trans_CircleRGV_PickOnTheWay ||
|
||||
a.ScheduleState == ScheduleStateCode.Trans_CircleRGV_Picking))
|
||||
.Count();
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
44
WPFWCSDemo/Schedules/CircleRGV/CircleRGVSchedule.cs
Normal file
44
WPFWCSDemo/Schedules/CircleRGV/CircleRGVSchedule.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Quartz;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using WPFWCSDemo.Utilities;
|
||||
|
||||
namespace WPFWCSDemo.Schedules.CircleRGV
|
||||
{
|
||||
[DisallowConcurrentExecution]
|
||||
public class CircleRGVSchedule : IJob
|
||||
{
|
||||
public async Task Execute(IJobExecutionContext context)
|
||||
{
|
||||
//Application.Current.Dispatcher.InvokeAsync(() =>
|
||||
//{
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
bool b = await CommonTask.Common.GetPingForRGVStation("192.168.6.100");
|
||||
|
||||
if (b)
|
||||
{
|
||||
await Update.UpdateDeviceNumber();
|
||||
|
||||
await Update.UpdateScheduleState();
|
||||
|
||||
Excute.ExecuteTask();
|
||||
|
||||
Generate.GenerateTask();
|
||||
|
||||
// //Log.Information($"-----------------设备调度-----------------");
|
||||
}
|
||||
});
|
||||
|
||||
//});
|
||||
|
||||
//return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
110
WPFWCSDemo/Schedules/CircleRGV/Excute.cs
Normal file
110
WPFWCSDemo/Schedules/CircleRGV/Excute.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
using Newtonsoft.Json;
|
||||
using Quartz;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WPFWCSDemo.Data;
|
||||
using WPFWCSDemo.Models.Devices.CircleRGVStation;
|
||||
using WPFWCSDemo.Models.Tables;
|
||||
using WPFWCSDemo.StateCode;
|
||||
using WPFWCSDemo.ViewModels;
|
||||
|
||||
namespace WPFWCSDemo.Schedules.CircleRGV
|
||||
{
|
||||
/// <summary>
|
||||
/// 执行任务调度
|
||||
/// </summary>
|
||||
[DisallowConcurrentExecution]
|
||||
public class Excute
|
||||
{
|
||||
static int count1;
|
||||
|
||||
static int count2;
|
||||
|
||||
/// <summary>
|
||||
/// 执行任务
|
||||
/// </summary>
|
||||
public static void ExecuteTask()
|
||||
{
|
||||
//获取所有输送口请求状态
|
||||
CircleRGVStationState? circleRGVStationState = CircleRGVsViewModel.GetCircleRGVStaionState();
|
||||
|
||||
//地面站对象是否为空
|
||||
if (circleRGVStationState is null)
|
||||
{
|
||||
count1 += 1;
|
||||
|
||||
if (count1 >= 15)
|
||||
{
|
||||
Log.Warning($"【WCS<下发任务>获取输送口参数失败】地面站参数对象:null({count1})!");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//下发任务前判断地面站【允许下发】
|
||||
if (circleRGVStationState.Read_Permission == 0)
|
||||
{
|
||||
count2 += 1;
|
||||
|
||||
if (count2 >= 15)
|
||||
{
|
||||
Log.Warning($"【WCS<下发任务>失败】地面站【禁止下发】({count2})!");
|
||||
Log.Warning($"【WCS<下发任务>失败】地面站参数:({JsonConvert.SerializeObject(circleRGVStationState)})!");
|
||||
|
||||
//using SiemensS7Net siemens = new SiemensS7Net(SiemensPLCS.S1500, "192.168.6.100");
|
||||
//siemens.ConnectServer();
|
||||
//Log.Warning($"【WCS<下发任务>失败】地面站创建新对象测试读写是否成功:({siemens.ReadInt16("DB611.0").IsSuccess})!");
|
||||
//Log.Warning($"【WCS<下发任务>失败】地面站创建新对象测试读写是否成功:({siemens.ReadInt16("DB611.0").Message})!");
|
||||
//Log.Warning($"【WCS<下发任务>失败】地面站创建新对象测试读写值,允许下发:({siemens.ReadInt16("DB611.0").Content},AB供栈请求:{siemens.ReadInt16("DB2100.3.1").Content})!");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
count1 = 0;
|
||||
|
||||
count2 = 0;
|
||||
|
||||
using var context = new AppDbContext();
|
||||
|
||||
TaskRT? taskRT = context.Tasks
|
||||
.OrderBy(t => t.CreateTime)
|
||||
.FirstOrDefault(t => t.TaskState == TaskStateCode.Task_Ready && t.ScheduleState == ScheduleStateCode.Trans_CircleRGV_Ready);
|
||||
|
||||
if (taskRT == null) return;
|
||||
|
||||
CircleRGVStationCommand? circleRGVStationCommand = new CircleRGVStationCommand()
|
||||
{
|
||||
Write_DeviceNumber = 0,
|
||||
Write_TaskType = int.Parse(taskRT.TaskType.ToString()[..1]),
|
||||
Write_TaskNumber = int.Parse(taskRT.TaskId),
|
||||
Write_SourceLocation = int.Parse(taskRT.SourceLocation!),
|
||||
Write_TargetLocation = int.Parse(taskRT.TargetLocation!),
|
||||
Write_SendFinish = 0,
|
||||
};
|
||||
|
||||
//circleRGVStationCommand.Write_Checksum = Checksum.GetChecksum(circleRGVStationCommand);
|
||||
|
||||
bool b = CircleRGVsViewModel.SendRGVStationCommand(circleRGVStationCommand);
|
||||
|
||||
if (b)
|
||||
{
|
||||
taskRT.TaskState = TaskStateCode.Task_Running;
|
||||
taskRT.ScheduleTime = DateTime.Now;
|
||||
|
||||
context.SaveChanges();
|
||||
|
||||
//Log.Information($"【WCS更新任务状态】任务号:{taskRT.TaskId}环穿下发完成,等待设备执行");
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log.Warning($"【WCS更新任务状态】任务号:{taskRT.TaskId}环穿下发失败");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
217
WPFWCSDemo/Schedules/CircleRGV/Generate.cs
Normal file
217
WPFWCSDemo/Schedules/CircleRGV/Generate.cs
Normal file
@@ -0,0 +1,217 @@
|
||||
using Quartz;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WPFWCSDemo.Common;
|
||||
using WPFWCSDemo.Data;
|
||||
using WPFWCSDemo.Models.Devices.CircleRGV;
|
||||
using WPFWCSDemo.Models.Devices.CircleRGVStation;
|
||||
using WPFWCSDemo.Models.Tables;
|
||||
using WPFWCSDemo.StateCode;
|
||||
using WPFWCSDemo.Utilities;
|
||||
using WPFWCSDemo.ViewModels;
|
||||
|
||||
namespace WPFWCSDemo.Schedules.CircleRGV
|
||||
{
|
||||
/// <summary>
|
||||
/// 生成任务
|
||||
/// </summary>
|
||||
[DisallowConcurrentExecution]
|
||||
public class Generate
|
||||
{
|
||||
private static int count = 0;
|
||||
public static void GenerateTask()
|
||||
{
|
||||
//获取所有输送口请求状态
|
||||
CircleRGVStationState? circleRGVStationState = CircleRGVsViewModel.GetCircleRGVStaionState();
|
||||
|
||||
//地面站对象是否为空
|
||||
if (circleRGVStationState is null)
|
||||
{
|
||||
count += 1;
|
||||
|
||||
if (count >= 30)
|
||||
{
|
||||
//Log.Warning($"【WCS<生成任务>获取输送口参数失败】地面站参数对象:null({count})!");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
count = 0;
|
||||
|
||||
|
||||
//------------------------------------1001有出实垛请求------------------------------------
|
||||
//------------------------------------1001有出实垛请求------------------------------------
|
||||
if (Check.CanTaskGenerated(RGVStation.LineH_Goods_In, circleRGVStationState.Read_IsNotException_1001) && circleRGVStationState.Read_GetRequest_1001)
|
||||
{
|
||||
//检查该放货口是否由上位手动禁止生成任务
|
||||
if (Check.LineTaskForPermission(RGVStation.LineH_Goods_Out) == 1)
|
||||
{
|
||||
InsertTask(RGVStation.LineH_Goods_In, RGVStation.LineH_Goods_Out, TaskType.Goods);
|
||||
}
|
||||
}
|
||||
|
||||
//****************************************************【2025.09修改】增加9#、10#立库入口****************************************************
|
||||
//****************************************************【2025.09修改】增加9#、10#立库入口****************************************************
|
||||
//****************************************************【2025.09修改】增加9#、10#立库入口****************************************************
|
||||
//------------------------------------1003有出实垛请求------------------------------------
|
||||
//------------------------------------1003有出实垛请求------------------------------------
|
||||
if (circleRGVStationState.Read_GetRequest_1003 &&
|
||||
circleRGVStationState.Read_PutRequest_1009 &&
|
||||
Check.CanTaskGenerated(RGVStation.LineM_Goods_In, circleRGVStationState.Read_IsNotException_1003))
|
||||
{
|
||||
if (Check.LineTaskForPermission(RGVStation.LineToWarehouse1_Out) == 1)
|
||||
{
|
||||
InsertTask(RGVStation.LineM_Goods_In, RGVStation.LineToWarehouse1_Out, TaskType.Goods);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------1005有出实垛请求------------------------------------
|
||||
//------------------------------------1005有出实垛请求------------------------------------
|
||||
if (circleRGVStationState.Read_GetRequest_1005 &&
|
||||
circleRGVStationState.Read_PutRequest_1010 &&
|
||||
Check.CanTaskGenerated(RGVStation.LineL_Goods_In, circleRGVStationState.Read_IsNotException_1005))
|
||||
{
|
||||
if (Check.LineTaskForPermission(RGVStation.LineToWarehouse2_Out) == 1)
|
||||
{
|
||||
InsertTask(RGVStation.LineL_Goods_In, RGVStation.LineToWarehouse2_Out, TaskType.Goods);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------1007有出实垛请求------------------------------------
|
||||
//------------------------------------1007有出实垛请求------------------------------------
|
||||
if (Check.CanTaskGenerated(RGVStation.LineG1_Goods_In, circleRGVStationState.Read_IsNotException_1007) && circleRGVStationState.Read_GetRequest_1007)
|
||||
{
|
||||
//检查该放货口是否由上位手动禁止生成任务
|
||||
if (Check.LineTaskForPermission(RGVStation.LineG_Goods_Out) == 1)
|
||||
{
|
||||
InsertTask(RGVStation.LineG1_Goods_In, RGVStation.LineG_Goods_Out, TaskType.Goods);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------1008有出实垛请求------------------------------------
|
||||
//------------------------------------1008有出实垛请求------------------------------------
|
||||
if (Check.CanTaskGenerated(RGVStation.LineG2_Goods_In, circleRGVStationState.Read_IsNotException_1008) && circleRGVStationState.Read_GetRequest_1008)
|
||||
{
|
||||
//检查该放货口是否由上位手动禁止生成任务
|
||||
if (Check.LineTaskForPermission(RGVStation.LineG_Goods_Out) == 1)
|
||||
{
|
||||
InsertTask(RGVStation.LineG2_Goods_In, RGVStation.LineG_Goods_Out, TaskType.Goods);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//------------------------------------1006有回空托请求------------------------------------
|
||||
if (circleRGVStationState.Read_PutRequest_1006 &&
|
||||
circleRGVStationState.Read_GetRequest_1013 &&
|
||||
Check.CanTaskGenerated(RGVStation.LineGH_Pallets_In, RGVStation.LineLM_Pallets_Out, circleRGVStationState.Read_IsNotException_1006))
|
||||
{
|
||||
InsertTask(RGVStation.LineGH_Pallets_In, RGVStation.LineLM_Pallets_Out, TaskType.Pallet);
|
||||
}
|
||||
|
||||
//------------------------------------1004有回空托请求------------------------------------
|
||||
if (circleRGVStationState.Read_PutRequest_1004 &&
|
||||
circleRGVStationState.Read_GetRequest_1013 &&
|
||||
Check.CanTaskGenerated(RGVStation.LineGH_Pallets_In, RGVStation.LineG_Pallets_Out, circleRGVStationState.Read_IsNotException_1004))
|
||||
{
|
||||
InsertTask(RGVStation.LineGH_Pallets_In, RGVStation.LineG_Pallets_Out, TaskType.Pallet);
|
||||
}
|
||||
|
||||
//------------------------------------1002有空托请求------------------------------------
|
||||
if (circleRGVStationState.Read_PutRequest_1002 &&
|
||||
circleRGVStationState.Read_GetRequest_1013 &&
|
||||
Check.CanTaskGenerated(RGVStation.LineGH_Pallets_In, RGVStation.LineH_Pallets_Out, circleRGVStationState.Read_IsNotException_1002))
|
||||
{
|
||||
InsertTask(RGVStation.LineGH_Pallets_In, RGVStation.LineH_Pallets_Out, TaskType.Pallet);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 插入一条新任务
|
||||
/// </summary>
|
||||
/// <param name="sourceLocation">源站点</param>
|
||||
/// <param name="taskType">任务类型 10-实垛 11-空托</param>
|
||||
public static void InsertTask(int sourceLocation,int targetLocation, int taskType)
|
||||
{
|
||||
using var context = new AppDbContext();
|
||||
|
||||
int taskNumber = SqlHelper.GetTaskIdByAutoGeneration();
|
||||
|
||||
string type = "";
|
||||
|
||||
if (taskType == TaskType.Goods) type = "<实垛>";
|
||||
if (taskType == TaskType.Pallet) type = "<空托>";
|
||||
|
||||
try
|
||||
{
|
||||
TaskRT taskRT = new TaskRT()
|
||||
{
|
||||
TaskId = taskNumber.ToString(),
|
||||
TaskType = taskType,
|
||||
TaskState = TaskStateCode.Task_Ready,
|
||||
ScheduleState = ScheduleStateCode.Trans_CircleRGV_Ready,
|
||||
SourceLocation = sourceLocation.ToString(),
|
||||
TargetLocation = targetLocation.ToString(),
|
||||
CreateTime = DateTime.Now,
|
||||
};
|
||||
|
||||
context.Tasks.Add(taskRT);
|
||||
|
||||
if (sourceLocation == RGVStation.LineGH_Pallets_In)
|
||||
{
|
||||
//更新取货状态---计算【空托】线相同输送口前后任务的间隔时间---用于避免生成重复任务
|
||||
var loadedState = context.LoadedState
|
||||
.FirstOrDefault(s => s.Station == targetLocation);
|
||||
|
||||
loadedState.GenerationTime = DateTime.Now;
|
||||
|
||||
context.SaveChanges();
|
||||
}
|
||||
else
|
||||
{
|
||||
//更新取货状态---计算【实垛】线相同输送口前后任务的间隔时间---用于避免生成重复任务
|
||||
var loadedState = context.LoadedState
|
||||
.FirstOrDefault(s => s.Station == sourceLocation);
|
||||
|
||||
loadedState.GenerationTime = DateTime.Now;
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Warning($"【WCS生成{type}任务异常】任务号:{taskNumber},{e.Message}");
|
||||
Log.Warning($"【WCS生成{type}任务异常】任务号:{taskNumber},{e.InnerException}");
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Information($"【WCS生成{type}任务】任务号:{taskNumber},取货站点:{sourceLocation},放货站点:{targetLocation}");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
97
WPFWCSDemo/Schedules/CommonTask/Common.cs
Normal file
97
WPFWCSDemo/Schedules/CommonTask/Common.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WPFWCSDemo.Common;
|
||||
using WPFWCSDemo.Data;
|
||||
using WPFWCSDemo.Models.Devices.CircleRGV;
|
||||
using WPFWCSDemo.Models.Devices.CircleRGVStation;
|
||||
using WPFWCSDemo.StateCode;
|
||||
using WPFWCSDemo.ViewModels;
|
||||
|
||||
namespace WPFWCSDemo.Schedules.CommonTask
|
||||
{
|
||||
public class Common
|
||||
{
|
||||
int deviceCount = RGVStation.RGVCount;
|
||||
|
||||
/// <summary>
|
||||
/// 记录输送口请求值
|
||||
/// </summary>
|
||||
public static void RecordRequestValue()
|
||||
{
|
||||
//获取所有输送口请求状态
|
||||
using CircleRGVStationState? circleRGVStationState = CircleRGVsViewModel.GetCircleRGVStaionState();
|
||||
|
||||
//地面站【允许下发】
|
||||
if (circleRGVStationState is null) return;
|
||||
|
||||
int a = circleRGVStationState.Read_GetRequest_1001 == true ? 1 : 0;
|
||||
int b = circleRGVStationState.Read_GetRequest_1003 == true ? 1 : 0;
|
||||
int c = circleRGVStationState.Read_GetRequest_1005 == true ? 1 : 0;
|
||||
int d = circleRGVStationState.Read_GetRequest_1007 == true ? 1 : 0;
|
||||
int e = circleRGVStationState.Read_GetRequest_1008 == true ? 1 : 0;
|
||||
|
||||
int ab = circleRGVStationState.Read_GetRequest_1013 == true ? 1 : 0;
|
||||
int bOut = circleRGVStationState.Read_PutRequest_1002 == true ? 1 : 0;
|
||||
int cd = circleRGVStationState.Read_PutRequest_1004 == true ? 1 : 0;
|
||||
int cOut = circleRGVStationState.Read_PutRequest_1006 == true ? 1 : 0;
|
||||
|
||||
//1009放货口
|
||||
int f = circleRGVStationState.Read_PutRequest_1009 == true ? 1 : 0;
|
||||
//1010放货口
|
||||
int g = circleRGVStationState.Read_PutRequest_1010 == true ? 1 : 0;
|
||||
|
||||
using var context = new AppDbContext();
|
||||
|
||||
context.Database.ExecuteSqlInterpolated(
|
||||
$"INSERT INTO CONVREQUEST VALUES({a},{b},{c},{d},{e},{DateTime.Now.ToString(TimeFormat.stringFormat)},{ab},{bOut},{cd},{cOut},{Guid.NewGuid()},{f},{g})");
|
||||
|
||||
context.Database.ExecuteSqlInterpolated(
|
||||
$"DELETE FROM CONVREQUEST WHERE [TIME]<{DateTime.Now.AddHours(-24).ToString(TimeFormat.stringFormat)}");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 检测plc网络
|
||||
/// </summary>
|
||||
/// <param name="ipAddress">ip地址</param>
|
||||
/// <param name="timeout"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<bool> GetPingForRGVStation(string ipAddress, int timeout = 5000)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (Ping ping = new Ping())
|
||||
{
|
||||
PingReply reply = await ping.SendPingAsync(ipAddress, timeout);
|
||||
|
||||
return reply.Status == IPStatus.Success;
|
||||
}
|
||||
}
|
||||
catch (PingException e)
|
||||
{
|
||||
Log.Error($"【地面站网络异常】{e.Message}");
|
||||
Log.Error($"【地面站网络异常】{e.InnerException}");
|
||||
return false;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error($"【地面站网络异常】{e.Message}");
|
||||
Log.Error($"【地面站网络异常】{e.InnerException}");
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
28
WPFWCSDemo/Schedules/CommonTask/CommonTask.cs
Normal file
28
WPFWCSDemo/Schedules/CommonTask/CommonTask.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Quartz;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WPFWCSDemo.Models.Tables;
|
||||
using WPFWCSDemo.Schedules.CircleRGV;
|
||||
using WPFWCSDemo.Schedules.CommonTask;
|
||||
|
||||
namespace WPFWCSDemo.Schedules.CommonTask
|
||||
{
|
||||
public class CommonTask : IJob
|
||||
{
|
||||
public async Task Execute(IJobExecutionContext context)
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
//bool b = await Common.GetPingForRGVStation("192.168.6.100");
|
||||
|
||||
Common.RecordRequestValue();
|
||||
|
||||
});
|
||||
|
||||
//return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
WPFWCSDemo/Schedules/ConvSchedule.cs
Normal file
12
WPFWCSDemo/Schedules/ConvSchedule.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WPFWCSDemo.Schedules
|
||||
{
|
||||
public class ConvSchedule
|
||||
{
|
||||
}
|
||||
}
|
||||
29
WPFWCSDemo/Schedules/GlobalTask.cs
Normal file
29
WPFWCSDemo/Schedules/GlobalTask.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WPFWCSDemo.StateCode;
|
||||
using WPFWCSDemo.Utilities;
|
||||
|
||||
namespace WPFWCSDemo.Schedules
|
||||
{
|
||||
/// <summary>
|
||||
/// 全局任务
|
||||
/// </summary>
|
||||
public static class GlobalTask
|
||||
{
|
||||
/// <summary>
|
||||
/// 1\4\7\10月1日自动备份
|
||||
/// </summary>
|
||||
public static void SqlBackupForTime()
|
||||
{
|
||||
string time = DateTime.Now.ToString("MM-dd HH:mm");
|
||||
if (time == "04-01 01:15" || time == "07-01 01:15" || time == "10-01 01:15" || time == "01-01 01:15")
|
||||
{
|
||||
SqlDatabaseMaintenance.SQLBackupAuto();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
132
WPFWCSDemo/Schedules/TaskFinish/Delete.cs
Normal file
132
WPFWCSDemo/Schedules/TaskFinish/Delete.cs
Normal file
@@ -0,0 +1,132 @@
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WPFWCSDemo.Common;
|
||||
using WPFWCSDemo.Data;
|
||||
using WPFWCSDemo.Models.Devices.CircleRGVStation;
|
||||
using WPFWCSDemo.StateCode;
|
||||
using WPFWCSDemo.Utilities.Table;
|
||||
using WPFWCSDemo.ViewModels;
|
||||
|
||||
namespace WPFWCSDemo.Schedules.TaskFinish
|
||||
{
|
||||
/// <summary>
|
||||
/// 任务移除
|
||||
/// </summary>
|
||||
public class Delete
|
||||
{
|
||||
/// <summary>
|
||||
/// 完成的调度任务从实时表删除记入历史记录
|
||||
/// </summary>
|
||||
/// <param name="taskRT">当前已完成的任务</param>
|
||||
public static void TaskDelete()
|
||||
{
|
||||
using var context = new AppDbContext();
|
||||
|
||||
//查找符合【任务状态】和【调度状态】的记录
|
||||
var taskRT = context.Tasks
|
||||
.Where(t => t.TaskState == TaskStateCode.Task_Finish ||
|
||||
t.TaskState == TaskStateCode.Task_Finish_Manual ||
|
||||
t.TaskState == TaskStateCode.Task_Finish_Cancel ||
|
||||
t.TaskState == TaskStateCode.Task_Cancel ||
|
||||
t.TaskState == TaskStateCode.Task_Finish_Timeout)
|
||||
.OrderBy(t => t.CreateTime)
|
||||
.ToList();
|
||||
|
||||
if (taskRT is null || taskRT.Count == 0) return;
|
||||
|
||||
for (int i = 0; i < taskRT.Count; i++)
|
||||
{
|
||||
//任务完成状态文本
|
||||
string strTaskState;
|
||||
|
||||
switch (taskRT[i].TaskState)
|
||||
{
|
||||
case TaskStateCode.Task_Finish:
|
||||
strTaskState = "任务自动完成";
|
||||
break;
|
||||
case TaskStateCode.Task_Finish_Manual:
|
||||
strTaskState = "任务手动完成";
|
||||
break;
|
||||
case TaskStateCode.Task_Finish_Cancel:
|
||||
strTaskState = "任务手动取消";
|
||||
break;
|
||||
case TaskStateCode.Task_Cancel:
|
||||
strTaskState = "任务自动作废";
|
||||
break;
|
||||
case TaskStateCode.Task_Finish_Timeout:
|
||||
strTaskState = "任务超时自动完成";
|
||||
break;
|
||||
default:
|
||||
strTaskState = "发生未知异常,请检查后手动处理";//其他状态:异常-手动处理
|
||||
break;
|
||||
}
|
||||
|
||||
Log.Information($"【WCS任务结束】【{strTaskState}】,任务号:{taskRT[i].TaskId}");
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------反馈任务结束成功后:删除表任务添加至历史记录---------------------------------------------
|
||||
int result = TaskManager.Delete(taskRT[i]);
|
||||
|
||||
if (result == 1)
|
||||
{
|
||||
if (taskRT[i].TaskType == TaskType.Goods)
|
||||
Log.Information($"【常规任务-实垛】【{strTaskState}】,任务号:{taskRT[i].TaskId},历史任务记录已保存");
|
||||
|
||||
if (taskRT[i].TaskType == TaskType.Pallet)
|
||||
Log.Information($"【常规任务-空托】【{strTaskState}】,任务号:{taskRT[i].TaskId},历史任务记录已保存");
|
||||
|
||||
if (taskRT[i].TaskType == TaskType.GoToRest)
|
||||
Log.Information($"【进休息区】【{strTaskState}】,作业号:{taskRT[i].JobId} 任务号:{taskRT[i].TaskId},历史任务记录已保存");
|
||||
|
||||
if (taskRT[i].TaskType == TaskType.BackToRail)
|
||||
Log.Information($"【返回轨道】【{strTaskState}】,作业号:{taskRT[i].JobId} 任务号:{taskRT[i].TaskId},历史任务记录已保存");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//LineFlagAutoReset();
|
||||
|
||||
}
|
||||
|
||||
|
||||
///// <summary>
|
||||
///// 防错机制【可下发任务标志】---如果当前某条线无输送任务,则重置该输送线请求标志为true
|
||||
///// </summary>
|
||||
//public static void LineFlagAutoReset()
|
||||
//{
|
||||
// using var context = new AppDbContext();
|
||||
|
||||
// int lineA = context.Tasks.Where(t => t.SourceLocation == RGVStation.LineA_In.ToString()).Count();
|
||||
// if (lineA == 0) LineAIsAvailable = true;
|
||||
|
||||
// int lineB = context.Tasks.Where(t => t.SourceLocation == RGVStation.LineB_In.ToString()).Count();
|
||||
// if (lineB == 0) LineBIsAvailable = true;
|
||||
|
||||
// int lineC = context.Tasks.Where(t => t.SourceLocation == RGVStation.LineC_In.ToString()).Count();
|
||||
// if (lineC == 0) LineCIsAvailable = true;
|
||||
|
||||
// int lineD = context.Tasks.Where(t => t.SourceLocation == RGVStation.LineD_In.ToString()).Count();
|
||||
// if (lineD == 0) LineDIsAvailable = true;
|
||||
|
||||
|
||||
// using CircleRGVStationState? circleRGVStationState = CircleRGVsViewModel.GetCircleRGVStaionState();
|
||||
|
||||
// //地面站【允许下发】
|
||||
// if (circleRGVStationState is null || circleRGVStationState.Read_Permission == 0) return;
|
||||
|
||||
// int lineAB = context.Tasks.Where(t => t.SourceLocation == RGVStation.LineAB_In.ToString()).Count();
|
||||
// if (lineAB == 0 && circleRGVStationState.Read_PutRequest_LineB) LineABIsAvailable = true;
|
||||
|
||||
// int lineCD = context.Tasks.Where(t => t.SourceLocation == RGVStation.LineCD_In.ToString()).Count();
|
||||
// if (lineCD == 0 && circleRGVStationState.Read_PutRequest_LineC) LineCDIsAvailable = true;
|
||||
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
59
WPFWCSDemo/Schedules/TaskFinish/Finish.cs
Normal file
59
WPFWCSDemo/Schedules/TaskFinish/Finish.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WPFWCSDemo.Data;
|
||||
using WPFWCSDemo.StateCode;
|
||||
|
||||
namespace WPFWCSDemo.Schedules.TaskFinish
|
||||
{
|
||||
/// <summary>
|
||||
/// 任务完成
|
||||
/// </summary>
|
||||
public class Finish
|
||||
{
|
||||
/// <summary>
|
||||
/// 更新【任务自动完成】状态
|
||||
/// </summary>
|
||||
public static void TaskFinish()
|
||||
{
|
||||
using var context = new AppDbContext();
|
||||
|
||||
//---------------------------------------------查询【调度状态】为已完成的任务---------------------------------------------
|
||||
//var query = context.Set<TaskRT>()
|
||||
// .Where(t => t.ScheduleState == ScheduleStateCode.Trans_CircleRGV_Finish && t.TaskState == TaskStateCode.Task_Running)
|
||||
// .OrderBy(t => t.CreateTime);
|
||||
|
||||
//string s = query.ToQueryString();
|
||||
|
||||
//查询
|
||||
//调度状态【环穿-执行完成】
|
||||
//任务状态【执行中】
|
||||
//的符合条件的任务
|
||||
var taskRT = context.Tasks?
|
||||
.Where(t => t.ScheduleState == ScheduleStateCode.Trans_CircleRGV_Finish && t.TaskState == TaskStateCode.Task_Running)
|
||||
.OrderBy(t => t.CreateTime)
|
||||
.ToList();
|
||||
|
||||
|
||||
if (taskRT is null || taskRT.Count == 0) return;
|
||||
|
||||
//所有符合上述条件的任务
|
||||
for (int i = 0; i < taskRT.Count; i++)
|
||||
{
|
||||
if (taskRT[i] is null) continue;
|
||||
|
||||
//任务状态更新为【自动完成】
|
||||
taskRT[i].TaskState = TaskStateCode.Task_Finish;
|
||||
|
||||
Log.Information($"【WCS更新调度状态】任务号:{taskRT[i].TaskId},环穿输送完成");
|
||||
}
|
||||
|
||||
context.SaveChanges();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
159
WPFWCSDemo/Schedules/TaskFinish/Handler.cs
Normal file
159
WPFWCSDemo/Schedules/TaskFinish/Handler.cs
Normal file
@@ -0,0 +1,159 @@
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WPFWCSDemo.Common;
|
||||
using WPFWCSDemo.Data;
|
||||
using WPFWCSDemo.Models.Devices.CircleRGV;
|
||||
using WPFWCSDemo.StateCode;
|
||||
using WPFWCSDemo.Utilities.Table;
|
||||
using WPFWCSDemo.ViewModels;
|
||||
|
||||
namespace WPFWCSDemo.Schedules.TaskFinish
|
||||
{
|
||||
/// <summary>
|
||||
/// 任务处理
|
||||
/// </summary>
|
||||
public class Handler
|
||||
{
|
||||
static int deviceCount = RGVStation.RGVCount;
|
||||
|
||||
/// <summary>
|
||||
/// 防错机制 ---
|
||||
/// 任务状态 ->【执行中】
|
||||
/// 调度状态 ->【环穿-待执行】
|
||||
/// 取货状态 ->【未取货】
|
||||
/// 同时满足的任务视为下发失败的任务
|
||||
/// 将任务状态更新为【待执行】令其重新下发
|
||||
/// </summary>
|
||||
public static void TaskForSendFailedHandler()
|
||||
{
|
||||
using var context = new AppDbContext();
|
||||
|
||||
var tasks = context.Tasks
|
||||
//.Set<TaskRT>()
|
||||
.OrderBy(t => t.CreateTime)
|
||||
.Where(t => t.TaskState == TaskStateCode.Task_Running &&
|
||||
t.ScheduleState == ScheduleStateCode.Trans_CircleRGV_Ready &&
|
||||
t.ScheduleTime <= DateTime.Now.AddSeconds(-30) &&
|
||||
string.IsNullOrEmpty(t.JobId))
|
||||
.ToList();
|
||||
|
||||
if (tasks is null || tasks.Count == 0) return;
|
||||
|
||||
for (int i = 0; i < tasks.Count; i++)
|
||||
{
|
||||
tasks[i].TaskState = TaskStateCode.Task_Ready;
|
||||
|
||||
if (context.SaveChanges() == 1) Log.Warning($"【向地面站下发任务】任务号:{tasks[i].TaskId}更新任务状态,尝试重新下发...");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 防错机制 ---
|
||||
/// 处理长时间未正常完成的遗留任务记录---获取下发时间距离当前一定时间的任务
|
||||
/// 将其任务号与所有小车状态匹配
|
||||
/// 判断该任务是否在执行中---否则视为遗留任务处理
|
||||
/// </summary>
|
||||
public static void TaskExceptionHandler()
|
||||
{
|
||||
//只处理一段时间前的任务
|
||||
int diff = -5;
|
||||
|
||||
using var context = new AppDbContext();
|
||||
|
||||
//查询符合条件的任务
|
||||
//任务状态---【执行中】
|
||||
//生成时间---【执行中】
|
||||
var tasks = context.Tasks
|
||||
.Where(t => t.TaskState == TaskStateCode.Task_Running && t.CreateTime <= DateTime.Now.AddMinutes(diff))
|
||||
.OrderBy(t => t.CreateTime)
|
||||
.ToList();
|
||||
|
||||
//获取所有符合条件的任务记录
|
||||
for (int i = 0; i < tasks.Count; i++)
|
||||
{
|
||||
List<CircleRGVState> circleRGVStates = CircleRGVsViewModel.GetAllCircleRGVState();
|
||||
|
||||
if (circleRGVStates == null || circleRGVStates.Count < deviceCount) continue;
|
||||
|
||||
//查找匹配【任务号】和无【允许下发】的设备
|
||||
var result = circleRGVStates
|
||||
.Where(a => a.Read_TaskNumber.ToString() == tasks[i].TaskId && !a.Read_Permission)
|
||||
.Count();
|
||||
|
||||
//有匹配结果---> 查询下一条记录
|
||||
if (result > 0) continue;
|
||||
|
||||
//无匹配结果---> 移除遗留任务
|
||||
int handlerResult = TaskManager.Delete(tasks[i]);
|
||||
|
||||
if (handlerResult == 1)
|
||||
{
|
||||
Log.Warning($"【WCS更新任务状态】任务号:{tasks[i].TaskId},执行中设备无匹配任务,已作为遗留任务超时处理");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#region 遍历小车状态参数(已弃用)
|
||||
//每条记录与所有小车状态匹配
|
||||
//for (int j = 1; j <= deviceCount; j++)
|
||||
//{
|
||||
// CircleRGVState circleRGVState = CircleRGVsViewModel.GetCircleRGVState(j);
|
||||
|
||||
// if (circleRGVState == null) continue;
|
||||
|
||||
// //过滤掉取货完成前的阶段
|
||||
// if (circleRGVState.Read_Phase < 2) continue;
|
||||
|
||||
// //匹配到任务号 ---> 任务号不是设备的唯一标识,需要继续判断
|
||||
// if (circleRGVState.Read_TaskNumber.ToString() == tasks[i].TaskId)
|
||||
// {
|
||||
// //无【允许下发】---表示有执行中任务---跳出并开始下一条任务记录的匹配处理
|
||||
// if (!circleRGVState.Read_Permission) break;
|
||||
|
||||
// //1.有【允许下发】---> 必须匹配任务号的所有小车均有【允许下发】才能满足条件
|
||||
// if (j == deviceCount)
|
||||
// {
|
||||
// int result = TaskManager.Delete(tasks[i]);
|
||||
|
||||
// if (result == 1)
|
||||
// {
|
||||
// Log.Warning($"【WCS更新任务状态】任务号:{tasks[i].TaskId},执行中设备无匹配任务号,已作为遗留任务超时处理");
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
// else//无任务号匹配
|
||||
// {
|
||||
// //---所有车都无任务号匹配,表示该任务为遗留任务
|
||||
// if (j == deviceCount)
|
||||
// {
|
||||
// int result = TaskManager.Delete(tasks[i]);
|
||||
|
||||
// if (result == 1)
|
||||
// {
|
||||
// Log.Warning($"【WCS更新任务状态】任务号:{tasks[i].TaskId},执行中设备无匹配任务号,已作为遗留任务超时处理");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
//}
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
29
WPFWCSDemo/Schedules/TaskFinish/TaskFinishSchedule.cs
Normal file
29
WPFWCSDemo/Schedules/TaskFinish/TaskFinishSchedule.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Quartz;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace WPFWCSDemo.Schedules.TaskFinish
|
||||
{
|
||||
public class TaskFinishSchedule : IJob
|
||||
{
|
||||
public Task Execute(IJobExecutionContext context)
|
||||
{
|
||||
Application.Current.Dispatcher.InvokeAsync(() =>
|
||||
{
|
||||
Finish.TaskFinish();
|
||||
Handler.TaskForSendFailedHandler();
|
||||
Handler.TaskExceptionHandler();
|
||||
Delete.TaskDelete();
|
||||
|
||||
//Log.Information($"-----------------任务处理调度-----------------");
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
195
WPFWCSDemo/Schedules/TaskFinishSchedule.cs
Normal file
195
WPFWCSDemo/Schedules/TaskFinishSchedule.cs
Normal file
@@ -0,0 +1,195 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using WPFWCSDemo.Common;
|
||||
using WPFWCSDemo.Data;
|
||||
using WPFWCSDemo.Models.Devices.CircleRGV;
|
||||
using WPFWCSDemo.Models.Devices.CircleRGVStation;
|
||||
using WPFWCSDemo.Models.Tables;
|
||||
using WPFWCSDemo.StateCode;
|
||||
using WPFWCSDemo.Utilities;
|
||||
using WPFWCSDemo.Utilities.Table;
|
||||
using WPFWCSDemo.ViewModels;
|
||||
|
||||
namespace WPFWCSDemo.Schedules
|
||||
{
|
||||
[Obsolete("该类下的方法已经移至其他类中使用",true)]
|
||||
public class TaskFinishSchedule
|
||||
{
|
||||
/// <summary>
|
||||
/// A线单次请求标志
|
||||
/// </summary>
|
||||
public static bool LineAIsAvailable = true;
|
||||
/// <summary>
|
||||
/// B线单次请求标志
|
||||
/// </summary>
|
||||
public static bool LineBIsAvailable = true;
|
||||
/// <summary>
|
||||
/// C线单次请求标志
|
||||
/// </summary>
|
||||
public static bool LineCIsAvailable = true;
|
||||
/// <summary>
|
||||
/// D线单次请求标志
|
||||
/// </summary>
|
||||
public static bool LineDIsAvailable = true;
|
||||
/// <summary>
|
||||
/// AB线单次请求标志
|
||||
/// </summary>
|
||||
public static bool LineABIsAvailable = true;
|
||||
/// <summary>
|
||||
/// CD线单次请求标志
|
||||
/// </summary>
|
||||
public static bool LineCDIsAvailable = true;
|
||||
|
||||
/// <summary>
|
||||
/// 自动完成处于一定时间内【放货中】状态的环穿【实垛】遗留任务
|
||||
/// </summary>
|
||||
public static void DeleteTaskForPuttingTimeout()
|
||||
{
|
||||
//查询【放货中】的任务
|
||||
using DataTable? dt = SqlHelper.ExecuteTable("SELECT TOP 1 * FROM TASK WHERE SCHEDULESTATE=@ScheduleState",
|
||||
new SqlParameter("@ScheduleState", ScheduleStateCode.Trans_CircleRGV_Putting)
|
||||
);
|
||||
if (dt is null || dt.Rows.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < dt.Rows.Count; i++)
|
||||
{
|
||||
//获取第i条记录
|
||||
using TaskRT taskRT = TaskManager.ToModels(dt.Rows[i]);
|
||||
|
||||
TimeSpan diff = DateTime.Now - taskRT.ScheduleTime;
|
||||
|
||||
//处于【放货中】的实垛任务---如果旧任务放货时未正常自动完成,则出现新的同设备任务后,旧任务2分钟后自动完成
|
||||
if (taskRT.TaskType == 10)
|
||||
{
|
||||
//if (diff.TotalMinutes >= 2)
|
||||
//{
|
||||
//查询是否有编号重复的任务
|
||||
int count = SqlHelper.GetRowCount("SELECT * FROM TASK WHERE JOBID=@JobId",
|
||||
new SqlParameter("@JobId", taskRT.JobId)
|
||||
);
|
||||
|
||||
//如果存在编号重复的任务,表示小车已经分配了新任务---将【放货中】的任务设置为超时完成
|
||||
if (count > 1)
|
||||
{
|
||||
//表示小车已接到新任务
|
||||
SqlHelper.ExecuteNonQuery("UPDATE TASK SET TASKSTATE=@TaskState WHERE TASKID=@TaskId",
|
||||
new SqlParameter("@TaskState", TaskStateCode.Task_Finish_Timeout),
|
||||
new SqlParameter("@TaskId", taskRT.TaskId)
|
||||
);
|
||||
|
||||
Log.Warning($"【WCS更新<放货中>状态】任务号:{taskRT.TaskId}已作为遗留任务处理");
|
||||
}
|
||||
|
||||
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 自动完成处于一定时间内【放货完成】状态的环穿遗留任务
|
||||
/// 该原因可能是由于某些因素使程序意外关闭导致的
|
||||
/// </summary>
|
||||
public static void DeleteTaskForFinishTimeout()
|
||||
{
|
||||
//查询【放货完成】的任务
|
||||
using DataTable? dt = SqlHelper.ExecuteTable("SELECT TOP 1 * FROM TASK WHERE SCHEDULESTATE=@ScheduleState AND CREATETIME<@CurrentTime",
|
||||
new SqlParameter("@ScheduleState", ScheduleStateCode.Trans_CircleRGV_Finish),
|
||||
new SqlParameter("@CurrentTime", DateTime.Now.AddMinutes(-8).ToString(TimeFormat.stringFormat))
|
||||
);
|
||||
if (dt is null || dt.Rows.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//获取第i条记录
|
||||
using TaskRT taskRT = TaskManager.ToModels(dt.Rows[0]);
|
||||
|
||||
if (taskRT is null) return;
|
||||
|
||||
//表示小车已接到新任务
|
||||
SqlHelper.ExecuteNonQuery("UPDATE TASK SET TASKSTATE=@TaskState WHERE TASKID=@TaskId",
|
||||
new SqlParameter("@TaskState", TaskStateCode.Task_Finish_Timeout),
|
||||
new SqlParameter("@TaskId", taskRT.TaskId)
|
||||
);
|
||||
|
||||
Log.Warning($"【WCS更新<放货完成>状态】任务号:{taskRT.TaskId}已作为遗留任务处理");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 防错机制(处理长时间可能未正常完成遗留任务记录)---获取下发时间距离当前时间较长的任务
|
||||
/// 将其任务号与执行中的小车匹配
|
||||
/// 判断该任务是否已经执行完成---完成则视为遗留任务处理
|
||||
/// </summary>
|
||||
public static void DeleteTaskForDeviceTaskNumberIsNotExist()
|
||||
{
|
||||
//查找【放货途中】和【放货中】的任务
|
||||
using DataTable? dt = SqlHelper.ExecuteTable("SELECT * FROM TASK WHERE (SCHEDULESTATE=@ScheduleState OR SCHEDULESTATE=@ScheduleState1) AND SCHEDULETIME<@CurrentTime",
|
||||
new SqlParameter("@ScheduleState", ScheduleStateCode.Trans_CircleRGV_PutOnTheWay),
|
||||
new SqlParameter("@ScheduleState1", ScheduleStateCode.Trans_CircleRGV_Putting),
|
||||
new SqlParameter("@CurrentTime", DateTime.Now.AddMinutes(-30).ToString(TimeFormat.stringFormat))
|
||||
);
|
||||
|
||||
if (dt is null || dt.Rows.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < dt.Rows.Count; i++)
|
||||
{
|
||||
using TaskRT? taskRT = TaskManager.ToModels(dt.Rows[i]);
|
||||
|
||||
//获取对应小车编号---此处需要保证小车编号正确性,在更新【放货】阶段的逻辑中再次更新了小车编号
|
||||
if (string.IsNullOrEmpty(taskRT.JobId)) continue;
|
||||
|
||||
//数据类型正确
|
||||
if (int.Parse(taskRT.JobId) > 0 && int.Parse(taskRT.JobId) < 10)
|
||||
{
|
||||
//获取任务表中编号对应的小车
|
||||
CircleRGVState? circleRGVState = CircleRGVsViewModel.GetCircleRGVState(int.Parse(taskRT.JobId));
|
||||
|
||||
if (circleRGVState == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//判断设备任务号是否与任务表中的任务号匹配
|
||||
//匹配---不执行操作
|
||||
//不匹配---视为遗留任务处理
|
||||
if (circleRGVState.Read_TaskNumber.ToString() != taskRT.TaskId)
|
||||
{
|
||||
//表示小车已接到新任务
|
||||
SqlHelper.ExecuteNonQuery("UPDATE TASK SET TASKSTATE=@TaskState WHERE TASKID=@TaskId",
|
||||
new SqlParameter("@TaskState", TaskStateCode.Task_Finish_Timeout),
|
||||
new SqlParameter("@TaskId", taskRT.TaskId)
|
||||
);
|
||||
|
||||
Log.Warning($"【WCS更新任务状态】任务号:{taskRT.TaskId}无法匹配与执行中设备任务号,已作为遗留任务超时处理");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user