using Model.InterFaceModel;
|
using Model.ModelDto.SysDto;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using WMS.DAL;
|
using WMS.Entity.Context;
|
using WMS.Entity.DataEntity;
|
using WMS.Entity.LogEntity;
|
using WMS.Entity.SysEntity;
|
using WMS.IBLL.IBllTransServer;
|
|
namespace WMS.BLL.BllTransServer
|
{
|
public class HopperTransportServer: IHopperTransportServer
|
{
|
private static readonly SqlSugarScope Db = DataContext.Db;
|
|
private readonly object RcsLock = new object();
|
|
|
public List<SysStorageArea> GetAreaListByUser(int userId)
|
{
|
try
|
{
|
//根据用户角色权限获取当前角色的区域
|
var user = Db.Queryable<SysUserInfor>().First(m=>m.IsDel == "0" && m.Id == userId);
|
if (user == null)
|
{
|
throw new Exception("没有查询到用户信息");
|
}
|
var role = Db.Queryable<SysRoles>().First(m => m.IsDel == "0" && m.RoleNo == user.RoleNo);
|
if (role == null)
|
{
|
throw new Exception("没有查询到角色信息");
|
}
|
var roleWareStr = Db.Queryable<SysRoleWareHouse>().Where(m => m.IsDel == "0" && m.RoleNo == role.RoleNo).Select(m=>m.WareHouseNo).ToList();
|
|
var area = Db.Queryable<SysStorageArea>().Where(m => m.IsDel == "0" && m.Status == "0" && roleWareStr.Contains(m.WareHouseNo)).ToList();
|
//var layer = "3";
|
//var areaList = new List<SysStorageArea>();
|
//if (layer == "3")
|
//{
|
// areaList = area.Where(m => m.AreaName.Contains("3楼")).ToList();
|
//}
|
//else if (layer == "4")
|
//{
|
// areaList = area.Where(m => m.AreaName.Contains("4楼")).ToList();
|
//}
|
return area;
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
public List<SysStorageLocat> GetLocatByArea(string area)
|
{
|
try
|
{
|
var locate = Db.Queryable<SysStorageLocat>().Where(m => m.AreaNo == area && m.IsDel == "0" && m.Flag == "0").ToList();
|
|
return locate;
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
public List<DicModel> GetPlnStatusByArea(string area)
|
{
|
try
|
{
|
var areaInfo = Db.Queryable<SysStorageArea>().First(m => m.AreaNo == area && m.IsDel == "0");
|
var strList = new List<DicModel>();
|
|
var dev = new string[] {};
|
if (areaInfo!=null && !string.IsNullOrWhiteSpace(areaInfo.DeviceCode))
|
{
|
dev = areaInfo.DeviceCode.Split(";");
|
}
|
|
foreach (var item in dev)
|
{
|
if (string.IsNullOrWhiteSpace(item))
|
{
|
continue;
|
}
|
if (strList.Count(m=>m.dic1 == item) == 0)
|
{
|
var v = "";
|
switch (item)
|
{
|
case "0":
|
v = "净桶";
|
break;
|
case "1":
|
v = "预混桶";
|
break;
|
case "2":
|
v = "满桶";
|
break;
|
case "3":
|
v = "脏桶";
|
break;
|
}
|
strList.Add(new DicModel
|
{
|
dic1 = item,
|
dic2 = v
|
});
|
}
|
}
|
if (strList.Count == 0)
|
{
|
strList.Add(new DicModel { dic1 = "0", dic2 = "净桶" });
|
//strList.Add(new DicModel { dic1 = "1", dic2 = "预混桶" });
|
strList.Add(new DicModel { dic1 = "2", dic2 = "满桶" });
|
strList.Add(new DicModel { dic1 = "3", dic2 = "脏桶" });
|
}
|
return strList;
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
public List<string> GetSkuByStatus(string palletStatus)
|
{
|
try
|
{
|
//获取储位上的库存物料
|
var detail = Db.Queryable<DataStockDetail>().Where(m => m.IsDel == "0" && !string.IsNullOrWhiteSpace(m.LocatNo) && m.PalletStatus == palletStatus).Select(m=>m.SkuNo).Distinct().ToList();
|
return detail;
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
public List<string> GetLotNoBySku(string skuNo)
|
{
|
try
|
{
|
var lotNoStr = Db.Queryable<DataStockDetail>().Where(m => m.IsDel == "0" && m.SkuNo == skuNo).Select(m => m.LotNo).Distinct().ToList();
|
return lotNoStr;
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
public List<string> GetSku()
|
{
|
try
|
{
|
//获取储位上的库存物料
|
var detail = Db.Queryable<SysMaterials>().Where(m => m.IsDel == "0" ).Select(m => m.SkuNo).Distinct().ToList();
|
return detail;
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
|
/// <summary>
|
/// 叫料 分配物料
|
/// </summary>
|
/// <param name="areaNo">区域</param>
|
/// <param name="endLocate">起始位置</param>
|
/// <param name="plnStatus">桶类型 0净桶 2满桶 3脏桶 </param>
|
/// <param name="standard">规格</param>
|
/// <param name="skuNo">物料号</param>
|
/// <param name="lotNo">批次</param>
|
/// <param name="userId">操作人</param>
|
/// <exception cref="Exception"></exception>
|
public void jiaoLiaoHopper(string areaNo,string endLocate,string plnStatus,string standard,string skuNo,string lotNo,int userId)
|
{
|
try
|
{
|
#region 判断
|
|
if (string.IsNullOrWhiteSpace(areaNo) || string.IsNullOrWhiteSpace(endLocate) || string.IsNullOrWhiteSpace(plnStatus) )
|
{
|
throw new Exception("区域/目标位/桶类型不能为空");
|
}
|
|
if (plnStatus == "0" && string.IsNullOrWhiteSpace(standard))
|
{
|
throw new Exception("净桶请选择规格");
|
|
}
|
else if(plnStatus == "2" && (string.IsNullOrWhiteSpace(skuNo) || string.IsNullOrWhiteSpace(lotNo)))
|
{
|
throw new Exception("满桶请选择物料与批次");
|
}
|
//判断目标叫料储位状态
|
var endLocateInfo = Db.Queryable<SysStorageLocat>().First(m => m.IsDel == "0" && m.LocatNo == endLocate && m.AreaNo == areaNo);
|
if (endLocateInfo == null)
|
{
|
throw new Exception("没有查询到目标储位信息");
|
}
|
if (endLocateInfo.Flag != "0")
|
{
|
throw new Exception("目标储位标识不是正常可用的");
|
}
|
if (endLocateInfo.Status!="0")
|
{
|
throw new Exception("目标储位状态不是空储位");
|
}
|
|
#endregion
|
|
//目标楼层
|
var layer = endLocateInfo.Layer;
|
var houseStr = layer == 3 ? "3楼中间站" : layer == 4 ? "4楼中间站" : "";
|
|
var house = Db.Queryable<SysWareHouse>().First(m => m.IsDel == "0" && m.WareHouseName == houseStr);
|
if (house == null)
|
{
|
throw new Exception("没有查询到仓库信息");
|
}
|
//查找状态是未分配且储位不为空的库存信息
|
var stockDetail = Db.Queryable<DataStockDetail>().Where(m => m.Status == "0" && m.WareHouseNo == house.WareHouseNo && !string.IsNullOrWhiteSpace(m.LocatNo)).ToList();
|
|
if (plnStatus == "0")
|
{
|
stockDetail = stockDetail.Where(m => m.PalletStatus == "0" && m.Standard == standard).OrderBy(m=>m.LocatNo).ToList();
|
}
|
else if (plnStatus == "2")
|
{
|
stockDetail = stockDetail.Where(m => m.PalletStatus == "2" && m.SkuNo == skuNo && m.LotNo == lotNo).OrderBy(m => m.LocatNo).ToList();
|
}
|
else
|
{
|
throw new Exception("桶类型错误");
|
}
|
if (stockDetail == null)
|
{
|
throw new Exception("没有查询到叫料的库存信息");
|
}
|
//查找合适的 桶号 储位
|
foreach (var item in stockDetail)
|
{
|
|
}
|
|
|
var taskNo = new Common().GetMaxNo("TK");
|
//添加任务
|
var task = new LogTask
|
{
|
TaskNo = taskNo,
|
Sender = "WMS",
|
Receiver = "WCS",
|
IsSuccess = 0, //是否下发成功 0失败 1成功
|
|
StartLocat = "",//起始位置
|
EndLocat = endLocate,//目标位置
|
PalletNo = "",//托盘码
|
IsSend = 1,//是否可再次下发
|
IsCancel = 1,//是否可取消
|
IsFinish = 1,//是否可完成
|
Type = "2",//任务类型 0 入库任务 1 出库任务 2 移库任务
|
Status = "0",//任务状态0:等待执行1正在执行2执行完成
|
OrderType = "3",//0 入库单 1 出库单 2 盘点单 3 移库单
|
|
CreateTime = DateTime.Now
|
};
|
Db.Insertable(task).ExecuteCommand();
|
//调用AGV接口下发任务
|
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
/// <summary>
|
/// 叫车 分配储位
|
/// </summary>
|
/// <param name="areaNo">区域</param>
|
/// <param name="StartLocate">起始位置</param>
|
/// <param name="plnNo">桶号</param>
|
/// <param name="plnStatus">桶类型 0净桶 2满桶 3脏桶 </param>
|
/// <param name="weight">重量</param>
|
/// <param name="skuNo">物料号</param>
|
/// <param name="lotNo">批次</param>
|
/// <param name="userId">操作人</param>
|
/// <exception cref="Exception"></exception>
|
public void jiaoCheHopper(string areaNo, string StartLocate, string plnNo, string plnStatus, decimal weight, string skuNo, string lotNo, int userId)
|
{
|
try
|
{
|
#region 判断
|
|
if (string.IsNullOrWhiteSpace(areaNo) || string.IsNullOrWhiteSpace(StartLocate) || string.IsNullOrWhiteSpace(plnStatus))
|
{
|
throw new Exception("区域/目标位/桶类型不能为空");
|
}
|
|
//if (plnStatus == "0" && string.IsNullOrWhiteSpace(standard))
|
//{
|
// throw new Exception("净桶请选择规格");
|
|
//}else
|
if (plnStatus == "2" && (string.IsNullOrWhiteSpace(skuNo) || string.IsNullOrWhiteSpace(lotNo)))
|
{
|
throw new Exception("满桶请选择物料与批次");
|
}
|
//判断目标叫料储位状态
|
var endLocateInfo = Db.Queryable<SysStorageLocat>().First(m => m.IsDel == "0" && m.LocatNo == StartLocate && m.AreaNo == areaNo);
|
if (endLocateInfo == null)
|
{
|
throw new Exception("没有查询到目标储位信息");
|
}
|
if (endLocateInfo.Flag != "0")
|
{
|
throw new Exception("目标储位标识不是正常可用的");
|
}
|
if (endLocateInfo.Status != "0")
|
{
|
throw new Exception("目标储位状态不是空储位");
|
}
|
|
#endregion
|
|
var pln = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == plnNo);
|
var locate = Db.Queryable<SysStorageLocat>().First(m => m.IsDel == "0" && m.AreaNo == areaNo && m.LocatNo == StartLocate);
|
var skuName = "";
|
var packagNo = "";
|
if (plnStatus == "2")
|
{
|
var sku = Db.Queryable<SysMaterials>().First(m => m.IsDel == "0" && m.SkuNo == skuNo);
|
if (sku == null)
|
{
|
throw new Exception("没有查询到物料信息");
|
}
|
skuName = sku.SkuName;
|
}
|
else if (plnStatus == "3")
|
{
|
|
}
|
|
var stockDetail = Db.Queryable<DataStockDetail>().First(m => m.PalletNo == plnNo);
|
if (stockDetail == null)
|
{
|
var stockDetailNew = new DataStockDetail()
|
{
|
LotNo = lotNo,
|
|
SkuNo = skuNo,
|
SkuName = skuName,
|
Standard = pln.Standard,
|
Qty = weight,
|
LockQty = 0,
|
FrozenQty = 0,
|
InspectQty = 0,
|
|
WareHouseNo = locate.WareHouseNo,
|
AreaNo = areaNo,
|
LocatNo = StartLocate,
|
PalletNo = plnNo,
|
|
PackagNo = packagNo,
|
PalletTags = "0",
|
CompleteTime = DateTime.Now,
|
|
PalletStatus = plnStatus,
|
Status = "0",
|
InspectMark = "0",
|
BitPalletMark = "0",
|
InspectStatus = "1",
|
};
|
Db.Insertable(stockDetailNew).ExecuteCommand();
|
}
|
else
|
{
|
stockDetail.PalletStatus = plnStatus;
|
stockDetail.SkuNo = skuNo;
|
stockDetail.LotNo = lotNo;
|
stockDetail.Qty = weight;
|
Db.Updateable(stockDetail).ExecuteCommand();
|
|
}
|
//获取储位地址
|
|
var taskNo = new Common().GetMaxNo("TK");
|
//添加任务
|
var task = new LogTask
|
{
|
TaskNo = taskNo,
|
Sender = "WMS",
|
Receiver = "WCS",
|
IsSuccess = 0, //是否下发成功 0失败 1成功
|
|
StartLocat = "",//起始位置
|
EndLocat = StartLocate,//目标位置
|
PalletNo = "",//托盘码
|
IsSend = 1,//是否可再次下发
|
IsCancel = 1,//是否可取消
|
IsFinish = 1,//是否可完成
|
Type = "2",//任务类型 0 入库任务 1 出库任务 2 移库任务
|
Status = "0",//任务状态0:等待执行1正在执行2执行完成
|
OrderType = "3",//0 入库单 1 出库单 2 盘点单 3 移库单
|
|
CreateTime = DateTime.Now
|
};
|
Db.Insertable(task).ExecuteCommand();
|
//调用AGV接口下发任务
|
|
|
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
|
|
|
}
|
}
|