| | |
| | | using Tiger.Model.Sharetronic.Shelf; |
| | | using Tiger.Business.WMS.Sharetronic.Shelf; |
| | | using Microsoft.IdentityModel.Tokens; |
| | | using Apache.NMS.ActiveMQ.Commands; |
| | | using Tiger.Model.MES.Yada; |
| | | using Tiger.Model.Entitys.MES.Position; |
| | | |
| | | namespace Tiger.Business.WMS.Transaction |
| | | { |
| | |
| | | public string OrgCode { get; set; } |
| | | public Inventory CurInvItem { get; set; } |
| | | public ScanShelfInfo CurScanShelf { get; set; } |
| | | public string Command { get; set; } = "Normal"; |
| | | #endregion |
| | | |
| | | #region Functions |
| | | /// <summary> |
| | | /// 扫描物料并复核,如果物料已经完成移库则货架上亮灯提醒储位 |
| | | /// 扫描入口 |
| | | /// </summary> |
| | | public async Task<ApiAction> ScanItem(BaseInput input) |
| | | public async Task<ApiAction<ScanOutput>> Scan(BaseInput input) |
| | | { |
| | | var action = new ApiAction(); |
| | | var action = new ApiAction<ScanOutput>(new ScanOutput()); |
| | | try |
| | | { |
| | | if (input.SN.IsNullOrEmpty()) |
| | |
| | | action.IsSuccessed = false; |
| | | //action.LocaleMsg = Biz.L("条码不能为空"); |
| | | action.LocaleMsg = Biz.L("WMS.Default.ScanItem.SnEmptyFailure"); |
| | | return action; |
| | | return SetOutPutMqttMsg(action, input.Locale); |
| | | } |
| | | //货架为空则扫描的认为是货架 |
| | | if (string.IsNullOrEmpty(CurScanShelf?.RackCode)) |
| | | //判断扫描的是否货架 |
| | | 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(); |
| | | //if (string.IsNullOrEmpty(CurScanShelf?.ShelfCode)) |
| | | if (!whUnit.IsNullOrEmpty() || string.IsNullOrEmpty(CurScanShelf?.ShelfCode)) |
| | | { |
| | | var _action = await ScanShelf(input.SN); |
| | | action.LocaleMsg = _action.LocaleMsg; |
| | | action.IsSuccessed = _action.IsSuccessed; |
| | | action.Data = _action.Data; |
| | | return action; |
| | | action = await ScanShelf(input.SN, whUnit); |
| | | } |
| | | else//扫描物料并复核 |
| | | { |
| | | action = await ScanItem(input); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | //取消当前操作 |
| | | ResetInfo(); |
| | | //action.CatchExceptionWithLog(ex, $"扫描[{input.SN}]异常"); |
| | | action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.Scan.ScanException", input.SN)); |
| | | } |
| | | return SetOutPutMqttMsg(action, input.Locale); |
| | | } |
| | | |
| | | Result<IInventory> result = WMS_ITEM_Biz.WmsItem.Get(input.SN, input.AuthOption, true); |
| | | if (!result.IsSuccessed) |
| | | /// <summary> |
| | | /// 扫描物料并复核,如果物料已经完成移库则货架上亮灯提醒储位 |
| | | /// </summary> |
| | | public async Task<ApiAction<ScanOutput>> ScanItem(BaseInput input) |
| | | { |
| | | var action = new ApiAction<ScanOutput>(new ScanOutput() { Command = Command }); |
| | | try |
| | | { |
| | | if (CurInvItem.IsNullOrEmpty()) |
| | | { |
| | | action.IsSuccessed = false; |
| | | action.LocaleMsg = result.LocaleMsg; |
| | | return action; |
| | | } |
| | | var inv = result.Data as Inventory; |
| | | //解析条码 |
| | | Result<IInventory> result = WMS_ITEM_Biz.WmsItem.Get(input.SN, input.AuthOption, true); |
| | | if (!result.IsSuccessed) |
| | | { |
| | | action.IsSuccessed = false; |
| | | action.LocaleMsg = result.LocaleMsg; |
| | | return action; |
| | | } |
| | | var inv = result.Data as Inventory; |
| | | |
| | | //验证条码是否正确 |
| | | if (!inv.isNormalStatus || inv.Status.GetValue() != WMS_ITEM.STATUSs.NotExists.GetValue() && inv.Status.GetValue() <= WMS_ITEM.STATUSs.InStore.GetValue()) |
| | | { |
| | | action.IsSuccessed = false; |
| | | //action.LocaleMsg = Biz.L("状态[{0}]异常,请重新扫描"); |
| | | action.LocaleMsg = Biz.L("WMS.Default.ScanItem.StatusException", string.Join(',', inv.StatusList.Select(q => q.GetDesc()))); |
| | | return action; |
| | | } |
| | | //物料验证 |
| | | if (inv.ItemInfo.IsNullOrEmpty() || inv.ItemInfo.IS_ACTIVE == "N") |
| | | { |
| | | action.IsSuccessed = false; |
| | | //action.LocaleMsg = Biz.L("物料编码[{0}]不存在或者该物料未启用"); |
| | | action.LocaleMsg = Biz.L("WMS.Default.ScanItem.ItemCodeNotExistsOrNotActive", inv.ItemInfo.ITEM_CODE.IsNullOrEmpty(inv.Barcode.ItemCode)); |
| | | return action; |
| | | } |
| | | //验证条码是否正确 |
| | | if (new[] { WMS_ITEM.STATUSs.InStore, WMS_ITEM.STATUSs.Loaded, WMS_ITEM.STATUSs.UseUp }.Contains(inv.Status)) |
| | | { |
| | | action.IsSuccessed = false; |
| | | //action.LocaleMsg = Biz.L("状态[{0}]异常,请重新扫描"); |
| | | action.LocaleMsg = Biz.L("WMS.Default.ScanItem.StatusException", string.Join(',', inv.StatusList.Select(q => q.GetDesc()))); |
| | | return action; |
| | | } |
| | | //物料验证 |
| | | if (inv.ItemInfo.IsNullOrEmpty() || inv.ItemInfo.IS_ACTIVE == "N") |
| | | { |
| | | action.IsSuccessed = false; |
| | | //action.LocaleMsg = Biz.L("物料编码[{0}]不存在或者该物料未启用"); |
| | | action.LocaleMsg = Biz.L("WMS.Default.ScanItem.ItemCodeNotExistsOrNotActive", inv.ItemInfo.ITEM_CODE.IsNullOrEmpty(inv.Barcode.ItemCode)); |
| | | return action; |
| | | } |
| | | |
| | | if (!inv.IsNullOrEmpty()) |
| | | { |
| | | if (inv.Items.Count == 0) |
| | | { |
| | | List<WMS_ITEM_HIS> ItemHistorys = new List<WMS_ITEM_HIS>(); |
| | |
| | | item.AUTH_ORG = input.AuthOption.CurOrg; |
| | | } |
| | | } |
| | | CurInvItem = inv; |
| | | |
| | | //检查物料数量,如果没有则查询雅达条码主档,把数量返回前端确认 |
| | | 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(); |
| | | foreach (var qty in qtyList) |
| | | { |
| | | 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("请确认条码[{0}]的数量是否正确"); |
| | | action.LocaleMsg = Biz.L("WMS.Default.ScanItem.ComfirmQty", input.SN); |
| | | return action; |
| | | } |
| | | } |
| | | |
| | | //更新已确认物料数量 |
| | | if (Command == "ComfirmQty") |
| | | { |
| | | var qtyList = (input.Data ?? "").JsonToObject<List<WMS_ITEM>>() ?? new List<WMS_ITEM>(); |
| | | if (!qtyList.Any() || qtyList.Any(q => q.QTY <= 0)) |
| | | { |
| | | action.IsSuccessed = false; |
| | | action.Data.Data = CurInvItem.Items.Select(q => new { q.SN, q.QTY }); |
| | | action.Data.Command = Command = "ComfirmQty"; |
| | | //action.LocaleMsg = Biz.L("数量不能小于等于零,请重新确认条码[{0}]的数量"); |
| | | action.LocaleMsg = Biz.L("WMS.Default.ScanItem.ReComfirmQty", input.SN); |
| | | return action; |
| | | } |
| | | else |
| | | { |
| | | foreach (var qty in qtyList) |
| | | { |
| | | var item = CurInvItem.Items.First(q => q.SN == qty.SN); |
| | | item.QTY = qty.QTY; |
| | | var pkg = CurInvItem.Packages.First(q => q.SN == qty.SN); |
| | | pkg.QTY = qty.QTY; |
| | | } |
| | | CurInvItem.UpdatePkgQty(); |
| | | |
| | | Command = "Normal"; |
| | | } |
| | | } |
| | | |
| | | var nLocation = new WMS_LOCATION(); |
| | | // 判断是否智能货架 |
| | | if (CurScanShelf.Shelf.IsLightShelf) |
| | | { |
| | | ShelfApiResult shelfApiResult = await Share.Shelf.PutOn(TransID, CurScanShelf.Shelf, inv.Items[0]); |
| | | ShelfApiResult shelfApiResult = await Share.Shelf.PutOn(TransID, CurScanShelf.Shelf, CurInvItem.Items[0]); |
| | | if (!shelfApiResult.IsSuccess) |
| | | { |
| | | action.IsSuccessed = false; |
| | |
| | | } |
| | | |
| | | //判断储位是否单放 |
| | | if (nLocation.IS_SINGLE == "Y" && inv.Items.Count > 1) |
| | | if (nLocation.IS_SINGLE == "Y" && CurInvItem.Items.Count > 1) |
| | | { |
| | | action.IsSuccessed = false; |
| | | //action.LocaleMsg = Biz.L("储位[{0}]只能存放一个物料"); |
| | | action.LocaleMsg = Biz.L("WMS.Default.ScanItem.LocationSingleFailure", nLocation.LOCATION_CODE); |
| | | CurInvItem = null; |
| | | return action; |
| | | } |
| | | |
| | | //执行上架 |
| | | foreach (var item in inv.Items) |
| | | 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(inv, input.AuthOption, nLocation.LOCATION_CODE); |
| | | Result<PutOnInfo> putonResult = WMS_ITEM_Biz.WmsItem.PutOn(CurInvItem, input.AuthOption, nLocation.LOCATION_CODE); |
| | | if (!putonResult.IsSuccessed) |
| | | { |
| | | action.IsSuccessed = false; |
| | | action.LocaleMsg = putonResult.LocaleMsg; |
| | | CurInvItem = null; |
| | | return action; |
| | | } |
| | | PutOnInfo putOnInfo = putonResult.Data; |
| | |
| | | throw dbTran.ErrorException; |
| | | } |
| | | // 返回其他入库对象 |
| | | action.Data = new DefaultInStoreOutput |
| | | action.Data.Data = new DefaultInStoreOutput |
| | | { |
| | | Barcode = inv.SN, |
| | | MaterialCode = inv.ItemInfo.ITEM_CODE, |
| | | MaterialName = inv.ItemInfo.ITEM_NAME, |
| | | CurrentQty = inv.Items[0].QTY, |
| | | Unit = inv.Items[0].UNIT, |
| | | DateCode = inv.Items[0].PROD_DATE, |
| | | 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", inv.SN, putOnInfo.Location.LOCATION_CODE); |
| | | action.LocaleMsg = Biz.L("WMS.Default.ScanItem.PutOnSucceeded", CurInvItem.SN, putOnInfo.Location.LOCATION_CODE); |
| | | CurInvItem = null; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | /// <summary> |
| | | /// 扫描货架或者储位 |
| | | /// </summary> |
| | | public async Task<ApiAction<ScanShelfInfo>> ScanShelf(string Code) |
| | | public async Task<ApiAction<ScanOutput>> ScanShelf(string Code, V_WH_UNIT whUnit) |
| | | { |
| | | var action = new ApiAction<ScanShelfInfo>(); |
| | | var action = new ApiAction<ScanOutput>(new ScanOutput() { Command = Command }); |
| | | try |
| | | { |
| | | if (Code.IsNullOrEmpty()) |
| | |
| | | CurScanShelf = new ScanShelfInfo(); |
| | | |
| | | // 查询货架信息 |
| | | var whUnit = await Biz.Db.Queryable<V_WH_UNIT>().Where(t => t.SHELF_CODE.ToUpper() == Code.ToUpper() && t.AUTH_ORG == OrgCode).IncludesAllFirstLayer().FirstAsync(); |
| | | 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()); |
| | | |
| | | // 扫描货架代码,且为智能货架 |
| | | if (whUnit != null && whUnit.SHELF_TYPE == WMS_SHELF.SHELF_TYPEs.Smart.GetValue()) |
| | | if (!whUnit.IsNullOrEmpty() && whUnit.SHELF_CODE == Code) |
| | | { |
| | | CurScanShelf.Shelf = whUnit.Shelf; |
| | | CurScanShelf.WarehouseCode = whUnit.WH_CODE; |
| | | CurScanShelf.RegionCode = whUnit.REGION_CODE; |
| | | CurScanShelf.ShelfCode = whUnit.SHELF_CODE; |
| | | CurScanShelf.LocationCode = whUnit.LOCATION_CODE; |
| | | CurScanShelf.ShelfType = whUnit.SHELF_TYPE; |
| | | CurScanShelf.IsSmartRack = true; |
| | | } |
| | | // 扫描库位代码 |
| | | else |
| | | 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).FirstAsync(); |
| | | if (nLocation == null) |
| | | { |
| | | action.IsSuccessed = false; |
| | | //action.LocaleMsg = Biz.L("储位[{0}]不存在"); |
| | | action.LocaleMsg = Biz.L("WMS.Default.ScanShelf.LocationNotExist", Code); |
| | | return action; |
| | | } |
| | | if (nLocation.IS_ACTIVE == "N") |
| | | //var nLocation = await Biz.Db.Queryable<V_WH_UNIT>().Where(t => t.LOCATION_CODE.ToUpper() == Code.ToUpper() && t.AUTH_ORG == OrgCode).IncludesAllFirstLayer().FirstAsync(); |
| | | //if (nLocation == null) |
| | | //{ |
| | | // action.IsSuccessed = false; |
| | | // //action.LocaleMsg = Biz.L("储位[{0}]不存在"); |
| | | // action.LocaleMsg = Biz.L("WMS.Default.ScanShelf.LocationNotExist", Code); |
| | | // return action; |
| | | //} |
| | | if (whUnit.IS_ACTIVE == "N") |
| | | { |
| | | action.IsSuccessed = false; |
| | | //action.LocaleMsg = Biz.L("扫描的储位[{0}]未启用"); |
| | | action.LocaleMsg = Biz.L("WMS.Default.ScanShelf.ShelfOrLocationDisabled", Code); |
| | | return action; |
| | | } |
| | | if (nLocation.Shelf.IsLightShelf || nLocation.Location.IS_SINGLE == "Y") |
| | | if (whUnit.Shelf.IsLightShelf || whUnit.Location.IS_SINGLE == "Y") |
| | | { |
| | | var locationData = Biz.Db.Queryable<WMS_ITEM>().Where(q => q.LOCATION_ID == nLocation.LOCATION_ID && q.AUTH_ORG == OrgCode).First(); |
| | | var locationData = Biz.Db.Queryable<WMS_ITEM>().Where(q => q.LOCATION_ID == whUnit.LOCATION_ID && q.AUTH_ORG == OrgCode).First(); |
| | | if (!locationData.IsNullOrEmpty()) |
| | | { |
| | | action.IsSuccessed = false; |
| | |
| | | return action; |
| | | } |
| | | } |
| | | CurScanShelf.Location = nLocation.Location; |
| | | CurScanShelf.WarehouseCode = nLocation.WH_CODE; |
| | | CurScanShelf.RegionCode = nLocation.REGION_CODE; |
| | | CurScanShelf.ShelfCode = nLocation.SHELF_CODE; |
| | | CurScanShelf.LocationCode = nLocation.LOCATION_CODE; |
| | | CurScanShelf.Shelf = whUnit.Shelf; |
| | | CurScanShelf.Location = whUnit.Location; |
| | | CurScanShelf.WarehouseCode = whUnit.WH_CODE; |
| | | CurScanShelf.RegionCode = whUnit.REGION_CODE; |
| | | CurScanShelf.ShelfCode = whUnit .SHELF_CODE; |
| | | CurScanShelf.LocationCode = whUnit.LOCATION_CODE; |
| | | CurScanShelf.IsSmartRack = false; |
| | | } |
| | | else |
| | | { |
| | | action.IsSuccessed = false; |
| | | //action.LocaleMsg = Biz.L("请输入或扫描有效的货架/储位码"); |
| | | action.LocaleMsg = Biz.L("WMS.Default.ScanShelf.ShelfCanNotEmpty"); |
| | | return action; |
| | | } |
| | | |
| | | CurScanShelf.IsScanShelf = true; |
| | | //action.LocaleMsg = Biz.L("扫描货架/储位[{0}]成功"); |
| | | action.LocaleMsg = Biz.L("WMS.Default.ScanShelf.ScanSucceeded", Code); |
| | | action.Data = CurScanShelf; |
| | | action.Data.Data = CurScanShelf; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | public override void ResetInfo() |
| | | { |
| | | base.ResetInfo(); |
| | | Command = null; |
| | | CurInvItem = null; |
| | | CurScanShelf = null; |
| | | } |