From 3dfa3d93337cca6363b0e138c74f80af96431b83 Mon Sep 17 00:00:00 2001
From: 展杰 <1240968267@qq.com>
Date: 星期五, 16 八月 2024 08:58:54 +0800
Subject: [PATCH] 合并上格最新代码

---
 MES.Service/service/Warehouse/OpeningReceiptServer.cs |   95 +++++++++++++++++++++++++++++------------------
 1 files changed, 59 insertions(+), 36 deletions(-)

diff --git a/MES.Service/service/Warehouse/OpeningReceiptServer.cs b/MES.Service/service/Warehouse/OpeningReceiptServer.cs
index 7e8c60e..d525417 100644
--- a/MES.Service/service/Warehouse/OpeningReceiptServer.cs
+++ b/MES.Service/service/Warehouse/OpeningReceiptServer.cs
@@ -1,55 +1,43 @@
 锘縰sing MES.Service.DB;
 using MES.Service.Dto.service;
 using MES.Service.Modes;
-using MES.Service.util;
 using SqlSugar;
 
 namespace MES.Service.service.Warehouse;
 
-public class OpeningReceiptServer :RepositoryNoEntity
+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} 涓嶅瓨鍦紝璇风‘璁わ紒");
-        }
-
-        int billTypeId = 100;
-        int transactionNo = 601;
 
         var checkBarcodeAlreadyReceived =
             CheckBarcodeAlreadyReceived(query.barcode);
 
-        if (checkBarcodeAlreadyReceived > 0)
-        {
-            throw new Exception("鏉$爜閲嶅鎵弿锛岃鏍稿锛�");
-        }
+        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, transactionNo, out string billNo);
+            depotCode, query.userName, out var billNo);
 
         UseTransaction(db =>
         {
@@ -64,8 +52,53 @@
             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();
+
+        var 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,
@@ -106,14 +139,11 @@
             TaskNo = barcodeInfo.TaskNo
         }).ExecuteCommand();
 
-        if (executeCommand <= 0)
-        {
-            throw new Exception("鍐欏叆澶辫触");
-        }
+        if (executeCommand <= 0) throw new Exception("鍐欏叆澶辫触");
     }
 
     private decimal GetOrCreateInventoryItemInId(MesInvItemBarcodes barcodeInfo,
-        string depotCode, string userName, int transactionNo, out string billNo)
+        string depotCode, string userName, out string billNo)
     {
         var inventory = Db.Queryable<MesInvItemIns>()
             .Where(d => d.InsDate >= DateTime.Today &&
@@ -125,7 +155,6 @@
                         d.SuppNo == barcodeInfo.SuppNo &&
                         d.DepotsCode == depotCode)
             .First();
-
         if (inventory != null)
         {
             billNo = inventory.BillNo;
@@ -139,7 +168,7 @@
         var executeReturnIdentity = Db.Insertable(new MesInvItemIns
         {
             BillNo = billNo,
-            BillTypeId = 100,
+            BillTypeId = billTypeId,
             InsDate = DateTime.Now,
             DepotsCode = depotCode,
             TransctionNo = transactionNo.ToString(),
@@ -218,10 +247,7 @@
             SuppNo = barcodeInfo.SuppNo
         }).ExecuteCommand();
 
-        if (executeCommand <= 0)
-        {
-            throw new Exception("鍐欏叆澶辫触");
-        }
+        if (executeCommand <= 0) throw new Exception("鍐欏叆澶辫触");
     }
 
     private void InsertBusinessRecord(MesInvItemBarcodes barcodeInfo,
@@ -231,7 +257,7 @@
         var executeCommand = Db.Insertable(new MesInvBusiness2
         {
             Status = 1,
-            BillTypeId = 100,
+            BillTypeId = billTypeId,
             TransactionCode = "601",
             BusinessType = 1,
             ItemBarcode = barcodeInfo.ItemBarcode,
@@ -254,9 +280,6 @@
             SuppNo = barcodeInfo.SuppNo
         }).ExecuteCommand();
 
-        if (executeCommand <= 0)
-        {
-            throw new Exception("鍐欏叆澶辫触");
-        }
+        if (executeCommand <= 0) throw new Exception("鍐欏叆澶辫触");
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3