@@ -5,6 +5,9 @@ | |||
<Nullable>enable</Nullable> | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
</PropertyGroup> | |||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> | |||
<NoWarn>1701;1702;8602</NoWarn> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.0.0" /> | |||
<PackageReference Include="BPA.Component.MongoClient" Version="1.0.12" /> | |||
@@ -8,7 +8,9 @@ using BPA.Component.Extensions; | |||
using BPA.Component.LogClient.Extensions; | |||
using BPA.Component.SDKCommon; | |||
using BPA.Component.WebApiExtensions.Extensions; | |||
using BPA.SaaS.TaskSchedule.Api.DTO; | |||
using BPA.SaaS.TaskSchedule.Api.Model; | |||
using BPA.SaaS.TaskSchedule.Api.Repository; | |||
using BPA.SaaS.TaskSchedule.Api.Service; | |||
using BPA.SaaS.TaskSchedule.Api.Service.QzScheduler; | |||
using BPA.SaaS.TaskSchedule.Api.Service.WarnAlarms; | |||
@@ -58,13 +60,14 @@ public static class SetupBootstrap | |||
services.AddControllersWithViews(mvcOptions => { mvcOptions.AddDefaultMvcOptions(true); }).AddRazorRuntimeCompilation(); | |||
services.AddEndpointsApiExplorer(); | |||
services.AddServiceSDK(_configuration); | |||
services.AddLangPackage<TaskScheduleLangPackge>(); | |||
services.AddHealthChecks(); | |||
services.SetupTaskSchedule(); | |||
services.AddHttpClient(typeof(SynRequestHttpJobScheduler).FullName); | |||
services.AddHttpClient(typeof(AnyTimeTaskScheduleExecutorService).FullName); | |||
services.AddHttpClient(typeof(WechatWebhookWarnAlarm).FullName); | |||
// services.AddCap(x => | |||
// { | |||
// var config = services.GetPreConfig(args); | |||
@@ -99,16 +102,17 @@ public static class SetupBootstrap | |||
public static ContainerBuilder SetupConfigureContainer(this ContainerBuilder builder) | |||
{ | |||
// 注入DB | |||
// builder.RegisterType<TaskScheduleDbSugarClient>().InstancePerLifetimeScope(); | |||
// // 服务层 | |||
// builder.RegisterAssemblyTypes(typeof(HomeService).Assembly) | |||
// .Where(t => t.Name.EndsWith("Service")) | |||
// .AsImplementedInterfaces(); | |||
// | |||
// // 仓储层 | |||
// builder.RegisterAssemblyTypes(typeof(HomeRepository).Assembly) | |||
// .Where(t => t.Name.EndsWith("Repository")) | |||
// .AsImplementedInterfaces(); | |||
builder.RegisterType<TaskScheduleMongoDbClient>().InstancePerLifetimeScope(); | |||
// 服务层 | |||
builder.RegisterAssemblyTypes(typeof(SystemDictionaryService).Assembly) | |||
.Where(t => t.Name.EndsWith("Service")) | |||
.AsImplementedInterfaces(); | |||
// 仓储层 | |||
builder.RegisterAssemblyTypes(typeof(SystemDictionaryRepository).Assembly) | |||
.Where(t => t.Name.EndsWith("Repository")) | |||
.AsImplementedInterfaces(); | |||
return builder; | |||
} | |||
@@ -124,6 +128,7 @@ public static class SetupBootstrap | |||
serviceProvider.PreHeatRunRabbitMQ(); | |||
serviceProvider.SetDebug(true); | |||
serviceProvider.GetService<ICapPublisher>(); | |||
serviceProvider.PreHeatTaskSchedule(); | |||
} | |||
/// <summary> | |||
@@ -1,45 +1,78 @@ | |||
using BPA.Common.Infrastructure.BizLogs; | |||
using BPA.Common.Infrastructure.Queue; | |||
using BPA.Component.RabbitMQClient.Enums; | |||
using BPA.Component.RabbitMQClient.Extensions; | |||
using BPA.Component.RabbitMQClient.Provider; | |||
using BPA.SaaS.TaskSchedule.Api.IService; | |||
using BPA.SaaS.TaskSchedule.Api.Model; | |||
using BPA.SaaS.TaskSchedule.Api.Service.Queue; | |||
using Microsoft.Extensions.DependencyInjection; | |||
namespace BPA.SaaS.TaskSchedule.Api.Bootstrap | |||
namespace BPA.SaaS.TaskSchedule.Api.Bootstrap; | |||
/// <summary> | |||
/// RabbitMQ配置 | |||
/// </summary> | |||
public static class SetupRabbitMqConfig | |||
{ | |||
/// <summary> | |||
/// RabbitMQ配置 | |||
/// 使用消息队列 | |||
/// </summary> | |||
/// <param name="services"></param> | |||
/// <returns></returns> | |||
public static IServiceCollection AddRabbitMQ(this IServiceCollection services) | |||
{ | |||
services.AddRabbitMQProvider(sp => sp.GetService<TaskScheduleApiConfig>().RabbitMqConfig); | |||
services.AddRabbitMQProducer<BizLogProducer, BaseBizLogMsgBody>(); | |||
services.AddRabbitMQProducer<SynDataTaskScheduleProducer, SynDataTaskScheduleMsgBody>(); | |||
services.AddRabbitMQConsumer<SynDataTaskScheduleConsumer, SynDataTaskScheduleMsgBody>(); | |||
services.AddRabbitMQProducer<AnyTimeTaskScheduleProducer, AnyTimeTaskScheduleMsgBody>(); | |||
services.AddRabbitMQConsumer<AnyTimeTaskScheduleConsumer, AnyTimeTaskScheduleMsgBody>(); | |||
return services; | |||
} | |||
/// <summary> | |||
/// 预热消息队列 | |||
/// </summary> | |||
public static class SetupRabbitMqConfig | |||
/// <param name="serviceProvider"></param> | |||
/// <returns></returns> | |||
public static void PreHeatRunRabbitMQ(this IServiceProvider serviceProvider) | |||
{ | |||
/// <summary> | |||
/// 使用消息队列 | |||
/// </summary> | |||
/// <param name="services"></param> | |||
/// <returns></returns> | |||
public static IServiceCollection AddRabbitMQ(this IServiceCollection services) | |||
{ | |||
//注入 RabbitMQProvider | |||
services.AddRabbitMQProvider(sp => sp.GetService<TaskScheduleApiConfig>()?.RabbitMqConfig); | |||
//注入 业务日志 生产者 | |||
services.AddRabbitMQProducer<BizLogProducer, BaseBizLogMsgBody>(); | |||
return services; | |||
} | |||
/// <summary> | |||
/// 预热消息队列 | |||
/// </summary> | |||
/// <param name="serviceProvider"></param> | |||
/// <returns></returns> | |||
public static IServiceProvider PreHeatRunRabbitMQ(this IServiceProvider serviceProvider) | |||
{ | |||
var rabbitMqProvider = serviceProvider.UseRabbitMQProvider<RabbitMQProvider>(); | |||
var exchangeConfig = rabbitMqProvider.BuildExchangeConfig(MqNameConfig.BizLogExchange); | |||
exchangeConfig.UseExchange(); | |||
exchangeConfig.UseProducer<BaseBizLogMsgBody, BizLogProducer>(); | |||
return serviceProvider; | |||
} | |||
var rabbitMqProvider = serviceProvider.UseRabbitMQProvider<RabbitMQProvider>(); | |||
var exchangeConfig = rabbitMqProvider.BuildExchangeConfig(MqNameConfig.BizLogExchange); | |||
exchangeConfig.UseExchange(); | |||
exchangeConfig.UseProducer<BaseBizLogMsgBody, BizLogProducer>(); | |||
#region SynData | |||
var synDataExchangeConfig = rabbitMqProvider.BuildExchangeConfig(MqNameConfig.SynDataTaskScheduleExchange, | |||
ExchangeType.Fanout); | |||
synDataExchangeConfig.UseExchange(); | |||
synDataExchangeConfig.UseProducer<SynDataTaskScheduleMsgBody, SynDataTaskScheduleProducer>(); | |||
var synDataQueueConfig = rabbitMqProvider.BuildQueueConfig(MqNameConfig.SynDataTaskScheduleQueue, | |||
MqNameConfig.SynDataTaskScheduleExchange); | |||
synDataQueueConfig.UseQueue(); | |||
synDataQueueConfig.UseConsumer<SynDataTaskScheduleMsgBody, SynDataTaskScheduleConsumer>(); | |||
#endregion | |||
#region AnyTime | |||
var anyTimeExchangeConfig = rabbitMqProvider.BuildExchangeConfig(MqNameConfig.AnyTimeTaskScheduleExchange, | |||
ExchangeType.X_Delayed_Message); | |||
anyTimeExchangeConfig.UseExchange(); | |||
anyTimeExchangeConfig.UseProducer<AnyTimeTaskScheduleMsgBody, AnyTimeTaskScheduleProducer>(); | |||
var anyTimeQueueConfig = rabbitMqProvider.BuildQueueConfig(MqNameConfig.AnyTimeTaskScheduleQueue, | |||
MqNameConfig.AnyTimeTaskScheduleExchange); | |||
anyTimeQueueConfig.UseQueue(); | |||
anyTimeQueueConfig.UseMultipleConsumer<AnyTimeTaskScheduleMsgBody, AnyTimeTaskScheduleConsumer>(5); | |||
#endregion | |||
} | |||
} |
@@ -31,13 +31,11 @@ namespace BPA.SaaS.TaskSchedule.Api.Bootstrap | |||
/// <param name="serviceProvider"></param> | |||
public static void PreHeatTaskSchedule(this IServiceProvider serviceProvider) | |||
{ | |||
//LogProvider.SetCurrentLogProvider(new QuartzLogProvider()); | |||
//初始化字典 | |||
serviceProvider.GetService<ISystemDictionaryService>().Start(); | |||
//启动任务 | |||
serviceProvider.GetService<ITaskInfoService>().Start(); | |||
//启动日志任务 | |||
//serviceProvider.GetService<ITaskLogService>().Start(); | |||
} | |||
} | |||
@@ -7,7 +7,7 @@ namespace BPA.SaaS.TaskSchedule.Api.IService | |||
/// <summary> | |||
/// 系统字典 | |||
/// </summary> | |||
public interface ISystemDictionaryService : ISynData | |||
public interface ISystemDictionaryService /*: ISynData*/ | |||
{ | |||
/// <summary> | |||
/// 保存 | |||
@@ -13,7 +13,7 @@ | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="BPA.Common.Enums" Version="1.0.8" /> | |||
<PackageReference Include="BPA.Common.Infrastructure" Version="1.0.11" /> | |||
<PackageReference Include="BPA.Common.Infrastructure" Version="1.0.12" /> | |||
<PackageReference Include="BPA.Component.ApolloClient" Version="1.0.9" /> | |||
<PackageReference Include="BPA.Component.DTOCommon" Version="1.0.11" /> | |||
<PackageReference Include="BPA.Component.LogClient" Version="1.0.3" /> | |||
@@ -2,7 +2,6 @@ | |||
using System.Net.NetworkInformation; | |||
using System.Net.Sockets; | |||
using BPA.Component.ApolloClient; | |||
using BPA.Component.DbClient; | |||
using BPA.Component.MongoClient; | |||
using BPA.Component.RabbitMQClient.Connection; | |||
using Com.Ctrip.Framework.Apollo; | |||
@@ -34,17 +33,11 @@ public class TaskScheduleApiConfig : ApolloBPAConfig<TaskScheduleApiConfig> | |||
[AutoWrite] | |||
public MongoConfig TaskScheduleMongoConfig { get; set; } | |||
/// <summary> | |||
/// 环境名称 测试 | 生产 | |||
/// </summary> | |||
[AutoWrite] | |||
public string EvnName { private set; get; } | |||
/// <summary> | |||
/// 报警器 | |||
/// </summary> | |||
[AutoWrite] | |||
public List<string> WarnAlarms { private set; get; } = new List<string>(); | |||
public List<string> WarnAlarms { private set; get; } = new(); | |||
/// <summary> | |||
/// 跟踪ID head名称 | |||
@@ -6,7 +6,7 @@ | |||
<ImplicitUsings>enable</ImplicitUsings> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="BPA.Common.Infrastructure" Version="1.0.11" /> | |||
<PackageReference Include="BPA.Common.Infrastructure" Version="1.0.12" /> | |||
<PackageReference Include="BPA.Component.DTOCommon" Version="1.0.11" /> | |||
<PackageReference Include="BPA.Component.Extensions" Version="1.0.4" /> | |||
<PackageReference Include="BPA.Component.MongoClient" Version="1.0.12" /> | |||
@@ -30,7 +30,7 @@ namespace BPA.SaaS.TaskSchedule.Api.Service.Queue | |||
{ | |||
//字典 | |||
var service = scope.ServiceProvider.GetRequiredService<ISystemDictionaryService>(); | |||
service.OnDataChange(msgBody); | |||
// service.OnDataChange(msgBody); | |||
} | |||
else if (msgBody.DataType == 2) | |||
{ | |||
@@ -10,176 +10,173 @@ using BPA.SaaS.TaskSchedule.Api.Service.Queue; | |||
using Microsoft.Extensions.Caching.Memory; | |||
using Microsoft.Extensions.Options; | |||
namespace BPA.SaaS.TaskSchedule.Api.Service | |||
namespace BPA.SaaS.TaskSchedule.Api.Service; | |||
public class SystemDictionaryService : ISystemDictionaryService | |||
{ | |||
public class SystemDictionaryService : ISystemDictionaryService | |||
private readonly Lazy<ISystemDictionaryRepository> systemDictionaryRepository; | |||
private readonly TaskScheduleLangPackge langPackage; | |||
private static readonly MemoryCache memoryCache = new(Options.Create(new MemoryCacheOptions())); | |||
private readonly SynDataTaskScheduleProducer synDataTaskScheduleProducer; | |||
public SystemDictionaryService(TaskScheduleLangPackge langPackage, | |||
Lazy<ISystemDictionaryRepository> systemDictionaryRepository, | |||
SynDataTaskScheduleProducer synDataTaskScheduleProducer) | |||
{ | |||
private readonly Lazy<ISystemDictionaryRepository> systemDictionaryRepository; | |||
private readonly TaskScheduleLangPackge langPackge; | |||
private readonly static MemoryCache memoryCache = new MemoryCache(Options.Create(new MemoryCacheOptions())); | |||
private readonly SynDataTaskScheduleProducer synDataTaskScheduleProducer; | |||
this.langPackage = langPackage; | |||
this.systemDictionaryRepository = systemDictionaryRepository; | |||
this.synDataTaskScheduleProducer = synDataTaskScheduleProducer; | |||
} | |||
public SystemDictionaryService( | |||
TaskScheduleLangPackge langPackge, | |||
Lazy<ISystemDictionaryRepository> systemDictionaryRepository, | |||
SynDataTaskScheduleProducer synDataTaskScheduleProducer) | |||
/// <summary> | |||
/// 保存 | |||
/// </summary> | |||
/// <param name="req"></param> | |||
/// <returns></returns> | |||
public BaseResult Save(SaveSystemDictionaryReq req) | |||
{ | |||
if (req.IsNull()) | |||
return BaseResult.Build(langPackage.ParamInvalid); | |||
req.Key = req.Key.ToTrim(); | |||
var cmd = 1; | |||
if (req.Id == 0) | |||
{ | |||
this.langPackge = langPackge; | |||
this.systemDictionaryRepository = systemDictionaryRepository; | |||
this.synDataTaskScheduleProducer = synDataTaskScheduleProducer; | |||
var has = systemDictionaryRepository.Value.Queryable() | |||
.Any(x => x.Type == req.Type && x.Key == req.Key && x.IsDelete == false); | |||
if (has) | |||
return BaseResult.Build(langPackage.KeyExist); | |||
var entity = new CrmSystemDictionary | |||
{ | |||
Id = BPAUniqueIdBulder.NextLong(), | |||
Key = req.Key, | |||
Type = req.Type, | |||
Value = req.Value.ToTrim(), | |||
ValueExt = req.ValueExt.ToTrim(), | |||
IsDelete = false | |||
}; | |||
req.Id = entity.Id; | |||
systemDictionaryRepository.Value.Add(entity); | |||
cmd = 1; | |||
} | |||
/// <summary> | |||
/// 保存 | |||
/// </summary> | |||
/// <param name="req"></param> | |||
/// <returns></returns> | |||
public BaseResult Save(SaveSystemDictionaryReq req) | |||
else | |||
{ | |||
if (req.IsNull()) | |||
return BaseResult.Build(langPackge.ParamInvalid); | |||
req.Key = req.Key.ToTrim(); | |||
var cmd = 1; | |||
if (req.Id == 0) | |||
var entity = systemDictionaryRepository.Value.Queryable().FirstOrDefault(x => x.Id == req.Id && x.IsDelete == false); | |||
if (entity == null) | |||
return BaseResult.Build(langPackage.KeyNotExist); | |||
var has = systemDictionaryRepository.Value.Queryable() | |||
.Any(x => x.Id != req.Id && x.Type == req.Type && x.Key == req.Key && x.IsDelete == false); | |||
if (has) | |||
return BaseResult.Build(langPackage.KeyExist); | |||
req.Value = req.Value.ToTrim(); | |||
req.ValueExt = req.ValueExt.ToTrim(); | |||
systemDictionaryRepository.Value.UpdateOne(x => new CrmSystemDictionary | |||
{ | |||
var has = systemDictionaryRepository.Value.Queryable() | |||
.Any(x => x.Type == req.Type && x.Key == req.Key && x.IsDelete == false); | |||
if (has) | |||
return BaseResult.Build(langPackge.KeyExist); | |||
var entity = new CrmSystemDictionary | |||
{ | |||
Id = BPAUniqueIdBulder.NextLong(), | |||
Key = req.Key, | |||
Type = req.Type, | |||
Value = req.Value.ToTrim(), | |||
ValueExt = req.ValueExt.ToTrim(), | |||
IsDelete = false | |||
}; | |||
req.Id = entity.Id; | |||
systemDictionaryRepository.Value.Add(entity); | |||
cmd = 1; | |||
} | |||
else | |||
{ | |||
var entity = systemDictionaryRepository.Value.Queryable().FirstOrDefault(x => x.Id == req.Id && x.IsDelete == false); | |||
if (entity == null) | |||
return BaseResult.Build(langPackge.KeyNotExist); | |||
var has = systemDictionaryRepository.Value.Queryable() | |||
.Any(x => x.Id != req.Id && x.Type == req.Type && x.Key == req.Key && x.IsDelete == false); | |||
if (has) | |||
return BaseResult.Build(langPackge.KeyExist); | |||
req.Value = req.Value.ToTrim(); | |||
req.ValueExt = req.ValueExt.ToTrim(); | |||
systemDictionaryRepository.Value.UpdateOne(x => new CrmSystemDictionary | |||
{ | |||
Type = req.Type, | |||
Value = req.Value, | |||
ValueExt = req.ValueExt | |||
}, x => x.Id == req.Id); | |||
cmd = 2; | |||
} | |||
//触发数据改变 | |||
synDataTaskScheduleProducer.Enqueue(new SynDataTaskScheduleMsgBody {Cmd = cmd, DataId = req.Id, DataType = 1}); | |||
Thread.Sleep(1000); | |||
return BaseResult.BuildOK(); | |||
Type = req.Type, | |||
Value = req.Value, | |||
ValueExt = req.ValueExt | |||
}, x => x.Id == req.Id); | |||
cmd = 2; | |||
} | |||
/// <summary> | |||
/// 删除 | |||
/// </summary> | |||
/// <param name="req"></param> | |||
/// <returns></returns> | |||
public BaseResult Delete(DeleteSystemDictionaryReq req) | |||
{ | |||
var entity = systemDictionaryRepository.Value.Queryable().First(s => s.Id == req.Id); | |||
if (entity == null || entity.IsDelete) | |||
return BaseResult.Build(langPackge.KeyNotExist); | |||
//更改为删除 | |||
systemDictionaryRepository.Value.UpdateOne(x => new CrmSystemDictionary {IsDelete = true}, x => x.Id == req.Id); | |||
//触发数据改变 | |||
synDataTaskScheduleProducer.Enqueue(new SynDataTaskScheduleMsgBody {Cmd = 3, DataId = req.Id, DataType = 1}); | |||
Thread.Sleep(1000); | |||
return BaseResult.BuildOK(); | |||
} | |||
//触发数据改变 | |||
synDataTaskScheduleProducer.Enqueue(new SynDataTaskScheduleMsgBody {Cmd = cmd, DataId = req.Id, DataType = 1}); | |||
Thread.Sleep(1000); | |||
return BaseResult.BuildOK(); | |||
} | |||
/// <summary> | |||
/// 获取所有的 | |||
/// </summary> | |||
/// <returns></returns> | |||
public BaseResult<List<SystemDictionaryDTO>> GetAll() | |||
{ | |||
var rows = systemDictionaryRepository.Value.Queryable().Where(x => x.IsDelete == false).Select(x => new SystemDictionaryDTO | |||
{ | |||
Id = x.Id, | |||
Type = x.Type, | |||
Key = x.Key, | |||
Value = x.Value, | |||
ValueExt = x.ValueExt | |||
}).ToList(); | |||
return BaseResult<List<SystemDictionaryDTO>>.BuildOK(rows); | |||
} | |||
/// <summary> | |||
/// 删除 | |||
/// </summary> | |||
/// <param name="req"></param> | |||
/// <returns></returns> | |||
public BaseResult Delete(DeleteSystemDictionaryReq req) | |||
{ | |||
var entity = systemDictionaryRepository.Value.Queryable().First(s => s.Id == req.Id); | |||
if (entity == null || entity.IsDelete) | |||
return BaseResult.Build(langPackage.KeyNotExist); | |||
//更改为删除 | |||
systemDictionaryRepository.Value.UpdateOne(x => new CrmSystemDictionary {IsDelete = true}, x => x.Id == req.Id); | |||
//触发数据改变 | |||
synDataTaskScheduleProducer.Enqueue(new SynDataTaskScheduleMsgBody {Cmd = 3, DataId = req.Id, DataType = 1}); | |||
Thread.Sleep(1000); | |||
return BaseResult.BuildOK(); | |||
} | |||
/// <summary> | |||
/// 获取缓存的字典信息 | |||
/// </summary> | |||
/// <param name="type"></param> | |||
/// <param name="key"></param> | |||
/// <returns></returns> | |||
public SystemDictionaryDTO GetCache(EnumSystemDictionaryType type, string key) | |||
/// <summary> | |||
/// 获取所有的 | |||
/// </summary> | |||
/// <returns></returns> | |||
public BaseResult<List<SystemDictionaryDTO>> GetAll() | |||
{ | |||
var rows = systemDictionaryRepository.Value.Queryable().Where(x => x.IsDelete == false).Select(x => new SystemDictionaryDTO | |||
{ | |||
var rkey = TaskScheduleRedisKey.DictionaryKey(type, key); | |||
return memoryCache.Get<SystemDictionaryDTO>(rkey); | |||
} | |||
Id = x.Id, | |||
Type = x.Type, | |||
Key = x.Key, | |||
Value = x.Value, | |||
ValueExt = x.ValueExt | |||
}).ToList(); | |||
return BaseResult<List<SystemDictionaryDTO>>.BuildOK(rows); | |||
} | |||
/// <summary> | |||
/// 当数据改变 | |||
/// </summary> | |||
/// <param name="msgBody"></param> | |||
public void OnDataChange(SynDataTaskScheduleMsgBody msgBody) | |||
{ | |||
var entity = systemDictionaryRepository.Value.Queryable().FirstOrDefault(f => f.Id == msgBody.DataId); | |||
if (entity == null) return; | |||
var rkey = TaskScheduleRedisKey.DictionaryKey(entity.Type, entity.Key); | |||
if (entity.IsDelete) | |||
memoryCache.Remove(rkey); | |||
else | |||
memoryCache.Set(rkey, new SystemDictionaryDTO | |||
{ | |||
Id = entity.Id, | |||
Key = entity.Key, | |||
Type = entity.Type, | |||
Value = entity.Value, | |||
ValueExt = entity.ValueExt | |||
}); | |||
} | |||
/// <summary> | |||
/// 获取缓存的字典信息 | |||
/// </summary> | |||
/// <param name="type"></param> | |||
/// <param name="key"></param> | |||
/// <returns></returns> | |||
public SystemDictionaryDTO GetCache(EnumSystemDictionaryType type, string key) | |||
{ | |||
var rkey = TaskScheduleRedisKey.DictionaryKey(type, key); | |||
return memoryCache.Get<SystemDictionaryDTO>(rkey); | |||
} | |||
/// <summary> | |||
/// 启动执行一次 | |||
/// </summary> | |||
public void Start() | |||
{ | |||
// systemDictionaryRepository.Value.UpdateMany(x => new CrmSystemDictionary { IsDelete = false }, x => x.Id > 0); | |||
var rows = systemDictionaryRepository.Value.Queryable().Where(x => x.IsDelete == false).Select(x => new SystemDictionaryDTO | |||
/// <summary> | |||
/// 当数据改变 | |||
/// </summary> | |||
/// <param name="msgBody"></param> | |||
public void OnDataChange(SynDataTaskScheduleMsgBody msgBody) | |||
{ | |||
var entity = systemDictionaryRepository.Value.Queryable().FirstOrDefault(f => f.Id == msgBody.DataId); | |||
if (entity == null) return; | |||
var rkey = TaskScheduleRedisKey.DictionaryKey(entity.Type, entity.Key); | |||
if (entity.IsDelete) | |||
memoryCache.Remove(rkey); | |||
else | |||
memoryCache.Set(rkey, new SystemDictionaryDTO | |||
{ | |||
Id = x.Id, | |||
Type = x.Type, | |||
Key = x.Key, | |||
Value = x.Value, | |||
ValueExt = x.ValueExt | |||
}).ToList(); | |||
rows.Each(item => | |||
Id = entity.Id, | |||
Key = entity.Key, | |||
Type = entity.Type, | |||
Value = entity.Value, | |||
ValueExt = entity.ValueExt | |||
}); | |||
} | |||
/// <summary> | |||
/// 启动执行一次 | |||
/// </summary> | |||
public void Start() | |||
{ | |||
var rows = systemDictionaryRepository.Value.Queryable().Where(x => x.IsDelete == false).Select(x => new SystemDictionaryDTO | |||
{ | |||
Id = x.Id, | |||
Type = x.Type, | |||
Key = x.Key, | |||
Value = x.Value, | |||
ValueExt = x.ValueExt | |||
}).ToList(); | |||
rows.Each(item => | |||
{ | |||
var rkey = TaskScheduleRedisKey.DictionaryKey(item.Type, item.Key); | |||
memoryCache.Set(rkey, new SystemDictionaryDTO | |||
{ | |||
var rkey = TaskScheduleRedisKey.DictionaryKey(item.Type, item.Key); | |||
memoryCache.Set(rkey, new SystemDictionaryDTO | |||
{ | |||
Id = item.Id, | |||
Key = item.Key, | |||
Type = item.Type, | |||
Value = item.Value, | |||
ValueExt = item.ValueExt | |||
}); | |||
Id = item.Id, | |||
Key = item.Key, | |||
Type = item.Type, | |||
Value = item.Value, | |||
ValueExt = item.ValueExt | |||
}); | |||
} | |||
}); | |||
} | |||
} |
@@ -27,7 +27,7 @@ namespace BPA.SaaS.TaskSchedule.Api.Service | |||
{ | |||
private static readonly MemoryCache memoryCache = new(Options.Create(new MemoryCacheOptions())); | |||
private readonly Lazy<ITaskInfoRepository> taskInfoRepository; | |||
private readonly TaskScheduleLangPackge langPackge; | |||
private readonly TaskScheduleLangPackge langPackage; | |||
private readonly Lazy<SynRequestSchedulerManager> schedulerManager; | |||
private readonly Lazy<ITaskLogRepository> taskLogRepository; | |||
private readonly Lazy<ITaskLogService> taskLogService; | |||
@@ -38,8 +38,7 @@ namespace BPA.SaaS.TaskSchedule.Api.Service | |||
/// <summary> | |||
/// 构造方法 | |||
/// </summary> | |||
public TaskInfoService( | |||
TaskScheduleLangPackge langPackge, | |||
public TaskInfoService(TaskScheduleLangPackge langPackage, | |||
Lazy<ITaskInfoRepository> taskInfoRepository, | |||
Lazy<SynRequestSchedulerManager> schedulerManager, | |||
Lazy<ITaskLogRepository> taskLogRepository, | |||
@@ -48,7 +47,7 @@ namespace BPA.SaaS.TaskSchedule.Api.Service | |||
SynDataTaskScheduleProducer synDataTaskScheduleProducer, | |||
Lazy<ISystemDictionaryService> systemDictionaryService) | |||
{ | |||
this.langPackge = langPackge; | |||
this.langPackage = langPackage; | |||
this.taskInfoRepository = taskInfoRepository; | |||
this.schedulerManager = schedulerManager; | |||
this.taskLogRepository = taskLogRepository; | |||
@@ -66,24 +65,24 @@ namespace BPA.SaaS.TaskSchedule.Api.Service | |||
public BaseResult<long> Save(SaveTaskInfoReq req) | |||
{ | |||
if (req.IsNull()) | |||
return BaseResult<long>.Build(langPackge.ParamInvalid); | |||
return BaseResult<long>.Build(langPackage.ParamInvalid); | |||
var isNew = req.Id <= 0; | |||
req.Name = req.Name.ToTrim(); | |||
req.BizSysApiName = req.BizSysApiName.ToTrim(); | |||
req.RequestURL = req.RequestURL.ToTrim(); | |||
if (req.RequestURL.IsNull()) | |||
return BaseResult<long>.Build(langPackge.ParamInvalid, "请求地址不能为空!"); | |||
return BaseResult<long>.Build(langPackage.ParamInvalid, "请求地址不能为空!"); | |||
if (req.RequestURLType == EnumRequestURLType.BizSysApi && req.BizSysApiName.IsNull()) | |||
return BaseResult<long>.Build(langPackge.ParamInvalid, "业务系统Api名称不能为空!"); | |||
return BaseResult<long>.Build(langPackage.ParamInvalid, "业务系统Api名称不能为空!"); | |||
if (req.RequestURLType == EnumRequestURLType.BizSysApi && !req.RequestURL.StartsWith("/")) | |||
return BaseResult<long>.Build(langPackge.ParamInvalid, "请求地址不能以 / 开头!"); | |||
return BaseResult<long>.Build(langPackage.ParamInvalid, "请求地址不能以 / 开头!"); | |||
if (req.RequestURLType == EnumRequestURLType.Custom && !req.RequestURL.ToLower().StartsWith("http")) | |||
return BaseResult<long>.Build(langPackge.ParamInvalid, "请求地址必须以http开头!"); | |||
return BaseResult<long>.Build(langPackage.ParamInvalid, "请求地址必须以http开头!"); | |||
if (req.TriggerType == EnumTriggerType.CronTrigger) | |||
{ | |||
(var checkResult, var msg) = schedulerManager.Value.CheckCronExpression(req.CronExpression); | |||
if (!checkResult) | |||
return BaseResult<long>.Build(langPackge.ParamInvalid, $"Cron表达式校验错误:{msg}!"); | |||
return BaseResult<long>.Build(langPackage.ParamInvalid, $"Cron表达式校验错误:{msg}!"); | |||
} | |||
//校验任务名称是否存在 | |||
@@ -91,7 +90,7 @@ namespace BPA.SaaS.TaskSchedule.Api.Service | |||
.WhereIF(!isNew, x => x.Id != req.Id) | |||
.Any(x => x.Name == req.Name && x.IsDelete == false); | |||
if (hasName) | |||
return BaseResult<long>.Build(langPackge.TaskExist); | |||
return BaseResult<long>.Build(langPackage.TaskExist); | |||
if (req.TaskType == EnumTaskType.AnyTime) | |||
req.TriggerType = EnumTriggerType.Nothing; | |||
var statusIsChange = false; | |||
@@ -132,7 +131,7 @@ namespace BPA.SaaS.TaskSchedule.Api.Service | |||
{ | |||
entity = taskInfoRepository.Value.Queryable().FirstOrDefault(x => x.Id == req.Id); | |||
if (entity.IsNull()) | |||
return BaseResult<long>.Build(langPackge.TaskNotExist); | |||
return BaseResult<long>.Build(langPackage.TaskNotExist); | |||
//检查状态是否改变 | |||
statusIsChange = entity.Status != req.Status; | |||
entity.BizSysApiName = req.BizSysApiName; | |||
@@ -202,7 +201,7 @@ namespace BPA.SaaS.TaskSchedule.Api.Service | |||
{ | |||
var dto = GetCache(req.Id); | |||
if (dto.IsNull()) | |||
return BaseResult.Build(langPackge.TaskNotExist); | |||
return BaseResult.Build(langPackage.TaskNotExist); | |||
//标记任务删除 | |||
taskInfoRepository.Value.UpdateOne(x => new CrmTaskInfo {IsDelete = true}, x => x.Id == req.Id); | |||
if (dto.TaskType == EnumTaskType.AnyTime) | |||
@@ -20,28 +20,25 @@ namespace BPA.SaaS.TaskSchedule.Api.WebApi.Controllers | |||
/// <summary> | |||
/// taskInfoService | |||
/// </summary> | |||
private Lazy<ITaskInfoService> taskInfoService; | |||
private ITaskInfoService taskInfoService; | |||
/// <summary> | |||
/// taskLogService | |||
/// </summary> | |||
private Lazy<ITaskLogService> taskLogService; | |||
private Lazy<ISystemDictionaryService> systemDictionaryService; | |||
private ITaskLogService taskLogService; | |||
/// <summary> | |||
/// systemDictionaryService | |||
/// </summary> | |||
private ISystemDictionaryService systemDictionaryService; | |||
/// <summary> | |||
/// HomeController | |||
/// </summary> | |||
/// <param name="logger"></param> | |||
/// <param name="taskInfoService"></param> | |||
/// <param name="taskLogService"></param> | |||
/// <param name="systemDictionaryService"></param> | |||
public HomeController( | |||
ILogger<HomeController> logger, | |||
Lazy<ITaskInfoService> taskInfoService, | |||
Lazy<ITaskLogService> taskLogService, | |||
Lazy<ISystemDictionaryService> systemDictionaryService) | |||
public HomeController(ILogger<HomeController> logger, | |||
ITaskInfoService taskInfoService, | |||
ITaskLogService taskLogService, | |||
ISystemDictionaryService systemDictionaryService) | |||
{ | |||
_logger = logger; | |||
this.taskInfoService = taskInfoService; | |||
@@ -59,12 +56,12 @@ namespace BPA.SaaS.TaskSchedule.Api.WebApi.Controllers | |||
if (data is BaseResult result) | |||
{ | |||
result.TrackId = Request.HttpContext.TraceIdentifier; | |||
result.Render(LangType.Zn); | |||
result.Render(); | |||
} | |||
return base.Json(data); | |||
} | |||
/// <summary> | |||
/// Index | |||
/// </summary> | |||
@@ -73,7 +70,7 @@ namespace BPA.SaaS.TaskSchedule.Api.WebApi.Controllers | |||
{ | |||
return View(); | |||
} | |||
/// <summary> | |||
/// 保存 | |||
/// </summary> | |||
@@ -82,9 +79,9 @@ namespace BPA.SaaS.TaskSchedule.Api.WebApi.Controllers | |||
[HttpPost] | |||
public IActionResult Save(SaveTaskInfoReq req) | |||
{ | |||
return Json(taskInfoService.Value.Save(req)); | |||
return Json(taskInfoService.Save(req)); | |||
} | |||
/// <summary> | |||
/// 删除 | |||
/// </summary> | |||
@@ -93,9 +90,9 @@ namespace BPA.SaaS.TaskSchedule.Api.WebApi.Controllers | |||
[HttpPost] | |||
public IActionResult Delete(DeleteTaskInfoReq req) | |||
{ | |||
return Json(taskInfoService.Value.Delete(req)); | |||
return Json(taskInfoService.Delete(req)); | |||
} | |||
/// <summary> | |||
/// 获取所有的任务信息 | |||
/// </summary> | |||
@@ -103,9 +100,9 @@ namespace BPA.SaaS.TaskSchedule.Api.WebApi.Controllers | |||
[HttpPost] | |||
public IActionResult GetAll() | |||
{ | |||
return Json(taskInfoService.Value.GetAll()); | |||
return Json(taskInfoService.GetAll()); | |||
} | |||
/// <summary> | |||
/// 执行一次 | |||
/// </summary> | |||
@@ -114,9 +111,9 @@ namespace BPA.SaaS.TaskSchedule.Api.WebApi.Controllers | |||
[HttpPost] | |||
public IActionResult DoOnce(DoOnceReq req) | |||
{ | |||
return Json(taskInfoService.Value.DoOnce(req)); | |||
return Json(taskInfoService.DoOnce(req)); | |||
} | |||
/// <summary> | |||
/// 添加任意时间任务日志 | |||
/// </summary> | |||
@@ -124,18 +121,18 @@ namespace BPA.SaaS.TaskSchedule.Api.WebApi.Controllers | |||
/// <returns></returns> | |||
[HttpPost] | |||
public IActionResult AddAnyTimeLog(AddAnyTimeLogReq req) | |||
=> Json(taskLogService.Value.AddAnyTimeLog(req)); | |||
=> Json(taskLogService.AddAnyTimeLog(req)); | |||
/// <summary> | |||
/// 清理日志 | |||
/// </summary> | |||
[HttpPost] | |||
public IActionResult Clear() | |||
{ | |||
taskLogService.Value.Clear(); | |||
taskLogService.Clear(); | |||
return Ok(); | |||
} | |||
/// <summary> | |||
/// 分页查询日志 | |||
/// </summary> | |||
@@ -143,30 +140,30 @@ namespace BPA.SaaS.TaskSchedule.Api.WebApi.Controllers | |||
/// <returns></returns> | |||
[HttpPost] | |||
public IActionResult GetPage(GetTaskLogPageReq req) | |||
=> Json(taskLogService.Value.GetPage(req)); | |||
=> Json(taskLogService.GetPage(req)); | |||
/// <summary> | |||
/// 保存 | |||
/// </summary> | |||
/// <param name="req"></param> | |||
/// <returns></returns> | |||
[HttpPost] | |||
public IActionResult SaveDic(SaveSystemDictionaryReq req) => Json(systemDictionaryService.Value.Save(req)); | |||
public IActionResult SaveDic(SaveSystemDictionaryReq req) => Json(systemDictionaryService.Save(req)); | |||
/// <summary> | |||
/// 删除 | |||
/// </summary> | |||
/// <param name="req"></param> | |||
/// <returns></returns> | |||
[HttpPost] | |||
public IActionResult DeleteDic(DeleteSystemDictionaryReq req) => Json(systemDictionaryService.Value.Delete(req)); | |||
public IActionResult DeleteDic(DeleteSystemDictionaryReq req) => Json(systemDictionaryService.Delete(req)); | |||
/// <summary> | |||
/// 获取所有的 | |||
/// </summary> | |||
/// <returns></returns> | |||
[HttpPost] | |||
public IActionResult GetAllDic() => Json(systemDictionaryService.Value.GetAll()); | |||
public IActionResult GetAllDic() => Json(systemDictionaryService.GetAll()); | |||
} | |||
} |