From ee6ed49aa82a2746facff0a89b94d74d37329e85 Mon Sep 17 00:00:00 2001 From: Ben Lin <maobin001@msn.com> Date: 星期四, 16 一月 2025 21:41:06 +0800 Subject: [PATCH] 添加扫描入库逻辑及相关属性和方法 --- Tiger.Model.Net/Entitys/MES/YadaU9/mes_WhLotCodeQtyInfo.cs | 40 +++--- Tiger.IBusiness.WMS/Transaction/IRePrintLabel.cs | 1 Tiger.Business.WMS/Transaction/ReprintLabel.cs | 253 +++++++++++++++++++++++++++++++++++++++++- Tiger.Controllers.WMS/Controllers/WMSController.RePrintLabel.cs | 46 +++++++ Tiger.Model.Net/Entitys/WMS/Api/Input_Entitys.cs | 14 ++ 5 files changed, 328 insertions(+), 26 deletions(-) diff --git a/Tiger.Business.WMS/Transaction/ReprintLabel.cs b/Tiger.Business.WMS/Transaction/ReprintLabel.cs index cdc9c08..8ec081f 100644 --- a/Tiger.Business.WMS/Transaction/ReprintLabel.cs +++ b/Tiger.Business.WMS/Transaction/ReprintLabel.cs @@ -1,5 +1,4 @@ 锘縰sing Rhea.Common; -using Tiger.Model.Minsun; using Microsoft.AspNetCore.Http; using SqlSugar; using System; @@ -15,6 +14,7 @@ using Tiger.Model.Sharetronic.Shelf; using Tiger.IBusiness; using Tiger.Model.MES.Yada; +using Apache.NMS.ActiveMQ.Commands; namespace Tiger.Business.WMS.Transaction { @@ -37,8 +37,9 @@ public string UserCode { get; set; } public long UserId { get; set; } public string OrgCode { get; set; } + public string LocationCode { get; set; } public List<V_WMS_ITEM> Vitem { get; set; } = new(); - public Inventory CurInv { get; set; } + public ScanShelfInfo CurScanShelf { get; set; } #endregion @@ -58,9 +59,38 @@ return SetOutPutMqttMsg(action, input.Locale); } var LotNos = Biz.DataSource["YadaU9C"].Client.Queryable<mes_WhLotCodeQtyInfo>().Where(t => t.Bin == input.SN).ToList(); - //var whUnit = await Biz.Db.Queryable<V_WH_UNIT>().Where(t => t.LOCATION_CODE.ToUpper() == input.SN && t.AUTH_ORG == OrgCode).IncludesAllFirstLayer().FirstAsync(); - var items = LotNos.Select(q => q.ItemCode); - var ItemList = Biz.Db.Queryable<BAS_ITEM>().Where(t => t.AUTH_ORG == OrgCode && items.Contains(t.ITEM_CODE)).IncludesAllFirstLayer().ToList(); + CurScanShelf = new ScanShelfInfo(); + // 鏌ヨ璐ф灦淇℃伅 + 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 (!whUnit.IsNullOrEmpty() && whUnit.LOCATION_CODE == input.SN) + { + if (whUnit.IS_ACTIVE == "N") + { + action.IsSuccessed = false; + //action.LocaleMsg = Biz.L("鎵弿鐨勫偍浣峓{0}]鏈惎鐢�"); + action.LocaleMsg = Biz.L("WMS.Default.ScanShelf.ShelfOrLocationDisabled", input.SN); + return action; + } + 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(); + if (!locationData.IsNullOrEmpty()) + { + action.IsSuccessed = false; + //action.LocaleMsg = Biz.L("鍌ㄤ綅[{0}]宸插瓨鏈夌墿鏂橻{1}]锛岃妫�鏌ョ郴缁熷簱瀛樹俊鎭�"); + action.LocaleMsg = Biz.L($"WMS.Default.ScanShelf.ItemAlreadyExistsInLocation", input.SN, locationData.SN); + return action; + } + } + 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; + LocationCode = whUnit.LOCATION_CODE; + } var temps = new List<TemplateInput>(); foreach (var item in LotNos) { @@ -68,14 +98,15 @@ { custCode="", itemCode= item.ItemCode, - itemDesc= ItemList.Where(q => q.ITEM_CODE == item.ItemCode).FirstOrDefault()?.ITEM_DESC, - sapItemCode= ItemList.Where(q => q.ITEM_CODE == item.ItemCode).FirstOrDefault()?.ExtInfo?.SapCode, + itemDesc= item.Description, + sapItemCode= item.SapCode, WoBatch = item.LotCode, batchQty= item.StoreQty, qrCode="", }; temps.Add(temp); } + Biz.Db.Storageable(LotNos, UserCode).ExecuteCommand(); action.Data.Data = temps; action.LocaleMsg = Biz.L("WMS.RePrint.ScanItem.ScanSuccessed"); } @@ -87,6 +118,214 @@ return SetOutPutMqttMsg(action, input.Locale); } + public async Task<ApiAction<ScanOutput>> ScanItem(BaseInput input) + { + var action = new ApiAction<ScanOutput>(new ScanOutput()); + try + { + List<WMS_ITEM> items = new List<WMS_ITEM>(); + List<WMS_ITEM_HIS> itemhiss = new List<WMS_ITEM_HIS>(); + List<WMS_ITEM_PKG> itemPkgs = new List<WMS_ITEM_PKG>(); + List<WMS_ITEM_EXT> itemExts = new List<WMS_ITEM_EXT>(); + var rePrints = (input.Data ?? "").JsonToObject<RePrintLabelBase>() ?? new RePrintLabelBase(); + if (!rePrints.SnList.Any() || rePrints.SnList.Any(q => q.Qty <= 0)) + { + action.IsSuccessed = false; + //action.LocaleMsg = Biz.L("鏁伴噺涓嶈兘灏忎簬绛変簬闆讹紝璇烽噸鏂扮‘璁ゆ潯鐮乕{0}]鐨勬暟閲�"); + action.LocaleMsg = Biz.L("WMS.Default.ScanItem.ReComfirmQty", input.SN); + return action; + } + else + { + if (Biz.Db.Queryable<WMS_ITEM>().Any(q=>q.SUPP_LOTNO == rePrints.BatchNo) && (Biz.Db.Queryable<WMS_ITEM>().Where(q=>q.SUPP_LOTNO == rePrints.BatchNo).Sum(x=>x.QTY)>= rePrints.BatchQty)) { + action.IsSuccessed = false; + action.LocaleMsg = Biz.L($"姝ゅ簱浣峓{LocationCode}]涓婄殑鎵规[{rePrints.BatchNo}]鏁伴噺宸茬粡澶熸暟锛屼笉鑳藉啀涓婃灦鐢熸垚鏍囩"); + return action; + } + foreach (var ent in rePrints.SnList) + { + string CurSN = DI.Resolve<ICodeRuleCache>()["InitialBarcode"]?.Generate($"{ent.SN}").Data.ToString() ?? ""; + ent.SN = CurSN; + + //瑙f瀽鏉$爜 + Result<IInventory> result = WMS_ITEM_Biz.WmsItem.Get(CurSN, input.AuthOption, true); + if (!result.IsSuccessed) + { + action.IsSuccessed = false; + action.LocaleMsg = result.LocaleMsg; + return action; + } + var inv = result.Data as Inventory; + + //楠岃瘉鏉$爜鏄惁姝g‘ + 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.Items.Count == 0) + { + List<WMS_ITEM_HIS> ItemHistorys = new List<WMS_ITEM_HIS>(); + WMS_ITEM Item; + WMS_ITEM_PKG ItemPkgs; + + Item = new() + { + SN = inv.Barcode.SN, + ITEM_CODE = inv.Barcode.ItemCode, + AUTH_ORG = input.AuthOption.CurOrg, + STATUS = WMS_ITEM.STATUSs.WaitIn.GetValue(), + QTY = inv.Barcode.Qty.ToDecimal(), + PROD_DATE = inv.Barcode.DateCode.ToDateTime(), + ERP_WH = CurScanShelf.WarehouseCode, + UNIT = inv.Barcode.Unit, + }; + + WMS_ITEM_HIS his = new(Item, $"鍌ㄤ綅琛ュ嵃涓婃灦鍏ュ簱"); + ItemHistorys.Add(his); + ItemPkgs = new() + { + SN = inv.Barcode.SN, + AUTH_ORG = input.AuthOption.CurOrg, + ITEM_CODE = inv.Barcode.ItemCode, + QTY = inv.Barcode.Qty.ToDecimal(), + ERP_WH = CurScanShelf.WarehouseCode, + UNIT = inv.Barcode.Unit, + }; + + var noExt = inv.Items.Where(q => !inv.ItemsExt.Any(s => s.SN == q.SN)).ToList(); + //鎵╁睍琛ㄤ笉瀛樺湪鏃舵柊寤� + foreach (var item in noExt) + { + inv.ItemsExt.Add(new() + { + SN = item.SN, + META_SN = inv.Barcode.MetaSn, + QR_CODE = inv.Barcode.MetaSn + }); + } + + inv.Items.Add(Item); + inv.History.Add(his); + inv.Packages.Add(ItemPkgs); + } + 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; + + inv.Packages.First().QTY = inv.Barcode.Qty.ToDecimal(); + inv.Packages.First().ERP_WH = CurScanShelf.WarehouseCode; + inv.Packages.First().AUTH_ORG = input.AuthOption.CurOrg; + } + //濡傛灉鎵弿澶栫鐨勪笉鑳芥洿鏂版暟閲� + else + { + foreach (var item in inv.Items) + { + item.ERP_WH = CurScanShelf.WarehouseCode; + item.AUTH_ORG = input.AuthOption.CurOrg; + } + foreach (var item in inv.Packages) + { + item.ERP_WH = CurScanShelf.WarehouseCode; + item.AUTH_ORG = input.AuthOption.CurOrg; + } + } + + //鏇存柊宸茬‘璁ょ墿鏂欐暟閲� + var _item = inv.Items.First(q => q.SN == CurSN); + _item.QTY = ent.Qty; + var pkg = inv.Packages.First(q => q.SN == CurSN); + pkg.QTY = ent.Qty; + inv.UpdatePkgQty(); + + var nLocation = new WMS_LOCATION(); + + if (CurScanShelf.LocationCode.IsNullOrEmpty() || CurScanShelf.WarehouseCode.IsNullOrEmpty()) + { + action.IsSuccessed = false; + //action.LocaleMsg = Biz.L("璇疯緭鍏ユ垨鎵弿鏈夋晥鐨勮揣鏋�/鍌ㄤ綅鐮�"); + action.LocaleMsg = Biz.L("WMS.Default.ScanShelf.ShelfCanNotEmpty"); + return action; + } + + nLocation = await Biz.Db.Queryable<WMS_LOCATION>().Where(t => t.LOCATION_CODE == CurScanShelf.LocationCode && t.AUTH_ORG == OrgCode).FirstAsync(); + + //鍒ゆ柇鍌ㄤ綅鏄惁鍗曟斁 + //if (nLocation.IS_SINGLE == "Y" && inv.Items.Count > 1) + //{ + // action.IsSuccessed = false; + // //action.LocaleMsg = Biz.L("鍌ㄤ綅[{0}]鍙兘瀛樻斁涓�涓墿鏂�"); + // action.LocaleMsg = Biz.L("WMS.Default.ScanItem.LocationSingleFailure", nLocation.LOCATION_CODE); + // CurInvItem = null; + // CurSN = ""; + // return action; + //} + + //鎵ц涓婃灦 + foreach (var item in inv.Items) + { + item.TRANS_CODE = "ReprintLabel"; + item.TRANS_NO = $"ReprintLabel{DateTime.Now:yyyyMMdd}"; + } + Result<PutOnInfo> putonResult = WMS_ITEM_Biz.WmsItem.PutOn(inv, input.AuthOption, nLocation.LOCATION_CODE); + if (!putonResult.IsSuccessed) + { + action.IsSuccessed = false; + action.LocaleMsg = putonResult.LocaleMsg; + inv = null; + CurSN = ""; + return action; + } + PutOnInfo putOnInfo = putonResult.Data; + items.AddRange(putOnInfo.Items); + itemhiss.AddRange(putOnInfo.History); + itemPkgs.AddRange(putOnInfo.Packages); + itemExts.AddRange(putOnInfo.ItemsExt); + } + //淇濆瓨鍒版暟鎹簱 + var db = Business.Biz.Db; + var dbTran = db.UseTran(() => + { + //鍏ュ簱 + db.Storageable(items, UserCode).ExecuteCommand(); + db.Storageable(itemPkgs, UserCode).ExecuteCommand(); + db.Insertable(itemhiss, UserCode).ExecuteCommand(); + var x = db.Storageable(itemExts, UserCode).ToStorage(); + x.AsInsertable.ExecuteCommand();//涓嶅瓨鍦ㄦ彃鍏� + x.AsUpdateable.ExecuteCommand();//瀛樺湪鏇存柊 + }); + if (!dbTran.IsSuccess) + { + Logger.Default.Fatal(dbTran.ErrorException, "Database transaction save exception"); + throw dbTran.ErrorException; + } + + LocationCode = ""; + action.Data.Data = rePrints; + action.LocaleMsg = Biz.L("搴撲綅鎵规鏉$爜涓婃灦鎴愬姛"); + } + } + catch (Exception ex) + { + action.CatchExceptionWithLog(ex, Biz.L("搴撲綅鎵规鏉$爜涓婃灦澶辫触")); + } + return action; + } + #endregion public override bool Close(bool needSaveHistoryLog = false) diff --git a/Tiger.Controllers.WMS/Controllers/WMSController.RePrintLabel.cs b/Tiger.Controllers.WMS/Controllers/WMSController.RePrintLabel.cs index 05d3c37..c656426 100644 --- a/Tiger.Controllers.WMS/Controllers/WMSController.RePrintLabel.cs +++ b/Tiger.Controllers.WMS/Controllers/WMSController.RePrintLabel.cs @@ -99,7 +99,7 @@ /// <returns></returns> [HttpPost] [Route("api/[controller]/RePrintLabel/Scan")] - public async Task<IActionResult> RePrintLabel_ScanItemAsync([FromBody] ApiAction<BaseInput> action) + public async Task<IActionResult> RePrintLabel_ScanAsync([FromBody] ApiAction<BaseInput> action) { ApiAction response; IRePrintLabel trans = null; @@ -137,5 +137,49 @@ return Ok(response); } + /// <summary> + /// 鎵弿鍏ュ簱 + /// </summary> + /// <param name="action"></param> + /// <returns></returns> + [HttpPost] + [Route("api/[controller]/RePrintLabel/ScanItem")] + public async Task<IActionResult> RePrintLabel_ScanItemAsync([FromBody] ApiAction<BaseInput> action) + { + ApiAction response; + IRePrintLabel trans = null; + try + { + if (iBiz.WMS.Context.GetTransDic().ContainsKey(action.ID)) + { + trans = iBiz.WMS.Context.GetTransDic()[action.ID] as IRePrintLabel; + if (!trans.IsFinished) + { + if (action.IsAsync) + { + response = action.GetResponse(await trans.Scan(action.Data)); + } + else + { + lock (trans.TransLock) { response = action.GetResponse(trans.ScanItem(action.Data).Result); } + } + } + else + { + response = action.GetResponse($"Transaction Error: 鏍囧噯涓婃灦浜嬪姟[ID:{action.ID}]宸茬粡鍏抽棴锛岃閲嶆柊鎵撳紑鏍囧噯涓婃灦鍔熻兘", false); + } + } + else + { + response = action.GetResponse($"Transaction Error: 鏍囧噯涓婃灦浜嬪姟[ID:{action.ID}]鏁版嵁涓㈠け锛岃閲嶆柊鎵撳紑鏍囧噯涓婃灦鍔熻兘", false); + } + } + catch (System.Exception ex) + { + response = action.GetResponse().CatchExceptionWithLog(ex); + } + trans?.AddHistory(Request, action); + return Ok(response); + } } } \ No newline at end of file diff --git a/Tiger.IBusiness.WMS/Transaction/IRePrintLabel.cs b/Tiger.IBusiness.WMS/Transaction/IRePrintLabel.cs index a9740b4..f5732d9 100644 --- a/Tiger.IBusiness.WMS/Transaction/IRePrintLabel.cs +++ b/Tiger.IBusiness.WMS/Transaction/IRePrintLabel.cs @@ -15,6 +15,7 @@ { public IRePrintLabel Init(string id, string userCode, string apiHost, string orgCode); public Task<ApiAction<ScanOutput>> Scan(BaseInput input); + public Task<ApiAction<ScanOutput>> ScanItem(BaseInput input); public bool Close(bool needSaveHistoryLog = false); diff --git a/Tiger.Model.Net/Entitys/MES/YadaU9/mes_WhLotCodeQtyInfo.cs b/Tiger.Model.Net/Entitys/MES/YadaU9/mes_WhLotCodeQtyInfo.cs index e833979..7e2ed30 100644 --- a/Tiger.Model.Net/Entitys/MES/YadaU9/mes_WhLotCodeQtyInfo.cs +++ b/Tiger.Model.Net/Entitys/MES/YadaU9/mes_WhLotCodeQtyInfo.cs @@ -7,10 +7,11 @@ namespace Tiger.Model.MES.Yada { - /// <summary> - /// 实体:mes_WhLotCodeQtyInfo - /// </summary> - [Serializable] + /// <summary> + /// 实体:mes_WhLotCodeQtyInfo + /// </summary> + [Description("Primary:LotCode")] + [Serializable] [SugarTable("mes_WhLotCodeQtyInfo")] public class mes_WhLotCodeQtyInfo : iViewEntity { @@ -42,21 +43,24 @@ /// /// </summary> public decimal StoreQty { get; set; } - /// <summary> - /// - /// </summary> - public string LotCode { get; set; } - #endregion + /// <summary> + /// + /// </summary> + [SugarColumn(IsPrimaryKey = true)] + public string LotCode { get; set; } + public string Description { get; set; } + public string SapCode { get; set; } + #endregion - #region 虚拟属性 - /*例子 + #region 虚拟属性 + /*例子 [SugarColumn(IsIgnore = true)] public string FieldName { get; set; } */ - #endregion + #endregion - #region 枚举变量 - /*例子 + #region 枚举变量 + /*例子 public enum FieldNames { [Description("枚举描述0")] @@ -65,11 +69,11 @@ Enum1, } */ - #endregion + #endregion - #region 公共方法 + #region 公共方法 - #endregion + #endregion - }//endClass + }//endClass } \ No newline at end of file diff --git a/Tiger.Model.Net/Entitys/WMS/Api/Input_Entitys.cs b/Tiger.Model.Net/Entitys/WMS/Api/Input_Entitys.cs index 95f9041..162a5cb 100644 --- a/Tiger.Model.Net/Entitys/WMS/Api/Input_Entitys.cs +++ b/Tiger.Model.Net/Entitys/WMS/Api/Input_Entitys.cs @@ -66,4 +66,18 @@ { public bool IsItemCodeList { get; set; } } + + public class RePrintLabelBase + { + public string BatchNo { get; set; } + public decimal BatchQty { get; set; } + public List<RePrintLabelEntity> SnList { get; set; }=new List<RePrintLabelEntity>(); + } + + public class RePrintLabelEntity + { + public string ID { get; set; } + public string SN { get; set; } + public decimal Qty { get; set; } + } } -- Gitblit v1.9.3