1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- using DBHelper;
- using Microsoft.EntityFrameworkCore;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using WCS.Core;
- using WCS.Entity;
- using WCS.Entity.Protocol;
- namespace WCS.Service
- {
- [Description("数据清理")]
- class DataClearHandler : LogicHandler
- {
- public override void Start()
- {
-
- }
- DateTime last = DateTime.MinValue;
- public override void Update(double milliseconds)
- {
- if ((DateTime.Now - last).TotalMilliseconds < 1000 * 60 * 60 * 24)
- return;
- last = DateTime.Now;
- DB.Do(db =>
- {
- db.Default.Database.ExecuteSqlRaw("delete WCS_EXCEPTION where datediff(dd,UPDATETIME,getdate())>7");
- var ps = db.Default.GetType().GetProperties();
- foreach (var p in ps)
- {
- if (!p.PropertyType.IsGenericType)
- continue;
- var tType = p.PropertyType.GenericTypeArguments[0];
- if (!tType.IsSubclassOf(typeof(WCS_PROTOCOLDATA)))
- continue;
- var sSql = $"Delete {tType.Name} where datediff(dd,Frame,getdate())>7";
- db.Default.Database.ExecuteSqlRaw(sSql);
- }
- });
- }
- }
- }
|