130 lines
4.9 KiB
C#
130 lines
4.9 KiB
C#
|
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
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 商品黑名单同步
|
|||
|
/// </summary>
|
|||
|
public class GoodsBlackTimer : MyTimer
|
|||
|
{
|
|||
|
readonly Client Client = Client.SingleClient;
|
|||
|
private SqlSugar.SqlSugarClient Db => Client.Db;
|
|||
|
/// <summary>
|
|||
|
/// 运行
|
|||
|
/// </summary>
|
|||
|
/// <param name="state"></param>
|
|||
|
/// <param name="timedOut"></param>
|
|||
|
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);
|
|||
|
var info = db.Queryable<GoodsBlacklist>().Where(w => w.Platform == platform && w.GoodsId == item.GoodsId).First();
|
|||
|
if (info == null)
|
|||
|
{
|
|||
|
info = new GoodsBlacklist();
|
|||
|
info.Platform = platform;
|
|||
|
info.StoreName = item.StoreName;
|
|||
|
info.GoodsId = item.GoodsId;
|
|||
|
info.Remark = item.Remark;
|
|||
|
info.UpdateTime = DateTime.Now;
|
|||
|
info.IsDel = item.IsRemove;
|
|||
|
info.IsCloud = true;
|
|||
|
db.Insertable(info).ExecuteCommand();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (info.IsDel)
|
|||
|
{
|
|||
|
//如果本地已经删除,则忽略。
|
|||
|
continue;
|
|||
|
}
|
|||
|
info.IsDel = item.IsRemove;
|
|||
|
info.Remark = item.Remark;
|
|||
|
info.UpdateTime = DateTime.Now;
|
|||
|
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(CloudGoodsBlacklistResult item)
|
|||
|
{
|
|||
|
return LianmengTypeHelper.GetPlatformType(item.Platform);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 读取
|
|||
|
/// </summary>
|
|||
|
/// <param name="isAsc"></param>
|
|||
|
/// <param name="callback"></param>
|
|||
|
public static void ReadBlacklist(DateTime updateDateTime, bool isAsc, Func<List<CloudGoodsBlacklistResult>, int, int, bool> callback)
|
|||
|
{
|
|||
|
var size = 1000;
|
|||
|
var index = 1;
|
|||
|
while (true)
|
|||
|
{
|
|||
|
var res = YZCloudApiHelper.GetGoodsBlacklist(new GoodsBlacklistSearchPagingInput()
|
|||
|
{
|
|||
|
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++;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|