fix: 修复定时任务
This commit is contained in:
@@ -27,7 +27,7 @@ public class AccessLogCacheJob : QuartzBackgroundWorkerBase
|
||||
|
||||
//每10秒执行一次,将本地缓存转入redis,防止丢数据
|
||||
Trigger = TriggerBuilder.Create().WithIdentity(nameof(AccessLogCacheJob))
|
||||
.WithSimpleSchedule((schedule) => { schedule.WithInterval(TimeSpan.FromSeconds(10)).RepeatForever();; })
|
||||
.WithSimpleSchedule((schedule) => { schedule.WithInterval(TimeSpan.FromSeconds(10)).RepeatForever(); })
|
||||
.Build();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Quartz;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Quartz;
|
||||
using Volo.Abp.BackgroundWorkers.Quartz;
|
||||
using Yi.Framework.DigitalCollectibles.Domain.Entities;
|
||||
using Yi.Framework.DigitalCollectibles.Domain.Managers;
|
||||
@@ -12,15 +13,18 @@ namespace Yi.Framework.DigitalCollectibles.Application.Jobs;
|
||||
public class OnHookAutoMiningJob : QuartzBackgroundWorkerBase
|
||||
{
|
||||
private readonly MiningPoolManager _miningPoolManager;
|
||||
private readonly ILogger<OnHookAutoMiningJob> _logger;
|
||||
|
||||
public OnHookAutoMiningJob(MiningPoolManager miningPoolManager)
|
||||
public OnHookAutoMiningJob(MiningPoolManager miningPoolManager, ILogger<OnHookAutoMiningJob> logger)
|
||||
{
|
||||
_miningPoolManager = miningPoolManager;
|
||||
JobDetail = JobBuilder.Create<AutoRefreshMiningPoolJob>().WithIdentity(nameof(AutoRefreshMiningPoolJob))
|
||||
_logger = logger;
|
||||
JobDetail = JobBuilder.Create<OnHookAutoMiningJob>().WithIdentity(nameof(OnHookAutoMiningJob))
|
||||
.Build();
|
||||
|
||||
//每小时执行一次
|
||||
Trigger = TriggerBuilder.Create().WithIdentity(nameof(AutoRefreshMiningPoolJob))
|
||||
Trigger = TriggerBuilder.Create().WithIdentity(nameof(OnHookAutoMiningJob))
|
||||
// .WithCronSchedule("10 * * * * ?")
|
||||
.WithCronSchedule("0 0 * * * ?")
|
||||
.Build();
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ public class CollectiblesService : ApplicationService
|
||||
input.StartTime is not null && input.EndTime is not null,
|
||||
u => u.CreationTime >= input.StartTime && u.CreationTime <= input.EndTime)
|
||||
.LeftJoin<CollectiblesAggregateRoot>((u, c) => u.CollectiblesId == c.Id)
|
||||
.OrderBy((u, c) => c.OrderNum)
|
||||
.OrderBy((u, c) => c.CreationTime)
|
||||
.GroupBy((u, c) => u.CollectiblesId)
|
||||
.Select((u, c) =>
|
||||
new CollectiblesUserGetOutputDto
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Volo.Abp.Application.Services;
|
||||
using Volo.Abp.Users;
|
||||
using Yi.Framework.DigitalCollectibles.Domain.Entities;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
namespace Yi.Framework.DigitalCollectibles.Application.Services;
|
||||
|
||||
/// <summary>
|
||||
/// 邀请码应用服务
|
||||
/// </summary>
|
||||
public class InvitationCodeService : ApplicationService
|
||||
{
|
||||
private readonly ISqlSugarRepository<InvitationCodeAggregateRoot> _repository;
|
||||
|
||||
public InvitationCodeService(ISqlSugarRepository<InvitationCodeAggregateRoot> repository)
|
||||
{
|
||||
_repository = repository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询当前登录用户的邀请码数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Authorize]
|
||||
public async Task<object> GetAsync()
|
||||
{
|
||||
var userId = CurrentUser.GetId();
|
||||
var entity = await _repository.GetFirstAsync(x => x.UserId == userId);
|
||||
if (entity is null)
|
||||
{
|
||||
return new { IsInvited=false, PointsNumber=0 };
|
||||
}
|
||||
|
||||
return new { entity.IsInvited, entity.PointsNumber };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当前用户填写邀请码
|
||||
/// </summary>
|
||||
/// <param name="invitedUserId"></param>
|
||||
/// <exception cref="UserFriendlyException"></exception>
|
||||
[Authorize]
|
||||
public async Task SetAsync([FromQuery] Guid invitedUserId)
|
||||
{
|
||||
var userId = CurrentUser.GetId();
|
||||
var entity = await _repository.GetFirstAsync(x => x.UserId == userId);
|
||||
if (entity is null)
|
||||
{
|
||||
await _repository.InsertAsync(new InvitationCodeAggregateRoot
|
||||
{
|
||||
UserId = userId,
|
||||
IsInvited = true,
|
||||
PointsNumber = 0
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
if (entity.IsInvited)
|
||||
{
|
||||
throw new UserFriendlyException("你已填写过邀请码,无法再次填写");
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.IsInvited = false;
|
||||
await _repository.UpdateAsync(entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var invitedEntity = await _repository.GetFirstAsync(x => x.UserId == invitedUserId);
|
||||
|
||||
if (entity is null)
|
||||
{
|
||||
await _repository.InsertAsync(new InvitationCodeAggregateRoot
|
||||
{
|
||||
UserId = invitedUserId,
|
||||
IsInvited = false,
|
||||
PointsNumber = 1
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
invitedEntity.PointsNumber += 1;
|
||||
await _repository.UpdateAsync(invitedEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,6 @@ public class CollectiblesRecordService : ApplicationService
|
||||
var output = await _miningPoolRecordRepository._DbQueryable.WhereIF(input.StartTime is not null && input.EndTime is not null,
|
||||
x => x.CreationTime >= input.StartTime && x.CreationTime <= input.EndTime)
|
||||
.Where(x => x.UserId == userId)
|
||||
.OrderByDescending(x => x.CreationTime)
|
||||
.LeftJoin<CollectiblesAggregateRoot>((x, c) => x.CollectiblesId==c.Id)
|
||||
.Select((x, c) =>
|
||||
new MiningPoolRecordDto
|
||||
@@ -58,6 +57,7 @@ public class CollectiblesRecordService : ApplicationService
|
||||
|
||||
}
|
||||
)
|
||||
.OrderByDescending(x => x.CreationTime)
|
||||
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
|
||||
|
||||
return new PagedResultDto<MiningPoolRecordDto>(total,output);
|
||||
@@ -78,7 +78,7 @@ public class CollectiblesRecordService : ApplicationService
|
||||
|
||||
//交易:是购买和出售,都需要展示
|
||||
.Where(x => x.SellUserId == userId||x.BuyId ==userId)
|
||||
.OrderByDescending(x => x.CreationTime)
|
||||
|
||||
.LeftJoin<CollectiblesAggregateRoot>((x, c) => x.CollectiblesId==c.Id)
|
||||
.Select((x, c) =>
|
||||
new MarketRecordDto
|
||||
@@ -104,6 +104,7 @@ public class CollectiblesRecordService : ApplicationService
|
||||
},
|
||||
}
|
||||
)
|
||||
.OrderByDescending(x => x.CreationTime)
|
||||
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
|
||||
|
||||
foreach (var dto in output)
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
using System.IO.Compression;
|
||||
using FreeRedis;
|
||||
using Volo.Abp.Application.Services;
|
||||
using Volo.Abp.Caching;
|
||||
using Yi.Framework.DigitalCollectibles.Domain.Entities;
|
||||
using Yi.Framework.DigitalCollectibles.Domain.Entities.Record;
|
||||
using Yi.Framework.DigitalCollectibles.Domain.Shared.Consts;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
@@ -9,10 +12,15 @@ namespace Yi.Framework.DigitalCollectibles.Application.Services.Tool;
|
||||
public class CollectiblesToolService : ApplicationService
|
||||
{
|
||||
private ISqlSugarRepository<CollectiblesAggregateRoot> _repository;
|
||||
private ISqlSugarRepository<MiningPoolRecordAggregateRoot> _recordRepository;
|
||||
|
||||
public CollectiblesToolService(ISqlSugarRepository<CollectiblesAggregateRoot> repository)
|
||||
private IRedisClient RedisClient => LazyServiceProvider.LazyGetRequiredService<IRedisClient>();
|
||||
|
||||
public CollectiblesToolService(ISqlSugarRepository<CollectiblesAggregateRoot> repository,
|
||||
ISqlSugarRepository<MiningPoolRecordAggregateRoot> recordRepository)
|
||||
{
|
||||
_repository = repository;
|
||||
_recordRepository = recordRepository;
|
||||
}
|
||||
|
||||
public async Task<object> DeleteInitAsync()
|
||||
@@ -32,7 +40,7 @@ public class CollectiblesToolService : ApplicationService
|
||||
ZipFile.ExtractToDirectory(dataPath, directoryPath, true); // true 表示覆盖已有文件
|
||||
|
||||
|
||||
var txtPath = Path.Combine("wwwroot", "dc","data", "data.txt");
|
||||
var txtPath = Path.Combine("wwwroot", "dc", "data", "data.txt");
|
||||
if (!File.Exists(txtPath))
|
||||
{
|
||||
throw new UserFriendlyException($"{txtPath}路径不存在文本");
|
||||
@@ -49,16 +57,17 @@ public class CollectiblesToolService : ApplicationService
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var items = line.Split(",").ToList();
|
||||
|
||||
|
||||
if (items.Count!=6)
|
||||
if (items.Count != 6)
|
||||
{
|
||||
errData.Add($"{i}行数据存,数据不对,只能6个数据");
|
||||
}
|
||||
|
||||
|
||||
var fileName = items[0];
|
||||
var code = Path.GetFileNameWithoutExtension(fileName) ;
|
||||
var code = Path.GetFileNameWithoutExtension(fileName);
|
||||
var name = items[1];
|
||||
var value = decimal.Parse(items[2]);
|
||||
var url = $"https://ccnetcore.com/prod-api/wwwroot/dc/data/{fileName}";
|
||||
@@ -79,19 +88,17 @@ public class CollectiblesToolService : ApplicationService
|
||||
};
|
||||
entities.Add(entity);
|
||||
|
||||
if (!File.Exists(Path.Combine(directoryPath,fileName)))
|
||||
if (!File.Exists(Path.Combine(directoryPath, fileName)))
|
||||
{
|
||||
errData.Add($"文件不存在:{Path.Combine(directoryPath,fileName)}");
|
||||
errData.Add($"文件不存在:{Path.Combine(directoryPath, fileName)}");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (errData.Any())
|
||||
{
|
||||
return new { ok = false, errData };
|
||||
}
|
||||
|
||||
|
||||
var allCode = await _repository._DbQueryable.Select(x => x.Code).ToListAsync();
|
||||
|
||||
var existCodes = allCode.Intersect(entities.Select(x => x.Code)).ToList();
|
||||
@@ -99,9 +106,46 @@ public class CollectiblesToolService : ApplicationService
|
||||
{
|
||||
return new { ok = false, existCodes };
|
||||
}
|
||||
|
||||
|
||||
|
||||
await _repository.InsertRangeAsync(entities);
|
||||
return new { ok = true,entities };
|
||||
return new { ok = true, entities };
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 跑马灯内容
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<string>> GetNoticeAsync()
|
||||
{
|
||||
//获取最新的3条挖矿记录,高级
|
||||
var record = await _recordRepository._DbQueryable
|
||||
.LeftJoin<CollectiblesAggregateRoot>((x, c) => x.CollectiblesId == c.Id)
|
||||
.Where((x,c)=>c.Rarity>=RarityEnum.Senior)
|
||||
.OrderByDescending((x, c) => x.CreationTime)
|
||||
.Select((x, c) => new
|
||||
{
|
||||
c.Name,
|
||||
c.ValueNumber,
|
||||
c.Rarity
|
||||
})
|
||||
.ToPageListAsync(1, 3);
|
||||
|
||||
var output = new List<string>();
|
||||
|
||||
var firstNoticeOrNull = await RedisClient.GetAsync("Yi:Notice");
|
||||
if (firstNoticeOrNull is not null)
|
||||
{
|
||||
output.Add(firstNoticeOrNull);
|
||||
}
|
||||
|
||||
foreach (var item in record)
|
||||
{
|
||||
output.Add($"恭喜神秘用户,挖到【{item.Rarity.GetRarityName()}-{item.Name}】,价值【{(int)(item.ValueNumber)}】");
|
||||
}
|
||||
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,23 @@ public enum RarityEnum
|
||||
|
||||
public static class RarityEnumExtensions
|
||||
{
|
||||
public static string GetRarityName(this RarityEnum enumValue)
|
||||
{
|
||||
// 获取枚举类型
|
||||
Type type = enumValue.GetType();
|
||||
|
||||
// 获取当前枚举值的 FieldInfo
|
||||
FieldInfo fieldInfo = type.GetField(enumValue.ToString());
|
||||
|
||||
// 获取 Display 特性
|
||||
DisplayAttribute displayAttribute = fieldInfo
|
||||
.GetCustomAttributes(typeof(DisplayAttribute), false)
|
||||
.FirstOrDefault() as DisplayAttribute;
|
||||
|
||||
// 返回名称,如果没有找到,则返回枚举值的名称
|
||||
return displayAttribute?.Name ?? enumValue.ToString();
|
||||
}
|
||||
|
||||
private static T GetAttribute<T>(RarityEnum rarity) where T : Attribute
|
||||
{
|
||||
var fieldInfo = typeof(RarityEnum).GetField(rarity.ToString());
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using FreeRedis;
|
||||
using Microsoft.Extensions.Caching.Distributed;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Volo.Abp.Caching;
|
||||
using Volo.Abp.Domain.Services;
|
||||
using Volo.Abp.EventBus.Local;
|
||||
@@ -27,6 +28,7 @@ public class MiningPoolManager : DomainService
|
||||
private readonly IDistributedCache<MiningPoolContent?> _miningPoolCache;
|
||||
private readonly IDistributedCache<UserMiningLimitCacheDto?> _userMiningLimitCache;
|
||||
private readonly ISqlSugarRepository<CollectiblesUserStoreAggregateRoot> _userStoreRepository;
|
||||
private readonly ILogger<MiningPoolManager> _logger;
|
||||
private IRedisClient RedisClient => LazyServiceProvider.LazyGetRequiredService<IRedisClient>();
|
||||
private ILocalEventBus LocalEventBus => LazyServiceProvider.LazyGetRequiredService<ILocalEventBus>();
|
||||
|
||||
@@ -34,7 +36,7 @@ public class MiningPoolManager : DomainService
|
||||
ISqlSugarRepository<CollectiblesAggregateRoot> collectiblesRepository,
|
||||
ISqlSugarRepository<OnHookAggregateRoot> onHookRepository,
|
||||
ISqlSugarRepository<CollectiblesUserStoreAggregateRoot> userStoreRepository,
|
||||
IDistributedCache<UserMiningLimitCacheDto> userMiningLimitCache)
|
||||
IDistributedCache<UserMiningLimitCacheDto> userMiningLimitCache, ILogger<MiningPoolManager> logger)
|
||||
{
|
||||
_settingProvider = settingProvider;
|
||||
this._miningPoolCache = miningPoolCache;
|
||||
@@ -42,6 +44,7 @@ public class MiningPoolManager : DomainService
|
||||
_onHookRepository = onHookRepository;
|
||||
_userStoreRepository = userStoreRepository;
|
||||
_userMiningLimitCache = userMiningLimitCache;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -270,7 +273,15 @@ public class MiningPoolManager : DomainService
|
||||
var userOnHookDic = currentOnHook.GroupBy(x => x.UserId).ToDictionary(x => x.Key, y => y.First());
|
||||
foreach (var onHookItem in userOnHookDic)
|
||||
{
|
||||
await MiningAsync(onHookItem.Value.UserId);
|
||||
try
|
||||
{
|
||||
await MiningAsync(onHookItem.Value.UserId);
|
||||
}
|
||||
catch (UserFriendlyException e)
|
||||
{
|
||||
_logger.LogInformation($"自动挖矿-{onHookItem.Value.UserId},{e.Message}");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user