From 8276722de62e0be1e68adf65f150686a236268bd Mon Sep 17 00:00:00 2001 From: zjh <2207896513@qq.com> Date: 星期五, 18 七月 2025 10:08:44 +0800 Subject: [PATCH] 产测接口代码提交 --- StandardPda/MES.Service/service/Warehouse/MesInvItemOutsManager.cs | 369 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 369 insertions(+), 0 deletions(-) diff --git a/StandardPda/MES.Service/service/Warehouse/MesInvItemOutsManager.cs b/StandardPda/MES.Service/service/Warehouse/MesInvItemOutsManager.cs new file mode 100644 index 0000000..790677b --- /dev/null +++ b/StandardPda/MES.Service/service/Warehouse/MesInvItemOutsManager.cs @@ -0,0 +1,369 @@ +锘縰sing MES.Service.DB; +using MES.Service.Dto.service; +using MES.Service.Modes; + +namespace MES.Service.service.Warehouse; + +public class MesInvItemOutsManager : Repository<MesInvItemOuts> +{ + private readonly int BILL_TYPE_ID = 200; + private readonly int TRANSACTION_NO = 203; + + public bool ReturnRequest(ItemOut oItemOut) + { + var itemOutFrom = oItemOut.from; + var itemOutLists = oItemOut.items; + + // 鏍规嵁AsnNo鍜孧esNo瀵规槑缁嗚繘琛屽垎缁� + var groupedItems = itemOutLists + .GroupBy(item => new { item.MesNo, item.SqNo }) + .ToList(); + + bool result = true; + foreach (var group in groupedItems) + { + //if (group.Key.AsnNo == null) + //{ + // throw new NotImplementedException("AsnNo涓嶈兘涓虹┖"); + //} + + if (group.Key.MesNo == null) + { + throw new NotImplementedException("鍏ュ簱鍗曞崟鍙蜂笉鑳戒负绌�"); + } + + if (group.Key.SqNo == null) + { + throw new NotImplementedException("閫�璐х敵璇峰崟琛屽彿涓嶈兘涓虹┖"); + } + + // 鍒涘缓涓�涓复鏃剁殑itemOutFrom瀵硅薄锛屼娇鐢ㄥ垎缁勭殑Key浣滀负涓昏灞炴�� + var tempItemOutFrom = new ItemOutFrom + { + + MesNo = group.Key.MesNo, + SqNo = group.Key.SqNo, + // 缁ф壙鍘熷itemOutFrom鐨勫叾浠栧睘鎬� + RtnNo = itemOutFrom.RtnNo, + Type = itemOutFrom.Type, + CreateBy = itemOutFrom.CreateBy, + FMRMODE = itemOutFrom.FMRMODE, + DepotId = itemOutFrom.DepotId, + SupperId = itemOutFrom.SupperId + }; + + // 鏍规嵁Type鎵ц涓嶅悓鐨勯�昏緫 + switch (tempItemOutFrom.Type) + { + case "1": + { + var mesInvItemOuts = Db.Queryable<MesInvItemOuts>() + .Where(s => s.BillTypeId == BILL_TYPE_ID + && s.TransactionNo == TRANSACTION_NO + && s.ItemOutNo == tempItemOutFrom.RtnNo + + ) + .Count(); + + if (mesInvItemOuts > 0) + { + throw new NotImplementedException( + tempItemOutFrom.RtnNo + + "鐨勯��鏂欑敵璇峰崟宸茬粡瀛樺湪"); + } + + // 涓哄綋鍓嶅垎缁勪繚瀛樻暟鎹� + var groupResult = Save(tempItemOutFrom, group.ToList()); + if (!groupResult) + { + result = false; + } + + break; + } + case "4": + var removeResult = Remove(tempItemOutFrom); + if (!removeResult) + { + result = false; + } + + break; + default: + result = false; + break; + } + } + + return result; + } + + private bool Save(ItemOutFrom from, List<ItemOutList> items) + { + var mesInvItemIns = Db.Queryable<MesInvItemIns>() + .Where(s => s.BillTypeId == 100 + && s.TransctionNo == "101" + && s.BillNo == from.MesNo + ).First(); + + if (mesInvItemIns == null) + { + throw new NotImplementedException("閲囪喘鍏ュ簱涓嶅瓨鍦�"); + } + + var mesDepots = Db.Queryable<MesDepots>() + .Where(s => s.DepotId == Decimal.Parse(from.DepotId)).First(); + + var mesLinkU9 = Db.Queryable<MesLinkU9>() + .Where(s => s.TableType == "MES_SUPPLIER" + && s.U9Id == from.SupperId).First(); + + if (mesLinkU9 == null) + { + throw new NotImplementedException("渚涘簲鍟咺D涓嶅瓨鍦ㄦ垨鏈悓姝ヤ簬U9"); + } + + var mesSupplier = Db.Queryable<MesSupplier>() + .Where(s => s.Id == Decimal.Parse(mesLinkU9.MesId)) + .First(); + + if (mesDepots == null) + { + throw new NotImplementedException("[" + from.DepotId + + "]浠撳簱涓嶅瓨鍦紝璇峰悓姝ョ粰MES"); + } + + if (mesSupplier == null) + { + throw new NotImplementedException("[" + from.SupperId + + "]渚涘簲鍟嗕笉瀛樺湪锛岃鍚屾缁橫ES"); + } + + var nextSequenceValue = + Db.Ado.SqlQuery<decimal>("SELECT SEQ_OUT_ID.NEXTVAL FROM DUAL") + .First(); + + // var billCode = + // Db.Ado.SqlQuery<string>( + // "SELECT GETBILLCODE1('1000', '1000', 'TLSQ') FROM DUAL") + // .First(); + var billCode = from.RtnNo; + + // 鍒涘缓閲囪喘閫�鏂欏崟璁板綍 + var mesInvItemOuts = new MesInvItemOuts + { + Id = nextSequenceValue, + ItemOutNo = billCode, + Status = 0, + CreateBy = "PL017", + CreateDate = DateTime.Now, + BillTypeId = 200, + TransactionNo = 203, + DepotCode = mesDepots.DepotCode, + FType = 0, + OutStatus = 0, + IsVisual = 1, + Factory = "1000", + Company = "1000", + SuppNo = mesSupplier.SuppNo, + ItemFlag = 0, + BoardFlag = 0, + OutType = "閲囪喘閫�鏂�", + Nflag = 0, + Fmrmode = from.FMRMODE, + Sapno = from.SqNo, + Organizeid = "1002503270000079", + }; + + // 鍒涘缓閲囪喘閫�鏂欏崟璁板綍 + var mesInvItemOutItems = new List<MesInvItemOutItems>(); + + foreach (var itemOutList in items) + { + // 妫�鏌ュ繀瑕佸瓧娈垫槸鍚︿负绌� + if (string.IsNullOrEmpty(itemOutList.SrcDocNo)) + { + throw new NotImplementedException("閲囪喘璁㈠崟鍙蜂笉鑳戒负绌�"); + } + + if (string.IsNullOrEmpty(itemOutList.SrcDocLineNo)) + { + throw new NotImplementedException("閲囪喘璁㈠崟琛屽彿涓嶈兘涓虹┖"); + } + + //if (string.IsNullOrEmpty(itemOutList.AsnLineNo)) + //{ + // throw new NotImplementedException("ASN琛屽彿涓嶈兘涓虹┖"); + //} + + if (string.IsNullOrEmpty(itemOutList.itemId)) + { + throw new NotImplementedException("鐗╂枡ID涓嶈兘涓虹┖"); + } + + var mesRohInData = Db.Queryable<MesRohInData>() + .Where(s => s.BillNo == itemOutList.SrcDocNo + && s.OrderLineId == itemOutList.SrcDocLineNo) + .First(); + + if (mesRohInData == null) + { + throw new NotImplementedException("閲囪喘璁㈠崟涓嶅瓨鍦�"); + } + + //var deliveryDetail = Db.Queryable<DeliveryDetail>() + // .Where(a => Int32.Parse(a.ZzitemId) == + // Int32.Parse(itemOutList.AsnLineNo)) + // .Count(); + + //if (deliveryDetail <= 0) + //{ + // throw new NotImplementedException("[" + from.AsnNo + "]鐨勬槑缁嗚[" + + // itemOutList.AsnLineNo + + // "]涓嶅瓨鍦�"); + //} + + var itemIdLinkU9 = Db.Queryable<MesLinkU9>() + .Where(s => s.TableType == "MES_ITEMS" + && s.U9Id == itemOutList.itemId).First(); + + if (mesLinkU9 == null) + { + throw new NotImplementedException("渚涘簲鍟咺D涓嶅瓨鍦ㄦ垨鏈悓姝ヤ簬U9"); + } + + var mesItems = Db.Queryable<MesItems>() + .Where(s => s.Id == Decimal.Parse(itemIdLinkU9.MesId)) + .First(); + + if (mesItems == null) + { + throw new NotImplementedException("[" + itemOutList.itemId + + "]鐗╂枡涓嶅瓨鍦紝璇峰悓姝ョ粰MES"); + } + + var mesInvItemInCItems = Db.Queryable<MesInvItemInCItems>() + .Where(s => s.ItemInId == mesInvItemIns.Id + && s.ItemNo == mesItems.ItemNo + && s.Ebeln == itemOutList.SrcDocNo + && s.EbelnLineNo == + Decimal.Parse(itemOutList.SrcDocLineNo) + && s.SuppNo == mesSupplier.SuppNo + ).First(); + + if (mesInvItemInCItems == null) + { + throw new NotImplementedException("娌℃湁瀵瑰簲鐨勫叆搴撴槑缁�"); + } + + + // 纭繚CbillNo涓嶄负绌� + if (string.IsNullOrEmpty(mesInvItemIns.CbillNo)) + { + throw new NotImplementedException("鍏ュ簱鍗曞叧鑱旂殑閲囪喘鍗曞彿涓嶈兘涓虹┖"); + } + + mesInvItemOutItems.Add(new MesInvItemOutItems + { + ItemOutId = nextSequenceValue, + ItemNo = mesItems.ItemNo, + Quantity = Decimal.Parse(itemOutList.qty), + CreateBy = "PL017", + CreateDate = DateTime.Now, + Factory = "1000", + Company = "1000", + DepotCode = mesDepots.DepotCode, + WorkNo = itemOutList.SrcDocNo, // 纭繚WorkNo鏈夊�� + WorkLine = + Decimal.Parse(itemOutList.SrcDocLineNo), // 纭繚WorkLine鏈夊�� + EbelnK3id = Decimal.Parse(mesRohInData.ErpId), + LineK3id = Decimal.Parse(mesRohInData.EbelnK3id), + FType = 0, + Status = 0, + PbillNo = mesInvItemIns.CbillNo, // 纭繚PbillNo鏈夊�� + RkNo = from.MesNo, // 纭繚RkNo鏈夊�� + RkLine = mesInvItemInCItems.Id, // 纭繚RkLine鏈夊�� + RkQty = mesInvItemInCItems.Quantity, + TlQty = 0, + ItemId = Decimal.Parse(itemIdLinkU9.MesId), // 纭繚ItemId鏈夊�� + //SqNo = itemOutList.SqNo, // 纭繚ItemId鏈夊�� + //ZzitemId = itemOutList.AsnLineNo, // 纭繚ItemId鏈夊�� + // Unit = item.Unit, + }); + } + + var outItemCommand = Db.Insertable(mesInvItemOutItems) + .PageSize(1).IgnoreColumnsNull().ExecuteCommand(); + if (outItemCommand <= 0) + { + throw new Exception("鍒涘缓閲囪喘閫�鏂欏崟瀛愯〃澶辫触"); + } + + // 鎻掑叆閲囪喘閫�鏂欏崟璁板綍 + var insertResult = Db.Insertable(mesInvItemOuts).IgnoreColumns(true) + .ExecuteCommand(); + if (insertResult <= 0) + { + throw new Exception("鍒涘缓閲囪喘閫�鏂欏崟澶辫触"); + } + + return outItemCommand + insertResult >= 2; + } + + private bool Remove(ItemOutFrom from) + { + // 鏌ユ壘瑕佸垹闄ょ殑閲囪喘閫�鏂欏崟 + var mesInvItemOuts = Db.Queryable<MesInvItemOuts>() + .Where(s => s.BillTypeId == BILL_TYPE_ID + && s.TransactionNo == TRANSACTION_NO + && s.ItemOutNo == from.RtnNo).ToList(); + + if (mesInvItemOuts == null || mesInvItemOuts.Count == 0) + { + throw new NotImplementedException("鎵句笉鍒板搴旂殑閲囪喘閫�鏂欏崟: " + from.RtnNo); + } + + // 妫�鏌ユ槸鍚︽湁宸插鏍哥殑鍗曟嵁锛屽鏋滃瓨鍦ㄥ凡瀹℃牳(Status=1)鍒欎笉鍏佽鍒犻櫎 + if (mesInvItemOuts.Any(item => item.Status == 1)) + { + throw new NotImplementedException("瀛樺湪宸插鏍哥殑閲囪喘閫�鏂欏崟锛屼笉鍏佽鍒犻櫎"); + } + + // 鍒犻櫎鎵�鏈夌浉鍏冲崟鎹� + foreach (var itemOut in mesInvItemOuts) + { + // 鏌ユ壘瑕佸垹闄ょ殑閲囪喘閫�鏂欏崟鏄庣粏 + var mesInvItemOutItems = Db.Queryable<MesInvItemOutItems>() + .Where(s => s.ItemOutId == itemOut.Id) + .ToList(); + + if (mesInvItemOutItems == null || mesInvItemOutItems.Count == 0) + { + throw new NotImplementedException( + $"鎵句笉鍒伴噰璐��鏂欏崟[{itemOut.ItemOutNo}]瀵瑰簲鐨勬槑缁�"); + } + + // 鍒犻櫎閲囪喘閫�鏂欏崟鏄庣粏 + var deleteItemsResult = Db.Deleteable<MesInvItemOutItems>() + .Where(s => s.ItemOutId == itemOut.Id) + .ExecuteCommand(); + + if (deleteItemsResult <= 0) + { + throw new Exception($"鍒犻櫎閲囪喘閫�鏂欏崟[{itemOut.ItemOutNo}]鏄庣粏澶辫触"); + } + + // 鍒犻櫎閲囪喘閫�鏂欏崟 + var deleteResult = Db.Deleteable<MesInvItemOuts>() + .Where(s => s.Id == itemOut.Id) + .ExecuteCommand(); + + if (deleteResult <= 0) + { + throw new Exception($"鍒犻櫎閲囪喘閫�鏂欏崟[{itemOut.ItemOutNo}]澶辫触"); + } + } + + return true; + } +} \ No newline at end of file -- Gitblit v1.9.3