using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using Common.DbExtends.Extends; using Common.Models.Enums; using Common.Models.UnqTables; using Common.Utils; using Newtonsoft.Json.Linq; using Server.Controllers.Help; using Server.Utils; namespace Server.Timers { /// /// 商店黑名单同步 /// public class StoreBlackTimer : MyTimer { readonly Client Client = Client.SingleClient; private SqlSugar.SqlSugarClient Db => Client.Db; /// /// 运行 /// /// /// protected override void Run(object state, bool timedOut) { //YZCloudApiHelper.GetBlacklist() ReadBlacklist(Client.Config.RuntimeCache.GetPublicValue("玩家商店黑名单同步时间", () => DateTime.MinValue), false, (items, index, total) => { //Console.WriteLine("输出:" + index + "|" + total + "|" + items.Count); var db = Db; var syncTime = Client.Config.RuntimeCache.GetPublicValue("玩家商店黑名单同步时间", () => DateTime.MinValue); if (syncTime != DateTime.MinValue) { syncTime = syncTime.AddMinutes(-1); } bool issyncAdd = false; db.UseTran(() => { foreach (var item in items) { if (item.UpdateDateTime >= syncTime) { issyncAdd = true; var platform = GetPlatform(item); if (platform == LianmengType.无) { continue; } var info = db.Queryable().Where(w => w.Platform == platform && w.StoreId == item.StoreId).First(); if (info == null) { info = new StoreBlacklist(); info.Platform = platform; info.StoreName = item.StoreName; info.Remark = item.Remark; info.UpdateTime = DateTime.Now; info.IsDel = item.IsRemove; info.IsCloud = true; info.StoreId = item.StoreId; db.Insertable(info).ExecuteCommand(); } else { if (info.IsDel) { //如果本地已经删除,则忽略。 continue; } info.Remark = item.Remark; info.UpdateTime = DateTime.Now; info.IsDel = item.IsRemove; info.IsCloud = true; db.Updateable(info).ExecuteCommand(); } } } }, ex => db.OnLog("同步商店黑名单", ex)); if (issyncAdd) { Client.Config.RuntimeCache.SetPublicValue("玩家商店黑名单同步时间", items.LastOrDefault().UpdateDateTime); } return false; }); } private LianmengType GetPlatform(CloudStoreBlacklistResult item) { return LianmengTypeHelper.GetPlatformType(item.Platform); } /// /// 读取 /// /// /// public static void ReadBlacklist(DateTime updateDateTime, bool isAsc, Func, int, int, bool> callback) { var size = 1000; var index = 1; while (true) { var res = YZCloudApiHelper.GetStoreBlacklist(new StoreBlacklistSearchPagingInput() { PageIndex = index, PageSize = size, UserToken = "", IsAsc = isAsc, UpdateDateTime = updateDateTime, AuditState = AuditStateEmun.Succee }); if (res == null || res.Datas.Count <= 0) { break; } if (callback?.Invoke(res.Datas, index, res.PageNumber) == true) { break; } if (index <= 0) { break; } index++; } } } }