using Common.DbExtends.Extends; using Common.DbExtends.Others; using Common.Models.JsonModels; using Common.Models.SubCountTables; using Common.Models.SubTables; using Common.Models.UnqTables; using Common.Utils; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Server.Timers { public class OldUserActivationTimer : MyTimer { private Client client = Client.SingleClient; SqlSugar.SqlSugarClient Db { get { return client.Db; } } private DateTime UpdateTime = DateTime.MinValue; protected override void Run(object state, bool timedOut) { var now = DateTime.Now; if (now.Hour == 4 || now.Hour == 5) { if (UpdateTime == DateTime.MinValue || UpdateTime.Day != now.Day) { try { UpdateTime = DateTime.Now; var robots = Db.Queryable().ToList(); var dbTables = Db.DbMaintenance.GetTableInfoList().Where(f => f.Name.StartsWith("userdata_")).ToList(); if (dbTables.Count == 0) return; foreach (var robot in robots) { var rebateConfig = Db.GetRebateConfigById(robot.ConfigRebateId); if (rebateConfig != null && rebateConfig.IsOldChange) { //排除掉设置的groupid和不自动归类的分组 var groupIds = Db.Queryable() .Where(f => f.Id != rebateConfig.GroupId && f.AotuSort == false) .Select(f => f.Id) .ToList(); var day = rebateConfig.UnuseDays; var lastTime = DateTime.Now.AddDays(-day); foreach (var item in dbTables) { var tabName = item.Name; var db = Db; db.CurrentConnectionConfig.ConfigureExternalServices.SplitTableService = new MySplitService(MySplitService.MySplitType.数量); db.Updateable() .SetColumns(f => f.GroupId == rebateConfig.GroupId) //.Where(f => f.LastBuyTime.AddDays(day) < DateTime.Now && f.CreateTime.AddDays(day) < DateTime.Now && !groupIds.Contains(f.GroupId)) .Where(f => f.LastBuyTime < lastTime && f.CreateTime < lastTime && !groupIds.Contains(f.GroupId)) .SplitTable(tab => tab.InTableNames(tabName)) .ExecuteCommand(); } } } } catch (Exception ex) { Db.OnLog("更改用户组", ex); throw; } } } } } }