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_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;
|
inventory = inventoryRepository.Find(x => x.FigureNumber == mesinfo.drawingNo).OrderByDescending(x => x.OnlineTime).FirstOrDefault();
|
|
#region 根据条件查询库存
|
//if (mesinfo.heatID != null)
|
//{
|
// inventory = inventoryRepository.Find(x => x.HeatNumber == mesinfo.heatID && x.FigureNumber == mesinfo.drawingNo && x.jobID == mesinfo.workOrder).OrderByDescending(x => x.OnlineTime).FirstOrDefault();
|
//}
|
//else
|
//{
|
// inventory = inventoryRepository.Find(x => x.FigureNumber == mesinfo.drawingNo && x.jobID == mesinfo.workOrder).OrderByDescending(x => x.OnlineTime).FirstOrDefault();
|
//}
|
#endregion
|
|
#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;
|
}
|
}
|
//if (TargetLocation != null) return TargetLocation;
|
}
|
#endregion
|
|
#region 寻找已分配同图号入库任务库位
|
TargetLocation = stationinfoRepository.Find(x => x.stationType == stationinfo.stationType && 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.column == TargetLocation.column && x.location_state == LocationStateEnum.Empty.ToString() && x.enable && x.area == TargetLocation.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 == 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 area1 = string.IsNullOrEmpty(mesinfo.area) ? GetArea(mesinfo.quantity, e) : mesinfo.area;
|
//var area = string.IsNullOrEmpty(mesinfo.area) ? GetArea(mesinfo.quantity, stationinfo.tray_type) : mesinfo.area;
|
var area = GetArea(mesinfo.quantity, stationinfo.tray_type);
|
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")
|
{
|
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)
|
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="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;
|
}
|
}
|
//if (TargetLocation != null) return TargetLocation;
|
}
|
#endregion
|
|
#region 未找到库存或当前库存行已满,寻找新的一行
|
//var area1 = string.IsNullOrEmpty(mesinfo.area) ? GetArea(mesinfo.quantity, e) : mesinfo.area;
|
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";
|
}
|
}
|
}
|