From e1bb81e4d128de114362d5c04e937169a66b819b Mon Sep 17 00:00:00 2001
From: kyy <3283105747@qq.com>
Date: 星期二, 21 十月 2025 15:10:07 +0800
Subject: [PATCH] 采购言退优化

---
 service/Warehouse/MesInvItemInCDetailsManager.cs |   89 +++++++++++++++++++++++++++++++-------------
 1 files changed, 63 insertions(+), 26 deletions(-)

diff --git a/service/Warehouse/MesInvItemInCDetailsManager.cs b/service/Warehouse/MesInvItemInCDetailsManager.cs
index a77ffc4..bb925b3 100644
--- a/service/Warehouse/MesInvItemInCDetailsManager.cs
+++ b/service/Warehouse/MesInvItemInCDetailsManager.cs
@@ -1288,8 +1288,8 @@
         if (string.IsNullOrEmpty(entity.sectionCode)) throw new ArgumentNullException(nameof(entity.sectionCode), "搴撲綅缂栧彿涓嶅厑璁镐负绌�");
         if (string.IsNullOrEmpty(entity.returnBarcode)) throw new ArgumentNullException(nameof(entity.returnBarcode), "鏉$爜涓嶅厑璁镐负绌�");
 
-        try
-        {
+        //try
+        //{
             // 妫�鏌ユ潯鐮佹槸鍚﹀凡鍏ュ簱
             var isInStock = Db.Queryable<MesInvItemInCDetails>()
                 .Where(it => it.ItemBarcode == entity.returnBarcode)
@@ -1312,22 +1312,59 @@
                 .Where(it => it.ItemBarcode.Trim().ToLower() == entity.returnBarcode.Trim().ToLower())
                 .First() ?? throw new InvalidOperationException($"鏈壘鍒版潯鐮� '{entity.returnBarcode}' 鐨勫尮閰嶄俊鎭�");
 
+            // 鑾峰彇鍒拌揣鏄庣粏ID锛堝亣璁句粠鏉$爜淇℃伅涓彲浠ヨ幏鍙栧埌dhmxGuid锛�
+            var dhmxGuid = itemBarcode.AboutGuid; 
+
+            // 鏌ヨ妫�楠屼俊鎭紙瀵瑰簲SQL涓殑瑙嗗浘鏌ヨ閫昏緫锛�
+            var checkParams = new List<SugarParameter>
+        {
+            new("@dHdMx", dhmxGuid),
+            new("@JYZT", null, true),  // 杈撳嚭鍙傛暟锛氭楠岀姸鎬�
+            new("@JYJG", null, true),  // 杈撳嚭鍙傛暟锛氭楠岀粨鏋�
+            new("@PDJG", null, true),  // 杈撳嚭鍙傛暟锛氬垽瀹氱粨鏋�
+            new("@ISRK", null, true),  // 杈撳嚭鍙傛暟锛氭槸鍚﹁兘鍏ュ簱
+            new("@CLYS", null, true)   // 杈撳嚭鍙傛暟锛氬鐞嗘剰瑙�
+        };
+
+            // 鎵ц鏌ヨ鑾峰彇妫�楠屼俊鎭�
+            Db.Ado.ExecuteCommand(@"
+            SELECT @JYZT = ISNULL(妫�楠岀姸鎬�, '鏈煡'),
+                   @JYJG = ISNULL(妫�楠岀粨鏋�, '鏈煡'),
+                   @PDJG = ISNULL(鍒ゅ畾缁撴灉, '鏈煡'),
+                   @ISRK = ISNULL(鏄惁鑳藉叆搴�, 0),
+                   @CLYS = ISNULL(澶勭悊鎰忚, '鏃�')
+            FROM v_dhmx
+            WHERE dhmxGuid = @dHdMx", checkParams);
+
+            // 瑙f瀽杈撳嚭鍙傛暟
+            var jyzt = checkParams[1].Value?.ToString() ?? "鏈煡";
+            var jyjg = checkParams[2].Value?.ToString() ?? "鏈煡";
+            var pdjg = checkParams[3].Value?.ToString() ?? "鏈煡";
+            var isRk = checkParams[4].Value != DBNull.Value ? Convert.ToInt32(checkParams[4].Value) : 0;
+            var clys = checkParams[5].Value?.ToString() ?? "鏃�";
+
+            // 妫�鏌ユ槸鍚︽煡璇㈠埌妫�楠岃褰�
+            if (string.IsNullOrEmpty(jyzt) && string.IsNullOrEmpty(jyjg))
+                throw new Exception($"鏈壘鍒板埌璐ф槑缁唅d涓篬{dhmxGuid}]鐨勬楠岃褰�");
+            // 妫�鏌ユ槸鍚﹀厑璁搁獙閫�锛堝紓甯哥洿鎺ユ姏鍑猴級
+            if (isRk != 1)
+                throw new Exception($"璇ユ潯鐮佸搴旂殑鏀舵枡鍗曟楠岀粨鏋�:[{jyjg}]锛屽垽瀹氱粨鏋�:[{pdjg}]锛屽鐞嗘剰瑙�:[{clys}]锛屼笉鑳借繘琛岄獙閫�鎿嶄綔");
+
+
+
+
             // 灏嗘煡璇㈠埌鐨勬潯鐮佷俊鎭祴鍊肩粰杩斿洖妯″瀷
             res.itemBarcodeDetails = itemBarcode;
-
-
             res.Message = "鏌ヨ鎴愬姛";
-
-
             return res;
-        }
-        catch (Exception ex)
-        {
-            // 璁板綍寮傚父鏃ュ織锛堝缓璁ˉ鍏呭叿浣撴棩蹇楄褰曚唬鐮侊級
-            res.Message = $"鎿嶄綔澶辫触: {ex.Message}";
-            res.SumQuantity = -1;
-            return res;
-        }
+        //}
+        //catch (Exception ex)
+        //{
+        //    // 璁板綍寮傚父鏃ュ織锛堝缓璁ˉ鍏呭叿浣撴棩蹇楄褰曚唬鐮侊級
+        //    res.Message = $"鎿嶄綔澶辫触: {ex.Message}";
+        //    res.SumQuantity = -1;
+        //    return res;
+        //}
     }
 
     // 楠岄��
@@ -1341,8 +1378,8 @@
         if (string.IsNullOrEmpty(entity.returnBarcode)) throw new ArgumentNullException(nameof(entity.returnBarcode), "鏉$爜涓嶅厑璁镐负绌�");
         if (entity.returnQuantity <= 0) throw new ArgumentException("楠岄��鏁伴噺蹇呴』澶т簬0", nameof(entity.returnQuantity));
 
-        try
-        {
+        //try
+        //{
             // 妫�鏌ユ潯鐮佹槸鍚﹀凡鍏ュ簱
             var isInStock = Db.Queryable<MesInvItemInCDetails>()
                 .Where(it => it.ItemBarcode == entity.returnBarcode)
@@ -1460,8 +1497,8 @@
                     cmd.Parameters.AddRange(rkParameters);
                     cmd.ExecuteNonQuery();
 
-                    rkMsg = rkParameters[3].Value.ToString();
-                    rkSum = rkParameters[4].Value.ToString();
+                    rkMsg = rkParameters[4].Value.ToString();
+                    rkSum = rkParameters[5].Value.ToString();
 
                     if (rkSum == "-1") throw new Exception(rkMsg);
                 }
@@ -1522,14 +1559,14 @@
             // res.SumQuantity = res.ItemBarCDetails?.Count ?? 0;
             res.SumQuantity = Convert.ToDecimal(totalCDetailsQuantity);
             return res;
-        }
-        catch (Exception ex)
-        {
-            // 璁板綍寮傚父鏃ュ織锛堝缓璁ˉ鍏呭叿浣撴棩蹇楄褰曚唬鐮侊級
-            res.Message = $"鎿嶄綔澶辫触: {ex.Message}";
-            res.SumQuantity = -1;
-            return res;
-        }
+        //}
+        //catch (Exception ex)
+        //{
+        //    // 璁板綍寮傚父鏃ュ織锛堝缓璁ˉ鍏呭叿浣撴棩蹇楄褰曚唬鐮侊級
+        //    res.Message = $"鎿嶄綔澶辫触: {ex.Message}";
+        //    res.SumQuantity = -1;
+        //    return res;
+        //}
     }
 
 }
\ No newline at end of file

--
Gitblit v1.9.3