| | |
| | | using System; |
| | | using 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; |
| | |
| | | { |
| | | 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天åä¸URL为ç¹å®å°åçæ¥å¿) |
| | | 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}"); |
| | | // åçé误æ¶ä¸æ´æ°æåæ§è¡æ¥æï¼ä»¥ä¾¿éè¯ |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |