From fba48d2d676cd9b6d493163aef9d87f6e5090aee Mon Sep 17 00:00:00 2001
From: 如洲 陈 <1278080563@qq.com>
Date: 星期五, 12 九月 2025 19:02:00 +0800
Subject: [PATCH] 出库检和退货检验

---
 MES.Service/service/QC/SJService.cs |  164 +++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 141 insertions(+), 23 deletions(-)

diff --git a/MES.Service/service/QC/SJService.cs b/MES.Service/service/QC/SJService.cs
index 47459cd..4e6384f 100644
--- a/MES.Service/service/QC/SJService.cs
+++ b/MES.Service/service/QC/SJService.cs
@@ -4,7 +4,10 @@
 using MES.Service.Modes;
 using MES.Service.util;
 using SqlSugar;
+using System.Net;
 using System.Xml.Linq;
+using System.Data;
+using System.Data.Common;
 
 namespace MES.Service.service.QC;
 
@@ -69,7 +72,7 @@
             .OrderBy(a => a.BillNo, OrderByType.Desc)
             .ToPageList(queryObj.PageIndex, queryObj.Limit);
 
-        if(queryObj.Id != null)
+        /*if(queryObj.Id != null)
         {
 
 
@@ -88,7 +91,7 @@
                       return commit;
                   });
 
-        }
+        }*/
 
         
 
@@ -438,7 +441,6 @@
         var count = db.Queryable<QsItemIpiItemDetail>()
             .Where(s => s.Pid == detail.Pid).Count();
 
-
         var result = 0;
 
         if (qsItemIpiItem.LevelNum != count) return 0;
@@ -459,7 +461,6 @@
                 return commit;
             });
 
-
         //鑷姩鍒ゅ畾鏄惁鍚堟牸
         //鑾峰彇妫�楠屽崟鐨勬楠岄」鐩悊璁轰釜鏁�
         var sum = db.Queryable<QsItemIpiItem>()
@@ -475,28 +476,69 @@
         //瀹為檯涓暟绛変簬鐞嗚涓暟鏃跺妫�楠屽崟杩涜鍒ゅ畾
         if (sum == icount)
         {
-            result = 0;
-
-            //鑾峰彇杩欎釜妫�楠屽崟涓嬬殑鎵�鏈夊悎鏍肩殑妫�楠岀粨鏋�
-            passCount = db.Queryable<QsItemIpiItemDetail>()
-                .Where(s => s.Gid == detail.Gid && s.Fstand == "鈭�").Count();
-
-            //鍚堟牸鐨勬楠岀粨鏋滅瓑浜庢�绘楠屾暟瑙嗕负鍚堟牸
-            if (icount == passCount) result = 1;
-
-            useTransactionWithOracle += SqlSugarHelper.UseTransactionWithOracle(
-                db =>
-                {
-                    return db.Updateable<QsItemIpiReq>()
-                        .SetColumns(s => s.IsPass == result)
-                        .SetColumns(s => s.StatusUser == detail.CreateBy)
-                        .SetColumns(s => s.CompleteTime == DateTime.Now)
-                        .Where(s => s.Id == detail.Gid)
-                        .ExecuteCommand();
-                });
+            // 璋冪敤瀛樺偍杩囩▼杩涜鑷姩鍒ゅ畾鍜屾彁浜�
+            CallSJAutoResultStoredProcedure(detail.Gid, detail.CreateBy);
         }
 
         return useTransactionWithOracle;
+    }
+
+    /// <summary>
+    /// 璋冪敤棣栨鑷姩鍒ゅ畾鍜屾彁浜ゅ瓨鍌ㄨ繃绋�
+    /// </summary>
+    /// <param name="gid">棣栨涓昏〃ID</param>
+    /// <param name="createBy">鎿嶄綔浜�</param>
+    private void CallSJAutoResultStoredProcedure(decimal? gid, string createBy)
+    {
+        try
+        {
+            var db = SqlSugarHelper.GetInstance();
+            
+            // 鑾峰彇棣栨鍗曚俊鎭�
+            var sjInfo = db.Queryable<QsItemIpiReq>()
+                .Where(s => s.Id == gid)
+                .First();
+                
+            if (sjInfo == null) return;
+
+            // 瀹氫箟杈撳嚭鍙傛暟
+            var outputResult = new SugarParameter("o_Result", null,
+                System.Data.DbType.Int32, ParameterDirection.Output, 4000);
+
+            var outputMessage = new SugarParameter("o_Msg", null,
+                System.Data.DbType.String, ParameterDirection.Output, 4000);
+
+            // 瀹氫箟杈撳叆鍙傛暟
+            var parameters = new List<SugarParameter>
+            {
+                new("p_Gid", gid, System.Data.DbType.Decimal, ParameterDirection.Input),
+                new("p_Bill_No", sjInfo.BillNo, System.Data.DbType.String, ParameterDirection.Input),
+                new("p_User", createBy, System.Data.DbType.String, ParameterDirection.Input),
+                outputResult,
+                outputMessage
+            };
+
+            // 鎵ц瀛樺偍杩囩▼
+            db.Ado.ExecuteCommand(
+                "BEGIN PRC_MES_SJ_AUTO_RESULT(:p_Gid, :p_Bill_No, :p_User, :o_Result, :o_Msg); END;",
+                parameters.ToArray());
+
+            // 鑾峰彇杈撳嚭鍙傛暟鐨勫��
+            var resultValue = outputResult.Value?.ToString();
+            var messageValue = outputMessage.Value?.ToString();
+
+            if ("1".Equals(resultValue)) 
+            {
+                throw new Exception($"棣栨鑷姩鍒ゅ畾澶辫触: {messageValue}");
+            }
+        }
+        catch (Exception ex)
+        {
+            // 璁板綍鏃ュ織浣嗕笉褰卞搷涓绘祦绋�
+            Console.WriteLine($"棣栨鑷姩鍒ゅ畾瀛樺偍杩囩▼璋冪敤澶辫触: {ex.Message}");
+            // 鍙互鏍规嵁闇�瑕佸喅瀹氭槸鍚︽姏鍑哄紓甯�
+            // throw new Exception($"棣栨鑷姩鍒ゅ畾澶辫触: {ex.Message}");
+        }
     }
 
     public int UpdateQSItemDetail(QsItemIpiItemDetail detail)
@@ -581,4 +623,80 @@
 
         return withOracle;
     }
+
+
+
+    public List<string> GetFtpFileList(string ftpAddress, string username, string password, string remotePath)
+    {
+        List<string> fileList = new List<string>();
+        try
+        {
+            // 鏋勯�燜TP璇锋眰鐨刄RI
+            string requestUri = $"{ftpAddress}/{remotePath}".TrimEnd('/'); // 纭繚璺緞鏍煎紡姝g‘
+
+            // 鍒涘缓FtpWebRequest瀵硅薄
+            FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(requestUri);
+            ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;
+            ftpRequest.Credentials = new NetworkCredential(username, password);
+            ftpRequest.UseBinary = true;
+
+            // 鑾峰彇鍝嶅簲
+            using (FtpWebResponse ftpResponse = (FtpWebResponse)ftpRequest.GetResponse())
+            {
+                using (StreamReader responseReader = new StreamReader(ftpResponse.GetResponseStream()))
+                {
+                    string line = responseReader.ReadLine();
+                    while (line != null)
+                    {
+                        fileList.Add(line);
+                        line = responseReader.ReadLine();
+                    }
+                }
+            }
+        }
+        catch (Exception ex)
+        {
+            Console.WriteLine("鑾峰彇FTP鏂囦欢鍒楄〃鏃跺彂鐢熼敊璇�: " + ex.Message);
+            
+        }
+        return fileList;
+    }
+
+
+    public byte[] DownloadFtpFile(string ftpAddress, string username, string password, string remotePath)
+    {
+        byte[] fileData = null;
+        try
+        {
+            // 鏋勯�燜TP璇锋眰鐨刄RI
+            string requestUri = $"{ftpAddress}/{remotePath}".TrimEnd('/'); // 纭繚璺緞鏍煎紡姝g‘
+
+            // 鍒涘缓FtpWebRequest瀵硅薄
+            FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(requestUri);
+            ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
+            ftpRequest.Credentials = new NetworkCredential(username, password);
+            ftpRequest.UseBinary = true;
+
+            // 鑾峰彇鍝嶅簲
+            using (FtpWebResponse ftpResponse = (FtpWebResponse)ftpRequest.GetResponse())
+            {
+                using (Stream responseStream = ftpResponse.GetResponseStream())
+                using (MemoryStream memoryStream = new MemoryStream())
+                {
+                    responseStream.CopyTo(memoryStream);
+                    fileData = memoryStream.ToArray();
+                }
+            }
+        }
+        catch (Exception ex)
+        {
+            Console.WriteLine("涓嬭浇FTP鏂囦欢鏃跺彂鐢熼敊璇�: " + ex.Message);
+        }
+        return fileData;
+    }
+
+
+
+
+
 }
\ No newline at end of file

--
Gitblit v1.9.3