From 0e860de56fbf7ac66b9563fb946055207f09f9d6 Mon Sep 17 00:00:00 2001 From: lg <999544862qq.com> Date: 星期四, 15 八月 2024 10:25:43 +0800 Subject: [PATCH] Merge branch 'master' of http://43.142.96.171:8080/r/~tjx/StandardPda --- MES.Service/service/Warehouse/OpeningReceiptServer.cs | 308 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 308 insertions(+), 0 deletions(-) diff --git a/MES.Service/service/Warehouse/OpeningReceiptServer.cs b/MES.Service/service/Warehouse/OpeningReceiptServer.cs new file mode 100644 index 0000000..74dc31e --- /dev/null +++ b/MES.Service/service/Warehouse/OpeningReceiptServer.cs @@ -0,0 +1,308 @@ +锘縰sing MES.Service.DB; +using MES.Service.Dto.service; +using MES.Service.Modes; +using SqlSugar; + +namespace MES.Service.service.Warehouse; + +public class OpeningReceiptServer : RepositoryNoEntity +{ + private const string Factory = "1000"; + + private const string Company = "1000"; + + private const int billTypeId = 100; + + private const int transactionNo = 601; + + public MesInvItemBarcodes ScanInBarcodeQC(WarehouseQuery query) + { + if (string.IsNullOrWhiteSpace(query.sectionCode)) + { + throw new Exception("璇锋壂搴撲綅鏉$爜锛�"); + } + + var depotCode = GetDepotCode(query.sectionCode); + if (depotCode == null) + { + throw new Exception($"002[搴撲綅缂栫爜 {query.sectionCode} 涓嶅瓨鍦紝璇风‘璁わ紒"); + } + + var checkBarcodeAlreadyReceived = + CheckBarcodeAlreadyReceived(query.barcode); + + if (checkBarcodeAlreadyReceived > 0) + { + throw new Exception("鏉$爜閲嶅鎵弿锛岃鏍稿锛�"); + } + + if (CheckBarcodeInStock(query.barcode) > 0) + { + throw new Exception("鏉$爜宸插湪搴撳瓨涓紝璇锋牳瀵癸紒"); + } + + var barcodeInfo = GetBarcodeInfo(query.barcode); + if (barcodeInfo == null || barcodeInfo.ComeFlg != 0) + { + throw new Exception("鏉$爜涓嶆槸鏈熷垵鏉$爜锛屾棤娉曠敤鏈熷垵鍏ュ簱锛�"); + } + + var inventoryItemInId = GetOrCreateInventoryItemInId(barcodeInfo, + depotCode, query.userName, out string billNo); + + UseTransaction(db => + { + // Insert records + InsertInventoryDetails(inventoryItemInId, billNo, barcodeInfo, + depotCode, query.sectionCode, query.userName); + InsertBusinessRecord(barcodeInfo, depotCode, query.sectionCode, + billNo, + query.userName); + InsertStockRecord(barcodeInfo, depotCode, query.sectionCode, + query.userName); + return 1; + }); + + return barcodeInfo; + } + + public PurchaseInventory GetForm(WarehouseQuery query) + { + var mesInvItemBarcodes = Db.Queryable<MesInvItemBarcodes>() + .Where(s => s.ItemBarcode == query.barcode).Count(); + + if (mesInvItemBarcodes <= 0) + { + throw new Exception("鏉$爜涓嶅瓨鍦�"); + } + + var mesInvItemInCDetails = Db.Queryable<MesInvItemInCDetails>() + .Where(s => s.ItemBarcode == query.barcode).Single(); + + PurchaseInventory entity = new PurchaseInventory + { + ItemIns = GetMesInvItemIns(mesInvItemInCDetails.ItemInId), + InvItemInCDetails = + GetMesInvItemInCDetailsList(mesInvItemInCDetails.ItemInId), + ItemStocks = Db.Queryable<MesInvItemStocks>() + .Where(s => s.ItemBarcode == query.barcode).ToList() + }; + + return entity; + } + + public MesInvItemIns GetMesInvItemIns(decimal id) + { + return Db.Queryable<MesInvItemIns>() + .Where(s => s.Id == id).Single(); + } + + public List<MesInvItemInCDetails> GetMesInvItemInCDetailsList(decimal id) + { + return Db.Queryable<MesInvItemInCDetails, MesUnit>((a, b) => + new JoinQueryInfos(JoinType.Inner, a.Unit == b.Id.ToString())) + .Where((a, b) => a.ItemInId == id) + .Select((a, b) => new MesInvItemInCDetails + { + ItemBarcode = a.ItemBarcode, + ItemNo = a.ItemNo, + ItemSname = a.ItemSname, + DepotSectionCode = a.DepotSectionCode, + Quantity = a.Quantity, + Unit = b.Fname, + Remark = a.Remark + }) + .ToList(); + } + + private void InsertInventoryDetails(decimal itemInId, string billNo, + MesInvItemBarcodes barcodeInfo, string depotCode, string sectionCode, + string user) + { + // Insert inventory details record + var executeCommand = Db.Insertable(new MesInvItemInCDetails + { + ItemInId = itemInId, + BillNo = billNo, + ItemBarcode = barcodeInfo.ItemBarcode, + Quantity = barcodeInfo.Quantity, + BarcodeFlag = 1, + EpFlag = 1, + WorkType = 1, + ItemNo = barcodeInfo.ItemNo, + LotNo = barcodeInfo.LotNo, + SuppNo = barcodeInfo.SuppNo, + DepotCode = depotCode, + DepotSectionCode = sectionCode, + ItemSname = barcodeInfo.ItemSname, + Unit = barcodeInfo.Unit, + CreateBy = user, + CreateDate = DateTime.Now, + LastupdateBy = user, + LastupdateDate = DateTime.Now, + Remark = barcodeInfo.Memo, + Factory = Factory, + Company = Company, + Ebeln = barcodeInfo.Mblnr, + EbelnLineNo = barcodeInfo.Zeile, + WorkNo = barcodeInfo.WorkNo, + WorkLine = barcodeInfo.WorkLine, + CbillNo = barcodeInfo.BillNo, + UrgentFlag = barcodeInfo.UrgentFlag, + BoardStyle = barcodeInfo.BoardStyle, + TaskNo = barcodeInfo.TaskNo + }).ExecuteCommand(); + + if (executeCommand <= 0) + { + throw new Exception("鍐欏叆澶辫触"); + } + } + + private decimal GetOrCreateInventoryItemInId(MesInvItemBarcodes barcodeInfo, + string depotCode, string userName, out string billNo) + { + var inventory = Db.Queryable<MesInvItemIns>() + .Where(d => d.InsDate >= DateTime.Today && + d.InsDate < DateTime.Today.AddDays(1) && + d.Sapstatus == 0 && + d.Status == 0 && + d.TransctionNo == transactionNo.ToString() && + d.CbillNo == barcodeInfo.BillNo && + d.SuppNo == barcodeInfo.SuppNo && + d.DepotsCode == depotCode) + .First(); + if (inventory != null) + { + billNo = inventory.BillNo; + return inventory.Id; + } + + var sql = + $"SELECT getbillcode1('{Factory}','{Company}','QCRK') FROM DUAL;"; + billNo = Db.Ado.SqlQuerySingle<string>(sql); + + var executeReturnIdentity = Db.Insertable(new MesInvItemIns + { + BillNo = billNo, + BillTypeId = billTypeId, + InsDate = DateTime.Now, + DepotsCode = depotCode, + TransctionNo = transactionNo.ToString(), + SuppNo = barcodeInfo.SuppNo, + CreateBy = userName, + CreateDate = DateTime.Now, + LastupdateBy = userName, + LastupdateDate = DateTime.Now, + Factory = Factory, + Company = Company, + UrgentFlag = barcodeInfo.UrgentFlag, + CbillNo = barcodeInfo.BillNo, + Fstatus = 0 + }).ExecuteReturnIdentity(); + + return executeReturnIdentity; + } + + private MesInvItemBarcodes GetBarcodeInfo(string itemBarcode) + { + // Get barcode information + return Db.Queryable<MesInvItemBarcodes>() + .First(b => b.ItemBarcode == itemBarcode); + } + + private int CheckBarcodeInStock(string itemBarcode) + { + // Check if the barcode is in stock + return Db.Queryable<MesInvItemStocks>() + .Where(stock => stock.ItemBarcode == itemBarcode).Count(); + } + + + private int CheckBarcodeAlreadyReceived(string itemBarcode) + { + // Check if the barcode is already received + return Db.Queryable<MesInvItemIns, MesInvItemInCDetails>( + (ins, details) => new JoinQueryInfos(JoinType.Inner, + ins.Id == details.ItemInId)) + .Where((ins, details) => details.ItemBarcode == itemBarcode) + .Count(); + } + + private string GetDepotCode(string sectionCode) + { + // This would be your query to get depot code based on section code + return Db.Queryable<MesDepotSections, MesDepots>((d, t) => + new JoinQueryInfos(JoinType.Inner, d.Zuid.ToString() == t.Zuid)) + .Where((d, t) => d.DepotSectionCode == sectionCode) + .Select<string>((d, t) => t.DepotCode) + .First(); + } + + + private void InsertStockRecord(MesInvItemBarcodes barcodeInfo, + string depotCode, + string sectionCode, string user) + { + var executeCommand = Db.Insertable(new MesInvItemStocks + { + TaskNo = barcodeInfo.TaskNo, + ItemBarcode = barcodeInfo.ItemBarcode, + ItemNo = barcodeInfo.ItemNo, + LotNo = barcodeInfo.LotNo, + Quantity = barcodeInfo.Quantity, + EpFlag = barcodeInfo.EpFlag, + DepotsCode = depotCode, + DepotSectionsCode = sectionCode, + CheckDate = barcodeInfo.CreateDate, + IndepDate = barcodeInfo.CreateDate, + Factory = Factory, + Company = Company, + BoardStyle = barcodeInfo.BoardStyle, + WorkNo = barcodeInfo.WorkNo, + WorkLine = barcodeInfo.WorkLine, + SuppNo = barcodeInfo.SuppNo + }).ExecuteCommand(); + + if (executeCommand <= 0) + { + throw new Exception("鍐欏叆澶辫触"); + } + } + + private void InsertBusinessRecord(MesInvItemBarcodes barcodeInfo, + string depotCode, string sectionCode, string billNo, string user) + { + // Insert business record + var executeCommand = Db.Insertable(new MesInvBusiness2 + { + Status = 1, + BillTypeId = billTypeId, + TransactionCode = "601", + BusinessType = 1, + ItemBarcode = barcodeInfo.ItemBarcode, + ItemNo = barcodeInfo.ItemNo, + LotNo = barcodeInfo.LotNo, + EpFlag = 1, + Quantity = barcodeInfo.Quantity, + ToInvDepotsCode = depotCode, + ToInvDepotSectionsCode = sectionCode, + CreateBy = user, + CreateDate = DateTime.Now, + LastupdateBy = user, + LastupdateDate = DateTime.Now, + Factory = Factory, + Company = Company, + TaskNo = barcodeInfo.TaskNo, + BillNo = billNo, + WorkNo = barcodeInfo.WorkNo, + WorkLine = barcodeInfo.WorkLine, + SuppNo = barcodeInfo.SuppNo + }).ExecuteCommand(); + + if (executeCommand <= 0) + { + throw new Exception("鍐欏叆澶辫触"); + } + } +} \ No newline at end of file -- Gitblit v1.9.3