| | |
| | | using Tiger.IBusiness; |
| | | using Tiger.Model.Sharetronic.Shelf; |
| | | using Tiger.Business.WMS.Sharetronic.Shelf; |
| | | using Microsoft.IdentityModel.Tokens; |
| | | using Apache.NMS.ActiveMQ.Commands; |
| | | //using Microsoft.IdentityModel.Tokens; |
| | | using Tiger.Model.MES.Yada; |
| | | using Tiger.Model.Entitys.MES.Position; |
| | | |
| | | namespace Tiger.Business.WMS.Transaction |
| | | { |
| | | /// <summary> |
| | | /// 标准上架事务 |
| | | /// </summary> |
| | | public class In_Default : WMSTransactionBase, IIn_Default |
| | | public class In_Default : WmsTask, IIn_Default |
| | | { |
| | | public IIn_Default Init(string id, string userCode, string apiHost, string orgCode) |
| | | { |
| | | TransID = id; |
| | | UserCode = userCode; |
| | | ApiHost = apiHost; |
| | | OrgCode = orgCode; |
| | | base.Init(id, apiHost, userCode, orgCode); |
| | | Logger.Console.Info($"Start {this.GetType().Name} Transaction[ID: {TransID}]"); |
| | | return this; |
| | | } |
| | | |
| | | #region Propertys & Variables |
| | | public string UserCode { get; set; } |
| | | public long UserId { get; set; } |
| | | public string OrgCode { get; set; } |
| | | public Inventory CurInvItem { get; set; } |
| | | public ScanShelfInfo CurScanShelf { get; set; } |
| | | public string Command { get; set; } = "Normal"; |
| | | |
| | | #endregion |
| | | |
| | | #region Functions |
| | |
| | | return SetOutPutMqttMsg(action, input.Locale); |
| | | } |
| | | //判断扫描的是否货架 |
| | | var whUnit = await Biz.Db.Queryable<V_WH_UNIT>().Where(t => (t.SHELF_CODE.ToUpper() == input.SN || t.LOCATION_CODE.ToUpper() == input.SN) && t.AUTH_ORG == OrgCode).IncludesAllFirstLayer().FirstAsync(); |
| | | var whUnit = await MainDB.Queryable<V_WH_UNIT>().Where(t => (t.SHELF_CODE.ToUpper() == input.SN || t.LOCATION_CODE.ToUpper() == input.SN) && t.AUTH_ORG == OrgCode).IncludesAllFirstLayer().FirstAsync(); |
| | | //if (string.IsNullOrEmpty(CurScanShelf?.ShelfCode)) |
| | | if (!whUnit.IsNullOrEmpty() || string.IsNullOrEmpty(CurScanShelf?.ShelfCode)) |
| | | { |
| | |
| | | catch (Exception ex) |
| | | { |
| | | //取消当前操作 |
| | | ResetInfo(); |
| | | ResetScan(); |
| | | //action.CatchExceptionWithLog(ex, $"扫描[{input.SN}]异常"); |
| | | action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.Scan.ScanException", input.SN)); |
| | | } |
| | |
| | | return action; |
| | | } |
| | | var inv = result.Data as Inventory; |
| | | var _inv = inv.Clone(); |
| | | |
| | | //验证条码是否正确 |
| | | if (new[] { WMS_ITEM.STATUSs.InStore, WMS_ITEM.STATUSs.Loaded, WMS_ITEM.STATUSs.UseUp }.Contains(inv.Status)) |
| | | { |
| | |
| | | ITEM_CODE = inv.Barcode.ItemCode, |
| | | AUTH_ORG = input.AuthOption.CurOrg, |
| | | STATUS = WMS_ITEM.STATUSs.WaitIn.GetValue(), |
| | | QTY = inv.Barcode.Qty.ToDecimal(), |
| | | QTY = inv.Barcode.Qty.ToDouble(), |
| | | PROD_DATE = inv.Barcode.DateCode.ToDateTime(), |
| | | ERP_WH = CurScanShelf.WarehouseCode, |
| | | UNIT = inv.Barcode.Unit, |
| | |
| | | SN = inv.Barcode.SN, |
| | | AUTH_ORG = input.AuthOption.CurOrg, |
| | | ITEM_CODE = inv.Barcode.ItemCode, |
| | | QTY = inv.Barcode.Qty.ToDecimal(), |
| | | QTY = inv.Barcode.Qty.ToDouble(), |
| | | ERP_WH = CurScanShelf.WarehouseCode, |
| | | UNIT = inv.Barcode.Unit, |
| | | }; |
| | |
| | | inv.Items.Add(Item); |
| | | inv.History.Add(his); |
| | | inv.Packages.Add(ItemPkgs); |
| | | _inv = inv.Clone(); |
| | | } |
| | | else if (inv.Items.Count == 1) |
| | | { |
| | | inv.Items.First().QTY = inv.Barcode.Qty.ToDecimal(); |
| | | inv.Items.First().ERP_WH = CurScanShelf.WarehouseCode; |
| | | inv.Items.First().AUTH_ORG = input.AuthOption.CurOrg; |
| | | //雅达不从条码上更新数量 |
| | | //else if (inv.Items.Count == 1) |
| | | //{ |
| | | // inv.Items.First().QTY = inv.Barcode.Qty.ToDouble(); |
| | | // inv.Items.First().ERP_WH = CurScanShelf.WarehouseCode; |
| | | // inv.Items.First().AUTH_ORG = input.AuthOption.CurOrg; |
| | | |
| | | inv.Packages.First().QTY = inv.Barcode.Qty.ToDecimal(); |
| | | inv.Packages.First().ERP_WH = CurScanShelf.WarehouseCode; |
| | | inv.Packages.First().AUTH_ORG = input.AuthOption.CurOrg; |
| | | } |
| | | // inv.Packages.First().QTY = inv.Barcode.Qty.ToDouble(); |
| | | // inv.Packages.First().ERP_WH = CurScanShelf.WarehouseCode; |
| | | // inv.Packages.First().AUTH_ORG = input.AuthOption.CurOrg; |
| | | //} |
| | | //如果扫描外箱的不能更新数量 |
| | | else |
| | | { |
| | |
| | | if (CurInvItem.Items.Any(q => q.QTY <= 0)) |
| | | { |
| | | var qtyList = Biz.DataSource["YadaU9C"].Client.Queryable<mes_MaterialBarCode>().Where(q => CurInvItem.Items.Select(q => q.SN).Contains(q.Code)).ToList(); |
| | | if (qtyList.Count == 0) |
| | | foreach (var qty in qtyList) |
| | | { |
| | | var item = CurInvItem.Items.First(q => q.SN == _inv.Barcode.SN); |
| | | item.QTY = _inv.Items.First(q => q.SN == _inv.Barcode.SN).QTY; |
| | | } |
| | | else |
| | | { |
| | | foreach (var qty in qtyList) |
| | | { |
| | | var item = CurInvItem.Items.First(q => q.SN == qty.Code); |
| | | item.QTY = qty.WhQty; |
| | | } |
| | | var item = CurInvItem.Items.First(q => q.SN == qty.Code); |
| | | item.QTY = qty.WhQty; |
| | | } |
| | | action.Data.Data = CurInvItem.Items.Select(q => new { q.SN, q.QTY }); |
| | | action.Data.Command = Command = "ComfirmQty"; |
| | |
| | | action.LocaleMsg = Biz.L("WMS.Default.ScanItem.LocationNotExistsInShelf", CurScanShelf.Shelf.SHELF_CODE, reaultShelf.ledAddr); |
| | | return action; |
| | | } |
| | | var locationData = Biz.Db.Queryable<WMS_ITEM>().Where(q => q.LOCATION_ID == nLocation.ID).First(); |
| | | var locationData = MainDB.Queryable<WMS_ITEM>().Where(q => q.LOCATION_ID == nLocation.ID).First(); |
| | | if (!locationData.IsNullOrEmpty()) |
| | | { |
| | | action.IsSuccessed = false; |
| | |
| | | return action; |
| | | } |
| | | |
| | | nLocation = await Biz.Db.Queryable<WMS_LOCATION>().Where(t => t.LOCATION_CODE == CurScanShelf.LocationCode && t.AUTH_ORG == OrgCode).FirstAsync(); |
| | | nLocation = await MainDB.Queryable<WMS_LOCATION>().Where(t => t.LOCATION_CODE == CurScanShelf.LocationCode && t.AUTH_ORG == OrgCode).FirstAsync(); |
| | | } |
| | | |
| | | //判断储位是否单放 |
| | |
| | | action.IsSuccessed = false; |
| | | //action.LocaleMsg = Biz.L("储位[{0}]只能存放一个物料"); |
| | | action.LocaleMsg = Biz.L("WMS.Default.ScanItem.LocationSingleFailure", nLocation.LOCATION_CODE); |
| | | CurInvItem = null; |
| | | ResetScan(); |
| | | return action; |
| | | } |
| | | |
| | | //执行上架 |
| | | //执行上架数据处理 |
| | | foreach (var item in CurInvItem.Items) |
| | | { |
| | | item.TRANS_CODE = "In_Default"; |
| | | item.TRANS_NO = $"In_Default_{DateTime.Now:yyyyMMdd}"; |
| | | } |
| | | Result<PutOnInfo> putonResult = WMS_ITEM_Biz.WmsItem.PutOn(CurInvItem, input.AuthOption, nLocation.LOCATION_CODE); |
| | | Result putonResult = PutOn(input.AuthOption, nLocation.LOCATION_CODE); |
| | | if (!putonResult.IsSuccessed) |
| | | { |
| | | action.IsSuccessed = false; |
| | | action.LocaleMsg = putonResult.LocaleMsg; |
| | | CurInvItem = null; |
| | | ResetScan(); |
| | | return action; |
| | | } |
| | | PutOnInfo putOnInfo = putonResult.Data; |
| | | |
| | | //保存到数据库 |
| | | var db = Business.Biz.Db; |
| | | var dbTran = db.UseTran(() => |
| | | { |
| | | //入库 |
| | | db.Storageable(putOnInfo.Items, UserCode).ExecuteCommand(); |
| | | db.Storageable(putOnInfo.Packages, UserCode).ExecuteCommand(); |
| | | db.Insertable(putOnInfo.History, UserCode).ExecuteCommand(); |
| | | var x = db.Storageable(putOnInfo.ItemsExt, UserCode).ToStorage(); |
| | | x.AsInsertable.ExecuteCommand();//不存在插入 |
| | | x.AsUpdateable.ExecuteCommand();//存在更新 |
| | | }); |
| | | if (!dbTran.IsSuccess) |
| | | { |
| | | Logger.Default.Fatal(dbTran.ErrorException, "Database transaction save exception"); |
| | | throw dbTran.ErrorException; |
| | | } |
| | | // 返回其他入库对象 |
| | | action.Data.Data = new DefaultInStoreOutput |
| | | { |
| | | Barcode = CurInvItem.SN, |
| | | MaterialCode = CurInvItem.ItemInfo.ITEM_CODE, |
| | | MaterialName = CurInvItem.ItemInfo.ITEM_NAME, |
| | | CurrentQty = CurInvItem.Items[0].QTY, |
| | | Unit = CurInvItem.Items[0].UNIT, |
| | | DateCode = CurInvItem.Items[0].PROD_DATE, |
| | | WarehouseCode = putOnInfo.Warehouse.WH_CODE, |
| | | RegionCode = putOnInfo.Region.REGION_CODE, |
| | | ShelfCode = putOnInfo.Shelf.SHELF_CODE, |
| | | LocationCode = putOnInfo.Location.LOCATION_CODE, |
| | | }; |
| | | |
| | | //action.LocaleMsg = Biz.L($"扫描条码[{0}]上架到储位[{1}]成功"); |
| | | action.LocaleMsg = Biz.L("WMS.Default.ScanItem.PutOnSucceeded", CurInvItem.SN, putOnInfo.Location.LOCATION_CODE); |
| | | CurInvItem = null; |
| | | //完成所有处理后使用事务保存数据 |
| | | action = DoIfFinish(action, input.Locale); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | //取消当前操作 |
| | | ResetInfo(); |
| | | ResetScan(); |
| | | //action.CatchExceptionWithLog(ex, $"扫描条码[{input.SN}]复核异常"); |
| | | action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.ScanItem.ScanException", input.SN)); |
| | | } |
| | |
| | | CurScanShelf = new ScanShelfInfo(); |
| | | |
| | | // 查询货架信息 |
| | | whUnit = whUnit.IsNullOrEmpty(await Biz.Db.Queryable<V_WH_UNIT>().Where(t => (t.SHELF_CODE.ToUpper() == Code || t.LOCATION_CODE.ToUpper() == Code) && t.AUTH_ORG == OrgCode).IncludesAllFirstLayer().FirstAsync()); |
| | | whUnit = whUnit.IsNullOrEmpty(await MainDB.Queryable<V_WH_UNIT>().Where(t => (t.SHELF_CODE.ToUpper() == Code || t.LOCATION_CODE.ToUpper() == Code) && t.AUTH_ORG == OrgCode).IncludesAllFirstLayer().FirstAsync()); |
| | | |
| | | // 扫描货架代码,且为智能货架 |
| | | if (!whUnit.IsNullOrEmpty() && whUnit.SHELF_CODE == Code) |
| | |
| | | // 扫描库位代码 |
| | | else if (!whUnit.IsNullOrEmpty() && whUnit.LOCATION_CODE == Code) |
| | | { |
| | | //var nLocation = await Biz.Db.Queryable<V_WH_UNIT>().Where(t => t.LOCATION_CODE.ToUpper() == Code.ToUpper() && t.AUTH_ORG == OrgCode).IncludesAllFirstLayer().FirstAsync(); |
| | | //var nLocation = await MainDB.Queryable<V_WH_UNIT>().Where(t => t.LOCATION_CODE.ToUpper() == Code.ToUpper() && t.AUTH_ORG == OrgCode).IncludesAllFirstLayer().FirstAsync(); |
| | | //if (nLocation == null) |
| | | //{ |
| | | // action.IsSuccessed = false; |
| | |
| | | } |
| | | if (whUnit.Shelf.IsLightShelf || whUnit.Location.IS_SINGLE == "Y") |
| | | { |
| | | var locationData = Biz.Db.Queryable<WMS_ITEM>().Where(q => q.LOCATION_ID == whUnit.LOCATION_ID && q.AUTH_ORG == OrgCode).First(); |
| | | var locationData = MainDB.Queryable<WMS_ITEM>().Where(q => q.LOCATION_ID == whUnit.LOCATION_ID && q.AUTH_ORG == OrgCode).First(); |
| | | if (!locationData.IsNullOrEmpty()) |
| | | { |
| | | action.IsSuccessed = false; |
| | |
| | | catch (Exception ex) |
| | | { |
| | | //取消当前操作 |
| | | ResetInfo(); |
| | | ResetScan(); |
| | | //action.CatchExceptionWithLog(ex, $"扫描货架/储位[{0}]异常"); |
| | | action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.ScanShelf.ScanException", Code)); |
| | | } |
| | | return action; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 完成所有处理后使用事务保存数据 |
| | | /// </summary> |
| | | /// <param name="action"></param> |
| | | /// <returns></returns> |
| | | public ApiAction<ScanOutput> DoIfFinish(ApiAction<ScanOutput> action, string locale) |
| | | { |
| | | //保存数据库 |
| | | SaveCommitListToDB(); |
| | | |
| | | // 返回数据 |
| | | action.Data.Data = new DefaultInStoreOutput |
| | | { |
| | | Barcode = CurInvItem.SN, |
| | | MaterialCode = CurInvItem.ItemInfo.ITEM_CODE, |
| | | MaterialName = CurInvItem.ItemInfo.ITEM_NAME, |
| | | CurrentQty = CurInvItem.Items[0].QTY, |
| | | Unit = CurInvItem.Items[0].UNIT, |
| | | DateCode = CurInvItem.Items[0].PROD_DATE, |
| | | WarehouseCode = CurInvItem.Warehouse.WH_CODE, |
| | | RegionCode = CurInvItem.Region.REGION_CODE, |
| | | ShelfCode = CurInvItem.Shelf.SHELF_CODE, |
| | | LocationCode = CurInvItem.Location.LOCATION_CODE, |
| | | }; |
| | | |
| | | //action.LocaleMsg = Biz.L($"扫描条码[{0}]上架到储位[{1}]成功"); |
| | | action.LocaleMsg = Biz.L("WMS.Default.ScanItem.PutOnSucceeded", CurInvItem.SN, CurInvItem.Location.LOCATION_CODE); |
| | | |
| | | //重置工序 |
| | | ResetScan(); |
| | | return action; |
| | | } |
| | | |
| | |
| | | /// <summary> |
| | | /// 重置当前操作,有需要则重写此方法 |
| | | /// </summary> |
| | | public override void ResetInfo() |
| | | public override void ResetScan() |
| | | { |
| | | base.ResetInfo(); |
| | | base.ResetScan(); |
| | | Command = null; |
| | | CurInvItem = null; |
| | | CurScanShelf = null; |