using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEA_Comm;
|
using WIDESEA_Core.EFDbContext;
|
using WIDESEA_Entity.DomainModels;
|
using WIDESEA_WCS.IRepositories;
|
using WIDESEA_WCS.Repositories;
|
using WIDESEA_WMS.IRepositories;
|
using WIDESEA_WMS.Repositories;
|
using static System.Collections.Specialized.BitVector32;
|
|
namespace WIDESEA_WCS.JobsPart.Common
|
{
|
public class GetLocation
|
{
|
private static readonly object GetEmptyLocationobj = new object();
|
/// <summary>
|
/// 获取可入库空货位
|
/// </summary>
|
/// <param name="stationinfoRepository"></param>
|
/// <param name="mesinfo"></param>
|
/// <param name="stationinfo"></param>
|
/// <returns></returns>
|
public static dt_stationinfo GetEmptyLocation(Idt_stationinfoRepository stationinfoRepository, VV_Mes_Workinfo mesinfo, dt_agvtask agvtask)
|
{
|
lock (GetEmptyLocationobj)
|
{
|
try
|
{
|
VOLContext context = new VOLContext();
|
Idt_inventoryRepository inventoryRepository = new dt_inventoryRepository(context);
|
string area1 = "";
|
if (agvtask.agv_Traytype == "LargeTray")
|
area1 = "4";
|
|
dt_stationinfo TargetLocation = null;
|
|
#region 寻找已分配同图号入库任务库位
|
TargetLocation = area1 == "4" ? stationinfoRepository.Find(x => x.stationType == agvtask.agv_materielid && x.location_state == LocationStateEnum.InBusy.ToString() && x.enable && x.area == area1).FirstOrDefault() : stationinfoRepository.Find(x => x.stationType == agvtask.agv_materielid && x.location_state == LocationStateEnum.InBusy.ToString() && (x.area == "2" || x.area == "3") && x.enable).FirstOrDefault();
|
if (TargetLocation != null)
|
{
|
TargetLocation = stationinfoRepository.Find(x => x.line == TargetLocation.line && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == TargetLocation.area).OrderBy(x => x.column).FirstOrDefault();
|
if (TargetLocation != null)
|
if (!GetStation.OutBusyStation(TargetLocation.stationCode) && !GetStation.QueueStation(TargetLocation.stationCode)) return TargetLocation;
|
}
|
#endregion
|
|
#region 查找库存
|
dt_inventory inventory = null;
|
inventory = area1 == "4" ? inventoryRepository.Find(x => x.FigureNumber == agvtask.agv_materielid && x.area == area1).OrderByDescending(x => x.OnlineTime).FirstOrDefault()
|
: inventoryRepository.Find(x => x.FigureNumber == agvtask.agv_materielid && (x.area == "2" || x.area == "3")).OrderByDescending(x => x.OnlineTime).FirstOrDefault();
|
#endregion
|
|
|
#region 根据库存查找可入库空货位
|
if (inventory != null)
|
{
|
var station = stationinfoRepository.FindFirst(x => x.stationCode == inventory.stationCode);
|
|
#region 寻找已分配同图号入库任务库位
|
//TargetLocation = stationinfoRepository.Find(x => x.stationType == agvtask.agv_materielid && x.location_state == LocationStateEnum.InBusy.ToString() && x.area == station.area).FirstOrDefault();
|
//if (TargetLocation != null)
|
//{
|
// TargetLocation = stationinfoRepository.Find(x => x.line == TargetLocation.line && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == TargetLocation.area).OrderBy(x => x.column).FirstOrDefault();
|
// if (TargetLocation != null)
|
// {
|
// if (!stationinfoRepository.Find(x => x.line == TargetLocation.line && x.area == TargetLocation.area && x.location_state == LocationStateEnum.OutBusy.ToString()).Any())
|
// return TargetLocation;
|
// }
|
//}
|
#endregion
|
|
#region 判断当前行是否还有空货位
|
TargetLocation = stationinfoRepository.Find(x => x.line == station.line && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == station.area).OrderBy(x => x.column).FirstOrDefault();
|
if (TargetLocation != null)
|
{
|
if (!GetStation.OutBusyStation(TargetLocation.stationCode) && !GetStation.QueueStation(TargetLocation.stationCode))
|
return TargetLocation;
|
}
|
#endregion
|
|
#region 寻找空货位
|
//var TargetLocations1 = stationinfoRepository.Find(x => x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == station.area).OrderBy(x => x.line).ThenBy(x => x.column).ToList();
|
//foreach (var Location in TargetLocations1)
|
//{
|
// if (stationinfoRepository.Find(x => x.line == Location.line && x.area == Location.area && x.stationType == agvtask.agv_materielid).Any())
|
// if (!stationinfoRepository.Find(x => x.line == Location.line && x.area == Location.area && x.location_state == LocationStateEnum.OutBusy.ToString()).Any()) return Location;
|
//}
|
#endregion
|
|
}
|
#endregion
|
|
#region 寻找已分配同图号入库任务库位
|
//TargetLocation = stationinfoRepository.Find(x => x.stationType == agvtask.agv_materielid && x.location_state == LocationStateEnum.InBusy.ToString() && (x.area == "1" || x.area == "2" || x.area == "3" || x.area == "4")).FirstOrDefault();
|
//if (TargetLocation != null)
|
//{
|
// if (TargetLocation.area == "1")
|
// {
|
// TargetLocation = stationinfoRepository.Find(x => x.line == TargetLocation.line && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == TargetLocation.area).OrderBy(x => x.column).FirstOrDefault();//按行存放
|
|
// if (TargetLocation != null)
|
// {
|
// if (!stationinfoRepository.Find(x => x.column == TargetLocation.column && x.area == TargetLocation.area /*&& x.enable*/ && x.location_state == LocationStateEnum.OutBusy.ToString()).Any())
|
// return TargetLocation;
|
// }
|
// }
|
// else
|
// {
|
// TargetLocation = stationinfoRepository.Find(x => x.line == TargetLocation.line && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == TargetLocation.area).OrderBy(x => x.column).FirstOrDefault();
|
// if (TargetLocation != null)
|
// {
|
// if (!stationinfoRepository.Find(x => x.line == TargetLocation.line && x.area == TargetLocation.area && x.location_state == LocationStateEnum.OutBusy.ToString()).Any())
|
// return TargetLocation;
|
// }
|
// }
|
//}
|
#endregion
|
|
#region 寻找对应库区空货位
|
//var TargetLocations = area1 == "4" ? stationinfoRepository.Find(x => x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == "4").OrderBy(x => x.line).ThenBy(x => x.column).ToList()
|
// : stationinfoRepository.Find(x => x.location_state == LocationStateEnum.Empty.ToString() && x.enable && (x.area == "2" || x.area == "3")).OrderBy(x => x.line).ThenBy(x => x.column).ToList();
|
//foreach (var Location in TargetLocations)
|
//{
|
// if (stationinfoRepository.Find(x => x.line == Location.line && x.area == Location.area && x.stationType == agvtask.agv_materielid).Any())
|
// if (!stationinfoRepository.Find(x => x.line == Location.line && x.area == Location.area && x.location_state == LocationStateEnum.OutBusy.ToString()).Any()) return Location;
|
//}
|
#endregion
|
|
#region 未找到库存或当前库存行已满,寻找新的一行
|
var area = GetArea(mesinfo.quantity, agvtask.agv_Traytype);
|
TargetLocation = stationinfoRepository.Find(x => x.column == (area == "2" ? 1 : 2) && x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).FirstOrDefault();
|
if (TargetLocation == null && area != "4")
|
{
|
area = area == "2" ? "3" : "2";
|
TargetLocation = stationinfoRepository.Find(x => x.column == (area == "2" ? 1 : 2) && x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).FirstOrDefault();
|
}
|
|
#region 查看当前空货位后是否存在有料
|
if (TargetLocation != null)
|
if (GetStation.QueueStation(TargetLocation.stationCode)) TargetLocation = null;
|
#endregion
|
|
#endregion
|
|
if (TargetLocation == null) throw new Exception("库位已满");
|
return TargetLocation;
|
}
|
catch (Exception ex)
|
{
|
throw;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 获取入库空货位
|
/// </summary>
|
/// <param name="stationinfoRepository"></param>
|
/// <param name="mesinfo"></param>
|
/// <param name="stationinfo"></param>
|
/// <param name="CompeletedNum"></param>
|
/// <param name="e"></param>
|
/// <returns></returns>
|
/// <exception cref="Exception"></exception>
|
public static dt_stationinfo GetEmptyLocation(Idt_stationinfoRepository stationinfoRepository, dt_mes_head mesinfo, dt_stationinfo stationinfo)
|
{
|
lock (GetEmptyLocationobj)
|
{
|
try
|
{
|
VOLContext context = new VOLContext();
|
Idt_mes_detailRepository mes_DetailRepository = new dt_mes_detailRepository(context);
|
Idt_inventoryRepository inventoryRepository = new dt_inventoryRepository(context);
|
var detail = mes_DetailRepository.Find(x => x.jobID == mesinfo.jobID).FirstOrDefault();
|
if (detail == null)
|
{
|
stationinfo.remark = "触发入库任务,但未找到工单子表!";
|
stationinfo.location_state = LocationStateEnum.Abnormal.ToString();
|
stationinfoRepository.Update(stationinfo, true);
|
return null;
|
}
|
#region 查找库存
|
dt_inventory inventory = null;
|
if (detail.heatID != null)
|
{
|
inventory = inventoryRepository.Find(x => /*x.HeatNumber == detail.heatID &&*/ x.FigureNumber == mesinfo.drawingNo /*&& x.jobID == mesinfo.jobID*/).OrderByDescending(x => x.OnlineTime).FirstOrDefault();
|
}
|
else
|
{
|
inventory = inventoryRepository.Find(x => x.FigureNumber == mesinfo.drawingNo /*&& x.jobID == mesinfo.jobID*/).OrderByDescending(x => x.OnlineTime).FirstOrDefault();
|
}
|
#endregion
|
|
dt_stationinfo TargetLocation = null;
|
|
#region 根据库存查找可入库空货位
|
if (inventory != null)
|
{
|
var station = stationinfoRepository.FindFirst(x => x.stationCode == inventory.stationCode);
|
if (station.area == "1")
|
{
|
TargetLocation = stationinfoRepository.Find(x => x.column == station.column && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == inventory.area).OrderByDescending(x => x.line).FirstOrDefault();
|
if (TargetLocation != null)
|
{
|
if (!stationinfoRepository.Find(x => x.column == TargetLocation.column && x.area == TargetLocation.area /*&& x.enable*/ && x.location_state == LocationStateEnum.OutBusy.ToString()).Any())
|
return TargetLocation;
|
}
|
}
|
else
|
{
|
TargetLocation = stationinfoRepository.Find(x => x.line == station.line && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == inventory.area).OrderBy(x => x.column).FirstOrDefault();
|
if (TargetLocation != null)
|
{
|
if (!stationinfoRepository.Find(x => x.line == TargetLocation.line && x.area == TargetLocation.area && x.location_state == LocationStateEnum.OutBusy.ToString()).Any())
|
return TargetLocation;
|
}
|
}
|
}
|
#endregion
|
|
#region 未找到库存或当前库存行已满,寻找新的一行
|
var area = string.IsNullOrEmpty(mesinfo.area) ? GetArea(mesinfo.quantity, stationinfo.tray_type) : mesinfo.area;
|
TargetLocation = stationinfoRepository.Find(x => x.column == (area == "2" ? 1 : 10) && x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).ThenBy(x => x.column).FirstOrDefault();
|
if (TargetLocation == null)
|
{
|
if (area == "2")
|
area = "3";
|
else if (area == "3")
|
area = "2";
|
TargetLocation = stationinfoRepository.Find(x => x.column == (area == "2" ? 1 : 10) && x.area == area && x.location_state == LocationStateEnum.Empty.ToString() && x.enable).OrderBy(x => x.line).ThenBy(x => x.column).FirstOrDefault();
|
if (TargetLocation == null && area != "4")
|
TargetLocation = stationinfoRepository.Find(x => x.line == 2 && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == "1").OrderBy(x => x.column).FirstOrDefault();
|
}
|
#endregion
|
|
if (TargetLocation == null) throw new Exception("库位已满");
|
return TargetLocation;
|
}
|
catch (Exception ex)
|
{
|
throw;
|
}
|
}
|
}
|
/// <summary>
|
/// 根据托盘类型选择库区
|
/// </summary>
|
/// <param name="quantity"></param>
|
/// <param name="tray_type"></param>
|
/// <returns></returns>
|
private static string GetArea(int quantity, string tray_type)
|
{
|
if (tray_type == "SmallTray")
|
{
|
if (quantity <= 180)
|
return "2";
|
else
|
return "3";
|
}
|
else
|
return "4";
|
}
|
|
/// <summary>
|
/// 根据车轮大小选择库区
|
/// </summary>
|
/// <param name="quantity"></param>
|
/// <param name="e"></param>
|
/// <returns></returns>
|
private static string GetArea(int quantity, float e)
|
{
|
if (e < 1100)
|
{
|
if (quantity <= 180)
|
return "2";
|
else
|
return "3";
|
}
|
else
|
return "4";
|
}
|
}
|
}
|