From 46908c0f79e7aab8a3fa41bfdcd8390bbc3659f2 Mon Sep 17 00:00:00 2001
From: xiazhengtongxue <133085197+xiazhengtongxue@users.noreply.github.com>
Date: 星期日, 04 一月 2026 11:48:15 +0800
Subject: [PATCH] 完善前端二期播种墙初始化和任务完成按钮,后端定期删除日志
---
项目代码/WCSServices/WIDESEAWCS_SystemServices/Sys_LogService.cs | 47 +++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 45 insertions(+), 2 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 fdb3067..5dc5329 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"
@@ -1,6 +1,8 @@
-锘縰sing System;
+锘縰sing NPOI.HSSF.Record;
+using System;
using System.Collections.Generic;
using System.Linq;
+using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Core.BaseServices;
@@ -12,8 +14,49 @@
{
public class Sys_LogService : ServiceBase<Sys_Log, ISys_LogRepository>, ISys_LogService
{
+ private static DateTime? _lastExecutionDate = null;
+ private readonly object _lock = new object();
+
public Sys_LogService(ISys_LogRepository BaseDal) : base(BaseDal)
{
+
+ }
+
+ public void DeleteOldLogs()
+ {
+ // 浣跨敤閿佺‘淇濈嚎绋嬪畨鍏�
+ lock (_lock)
+ {
+ var today = DateTime.Today;
+
+ // 妫�鏌ヤ粖澶╂槸鍚﹀凡缁忔墽琛岃繃
+ if (_lastExecutionDate.HasValue && _lastExecutionDate.Value.Date == today)
+ {
+ return;
+ }
+ try
+ {
+ // 璁$畻3涓湀鍓嶇殑鏃ユ湡
+ var threeMonthsAgo = DateTime.Now.AddMonths(-3);
+ // 璁$畻3澶╁墠鐨勬棩鏈�
+ var sevenDaysAgo = DateTime.Now.AddDays(-3);
+ // 鐗瑰畾URL
+ var specificUrl = "http://11.2.30.141:10870/interfaces/api/amr/robotQuery";
+
+ // 鏋勫缓鍒犻櫎鏉′欢锛�3涓湀鍓嶇殑鏃ュ織 鎴� (7澶╁墠涓擴RL涓虹壒瀹氬湴鍧�鐨勬棩蹇�)
+ var result = BaseDal.Db.Deleteable<Sys_Log>()
+ .Where(log => log.EndDate < threeMonthsAgo ||
+ (log.EndDate < sevenDaysAgo && log.Url == specificUrl))
+ .ExecuteCommand();
+ // 鏇存柊鏈�鍚庢墽琛屾棩鏈熶负浠婂ぉ
+ _lastExecutionDate = today;
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"鎵ц鏃ュ織娓呯悊鏃跺彂鐢熼敊璇細{ex.Message}");
+ // 鍙戠敓閿欒鏃朵笉鏇存柊鏈�鍚庢墽琛屾棩鏈燂紝浠ヤ究閲嶈瘯
+ }
+ }
}
}
-}
+}
\ No newline at end of file
--
Gitblit v1.9.3