using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEA_Comm;
|
using WIDESEA_Comm.LogInfo;
|
using WIDESEA_Comm.TaskNo;
|
using WIDESEA_Core.EFDbContext;
|
using WIDESEA_Entity.DomainModels;
|
using WIDESEA_WCS.IRepositories;
|
using WIDESEA_WCS.Repositories;
|
using WIDESEA_WCS.WCSClient;
|
using WIDESEA_WMS.IRepositories;
|
using WIDESEA_WMS.Repositories;
|
|
namespace WIDESEA_WCS.JobsPart.Common
|
{
|
public class EmptyTrayTask
|
{
|
|
/// <summary>
|
/// 创建补空托任务
|
/// </summary>
|
public static void CreateEmptyTrayTask()
|
{
|
try
|
{
|
var Pipeline_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "链条机");
|
if (Pipeline_client == null) throw new Exception("链条机调度服务未开启!");
|
if (!Pipeline_client.IsConnected) throw new Exception("与链条机连接超时!");
|
VOLContext context = new VOLContext();
|
Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
|
Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(context);
|
List<string> strings = new List<string>() { };
|
var stations = stationinfoRepository.Find(x => x.stationCode.Contains("X") || x.stationCode.Contains("W01001004") || x.stationCode.Contains("W01001005")).ToList();
|
stations = stations.Where(x => x.location_state == "Empty" && x.enable).ToList();
|
foreach (var station in stations)
|
{
|
if (agvtaskRepository.Find(x => x.agv_toaddress == station.stationCode).Any())
|
continue;
|
var PalletSignal = Pipeline_client.ReadByOrder<Int16>("R_PalletSignal", station.stationCode);//读取托盘信号:1:有,2无
|
var MaterialSignal = Pipeline_client.ReadByOrder<Int16>("R_MaterialSignal", station.stationCode);//读取货物信号:1:有,2无
|
if (PalletSignal == 2 && MaterialSignal == 2)
|
{
|
dt_agvtask taskPart = new dt_agvtask()
|
{
|
agv_fromaddress = "",
|
agv_id = Guid.NewGuid(),
|
agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
|
agv_grade = 2,
|
agv_createtime = DateTime.Now,
|
agv_taskstate = "Queue",
|
agv_qty = 1,
|
agv_tasktype = "TaskType_EmptyPallet",
|
agv_toaddress = station.stationCode,
|
agv_userid = "系统",
|
agv_TrayStatus = "EmptyTray",// station.tray_status,
|
agv_Traytype = station.tray_type
|
};
|
station.location_state = LocationStateEnum.Busy.ToString();
|
stationinfoRepository.Update(station, true);
|
agvtaskRepository.Add(taskPart, true);
|
WriteDBLog.Success("创建补空托任务", $"任务编号:{taskPart.agv_tasknum}", "PCS");
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
WriteDBLog.Error("创建补空托任务", $"错误信息:{ex.Message}", "PCS");
|
}
|
}
|
|
/// <summary>
|
/// 库内补空托任务
|
/// </summary>
|
public static void InEmptyTrayTask()
|
{
|
try
|
{
|
VOLContext context = new VOLContext();
|
Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
|
Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(context);
|
var stations = stationinfoRepository.Find(x => x.area == "2" && x.enable && x.location_state == LocationStateEnum.Empty.ToString()).OrderBy(x => x.line).OrderBy(x => x.column).ToList();
|
if (stations.Count < 1)
|
{
|
stations = stationinfoRepository.Find(x => x.area == "3" && x.enable && x.location_state == LocationStateEnum.Empty.ToString()).OrderBy(x => x.line).OrderBy(x => x.column).ToList();
|
}
|
foreach (var station in stations)
|
{
|
if (agvtaskRepository.Find(x => x.agv_toaddress == station.stationCode).Any())
|
continue;
|
dt_agvtask taskPart = new dt_agvtask()
|
{
|
agv_fromaddress = "",
|
agv_id = Guid.NewGuid(),
|
agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
|
agv_grade = 2,
|
agv_createtime = DateTime.Now,
|
agv_taskstate = "Queue",
|
agv_qty = 1,
|
agv_tasktype = "TaskType_EmptyPallet",
|
agv_toaddress = station.stationCode,
|
agv_userid = "系统",
|
agv_TrayStatus = "EmptyTray",// station.tray_status, "SmallTray" : "LargeTray"
|
agv_Traytype = station.area == "4" ? "LargeTray" : "SmallTray",
|
};
|
agvtaskRepository.Add(taskPart, true);
|
station.location_state = LocationStateEnum.InBusy.ToString();
|
stationinfoRepository.Update(station, true);
|
WriteDBLog.Success("创建补库内空托任务", $"任务编号:{taskPart.agv_tasknum}", "PCS");
|
}
|
}
|
catch (Exception ex)
|
{
|
WriteDBLog.Error("创建补库内空托任务", $"错误信息:{ex.Message}", "PCS");
|
//throw;
|
}
|
}
|
}
|
}
|