| | |
| | | using WMS.Entity.BllSoEntity; |
| | | using Model.ModelVm.PdaVm; |
| | | using Model.ModelDto.PdaDto; |
| | | using Dm; |
| | | using Model.InterFaceModel; |
| | | |
| | | namespace WMS.BLL.BllPdaServer |
| | | { |
| | |
| | | sqlString += $"group by BoxNo,SkuNo,SkuName,LotNo; "; |
| | | } |
| | | var models = Db.Ado.SqlQuery<BoxInfoDto>(sqlString); |
| | | |
| | | return models; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw ex; |
| | | } |
| | | } |
| | | |
| | | // 根据托盘号或箱码获取托盘信息 liudl |
| | | public List<PalletBindDto> GetPalletBindInfo(BllPalletBind model) |
| | | { |
| | | try |
| | | { |
| | | string sqlString = string.Empty; |
| | | sqlString = "select b.SkuNo,b.SkuName,a.LotNo,a.Qty,a.PalletNo,a.Id from BllPalletBind a left join BllArrivalNoticeDetail b on a.ASNDetailNo = b.Id where a.IsDel = '0' and b.IsDel = '0' "; |
| | | if (!string.IsNullOrEmpty(model.PalletNo)) |
| | | { |
| | | sqlString += $"and PalletNo = '{model.PalletNo}' and a.Status = '0' "; |
| | | } |
| | | else |
| | | { |
| | | throw new Exception("托盘号异常!"); |
| | | } |
| | | var models = Db.Ado.SqlQuery<PalletBindDto>(sqlString); |
| | | |
| | | return models; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | // 删除已组信息 |
| | | public string DelPalletBind(BllPalletBind model) |
| | | { |
| | | string strMsg = ""; |
| | | string sqlString = string.Empty; |
| | | try |
| | | { |
| | | if (model.Id == 0) |
| | | { |
| | | throw new Exception("-1:托盘ID不可为0!"); |
| | | } |
| | | |
| | | //获取托盘绑定信息 |
| | | var bind = Db.Queryable<BllPalletBind>().First(a => a.IsDel == "0" && a.Status == "0" && a.Id == model.Id); |
| | | //验证托盘绑定信息是否为空 |
| | | if (bind == null) |
| | | { |
| | | throw new Exception("-1:未获取到对应托盘信息,请核实!"); |
| | | } |
| | | //判断托盘绑定信息是否不是等待执行 |
| | | if (bind.Status != "0") |
| | | { |
| | | throw new Exception("-1:该托盘已正在入库,请核实!"); |
| | | } |
| | | //获取是否有指定库位 |
| | | SysStorageLocat locat = new SysStorageLocat(); |
| | | int isNullLocat = 0; |
| | | //判断储位是否为空 |
| | | if (!string.IsNullOrWhiteSpace(bind.LocatNo)) |
| | | { |
| | | isNullLocat = 1; |
| | | locat = Db.Queryable<SysStorageLocat>().First(a=>a.IsDel == "0" && a.WareHouseNo == bind.WareHouseNo && a.RoadwayNo == bind.RoadwayNo && a.LocatNo == bind.LocatNo); |
| | | //判断储位地址是否为正在入库 |
| | | if (locat.Status != "2") |
| | | { |
| | | throw new Exception("-1:当前托盘绑定的储位地址不是正在入库,请核实!"); |
| | | } |
| | | } |
| | | //获取托盘信息 |
| | | var pallet = Db.Queryable<SysPallets>().First(a => a.IsDel == "0" && a.PalletNo == model.PalletNo); |
| | | //判断托盘信息是否为空 |
| | | if (pallet == null) |
| | | { |
| | | throw new Exception("-1:未获取到对应托盘信息,请核实!"); |
| | | } |
| | | //获取对应入库单据总单 |
| | | var notice = Db.Queryable<BllArrivalNotice>().First(a => a.IsDel == "0" && a.ASNNo == bind.ASNNo); |
| | | //验证入库单总单信息 |
| | | if (notice == null) |
| | | { |
| | | throw new Exception("-1:未获取到对应入库单总单信息,请核实!"); |
| | | } |
| | | //获取对应入库单据明细 |
| | | var noticeDetail = Db.Queryable<BllArrivalNoticeDetail>().First(a => a.IsDel == "0" && a.Id == bind.ASNDetailNo); |
| | | //验证入库单单据明细 |
| | | if (noticeDetail == null) |
| | | { |
| | | throw new Exception("-1:未获取到对应入库单单据明细信息,请核实!"); |
| | | } |
| | | |
| | | |
| | | Db.BeginTran(); |
| | | //减少入库单明细数量 判断已组数量是否为0 再判断完成数量是否为0 |
| | | noticeDetail.FactQty -= bind.Qty; |
| | | //判断已组数量是否为0 |
| | | if (noticeDetail.FactQty == 0) |
| | | { |
| | | //判断是否有完成数量 |
| | | if (noticeDetail.CompleteQty == 0) |
| | | { |
| | | noticeDetail.Status = "0"; //入库单明细状态 |
| | | notice.Status = "0"; //入库单总单状态 |
| | | } |
| | | } |
| | | Db.Updateable(noticeDetail).ExecuteCommand(); |
| | | Db.Updateable(notice).ExecuteCommand(); |
| | | |
| | | |
| | | // 清除托盘绑定上信息 |
| | | //ASNNo,ASNDetailNo,Qty,FullQty,LotNo,LotText,SupplierLot,IsDel,UpdateTime,UpdateUser |
| | | bind.ASNNo = ""; //入库单号 |
| | | bind.ASNDetailNo = 0; //入库单明细id |
| | | bind.Qty = 0; //数量 |
| | | bind.FullQty = 0; //整托数量 |
| | | bind.LotNo = ""; //批次 |
| | | bind.LotText = ""; //批次描述 |
| | | bind.SupplierLot = ""; //供货批次 |
| | | bind.IsDel = "1"; //是否删除 |
| | | bind.UpdateTime = Db.GetDate(); //修改时间 |
| | | bind.UpdateUser = model.CreateUser; //修改人 |
| | | if (isNullLocat == 1) |
| | | { |
| | | bind.LocatNo = ""; //储位地址 |
| | | bind.RoadwayNo = ""; //所属巷道 |
| | | bind.WareHouseNo = ""; //所属仓库 |
| | | //修改储位信息状态 |
| | | locat.Status = "0"; //储位状态 0:空储位 |
| | | Db.Updateable(locat).ExecuteCommand(); |
| | | } |
| | | Db.Updateable(bind).ExecuteCommand(); |
| | | |
| | | //修改托盘信息状态 |
| | | pallet.Status = "0"; //0:未使用 |
| | | Db.Updateable(pallet).ExecuteCommand(); |
| | | |
| | | Db.CommitTran(); |
| | | return strMsg; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Db.RollbackTran(); |
| | | throw ex; |
| | | } |
| | | } |
| | | |
| | | // 平库完成入库操作 |
| | | public string CompleteInStock(PalletBindVm model) |
| | | { |
| | |
| | | #endregion |
| | | |
| | | #region 地码信息(储位信息) |
| | | var storageLocat = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == model.LocatNo && w.Status == "0"); |
| | | var storageLocat = Db.Queryable<SysStorageLocat>().First(w => w.IsDel == "0" && w.LocatNo == model.LocatNo && w.Status == "0" && w.WareHouseNo == "W02"); |
| | | if (storageLocat == null) |
| | | { |
| | | strMsg = "-1:储位信息不存在或非空闲状态,请核查!"; |
| | |
| | | |
| | | //修改组托状态 |
| | | palletbindInfo.Status = "2"; //2 入库完成 |
| | | palletbindInfo.WareHouseNo = "W02";//所属仓库 |
| | | palletbindInfo.LocatNo = model.LocatNo;//储位地址 |
| | | palletbindInfo.UpdateTime = serverTime; |
| | | palletbindInfo.UpdateUser = model.CreateUser; |
| | | palletbindInfo.CompleteTime = serverTime; //完成时间 |
| | |
| | | #endregion |
| | | |
| | | #endregion |
| | | } |
| | | } |
| | | storageLocat.Status = "1"; |
| | | storageLocat.UpdateTime= serverTime; //修改时间 |
| | | storageLocat.UpdateUser = model.CreateUser; //修改人 |
| | | //修改储位状态 |
| | | Db.Updateable(storageLocat).ExecuteCommand(); |
| | | |
| | | new OperationASNServer().AddLogOperationAsn("PDA模块", "平库入库", model.PalletNo, "完成", $"在PDA上完成单据号为:{model.ASNNo}的托盘码为:{model.PalletNo}的平库入库操作", (int)model.CreateUser); |
| | | |
| | |
| | | PalletNo = model.PalletNo, |
| | | PalletNo2 = "", |
| | | PalletNo3 = "", |
| | | Qty = 0, |
| | | Qty = model.SkuQty, |
| | | FullQty = pNum, |
| | | Status = "0", |
| | | Type = "0", |
| | |
| | | IsBelt = "0", |
| | | CreateUser = userId |
| | | }; |
| | | if (model.SkuQty > pNum) |
| | | { |
| | | throw new Exception($"绑定失败,{model.PalletNo}托盘绑定数量大于该物品托盘包装数量!"); |
| | | } |
| | | // 插入托盘绑定表 |
| | | bindId = Db.Insertable(bind).ExecuteReturnIdentity(); |
| | | } |
| | |
| | | #region 箱码信息 |
| | | var msgStr = $"箱号为{model.BoxNo}"; |
| | | var boxInfoList = new List<BllBoxInfo>(); |
| | | //首箱 |
| | | var boxInfo = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.BoxNo && m.Status == "0").ToList(); |
| | | if (boxInfo.Count == 0) |
| | | if (model.SkuQty == 0) |
| | | { |
| | | throw new Exception("-1:箱码信息不存在!"); |
| | | } |
| | | boxInfoList.AddRange(boxInfo); |
| | | //是否连续组托 |
| | | if (model.IsContinue == "1") |
| | | { |
| | | //尾箱 |
| | | var boxInfo2 = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.TailBoxNo && m.Status == "0").ToList(); |
| | | if (boxInfo2.Count == 0) |
| | | //首箱 |
| | | var boxInfo = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.BoxNo && m.Status == "0").ToList(); |
| | | if (boxInfo.Count == 0) |
| | | { |
| | | throw new Exception("-1:尾箱码信息不存在!"); |
| | | throw new Exception("-1:箱码信息不存在!"); |
| | | } |
| | | boxInfoList.AddRange(boxInfo2); |
| | | var sql = $"select * from BllBoxInfo where IsDel = '0' and Status = '0' and boxNo>'{model.BoxNo}' and boxNo<'{model.TailBoxNo}'; "; |
| | | var list = Db.Ado.SqlQuery<BllBoxInfo>(sql); |
| | | boxInfoList.AddRange(list); |
| | | msgStr += $"尾箱号为{model.TailBoxNo}"; |
| | | boxInfoList.AddRange(boxInfo); |
| | | //是否连续组托 |
| | | if (model.IsContinue == "1") |
| | | { |
| | | //尾箱 |
| | | var boxInfo2 = Db.Queryable<BllBoxInfo>().Where(m => m.IsDel == "0" && m.BoxNo == model.TailBoxNo && m.Status == "0").ToList(); |
| | | if (boxInfo2.Count == 0) |
| | | { |
| | | throw new Exception("-1:尾箱码信息不存在!"); |
| | | } |
| | | boxInfoList.AddRange(boxInfo2); |
| | | var sql = $"select * from BllBoxInfo where IsDel = '0' and Status = '0' and boxNo>'{model.BoxNo}' and boxNo<'{model.TailBoxNo}'; "; |
| | | var list = Db.Ado.SqlQuery<BllBoxInfo>(sql); |
| | | boxInfoList.AddRange(list); |
| | | msgStr += $"尾箱号为{model.TailBoxNo}"; |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | // 更改箱支关系表 |
| | | decimal factQty = 0.00m;//托盘总数量 |
| | | var boxGroup = boxInfoList.GroupBy(m => m.BoxNo).ToList(); |
| | | foreach (var g in boxGroup) |
| | | if (model.SkuQty == 0) |
| | | { |
| | | var boxFullQty = 0;//箱内总数量 |
| | | foreach (var box in g) |
| | | var boxGroup = boxInfoList.GroupBy(m => m.BoxNo).ToList(); |
| | | foreach (var g in boxGroup) |
| | | { |
| | | if (box.BindNo != null && box.BindNo != 0) |
| | | var boxFullQty = 0;//箱内总数量 |
| | | foreach (var box in g) |
| | | { |
| | | continue; |
| | | if (box.BindNo != null && box.BindNo != 0) |
| | | { |
| | | continue; |
| | | } |
| | | //箱内物料批次与单据明细不符合 |
| | | if (box.SkuNo != detail.SkuNo || box.LotNo != detail.LotNo) |
| | | { |
| | | throw new Exception($"-1:{box.BoxNo}箱内物料及批次与单据不一致,请核实!"); |
| | | } |
| | | |
| | | box.ASNNo = model.AsnNo; |
| | | box.ASNDetailNo = model.AsnDetailId; |
| | | box.BindNo = bindId; |
| | | box.PalletNo = model.PalletNo; |
| | | box.Status = "1"; |
| | | box.CompleteTime = DateTime.Now; |
| | | box.UpdateTime = DateTime.Now; |
| | | box.UpdateUser = userId; |
| | | |
| | | factQty += box.Qty; |
| | | boxFullQty += box.Qty; |
| | | } |
| | | //箱内物料批次与单据明细不符合 |
| | | if (box.SkuNo != detail.SkuNo || box.LotNo != detail.LotNo) |
| | | if (boxFullQty > bNum) |
| | | { |
| | | throw new Exception($"-1:{box.BoxNo}箱内物料及批次与单据不一致,请核实!"); |
| | | throw new Exception($"绑定失败,{g.Key}箱码绑定数量大于该物品包装数量!"); |
| | | } |
| | | |
| | | box.ASNNo = model.AsnNo; |
| | | box.ASNDetailNo = model.AsnDetailId; |
| | | box.BindNo = bindId; |
| | | box.PalletNo = model.PalletNo; |
| | | box.Status = "1"; |
| | | box.CompleteTime = DateTime.Now; |
| | | box.UpdateTime = DateTime.Now; |
| | | box.UpdateUser = userId; |
| | | |
| | | factQty += box.Qty; |
| | | boxFullQty += box.Qty; |
| | | } |
| | | if (boxFullQty > bNum) |
| | | { |
| | | throw new Exception($"绑定失败,{g.Key}箱码绑定数量大于该物品包装数量!"); |
| | | } |
| | | Db.Updateable(boxInfoList).ExecuteCommand(); |
| | | |
| | | // 更新托盘绑定表 |
| | | bind.Qty += factQty; |
| | | } |
| | | Db.Updateable(boxInfoList).ExecuteCommand(); |
| | | |
| | | // 更新托盘绑定表 |
| | | bind.Qty += factQty; |
| | | if (bind.FullQty < bind.Qty) |
| | | { |
| | | throw new Exception("托盘绑定数量已超出该物料包装数量"); |
| | |
| | | { |
| | | bind.BitPalletMark = "0"; |
| | | } |
| | | if (bind.Qty > pNum) |
| | | { |
| | | throw new Exception($"绑定失败,{bind.PalletNo}托盘绑定数量大于该物品托盘包装数量!"); |
| | | } |
| | | Db.Updateable(bind).Where(m => m.Id == bindId).ExecuteCommand(); |
| | | |
| | | // 更改入库单明细已组数量 |
| | | var sqlString = string.Empty; |
| | | sqlString += $"update BllArrivalNoticeDetail set FactQty = FactQty + '{factQty}' where id = '{model.AsnDetailId}';"; |
| | | if (factQty == 0) |
| | | { |
| | | sqlString += $"update BllArrivalNoticeDetail set FactQty = FactQty + '{bind.Qty}' where id = '{model.AsnDetailId}';"; |
| | | } |
| | | else |
| | | { |
| | | sqlString += $"update BllArrivalNoticeDetail set FactQty = FactQty + '{factQty}' where id = '{model.AsnDetailId}';"; |
| | | } |
| | | |
| | | Db.Ado.ExecuteCommand(sqlString); |
| | | |
| | | // 更改入库单及入库明细状态 |
| | |
| | | //添加托盘记录表数据 |
| | | sqlStr += $"insert into LogPalletTrack values('{model.PalletNo}','{model.AsnNo}','组盘','0',getDate(),{userId},NULL,NULL);"; |
| | | Db.Ado.ExecuteCommand(sqlStr); |
| | | new OperationASNServer().AddLogOperationAsn("PDA模块", "产品组托", model.AsnNo, "添加", $"添加了托盘码为:{model.PalletNo}、{msgStr}的组盘信息", userId); |
| | | new OperationASNServer().AddLogOperationAsn("PDA模块", "托盘绑定", model.AsnNo, "添加", $"添加了托盘码为:{model.PalletNo}、{msgStr}的组盘信息", userId); |
| | | |
| | | Db.CommitTran(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Db.RollbackTran(); |
| | | throw ex; |
| | | } |
| | | } |