From 1581189aad05d97267d240a65e0215f4946130e5 Mon Sep 17 00:00:00 2001
From: xiazhengtongxue <133085197+xiazhengtongxue@users.noreply.github.com>
Date: 星期四, 12 三月 2026 15:29:30 +0800
Subject: [PATCH] feat: 新增异常任务处理按钮 fix: 修复任务取消bug,按照分组取消。 refactor: 重构日志为文本,减少数据库压力

---
 项目代码/WCSServices/WIDESEAWCS_SystemServices/Sys_LogService.cs |  177 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 174 insertions(+), 3 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..ce0fd89 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()
@@ -734,5 +735,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