From 0aa54059b26e6641196e9953490dd18616e916e3 Mon Sep 17 00:00:00 2001 From: 啊鑫 <t2856754968@163.com> Date: 星期三, 10 九月 2025 17:26:47 +0800 Subject: [PATCH] 精简修正代码 --- service/Warehouse/MesInvItemInCDetailsManager.cs | 203 +++++++++++++++++++++++++++----------------------- 1 files changed, 109 insertions(+), 94 deletions(-) diff --git a/service/Warehouse/MesInvItemInCDetailsManager.cs b/service/Warehouse/MesInvItemInCDetailsManager.cs index 8dfc5d4..065d517 100644 --- a/service/Warehouse/MesInvItemInCDetailsManager.cs +++ b/service/Warehouse/MesInvItemInCDetailsManager.cs @@ -1,5 +1,4 @@ -锘縰sing Masuit.Tools.Models; -using NewPdaSqlServer.DB; +锘縰sing NewPdaSqlServer.DB; using NewPdaSqlServer.Dto.service; using NewPdaSqlServer.entity; using NewPdaSqlServer.entity.Base; @@ -7,7 +6,6 @@ using NewPdaSqlServer.util; using Newtonsoft.Json; using SqlSugar; -using static Microsoft.EntityFrameworkCore.DbLoggerCategory; namespace NewPdaSqlServer.service.Warehouse; @@ -36,11 +34,13 @@ if (itemBarcodeDetails == null) throw new Exception("鏉$爜涓嶅瓨鍦紝璇锋牳瀵癸紒"); - if (string.IsNullOrEmpty(itemBarcodeDetails.Memo) || itemBarcodeDetails.Memo != "閲囪喘鍏ュ簱") + if (string.IsNullOrEmpty(itemBarcodeDetails.Memo) || + itemBarcodeDetails.Memo != "閲囪喘鍏ュ簱") throw new Exception("姝ゆ潯鐮佷笉灞炰簬鍒拌揣鏉$爜锛屾棤娉曠敤閲囪喘鍏ュ簱锛�"); var inventory = Db.Queryable<MesInvItemArn>() - .Where(it => it.BillNo == itemBarcodeDetails.BillNo && it.Fstatus == true ) + .Where(it => + it.BillNo == itemBarcodeDetails.BillNo && it.Fstatus == true) .First(); if (inventory == null) @@ -68,14 +68,14 @@ throw new Exception("姝ゆ潯鐮佹壘涓嶅埌瀵瑰簲鏀惰揣鍗曟槑缁嗭紒"); //鑾峰彇鍒拌揣妫�楠屾槑缁� - var sqlParams = new List<SugarParameter> { new("@dhmxGuid", itemBarcodeDetails.AboutGuid) }; + var sqlParams = new List<SugarParameter> + { new("@dhmxGuid", itemBarcodeDetails.AboutGuid) }; var sql1 = @"SELECT *FROM v_dhmx WHERE dhmxGuid = @dhmxGuid "; var dhjymx = Db.Ado.SqlQuery<vDhmx>(sql1, sqlParams).First(); //鍒ゅ畾妫�楠岃兘鍚﹀叆搴� - if (dhjymx.CanStore!= 1) - { - throw new Exception($"璇ユ潯鐮佸搴旂殑鏀舵枡鍗曟楠岀粨鏋�:銆恵dhjymx.InspectionResult}銆�,鍒ゅ畾缁撴灉锛氥�恵dhjymx.JudgmentResult}銆戯紝澶勭悊鎰忚锛氥�恵dhjymx.HandlingSuggestion}銆�,鏃犳硶鍏ュ簱"); - } + if (dhjymx.CanStore != 1) + throw new Exception( + $"璇ユ潯鐮佸搴旂殑鏀舵枡鍗曟楠岀粨鏋�:銆恵dhjymx.InspectionResult}銆�,鍒ゅ畾缁撴灉锛氥�恵dhjymx.JudgmentResult}銆戯紝澶勭悊鎰忚锛氥�恵dhjymx.HandlingSuggestion}銆�,鏃犳硶鍏ュ簱"); var depotCode = Db.Queryable<MesDepotSections>() .Where(it => it.DepotSectionCode == sectionCode) @@ -91,17 +91,12 @@ var checkGuid = UtilityHelper.CheckGuid(depotCode); if (checkGuid && depotCode != null) - { mesDepost = Db.Queryable<MesDepots>() .Where(s => s.DepotId.ToString() == depotCode).First(); - - // if (depotCode != mesDepost.Guid) - // throw new Exception("鎵弿搴撲綅涓庨噰璐叆搴撳簱浣嶄笉涓�鑷达紒"); - } + // if (depotCode != mesDepost.Guid) + // throw new Exception("鎵弿搴撲綅涓庨噰璐叆搴撳簱浣嶄笉涓�鑷达紒"); else - { throw new Exception("搴撲綅缂栫爜 " + sectionCode + " 涓嶅瓨鍦紝璇风‘璁わ紒"); - } //num = Db.Queryable<MesInvItemInCDetails>() @@ -121,19 +116,18 @@ var wmsManager = new WmsBaseMangeer(); // 鏂板鍏ュ簱鏍¢獙锛堣皟鐢ㄥ瓨鍌ㄨ繃绋嬶級 var checkResult = wmsManager.pdaInvJY( - db: Db, - edtUserNo: entity.userName, - barcode: entity.barcode, - sectionCode: sectionCode, - stockId: mesDepost.DepotId.ToString(), - stockOrgId: mesDepost.FSubsidiary, - billNo: "", // 鏍规嵁瀹為檯鍗曟嵁鍙蜂紶鍊� - transactionNo: "101" // 浜嬪姟绫诲瀷涓庡瓨鍌ㄨ繃绋嬪尮閰� + Db, + entity.userName, + entity.barcode, + sectionCode, + mesDepost.DepotId.ToString(), + mesDepost.FSubsidiary, + "", // 鏍规嵁瀹為檯鍗曟嵁鍙蜂紶鍊� + "101" // 浜嬪姟绫诲瀷涓庡瓨鍌ㄨ繃绋嬪尮閰� ); if (Convert.ToInt32(checkResult.result) < 1) throw new Exception($"鍏ュ簱鏍¢獙澶辫触锛歿checkResult.strMsg}"); - //num = Db.Queryable<MesInvItemArn>() @@ -202,13 +196,15 @@ UseTransaction(db => { var existingRecord = db.Queryable<MesInvItemIns>() - .Where(it => it.InsDate.Value.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd") - && it.TaskNo == itemBarcodeDetails.BillNo - && it.Status == 0 - && it.TransctionNo == transactionNo - && it.CreateBy == entity.userName - && it.BillTypeId == billTypeId - && it.DepotsId == mesDepost.DepotId) + .Where(it => + it.InsDate.Value.ToString("yyyy-MM-dd") == + DateTime.Now.ToString("yyyy-MM-dd") + && it.TaskNo == itemBarcodeDetails.BillNo + && it.Status == 0 + && it.TransctionNo == transactionNo + && it.CreateBy == entity.userName + && it.BillTypeId == billTypeId + && it.DepotsId == mesDepost.DepotId) .Select(it => new { it.Guid, @@ -248,7 +244,10 @@ CreateDate = DateTime.Now, LastupdateBy = user, LastupdateDate = DateTime.Now, - UrgentFlag = itemBarcodeDetails.UrgentFlag.GetValueOrDefault() ? "1" : "0", + UrgentFlag = + itemBarcodeDetails.UrgentFlag.GetValueOrDefault() + ? "1" + : "0", CbillNo = itemBarcodeDetails.BillNo, Fstatus = 0, Status = 0, @@ -298,10 +297,10 @@ var count = db.Queryable<MesInvItemInCItems>() .Where(it => it.ItemInId == cId && - it.ItemId == detail.ItemId && - it.DepotId == mesDepost.DepotId.ToString() && - it.EbelnK3id == detail.EbelnK3id && - it.LineK3id == detail.LineK3id) + it.ItemId == detail.ItemId && + it.DepotId == mesDepost.DepotId.ToString() && + it.EbelnK3id == detail.EbelnK3id && + it.LineK3id == detail.LineK3id) .Count(); cSyQty -= remainingQty.Value; @@ -329,7 +328,8 @@ EbelnK3id = detail.EbelnK3id, LineK3id = detail.LineK3id, DepotId = mesDepost.DepotId.ToString(), - itemDabid = itemBarcodeDetails.AboutGuid.ToString() + itemDabid = itemBarcodeDetails.AboutGuid + .ToString() }).IgnoreColumns(true).ExecuteCommand(); else db.Updateable<MesInvItemInCItems>() @@ -338,7 +338,8 @@ .Where(it => it.ItemInId == cId && it.ItemId == detail.ItemId && - it.DepotId == mesDepost.DepotId.ToString() && + it.DepotId == + mesDepost.DepotId.ToString() && it.EbelnK3id == detail.EbelnK3id && it.LineK3id == detail.LineK3id) .IgnoreColumns(true) @@ -395,10 +396,10 @@ var count = db.Queryable<MesInvItemInCItems>() .Where(it => it.ItemInId == cId && - it.ItemId == detail.ItemId && - it.DepotId == mesDepost.DepotId.ToString() && - it.EbelnK3id == detail.EbelnK3id && - it.LineK3id == detail.LineK3id) + it.ItemId == detail.ItemId && + it.DepotId == mesDepost.DepotId.ToString() && + it.EbelnK3id == detail.EbelnK3id && + it.LineK3id == detail.LineK3id) .Count(); if (count == 0) @@ -433,7 +434,8 @@ .Where(it => it.ItemInId == cId && it.ItemId == detail.ItemId && - it.DepotId == mesDepost.DepotId.ToString() && + it.DepotId == + mesDepost.DepotId.ToString() && it.EbelnK3id == detail.EbelnK3id && it.LineK3id == detail.LineK3id) .IgnoreColumns(true) @@ -520,10 +522,10 @@ // 妫�鏌ユ槸鍚﹀瓨鍦ㄤ簬 MES_INV_ITEM_IN_C_ITEMS 琛� var existingCount = db.Queryable<MesInvItemInCItems>() .Where(it => - it.ItemInId == cId && - it.ItemId == detailone.ItemId && - it.DepotId == mesDepost.DepotId.ToString() && - it.itemDabid == itemBarcodeDetails.AboutGuid.ToString()) + it.ItemInId == cId && + it.ItemId == detailone.ItemId && + it.DepotId == mesDepost.DepotId.ToString() && + it.itemDabid == itemBarcodeDetails.AboutGuid.ToString()) .Count(); if (existingCount == 0) @@ -558,13 +560,16 @@ db.Updateable<MesInvItemInCItems>() .SetColumns(it => new MesInvItemInCItems { - Quantity = SqlFunc.IsNull(it.Quantity, 0) + itemBarcodeDetails.Quantity // 纭繚 Quantity 涓嶄负 null + Quantity = SqlFunc.IsNull(it.Quantity, 0) + + itemBarcodeDetails + .Quantity // 纭繚 Quantity 涓嶄负 null }) .Where(it => - it.ItemInId == cId && - it.ItemId == detailone.ItemId && - it.DepotId == mesDepost.DepotId.ToString() && - it.itemDabid == itemBarcodeDetails.AboutGuid.ToString()) + it.ItemInId == cId && + it.ItemId == detailone.ItemId && + it.DepotId == mesDepost.DepotId.ToString() && + it.itemDabid == + itemBarcodeDetails.AboutGuid.ToString()) //.IgnoreColumns(true) // 淇濈暀 IgnoreColumns .ExecuteCommand(); @@ -644,7 +649,6 @@ // 鎻掑叆 mes_inv_item_stocks 琛� } - db.Insertable(new MesInvItemStocks @@ -755,38 +759,45 @@ //result.Message = // $"鏉$爜鏁伴噺 {itemBarcodeDetails.Quantity},閲囪喘璁㈠崟 {itemBarcodeDetails.WorkNo} 椤规 {itemBarcodeDetails.WorkLine} 鐗╂枡 {mesItems.ItemNo} 鏈鍏ュ簱鎬绘暟锛歿totalCDetailsQuantity} 鎬诲埌 {comeQty} 宸插叆 {invQty} 娆� {diffQty}"; - result.Message = $"鐗╂枡{mesItems.ItemNo}鍏ュ簱鎴愬姛鏁伴噺{itemBarcodeDetails.Quantity.ToString()}"; + result.Message = + $"鐗╂枡{mesItems.ItemNo}鍏ュ簱鎴愬姛鏁伴噺{itemBarcodeDetails.Quantity.ToString()}"; result.itemDetail = mesItems; - result.ItemInDetails = db.Queryable<MesInvItemInCItems,MesItems>( - (a, b) => new JoinQueryInfos( - JoinType.Left, - a.ItemId == b.ItemId) + result.ItemInDetails = db + .Queryable<MesInvItemInCItems, MesItems>((a, b) => + new JoinQueryInfos( + JoinType.Left, + a.ItemId == b.ItemId) ) - .Where(a => a.ItemInId == cId && a.ItemId == itemBarcodeDetails.ItemId) - .Select<dynamic>((a, b) => new + .Where(a => + a.ItemInId == cId && + a.ItemId == itemBarcodeDetails.ItemId) + .Select<dynamic>((a, b) => new { - ItemNo = b.ItemNo, - ItemName = b.ItemName, - ItemModel = b.ItemModel, + b.ItemNo, + b.ItemName, + b.ItemModel, FQty = a.Quantity, // 鐢宠鏁伴噺 FMaterialId = b.ItemId, Id = b.Guid.ToString() }) .ToList(); - result.ItemBarCDetails = db.Queryable<MesInvItemInCDetails, MesItems>( - (a, b) => new JoinQueryInfos( - JoinType.Left, - a.ItemId == b.ItemId) + result.ItemBarCDetails = db + .Queryable<MesInvItemInCDetails, MesItems>((a, b) => + new JoinQueryInfos( + JoinType.Left, + a.ItemId == b.ItemId) ) - .Where(a => a.ItemInId == cId && a.ItemId == itemBarcodeDetails.ItemId) + .Where(a => + a.ItemInId == cId && + a.ItemId == itemBarcodeDetails.ItemId) .Select<dynamic>((a, b) => new { - ItemNo = b.ItemNo, - ItemName = b.ItemName, - ItemModel = b.ItemModel, + b.ItemNo, + b.ItemName, + b.ItemModel, FQty = a.Quantity, // 鐢宠鏁伴噺 FMaterialId = b.ItemId, Id = a.Guid.ToString(), @@ -864,15 +875,17 @@ // 鍒涘缓 鎻掑叆鏃ュ織 var logService = new LogService(); - var LogMsg = "銆怭DA銆戦噰璐叆搴撱�傛潯鐮併��" + entity.barcode + "銆� 鍏ュ簱鍗曞彿銆�" + cBillNo + "銆�"; - logService.CreateLog(db, entity.userName, inventory.Guid.ToString(), "MES_INV_ITEM_ARN", LogMsg, inventory.BillNo); + var LogMsg = "銆怭DA銆戦噰璐叆搴撱�傛潯鐮併��" + entity.barcode + "銆� 鍏ュ簱鍗曞彿銆�" + + cBillNo + "銆�"; + logService.CreateLog(db, entity.userName, inventory.Guid.ToString(), + "MES_INV_ITEM_ARN", LogMsg, inventory.BillNo); return 1; }); var purchaseInventory = getPurchaseInventory(entity); - + //result.ItemInDetails = purchaseInventory.ItemInDetails; //result.InvItemInCDetails = purchaseInventory.InvItemInCDetails; @@ -901,11 +914,11 @@ } var totalCount = 0; - var result = Db.Queryable<MesInvItemIns, MesDepots, MesSupplier>( - (a, b, c) => - new JoinQueryInfos(JoinType.Left, - a.DepotsId == b.DepotId, - JoinType.Left, a.SuppId == c.Id.ToString())) + var result = Db + .Queryable<MesInvItemIns, MesDepots, MesSupplier>((a, b, c) => + new JoinQueryInfos(JoinType.Left, + a.DepotsId == b.DepotId, + JoinType.Left, a.SuppId == c.Id.ToString())) .WhereIF(UtilityHelper.CheckGuid(parsedGuid), (a, b, c) => a.Guid == parsedGuid) .Select((a, b, c) => new MesInvItemIns @@ -937,8 +950,9 @@ if (!isValid) throw new ApplicationException("GUID杞崲閿欒"); - var result = Db.Queryable<MesInvItemInCDetails, MesItems, MesUnit>( - (g, c, d) => new JoinQueryInfos( + var result = Db + .Queryable<MesInvItemInCDetails, MesItems, MesUnit>((g, c, d) => + new JoinQueryInfos( JoinType.Left, g.ItemId == c.Id, JoinType.Inner, d.Id == Convert.ToDecimal(g.Unit) ) @@ -968,8 +982,9 @@ if (!isValid) throw new ApplicationException("GUID杞崲閿欒"); - var result = Db.Queryable<MesInvItemInCDetails, MesItems, MesUnit>( - (g, c, d) => new JoinQueryInfos( + var result = Db + .Queryable<MesInvItemInCDetails, MesItems, MesUnit>((g, c, d) => + new JoinQueryInfos( JoinType.Left, g.ItemId == c.Id, JoinType.Inner, d.Id.ToString() == c.Fpurchaseunitid @@ -1086,15 +1101,15 @@ if (invItemIns.Status == 1) throw new Exception("鍏ュ簱鍗曞凡瀹℃牳锛屼笉鑳介噸澶嶆帹閫�"); var materials = Db.Queryable<MesInvItemInCItems, MesItems, MesUnit, - MesInvItemArnDetail>( - (g, c, d, a) => new JoinQueryInfos( - JoinType.Left, - g.ItemId == c.Id, JoinType.Inner, - d.Id.ToString() == c.Fpurchaseunitid, - JoinType.Inner, a.Ebeln == g.WorkNo && g.CbillNo == a.CbillNo - ) - ).Where((g, c, d, a) => g.BillNo == billNo).Select<Material>( - (g, c, d, a) => new Material + MesInvItemArnDetail>((g, c, d, a) => new JoinQueryInfos( + JoinType.Left, + g.ItemId == c.Id, JoinType.Inner, + d.Id.ToString() == c.Fpurchaseunitid, + JoinType.Inner, + a.Ebeln == g.WorkNo && g.CbillNo == a.CbillNo + ) + ).Where((g, c, d, a) => g.BillNo == billNo) + .Select<Material>((g, c, d, a) => new Material { FMaterialId = c.ItemNo, FRealQty = g.Quantity.ToString(), -- Gitblit v1.9.3