fix: 修复定时任务
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user