using HH.WCS.Hexafluo.util;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
|
namespace HH.WCS.Hexafluo.wms
|
{
|
internal class LocationHelper
|
{
|
private static Dictionary<string, Location> locations = null;
|
// private static Dictionary<string, LocationExt> locationExts = null;
|
|
static LocationHelper()
|
{
|
//初始化location加入到字典缓存
|
try
|
{
|
locations = new Dictionary<string, Location>();
|
var list = GetAllLocList();
|
if (list.Count > 0)
|
{
|
list.ForEach(a =>
|
{
|
if (locations.Keys.Contains(a.S_LOC_CODE.Trim()))
|
{
|
Console.WriteLine($"重复的数据为{a.S_LOC_CODE}");
|
}
|
else
|
{
|
locations.Add(a.S_LOC_CODE.Trim(), a);
|
}
|
});
|
}
|
}
|
catch (Exception ex)
|
{
|
Console.WriteLine(ex.Message);
|
}
|
//初始化locationExt加入到集合缓存
|
//locationExts = new Dictionary<string, LocationExt>();
|
//var exts = GetAllLocExtList();
|
//if (exts.Count > 0)
|
//{
|
// exts.ForEach(a =>
|
// {
|
// locationExts.Add($"{a.S_LOC_CODE.Trim()}_{a.S_PICKUP_POINT.Trim()}", a);
|
// });
|
//}
|
}
|
|
internal static bool CheckExist(string loc)
|
{
|
return locations.Keys.Contains(loc);
|
}
|
internal static Location GetLocation(string loc)
|
{
|
if (CheckExist(loc.Trim()))
|
{
|
return locations[loc.Trim()];
|
}
|
return null;
|
}
|
|
/// <summary>
|
/// 获取货位站点信息
|
/// </summary>
|
/// <param name="loc"></param>
|
/// <returns></returns>
|
internal static int GetAgvSite(string loc)
|
{
|
var site = 0;
|
if (locations.Keys.Contains(loc.Trim()))
|
{
|
var location = locations[loc.Trim()];
|
site = location.N_AGV_CODE;
|
}
|
else
|
{
|
var location = GetLoc(loc.Trim());
|
if (location != null)
|
{
|
locations.Add(loc.Trim(), location);
|
site = location.N_AGV_CODE;
|
}
|
}
|
return site;
|
}
|
|
internal static int GetAgvSiteZc(string loc)
|
{
|
var location = GetLocZc(loc.Trim());
|
return location.N_AGV_CODE;
|
}
|
internal static int GetAgvSiteZc2(string loc)
|
{
|
var location = GetLocZc(loc.Trim());
|
return location.N_AGV_CODE_T;
|
}
|
|
|
internal static int ZcGetAgvSite(string loc)
|
{
|
var site = 0;
|
if (locations.Keys.Contains(loc.Trim()))
|
{
|
var location = locations[loc.Trim()];
|
site = location.N_AGV_CODE;
|
}
|
return site;
|
}
|
|
//internal static int GetAgvSite(string loc, string actionType)
|
//{
|
// var site = 0;
|
// var key = $"{loc.Trim()}_{actionType.Trim()}";
|
// if (locationExts.Keys.Contains(loc.Trim()))
|
// {
|
// var location = locationExts[loc.Trim()];
|
// site = int.Parse(location.S_AGV_SITE);
|
// }
|
// return site;
|
//}
|
|
/// <summary>
|
/// 获取所有货位信息
|
/// </summary>
|
/// <returns></returns>
|
internal static List<Location> GetAllLocList()
|
{
|
return SqlSugarHelper.Db.Queryable<Location>().ToList();
|
}
|
internal static Location GetLoc(string code)
|
{
|
var db = new SqlHelper<object>().GetInstance();
|
return db.Queryable<Location>().Where(a => a.S_LOC_CODE.Trim() == code).First();
|
}
|
internal static Location GetLocZc(string code)
|
{
|
var chi = new SqlHelper<object>().GetInstance();
|
var newDb = chi.CopyNew();
|
return newDb.Queryable<Location>().Where(a => a.S_LOC_CODE.Trim() == code).First();
|
}
|
|
|
/// <summary>
|
/// 判断没有入库锁和出库锁
|
/// </summary>
|
/// <param name="code"></param>
|
/// <returns></returns>
|
internal static bool CheckLocFree(string code)
|
{
|
var result = false;
|
var loc = GetLoc(code);
|
if (loc != null)
|
{
|
result = loc.S_LOCK_STATE.Trim() == "无";
|
}
|
return result;
|
}
|
internal static List<LocCntrRel> GetLocCntr(string loc)
|
{
|
var result = new List<LocCntrRel>();
|
//1.0 查货位容器表
|
var db = new SqlHelper<object>().GetInstance();
|
var list = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE == loc.Trim()).OrderBy(a => a.T_CREATE).ToList();
|
if (list.Count > 0)
|
{
|
list.ForEach(a =>
|
{
|
//获取容器信息
|
var cntr = db.Queryable<Container>().Where(b => b.S_CNTR_CODE == a.S_CNTR_CODE).First();
|
if (cntr != null)
|
{
|
a.Container = cntr;
|
result.Add(a);
|
}
|
});
|
}
|
return result;
|
|
}
|
internal static List<LocCntrRel> GetLocCntrRel(string loc)
|
{
|
//1.0 查货位容器表
|
var db = new SqlHelper<object>().GetInstance();
|
var result = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE == loc.Trim()).ToList();
|
return result;
|
|
}
|
internal static List<Location> GetLocListFull(string area)
|
{
|
//1.0 查货位容器表
|
var db = new SqlHelper<object>().GetInstance();
|
var list = db.Queryable<Location>().Where(a => a.S_AREA_CODE.Trim() == area && a.N_CURRENT_NUM > 0).ToList();
|
return list;
|
}
|
|
/// <summary>
|
/// 获取该库区所有的货位
|
/// </summary>
|
/// <param name="area"></param>
|
/// <returns></returns>
|
internal static List<Location> GetLocListHg(string LocationCode)
|
{
|
//1.0 查货位容器表
|
var db = new SqlHelper<object>().GetInstance();
|
var list = db.Queryable<Location>().LeftJoin<LocCntrRel>((L, Y) => L.S_LOC_CODE == Y.S_LOC_CODE).Where(L => L.S_LOC_CODE.Trim() == LocationCode && L.N_CURRENT_NUM > 0 && L.S_LOCK_STATE == "无").Select(L => L).ToList();
|
return list;
|
}
|
|
internal static List<LocCntrRel> GetTrayList(string LocationCode)
|
{
|
//1.0 查货位容器表
|
var db = new SqlHelper<object>().GetInstance();
|
var list = db.Queryable<LocCntrRel>().Where(T => T.S_LOC_CODE == LocationCode).ToList();
|
return list;
|
}
|
internal static List<CntrItemRel> GetTrayItemList(string TrayCode)
|
{
|
//1.0 查货位容器表
|
var db = new SqlHelper<object>().GetInstance();
|
var list = db.Queryable<CntrItemRel>().Where(T => T.S_CNTR_CODE == TrayCode).ToList();
|
return list;
|
}
|
internal static List<Item> GetItemCodeList(string ItemCode)
|
{
|
//1.0 查货位容器表
|
var db = new SqlHelper<object>().GetInstance();
|
var list = db.Queryable<Item>().Where(T => T.S_ITEM_CODE == ItemCode).ToList();
|
return list;
|
}
|
|
internal static List<Location> GetLocListEmpty(string area)
|
{
|
//1.0 查货位容器表
|
var db = new SqlHelper<object>().GetInstance();
|
var list = db.Queryable<Location>().Where(a => a.S_AREA_CODE.Trim() == area).ToList();
|
return list;
|
|
}
|
internal static List<Location> GetLocListLock(string area)
|
{
|
//1.0 查货位容器表
|
var db = new SqlHelper<object>().GetInstance();
|
var list = db.Queryable<Location>().Where(a => a.S_AREA_CODE.Trim() == area && a.S_LOCK_STATE != "无").ToList();
|
return list;
|
}
|
|
/// <summary>
|
/// 根据货位集合获取有容器的货位
|
/// </summary>
|
/// <param name="loc"></param>
|
/// <returns></returns>
|
internal static List<Location> GetLocList(List<string> loc)
|
{
|
//1.0 查货位容器表
|
var db = new SqlHelper<object>().GetInstance();
|
var list = db.Queryable<Location>().Where(a => loc.Contains(a.S_LOC_CODE) && a.N_CURRENT_NUM > 0).ToList();
|
return list;
|
|
}
|
|
/// <summary>
|
/// 根据货位编码获取货位信息,不管有没有容器
|
/// </summary>
|
/// <param name="loc"></param>
|
/// <returns></returns>
|
internal static List<Location> GetLocListAny(List<string> loc)
|
{
|
//1.0 查货位容器表
|
var db = new SqlHelper<object>().GetInstance();
|
var list = db.Queryable<Location>().Where(a => loc.Contains(a.S_LOC_CODE)).ToList();
|
return list;
|
|
}
|
internal static List<Location> GetLocListCol(int Col)
|
{
|
//1.0 查货位容器表
|
var db = new SqlHelper<object>().GetInstance();
|
var list = db.Queryable<Location>().Where(a => a.N_COL == Col).ToList();
|
return list;
|
|
}
|
|
/// <summary>
|
/// 根据货位集合获取有容器 没有锁的货位
|
/// </summary>
|
/// <param name="loc"></param>
|
/// <returns></returns>
|
internal static List<Location> GetLocListFree(List<string> loc)
|
{
|
//1.0 查货位容器表
|
var db = new SqlHelper<object>().GetInstance();
|
var list = db.Queryable<Location>().Where(a => loc.Contains(a.S_LOC_CODE) && a.N_CURRENT_NUM > 0 && a.S_LOCK_STATE.Trim() == "无").ToList();
|
return list;
|
|
}
|
|
/// <summary>
|
/// 获取固定数量容器 没有锁的货位
|
/// </summary>
|
/// <param name="loc"></param>
|
/// <param name="current"></param>
|
/// <returns></returns>
|
internal static List<Location> GetLocListFree(List<string> loc, int current)
|
{
|
//1.0 查货位容器表
|
var db = new SqlHelper<object>().GetInstance();
|
var list = db.Queryable<Location>().Where(a => loc.Contains(a.S_LOC_CODE) && a.N_CURRENT_NUM == current && a.S_LOCK_STATE.Trim() == "无").ToList();
|
return list;
|
|
}
|
|
/// <summary>
|
/// 获取数量大于等于固定数量容器 没有锁的货位
|
/// </summary>
|
/// <param name="loc"></param>
|
/// <param name="current"></param>
|
/// <returns></returns>
|
internal static List<Location> GetLocList(List<string> loc, int current)
|
{
|
//1.0 查货位容器表
|
var db = new SqlHelper<object>().GetInstance();
|
var list = db.Queryable<Location>().Where(a => loc.Contains(a.S_LOC_CODE) && a.N_CURRENT_NUM >= current && a.S_LOCK_STATE.Trim() == "无").ToList();
|
return list;
|
|
}
|
|
/// <summary>
|
/// 根据货位集合获取 没有容器 没有锁的货位
|
/// </summary>
|
/// <param name="loc"></param>
|
/// <returns></returns>
|
internal static List<Location> GetLocListEmptyFree(List<string> loc)
|
{
|
//1.0 查货位容器表
|
var db = new SqlHelper<object>().GetInstance();
|
var list = db.Queryable<Location>().Where(a => loc.Contains(a.S_LOC_CODE) && a.N_CURRENT_NUM == 0 && a.S_LOCK_STATE.Trim() == "无").ToList();
|
return list;
|
|
}
|
|
/// <summary>
|
/// 入库锁定终点,出库锁定起点
|
/// </summary>
|
/// <param name="loc"></param>
|
/// <param name="lockState">1:入库锁、2:出库锁、2:其它锁</param>
|
/// <returns></returns>
|
public static bool LockLoc(string loc, string lockState)
|
{
|
var res = false;
|
var db = new SqlHelper<object>().GetInstance();
|
var model = db.Queryable<Location>().Where(a => a.S_LOC_CODE == loc).First();
|
if (model != null && model.S_LOCK_STATE.Trim() == "无")
|
{
|
model.S_LOCK_STATE = lockState;
|
res = db.Updateable(model).UpdateColumns(it => new { it.S_LOCK_STATE }).ExecuteCommand() > 0;
|
}
|
return res;
|
}
|
|
/// <summary>
|
/// 绑定解绑
|
/// </summary>
|
/// <param name="loc"></param>
|
/// <returns></returns>
|
public static bool BindLoc(string loc, int I)
|
{
|
var res = false;
|
LogHelper.CameraInfo("UnLockLoc:" + loc);
|
var db = new SqlHelper<object>().GetInstance();
|
var model = db.Queryable<Location>().Where(a => a.S_LOC_CODE == loc).First();
|
if (model != null && I == 1)
|
{
|
model.N_CURRENT_NUM = 1;
|
res = db.Updateable(model).UpdateColumns(it => new { it.N_CURRENT_NUM }).ExecuteCommand() > 0;
|
Console.WriteLine("绑定 货位:" + loc + " 是否成功:" + res);
|
LogHelper.CameraInfo("绑定 货位:" + loc + " 是否成功:" + res);
|
}
|
else if (model != null && I == 0)
|
{
|
model.N_CURRENT_NUM = 0;
|
res = db.Updateable(model).UpdateColumns(it => new { it.N_CURRENT_NUM }).ExecuteCommand() > 0;
|
Console.WriteLine("解绑 货位:" + loc + " 是否成功:" + res);
|
LogHelper.CameraInfo("解绑 货位:" + loc + " 是否成功:" + res);
|
}
|
|
return res;
|
}
|
|
/// <summary>
|
/// 取货完解锁起点,卸货完解锁终点,可检验锁的来源,也可以不校验
|
/// </summary>
|
/// <param name="loc"></param>
|
/// <returns></returns>
|
public static bool UnLockLoc(string loc)
|
{
|
LogHelper.CompInfo("UnLockLoc:" + loc);
|
var res = false;
|
var db = new SqlHelper<object>().GetInstance();
|
var model = db.Queryable<Location>().Where(a => a.S_LOC_CODE == loc).First();
|
if (model != null)
|
{
|
model.S_LOCK_STATE = "无";
|
res = db.Updateable(model).UpdateColumns(it => new { it.S_LOCK_STATE }).ExecuteCommand() > 0;
|
LogHelper.CompInfo("UnLockLoc:解锁结果" + res);
|
}
|
else
|
{
|
LogHelper.CompInfo("UnLockLoc 失败");
|
}
|
return res;
|
}
|
|
/// <summary>
|
/// 删除货位容器表记录,修改货位容器数量
|
/// </summary>
|
/// <param name="loc"></param>
|
/// <param name="cntrs"></param>
|
/// <returns></returns>
|
public static bool UnBindingLoc(string loc, List<string> cntrs)
|
{
|
var res = false;
|
var db = new SqlHelper<object>().GetInstance();
|
var location = db.Queryable<Location>().Where(a => a.S_LOC_CODE == loc).First();
|
try
|
{
|
var lcrList = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE == loc).ToList();
|
db.BeginTran();
|
var count = db.Deleteable<LocCntrRel>().Where(it => cntrs.Contains(it.S_CNTR_CODE) && it.S_LOC_CODE == loc).ExecuteCommand();
|
location.N_CURRENT_NUM = lcrList.Count - count;
|
location.S_LOCK_STATE = "无";
|
db.Updateable(location).UpdateColumns(it => new { it.N_CURRENT_NUM, it.S_LOCK_STATE }).ExecuteCommand();
|
db.Ado.CommitTran();
|
res = true;
|
}
|
catch (Exception ex)
|
{
|
db.Ado.RollbackTran();
|
}
|
return res;
|
}
|
/// <summary>
|
/// 货位绑定容器
|
/// </summary>
|
/// <param name="loc"></param>
|
/// <param name="cntrs"></param>
|
/// <returns></returns>
|
public static bool BindingLoc(string loc, List<string> cntrs)
|
{
|
var res = false;
|
var db = new SqlHelper<object>().GetInstance();
|
var location = db.Queryable<Location>().Where(a => a.S_LOC_CODE == loc).First();
|
try
|
{
|
var lcrList = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE == loc).ToList();
|
db.BeginTran();
|
int count = 0;
|
cntrs.ForEach(a =>
|
{
|
if (lcrList.Count(b => b.S_CNTR_CODE.Trim() == a) == 0)
|
{
|
db.Insertable<LocCntrRel>(new LocCntrRel { S_LOC_CODE = loc, S_CNTR_CODE = a }).ExecuteCommand();
|
count++;
|
}
|
});
|
location.N_CURRENT_NUM = lcrList.Count + count;
|
location.S_LOCK_STATE = "无";
|
db.Updateable(location).UpdateColumns(it => new { it.N_CURRENT_NUM, it.S_LOCK_STATE }).ExecuteCommand();
|
db.Ado.CommitTran();
|
res = true;
|
}
|
catch (Exception ex)
|
{
|
db.Ado.RollbackTran();
|
Console.WriteLine("货位绑定容器 释放报错:" + ex.Message);
|
}
|
return res;
|
}
|
|
/// <summary>
|
/// 先获取字典中的货位信息 如果没有则查询数据库 并更新字段
|
/// </summary>
|
/// <returns></returns>
|
public static Location LocationCode(string loc)
|
{
|
try
|
{
|
var loca = GetLocation(loc);
|
if (loca == null)
|
{
|
var location = SqlSugarHelper.Db.Queryable<Location>().Where(a => a.S_LOC_CODE == loc)?.First();
|
if (location != null)
|
{
|
locations.Add(location.S_LOC_CODE.Trim(), location);
|
return location;
|
}
|
else
|
{
|
return null;
|
}
|
}
|
else
|
{
|
return loca;
|
}
|
}
|
catch (Exception ex)
|
{
|
LogHelper.Info("处理自管任务", "查询货位码时报错:" + ex.Message + ex.StackTrace);
|
return null;
|
}
|
}
|
|
public static Location LocationCodeJbw(string loc)
|
{
|
try
|
{
|
var location = SqlSugarHelper.Db.Queryable<Location>().Where(a => a.S_LOC_CODE == loc)?.First();
|
return location;
|
}
|
catch (Exception ex)
|
{
|
LogHelper.Info("处理自管任务", "查询货位码时报错:" + ex.Message + ex.StackTrace);
|
return null;
|
}
|
}
|
}
|
}
|