| | |
| | | using System.Text; |
| | | using System.Threading; |
| | | using System.Threading.Tasks; |
| | | using Model.InterFaceModel; |
| | | using Model.ModelDto.LogDto; |
| | | using Model.ModelDto.SysDto; |
| | | using SqlSugar; |
| | | using WMS.BLL.LogServer; |
| | | using WMS.Entity.Context; |
| | | using WMS.Entity.DataEntity; |
| | | using WMS.Entity.SysEntity; |
| | | using WMS.IBLL.ILogServer; |
| | | using WMS.IBLL.ISysServer; |
| | |
| | | } |
| | | } |
| | | |
| | | public async Task<bool> AddPallets(int groupCount, int userId) |
| | | /// <summary> |
| | | /// 添加桶信息并增加库存 |
| | | /// </summary> |
| | | /// <param name="palletNo"></param> |
| | | /// <param name="locatNo"></param> |
| | | /// <param name="userId"></param> |
| | | /// <exception cref="Exception"></exception> |
| | | public void AddPallets(string palletNo,string locatNo, string deviceCode, int userId) |
| | | { |
| | | var db = DataContext.Db; |
| | | try |
| | | { |
| | | var db = DataContext.Db; |
| | | if (groupCount <= 0) |
| | | { |
| | | if (string.IsNullOrEmpty(palletNo)) |
| | | { |
| | | throw new Exception("组数需大于0"); |
| | | throw new Exception("请输入桶号"); |
| | | } |
| | | |
| | | var pallNo = db.Queryable<SysPallets>().Max(m => m.PalletNo); |
| | | |
| | | var str = pallNo.Substring(3, 5); |
| | | string remove = pallNo.Substring(0, 3); |
| | | int sibelius = Convert.ToInt16(str); |
| | | var num = 0; |
| | | for (int i = 0; i < groupCount; i++) |
| | | if (string.IsNullOrEmpty(locatNo)) |
| | | { |
| | | sibelius += 1; |
| | | if (sibelius>99999) |
| | | throw new Exception("请输入储位地址"); |
| | | } |
| | | var palletModel = db.Queryable<SysPallets>().First(w => w.PalletNo == palletNo && w.IsDel == "0"); |
| | | if (palletModel != null) |
| | | { |
| | | throw new Exception("该桶号已存在"); |
| | | } |
| | | var locatModel= db.Queryable<SysStorageLocat>().First(w => w.LocatNo == locatNo && w.IsDel == "0"); |
| | | if (locatModel == null) |
| | | { |
| | | throw new Exception("储位地址不存在"); |
| | | } |
| | | if (locatModel.Status != "0") |
| | | { |
| | | throw new Exception("该储位地址非空闲状态"); |
| | | } |
| | | var areaModel = db.Queryable<SysStorageArea>().First(w => w.IsDel == "0" && w.AreaNo == locatModel.AreaNo); |
| | | if (areaModel == null) |
| | | { |
| | | throw new Exception("储位地址所属区域不存在"); |
| | | } |
| | | if (!areaModel.AreaName.Contains("净桶")) |
| | | { |
| | | throw new Exception("新添加的桶只能绑定净桶区"); |
| | | } |
| | | if (!string.IsNullOrEmpty(deviceCode)) |
| | | { |
| | | var areaInfo = db.Queryable<SysStorageArea>().First(w => w.IsDel == "0" && w.DeviceCode.Contains(deviceCode)); |
| | | if (areaInfo == null) |
| | | { |
| | | throw new Exception("托盘码位数已达上线"); |
| | | throw new Exception("未查到设备所属区域信息"); |
| | | } |
| | | string code = remove + Convert.ToString(sibelius).PadLeft(5, '0'); |
| | | if (db.Queryable<SysPallets>().Count(m=>m.PalletNo == code)>=1) |
| | | if (!areaInfo.AreaName.Contains("接料设备")) |
| | | { |
| | | continue; |
| | | throw new Exception("只能绑定接料设备"); |
| | | } |
| | | var item = new SysPallets |
| | | if (areaInfo.WareHouseNo != "M03") |
| | | { |
| | | PalletNo = code, |
| | | Status = "0", |
| | | Type = "0", |
| | | CreateUser = userId |
| | | }; |
| | | Thread.Sleep(100); |
| | | num += db.Insertable(item).ExecuteCommand(); |
| | | if (num > 0) |
| | | { |
| | | if (groupCount > 1) |
| | | { |
| | | await _operation.InsertOperation("仓库设置", "条码管理", item.PalletNo, "批量添加", "批量添加托盘信息 托盘号:" + item.PalletNo, userId); |
| | | } |
| | | else |
| | | { |
| | | await _operation.InsertOperation("仓库设置", "条码管理", item.PalletNo, "添加", "添加托盘信息 托盘号:" + item.PalletNo, userId); |
| | | } |
| | | |
| | | throw new Exception("只有大单体车间才能绑定设备"); |
| | | } |
| | | } |
| | | //开启事务 |
| | | db.BeginTran(); |
| | | |
| | | return num > 0; |
| | | palletModel = new SysPallets(); |
| | | palletModel.PalletNo = palletNo; |
| | | palletModel.Type = "0"; |
| | | palletModel.Status = "0"; |
| | | palletModel.CreateUser = userId; |
| | | //添加桶 |
| | | db.Insertable(palletModel).ExecuteCommand(); |
| | | |
| | | var comTime = DateTime.Now; |
| | | var model = new DataStockDetail() |
| | | { |
| | | ASNNo = "", |
| | | Qty = 0, |
| | | LockQty = 0, |
| | | FrozenQty = 0, |
| | | InspectQty = 0, |
| | | WareHouseNo = locatModel.WareHouseNo,//所属仓库 |
| | | RoadwayNo = "",//所属巷道 |
| | | AreaNo = locatModel.AreaNo,//所属区域 |
| | | LocatNo = locatModel.LocatNo,//储位地址 |
| | | PalletNo = palletNo, |
| | | PalletNo2 = "", |
| | | PalletNo3 = "", |
| | | PalletTags = "0", |
| | | CompleteTime = comTime, |
| | | ProductionTime = null, |
| | | ExpirationTime = null, |
| | | Status = "0", |
| | | InspectMark = "0", |
| | | InspectStatus = "0",//待检验 |
| | | BitPalletMark = "0", |
| | | PackagNo = "", |
| | | IsBale = "0", |
| | | IsBelt = "0", |
| | | |
| | | SkuNo = "", |
| | | SkuName = "", |
| | | LotNo = "", |
| | | |
| | | PalletStatus = "0",//净桶 |
| | | |
| | | UDF1 = deviceCode, |
| | | |
| | | IsDel = "0", |
| | | CreateUser = userId, |
| | | CreateTime = comTime, |
| | | UpdateTime=comTime, |
| | | }; |
| | | //插入库存明细 |
| | | db.Insertable(model).ExecuteCommand(); |
| | | |
| | | //更新储位状态 |
| | | locatModel.Status = "1";//有物品 |
| | | db.Updateable(locatModel).ExecuteCommand(); |
| | | |
| | | //提交事务 |
| | | db.CommitTran(); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | //回滚事务 |
| | | db.RollbackTran(); |
| | | throw new Exception(e.Message); |
| | | } |
| | | } |