From 4f3b0a6727ecfa555892ebea64bd76e5a07cd6fb Mon Sep 17 00:00:00 2001
From: xiazhengtongxue <133085197+xiazhengtongxue@users.noreply.github.com>
Date: 星期二, 17 三月 2026 10:01:38 +0800
Subject: [PATCH] feat: 新增WMS异常上报自动恢复异常按钮

---
 项目代码/WCSServices/WIDESEAWCS_SystemServices/Sys_LogService.cs |  202 ++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 187 insertions(+), 15 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_SystemServices/Sys_LogService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_SystemServices/Sys_LogService.cs"
index 9097c5d..9ffc2aa 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_SystemServices/Sys_LogService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCSServices/WIDESEAWCS_SystemServices/Sys_LogService.cs"
@@ -131,6 +131,7 @@
 using System.Linq.Expressions;
 using System.Text;
 using System.Threading.Tasks;
+using WIDESEAWCS_Core;
 using WIDESEAWCS_Core.BaseServices;
 using WIDESEAWCS_ISystemRepository;
 using WIDESEAWCS_ISystemServices;
@@ -149,7 +150,7 @@
 
         private const string DbName = "WIDESEA_HF";
         private const string ConnectionString = "Data Source=11.2.30.112;Initial Catalog=WIDESEA_HF;User ID=kuka;Password=kuka;Integrated Security=False;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
-        private const long MaxMdfSizeBytes = 8L * 1024 * 1024 * 1024; // 8GB
+        private const long MaxMdfSizeBytes = 7L * 1024 * 1024 * 1024; // 7GB
         private const int TargetShrinkSizeMB = 4500; // 4.5GB
         private const double FragmentationThreshold = 30.0; // 30%纰庣墖鐜囬槇鍊�
         private const int MaintenanceIntervalDays = 15; // 15澶╂墽琛屼竴娆�
@@ -163,7 +164,7 @@
         public Sys_LogService(ISys_LogRepository BaseDal) : base(BaseDal)
         {
             // 纭繚澶囦唤鐩綍瀛樺湪
-            EnsureBackupDirectory();
+            //EnsureBackupDirectory();
         }
 
         private void EnsureBackupDirectory()
@@ -196,19 +197,20 @@
                 }
                 try
                 {
-                    // 璁$畻3涓湀鍓嶇殑鏃ユ湡
-                    var threeMonthsAgo = DateTime.Now.AddMonths(-3);
-                    // 璁$畻3澶╁墠鐨勬棩鏈�
-                    var threeDaysAgo = DateTime.Now.AddDays(-3);
-                    // 鐗瑰畾URL
-                    var specificUrl = "http://11.2.30.141:10870/interfaces/api/amr/robotQuery";
-                    var anonUrl = "http://11.2.30.111/anon/api/kuka/drivestatus";
+                    var result = BaseDal.Db.Deleteable<Sys_Log>().ExecuteCommand();
+                    //// 璁$畻3涓湀鍓嶇殑鏃ユ湡
+                    //var threeMonthsAgo = DateTime.Now.AddMonths(-3);
+                    //// 璁$畻3澶╁墠鐨勬棩鏈�
+                    //var threeDaysAgo = DateTime.Now.AddDays(-3);
+                    //// 鐗瑰畾URL
+                    //var specificUrl = "http://11.2.30.141:10870/interfaces/api/amr/robotQuery";
+                    //var anonUrl = "http://11.2.30.111/anon/api/kuka/drivestatus";
 
-                    // 鏋勫缓鍒犻櫎鏉′欢锛�3涓湀鍓嶇殑鏃ュ織 鎴� (3澶╁墠涓擴RL涓虹壒瀹氬湴鍧�鐨勬棩蹇�)
-                    var result = BaseDal.Db.Deleteable<Sys_Log>()
-                        .Where(log => log.EndDate < threeMonthsAgo ||
-                                     (log.EndDate < threeDaysAgo && (log.Url == specificUrl || log.Url == anonUrl)))
-                        .ExecuteCommand();
+                    //// 鏋勫缓鍒犻櫎鏉′欢锛�3涓湀鍓嶇殑鏃ュ織 鎴� (3澶╁墠涓擴RL涓虹壒瀹氬湴鍧�鐨勬棩蹇�)
+                    //var result = BaseDal.Db.Deleteable<Sys_Log>()
+                    //    .Where(log => log.EndDate < threeMonthsAgo ||
+                    //                 (log.EndDate < threeDaysAgo && (log.Url == specificUrl || log.Url == anonUrl)))
+                    //    .ExecuteCommand();
                     // 鏇存柊鏈�鍚庢墽琛屾棩鏈熶负浠婂ぉ
                     _lastExecutionDate = today;
                 }
@@ -734,5 +736,175 @@
                 throw;
             }
         }
-    }
+
+
+
+
+            /// <summary>
+            /// 閫掑綊鑾峰彇鏂囦欢淇℃伅
+            /// </summary>
+            /// <param name="dirPath"></param>
+            /// <returns></returns>
+            private DirInfo GetDirInfo(string dirPath)
+            {
+                //褰撳墠鏂囦欢澶�
+                var dirInfo = new DirInfo();
+                dirInfo.dirName = Path.GetFileName(dirPath);
+
+                //瀛愭枃浠�
+                List<FileDataInfo> files = new List<FileDataInfo>();
+                foreach (var file in Directory.GetFiles(dirPath))
+                {
+                    files.Add(new FileDataInfo()
+                    {
+                        filePath = file,
+                        fileName = Path.GetFileName(file)
+                    });
+                }
+
+                //瀛愭枃浠跺す
+                var dirs = Directory.GetDirectories(dirPath);
+                dirInfo.dirs = new List<DirInfo>();
+                foreach (var dir in dirs)
+                {
+                    dirInfo.dirs.Add(GetDirInfo(dir));
+                }
+
+                //瀛愭枃浠跺す锛屼笌瀛愮洰褰曞悎骞�
+                foreach (var file in files)
+                {
+                    dirInfo.dirs.Add(new DirInfo() { dirPath = file.filePath, dirName = file.fileName });
+                }
+                return dirInfo;
+            }
+
+            /// <summary>
+            /// 鑾峰彇鏃ュ織鏂囦欢鍒楄〃
+            /// </summary>
+            /// <returns></returns>
+            public WebResponseContent GetLogList()
+            {
+                WebResponseContent content = new WebResponseContent();
+                string path = Path.Combine(AppContext.BaseDirectory, "log");
+                if (!Directory.Exists(path))
+                {
+                    return content.Error("鏆傛棤鏃ュ織鏂囦欢");
+                }
+
+                content.Data = GetDirInfo(path);
+                content.OK();
+                return content;
+            }
+
+            /// <summary>
+            /// 鑾峰彇鏂囦欢鍐呭
+            /// </summary>
+            /// <param name="parm"></param>
+            /// <returns></returns>
+            public WebResponseContent GetLogData(GetLogParm parm)
+            {
+                WebResponseContent content = new WebResponseContent();
+                string res = "";
+                //鏄惁璇诲彇鍒版渶鍚�
+                bool isEnd = false;
+                long startIndex = 0;
+                //鏂囦欢澶у皬
+                long len = 0;
+                try
+                {
+                if (!File.Exists(parm.path))
+                {
+                        throw new Exception($"鏂囦欢{parm.path}涓嶅瓨鍦紒");
+                    }
+                    using (FileStream fs = new FileStream(parm.path, FileMode.Open, FileAccess.Read, FileShare.Read))
+                    {
+                        //鏈�澶ц鍙栧ぇ灏�
+                        int maxsize = (int)(1024 * parm.maxsize_KB);
+                        len = fs.Length;
+                        long startPos = (long)(len * (parm.percent / 100));//璧峰浣嶇疆
+                        long readLen = len - startPos;//璇诲彇闀垮害
+
+                        //鍚戝墠鍔犺浇
+                        if (parm.topStartPos != 0)
+                        {
+                            startPos = parm.topStartPos - maxsize;
+                            if (startPos < 0)
+                            {
+                                //宸茶鍒拌捣濮嬩綅
+                                startPos = 0;
+                                readLen = parm.topStartPos;
+                            }
+                            else
+                            {
+                                readLen = maxsize;
+                            }
+                        }
+                        else
+                        {
+                            //璇诲彇澶у皬鏄惁瓒呭嚭鏈�澶ч暱搴�
+                            if (readLen > maxsize)
+                            {
+                                readLen = maxsize;
+                            }
+                            else
+                            {
+                                isEnd = true;
+                            }
+                        }
+
+                        //鍔犺浇100%锛屾寜鏈�澶у唴瀹硅鍙�
+                        if (parm.percent == 100)
+                        {
+                            if (len < maxsize)
+                            {
+                                startPos = 0;
+                                readLen = len;
+                            }
+                            else
+                            {
+                                startPos = len - maxsize;
+                                readLen = maxsize;
+                            }
+                        }
+
+                        fs.Seek(startPos, SeekOrigin.Begin);
+                        var buffer = new byte[readLen];
+                        fs.Read(buffer, 0, (int)readLen);
+
+                        startIndex = startPos;
+                        if (startPos != 0 && (parm.percent != 0 || parm.topStartPos != 0))
+                        {
+                            //涓嶆槸浠庡ご鍔犺浇锛屽垹闄ゅ彲鑳戒笉瀹屾暣鐨勭涓�琛�
+                            int skipCount = 0;
+                            for (int i = 0; i < buffer.Length; i++)
+                            {
+                                if (buffer[i] == 10)
+                                {
+                                    skipCount = i;
+                                    break;
+                                }
+                            }
+                            if (skipCount != 0)
+                            {
+                                //鍘绘帀鎹㈣
+                                skipCount++;
+                                //涓嬫璇诲彇鍓嶅欢
+                                startIndex += skipCount;
+                            }
+                            res = Encoding.UTF8.GetString(buffer.Skip(skipCount).ToArray());
+                        }
+                        else
+                        {
+                            res = Encoding.UTF8.GetString(buffer);
+                        }
+                    }
+                }
+                catch (Exception ex)
+                {
+                    return content.Error(ex.Message);
+                }
+                return content.OK(data: new { content = res, isEnd, startIndex, len });
+            }
+        }
+
 }
\ No newline at end of file

--
Gitblit v1.9.3