Files
FT479/WPFWCSDemo/Schedules/CircleRGV/Generate.cs
2026-06-29 14:46:32 +08:00

218 lines
9.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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}");
}
}
}