From dc203bafb60dc9985c805c6a4ec5f8018f3d3cf6 Mon Sep 17 00:00:00 2001 From: Ben Lin <maobin001@msn.com> Date: 星期五, 10 一月 2025 11:37:00 +0800 Subject: [PATCH] 更新 Scan 方法和 ReprintLabel 相关逻辑 --- Tiger.Business.WMS/Transaction/Out_Default.cs | 164 +++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 117 insertions(+), 47 deletions(-) diff --git a/Tiger.Business.WMS/Transaction/Out_Default.cs b/Tiger.Business.WMS/Transaction/Out_Default.cs index 88d5500..1402921 100644 --- a/Tiger.Business.WMS/Transaction/Out_Default.cs +++ b/Tiger.Business.WMS/Transaction/Out_Default.cs @@ -10,6 +10,7 @@ using Tiger.Model; using Tiger.IBusiness; using Org.BouncyCastle.Ocsp; +using Tiger.Model.MES.Yada; namespace Tiger.Business.WMS.Transaction { @@ -35,15 +36,16 @@ 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<DefaultScanItemOutput>> ScanItem(BaseInput input) + public async Task<ApiAction<ScanOutput>> Scan(BaseInput input) { - var action = new ApiAction<DefaultScanItemOutput>(); + var action = new ApiAction<ScanOutput>(new ScanOutput()); try { if (input.SN.IsNullOrEmpty()) @@ -51,42 +53,108 @@ action.IsSuccessed = false; //action.LocaleMsg = Biz.L("鏉$爜涓嶈兘涓虹┖"); action.LocaleMsg = Biz.L("WMS.Default.ScanItem.SnEmptyFailure"); - return action; + return SetOutPutMqttMsg(action, input.Locale); + } + //鎵弿鐗╂枡骞跺鏍� + { + 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); + } + + /// <summary> + /// 鎵弿鐗╂枡骞跺鏍革紝濡傛灉鏄櫤鑳借揣鏋跺垯浜伅鎻愰啋鍌ㄤ綅 + /// </summary> + public async Task<ApiAction<ScanOutput>> ScanItem(BaseInput input) + { + var action = new ApiAction<ScanOutput>(new ScanOutput() { Command = Command }); + try + { + if (CurInvItem.IsNullOrEmpty()) + { + //瑙f瀽鏉$爜 + 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; + + //楠岃瘉鏉$爜鏄惁姝g‘ + if (!inv.isNormalStatus || inv.Status != WMS_ITEM.STATUSs.InStore) + { + action.IsSuccessed = false; + //action.LocaleMsg = Biz.L($"鐘舵�乕{0}]寮傚父锛岃閲嶆柊鎵弿"); + action.LocaleMsg = Biz.L("WMS.Default.ScanItem.StatusException", string.Join(',', inv.StatusList.Select(x => x.GetDesc()))); + return action; + } + //鍌ㄤ綅楠岃瘉 + if (inv.Location.IsNullOrEmpty()) + { + action.IsSuccessed = false; + //action.LocaleMsg = Biz.L($"鏉$爜[{0}]搴撳瓨淇℃伅寮傚父: 娌℃湁鍌ㄤ綅淇℃伅锛岃鍏堜笂鏋跺悗鍐嶆壂鎻�(鍌ㄤ綅Id: {1})"); + action.LocaleMsg = Biz.L("WMS.Default.ScanItem.LocationIsNull", inv.CurPkg.SN, inv.CurPkg.LOCATION_ID); + 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; + } + CurInvItem = inv; + + //鎶婄墿鏂欐暟閲忚繑鍥炲墠绔‘璁よ涓嬫灦鐨勬暟閲� + if (CurInvItem.Items.Any(q => q.QTY > 1)) + { + 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.ComfirmOutQty", input.SN); + return action; + } } - //瑙f瀽鏉$爜 - Result<IInventory> result = WMS_ITEM_Biz.WmsItem.Get(input.SN, input.AuthOption, true); - if (!result.IsSuccessed) + Dictionary<string, decimal> downDic = null; + //鏇存柊涓嬫灦鍚庣殑鐗╂枡鏁伴噺 + if (Command == "ComfirmQty") { - action.IsSuccessed = false; - action.LocaleMsg = result.LocaleMsg; - return action; - } - CurInvItem = result.Data as Inventory; - - //楠岃瘉鏉$爜鏄惁姝g‘ - if (!CurInvItem.isNormalStatus || CurInvItem.Status != WMS_ITEM.STATUSs.InStore) - { - action.IsSuccessed = false; - //action.LocaleMsg = Biz.L($"鐘舵�乕{0}]寮傚父锛岃閲嶆柊鎵弿"); - action.LocaleMsg = Biz.L("WMS.Default.ScanItem.StatusException", string.Join(',', CurInvItem.StatusList.Select(x => x.GetDesc()))); - return action; - } - //鍌ㄤ綅楠岃瘉 - if (CurInvItem.Location.IsNullOrEmpty()) - { - action.IsSuccessed = false; - //action.LocaleMsg = Biz.L($"鏉$爜[{0}]搴撳瓨淇℃伅寮傚父: 娌℃湁鍌ㄤ綅淇℃伅锛岃鍏堜笂鏋跺悗鍐嶆壂鎻�(鍌ㄤ綅Id: {1})"); - action.LocaleMsg = Biz.L("WMS.Default.ScanItem.LocationIsNull", CurInvItem.CurPkg.SN, CurInvItem.CurPkg.LOCATION_ID); - return action; - } - //鐗╂枡楠岃瘉 - if (CurInvItem.ItemInfo.IsNullOrEmpty() || CurInvItem.ItemInfo.IS_ACTIVE == "N") - { - action.IsSuccessed = false; - //action.LocaleMsg = Biz.L($"鐗╂枡缂栫爜[{0}]涓嶅瓨鍦ㄦ垨鑰呰鐗╂枡鏈惎鐢�"); - action.LocaleMsg = Biz.L("WMS.Default.ScanItem.ItemCodeNotExistsOrNotActive", CurInvItem.ItemInfo.ITEM_CODE.IsNullOrEmpty(CurInvItem.Barcode.ItemCode)); - return action; + var qtyList = (input.Data ?? "").JsonToObject<List<WMS_ITEM>>() ?? new List<WMS_ITEM>(); + if (!qtyList.Any() || qtyList.Sum(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.ReComfirmOutQty", input.SN); + return action; + } + else if (qtyList.Any(q => q.QTY > CurInvItem.Items.First(i => i.SN == q.SN).QTY)) + { + 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.ReComfirmExceedOutQty", input.SN); + return action; + } + else + { + downDic = qtyList.ToDictionary(k => k.SN, v => v.QTY); + Command = "Normal"; + } } //鍑哄簱涓嬫灦 @@ -95,11 +163,12 @@ item.TRANS_CODE = "Out_Default"; item.TRANS_NO = $"Out_Default_{DateTime.Now:yyyyMMdd}"; } - Result<TakeDownInfo> downResult = WMS_ITEM_Biz.WmsItem.TakeDown(CurInvItem, input.AuthOption, WMS_ITEM.STATUSs.Sended); + Result<TakeDownInfo> downResult = WMS_ITEM_Biz.WmsItem.TakeDown(CurInvItem, downDic, input.AuthOption, WMS_ITEM.STATUSs.OffShelf); if (!downResult.IsSuccessed) { action.IsSuccessed = false; action.LocaleMsg = downResult.LocaleMsg; + CurInvItem = null; return action; } TakeDownInfo downInfo = downResult.Data; @@ -125,7 +194,7 @@ throw dbTran.ErrorException; } - action.Data = new DefaultScanItemOutput() + action.Data.Data = new DefaultScanItemOutput() { SN = CurInvItem.SN, ItemCode = CurInvItem.ItemInfo.ITEM_CODE, @@ -138,13 +207,14 @@ ScanAfCut = CurInvItem.Warehouse.SCAN_AF_CUT }; //action.LocaleMsg = Biz.L($"鎵弿鏉$爜[{0}]浠庡偍浣峓{1}]涓嬫灦鎴愬姛"); - action.LocaleMsg = Biz.L("WMS.Default.ScanItem.TakeDownSucceeded", action.Data.SN, action.Data.locationCode); + action.LocaleMsg = Biz.L("WMS.Default.ScanItem.TakeDownSucceeded", CurInvItem.SN, CurInvItem.Location?.LOCATION_CODE); + CurInvItem = null; } catch (Exception ex) { ResetInfo(); //action.CatchExceptionWithLog(ex, $"鎵弿鏉$爜[{input.SN}]澶嶆牳寮傚父"); - action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.ScanItem.ScanException", action.Data.SN)); + action.CatchExceptionWithLog(ex, Biz.L("WMS.Default.ScanItem.ScanException", input.SN)); } return action; } @@ -152,9 +222,9 @@ /// <summary> /// 鎵弿璐ф灦鎴栬�呭偍浣�(渚涗寒鐏揣鏋朵娇鐢�) /// </summary> - public async Task<ApiAction<ScanShelfInfo>> ScanShelf(string Code) + public async Task<ApiAction<ScanOutput>> ScanShelf(string Code) { - var action = new ApiAction<ScanShelfInfo>(); + var action = new ApiAction<ScanOutput>(new ScanOutput() { Command = Command }); try { if (Code.IsNullOrEmpty()) @@ -177,14 +247,13 @@ 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; } - // 鎵弿鍌ㄤ綅浠g爜 + // 鎵弿搴撲綅浠g爜 else { - var nLocation = await Biz.Db.Queryable<V_WH_UNIT>().Where(t => t.LOCATION_CODE.ToUpper() == Code.ToUpper() && t.AUTH_ORG == OrgCode).FirstAsync(); + 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; @@ -210,7 +279,7 @@ // return action; // } //} - + CurScanShelf.Shelf = nLocation.Shelf; CurScanShelf.Location = nLocation.Location; CurScanShelf.WarehouseCode = nLocation.WH_CODE; CurScanShelf.RegionCode = nLocation.REGION_CODE; @@ -222,7 +291,7 @@ 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) { @@ -242,6 +311,7 @@ public override void ResetInfo() { base.ResetInfo(); + Command = null; CurInvItem = null; CurScanShelf = null; } -- Gitblit v1.9.3