From 35721fc8c34198b7cbc97f88213a3d25f24431c0 Mon Sep 17 00:00:00 2001 From: Ben Lin <maobin001@msn.com> Date: 星期四, 20 二月 2025 15:20:51 +0800 Subject: [PATCH] 雅达-半成品入库打印 --- Tiger.IBusiness.MES/Tiger.IBusiness.MES.csproj | 4 Tiger.IBusiness/iERP/IMES_U9C.cs | 0 Tiger.Api/Language.db | 0 Tiger.IBusiness/iERP/IU9C_MES.cs | 0 Tiger.Business.WMS/Transaction/In_SemiProd.cs | 311 ++++++++++++++++++++++++++++++++++++++++++--------- 5 files changed, 257 insertions(+), 58 deletions(-) diff --git a/Tiger.Api/Language.db b/Tiger.Api/Language.db index de8909e..afc0c85 100644 --- a/Tiger.Api/Language.db +++ b/Tiger.Api/Language.db Binary files differ diff --git a/Tiger.Business.WMS/Transaction/In_SemiProd.cs b/Tiger.Business.WMS/Transaction/In_SemiProd.cs index 0b9a3bf..88742fa 100644 --- a/Tiger.Business.WMS/Transaction/In_SemiProd.cs +++ b/Tiger.Business.WMS/Transaction/In_SemiProd.cs @@ -16,6 +16,8 @@ using Tiger.Model.MES.Yada; using Apache.NMS.ActiveMQ.Commands; using System.Diagnostics; +using static Microsoft.CodeAnalysis.CSharp.SyntaxTokenParser; +using Tiger.Model.Entitys.MES.U9C; namespace Tiger.Business.WMS.Transaction { @@ -24,6 +26,7 @@ /// </summary> public class In_SemiProd : WMSTransactionBase, IIn_SemiProd { + private readonly IMES_U9C _IMES_U9C = DI.Resolve<IMES_U9C>(); public IIn_SemiProd Init(string id, string userCode, string apiHost, string orgCode) { TransID = id; @@ -38,9 +41,18 @@ 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 ScanShelfInfo CurScanShelf { get; set; } + public List<V_WMS_ITEM> Vitem { get; set; } = new(); + public int pageSize { get; set; } + public RcvRptDocCreateInput RcvRptInput { get; set; } = new RcvRptDocCreateInput(); + public List<ProdInBatch> ProdInBatchs { get; set; } = new List<ProdInBatch>(); + public List<BIZ_ERP_PROD_IN_BTH> ErpProdInBths { get; set; } = new List<BIZ_ERP_PROD_IN_BTH>(); + public List<BIZ_ERP_PROD_IN> ErpProdIns { get; set; } = new List<BIZ_ERP_PROD_IN>(); + /// <summary> + /// 鎵弿鍒楄〃 + /// </summary> + public List<InStoreScanInfo> InStoreScanInfos { get; set; } = new List<InStoreScanInfo>(); + public List<BIZ_ERP_PROD_IN_SN> ErpProdInSns { get; set; } = new List<BIZ_ERP_PROD_IN_SN>(); + public InStoreInfos inStoreInfos { get; set; } #endregion @@ -56,72 +68,157 @@ if (input.SN.IsNullOrEmpty()) { action.IsSuccessed = false; - action.LocaleMsg = Biz.L("WMS.RePrint.ScanItem.SnEmptyFailure"); + action.LocaleMsg = Biz.L("WMS.InSemiProd.ScanItem.SnEmptyFailure"); return SetOutPutMqttMsg(action, input.Locale); } - var LotNos = Biz.DataSource["YadaU9C"].Client.Ado.SqlQuery<mes_WhLotCodeQtyInfo>($"select *,'' as ID from mes_WhLotCodeQtyInfo where Bin = '{input.SN}'"); - //Biz.DataSource["YadaU9C"].Client.Queryable<mes_WhLotCodeQtyInfo>().Where(t => t.Bin == input.SN).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) + var wo = await Biz.Db.Queryable<BIZ_MES_WO>().Where(q => q.ORDER_NO == input.SN).IncludesAllFirstLayer().IncludesAllSecondLayer(q => q._ItemInfos).FirstAsync(); + if (wo == null) { - 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; - } - else { action.IsSuccessed = false; - //action.LocaleMsg = Biz.L("璇疯緭鍏ユ垨鎵弿鏈夋晥鐨勮揣鏋�/鍌ㄤ綅鐮�"); - action.LocaleMsg = Biz.L("WMS.Default.ScanShelf.ShelfCanNotEmpty"); + action.LocaleMsg = Biz.L("WMS.InSemiProd.ScanItem.WoEmptyFailure", input.SN); // $"宸ュ崟[{input.SN}]涓嶅瓨鍦�" return action; } - var temps = new List<TemplateInput>(); - foreach (var item in LotNos) + + InStoreInfo Info = new() { - var temp = new TemplateInput + ErpProdInBth = new() { - custCode="", - itemCode= item.ItemCode, - itemDesc= item.Description, - sapItemCode= item.SapCode, - WoBatch = item.LotCode, - batchQty= item.StoreQty, - qrCode="", + WORK_ORDER = wo.ORDER_NO, + BATCH_NO = "", + SALES_ORDER = wo.SALES_ORDER, + ITEM_CODE = wo.ITEM_CODE, + ITEM_NAME = wo.ItemInfo?.ITEM_DESC, + SapCode = wo.ItemInfo?.ExtInfo?.SapCode, + SCAN_QTY = input.Data.ToInt32(), + IS_HANDLED = "N" //Y-宸茬敓鎴愶紝N-鏈敓鎴愶紝F-澶辫触 + }, + InStoreScanInfo = new() + { + SN = "", + SALES_ORDER = wo.SALES_ORDER, + WORK_ORDER = wo.ORDER_NO, + BATCH_NO = "", + SCAN_QTY = input.Data.ToInt32() + } + }; + + //瑕佸瓨鍏ョ殑鎵规鍏ュ簱鍗曟暟鎹� + int n = InStoreScanInfos.Where(q => q.WORK_ORDER == Info.ErpProdInBth.WORK_ORDER).Count(); + if (!ErpProdInBths.Any(q => q.WORK_ORDER == Info.ErpProdInBth.WORK_ORDER)) + { + Info.ErpProdInBth.AUTH_ORG = OrgCode; + Info.ErpProdInBth.BATCH_NO = ""; + Info.ErpProdInBth.CREATE_USER = UserCode; + Info.ErpProdInBth.CREATE_TIME = DateTime.Now; + Info.ErpProdInBth.SCANED_DATE = DateTime.Now; + Info.ErpProdInBth.HANDLED_DATE = DateTime.Now; + Info.ErpProdInBth.IS_SCANED = "Y"; + Info.ErpProdInBth.ORDER_NO = UserCode; + Info.ErpProdInBth.IS_HANDLED = "N"; + Info.ErpProdInBth.CartonQty = n == 0 ? 1 : n; + BIZ_ERP_PROD_IN prodIn = new() + { + AUTH_ORG = OrgCode, + BILLCODE = UserCode, + BILLDATE = DateTime.Now, + STATUS = 0, + HANDLED = -1, + WAREHOUSECODE = "", + SOURCECODE = Info.ErpProdInBth.WORK_ORDER, + HANDLED_DATE = DateTime.Now, }; - temps.Add(temp); + ErpProdInBths.Add(Info.ErpProdInBth); + ErpProdIns.Add(prodIn); + } + //else + //{ + // if (!InStoreScanInfos.Any(q => q.WORK_ORDER == Info?.ErpProdInBth.WORK_ORDER && q.SN == CurSN)) + // { + // var erpbth = ErpProdInBths.Where(q => q.WORK_ORDER == Info.ErpProdInBth.WORK_ORDER).FirstOrDefault(); + // if (!erpbth.IsNullOrEmpty()) + // { + // erpbth.SCAN_QTY += Info.InStoreScanInfo.SCAN_QTY.ToDouble(); + // erpbth.CartonQty = n + 1; + // } + // } + //} + + //鐢熸垚鎵撳嵃瀹炰綋 + if (RcvRptInput.PrintJsons.Count == 0) + { + RcvRptInput.PrintJsons.Add(new() + { + ID = Guid.NewGuid().ToString("N"), + Items = new() { + Info.ErpProdInBth + } + }); + } + else + { + //鎷煎垎椤� + bool isAdded = false; + foreach (var item in RcvRptInput.PrintJsons) + { + if (!item.Items.Any(q => q.WORK_ORDER == Info.ErpProdInBth.WORK_ORDER)) + { + if (item.Items.Count < pageSize) + { + item.Items.Add(Info.ErpProdInBth); + isAdded = true; + } + } + else + { + isAdded = true; + } + } + if (!isAdded) + { + RcvRptInput.PrintJsons.Add(new() + { + ID = Guid.NewGuid().ToString("N"), + Items = new() { + Info.ErpProdInBth + } + }); + } } - var y = Biz.Db.Storageable(LotNos, UserCode) - .WhereColumns(t => new { t.ItemCode, t.LotCode }) - .ToStorage(); - y.AsInsertable.ExecuteCommand(); - y.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand(); - action.Data.Data = temps; - action.LocaleMsg = Biz.L("WMS.RePrint.ScanItem.ScanSuccessed"); + //淇濆瓨鏁版嵁搴� + var db = Business.Biz.Db; + var dbTran = db.UseTran(() => + { + var x = db.Storageable(ErpProdInBths, $"InStoreOrderNo_{UserCode}") + .WhereColumns(t => new { t.ORDER_NO, t.WORK_ORDER, t.GHOST_ROW }) + .ToStorage(); + x.AsInsertable.ExecuteCommand(); + x.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand(); + + //var s = db.Storageable(ErpProdInSns, $"InStoreOrderNo_{UserCode}") + // .WhereColumns(t => new { t.CARTONNO, t.SN, t.GHOST_ROW }) + // .ToStorage(); + //s.AsInsertable.ExecuteCommand(); + //s.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand(); + }); + if (!dbTran.IsSuccess) + { + Logger.Default.Fatal(dbTran.ErrorException, "Database transaction save exception"); + this.Close(!dbTran.IsSuccess); + throw dbTran.ErrorException; + } + RcvRptInput.RcvRptDocBases = new(); + RcvRptInput.labels = new(); + RcvRptInput.ErpProdInBths = ErpProdInBths; + RcvRptInput.userId = UserCode; + inStoreInfos = new() + { + ErpProdInBths = ErpProdInBths, + InStoreScanInfos = InStoreScanInfos, + }; + + action.Data.Data = inStoreInfos; + action.LocaleMsg = Biz.L("WMS.InSemiProd.ScanItem.ScanSuccessed"); //$"宸ュ崟鏉$爜[{input.SN}]鎵弿鎴愬姛锛岃濉叆宸ュ崟鏁伴噺鍚庣偣鎻愪氦" } catch (Exception ex) { @@ -145,6 +242,104 @@ return action; } + + /// <summary> + /// 璋冪敤U9C鎺ュ彛鐢熸垚鍏ュ簱鍗� + /// </summary> + /// <param name="code"></param> + /// <returns></returns> + public async Task<ApiAction<RcvRptDocCreateInput>> GenerateInStoreOrder() + { + var action = new ApiAction<RcvRptDocCreateInput>(); + try + { + //濡傛灉鎵弿璁板綍涓�0 + if (!RcvRptInput.ErpProdInBths.Any(q => q.IS_HANDLED == "N")) + { + action.IsSuccessed = false; + action.LocaleMsg = Biz.L($"娌℃湁瑕佸叆搴撶殑浜у搧鏁版嵁锛岃鎵弿鍖呰瀹屾垚鐨勭浜岀淮鐮侀噸鏂扮敓鎴愬叆搴撳崟鎹紒"); + return action; + } + if (RcvRptInput.RcvRptDocBases.IsNullOrEmpty() || RcvRptInput.RcvRptDocBases.Count == 0) + { + foreach (var item in RcvRptInput.ErpProdInBths) + { + var DocBase = new RcvRptDocBase() + { + WorkOrder = item.WORK_ORDER, + ItemCode = item.ITEM_CODE, + WhCode = "10105", + PkgQty = item.SCAN_QTY.ToInt32(), + CompleteQty = item.SCAN_QTY.ToInt32(), + OutputType = 0, + StorageType = 4, + DocState = 1, + Status = "N" + }; + if (!RcvRptInput.RcvRptDocBases.Any(q => q.WorkOrder == item.WORK_ORDER)) + { + RcvRptInput.RcvRptDocBases.Add(DocBase); + } + } + } + else + { + action.IsSuccessed = false; + action.LocaleMsg = Biz.L($"鏈夊瓨鍦ㄦ湭鎻愪氦鐨勫叆搴撳崟锛屼笉鑳界敓鎴愬叆搴撳崟"); + return action; + } + action = await _IMES_U9C.RcvRptDocCreate(RcvRptInput); + if (action.IsSuccessed) + { + foreach (var sn in ErpProdInSns) + { + var d = action.Data.ErpProdInBths.Where(q => q.WORK_ORDER == sn.SOURCECODE).FirstOrDefault(); + if (!d.IsNullOrEmpty()) + { + sn.BUSINESSCODE = d.ORDER_NO; + sn.UPDATE_USER = UserCode; + sn.UPDATE_TIME = DateTime.Now; + } + } + foreach (var p in ErpProdIns) + { + var d = action.Data.ErpProdInBths.Where(q => q.WORK_ORDER == p.SOURCECODE).FirstOrDefault(); + if (!d.IsNullOrEmpty()) + { + p.BILLCODE = d.ORDER_NO; + p.UPDATE_USER = UserCode; + p.UPDATE_TIME = DateTime.Now; + p.HANDLED = 0; + } + } + //淇濆瓨鏁版嵁搴� + var db = Business.Biz.Db; + var dbTran = db.UseTran(() => + { + db.Updateable(ErpProdInSns, $"InStoreOrderNo_{UserCode}").UpdateColumns(q => new { q.UPDATE_TIME, q.UPDATE_USER, q.BUSINESSCODE }).ExecuteCommand(); + + var x = db.Storageable(ErpProdIns, $"InStoreOrderNo_{UserCode}") + .WhereColumns(t => new { t.BILLCODE, t.SOURCECODE, t.GHOST_ROW }) + .ToStorage(); + x.AsInsertable.ExecuteCommand(); + x.AsUpdateable.IgnoreColumns(x => x.ID).ExecuteCommand(); + }); + if (!dbTran.IsSuccess) + { + Logger.Default.Fatal(dbTran.ErrorException, "Database transaction save exception"); + this.Close(!dbTran.IsSuccess); + throw dbTran.ErrorException; + } + } + + } + catch (Exception ex) + { + action.CatchExceptionWithLog(ex, $"璋冪敤U9C鎺ュ彛鐢熸垚鍏ュ簱鍗曞紓甯�"); + } + return action; + } + #endregion public override bool Close(bool needSaveHistoryLog = false) diff --git a/Tiger.IBusiness.MES/Tiger.IBusiness.MES.csproj b/Tiger.IBusiness.MES/Tiger.IBusiness.MES.csproj index 5e6cbbe..6725a7e 100644 --- a/Tiger.IBusiness.MES/Tiger.IBusiness.MES.csproj +++ b/Tiger.IBusiness.MES/Tiger.IBusiness.MES.csproj @@ -13,4 +13,8 @@ <ProjectReference Include="..\Tiger.IBusiness\Tiger.IBusiness.csproj" /> </ItemGroup> + <ItemGroup> + <Folder Include="iERP\" /> + </ItemGroup> + </Project> diff --git a/Tiger.IBusiness.MES/iERP/IMES_U9C.cs b/Tiger.IBusiness/iERP/IMES_U9C.cs similarity index 100% rename from Tiger.IBusiness.MES/iERP/IMES_U9C.cs rename to Tiger.IBusiness/iERP/IMES_U9C.cs diff --git a/Tiger.IBusiness.MES/iERP/IU9C_MES.cs b/Tiger.IBusiness/iERP/IU9C_MES.cs similarity index 100% rename from Tiger.IBusiness.MES/iERP/IU9C_MES.cs rename to Tiger.IBusiness/iERP/IU9C_MES.cs -- Gitblit v1.9.3