From 4f8d1da89bc7cf399e6d90d6230ad6c28114443a Mon Sep 17 00:00:00 2001 From: 南骏 池 <chiffly@163.com> Date: 星期一, 23 六月 2025 11:20:13 +0800 Subject: [PATCH] 1.采购入库优化 2.采购退货推荐库位优化 --- service/Warehouse/MesItemQtrkManager.cs | 237 +++++++++++++++++++++++++++++++---------------------------- 1 files changed, 125 insertions(+), 112 deletions(-) diff --git a/service/Warehouse/MesItemQtrkManager.cs b/service/Warehouse/MesItemQtrkManager.cs index c6baffe..9eb138c 100644 --- a/service/Warehouse/MesItemQtrkManager.cs +++ b/service/Warehouse/MesItemQtrkManager.cs @@ -1,8 +1,10 @@ 锘縰sing 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; @@ -10,90 +12,88 @@ { public List<string> GetQtckList() { - return Db.Queryable<MesItemQtrk>() - .Where(x => (x.Qt015 ?? 0) == 1 && (x.Qt014 ?? 0) == 0) - .Select(x => x.Qtck) - .ToList(); + //return Db.Queryable<MesItemQtrk>() + // .Where(x => (x.Qt015 ?? 0) == 1 && (x.Qt014 ?? 0) == 0) + // .Select(x => x.Qtck) + // .ToList(); + + const string sql = @"SELECT qtck + FROM MES_ITEM_QTRK + WHERE QT015 = 1 AND QT028 = 1 AND QT032 = 1 + AND QT014 = 0 "; + + return Db.Ado.SqlQuery<string>(sql); } - public List<MesItemQtrrDetail> GetQtckDetailList(WarehouseQuery query) + public ProductionPickDto GetQtckDetailList(WarehouseQuery query) { - // 1. 楠岃瘉鐢宠鍗曟槸鍚﹀瓨鍦� - var qtrk = Db.Queryable<MesItemQtrk>() - .Where(x => x.Qtck == query.billNo) - .First(); - if (qtrk == null) - throw new Exception($"鏈煡璇㈠埌姝ゅ叾浠栧叆搴撶敵璇峰崟 {query.billNo}"); + // 鍏宠仈鏌ヨ鐗╂枡琛ㄣ�佺墿鏂欐槑缁嗚〃鍜岀墿鏂欏熀纭�淇℃伅琛� + if (string.IsNullOrEmpty(query.billNo)) throw new Exception("鐢宠鍗曞彿涓虹┖"); - // 2. 楠岃瘉鐢宠鍗曠姸鎬� - if (qtrk.Qt015 != 1) - throw new Exception($"鍏朵粬鍏ュ簱鐢宠鍗� {query.billNo} 鏈鏍革紝璇风‘璁わ紒"); + var mesInvItemOuts = base.GetSingle(it => it.Qtck == query.billNo); + if (mesInvItemOuts == null) throw new Exception("鍏朵粬鍏ュ簱鐢宠鍗曚笉瀛樺湪"); - if (qtrk.Qt014 == 1) - throw new Exception($"鍏朵粬鍏ュ簱鐢宠鍗� {query.billNo} 宸插畬缁擄紝璇风‘璁わ紒"); + 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 "; - // 3. 鏌ヨ鐢宠鍗曟槑缁� - var 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 == query.billNo && - (b.Qd007 ?? 0) - (b.Qd008 ?? 0) > 0) - .OrderBy((a, b, c) => b.Qd002) - .Select((a, b, c) => new MesItemQtrrDetail - { - Qtck = a.Qtck, - ItemNo = c.ItemNo, - ItemName = c.ItemName, - Qd007 = b.Qd007 ?? 0, - Qd008 = b.Qd008 ?? 0 - }) - .ToList(); + var sqlParams = new List<SugarParameter> { + new("@billNo", query.billNo) + }; - return details; + 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 + { + //daa001 = womdaa.Daa001, + //PlanNo = womcaa.Caa020, + items = DS_list, + Ysitems = YS_list + }; + + return dto; } - public String ScanInDepotsQT(WarehouseQuery query) + public string ScanInDepotsQT(WarehouseQuery query) { - var sectionCode = query.sectionCode; + var sectionCode = query.sectionCode; var billNo = query.billNo; // 1. 楠岃瘉搴撲綅鏉$爜鏄惁涓虹┖ - if (string.IsNullOrEmpty(sectionCode)) - { - throw new Exception("璇锋壂搴撲綅鏉$爜锛�"); - } + if (string.IsNullOrEmpty(sectionCode)) throw new Exception("璇锋壂搴撲綅鏉$爜锛�"); // 2. 鏌ヨ搴撲綅瀵瑰簲鐨勪粨搴撶紪鐮� - var depotCode = Db.Queryable<MesDepotSections, MesDepots>( + 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.DepotCode) + .Select((a, b) => b.DepotId) .First(); - if (depotCode == null) - { + if (depotId == null) throw new Exception($"搴撲綅缂栫爜 {sectionCode} 涓嶅瓨鍦紝璇风‘璁わ紒"); - } // 3. 鏌ヨ鐢宠鍗曞搴旂殑浠撳簱 var qtrk = Db.Queryable<MesItemQtrk>() .Where(x => x.Qtck == billNo) - .Select(x => x.Qt011) + .Select(x => x.Qt008) .First(); - if (qtrk == null) - { - throw new Exception($"搴撲綅缂栫爜 {sectionCode} 涓嶅瓨鍦紝璇风‘璁わ紒"); - } + if (qtrk == null) throw new Exception($"搴撲綅缂栫爜 {sectionCode} 涓嶅瓨鍦紝璇风‘璁わ紒"); // 4. 楠岃瘉搴撲綅鏄惁灞炰簬鐢宠浠撳簱 - if (depotCode != qtrk) - { - throw new Exception($"鎵爜搴撲綅 {sectionCode} 涓嶅睘浜庣敵璇锋浠撳簱!"); - } + if (depotId != Convert.ToInt32(qtrk)) + throw new Exception($"鎵爜搴撲綅 {sectionCode} 涓嶅睘浜庣敵璇蜂粨搴�!"); // 5. 杩斿洖鎴愬姛淇℃伅 return $"浠撳簱锛歿qtrk} 搴撲綅锛歿sectionCode}"; @@ -112,9 +112,7 @@ // 1. 楠岃瘉搴撲綅鏉$爜鏄惁涓虹┖ if (string.IsNullOrEmpty(p_section_code)) - { throw new Exception("璇锋壂搴撲綅鏉$爜锛�"); - } // 2. 鏌ヨ搴撲綅瀵瑰簲鐨勪粨搴撶紪鐮佸拰浠撳簱ID var depotInfo = Db.Queryable<MesDepotSections, MesDepots>( @@ -125,56 +123,50 @@ .First(); if (depotInfo == null) - { throw new Exception($"搴撲綅缂栫爜 {p_section_code} 涓嶅瓨鍦紝璇风‘璁わ紒"); - } var c_depot_code = depotInfo.DepotCode; var c_depot_id = depotInfo.DepotId; + + var mesDepost = Db.Queryable<MesDepots>() + .Where(s => s.DepotId == c_depot_id).First(); + + + + // 3. 楠岃瘉鏉$爜鏄惁宸插叆搴� var existsInStock = Db.Queryable<MesInvItemInCDetails>() .Any(x => x.ItemBarcode == p_item_barcode); - if (existsInStock) - { - throw new Exception("姝ゆ潯鐮佸凡鎵爜鍏ュ簱瀹屾垚,璇锋牳瀵癸紒"); - } + if (existsInStock) throw new Exception("姝ゆ潯鐮佸凡鎵爜鍏ュ簱瀹屾垚,璇锋牳瀵癸紒"); // 4. 鏌ヨ鏉$爜淇℃伅 var barcode = Db.Queryable<MesInvItemBarcodes>() .Where(x => x.ItemBarcode == p_item_barcode) .First(); - if (barcode == null) - { - throw new Exception("鏉$爜涓嶅瓨鍦�,璇锋牳瀵癸紒"); - } + if (barcode == null) throw new Exception("鏉$爜涓嶅瓨鍦�,璇锋牳瀵癸紒"); - if (barcode.ComeFlg != 3) - { - throw new Exception("鏉$爜涓嶆槸鍏朵粬鍏ュ簱鏉$爜,鏃犳硶鐢ㄥ叾浠栧叆搴擄紒"); - } + //if (barcode.ComeFlg != 3) throw new Exception("鏉$爜涓嶆槸鍏朵粬鍏ュ簱鏉$爜,鏃犳硶鐢ㄥ叾浠栧叆搴擄紒"); // 楠岃瘉鏉$爜鏄惁宸插湪搴撳瓨涓� var stockCount = Db.Queryable<MesInvItemStocks>() .Where(x => x.ItemBarcode == p_item_barcode) .Count(); - if (stockCount > 0) - { - throw new Exception("姝ゆ潯鐮佸凡鎵爜鍏ュ簱瀹屾垚,璇锋牳瀵癸紒"); - } + if (stockCount > 0) throw new Exception("姝ゆ潯鐮佸凡鎵爜鍏ュ簱瀹屾垚,璇锋牳瀵癸紒"); // 5. 鏌ヨ鍏朵粬鍏ュ簱鐢宠鍗� var qtrk = Db.Queryable<MesItemQtrk>() .Where(x => x.Qtck == p_bill_no) .First(); - if (qtrk == null) - { - throw new Exception("鍏朵粬鍏ュ簱鐢宠鍗曚笉瀛樺湪锛�"); - } + if (qtrk == null) throw new Exception("鍏朵粬鍏ュ簱鐢宠鍗曚笉瀛樺湪锛�"); + + // 楠岃瘉搴撲綅鏄惁灞炰簬鐢宠浠撳簱 + if (c_depot_id != Convert.ToInt32(qtrk.Qt008)) + throw new Exception($"鎵爜搴撲綅 {p_section_code} 涓嶅睘浜庣敵璇蜂粨搴�!"); // 6. 鏌ヨ鐢宠鍗曟槑缁� var detail = Db.Queryable<MesItemQtrrDetail>() @@ -184,30 +176,45 @@ .First(); if (detail == null) - { throw new Exception($"鍏朵粬鍏ュ簱鐢宠鍗晎p_bill_no}鏃犳鐗╂枡{barcode.ItemNo} 璇锋牳瀵癸紒"); - } // 7. 楠岃瘉鏁伴噺 if (barcode.Quantity > (detail.Qd007 ?? 0) - (detail.Qd008 ?? 0)) - { throw new Exception("鏉$爜鏁伴噺瓒呰繃鐢宠鏁伴噺,璇锋牳瀵癸紒"); - } var details = new List<MesItemQtrrDetail>(); - // 8. 鎵ц鍏ュ簱浜嬪姟 + string pattern = @"\(([^)]+)\)"; + Match match = Regex.Match(qtrk.Qt023, pattern); + var owner_type = ""; + + // 8.鑾峰彇璐т富绫诲瀷 + if (match.Success) + { + owner_type = match.Groups[1].Value; + } + else + { + throw new Exception("鍏朵粬鍏ュ簱鐢宠鍗曡揣涓荤被鍨嬫湁璇�,璇锋牳瀵癸紒"); + } + + + + // 10. 鎵ц鍏ュ簱浜嬪姟 UseTransaction(db => { var res = 0; // 鏌ヨ鏄惁瀛樺湪鏈叆搴撶殑鍏ュ簱鍗� var existingInv = db.Queryable<MesInvItemIns>() .Where(x => x.Status == 0 + && x.InsDate.Value.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd") && x.TransctionNo == transactionNo.ToString() - && x.CbillNo == p_bill_no - && x.SuppNo == barcode.SuppNo + && 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.DepotsId == c_depot_id) + //&& x.SuppNo == barcode.SuppNo) .First(); var newId = Guid.Empty; @@ -216,7 +223,7 @@ if (existingInv == null) { newId = Guid.NewGuid(); - billNo = BillNo.GetBillNo("INV_IN_OTHER"); + billNo = BillNo.GetBillNo("QTRK(鍏朵粬鍏ュ簱)"); barcode.UrgentFlag ??= false; @@ -233,11 +240,16 @@ CreateDate = DateTime.Now, LastupdateBy = c_user, LastupdateDate = DateTime.Now, - UrgentFlag = barcode.UrgentFlag.Value ? (byte)1 : (byte)0, - CbillNo = p_bill_no, + UrgentFlag = barcode.UrgentFlag.Value ? "1" : "0", + //CbillNo = p_bill_no, Fstatus = 0, Status = 0, - Reason = qtrk.Qt010 + Reason = qtrk.Qt010, + TaskNo = p_bill_no, + DepotsId = Convert.ToInt64(c_depot_id) , + InType = "鍏朵粬鍏ュ簱", + ReceiveOrgId = qtrk.Qt022 + }).IgnoreColumns(true).ExecuteCommand(); } else @@ -250,12 +262,12 @@ var existingItem = db.Queryable<MesInvItemInCItems>() .Where(x => x.ItemInId == newId && x.ItemId == barcode.ItemId - && x.WorkNo == barcode.WorkNo - && x.WorkLine == barcode.WorkLine) + && x.DepotId == c_depot_id.ToString() + ) + //&& x.DepotCode = .First(); if (existingItem == null) - { // 涓嶅瓨鍦ㄥ垯鏂板鍏ュ簱鏄庣粏 res += db.Insertable(new MesInvItemInCItems { @@ -280,21 +292,19 @@ Remark = barcode.Memo, EbelnK3id = barcode.EbelnK3id, LineK3id = barcode.LineK3id, - ItemId = barcode.ItemId + ItemId = barcode.ItemId, + DepotId = c_depot_id.ToString(), + itemDabid = barcode.AboutGuid.ToString(), }).IgnoreColumns(true).ExecuteCommand(); - } else - { // 瀛樺湪鍒欐洿鏂版暟閲� res += db.Updateable<MesInvItemInCItems>() .SetColumns( x => x.Quantity == x.Quantity + barcode.Quantity) .Where(x => x.ItemInId == newId - && x.ItemId == barcode.ItemId - && x.WorkNo == barcode.WorkNo - && x.WorkLine == barcode.WorkLine) + && x.ItemId == barcode.ItemId + && x.DepotId == c_depot_id.ToString()) .ExecuteCommand(); - } // 鎻掑叆鍏ュ簱鏄庣粏璁板綍 @@ -311,7 +321,7 @@ LotNo = barcode.LotNo, SuppId = barcode.SuppId, SuppNo = barcode.SuppNo, - DepotId = c_depot_id, + DepotId = Convert.ToInt64(c_depot_id), DepotCode = c_depot_code, DepotSectionCode = p_section_code, ItemSname = barcode.ItemSname, @@ -366,7 +376,7 @@ SuppNo = barcode.SuppNo, EbelnK3id = barcode.EbelnK3id, LineK3id = barcode.LineK3id, - ItemId = barcode.ItemId, + ItemId = barcode.ItemId // SalesOrder = barcode.SalesOrder, // IsZy = barcode.IsZy, // OuterBarcode = barcode.OuterBarcode @@ -399,6 +409,10 @@ LineK3id = barcode.LineK3id, ItemId = barcode.ItemId, BillNo = barcode.BillNo, + OwnerId = qtrk.Qt024, + OwnerType = owner_type, + StockOrgId = qtrk.Qt022, + IndepUserCode = c_user // SalesOrder = barcode.SalesOrder, // IsZy = barcode.IsZy, // Visable = 0, @@ -414,7 +428,8 @@ // 鏇存柊鐢宠鍗曟槑缁嗗凡鍏ュ簱鏁伴噺 res += db.Updateable<MesItemQtrrDetail>() .SetColumns(x => x.Qd008 == (x.Qd008 ?? 0) + barcode.Quantity) - .Where(x => x.Guid == barcode.Guid) + .Where(x => x.QtrkGuid == qtrk.Guid && + x.ItemId == barcode.ItemId.ToString()) .ExecuteCommand(); // 妫�鏌ユ槸鍚﹀畬鍏ㄥ叆搴撳苟鏇存柊鐘舵�� @@ -423,12 +438,10 @@ .First(); if ((detail1.Qd007 ?? 0) - (detail1.Qd008 ?? 0) == barcode.Quantity) - { res += db.Updateable<MesItemQtrrDetail>() .SetColumns(x => x.Qd011 == 1) .Where(x => x.Guid == detail1.Guid) .ExecuteCommand(); - } details = Db.Queryable<MesItemQtrk, MesItemQtrrDetail, MesItems>( (a, b, c) => new JoinQueryInfos( @@ -449,17 +462,17 @@ .ToList(); if (CollectionUtil.IsNullOrEmpty(details)) - { res += db.Updateable<MesItemQtrk>() .SetColumns(s => s.Qt014 == 1) .Where(x => x.Qtck == p_bill_no) .ExecuteCommand(); - } - if (res < 5) - { - throw new Exception("鎻掑叆鎴栨洿鏂板け璐�"); - } + // 鍒涘缓 鎻掑叆鏃ュ織 + 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); + + if (res < 5) throw new Exception("鎻掑叆鎴栨洿鏂板け璐�"); return res; }); -- Gitblit v1.9.3