This commit is contained in:
cli 2025-03-21 14:30:11 +08:00
parent e7f94ceae4
commit 49548768e6
4 changed files with 27 additions and 18 deletions

View File

@ -9,11 +9,14 @@ using Volo.Abp;
using System.Reflection;
using JiShe.CollectBus.FreeSql;
using System;
using JiShe.CollectBus.Common.Extensions;
using Volo.Abp.AspNetCore.Mvc.AntiForgery;
using JiShe.CollectBus.FreeRedisProvider;
using JiShe.CollectBus.Workers;
using Volo.Abp.BackgroundWorkers.Hangfire;
using JiShe.CollectBus.MongoDB;
using AutoMapper.Configuration.Annotations;
using JiShe.CollectBus.Common.Attributes;
namespace JiShe.CollectBus;
@ -49,10 +52,13 @@ public class CollectBusApplicationModule : AbpModule
{
var assembly = Assembly.GetExecutingAssembly();
var types = assembly.GetTypes().Where(t => typeof(ICollectWorker).IsAssignableFrom(t) && !t.IsInterface).ToList();
foreach (var type in types)
{
context.AddBackgroundWorkerAsync(type);
var ignoreJob = type.GetCustomAttribute<IgnoreJobAttribute>();
if (ignoreJob == null)
{
context.AddBackgroundWorkerAsync(type);
}
}
}

View File

@ -14,11 +14,6 @@ namespace JiShe.CollectBus.EnergySystem
{
public class CacheAppService : CollectBusAppService, ICacheAppService
{
//public async Task<V_FocusAmmeter> GetHashByKey(string key)
//{
// await FreeRedisProvider.Instance.HGetAsync<V_FocusAmmeter>(key,);
//}
public async Task SetHashByKey(string key)
{
var data = await SqlProvider.Instance.Change(DbEnum.EnergyDB).Select<V_FocusAmmeter>().ToListAsync();
@ -27,16 +22,7 @@ namespace JiShe.CollectBus.EnergySystem
foreach (var group in groupData)
{
try
{
var aa = group.ToDictionary(a => $"{a.ID}_{a.Address}" , b => b);
await FreeRedisProvider.Instance.HSetAsync($"{RedisConst.CacheAmmeterFocusKey}:{group.Key}", aa);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
await FreeRedisProvider.Instance.HSetAsync($"{RedisConst.CacheAmmeterFocusKey}:{group.Key}", group.ToDictionary(a => $"{a.ID}_{a.Address}", b => b));
}
}

View File

@ -1,6 +1,8 @@
using System.Threading;
using System;
using System.Threading;
using System.Threading.Tasks;
using Hangfire;
using JiShe.CollectBus.Common.Attributes;
using Microsoft.Extensions.Logging;
using Volo.Abp.BackgroundWorkers.Hangfire;
using Volo.Abp.DependencyInjection;
@ -8,6 +10,7 @@ using Volo.Abp.Uow;
namespace JiShe.CollectBus.Workers
{
[IgnoreJob]
public class EpiCollectWorker : HangfireBackgroundWorkerBase, ITransientDependency,ICollectWorker
{
private readonly ILogger<EpiCollectWorker> _logger;
@ -21,6 +24,7 @@ namespace JiShe.CollectBus.Workers
_logger = logger;
RecurringJobId = nameof(EpiCollectWorker);
CronExpression = Cron.Daily();
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JiShe.CollectBus.Common.Attributes
{
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public class IgnoreJobAttribute : Attribute
{
}
}