From 6ba24a49c009cca01d9c02b9dae692a53b8be116 Mon Sep 17 00:00:00 2001 From: huanghongfeng <huanghongfeng@hnkhzn.com> Date: 星期三, 24 九月 2025 13:58:30 +0800 Subject: [PATCH] 入库 --- 代码管理/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/LogJob.cs | 80 ++++++++++++++++++++++++++++++++-------- 1 files changed, 64 insertions(+), 16 deletions(-) diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/LogJob.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/LogJob.cs" index ebb0563..68e8fae 100644 --- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/LogJob.cs" +++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/LogJob.cs" @@ -1,11 +1,9 @@ 锘縰sing HslCommunication; using HslCommunication.Core; -using HslCommunication.WebSocket; using Microsoft.AspNetCore.Http; using Microsoft.VisualBasic.FileIO; using Newtonsoft.Json; using Quartz; -using Quartz.Util; using SixLabors.ImageSharp.PixelFormats; using System; using System.Collections.Generic; @@ -27,20 +25,19 @@ [DisallowConcurrentExecution] public class LogJob : IJob { - static object sendData = null; public Task Execute(IJobExecutionContext context) { try { - + Task.Run(() => { try { - while (true) - { - Run(5); - } + WriteLog.GetLog("LogJob").Write($"鏃ュ織璁板綍锛歿DateTime.Now}", "LogJob"); + Run(10); + Run2(10); + Thread.Sleep(1000 * 10); } catch { } }); @@ -55,18 +52,69 @@ } private static void Run(int saveDays) { - sendData = new { code = "1002", Messagest = $"杞﹁疆SN鍙凤細123123123" }; - CacheData.WebSocket.PublishAllClientPayload(sendData.Serialize()); + var logPath = System.Environment.CurrentDirectory + "/log"; + if (Directory.Exists(logPath)) + { + var nowTime = DateTime.Now; + var dayDir = Directory.GetDirectories(logPath, "20*", System.IO.SearchOption.AllDirectories); + + foreach (var dirpath in dayDir) + { + //鏂囦欢澶瑰悕 + var dirName = Path.GetFileName(dirpath).Replace("_", "-"); + + DateTime targetDate = DateTime.ParseExact(dirName, "yyyyMMdd", null); + if ((nowTime - targetDate).TotalDays >= saveDays) + { + + //鍒犻櫎鏂囦欢鍜屾枃浠跺す + try + { + var flies = Directory.GetFiles(dirpath); + + foreach (var item in flies) + { + File.Delete(item); + } + Directory.Delete(dirpath); + } + catch { } + } + } + } } - public class CacheData + private static void Run2(int saveDays) { - public static WebSocketServer WebSocket = new WebSocketServer(); - - public static void StartServer() + var logPath = System.Environment.CurrentDirectory + "/txt"; + if (Directory.Exists(logPath)) { - WebSocket = new WebSocketServer(); - WebSocket.ServerStart(1880); + var nowTime = DateTime.Now; + var dayDir = Directory.GetDirectories(logPath, "20*", System.IO.SearchOption.AllDirectories); + + foreach (var dirpath in dayDir) + { + //鏂囦欢澶瑰悕 + var dirName = Path.GetFileName(dirpath).Replace("_", "-"); + + DateTime targetDate = DateTime.ParseExact(dirName, "yyyyMMdd", null); + if ((nowTime - targetDate).TotalDays >= saveDays) + { + + //鍒犻櫎鏂囦欢鍜屾枃浠跺す + try + { + var flies = Directory.GetFiles(dirpath); + + foreach (var item in flies) + { + File.Delete(item); + } + Directory.Delete(dirpath); + } + catch { } + } + } } } } -- Gitblit v1.9.3