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_Common;
|
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 == LocationStateEnum.Empty.ToString() && 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)
|
{
|
//if (station.remark == TrayTypeEnum.SmallTray.ToString() || station.remark == TrayTypeEnum.LargeTray.ToString()) station.tray_type = station.remark;
|
|
var agv_task = agvtaskRepository.Find(x => x.agv_taskstate == AGVTaskStateEnum.Queue.ToString() && x.agv_tasktype == AGVTaskTypeEnum.TaskType_EmptyPallet.ToString() && string.IsNullOrEmpty(x.agv_toaddress) && x.agv_Traytype == station.tray_type).OrderByDescending(x => x.agv_grade).ThenBy(x => x.agv_createtime).FirstOrDefault();
|
if (agv_task != null)
|
{
|
agv_task.agv_taskstate = AGVTaskStateEnum.Create.ToString();
|
//agv_task.EndQuantity = EmptyStation.quantity;
|
agv_task.agv_toaddress = station.stationCode;
|
agvtaskRepository.Update(agv_task, true);
|
station.location_state = LocationStateEnum.Busy.ToString();
|
stationinfoRepository.Update(station, true);
|
WriteDBLog.Success("更新补空托任务", $"任务编号:{agv_task.agv_tasknum}", "PCS");
|
}
|
else
|
{
|
dt_agvtask taskPart = new dt_agvtask()
|
{
|
agv_fromaddress = "",
|
agv_id = Guid.NewGuid(),
|
agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
|
agv_grade = station.stationCode.Contains("W0100100") ? 3 : 1,
|
agv_createtime = DateTime.Now,
|
agv_taskstate = AGVTaskStateEnum.Queue.ToString(),
|
agv_qty = 1,
|
agv_tasktype = AGVTaskTypeEnum.TaskType_EmptyPallet.ToString(),
|
agv_toaddress = station.stationCode,
|
agv_userid = "系统",
|
agv_TrayStatus = TrayStateEnum.EmptyTray.ToString(),// 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.stationCode.Contains("C01004") && x.enable && x.location_state == LocationStateEnum.Stroge.ToString()).OrderByDescending(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_fromaddress == station.stationCode).Any())
|
continue;
|
dt_agvtask taskPart = new dt_agvtask()
|
{
|
agv_fromaddress = station.stationCode,
|
agv_id = Guid.NewGuid(),
|
agv_tasknum = IdenxManager.GetTaskNo("KH-", "WMS"),
|
agv_grade = 1,
|
agv_createtime = DateTime.Now,
|
agv_taskstate = "Queue",
|
//agv_materielid = station.stationType,
|
agv_qty = 1,
|
StarQuantity = 0,
|
EndQuantity = 0,// EmptyStation.quantity,
|
agv_tasktype = "TaskType_EmptyPallet",
|
agv_toaddress = "",// EmptyStation.stationCode,
|
agv_userid = "系统",
|
agv_TrayStatus = "EmptyTray",//station.tray_status,
|
agv_Traytype = station.tray_type,
|
};
|
agvtaskRepository.Add(taskPart, true);
|
station.location_state = LocationStateEnum.OutBusy.ToString();
|
stationinfoRepository.Update(station, true);
|
//WriteDBLog.Success("创建空托任务", $"任务编号:{taskPart.agv_tasknum}", "PCS");
|
}
|
}
|
catch (Exception ex)
|
{
|
//WriteDBLog.Error("创建补库内空托任务", $"错误信息:{ex.Message}", "PCS");
|
//throw;
|
}
|
}
|
public static void task()
|
{
|
VOLContext context = new VOLContext();
|
Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context);
|
Idt_agvtaskRepository agvtaskRepository = new dt_agvtaskRepository(context);
|
var tasks = agvtaskRepository.Find(x => x.agv_taskstate == "Queue").OrderBy(x => x.agv_createtime).ToList();
|
foreach (var task in tasks)
|
{
|
if (task.agv_tasktype == "TaskType_EmptyPallet")
|
{
|
if (task.agv_toaddress == "")
|
{
|
var EmptyStation = stationinfoRepository.Find(x => x.area == "11" && x.stationCode.Contains("A") && x.quantity < 5 && x.enable).OrderByDescending(x => x.line).OrderBy(x => x.column).FirstOrDefault();
|
if (EmptyStation == null) return;
|
if (EmptyStation.location_state == LocationStateEnum.Busy.ToString()) return;
|
task.agv_toaddress = EmptyStation.stationCode;
|
task.EndQuantity = EmptyStation.quantity;
|
task.agv_taskstate = "Create";
|
EmptyStation.location_state = LocationStateEnum.Busy.ToString();
|
stationinfoRepository.Update(EmptyStation, true);
|
agvtaskRepository.Update(task, true);
|
}
|
}
|
}
|
}
|
}
|
}
|