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_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;
|
using static System.Collections.Specialized.BitVector32;
|
|
namespace WIDESEA_WCS.JobsPart.Common
|
{
|
public class GetStation
|
{
|
/// <summary>
|
/// 当前库位同一行是否存在入库占用
|
/// true:是 false:否
|
/// </summary>
|
/// <param name="StationCode"></param>
|
/// <returns></returns>
|
public static bool InBusyStation(string StationCode)
|
{
|
bool OK = false;
|
try
|
{
|
VOLContext Context = new VOLContext();
|
Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
|
var station = stationinfoRepository.Find(x => x.stationCode == StationCode).FirstOrDefault();
|
OK = stationinfoRepository.Find(x => x.area == station.area && x.line == station.line && x.location_state == LocationStateEnum.InBusy.ToString()).Any();
|
}
|
catch (Exception ex)
|
{
|
|
}
|
return OK;
|
}
|
/// <summary>
|
/// 当前库位同一行是否存在出库占用
|
/// true:是 false:否
|
/// </summary>
|
/// <param name="StationCode"></param>
|
/// <returns></returns>
|
public static bool OutBusyStation(string StationCode)
|
{
|
bool OK = false;
|
try
|
{
|
VOLContext Context = new VOLContext();
|
Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
|
var station = stationinfoRepository.Find(x => x.stationCode == StationCode).FirstOrDefault();
|
OK = stationinfoRepository.Find(x => x.area == station.area && x.line == station.line && x.location_state == LocationStateEnum.OutBusy.ToString()).Any();
|
}
|
catch (Exception ex)
|
{
|
|
}
|
return OK;
|
}
|
/// <summary>
|
/// 当前库位外边的货位是否都为空
|
/// true:否 false:是
|
/// </summary>
|
/// <param name="StationCode"></param>
|
/// <returns></returns>
|
public static bool QueueStation(string StationCode)
|
{
|
bool OK = false;
|
try
|
{
|
VOLContext Context = new VOLContext();
|
Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
|
var station = stationinfoRepository.Find(x => x.stationCode == StationCode).FirstOrDefault();
|
if (station.area == "10" || station.area == "11")
|
{
|
OK = stationinfoRepository.Find(x => x.area == station.area && x.line == station.line && x.column < station.column && x.location_state != LocationStateEnum.Empty.ToString()).Any();
|
}
|
else
|
{
|
OK = stationinfoRepository.Find(x => x.area == station.area && x.line == station.line && x.column > station.column && x.location_state != LocationStateEnum.Empty.ToString()).Any();
|
}
|
|
}
|
catch (Exception ex)
|
{
|
|
}
|
return OK;
|
}
|
/// <summary>
|
/// 找可入库空托位
|
/// </summary>
|
public static void EmptyStation()
|
{
|
try
|
{
|
VOLContext Context = new VOLContext();
|
Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
|
Idt_agvtaskRepository agvtaskService = new dt_agvtaskRepository(Context);
|
var Stations = stationinfoRepository.Find(x => x.stationCode.Contains("DD") && x.quantity == 5 && x.enable).ToList();
|
foreach (var Station in Stations)
|
{
|
var area = Station.tray_type == "SmallTray" ? "11" : "10";
|
}
|
}
|
catch (Exception ex)
|
{
|
|
}
|
}
|
|
/// <summary>
|
/// 获取空托盘货位
|
/// </summary>
|
/// <returns></returns>
|
public static void EmptyPalletStation(dt_agvtask task)
|
{
|
dt_stationinfo EmptyStation = null;
|
try
|
{
|
VOLContext Context = new VOLContext();
|
Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
|
Idt_agvtaskRepository agvtaskService = new dt_agvtaskRepository(Context);
|
var Pipeline_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "链条机");
|
if (Pipeline_client == null) throw new Exception("链条机调度服务未开启!");
|
if (!Pipeline_client.IsConnected) throw new Exception("与链条机连接超时!");
|
var area = task.agv_Traytype == "SmallTray" ? "11" : "10";
|
|
#region 查找AB库区可出库空托货位
|
if (area == "11")
|
{
|
EmptyStation = stationinfoRepository.Find(x => x.quantity > 0 && (x.area == "2" || x.area == "3") && x.tray_status == TrayStateEnum.EmptyTray.ToString() && x.enable).OrderBy(x => x.area).ThenBy(x => x.line).ThenByDescending(x => x.column).FirstOrDefault();
|
|
#region 必须出完AB库空托才能出空托区
|
//if (EmptyStation != null)
|
// if (QueueStation(EmptyStation.stationCode) || stationinfoRepository.Find(x => x.line == EmptyStation.line && x.area == EmptyStation.area && x.location_state.Contains("Busy")).Any()) return;
|
#endregion
|
|
#region AB库空托位占用出空托区
|
if (EmptyStation != null)
|
if (QueueStation(EmptyStation.stationCode) || stationinfoRepository.Find(x => x.line == EmptyStation.line && x.area == EmptyStation.area && x.location_state.Contains("Busy")).Any()) EmptyStation = null;
|
#endregion
|
}
|
#endregion
|
|
#region 查找空托库区
|
if (EmptyStation == null)
|
EmptyStation = stationinfoRepository.Find(x => x.quantity > 0 && x.area == area && x.tray_status == TrayStateEnum.EmptyTray.ToString() && x.enable).OrderBy(x => x.column).FirstOrDefault();
|
#endregion
|
|
#region 空托货位不为空判断是否存在其他任务
|
if (EmptyStation != null)
|
if (QueueStation(EmptyStation.stationCode) || stationinfoRepository.Find(x => x.line == EmptyStation.line && x.area == EmptyStation.area && x.location_state.Contains("Busy")).Any()) EmptyStation = null;
|
#endregion
|
|
#region 更新补空托队列任务
|
if (EmptyStation != null)
|
{
|
var PalletSignal = Pipeline_client.ReadByOrder<Int16>("R_PalletSignal", task.agv_toaddress);//读取托盘信号:1:有,2无
|
var MaterialSignal = Pipeline_client.ReadByOrder<Int16>("R_MaterialSignal", task.agv_toaddress);//读取货物信号:1:有,2无
|
if (PalletSignal == 2 && MaterialSignal == 2)
|
{
|
task.agv_fromaddress = EmptyStation.stationCode;
|
task.StarQuantity = EmptyStation.quantity - 1;
|
task.agv_taskstate = "Create";
|
agvtaskService.Update(task, true);
|
EmptyStation.location_state = LocationStateEnum.Busy.ToString();
|
stationinfoRepository.Update(EmptyStation, true);
|
WriteDBLog.Success("更新空盘队列任务", $"任务编号:{task.agv_tasknum}", "PCS");
|
}
|
}
|
#endregion
|
|
}
|
catch (Exception ex)
|
{
|
throw;
|
}
|
}
|
public static dt_stationinfo Station(dt_stationinfo EmptyStation, Idt_stationinfoRepository stationinfoRepository)
|
{
|
dt_stationinfo stationinfo = null;
|
try
|
{
|
if (stationinfoRepository.Find(x => x.area == EmptyStation.area && x.line == EmptyStation.line && x.location_state.Contains("Busy")).Any()) return stationinfo;
|
|
|
stationinfo = stationinfoRepository.Find(x => x.area == EmptyStation.area && x.line == EmptyStation.line && x.quantity > 0 && x.enable).OrderByDescending(x => x.column).FirstOrDefault();
|
if (stationinfo != null)
|
{
|
if (stationinfo.quantity < 5) return stationinfo;
|
else
|
stationinfo = stationinfoRepository.Find(x => x.area == EmptyStation.area && x.line == EmptyStation.line && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.column).FirstOrDefault();
|
}
|
else
|
{
|
stationinfo = stationinfoRepository.Find(x => x.area == EmptyStation.area && x.line == EmptyStation.line && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.column).FirstOrDefault();
|
}
|
//if (stationinfo == null)
|
|
}
|
catch (Exception ex)
|
{
|
|
}
|
return stationinfo;
|
}
|
/// <summary>
|
/// 空托可入库货位
|
/// </summary>
|
/// <param name="area"></param>
|
/// <returns></returns>
|
public static dt_stationinfo EmptyPalletStation(string area)
|
{
|
dt_stationinfo stationinfo = null;
|
try
|
{
|
VOLContext Context = new VOLContext();
|
Idt_agvtaskRepository agvtaskService = new dt_agvtaskRepository(Context);
|
Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(Context);
|
|
#region 查找空托盘库区
|
//if (stationinfoRepository.Find(x => x.area == area && x.location_state == LocationStateEnum.Busy.ToString()).Any() && area != "10")
|
if (stationinfoRepository.Find(x => x.stationCode == "A01001001" && x.quantity == 5 && x.location_state == LocationStateEnum.Stroge.ToString()).Any())
|
{
|
var EmptyStation = stationinfoRepository.Find(x => x.stationCode == "C01005002" && x.location_state == LocationStateEnum.Empty.ToString()).FirstOrDefault();
|
if (EmptyStation != null)
|
{
|
if (!stationinfoRepository.Find(x => x.line == EmptyStation.line && x.area == EmptyStation.area && x.location_state != LocationStateEnum.Empty.ToString()).Any())
|
return EmptyStation;
|
}
|
EmptyStation = stationinfoRepository.Find(x => x.quantity > 0 && x.stationCode == "C01005002" && x.location_state == "Stroge" && x.tray_status == "EmptyTray" && x.enable).FirstOrDefault();
|
|
|
if (EmptyStation != null) stationinfo = Station(EmptyStation, stationinfoRepository);
|
if (stationinfo != null) return stationinfo;
|
|
EmptyStation = stationinfoRepository.Find(x => x.area == EmptyStation.area && x.line == EmptyStation.line && x.enable).OrderByDescending(x => x.column).FirstOrDefault();
|
|
if (EmptyStation.quantity == 5)
|
{
|
EmptyStation = stationinfoRepository.Find(x => x.stationCode == "C01004002" && x.location_state == LocationStateEnum.Empty.ToString()).FirstOrDefault();
|
if (EmptyStation != null)
|
{
|
if (!stationinfoRepository.Find(x => x.line == EmptyStation.line && x.area == EmptyStation.area && x.location_state != LocationStateEnum.Empty.ToString()).Any())
|
return EmptyStation;
|
}
|
|
EmptyStation = stationinfoRepository.Find(x => x.quantity > 0 && x.stationCode == "C01004002" && x.location_state == "Stroge" && x.tray_status == "EmptyTray" && x.enable).FirstOrDefault();
|
if (EmptyStation != null) stationinfo = Station(EmptyStation, stationinfoRepository);
|
}
|
|
}
|
else
|
{
|
if (stationinfoRepository.Find(x => x.area == area && x.location_state == LocationStateEnum.Busy.ToString()).Any()) return stationinfo;
|
stationinfo = stationinfoRepository.Find(x => x.area == area && x.quantity > 0 && x.enable).OrderBy(x => x.column).FirstOrDefault();
|
if (stationinfo != null)
|
if (stationinfo.quantity < 5) return stationinfo;
|
stationinfo = stationinfoRepository.Find(x => x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderByDescending(x => x.column).FirstOrDefault();
|
|
}
|
#endregion
|
}
|
catch (Exception ex)
|
{
|
throw;
|
}
|
return stationinfo;
|
}
|
}
|
}
|