using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Security.Policy;
|
using System.Text;
|
using System.Threading.Tasks;
|
using Model.InterFaceModel;
|
using Model.ModelDto.BllCheckDto;
|
using Model.ModelDto.LogDto;
|
using Model.ModelDto.PdaDto;
|
using Model.ModelDto.SysDto;
|
using Model.ModelVm;
|
using Newtonsoft.Json;
|
using SqlSugar;
|
using Utility.Tools;
|
using WMS.BLL.LogServer;
|
using WMS.BLL.SysServer;
|
using WMS.DAL;
|
using WMS.Entity.BllAsnEntity;
|
using WMS.Entity.BllCheckEntity;
|
using WMS.Entity.BllSoEntity;
|
using WMS.Entity.Context;
|
using WMS.Entity.DataEntity;
|
using WMS.Entity.LogEntity;
|
using WMS.Entity.SysEntity;
|
using WMS.IBLL.IPdaServer;
|
|
namespace WMS.BLL.BllPdaServer
|
{
|
public class PdaCrServer : IPdaCrServer
|
{
|
private static readonly SqlSugarScope Db = DataContext.Db;
|
|
|
#region 盘点
|
|
//获取盘库单正在执行单号
|
public List<string> GetStockCheckNoList(string palletNo)
|
{
|
try
|
{
|
List<string> list;
|
if (!string.IsNullOrWhiteSpace(palletNo))
|
{
|
list = Db.Queryable<BllStockCheckDetail>().Where(m => m.IsDel == "0" && m.PalletNo == palletNo && m.Status == 2).Select(m => m.CRNo).Distinct().ToList();
|
|
}
|
else
|
{
|
list = Db.Queryable<BllStockCheck>().Where(m => m.IsDel == "0" && m.Status == 1).Select(m => m.CRNo)
|
.Distinct().ToList();
|
}
|
|
return list;
|
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
//获取盘点明细物料批次信息
|
public List<StockCheckDetailDto> GetStockCheckDetailList(string crNo, string palletNo)
|
{
|
try
|
{
|
if (string.IsNullOrWhiteSpace(crNo))
|
{
|
throw new Exception("盘点单据不能为空");
|
}
|
|
var list = Db.Queryable<BllStockCheckDetail>().Where(m => m.IsDel == "0" && m.CRNo == crNo);
|
|
if (!string.IsNullOrWhiteSpace(palletNo))
|
{
|
list = list.Where(m => m.PalletNo == palletNo);
|
}
|
|
var data = list.GroupBy(m => new { m.SkuNo, m.SkuName, m.LotNo }).Select(m => new StockCheckDetailDto()
|
{
|
SkuNo = m.SkuNo,
|
SkuName = m.SkuName,
|
LotNo = m.LotNo
|
}).ToList();
|
|
return data;
|
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
//获取要盘点的箱码信息(盘点记录中数据)
|
public List<StockCheckLogDto> GetStockCheckLogList(string crNo, string crDetail, string palletNo, string boxNo, string isContinue)
|
{
|
try
|
{
|
if (string.IsNullOrWhiteSpace(crNo))
|
{
|
throw new Exception("盘点单据不能为空");
|
}
|
if (string.IsNullOrWhiteSpace(crDetail))
|
{
|
throw new Exception("物料批次不能为空");
|
}
|
if (string.IsNullOrWhiteSpace(palletNo))
|
{
|
throw new Exception("托盘码不能为空");
|
}
|
|
var detail = crDetail.Split("-");
|
var sku = detail[0];
|
//判断是否为无码物料
|
var skuinfo = Db.Queryable<SysMaterials>().First(m => m.IsDel == "0" && m.SkuNo == sku);
|
//判断是否存在物料消息
|
if (skuinfo == null)
|
{
|
throw new Exception("托盘码不能为空");
|
}
|
int isQtySku = 0;
|
if (skuinfo.Type == "4" && isContinue == "1")
|
{
|
isQtySku = 1;
|
}
|
var lotNo = detail[1];
|
var list = Db.Queryable<BllStockCheckLog>().Where(m => m.IsDel == "0" && m.CRNo == crNo);
|
//var deList= Db.Queryable<BllStockCheckDetail>().Where(m => m.IsDel == "0" && m.SkuNo == sku && m.LotNo == lotNo && m.PalletNo == palletNo);
|
//if (deList.Count() == 0)
|
//{
|
// throw new Exception("未查询到托盘上的盘点物料批次信息");
|
//}
|
list = list.Where(m => m.SkuNo == sku && m.LotNo == lotNo && m.PalletNo == palletNo);
|
if (!string.IsNullOrWhiteSpace(boxNo))
|
{
|
list = list.Where(m => m.BoxNo == boxNo);
|
}
|
List<StockCheckLogDto> data = new List<StockCheckLogDto>();
|
//判断是否为无码物料
|
if (isQtySku == 1)
|
{
|
//获取库存信息
|
var stockDetail = Db.Queryable<DataStockDetail>().First(a => a.IsDel == "0" && a.Status == "3" && a.SkuNo == sku && a.PalletNo == palletNo);
|
|
var model = new StockCheckLogDto()
|
{
|
PalletNo = palletNo,
|
SkuNo = sku,
|
Qty = stockDetail.Qty,
|
CheckResult = 4,
|
};
|
|
data.Add(model);
|
|
}
|
else
|
{
|
data = list.Select(m => new StockCheckLogDto()
|
{
|
BoxNo = m.BoxNo,
|
BoxNo3 = m.BoxNo3,
|
SkuNo = m.SkuNo,
|
SkuName = m.SkuName,
|
LotNo = m.LotNo,
|
Qty = m.Qty,
|
CheckResult = m.CheckResult,
|
|
}).ToList();
|
|
}
|
|
return data;
|
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
public void CrSetCheck(string crNo, string crDetail, string palletNo, string boxNo, string boxNo3, string result, decimal? qty, string isContinue, int userId)
|
{
|
try
|
{
|
if (string.IsNullOrWhiteSpace(crNo))
|
{
|
throw new Exception("盘点单据不能为空");
|
}
|
if (string.IsNullOrWhiteSpace(crDetail))
|
{
|
throw new Exception("物料批次不能为空");
|
}
|
if (string.IsNullOrWhiteSpace(palletNo))
|
{
|
throw new Exception("托盘码不能为空");
|
}
|
//箱码为空 是整托要盘点的都正常
|
var detail = crDetail.Split("-");
|
var sku = detail[0];
|
var lotNo = detail[1];
|
//盘点明细
|
var checkDetail = Db.Queryable<BllStockCheckDetail>().First(m =>
|
m.IsDel == "0" && m.CRNo == crNo && m.PalletNo == palletNo && m.SkuNo == sku && m.LotNo == lotNo);
|
if (checkDetail == null)
|
{
|
throw new Exception("未查询到未盘点的盘点明细信息");
|
}
|
//盘点记录
|
var checkLog = Db.Queryable<BllStockCheckLog>().Where(m =>
|
m.IsDel == "0" && m.CRNo == crNo && m.PalletNo == palletNo && m.SkuNo == sku && m.LotNo == lotNo && m.CheckResult == null);
|
var time = DateTime.Now;
|
//正常
|
if (result == "0")
|
{
|
if (!string.IsNullOrWhiteSpace(boxNo))
|
{
|
checkLog = checkLog.Where(m => m.BoxNo == boxNo);
|
}
|
if (!string.IsNullOrWhiteSpace(boxNo3))
|
{
|
checkLog = checkLog.Where(m => m.BoxNo3 == boxNo3);
|
}
|
|
if (checkLog.Count() == 0 && isContinue == "0")
|
{
|
throw new Exception("未查询到未盘点的箱支信息");
|
}
|
|
var list = checkLog.ToList();
|
var num = 0;
|
foreach (var l in list)
|
{
|
if (l.CheckResult != null)
|
{
|
continue;
|
}
|
l.RealQty = l.Qty;
|
l.CheckResult = 0;
|
l.CheckDate = time;
|
l.CheckUserId = userId;
|
|
num += (int)l.Qty;
|
}
|
|
if (checkDetail.RealQty == null)
|
{
|
checkDetail.RealQty = 0;
|
}
|
checkDetail.RealQty += num;
|
checkDetail.CheckResult = 0;
|
//if (checkDetail.CheckResult == null || checkDetail.CheckResult == 0)
|
//{
|
// checkDetail.CheckResult = 0;
|
//}
|
Db.Updateable(checkDetail).ExecuteCommand();
|
Db.Updateable(list).ExecuteCommand();
|
}
|
//盘亏
|
else if (result == "1")
|
{
|
if (!string.IsNullOrWhiteSpace(boxNo))
|
{
|
checkLog = checkLog.Where(m => m.BoxNo == boxNo);
|
}
|
if (!string.IsNullOrWhiteSpace(boxNo3))
|
{
|
checkLog = checkLog.Where(m => m.BoxNo3 == boxNo3);
|
}
|
|
if (checkLog.Count() == 0 && isContinue == "0")
|
{
|
throw new Exception("未查询到箱支信息");
|
}
|
|
//
|
if (isContinue == "1")
|
{
|
if (qty == null || qty <= 0)
|
{
|
throw new Exception("数量盘点时、盘亏数量不能为空且需大于0");
|
}
|
}
|
|
|
var list = checkLog.ToList();
|
var num = 0;
|
foreach (var l in list)
|
{
|
l.RealQty = 0;
|
l.CheckResult = 1;
|
l.CheckDate = time;
|
l.CheckUserId = userId;
|
num -= int.Parse(l.RealQty.ToString());
|
}
|
if (checkDetail.RealQty == null)
|
{
|
checkDetail.RealQty = 0;
|
}
|
checkDetail.RealQty += num;
|
if (isContinue == "1")
|
{
|
checkDetail.RealQty = qty;
|
}
|
checkDetail.CheckResult = 1;
|
var checkInfo = Db.Queryable<BllStockCheckLog>().First(m =>
|
m.IsDel == "0" && m.CRNo == crNo && m.PalletNo == palletNo && m.SkuNo == sku && m.LotNo == lotNo);
|
checkInfo.RealQty = qty;
|
checkInfo.CheckResult = 1;
|
|
checkInfo.CheckUserId = userId;
|
checkInfo.CheckDate = time;
|
|
checkInfo.UpdateUser = userId;
|
checkInfo.UpdateTime = time;
|
Db.Updateable(checkInfo).ExecuteCommand();
|
Db.Updateable(checkDetail).ExecuteCommand();
|
Db.Updateable(list).ExecuteCommand();
|
}
|
//盘盈
|
else if (result == "2")
|
{
|
if (isContinue == "0")
|
{
|
if (string.IsNullOrWhiteSpace(boxNo) || string.IsNullOrWhiteSpace(boxNo3))
|
{
|
throw new Exception("盘盈时箱码与支码不能为空");
|
}
|
}
|
if (qty == null || qty <= 0)
|
{
|
throw new Exception("盘盈时数量不能为空且需大于0");
|
}
|
if (isContinue == "0")
|
{
|
var count = Db.Queryable<DataBoxInfo>()
|
.Count(m => m.IsDel == "0" && m.BoxNo == boxNo && m.BoxNo3 == boxNo3);
|
var count2 = Db.Queryable<BllStockCheckLog>()
|
.Count(m => m.IsDel == "0" && m.BoxNo == boxNo && m.BoxNo3 == boxNo3);
|
if (count > 0 || count2 > 0)
|
{
|
throw new Exception("当前库存中已存在该箱支信息");
|
}
|
}
|
BllStockCheckLog crLog = new BllStockCheckLog();
|
if (isContinue == "0")
|
{
|
crLog = new BllStockCheckLog()
|
{
|
CRNo = crNo,
|
PalletNo = palletNo,
|
BoxNo = boxNo,
|
BoxNo2 = null,
|
BoxNo3 = boxNo3,
|
Qty = qty,
|
SkuNo = checkDetail.SkuNo,
|
SkuName = checkDetail.SkuName,
|
Standard = checkDetail.Standard,
|
LotNo = checkDetail.LotNo,
|
LotText = checkDetail.LotText,
|
SupplierLot = checkDetail.SupplierLot,
|
|
RealQty = qty,
|
CheckResult = 2,
|
CheckDate = time,
|
CheckUserId = userId,
|
|
CreateUser = userId,
|
CreateTime = time
|
};
|
}
|
else
|
{
|
var checkInfo = Db.Queryable<BllStockCheckLog>().First(m =>
|
m.IsDel == "0" && m.CRNo == crNo && m.PalletNo == palletNo && m.SkuNo == sku && m.LotNo == lotNo);
|
checkInfo.RealQty = qty;
|
checkInfo.CheckResult = 2;
|
|
checkInfo.CheckUserId = userId;
|
checkInfo.CheckDate = time;
|
|
checkInfo.UpdateUser = userId;
|
checkInfo.UpdateTime = time;
|
Db.Updateable(checkInfo).ExecuteCommand();
|
}
|
|
if (checkDetail.RealQty == null && isContinue == "0")
|
{
|
checkDetail.RealQty = 0;
|
}
|
checkDetail.RealQty += qty;
|
if (isContinue == "1")
|
{
|
checkDetail.RealQty = qty;
|
}
|
checkDetail.CheckResult = 2;
|
Db.Updateable(checkDetail).ExecuteCommand();
|
if (isContinue == "0")
|
{
|
Db.Insertable(crLog).ExecuteCommand();
|
}
|
}
|
else
|
{
|
Db.RollbackTran();
|
throw new Exception("盘点结果不符,请核实!");
|
}
|
var checkLogNum = Db.Queryable<BllStockCheckLog>().Where(m => m.IsDel == "0" && m.CRNo == crNo && m.PalletNo == palletNo && m.SkuNo == sku && m.LotNo == lotNo);
|
if (checkLogNum.Count(m => m.CheckResult == null) == 0)
|
{
|
var checkDe = Db.Queryable<BllStockCheckDetail>().First(m =>
|
m.IsDel == "0" && m.CRNo == crNo && m.PalletNo == palletNo && m.SkuNo == sku && m.LotNo == lotNo);
|
checkDe.Status = 3;
|
Db.Updateable(checkDe).ExecuteCommand();
|
var checkDeNum = Db.Queryable<BllStockCheckDetail>().Count(m =>
|
m.IsDel == "0" && m.CRNo == crNo && m.Status != 3 && m.Id != checkDe.Id);
|
if (checkDeNum == 0)
|
{
|
var check = Db.Queryable<BllStockCheck>().First(m => m.CRNo == crNo && m.IsDel == "0");
|
check.Status = 2;
|
check.CompleteDate = DateTime.Now;
|
Db.Updateable(check).ExecuteCommand();
|
|
}
|
}
|
Db.CommitTran();
|
}
|
catch (Exception e)
|
{
|
Db.RollbackTran();
|
throw new Exception(e.Message);
|
}
|
}
|
|
#endregion
|
|
#region 库存查询
|
|
/// <summary>
|
/// pda库存查询
|
/// </summary>
|
/// <param name="locatNo">储位编号</param>
|
/// <param name="palletNo">托盘号</param>
|
/// <returns></returns>
|
public List<DataStockDetail> GetStockQueryList(string locatNo, string palletNo)
|
{
|
string str = "select LocatNo,PalletNo,SkuName,SkuNo,Standard,LotNo,Qty,LockQty,FrozenQty,InspectQty from DataStockDetail Where IsDel = @isdel";
|
//判断储位编号是否为空
|
if (!string.IsNullOrEmpty(locatNo))
|
{
|
str += " and LocatNo like @locatno";
|
}
|
//判断托盘号是否为空
|
if (!string.IsNullOrEmpty(palletNo))
|
{
|
str += " and PalletNo like @palletno";
|
}
|
|
//排序
|
str += " order by LotNo,LocatNo,PalletNo";
|
List<DataStockDetail> stockList = Db.Ado.SqlQuery<DataStockDetail>(str, new
|
{
|
isdel = "0", //是否删除
|
locatno = "%" + locatNo + "%", //储位编号
|
palletno = "%" + palletNo + "%", //托盘号
|
});
|
return stockList;
|
}
|
|
#endregion
|
|
#region 托盘变更(托盘解绑绑定)
|
|
//根据托盘号获取箱码和箱内数量
|
public List<PdaPalletNoCheckDto> GetDataDetailList(string palletNo)
|
{
|
try
|
{
|
if (string.IsNullOrWhiteSpace(palletNo))
|
{
|
throw new Exception("托盘号不能为空");
|
}
|
var detail = Db.Queryable<DataStockDetail>().Where(m => m.IsDel == "0" && m.PalletNo == palletNo).Select(m => m.Id).ToList();
|
var info = Db.Queryable<DataBoxInfo>().Where(m => m.IsDel == "0" && detail.Contains(m.StockDetailId))
|
.GroupBy(m => m.BoxNo).Select(a => new PdaPalletNoCheckDto
|
{
|
BoxNo = a.BoxNo,
|
Qty = SqlFunc.AggregateSum(a.Qty)
|
}).ToList();
|
return info;
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
//根据箱码获取物料、批次、数量等信息
|
public PdaPalletNoCheckDto GetBoxInfoByBox(string boxNo)
|
{
|
try
|
{
|
if (string.IsNullOrWhiteSpace(boxNo))
|
{
|
throw new Exception("箱码不能为空");
|
}
|
|
var info = Db.Queryable<DataBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == boxNo)
|
.GroupBy(m => new { m.BoxNo, m.SkuNo, m.SkuName, m.LotNo }).Select(a => new PdaPalletNoCheckDto
|
{
|
BoxNo = a.BoxNo,
|
SkuNo = a.SkuNo,
|
SkuName = a.SkuName,
|
LotNo = a.LotNo,
|
Qty = SqlFunc.AggregateSum(a.Qty)
|
}).ToList();
|
if (info.Count > 1)
|
{
|
throw new Exception("当前箱码查询出多条物料或批次信息,请核实");
|
}
|
|
return info.FirstOrDefault();
|
}
|
catch (Exception e)
|
{
|
throw new Exception(e.Message);
|
}
|
}
|
|
//解绑原托盘绑定新托盘
|
public void SaveUnbind(string palletNo, string boxNo, string palletNoNew, int userId)
|
{
|
try
|
{
|
if (string.IsNullOrWhiteSpace(palletNo) || string.IsNullOrWhiteSpace(palletNoNew))
|
{
|
throw new Exception("新旧托盘号不能为空");
|
}
|
if (palletNo == palletNoNew)
|
{
|
throw new Exception("新旧托盘号不能为相同");
|
}
|
//库存箱支信息
|
var infos = Db.Queryable<DataBoxInfo>().Where(m => m.IsDel == "0" && m.PalletNo == palletNo);//整托变更
|
if (!string.IsNullOrWhiteSpace(boxNo))
|
{
|
//按箱变更
|
infos = infos.Where(m => m.IsDel == "0" && m.BoxNo == boxNo);
|
}
|
List<DataBoxInfo> infosList = infos.ToList();
|
if (infosList.Count <= 0)
|
{
|
throw new Exception("原托盘上未查到箱支明细,请核实");
|
}
|
//库存明细id
|
var infoIds = infos.GroupBy(m => m.StockDetailId).Select(a => a.StockDetailId).ToList();
|
if (infoIds.Count == 0)
|
{
|
throw new Exception("未查询到当前箱码信息,请核实");
|
}
|
//开启事务
|
Db.BeginTran();
|
var comTime = DateTime.Now;
|
//新托盘库存明细
|
bool newPalletHaveGoods = false;//新托盘上是否有物品
|
string pallWareHouseNo = string.Empty;//新托盘所在的位置(库外/平库)
|
var stockDetailList = Db.Queryable<DataStockDetail>().Where(m => m.IsDel == "0" && m.PalletNo == palletNoNew).ToList();
|
if (stockDetailList != null && stockDetailList.Count() > 0)
|
{
|
newPalletHaveGoods = true;
|
pallWareHouseNo = stockDetailList[0].WareHouseNo;
|
if (!string.IsNullOrEmpty(stockDetailList[0].LocatNo))
|
{
|
throw new Exception("新托盘在立库内不允许变更,请核实");
|
}
|
#region 验证是否允许立库同托盘不同物料入库或同托盘同物料不同批次入库
|
var box = Db.Queryable<DataBoxInfo>().First(m => m.IsDel == "0" && m.PalletNo == palletNoNew && m.BitBoxMark == "0");
|
if (box != null)
|
{
|
foreach (var item in infosList)
|
{
|
if (box.SkuNo != item.SkuNo || box.LotNo != item.LotNo)
|
{
|
var funSetting = Db.Queryable<SysFunSetting>().First(a => a.IsDel == "0" && a.FunSetNo == "Fun045");
|
if (funSetting == null || funSetting.IsEnable == "OFF")
|
{
|
throw new Exception($"不允许立库同托盘不同物料入库或同托盘不同批次入库!");
|
}
|
}
|
}
|
}
|
#endregion
|
}
|
if (!newPalletHaveGoods)//新托盘上没有物品
|
{
|
var pallet = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == palletNoNew);
|
if (pallet == null)
|
{
|
throw new Exception("未查询到新托盘号信息");
|
}
|
if (pallet.Status == "0")
|
{
|
pallet.Status = "1";//将新托盘状态修改为已使用
|
Db.Updateable(pallet).ExecuteCommand();
|
}
|
else
|
{
|
throw new Exception("新托盘号状态不是未使用");
|
}
|
}
|
foreach (var infoIdItem in infoIds)
|
{
|
var infosList2 = infosList.Where(w => w.StockDetailId == infoIdItem).ToList();
|
//原托盘库存明细
|
var stockDetail1 = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.PalletNo == palletNo && m.Id == infoIdItem);
|
if (stockDetail1 == null)
|
{
|
throw new Exception("未在原托盘上查询到箱码信息,请核实");
|
}
|
if (!string.IsNullOrEmpty(stockDetail1.LocatNo))
|
{
|
throw new Exception("原托盘在立库内不允许变更,请核实");
|
}
|
var stockDetail2 = stockDetailList.FirstOrDefault(w => w.SkuNo == stockDetail1.SkuNo && w.LotNo == stockDetail1.LotNo);
|
|
var stId = 0;
|
if (stockDetail2 == null) //添加-新托盘上没有同物料同批次物品
|
{
|
//新托盘添加库存明细
|
var detail = new DataStockDetail()
|
{
|
LotNo = stockDetail1.LotNo,
|
LotText = stockDetail1.LotText,
|
SupplierLot = stockDetail1.SupplierLot,
|
SkuNo = stockDetail1.SkuNo,
|
SkuName = stockDetail1.SkuName,
|
Standard = stockDetail1.Standard,
|
Qty = infosList2.Sum(m => m.Qty),
|
LockQty = 0,
|
FrozenQty = 0,
|
InspectQty = 0,
|
ASNNo = stockDetail1.ASNNo,
|
ASNDetailNo = stockDetail1.ASNDetailNo,
|
WareHouseNo = pallWareHouseNo,
|
RoadwayNo = "",
|
AreaNo = "",
|
LocatNo = stockDetail1.LocatNo,
|
PalletNo = palletNoNew,//新托盘号
|
PalletNo2 = "",
|
PalletNo3 = "",
|
|
CompleteTime = comTime,
|
ProductionTime = stockDetail1.ProductionTime,
|
ExpirationTime = stockDetail1.ExpirationTime,
|
Status = "0",
|
InspectMark = stockDetail1.InspectMark,
|
InspectStatus = stockDetail1.InspectStatus,
|
BitPalletMark = stockDetail1.BitPalletMark,
|
PackagNo = stockDetail1.PackagNo,
|
IsBale = "0",
|
IsBelt = "0",
|
|
IsDel = "0",
|
CreateUser = userId,
|
CreateTime = DateTime.Now
|
};
|
stId = Db.Insertable(detail).ExecuteReturnIdentity();
|
}
|
else //修改-新托盘有物品
|
{
|
stockDetail2.Qty += infosList2.Sum(m => m.Qty);//新托盘增加库存
|
Db.Updateable(stockDetail2).ExecuteCommand();
|
stId = stockDetail2.Id;
|
}
|
//修改库存
|
stockDetail1.Qty -= infosList2.Sum(m => m.Qty);
|
stockDetail1.BitPalletMark = "1";//是否零托 0:否 1:是
|
if (stockDetail1.Qty == 0)
|
{
|
Db.Deleteable(stockDetail1).ExecuteCommand();//删除原托盘库存明细
|
//判原托盘还有没有货物
|
var stockDetail3 = Db.Queryable<DataStockDetail>().Where(m => m.IsDel == "0" && m.PalletNo == palletNo && m.Id != infoIds.First()).ToList();
|
if (stockDetail3 == null || stockDetail3.Count <= 0)
|
{
|
var pallet = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == palletNo);
|
pallet.Status = "0";//原托盘没有货物后将状态修改为未使用
|
Db.Updateable(pallet).ExecuteCommand();
|
}
|
}
|
else
|
{
|
Db.Updateable(stockDetail1).ExecuteCommand();//修改原托盘库存明细
|
}
|
foreach (var item in infosList2)
|
{
|
//修改库存箱码明细
|
item.StockDetailId = stId;
|
item.BindNo = null;
|
item.PalletNo = palletNoNew;
|
Db.Updateable(item).ExecuteCommand();
|
}
|
//添加托盘解绑绑定记录
|
var unBind = new BllPalletUnbind()
|
{
|
UpbindPalletNo = palletNo,
|
BindPalletNo = palletNoNew,
|
LotNo = stockDetail1.LotNo,
|
LotText = stockDetail1.LotText,
|
SupplierLot = stockDetail1.SupplierLot,
|
SkuNo = stockDetail1.SkuNo,
|
SkuName = stockDetail1.SkuName,
|
Standard = stockDetail1.Standard,
|
Qty = infosList2.Sum(m => m.Qty),
|
PalletNo2 = stockDetail1.PalletNo2,
|
PalletNo3 = stockDetail1.PalletNo3,
|
BoxNo = boxNo,
|
InspectNo = "",
|
InspectStatus = stockDetail1.InspectStatus,
|
|
IsDel = "0",
|
CreateTime = comTime,
|
CreateUser = userId
|
};
|
Db.Insertable(unBind).ExecuteCommand();
|
}
|
//添加操作日志
|
if (string.IsNullOrEmpty(boxNo))
|
{
|
boxNo = "全部";
|
}
|
new OperationCrServer().AddLogOperationCr("库内作业", "操作日志", boxNo, "编辑", $"托盘变更:原托盘码:{palletNo}上的箱码{boxNo}解绑,绑定到新托盘{palletNoNew}上", userId);
|
//提交事务
|
Db.CommitTran();
|
}
|
catch (Exception e)
|
{
|
Db.RollbackTran();
|
throw new Exception(e.Message);
|
}
|
}
|
|
#endregion
|
|
#region AGV转运
|
/// <summary>
|
/// 获取托盘所在储位地址
|
/// </summary>
|
/// <param name="palletNo"></param>
|
/// <returns></returns>
|
public string GetPalletLocatNo(string palletNo)
|
{
|
try
|
{
|
var models = Db.Queryable<DataStockDetail>().First(w => w.IsDel == "0" && w.PalletNo == palletNo);
|
if (models == null)
|
{
|
throw new Exception("托盘库存信息不存在,请检查!");
|
}
|
if (string.IsNullOrEmpty(models.LocatNo))
|
{
|
throw new Exception("托盘储位信息不存在,请检查!");
|
}
|
if (models.WareHouseNo != "W02")
|
{
|
throw new Exception("该托盘未在平库内,请检查!");
|
}
|
return models.LocatNo;
|
}
|
catch (Exception ex)
|
{
|
throw new Exception(ex.Message);
|
}
|
}
|
|
/// <summary>
|
/// 获取托盘所在楼层所有区域
|
/// </summary>
|
/// <param name="palletNo"></param>
|
/// <returns></returns>
|
public List<SysStorageArea> GetStorageArea(string palletNo)
|
{
|
try
|
{
|
var storageArea = new List<SysStorageArea>();
|
if (string.IsNullOrEmpty(palletNo))
|
{
|
storageArea = Db.Queryable<SysStorageArea>().Where(w => w.IsDel == "0" && w.Status == "0" && w.WareHouseNo == "W02").OrderBy(o => o.AreaNo).ToList();
|
}
|
else
|
{
|
var models = Db.Queryable<DataStockDetail>().First(w => w.IsDel == "0" && w.PalletNo == palletNo);
|
if (models == null)
|
{
|
throw new Exception("托盘库存信息不存在,请检查!");
|
}
|
if (string.IsNullOrEmpty(models.LocatNo))
|
{
|
throw new Exception("托盘储位信息不存在,请检查!");
|
}
|
//if (models.WareHouseNo != "W02")
|
//{
|
// throw new Exception("该托盘未在平库内,请检查!");
|
//}
|
var storageLocat = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == models.LocatNo);
|
if (storageLocat == null)
|
{
|
throw new Exception("储位信息不存在,请检查!");
|
}
|
|
if (storageLocat.AreaNo.Contains("B0"))
|
{
|
storageArea = Db.Queryable<SysStorageArea>().Where(w => w.IsDel == "0" && w.Status == "0" && w.AreaNo.Contains("B0") && w.WareHouseNo == "W02").OrderBy(o => o.AreaNo).ToList();
|
}
|
else
|
{
|
storageArea = Db.Queryable<SysStorageArea>().Where(w => w.IsDel == "0" && w.Status == "0" && w.AreaNo.Contains("B1") && w.WareHouseNo == "W02").OrderBy(o => o.AreaNo).ToList();
|
}
|
}
|
return storageArea;
|
}
|
catch (Exception ex)
|
{
|
throw new Exception(ex.Message);
|
}
|
}
|
/// <summary>
|
/// 获取已分配的出库单据
|
/// </summary>
|
/// <returns></returns>
|
public List<string> GetRunSoNoticeList()
|
{
|
try
|
{
|
var allotList = Db.Queryable<BllExportNotice>().Where(m => m.IsDel == "0" && (m.Status == "3" || m.Status == "4")).Select(m => m.SONo).Distinct().ToList();
|
return allotList;
|
}
|
catch (Exception ex)
|
{
|
throw new Exception(ex.Message);
|
}
|
}
|
/// <summary>
|
/// 根据托盘号获取托盘上物料信息
|
/// </summary>
|
/// <param name="palletNo"></param>
|
/// <returns></returns>
|
public List<DataStockDetail> GetSkuInfoByPalletNo(string palletNo)
|
{
|
try
|
{
|
if (string.IsNullOrEmpty(palletNo))
|
{
|
throw new Exception("请扫描托盘条码!");
|
}
|
var skuInfoList = Db.Queryable<DataStockDetail>().Where(m => m.IsDel == "0" && m.PalletNo == palletNo).ToList();
|
return skuInfoList;
|
}
|
catch (Exception ex)
|
{
|
throw new Exception(ex.Message);
|
}
|
}
|
/// <summary>
|
/// 根据出库单号获取分配的托盘信息
|
/// </summary>
|
/// <param name="soNo"></param>
|
/// <returns></returns>
|
public List<string> GetPalletNoListBySoNo(string soNo)
|
{
|
try
|
{
|
if (string.IsNullOrEmpty(soNo))
|
{
|
throw new Exception("请选择出库单号!");
|
}
|
var palletNoList = Db.Queryable<BllExportAllot>().Where(m => m.IsDel == "0" && m.SONo == soNo).Select(m => m.PalletNo).Distinct().ToList();
|
return palletNoList;
|
}
|
catch (Exception ex)
|
{
|
throw new Exception(ex.Message);
|
}
|
}
|
|
/// <summary>
|
/// agv转运呼叫小车
|
/// </summary>
|
/// <param name="palletNo"></param>
|
/// <param name="areaNo"></param>
|
/// <param name="ruku"></param>
|
public void AgvTransport(string palletNo, string areaNo, string ruku, int userId, string url, string wcsurl)
|
{
|
if (string.IsNullOrEmpty(palletNo))
|
{
|
throw new Exception("请扫描托盘条码!");
|
}
|
if (string.IsNullOrEmpty(areaNo) && string.IsNullOrEmpty(ruku))
|
{
|
throw new Exception("请选择目标区域或入库口!");
|
}
|
if (!string.IsNullOrEmpty(areaNo) && !string.IsNullOrEmpty(ruku))
|
{
|
throw new Exception("目标区域和入库口不能同时选择!");
|
}
|
try
|
{
|
string EndLocat = string.Empty,OrderTy = "";//目标位置
|
var tasktype = "D00"; //小车任务类型,默认为点到点任务
|
|
var log = Db.Queryable<LogTask>().First(w => w.IsDel == "0" && w.PalletNo == palletNo && (w.Status == "0" || w.Status == "1"));
|
if (log != null)
|
{
|
throw new Exception("该托盘已有小车等待执行或正在执行的任务!");
|
}
|
var stockDetail = Db.Queryable<DataStockDetail>().First(w => w.IsDel == "0" && w.PalletNo == palletNo);
|
if (stockDetail == null)
|
{
|
throw new Exception("托盘上物料库存明细信息不存在,请检查!");
|
}
|
if (!string.IsNullOrEmpty(areaNo))
|
{
|
var storageArea = Db.Queryable<SysStorageArea>().First(w => w.IsDel == "0" && w.AreaNo == areaNo);
|
if (storageArea == null)
|
{
|
throw new Exception("所选区域信息不存在,请检查!");
|
}
|
EndLocat = GetLocat(areaNo, stockDetail.SkuNo, stockDetail.LotNo, palletNo);
|
OrderTy = "3";//移库
|
}
|
else
|
{
|
EndLocat = ruku;
|
OrderTy = "0";//入库
|
|
|
}
|
var stock = Db.Queryable<DataStock>().First(w => w.IsDel == "0" && w.SkuNo == stockDetail.SkuNo && w.LotNo == stockDetail.LotNo);
|
if (stock == null)
|
{
|
throw new Exception("托盘上物料库存信息不存在,请检查!");
|
}
|
if (string.IsNullOrEmpty(stockDetail.LocatNo))
|
{
|
throw new Exception("托盘储位信息不存在,请检查!");
|
}
|
if (stockDetail.WareHouseNo != "W02")
|
{
|
throw new Exception("该托盘未在平库内,请检查!");
|
}
|
//起始储位信息
|
var storageLocat = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == stockDetail.LocatNo);
|
if (storageLocat == null)
|
{
|
throw new Exception("储位信息不存在,请检查!");
|
}
|
//目标储位信息
|
var storageLocatEnd = new SysStorageLocat();
|
if (!string.IsNullOrEmpty(areaNo))
|
{
|
storageLocatEnd = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == EndLocat && w.Flag == "0" && w.Status == "0");
|
if (storageLocatEnd == null)
|
{
|
throw new Exception("目标储位信息不存在,请检查!");
|
}
|
}
|
|
//开启事务
|
Db.BeginTran();
|
|
//请求WCS入库口放货确认
|
if (!string.IsNullOrEmpty(ruku))
|
{
|
try
|
{
|
var port = new
|
{
|
Port = EndLocat
|
};
|
var json = JsonConvert.SerializeObject(port);
|
var res = HttpHelper.DoPost(wcsurl, json, "请求WCS入库口是否可放货", "WCS");
|
|
//////解析返回数据
|
var ret = JsonConvert.DeserializeObject<WcsModel>(res);
|
if (ret.StatusCode == -1)
|
{
|
throw new Exception(EndLocat + "号入库口已有其他任务占用,请选择其他入库口");
|
}
|
}
|
catch (Exception ex)
|
{
|
throw new Exception(ex.Message);
|
}
|
}
|
|
|
|
//添加出库任务
|
var taskNo = new Common().GetMaxNo("TK");
|
var exTask = new LogTask
|
{
|
TaskNo = taskNo,
|
Sender = "WMS",
|
Receiver = "AGV",
|
IsSuccess = 0, //是否下发成功 0失败 1成功
|
|
StartLocat = stockDetail.LocatNo,//起始位置
|
EndLocat = EndLocat,//目标位置
|
PalletNo = palletNo,//托盘码
|
Msg = string.Format("转运任务:{0}=>>{1}", stockDetail.LocatNo, EndLocat),
|
IsSend = 1,//是否可再次下发
|
IsCancel = 1,//是否可取消
|
IsFinish = 1,//是否可完成
|
Type = OrderTy,//任务类型 0 入库任务 1 出库任务 2 移库任务
|
Status = "0",//任务状态0:等待执行1正在执行2执行完成
|
OrderType = OrderTy,//0 入库单 1 出库单 2 盘点单 3 移库单
|
|
CreateTime = DateTime.Now
|
};
|
Db.Insertable(exTask).ExecuteCommand();
|
|
//修改库存明细信息
|
stockDetail.Status = "4";//移库锁定
|
//stockDetail.LockQty = stockDetail.Qty;//锁定库存数量
|
Db.Updateable(stockDetail).ExecuteCommand();
|
//修改库存信息
|
//stock.LockQty += (decimal)stockDetail.Qty;
|
//Db.Updateable(stock).ExecuteCommand();
|
|
//修改起始储位地址状态
|
storageLocat.Status = "5";//0:空储位 1:有物品 2:入库中 3:出库中 4:移入中 5:移出中
|
Db.Updateable(storageLocat).ExecuteCommand();
|
|
//修改目标储位地址状态
|
if (storageLocatEnd != null)
|
{
|
storageLocatEnd.Status = "4";//0:空储位 1:有物品 2:入库中 3:出库中 4:移入中 5:移出中
|
Db.Updateable(storageLocatEnd).ExecuteCommand();
|
}
|
//添加操作日志记录
|
var k = new OperationCrServer().AddLogOperationCr("PDA模块", "AGV转运", palletNo, OrderTy == "0" ?"入库":"移库", $"PDA呼叫小车对托盘号:{palletNo}发起转运", userId);
|
|
#region 呼叫小车代码
|
|
var endlono = EndLocat;
|
if (OrderTy == "0")
|
{
|
tasktype = "RK0"; //入库任务
|
}
|
|
//缓存库位转换 3楼接驳位Y003_001,Y003_002,Y003_003
|
if (storageLocatEnd.AreaNo == "B12")
|
{
|
switch (EndLocat.ToString().Substring(4, 1))
|
{
|
case "1":
|
endlono = "Y003_0" + EndLocat.ToString().Substring(5, 2);
|
tasktype = "D00"; //点到点任务
|
break;
|
default:
|
break;
|
}
|
}
|
|
//点到点指令集合
|
object[] position = new object[2];
|
position[0] = new
|
{
|
positionCode = stockDetail.LocatNo,
|
type = "00"
|
};
|
position[1] = new
|
{
|
positionCode = endlono,
|
type = "00"
|
};
|
|
List<AgvSchedulingTask> agvTaskList = new List<AgvSchedulingTask>();
|
|
|
AgvSchedulingTask agvTask = new AgvSchedulingTask();
|
Random r = new Random();
|
long ran = DateTime.Now.Ticks;
|
agvTask.ReqCode = ran.ToString();
|
agvTask.TaskCode = taskNo;
|
agvTask.TaskTyp = tasktype;
|
agvTask.PositionCodePath = position;
|
agvTask.CtnrTyp = "1";
|
if (tasktype == "D02")
|
{
|
agvTask.CtnrNum = "10"; //叠托任务需要下发空托盘数量
|
}
|
|
agvTaskList.Add(agvTask);
|
|
|
// 正式运行程序放开
|
string str = "";
|
var list2 = agvTaskList.Select(m => m.TaskCode).ToList();
|
var jsonData = JsonConvert.SerializeObject(agvTaskList);
|
jsonData = jsonData.Substring(1, jsonData.Length - 1);
|
jsonData = jsonData.Substring(0, jsonData.Length - 1);
|
string response = "";
|
|
try
|
{
|
var time1 = DateTime.Now;//发送时间 .ToString("yyyy-MM-dd HH:mm:ss")
|
response = HttpHelper.DoPost(url, jsonData, "下发给AGV转运命令", "AGV");
|
var time2 = DateTime.Now;//返回时间 .ToString("yyyy-MM-dd HH:mm:ss")
|
|
//////解析返回数据
|
var agvModel = JsonConvert.DeserializeObject<OutCommanAgvDto>(response);
|
if (agvModel.Code == "0")
|
{
|
//更改任务的发送返回时间//
|
new TaskServer().EditTaskIssueOk(list2, time1, time2);
|
str += "下发成功";
|
}
|
if (agvModel.Code == "1")
|
{
|
new TaskServer().EditTaskIssueNo(list2, time1, time2, agvModel.Message);
|
throw new Exception(agvModel.Message);
|
}
|
}
|
catch (Exception ex)
|
{
|
throw new Exception(ex.Message);
|
}
|
|
#endregion
|
|
//提交事务
|
Db.CommitTran();
|
}
|
catch (Exception ex)
|
{
|
Db.RollbackTran();
|
throw new Exception(ex.Message);
|
}
|
}
|
/// <summary>
|
/// agv转运呼叫小车取货
|
/// </summary>
|
/// <param name="soNo"></param>
|
/// <param name="palletNo"></param>
|
/// <param name="areaNo"></param>
|
/// <param name="userId"></param>
|
public List<string> AgvTransport2(string soNo, string palletNo, string areaNo,string ruku, int userId, string url)
|
{
|
if (string.IsNullOrEmpty(soNo))
|
{
|
throw new Exception("请选择出库单据!");
|
}
|
if (string.IsNullOrEmpty(areaNo))
|
{
|
throw new Exception("请选择目标区域!");
|
}
|
try
|
{
|
//开启事务
|
Db.BeginTran();
|
List<AgvSchedulingTask> agvTaskList = new List<AgvSchedulingTask>();
|
var strList = new List<string>();//错误信息集合 //0 :部分托盘已有小车等待执行或正在执行的任务
|
//出库单信息
|
var notice = Db.Queryable<BllExportNotice>().First(w => w.IsDel == "0" && w.SONo == soNo);
|
if (notice == null)
|
{
|
throw new Exception("出库单据信息不存在,请检查!");
|
}
|
//目标区域信息
|
var storageArea = Db.Queryable<SysStorageArea>().First(w => w.IsDel == "0" && w.AreaNo == areaNo);
|
if (storageArea == null)
|
{
|
throw new Exception("所选区域信息不存在,请检查!");
|
}
|
List<DataStockDetail> stockDetailList = new List<DataStockDetail>();//需要的托盘明细
|
if (!string.IsNullOrEmpty(palletNo))//单托盘叫货
|
{
|
stockDetailList = Db.Queryable<DataStockDetail>().Where(w => w.IsDel == "0" && w.PalletNo == palletNo).ToList();
|
}
|
else//整个出库单叫货
|
{
|
// string sqlStr = $"select * from DataStockDetail where PalletNo in (select PalletNo from BllExportAllot where IsDel='0' and SONo='{soNo}')";
|
// stockDetailList = Db.Ado.SqlQuery<DataStockDetail>(sqlStr).ToList();
|
stockDetailList = Db.Queryable<DataStockDetail>().Where(w => w.IsDel == "0" && w.SONo == soNo).ToList();
|
}
|
if (stockDetailList.Count <= 0)
|
{
|
throw new Exception("托盘明细不存在,请检查!");
|
}
|
|
var log = Db.Queryable<LogTask>().Where(w => w.IsDel == "0" && (w.Status == "0" || w.Status == "1"));//任务表
|
var storageLocat = Db.Queryable<SysStorageLocat>().Where(w => w.IsDel == "0");//储位表
|
var stock = Db.Queryable<DataStock>().Where(w => w.IsDel == "0");//库存总表
|
string EndLocat = string.Empty;//目标位置
|
string hasLocatNoList = string.Empty;//已分配的储位
|
|
foreach (var item in stockDetailList)
|
{
|
|
if (string.IsNullOrEmpty(item.LocatNo))
|
{
|
throw new Exception($"托盘号:{item.PalletNo}的储位信息不存在,请检查!");
|
}
|
if (item.WareHouseNo != "W02")
|
{
|
throw new Exception($"托盘号:{item.PalletNo}未在平库内,请检查!");
|
}
|
//任务信息
|
var logInfo = log.First(w => w.PalletNo == item.PalletNo);
|
if (logInfo != null)
|
{
|
if (!strList.Contains("1"))
|
{
|
strList.Add("1");
|
}
|
continue;
|
//throw new Exception($"托盘号:{item.PalletNo}已有小车等待执行或正在执行的任务!");
|
}
|
//起始储位信息
|
var storageLocatBegin = storageLocat.First(w => w.LocatNo == item.LocatNo);
|
if (storageLocat == null)
|
{
|
throw new Exception($"托盘号:{item.PalletNo}所在的储位信息不存在,请检查!");
|
}
|
//获取目标储位
|
EndLocat = GetLocat(areaNo, item.SkuNo, item.LotNo, palletNo);
|
if (string.IsNullOrEmpty(EndLocat))
|
{
|
throw new Exception("分配目标储位失败,请检查!");
|
}
|
if (string.IsNullOrEmpty(hasLocatNoList))
|
{
|
hasLocatNoList = EndLocat;
|
}
|
else
|
{
|
hasLocatNoList = hasLocatNoList + "," + EndLocat;
|
}
|
//目标储位信息
|
var storageLocatEnd = storageLocat.First(w => w.LocatNo == EndLocat && w.Flag == "0" && w.Status == "0");
|
if (storageLocatEnd == null)
|
{
|
throw new Exception("目标储位信息不存在,请检查!");
|
}
|
|
//添加出库任务
|
var taskNo = new Common().GetMaxNo("TK");
|
var exTask = new LogTask
|
{
|
TaskNo = taskNo,
|
Sender = "WMS",
|
Receiver = "AGV",
|
IsSuccess = 0, //是否下发成功 0失败 1成功
|
Msg = string.Format("转运任务:{0}=>>{1}", item.LocatNo, EndLocat),
|
StartLocat = item.LocatNo,//起始位置
|
EndLocat = EndLocat,//目标位置
|
PalletNo = item.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(exTask).ExecuteCommand();
|
|
var endlono = EndLocat;
|
var tasktype = "D00";
|
|
//根据目的地址库区获取小车任务类型
|
switch (storageLocatEnd.AreaNo)
|
{
|
case "B13":
|
tasktype = "D02"; // 叠托任务(目的地址为空托盘收集区)
|
break;
|
case "B15":
|
tasktype = "D01"; // 拆托任务(目的地址为拣货区)
|
break;
|
}
|
|
//缓存库位转换 3楼原辅料Y003_001到Y003_011
|
if (storageLocatEnd.AreaNo == "B12")
|
{
|
switch (EndLocat.ToString().Substring(4, 1))
|
{
|
case "1":
|
endlono = "Y003_0" + EndLocat.ToString().Substring(5, 2);
|
break;
|
default:
|
break;
|
}
|
}
|
|
//点到点指令集合
|
object[] position = new object[2];
|
position[0] = new
|
{
|
positionCode = item.LocatNo,
|
type = "00"
|
};
|
position[1] = new
|
{
|
positionCode = endlono,
|
type = "00"
|
};
|
|
AgvSchedulingTask agvTask = new AgvSchedulingTask();
|
Random r = new Random();
|
long ran = DateTime.Now.Ticks;
|
agvTask.ReqCode = ran.ToString();
|
agvTask.TaskCode = taskNo;
|
agvTask.TaskTyp = tasktype;
|
agvTask.PositionCodePath = position;
|
|
agvTaskList.Add(agvTask);
|
|
//修改库存明细信息
|
item.Status = "4";//移库锁定
|
//item.LockQty = item.Qty;//锁定库存数量
|
Db.Updateable(item).ExecuteCommand();
|
|
//修改起始储位地址状态
|
storageLocatBegin.Status = "5";//0:空储位 1:有物品 2:入库中 3:出库中 4:移入中 5:移出中
|
Db.Updateable(storageLocatBegin).ExecuteCommand();
|
//修改目标储位地址状态
|
storageLocatEnd.Status = "4";//0:空储位 1:有物品 2:入库中 3:出库中 4:移入中 5:移出中
|
Db.Updateable(storageLocatEnd).ExecuteCommand();
|
|
if (!strList.Contains("0"))
|
{
|
strList.Add("0");
|
}
|
|
//var stockInfo = stock.First(w => w.SkuNo == item.SkuNo && w.LotNo == item.LotNo);
|
////修改库存信息
|
//stockInfo.LockQty += (decimal)item.Qty;//锁定数量
|
//Db.Updateable(stockInfo).ExecuteCommand();
|
}
|
if (string.IsNullOrEmpty(palletNo))
|
{
|
//添加操作日志记录
|
var k = new OperationCrServer().AddLogOperationCr("PDA模块", "AGV转运", palletNo, "移库", $"PDA呼叫小车对出库单:{soNo}下所有托盘发起转运", userId);
|
}
|
else
|
{
|
//添加操作日志记录
|
var k = new OperationCrServer().AddLogOperationCr("PDA模块", "AGV转运", palletNo, "移库", $"PDA呼叫小车对托盘号:{palletNo}发起转运", userId);
|
}
|
|
#region 呼叫小车代码
|
|
|
|
|
// 正式运行程序放开
|
string str = "";
|
var list2 = agvTaskList.Select(m => m.TaskCode).ToList();
|
var jsonData = JsonConvert.SerializeObject(agvTaskList);
|
jsonData = jsonData.Substring(1, jsonData.Length - 1);
|
jsonData = jsonData.Substring(0, jsonData.Length - 1);
|
string response = "";
|
|
try
|
{
|
var time1 = DateTime.Now;//发送时间 .ToString("yyyy-MM-dd HH:mm:ss")
|
response = HttpHelper.DoPost(url, jsonData, "下发给AGV转运取货命令", "AGV");
|
var time2 = DateTime.Now;//返回时间 .ToString("yyyy-MM-dd HH:mm:ss")
|
|
//////解析返回数据
|
var agvModel = JsonConvert.DeserializeObject<OutCommanAgvDto>(response);
|
if (agvModel.Code == "0")
|
{
|
//更改任务的发送返回时间//
|
new TaskServer().EditTaskIssueOk(list2, time1, time2);
|
str += "下发成功";
|
//IsTrue = true;
|
}
|
if (agvModel.Code == "1")
|
{
|
new TaskServer().EditTaskIssueNo(list2, time1, time2, agvModel.Message);
|
throw new Exception(agvModel.Message);
|
}
|
}
|
catch (Exception ex)
|
{
|
throw new Exception(ex.Message);
|
}
|
|
|
#endregion
|
|
//提交事务
|
Db.CommitTran();
|
return strList;
|
}
|
catch (Exception ex)
|
{
|
Db.RollbackTran();
|
throw new Exception(ex.Message);
|
}
|
}
|
|
/// <summary>
|
/// 空托盘入库呼叫小车
|
/// </summary>
|
/// <param name="palletNo"></param>
|
/// <param name="areaNo"></param>
|
/// <param name="ruku"></param>
|
public void AgvTransport3(string palletNo, string LocatNo, string ruku, int userId, string url, string wcsurl)
|
{
|
if (string.IsNullOrEmpty(palletNo))
|
{
|
throw new Exception("请扫描托盘条码!");
|
}
|
if (string.IsNullOrEmpty(ruku))
|
{
|
throw new Exception("请选择入库口!");
|
}
|
try
|
{
|
if (ruku == "001")
|
{
|
var xlocate = Db.Queryable<SysStorageLocat>().First(w => w.Status == "0" && (w.LocatNo == "B13010101" || w.LocatNo == "B13020101" || w.LocatNo == "B13030101"));
|
if (xlocate == null)
|
{
|
throw new Exception("空托盘收集器已满");
|
}
|
ruku = Db.Queryable<SysStorageLocat>().First(w => w.Status == "0" && (w.LocatNo == "B13010101" || w.LocatNo == "B13020101" || w.LocatNo == "B13030101")).LocatNo;
|
}
|
if (ruku == "002")
|
{
|
var dlocate = Db.Queryable<SysStorageLocat>().First(w => w.Status == "0" && (w.LocatNo == "B13040101" || w.LocatNo == "B13050101" || w.LocatNo == "B13060101"));
|
if (dlocate == null)
|
{
|
throw new Exception("空托盘收集器已满");
|
}
|
ruku = Db.Queryable<SysStorageLocat>().First(w => w.Status == "0" && (w.LocatNo == "B13040101" || w.LocatNo == "B13050101" || w.LocatNo == "B13060101")).LocatNo;
|
}
|
if (ruku == null)
|
{
|
throw new Exception("当前托盘收集器工位无空余,请将空托盘垛入立体库");
|
}
|
string EndLocat = ruku;//目标位置
|
string OrderTy = ruku.Length ==3 ? "0":"2";
|
var tasktype = "RK0"; //入库任务
|
int palnoqty = 1;
|
var log = Db.Queryable<LogTask>().First(w => w.IsDel == "0" && w.PalletNo == palletNo && (w.Status == "0" || w.Status == "1"));
|
if (log != null)
|
{
|
throw new Exception("该托盘已有小车等待执行或正在执行的任务!");
|
}
|
//起始储位信息
|
var storageLocat = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == LocatNo);
|
if (storageLocat == null)
|
{
|
throw new Exception("储位信息不存在,请检查!");
|
}
|
|
//开启事务
|
Db.BeginTran();
|
if (EndLocat.Length == 3)
|
{
|
//请求WCS入库口放货确认
|
try
|
{
|
var port = new
|
{
|
Port = EndLocat
|
};
|
var json = JsonConvert.SerializeObject(port);
|
var res = HttpHelper.DoPost(wcsurl, json, "请求WCS入库口是否可放货", "WCS");
|
|
//////解析返回数据
|
var ret = JsonConvert.DeserializeObject<WcsModel>(res);
|
if (ret.StatusCode == -1)
|
{
|
throw new Exception(EndLocat + "号入库口已有其他任务占用,请选择其他入库口");
|
}
|
}
|
catch (Exception ex)
|
{
|
throw new Exception(ex.Message);
|
}
|
}
|
else
|
{
|
tasktype = "D02";
|
palnoqty = (int)Db.Queryable<BllPalletBind>().First(w => w.PalletNo == palletNo && w.Status == "1" && w.IsDel == "0").Qty;
|
|
}
|
|
//添加入库任务
|
var taskNo = new Common().GetMaxNo("TK");
|
var exTask = new LogTask
|
{
|
TaskNo = taskNo,
|
Sender = "WMS",
|
Receiver = "AGV",
|
IsSuccess = 0, //是否下发成功 0失败 1成功
|
|
StartLocat = LocatNo,//起始位置
|
EndLocat = EndLocat,//目标位置
|
PalletNo = palletNo,//托盘码
|
Msg = string.Format("转运任务:{0}=>>{1}", LocatNo, EndLocat),
|
IsSend = 0,//是否可再次下发
|
IsCancel = 0,//是否可取消
|
IsFinish = 0,//是否可完成
|
Type = OrderTy,//任务类型 0 入库任务 1 出库任务 2 移库任务
|
Status = "0",//任务状态0:等待执行1正在执行2执行完成
|
OrderType = OrderTy,//0 入库单 1 出库单 2 盘点单 3 移库单
|
|
CreateTime = DateTime.Now
|
};
|
Db.Insertable(exTask).ExecuteCommand();
|
|
//修改起始储位地址状态
|
storageLocat.Status = "5";//0:空储位 1:有物品 2:入库中 3:出库中 4:移入中 5:移出中
|
Db.Updateable(storageLocat).ExecuteCommand();
|
|
//添加操作日志记录
|
var k = new OperationCrServer().AddLogOperationCr("PDA模块", "空托入库", palletNo, OrderTy == "0" ? "入库" : "移库", $"PDA呼叫小车对托盘号:{palletNo}发起转运", userId);
|
|
#region 呼叫小车代码
|
|
//点到点指令集合
|
object[] position = new object[2];
|
position[0] = new
|
{
|
positionCode = LocatNo,
|
type = "00"
|
};
|
position[1] = new
|
{
|
positionCode = EndLocat,
|
type = "00"
|
};
|
|
List<AgvSchedulingTask> agvTaskList = new List<AgvSchedulingTask>();
|
|
|
AgvSchedulingTask agvTask = new AgvSchedulingTask();
|
Random r = new Random();
|
long ran = DateTime.Now.Ticks;
|
agvTask.ReqCode = ran.ToString();
|
agvTask.TaskCode = taskNo;
|
agvTask.TaskTyp = tasktype;
|
agvTask.PositionCodePath = position;
|
agvTask.CtnrTyp = palnoqty.ToString();
|
|
agvTaskList.Add(agvTask);
|
|
|
// 正式运行程序放开
|
string str = "";
|
var list2 = agvTaskList.Select(m => m.TaskCode).ToList();
|
var jsonData = JsonConvert.SerializeObject(agvTaskList);
|
jsonData = jsonData.Substring(1, jsonData.Length - 1);
|
jsonData = jsonData.Substring(0, jsonData.Length - 1);
|
string response = "";
|
|
try
|
{
|
var time1 = DateTime.Now;//发送时间 .ToString("yyyy-MM-dd HH:mm:ss")
|
response = HttpHelper.DoPost(url, jsonData, "下发给AGV转运命令", "AGV");
|
var time2 = DateTime.Now;//返回时间 .ToString("yyyy-MM-dd HH:mm:ss")
|
|
//////解析返回数据
|
var agvModel = JsonConvert.DeserializeObject<OutCommanAgvDto>(response);
|
if (agvModel.Code == "0")
|
{
|
//更改任务的发送返回时间//
|
new TaskServer().EditTaskIssueOk(list2, time1, time2);
|
str += "下发成功";
|
}
|
if (agvModel.Code == "1")
|
{
|
new TaskServer().EditTaskIssueNo(list2, time1, time2, agvModel.Message);
|
throw new Exception(agvModel.Message);
|
}
|
}
|
catch (Exception ex)
|
{
|
throw new Exception(ex.Message);
|
}
|
|
#endregion
|
|
//提交事务
|
Db.CommitTran();
|
}
|
catch (Exception ex)
|
{
|
Db.RollbackTran();
|
throw new Exception(ex.Message);
|
}
|
}
|
|
#region
|
|
/// <summary>
|
/// agv调度任务下发
|
/// </summary>
|
/// <param name="type">搬运类型</param>
|
/// <param name="taskno">任务号</param>
|
/// <param name="positionStart">起始地址</param>
|
/// <param name="positionEnd">目的地址</param> 2
|
/// <param name="url">接口URL</param>
|
public OutCommanAgvDto AGVTask(string type, string taskno, string positionStart, string positionEnd ,string url)
|
{
|
|
var endlono = positionEnd;
|
var tasktype = type;
|
var storageLocatEnd = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == endlono && w.Flag == "0" && w.Status == "0");
|
if (storageLocatEnd == null)
|
{
|
throw new Exception("生成的AGV任务目的地址不正确");
|
}
|
//根据目的地址库区获取小车任务类型
|
switch (storageLocatEnd.AreaNo)
|
{
|
case "B13":
|
tasktype = "D02"; // 叠托任务(目的地址为空托盘收集区)
|
break;
|
case "B15":
|
tasktype = "D01"; // 拆托任务(目的地址为拣货区)
|
break;
|
}
|
|
// MES申请备料,备料区库位需要转换 车间备料缓存位名称:Y003_001-->Y003_011
|
if (storageLocatEnd.AreaNo == "B12")
|
{
|
switch (endlono.ToString().Substring(4, 1))
|
{
|
case "1":
|
endlono = "Y003_0" + endlono.Substring(5, 2);
|
break;
|
default:
|
break;
|
}
|
}
|
List<AgvSchedulingTask> agvTaskList = new List<AgvSchedulingTask>();
|
|
object[] position = new object[2];
|
position[0] = new
|
{
|
positionCode = positionStart,
|
type = "00"
|
};
|
position[1] = new
|
{
|
positionCode = endlono,
|
type = "00"
|
};
|
|
AgvSchedulingTask agvTask = new AgvSchedulingTask();
|
Random r = new Random();
|
long ran = DateTime.Now.Ticks;
|
agvTask.ReqCode = ran.ToString();
|
//agvTask.ReqCode = taskno; //agv请求编号,需要随机生成 (最大32位)
|
agvTask.TaskCode = taskno; //任务号
|
agvTask.TaskTyp = tasktype; //搬运类型
|
agvTask.PositionCodePath = position; //起始和目的位集合
|
agvTask.CtnrTyp = "1"; //容器类型,值为1
|
if (tasktype == "D02")
|
{
|
agvTask.CtnrNum = "10"; //叠托任务需要下发空托盘数量
|
}
|
|
agvTaskList.Add(agvTask);
|
|
string str = "";
|
var list2 = agvTaskList.Select(m => m.TaskCode).ToList();
|
var jsonData = JsonConvert.SerializeObject(agvTaskList);
|
jsonData = jsonData.Substring(1, jsonData.Length-1);
|
jsonData = jsonData.Substring(0, jsonData.Length - 1);
|
|
try
|
{
|
var time1 = DateTime.Now;//发送时间 .ToString("yyyy-MM-dd HH:mm:ss")
|
var response = HttpHelper.DoPost(url, jsonData, "下发给AGV转运命令", "AGV");
|
//response = HttpHelper.DoPost(url, jsonData, "下发给AGV转运命令", "AGV");
|
var time2 = DateTime.Now;//返回时间 .ToString("yyyy-MM-dd HH:mm:ss")
|
|
//////解析返回数据
|
var agvModel = JsonConvert.DeserializeObject<OutCommanAgvDto>(response);
|
if (agvModel.Code == "0")
|
{
|
//更改任务的发送返回时间//
|
new TaskServer().EditTaskIssueOk(list2, time1, time2);
|
str += "下发成功";
|
}
|
if (agvModel.Code == "1")
|
{
|
new TaskServer().EditTaskIssueNo(list2, time1, time2, agvModel.Message);
|
throw new Exception(agvModel.Message);
|
}
|
return agvModel;
|
}
|
catch (Exception ex)
|
{
|
throw new Exception(ex.Message);
|
}
|
|
}
|
|
/// <summary>
|
/// agv任务取消
|
/// </summary>
|
/// <param name="taskno">取消任务编号</param>
|
/// <param name="url">接口URL</param>
|
public void cancelTask(string taskno,string url)
|
{
|
try
|
{
|
AgvCancelTask agvTaskList = new AgvCancelTask();
|
Random r = new Random();
|
long ran = DateTime.Now.Ticks;
|
agvTaskList.ReqCode = ran.ToString();
|
//agvTaskList.ReqCode = "006"; //随机生成
|
agvTaskList.TaskCode = taskno.ToString();
|
//agvTaskList.ReqTime = DateTime.Now.ToString();
|
|
var jsonData = JsonConvert.SerializeObject(agvTaskList);
|
var response = HttpHelper.DoPost(url, jsonData, "下发给AGV转运命令", "AGV");
|
var agvModel = JsonConvert.DeserializeObject<cancelTaskModel>(response);
|
|
if (agvModel.Code != "0")
|
{
|
throw new Exception("下发AGV取消任务失败");
|
}
|
|
}
|
catch (Exception ex)
|
{
|
|
throw ex;
|
}
|
|
}
|
|
#endregion
|
|
/// <summary>
|
/// 根据区域分配储位
|
/// </summary>
|
/// <param name="areaNo"></param>
|
/// <param name="skuNo"></param>
|
/// <param name="lotNo"></param>
|
/// <returns></returns>
|
private string GetLocat(string areaNo, string skuNo, string lotNo, string palletNo, string hasLocatNoList = "")
|
{
|
try
|
{
|
string endLocat = string.Empty;//目标储位
|
//当然区域所有储位信息
|
var storageLocatList = Db.Queryable<SysStorageLocat>().Where(w => w.WareHouseNo == "W02" && w.AreaNo == areaNo).ToList();
|
//同区域同批次物料的储位信息
|
List<string> locatList = Db.Queryable<DataStockDetail>().Where(w => w.IsDel == "0" && w.SkuNo == skuNo && w.LotNo == lotNo && w.WareHouseNo == "W02" && w.AreaNo == areaNo && w.PalletNo != palletNo)
|
.OrderByDescending(o => o.LocatNo).Select(s => s.LocatNo).Distinct().ToList();
|
foreach (var item in locatList)
|
{
|
var locatInfo = storageLocatList.Where(w => w.LocatNo == item).First();
|
|
var locatInfo2 = storageLocatList.Where(w => w.IsDel == "0" && w.Status == "0" && w.Flag == "0" && w.LocatNo != locatInfo.LocatNo && w.Row == locatInfo.Row && !hasLocatNoList.Contains(w.LocatNo))
|
.OrderByDescending(o => o.Column).First();
|
if (locatInfo2 != null)
|
{
|
endLocat = locatInfo2.LocatNo;
|
}
|
}
|
if (string.IsNullOrEmpty(endLocat))
|
{
|
var locatInfo3 = storageLocatList.Where(w => w.IsDel == "0" && w.Flag == "0" && w.Status == "0" && !hasLocatNoList.Contains(w.LocatNo))
|
.OrderByDescending(m => m.Layer).OrderByDescending(m => m.Column).OrderByDescending(m => m.Row).First();
|
|
if (locatInfo3 != null)
|
{
|
endLocat = locatInfo3.LocatNo;
|
}
|
}
|
|
return endLocat;
|
}
|
catch (Exception ex)
|
{
|
throw new Exception(ex.Message);
|
}
|
}
|
|
/// <summary>
|
/// 下发AGV任务继续执行
|
/// </summary>
|
/// <param name="taskno"></param>
|
/// <param name="url"></param>
|
/// <returns></returns>
|
public void AgvContinue(string taskno,string url)
|
{
|
|
Random r = new Random();
|
long ran = DateTime.Now.Ticks;
|
var ReqCode = ran.ToString();
|
var data = new
|
{
|
reqCode = ReqCode,
|
taskCode = taskno
|
};
|
var jsonData = JsonConvert.SerializeObject(data);
|
try
|
{
|
var response = HttpHelper.DoPost(url, jsonData, "下发给AGV继续执行命令", "AGV");
|
|
//////解析返回数据
|
var agvModel = JsonConvert.DeserializeObject<OutCommanAgvDto>(response);
|
if (agvModel.Code == "1")
|
{
|
throw new Exception(agvModel.Message);
|
}
|
}
|
catch (Exception ex)
|
{
|
throw new Exception(ex.Message);
|
}
|
}
|
#endregion
|
|
#region 人工转运
|
|
//人工转运
|
public void ArtificialTransport(string palletNo, string locatNo, string endLocatNo, string mesTokenUrl, string mesUrl,int userId)
|
{
|
if (string.IsNullOrEmpty(palletNo))
|
{
|
throw new Exception("请扫描托盘条码!");
|
}
|
if (string.IsNullOrEmpty(locatNo))
|
{
|
throw new Exception("请选择起始地址!");
|
}
|
if (string.IsNullOrEmpty(endLocatNo))
|
{
|
throw new Exception("请输入目标地址!");
|
}
|
|
try
|
{
|
#region 判断信息
|
//开启事务
|
Db.BeginTran();
|
|
var stockDetail = Db.Queryable<DataStockDetail>().Where(w => w.IsDel == "0" && w.PalletNo == palletNo).ToList();
|
if (stockDetail.Count == 0)
|
{
|
throw new Exception("托盘上物料库存明细信息不存在,请检查!");
|
}
|
|
if (string.IsNullOrEmpty(stockDetail.First().LocatNo))
|
{
|
throw new Exception("托盘储位信息不存在,请检查!");
|
}
|
if (stockDetail.First().WareHouseNo != "W02")
|
{
|
throw new Exception("该托盘未在平库内,请检查!");
|
}
|
|
|
|
//起始储位信息
|
var storageLocat = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == locatNo);
|
if (storageLocat == null)
|
{
|
throw new Exception("起始地址储位信息不存在,请检查!");
|
}
|
//目标储位信息
|
var EndLocat = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == endLocatNo);
|
if (EndLocat == null)
|
{
|
throw new Exception("目标地址储位信息不存在,请检查!");
|
}
|
|
#endregion
|
|
|
|
//需先判断目标地址前方是否有空储位
|
|
storageLocat.Status = "0"; //更改起始储位
|
Db.Updateable(storageLocat).ExecuteCommand();
|
EndLocat.Status = "1"; //更改目标储位
|
Db.Updateable(storageLocat).ExecuteCommand();
|
|
var data = new List<RequertBeiliaoInfoModel>();
|
|
//更改库存明细
|
foreach (var item in stockDetail)
|
{
|
item.LocatNo = EndLocat.LocatNo;//储位更改
|
item.WareHouseNo = EndLocat.WareHouseNo;//所属仓库更改
|
item.RoadwayNo = EndLocat.RoadwayNo;//所属巷道更改
|
item.AreaNo = EndLocat.AreaNo;//所属区域更改
|
|
Db.Updateable(item).ExecuteCommand();
|
|
if (EndLocat != null && EndLocat.AreaNo == "B12") //是否是3楼缓存区 是:删除库存
|
{
|
if (string.IsNullOrWhiteSpace(item.SONo))
|
{
|
throw new Exception("当前托盘不是拼托出库托盘");
|
}
|
var boxInfo = Db.Queryable<DataBoxInfo>().Where(m => m.IsDel == "0" && m.StockDetailId == item.Id).ToList();
|
if (boxInfo.Count == 0)
|
{
|
throw new Exception("托盘上物料箱码信息不存在,请检查!");
|
}
|
//var boxno = boxInfo.GroupBy(w => w.BoxNo).ToList();
|
var boxno = Db.Queryable<DataBoxInfo>().Where(m => m.IsDel == "0" && m.StockDetailId == item.Id).GroupBy(m => new
|
{
|
m.BoxNo,
|
m.ProductionTime,
|
m.ExpirationTime,
|
}).Select(it => new DataBoxInfo()
|
{
|
BoxNo = it.BoxNo,
|
ProductionTime = it.ProductionTime,
|
ExpirationTime = it.ExpirationTime,
|
}).ToList();
|
|
//记录托盘上信息给MES
|
foreach (var item2 in boxno) {
|
//var a = item.ProductionTime.ToString();
|
data.Add(new RequertBeiliaoInfoModel()
|
{
|
no = item2.BoxNo,
|
materiel_no = item.SkuNo,
|
materiel_name = item.SkuName,
|
qty = item.Qty,
|
batch = item.LotNo,
|
producttime = item2.ProductionTime.ToString().Substring(0,10),
|
expiry = item2.ExpirationTime.ToString().Substring(0, 10)
|
|
});
|
}
|
//库存箱码明细删除
|
Db.Deleteable(boxInfo).ExecuteCommand();
|
//删除库存托盘信息
|
Db.Deleteable(item).ExecuteCommand();
|
//更改库存总表
|
var stock = Db.Queryable<DataStock>().First(w => w.IsDel == "0" && w.SkuNo == item.SkuNo && w.LotNo == item.LotNo);
|
stock.LockQty -= (decimal)item.Qty;
|
stock.Qty -= (decimal)item.Qty;
|
Db.Updateable(stock).ExecuteCommand();
|
//更改托盘状态
|
var pallet = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == palletNo);
|
if (pallet != null)
|
{
|
pallet.Status = "0";
|
Db.Updateable(pallet).ExecuteCommand();
|
}
|
}
|
}
|
|
|
if (EndLocat != null && EndLocat.AreaNo == "B12")
|
{
|
//获取令牌
|
//var token = new Token().GetMesToken(mesTokenUrl);
|
var token = "";
|
Dictionary<string, string> mesDic = new Dictionary<string, string>()
|
{
|
{"Authorization",token }
|
};
|
var endlono = EndLocat.LocatNo;
|
//缓存库位转换
|
switch (EndLocat.LocatNo.ToString().Substring(4, 1))
|
{
|
case "1":
|
endlono = "Y003_0" + EndLocat.LocatNo.ToString().Substring(5, 2);
|
break;
|
default:
|
break;
|
}
|
var mescode = Db.Queryable<BllExportNotice>().Where(w => w.SONo == stockDetail.First().SONo).First();
|
var mesData = new RequertBeiliaoModel()
|
{
|
morder_no = mescode.OrderCode,
|
pallet = stockDetail.First().PalletNo,
|
layer_no = endlono,
|
items = data
|
};
|
var jsonData = JsonConvert.SerializeObject(mesData);
|
//调用接口
|
var response = HttpHelper.DoPost(mesUrl, jsonData, "备料完成运至缓存区反馈至MES", "MES", mesDic);
|
|
var obj = JsonConvert.DeserializeObject<MesModel>(response);//解析返回数据
|
if (obj.status != "success")
|
{
|
throw new Exception("备料同步MES失败:" + obj.message);
|
}
|
|
}
|
|
|
|
//添加操作日志记录
|
var k = new OperationCrServer().AddLogOperationCr("PDA模块", "人工转运", palletNo, "移库", $"PDA呼叫小车对托盘号:{palletNo}发起转运", userId);
|
|
//提交事务
|
Db.CommitTran();
|
}
|
catch (Exception ex)
|
{
|
Db.RollbackTran();
|
throw new Exception(ex.Message);
|
}
|
|
|
|
|
}
|
#endregion
|
|
#region 箱码查询
|
/// <summary>
|
/// 箱码查询
|
/// </summary>
|
/// <param name="boxNo">箱码</param>
|
/// <returns></returns>
|
public DataBoxDto GetBoxQueryList(string boxNo)
|
{
|
// 实例化返回类
|
DataBoxDto boxModel = new DataBoxDto();
|
List<DataBoxInfoDto> list = new List<DataBoxInfoDto>();
|
|
// 根据箱码获取箱信息
|
var boxData = Db.Queryable<DataBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == boxNo);
|
|
if (boxData.Count() == 0)
|
{
|
// 根据盒码获取箱信息
|
boxData = Db.Queryable<DataBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo2 == boxNo);
|
if (boxData.Count() == 0)
|
{
|
boxModel = Db.Queryable<DataBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo3 == boxNo).Select(it => new DataBoxDto() { Qty = it.Qty }, true).First();
|
return boxModel;
|
}
|
|
list = boxData.Select(it => new DataBoxInfoDto()
|
{
|
BoxNo2 = it.BoxNo3,
|
Qty2 = it.Qty
|
}).ToList();
|
|
boxData = Db.Queryable<DataBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo2 == boxNo);
|
boxModel = boxData.GroupBy(m => new
|
{
|
m.BoxNo,
|
m.SkuName,
|
m.SkuNo,
|
m.LotNo,
|
m.SupplierLot,
|
m.InspectStatus
|
}).Select(it => new DataBoxDto()
|
{
|
BoxNo = it.BoxNo,
|
SkuName = it.SkuName,
|
SkuNo = it.SkuNo,
|
LotNo = it.LotNo,
|
SupplierLot = it.SupplierLot,
|
InspectStatus = it.InspectStatus == "0" ? "待检" : it.InspectStatus == "1" ? "合格":"不合格",
|
Qty = SqlFunc.AggregateSum(it.Qty)
|
}).First();
|
|
boxModel.InfoList = list;
|
return boxModel;
|
}
|
else //箱码内数据
|
{
|
// 处理多级码
|
var num = boxData.Count(m => !string.IsNullOrWhiteSpace(m.BoxNo2));
|
if (num > 0)
|
{
|
list = boxData.GroupBy(m => new
|
{
|
m.BoxNo2
|
}).Select(it => new DataBoxInfoDto()
|
{
|
BoxNo2 = it.BoxNo2,
|
Qty2 = SqlFunc.AggregateSum(it.Qty)
|
}).ToList();
|
}
|
else
|
{
|
list = boxData.Select(it => new DataBoxInfoDto()
|
{
|
BoxNo2 = SqlFunc.IsNull(it.BoxNo3,""),
|
Qty2 = it.Qty
|
}).ToList();
|
}
|
|
// 箱码信息赋值
|
boxData = Db.Queryable<DataBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == boxNo);
|
boxModel = boxData.GroupBy(m => new
|
{
|
m.BoxNo,
|
m.SkuName,
|
m.SkuNo,
|
m.LotNo,
|
m.SupplierLot,
|
m.InspectStatus
|
}).Select(it => new DataBoxDto()
|
{
|
BoxNo = it.BoxNo,
|
SkuName = it.SkuName,
|
SkuNo = it.SkuNo,
|
LotNo = it.LotNo,
|
SupplierLot = it.SupplierLot,
|
InspectStatus = it.InspectStatus == "0" ? "待检" : it.InspectStatus == "1" ? "合格" : "不合格",
|
Qty = SqlFunc.AggregateSum(it.Qty)
|
}).First();
|
boxModel.InfoList = list;
|
|
return boxModel;
|
}
|
}
|
#endregion
|
|
}
|
}
|