From 971e03ccbe5124d4761f56e71025453d1d4742bc Mon Sep 17 00:00:00 2001
From: 啊鑫 <t2856754968@163.com>
Date: 星期三, 17 九月 2025 14:17:08 +0800
Subject: [PATCH] 111

---
 service/base/WmsBaseMangeer.cs                   |   19 +++++
 service/Warehouse/MesInvItemInCDetailsManager.cs |  140 ++++++++++++++++++++++++++++++++++------------
 2 files changed, 119 insertions(+), 40 deletions(-)

diff --git a/service/Warehouse/MesInvItemInCDetailsManager.cs b/service/Warehouse/MesInvItemInCDetailsManager.cs
index 8dfc5d4..0fd977c 100644
--- a/service/Warehouse/MesInvItemInCDetailsManager.cs
+++ b/service/Warehouse/MesInvItemInCDetailsManager.cs
@@ -17,6 +17,16 @@
 
     public ItemInBaseModel SaveBarCodes(WarehouseQuery entity)
     {
+        // 鍙傛暟楠岃瘉
+        if (entity == null)
+            throw new ArgumentNullException(nameof(entity), "鍙傛暟瀵硅薄涓嶈兘涓虹┖");
+
+        if (string.IsNullOrEmpty(entity.userName))
+            throw new ArgumentException("鐢ㄦ埛鍚嶄笉鑳戒负绌�", nameof(entity.userName));
+
+        if (string.IsNullOrEmpty(entity.barcode))
+            throw new ArgumentException("鏉$爜涓嶈兘涓虹┖", nameof(entity.barcode));
+
         string functionName = "閲囪喘鍏ュ簱", fieldName = null, inFieldVal = null;
         string user = entity.userName,
             sectionCode = entity.sectionCode,
@@ -29,22 +39,32 @@
         if (string.IsNullOrEmpty(sectionCode))
             throw new Exception("璇锋壂搴撲綅鏉$爜锛�");
 
-        var itemBarcodeDetails = Db.Queryable<MesInvItemBarcodes>()
-            .Where(it => it.ItemBarcode == itemBarcode)
-            .First();
-
-        if (itemBarcodeDetails == null)
+        MesInvItemBarcodes itemBarcodeDetails;
+        try
+        {
+            itemBarcodeDetails = Db.Queryable<MesInvItemBarcodes>()
+                .Where(it => it.ItemBarcode == itemBarcode)
+                .First();
+        }
+        catch
+        {
             throw new Exception("鏉$爜涓嶅瓨鍦紝璇锋牳瀵癸紒");
+        }
 
         if (string.IsNullOrEmpty(itemBarcodeDetails.Memo) || itemBarcodeDetails.Memo != "閲囪喘鍏ュ簱")
             throw new Exception("姝ゆ潯鐮佷笉灞炰簬鍒拌揣鏉$爜锛屾棤娉曠敤閲囪喘鍏ュ簱锛�");
 
-        var inventory = Db.Queryable<MesInvItemArn>()
-            .Where(it => it.BillNo == itemBarcodeDetails.BillNo && it.Fstatus == true )
-            .First();
-
-        if (inventory == null)
+        MesInvItemArn inventory;
+        try
+        {
+            inventory = Db.Queryable<MesInvItemArn>()
+                .Where(it => it.BillNo == itemBarcodeDetails.BillNo && it.Fstatus == true )
+                .First();
+        }
+        catch
+        {
             throw new Exception("姝ゆ潯鐮佹壘涓嶅埌瀵瑰簲鏀惰揣鍗曟垨鏈鏍革紒");
+        }
 
         // var inventoryDetails = Db.Queryable<MesInvItemArnDetail>()
         //     .Where(it => it.ParentGuid == inventory.Guid
@@ -53,47 +73,76 @@
         //                  && it.Ebeln == itemBarcodeDetails.WorkNo)
         //     .First();
 
-        var inventoryDetails = Db.Queryable<MesInvItemArnDetail>()
-            .Where(it => it.Guid == itemBarcodeDetails.AboutGuid)
-            .First();
-
-        var cgddDetails = Db.Queryable<MesRohInData>()
-            .Where(it => it.EbelnK3id == inventoryDetails.LineK3id)
-            .First();
-
-        if (cgddDetails == null)
-            throw new Exception("姝ゆ潯鐮佹壘涓嶅埌瀵瑰簲閲囪喘璁㈠崟鏄庣粏锛�");
-
-        if (inventoryDetails == null)
+        MesInvItemArnDetail inventoryDetails;
+        try
+        {
+            inventoryDetails = Db.Queryable<MesInvItemArnDetail>()
+                .Where(it => it.Guid == itemBarcodeDetails.AboutGuid)
+                .First();
+        }
+        catch
+        {
             throw new Exception("姝ゆ潯鐮佹壘涓嶅埌瀵瑰簲鏀惰揣鍗曟槑缁嗭紒");
+        }
+
+        MesRohInData cgddDetails;
+        try
+        {
+            cgddDetails = Db.Queryable<MesRohInData>()
+                .Where(it => it.EbelnK3id == inventoryDetails.LineK3id)
+                .First();
+        }
+        catch
+        {
+            throw new Exception("姝ゆ潯鐮佹壘涓嶅埌瀵瑰簲閲囪喘璁㈠崟鏄庣粏锛�");
+        }
 
         //鑾峰彇鍒拌揣妫�楠屾槑缁�
         var sqlParams = new List<SugarParameter> { new("@dhmxGuid", itemBarcodeDetails.AboutGuid) };
         var sql1 = @"SELECT *FROM v_dhmx WHERE dhmxGuid = @dhmxGuid ";
-        var dhjymx = Db.Ado.SqlQuery<vDhmx>(sql1, sqlParams).First();
+        vDhmx dhjymx;
+        try
+        {
+            dhjymx = Db.Ado.SqlQuery<vDhmx>(sql1, sqlParams).First();
+        }
+        catch
+        {
+            throw new Exception("璇ユ潯鐮佹壘涓嶅埌瀵瑰簲鐨勬楠屾槑缁嗭紒");
+        }
+
         //鍒ゅ畾妫�楠岃兘鍚﹀叆搴�
         if (dhjymx.CanStore!= 1)
         {
             throw new Exception($"璇ユ潯鐮佸搴旂殑鏀舵枡鍗曟楠岀粨鏋�:銆恵dhjymx.InspectionResult}銆�,鍒ゅ畾缁撴灉锛氥�恵dhjymx.JudgmentResult}銆戯紝澶勭悊鎰忚锛氥�恵dhjymx.HandlingSuggestion}銆�,鏃犳硶鍏ュ簱");
         }
 
-        var depotCode = Db.Queryable<MesDepotSections>()
-            .Where(it => it.DepotSectionCode == sectionCode)
-            .Select(it => it.DepotGuid)
-            .First();
-
-        var depotCode2 = Db.Queryable<MesInvItemArn>()
-            .Where(it => it.BillNo == itemBarcodeDetails.BillNo)
-            .Select(it => it.DepotsId)
-            .First();
+        string depotCode;
+        try
+        {
+            depotCode = Db.Queryable<MesDepotSections>()
+                .Where(it => it.DepotSectionCode == sectionCode)
+                .Select(it => it.DepotGuid)
+                .First();
+        }
+        catch
+        {
+            throw new Exception("搴撲綅缂栫爜 " + sectionCode + " 涓嶅瓨鍦紝璇风‘璁わ紒");
+        }
 
         MesDepots mesDepost = null;
 
         var checkGuid = UtilityHelper.CheckGuid(depotCode);
         if (checkGuid && depotCode != null)
         {
-            mesDepost = Db.Queryable<MesDepots>()
-                .Where(s => s.DepotId.ToString() == depotCode).First();
+            try
+            {
+                mesDepost = Db.Queryable<MesDepots>()
+                    .Where(s => s.Guid == depotCode).First();
+            }
+            catch
+            {
+                throw new Exception("搴撲綅缂栫爜 " + sectionCode + " 瀵瑰簲鐨勪粨搴撲笉瀛樺湪锛岃纭锛�");
+            }
 
             // if (depotCode != mesDepost.Guid)
             //     throw new Exception("鎵弿搴撲綅涓庨噰璐叆搴撳簱浣嶄笉涓�鑷达紒");
@@ -130,6 +179,9 @@
             billNo: "", // 鏍规嵁瀹為檯鍗曟嵁鍙蜂紶鍊�
             transactionNo: "101" // 浜嬪姟绫诲瀷涓庡瓨鍌ㄨ繃绋嬪尮閰�
         );
+
+        if (checkResult == null)
+            throw new Exception("鍏ュ簱鏍¢獙澶辫触锛氳繑鍥炵粨鏋滀负绌�");
 
         if (Convert.ToInt32(checkResult.result) < 1)
             throw new Exception($"鍏ュ簱鏍¢獙澶辫触锛歿checkResult.strMsg}");
@@ -214,7 +266,8 @@
                     it.Guid,
                     it.BillNo
                 })
-                .First();
+                .ToList()
+                .FirstOrDefault();
 
             var cId = Guid.Empty;
             string cBillNo = null;
@@ -230,8 +283,16 @@
                 cId = Guid.NewGuid();
                 cBillNo = BillNo.GetBillNo("CGRK(閲囪喘鍏ュ簱)");
 
-                var suppNo = db.Queryable<MesSupplier>()
-                    .Where(s => s.Id.ToString() == inventory.SuppId).First();
+                MesSupplier suppNo;
+                try
+                {
+                    suppNo = db.Queryable<MesSupplier>()
+                        .Where(s => s.Id.ToString() == inventory.SuppId).First();
+                }
+                catch
+                {
+                    throw new Exception("鎵句笉鍒板搴旂殑渚涘簲鍟嗕俊鎭紒");
+                }
 
                 db.Insertable(new MesInvItemIns
                 {
@@ -259,7 +320,10 @@
                 }).IgnoreColumns(true).ExecuteCommand();
             }
 
-            cSyQty = itemBarcodeDetails.Quantity.Value;
+            cSyQty = itemBarcodeDetails.Quantity ?? 0;
+
+            if (cSyQty <= 0)
+                throw new Exception("鏉$爜鏁伴噺鏃犳晥锛岃妫�鏌ユ潯鐮佷俊鎭紒");
 
             entity.id = cId.ToString();
             entity.PageIndex = 1;
diff --git a/service/base/WmsBaseMangeer.cs b/service/base/WmsBaseMangeer.cs
index e3eadf8..b3bbe50 100644
--- a/service/base/WmsBaseMangeer.cs
+++ b/service/base/WmsBaseMangeer.cs
@@ -31,6 +31,20 @@
             string barcode, string sectionCode, string stockId, string stockOrgId,
             string billNo, string transactionNo)
         {
+            // 鍙傛暟楠岃瘉
+            if (string.IsNullOrEmpty(edtUserNo))
+                throw new ArgumentException("鎿嶄綔浜哄伐鍙蜂笉鑳戒负绌�", nameof(edtUserNo));
+            if (string.IsNullOrEmpty(barcode))
+                throw new ArgumentException("鐗╂枡鏉$爜涓嶈兘涓虹┖", nameof(barcode));
+            if (string.IsNullOrEmpty(sectionCode))
+                throw new ArgumentException("搴撲綅缂栫爜涓嶈兘涓虹┖", nameof(sectionCode));
+            if (string.IsNullOrEmpty(stockId))
+                throw new ArgumentException("浠撳簱ID涓嶈兘涓虹┖", nameof(stockId));
+            if (string.IsNullOrEmpty(stockOrgId))
+                throw new ArgumentException("搴撳瓨缁勭粐ID涓嶈兘涓虹┖", nameof(stockOrgId));
+            if (string.IsNullOrEmpty(transactionNo))
+                throw new ArgumentException("浜嬪姟绫诲瀷涓嶈兘涓虹┖", nameof(transactionNo));
+
             var outputMsg = "";
             var outputStatus = -1;
 
@@ -46,7 +60,7 @@
                     new("@pi_sectionCode", SqlDbType.NVarChar, 100) { Value = sectionCode },
                     new("@pi_stockId", SqlDbType.NVarChar, 100) { Value = stockId },
                     new("@pi_stockOrgId", SqlDbType.NVarChar, 100) { Value = stockOrgId },
-                    new("@pi_billno", SqlDbType.NVarChar, 100) { Value = billNo },
+                    new("@pi_billno", SqlDbType.NVarChar, 100) { Value = string.IsNullOrEmpty(billNo) ? DBNull.Value : billNo },
                     new("@pi_transaction_no", SqlDbType.NVarChar, 10) { Value = transactionNo },
                     new("@pi_val1", SqlDbType.NVarChar, 100) { Value = DBNull.Value }, // 棰勭暀鎵╁睍瀛楁
                     new("@pi_val2", SqlDbType.NVarChar, 100) { Value = DBNull.Value }, // 棰勭暀鎵╁睍瀛楁
@@ -122,8 +136,9 @@
         /// <returns>璐т富绫诲瀷(BD_OwnerOrg/BD_Customer/BD_Supplier)</returns>
         public string GetOwnerType(string ownerId)
         {
+            // 濡傛灉 ownerId 涓虹┖锛岃繑鍥為粯璁ょ殑璐т富绫诲瀷
             if (string.IsNullOrEmpty(ownerId))
-                throw new ArgumentNullException(nameof(ownerId));
+                return "BD_OwnerOrg"; // 榛樿涓虹粍缁囩被鍨�
 
             if (Db.Queryable<SysOrganization>().Any(x => x.Fid == ownerId))
             {

--
Gitblit v1.9.3