From 0aa54059b26e6641196e9953490dd18616e916e3 Mon Sep 17 00:00:00 2001 From: 啊鑫 <t2856754968@163.com> Date: 星期三, 10 九月 2025 17:26:47 +0800 Subject: [PATCH] 精简修正代码 --- service/Warehouse/MesItemQtrkManager.cs | 252 +++++++++++++++++++++++++++++--------------------- 1 files changed, 145 insertions(+), 107 deletions(-) diff --git a/service/Warehouse/MesItemQtrkManager.cs b/service/Warehouse/MesItemQtrkManager.cs index 9eb138c..8c3615a 100644 --- a/service/Warehouse/MesItemQtrkManager.cs +++ b/service/Warehouse/MesItemQtrkManager.cs @@ -1,102 +1,107 @@ -锘縰sing NewPdaSqlServer.DB; +锘縰sing System.Text.RegularExpressions; +using NewPdaSqlServer.DB; using NewPdaSqlServer.Dto.service; using NewPdaSqlServer.entity; using NewPdaSqlServer.entity.Base; using NewPdaSqlServer.util; using SqlSugar; -using System.Text.RegularExpressions; namespace NewPdaSqlServer.service.Warehouse; public class MesItemQtrkManager : Repository<MesItemQtrk> { - public List<string> GetQtckList() + public dynamic GetQtckList(dynamic RequestInfo) { - //return Db.Queryable<MesItemQtrk>() - // .Where(x => (x.Qt015 ?? 0) == 1 && (x.Qt014 ?? 0) == 0) - // .Select(x => x.Qtck) - // .ToList(); + var orgId = RequestInfo.OrgId; - const string sql = @"SELECT qtck - FROM MES_ITEM_QTRK - WHERE QT015 = 1 AND QT028 = 1 AND QT032 = 1 - AND QT014 = 0 "; + if (orgId == null) + throw new Exception("缁勭粐涓嶅瓨鍦紒"); - return Db.Ado.SqlQuery<string>(sql); - } - - public ProductionPickDto GetQtckDetailList(WarehouseQuery query) - { - // 鍏宠仈鏌ヨ鐗╂枡琛ㄣ�佺墿鏂欐槑缁嗚〃鍜岀墿鏂欏熀纭�淇℃伅琛� - if (string.IsNullOrEmpty(query.billNo)) throw new Exception("鐢宠鍗曞彿涓虹┖"); - - var mesInvItemOuts = base.GetSingle(it => it.Qtck == query.billNo); - if (mesInvItemOuts == null) throw new Exception("鍏朵粬鍏ュ簱鐢宠鍗曚笉瀛樺湪"); - - var sql = @"SELECT c.item_no ItemNo,c.item_name ItemName,c.item_model ItemModel, - ISNULL(A.qd007,0) FQty,ISNULL(A.qd008,0) SQty,ISNULL(A.qd007,0) - ISNULL(A.qd008,0) DSQty - FROM MES_ITEM_QTRR_DETAIL A - LEFT JOIN MES_ITEM_QTRK B ON A.qtrkGuid = B.guid - LEFT JOIN MES_ITEMS C ON A.itemId = C.item_id - WHERE B.qtck = @billNo AND QT015 = 1 AND QT028 = 1 AND QT032 = 1 AND QT014 = 0 "; - - var sqlParams = new List<SugarParameter> { - new("@billNo", query.billNo) - }; - - var womdabs = Db.Ado.SqlQuery<ItemDetailModel>(sql, sqlParams); - - if (womdabs.Count < 1) - throw new Exception($"璇ュ叾浠栧叆搴撶敵璇峰崟 {query.billNo} 鏈叏閮ㄥ鏍告垨宸插畬缁擄紝璇风‘璁わ紒"); - - var DS_list = womdabs.Where(s => s.DSQty > 0).ToList(); - - var YS_list = womdabs.Where(s => s.SQty > 0).ToList(); - - var dto = new ProductionPickDto + // 鑾峰彇鏈畬鎴愮殑閫�鏂欏崟鍙峰垪琛� + var parameters = new[] { - //daa001 = womdaa.Daa001, - //PlanNo = womcaa.Caa020, - items = DS_list, - Ysitems = YS_list + new SugarParameter("@pi_orgId", orgId), + new SugarParameter("@inP1", null), + new SugarParameter("@inP2", null), + new SugarParameter("@inP3", null), + new SugarParameter("@inP4", null) }; - - return dto; + try + { + // 杩斿洖鍗曞彿瀛楃涓插垪琛� + var blDetails = Db.Ado.SqlQuery<string>( + "EXEC prc_pda_qtrk_list @pi_orgId,@inP1,@inP2,@inP3,@inP4", + parameters); + return blDetails; + } + catch (Exception ex) + { + throw new Exception($"{ex.Message}"); + } } - public string ScanInDepotsQT(WarehouseQuery query) + public dynamic GetQtckDetailList(dynamic query, dynamic RequestInfo) { - var sectionCode = query.sectionCode; + var orgId = RequestInfo.OrgId; + + if (orgId == null) + throw new Exception("缁勭粐涓嶅瓨鍦紒"); + + var parameters = new[] + { + new SugarParameter("@billNo", query.billNo), + new SugarParameter("@pi_orgId", orgId), + new SugarParameter("@inP1", null), + new SugarParameter("@inP2", null), + new SugarParameter("@inP3", null), + new SugarParameter("@inP4", null) + }; + try + { + var blDetails = Db.Ado.SqlQuery<dynamic>( + "EXEC prc_pda_qtrk_detailList @billNo,@pi_orgId,@inP1,@inP2,@inP3,@inP4", + parameters); + var items = blDetails.Where(x => x.DSQty > 0).ToList(); // 寰呮壂鐗╂枡 + var ysitems = blDetails.Where(x => x.SQty > 0).ToList(); // 宸叉壂鐗╂枡 + return new + { + items, ysitems + }; + } + catch (Exception ex) + { + // 淇濈暀鍘熸湁寮傚父澶勭悊閫昏緫 + throw new Exception($"{ex.Message}"); + } + } + + public dynamic ScanInDepotsQT(WarehouseQuery query) + { + var sectionCode = query.sectionCode; var billNo = query.billNo; // 1. 楠岃瘉搴撲綅鏉$爜鏄惁涓虹┖ if (string.IsNullOrEmpty(sectionCode)) throw new Exception("璇锋壂搴撲綅鏉$爜锛�"); - // 2. 鏌ヨ搴撲綅瀵瑰簲鐨勪粨搴撶紪鐮� - var depotId = Db.Queryable<MesDepotSections, MesDepots>( - (a, b) => new JoinQueryInfos( - JoinType.Inner, a.DepotGuid == b.Guid)) - .Where((a, b) => a.DepotSectionCode == sectionCode) - .Select((a, b) => b.DepotId) - .First(); + var sqlParams = new List<SugarParameter> + { new("@sectionCode", sectionCode) }; - if (depotId == null) + var sql2 = @" SELECT TOP 1 b.depot_code, + b.depot_id, + B.FSubsidiary, + B.depot_name + FROM MES_DEPOT_SECTIONS a + INNER JOIN + MES_DEPOTS b ON a.depot_guid = b.Guid + WHERE a.depot_section_code = @sectionCode;"; + + var depotInfo = Db.Ado.SqlQuery<dynamic>(sql2, sqlParams).First(); + + if (depotInfo is null) throw new Exception($"搴撲綅缂栫爜 {sectionCode} 涓嶅瓨鍦紝璇风‘璁わ紒"); - // 3. 鏌ヨ鐢宠鍗曞搴旂殑浠撳簱 - var qtrk = Db.Queryable<MesItemQtrk>() - .Where(x => x.Qtck == billNo) - .Select(x => x.Qt008) - .First(); - - if (qtrk == null) throw new Exception($"搴撲綅缂栫爜 {sectionCode} 涓嶅瓨鍦紝璇风‘璁わ紒"); - - // 4. 楠岃瘉搴撲綅鏄惁灞炰簬鐢宠浠撳簱 - if (depotId != Convert.ToInt32(qtrk)) - throw new Exception($"鎵爜搴撲綅 {sectionCode} 涓嶅睘浜庣敵璇蜂粨搴�!"); - // 5. 杩斿洖鎴愬姛淇℃伅 - return $"浠撳簱锛歿qtrk} 搴撲綅锛歿sectionCode}"; + return depotInfo; } public (WarehouseQuery form, List<MesItemQtrrDetail> item) @@ -115,9 +120,8 @@ throw new Exception("璇锋壂搴撲綅鏉$爜锛�"); // 2. 鏌ヨ搴撲綅瀵瑰簲鐨勪粨搴撶紪鐮佸拰浠撳簱ID - var depotInfo = Db.Queryable<MesDepotSections, MesDepots>( - (a, b) => - new JoinQueryInfos(JoinType.Inner, a.DepotGuid == b.Guid)) + var depotInfo = Db.Queryable<MesDepotSections, MesDepots>((a, b) => + new JoinQueryInfos(JoinType.Inner, a.DepotGuid == b.Guid)) .Where((a, b) => a.DepotSectionCode == p_section_code) .Select((a, b) => new { b.DepotCode, b.DepotId }) .First(); @@ -128,11 +132,21 @@ var c_depot_code = depotInfo.DepotCode; var c_depot_id = depotInfo.DepotId; + var sqlParams = new List<SugarParameter> + { new("@barcode", p_item_barcode), new("@billNo", p_bill_no) }; + +// var sql1 = @" SELECT TOP 1 A.rkCkId +//FROM MES_QA_ITEMS_DETECT_01 A +// LEFT JOIN MES_INV_ITEM_BARCODES B ON A.item_id = B.ITEM_ID +//WHERE order_type = '鍏跺畠鍏ュ簱妫�' +// AND A.lot_no = @billNo +// AND ITEM_BARCODE = @barcode "; + +// var appDepotInfo = Db.Ado.SqlQuery<dynamic>(sql1, sqlParams).First(); + + var mesDepost = Db.Queryable<MesDepots>() - .Where(s => s.DepotId == c_depot_id).First(); - - - + .Where(s => s.DepotId == c_depot_id).First(); // 3. 楠岃瘉鏉$爜鏄惁宸插叆搴� @@ -164,9 +178,35 @@ if (qtrk == null) throw new Exception("鍏朵粬鍏ュ簱鐢宠鍗曚笉瀛樺湪锛�"); - // 楠岃瘉搴撲綅鏄惁灞炰簬鐢宠浠撳簱 - if (c_depot_id != Convert.ToInt32(qtrk.Qt008)) - throw new Exception($"鎵爜搴撲綅 {p_section_code} 涓嶅睘浜庣敵璇蜂粨搴�!"); + if (p_bill_no != barcode.BillNo) + throw new Exception($"璇ユ潯鐮佸搴旂殑鐢宠鍗曘�恵barcode.BillNo}銆戜笌褰撳墠鐢宠鍗曞彿涓嶅尮閰嶏紒"); + + if (qtrk.Qt008 != c_depot_id.ToString()) + throw new Exception( + $"璇� {p_section_code} 瀵瑰簲鐨勪粨搴� 涓� 妫�楠屽垽瀹氱殑鍏ュ簱浠撳簱涓嶄竴鑷达紝璇风‘璁わ紒"); + + var sql = + @"SELECT c.item_no ItemNo,c.item_name ItemName,c.item_model ItemModel, + ISNULL(A.qd007,0) FQty,ISNULL(A.qd008,0) SQty,ISNULL(A.qd007,0) - ISNULL(A.qd008,0) DSQty + FROM MES_ITEM_QTRR_DETAIL A + LEFT JOIN MES_ITEM_QTRK B ON A.qtrkGuid = B.guid + LEFT JOIN MES_ITEMS C ON A.itemId = C.item_id + WHERE B.qtck = @billNo AND QT015 = 1 AND QT028 = 1 AND QT032 = 1 AND QT014 = 0 "; + //AND QT014 = 0 + + var sqlParams1 = new List<SugarParameter> + { + new("@billNo", p_bill_no) + }; + + var womdabs = Db.Ado.SqlQuery<ItemDetailModel>(sql, sqlParams1); + + if (womdabs.Count < 1) + throw new Exception($"璇ュ叾浠栧叆搴撶敵璇峰崟 {query.billNo} 鏈叏閮ㄥ鏍告垨宸插畬缁擄紝璇风‘璁わ紒"); + + //// 楠岃瘉搴撲綅鏄惁灞炰簬鐢宠浠撳簱 + //if (c_depot_id != Convert.ToInt32(qtrk.Qt008)) + // throw new Exception($"鎵爜搴撲綅 {p_section_code} 涓嶅睘浜庣敵璇蜂粨搴�!"); // 6. 鏌ヨ鐢宠鍗曟槑缁� var detail = Db.Queryable<MesItemQtrrDetail>() @@ -184,20 +224,15 @@ var details = new List<MesItemQtrrDetail>(); - string pattern = @"\(([^)]+)\)"; - Match match = Regex.Match(qtrk.Qt023, pattern); + var pattern = @"\(([^)]+)\)"; + var match = Regex.Match(qtrk.Qt023, pattern); var owner_type = ""; // 8.鑾峰彇璐т富绫诲瀷 if (match.Success) - { owner_type = match.Groups[1].Value; - } else - { throw new Exception("鍏朵粬鍏ュ簱鐢宠鍗曡揣涓荤被鍨嬫湁璇�,璇锋牳瀵癸紒"); - } - // 10. 鎵ц鍏ュ簱浜嬪姟 @@ -207,14 +242,15 @@ // 鏌ヨ鏄惁瀛樺湪鏈叆搴撶殑鍏ュ簱鍗� var existingInv = db.Queryable<MesInvItemIns>() .Where(x => x.Status == 0 - && x.InsDate.Value.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd") + && x.InsDate.Value.ToString("yyyy-MM-dd") == + DateTime.Now.ToString("yyyy-MM-dd") && x.TransctionNo == transactionNo.ToString() && x.TaskNo == p_bill_no //&& x.CbillNo == p_bill_no && x.BillTypeId == billTypeId && x.DepotsId == Convert.ToInt64(c_depot_id)) - // && x.DepotsCode == c_depot_code) - //&& x.SuppNo == barcode.SuppNo) + // && x.DepotsCode == c_depot_code) + //&& x.SuppNo == barcode.SuppNo) .First(); var newId = Guid.Empty; @@ -246,10 +282,9 @@ Status = 0, Reason = qtrk.Qt010, TaskNo = p_bill_no, - DepotsId = Convert.ToInt64(c_depot_id) , + DepotsId = Convert.ToInt64(c_depot_id), InType = "鍏朵粬鍏ュ簱", ReceiveOrgId = qtrk.Qt022 - }).IgnoreColumns(true).ExecuteCommand(); } else @@ -263,7 +298,7 @@ .Where(x => x.ItemInId == newId && x.ItemId == barcode.ItemId && x.DepotId == c_depot_id.ToString() - ) + ) //&& x.DepotCode = .First(); @@ -294,16 +329,16 @@ LineK3id = barcode.LineK3id, ItemId = barcode.ItemId, DepotId = c_depot_id.ToString(), - itemDabid = barcode.AboutGuid.ToString(), + itemDabid = barcode.AboutGuid.ToString() }).IgnoreColumns(true).ExecuteCommand(); else // 瀛樺湪鍒欐洿鏂版暟閲� res += db.Updateable<MesInvItemInCItems>() - .SetColumns( - x => x.Quantity == x.Quantity + barcode.Quantity) + .SetColumns(x => + x.Quantity == x.Quantity + barcode.Quantity) .Where(x => x.ItemInId == newId - && x.ItemId == barcode.ItemId - && x.DepotId == c_depot_id.ToString()) + && x.ItemId == barcode.ItemId + && x.DepotId == c_depot_id.ToString()) .ExecuteCommand(); @@ -429,7 +464,7 @@ res += db.Updateable<MesItemQtrrDetail>() .SetColumns(x => x.Qd008 == (x.Qd008 ?? 0) + barcode.Quantity) .Where(x => x.QtrkGuid == qtrk.Guid && - x.ItemId == barcode.ItemId.ToString()) + x.ItemId == barcode.ItemId.ToString()) .ExecuteCommand(); // 妫�鏌ユ槸鍚﹀畬鍏ㄥ叆搴撳苟鏇存柊鐘舵�� @@ -443,10 +478,11 @@ .Where(x => x.Guid == detail1.Guid) .ExecuteCommand(); - details = Db.Queryable<MesItemQtrk, MesItemQtrrDetail, MesItems>( - (a, b, c) => new JoinQueryInfos( - JoinType.Left, a.Guid == b.QtrkGuid, - JoinType.Left, c.Id.ToString() == b.ItemId)) + details = Db + .Queryable<MesItemQtrk, MesItemQtrrDetail, + MesItems>((a, b, c) => new JoinQueryInfos( + JoinType.Left, a.Guid == b.QtrkGuid, + JoinType.Left, c.Id.ToString() == b.ItemId)) .Where((a, b, c) => a.Qtck == p_bill_no && (b.Qd007 ?? 0) - (b.Qd008 ?? 0) > 0) @@ -469,8 +505,10 @@ // 鍒涘缓 鎻掑叆鏃ュ織 var logService = new LogService(); - var LogMsg = "銆怭DA銆戝叾浠栧叆搴撱�傛潯鐮併��" + query.barcode + "銆戞暟閲忋��" + barcode.Quantity.ToString() + "銆� 鍏ュ簱鍗曞彿銆�" + billNo + "銆�"; - logService.CreateLog(db, query.userName, qtrk.Guid.ToString(), "MES_ITEM_QTRK", LogMsg, qtrk.Qtck); + var LogMsg = "銆怭DA銆戝叾浠栧叆搴撱�傛潯鐮併��" + query.barcode + "銆戞暟閲忋��" + + barcode.Quantity + "銆� 鍏ュ簱鍗曞彿銆�" + billNo + "銆�"; + logService.CreateLog(db, query.userName, qtrk.Guid.ToString(), + "MES_ITEM_QTRK", LogMsg, qtrk.Qtck); if (res < 5) throw new Exception("鎻掑叆鎴栨洿鏂板け璐�"); -- Gitblit v1.9.3