Merge branch 'refs/heads/abp' into digital-collectibles
# Conflicts: # Yi.Abp.Net8/Yi.Abp.sln # Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Application/Jobs/AccessLogCacheJob.cs # Yi.Abp.Net8/src/Yi.Abp.Application/Jobs/DemoResetJob.cs # Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs
This commit is contained in:
53
Yi.Abp.Net8/src/Yi.Abp.Application/Jobs/DemoResetJob.cs
Normal file
53
Yi.Abp.Net8/src/Yi.Abp.Application/Jobs/DemoResetJob.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Volo.Abp.BackgroundWorkers.Hangfire;
|
||||
using Volo.Abp.Data;
|
||||
using Yi.Framework.Rbac.Domain.Entities;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
namespace Yi.Abp.Application.Jobs
|
||||
{
|
||||
public class DemoResetJob : HangfireBackgroundWorkerBase
|
||||
{
|
||||
private ISqlSugarDbContext _dbContext;
|
||||
private ILogger<DemoResetJob> _logger => LoggerFactory.CreateLogger<DemoResetJob>();
|
||||
private IDataSeeder _dataSeeder;
|
||||
private IConfiguration _configuration;
|
||||
public DemoResetJob(ISqlSugarDbContext dbContext, IDataSeeder dataSeeder, IConfiguration configuration)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
RecurringJobId = "重置demo环境";
|
||||
//每天1点和13点进行重置demo环境
|
||||
CronExpression = "0 0 1,13 * * ?";
|
||||
|
||||
_dataSeeder = dataSeeder;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
public override async Task DoWorkAsync(CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
//开启演示环境重置功能
|
||||
if (_configuration.GetSection("EnableDemoReset").Get<bool>())
|
||||
{
|
||||
//定时任务,非常简单
|
||||
_logger.LogWarning("演示环境正在还原!");
|
||||
var db = _dbContext.SqlSugarClient.CopyNew();
|
||||
db.DbMaintenance.TruncateTable<UserAggregateRoot>();
|
||||
db.DbMaintenance.TruncateTable<UserRoleEntity>();
|
||||
db.DbMaintenance.TruncateTable<RoleAggregateRoot>();
|
||||
db.DbMaintenance.TruncateTable<RoleMenuEntity>();
|
||||
db.DbMaintenance.TruncateTable<MenuAggregateRoot>();
|
||||
db.DbMaintenance.TruncateTable<RoleDeptEntity>();
|
||||
db.DbMaintenance.TruncateTable<DeptAggregateRoot>();
|
||||
db.DbMaintenance.TruncateTable<PostAggregateRoot>();
|
||||
db.DbMaintenance.TruncateTable<UserPostEntity>();
|
||||
|
||||
//删除种子数据
|
||||
await _dataSeeder.SeedAsync();
|
||||
_logger.LogWarning("演示环境还原成功!");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using Quartz;
|
||||
using Hangfire;
|
||||
using SqlSugar;
|
||||
using Volo.Abp.BackgroundWorkers.Quartz;
|
||||
using Volo.Abp.BackgroundWorkers.Hangfire;
|
||||
using Volo.Abp.Domain.Repositories;
|
||||
using Volo.Abp.Uow;
|
||||
using Yi.Framework.Rbac.Domain.Entities;
|
||||
@@ -11,26 +11,21 @@ namespace Yi.Abp.Application.Jobs
|
||||
/// <summary>
|
||||
/// 定时任务
|
||||
/// </summary>
|
||||
public class TestJob : QuartzBackgroundWorkerBase
|
||||
public class TestJob : HangfireBackgroundWorkerBase
|
||||
{
|
||||
private ISqlSugarRepository<UserAggregateRoot> _repository;
|
||||
public TestJob(ISqlSugarRepository<UserAggregateRoot> repository)
|
||||
{
|
||||
_repository = repository;
|
||||
JobDetail = JobBuilder.Create<TestJob>().WithIdentity(nameof(TestJob)).Build();
|
||||
Trigger = TriggerBuilder.Create().WithIdentity(nameof(TestJob)).StartNow()
|
||||
.WithSimpleSchedule(x => x
|
||||
.WithIntervalInSeconds(1000 * 60)
|
||||
.RepeatForever())
|
||||
.Build();
|
||||
RecurringJobId = "测试";
|
||||
//每天一次
|
||||
CronExpression = Cron.Daily();
|
||||
}
|
||||
public override async Task Execute(IJobExecutionContext context)
|
||||
public override Task DoWorkAsync(CancellationToken cancellationToken = new CancellationToken())
|
||||
{
|
||||
//定时任务,非常简单
|
||||
Console.WriteLine("你好,世界");
|
||||
// var eneities= await _repository.GetListAsync();
|
||||
//var entities= await _sqlSugarClient.Queryable<UserEntity>().ToListAsync();
|
||||
//await Console.Out.WriteLineAsync(entities.Count().ToString());
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\framework\Yi.Framework.BackgroundWorkers.Hangfire\Yi.Framework.BackgroundWorkers.Hangfire.csproj" />
|
||||
<ProjectReference Include="..\..\framework\Yi.Framework.Ddd.Application\Yi.Framework.Ddd.Application.csproj" />
|
||||
<ProjectReference Include="..\..\module\bbs\Yi.Framework.Bbs.Application\Yi.Framework.Bbs.Application.csproj" />
|
||||
<ProjectReference Include="..\..\module\chat-hub\Yi.Framework.ChatHub.Application\Yi.Framework.ChatHub.Application.csproj" />
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Volo.Abp.SettingManagement;
|
||||
using Yi.Abp.Application.Contracts;
|
||||
using Yi.Abp.Domain;
|
||||
using Yi.Framework.BackgroundWorkers.Hangfire;
|
||||
using Yi.Framework.Bbs.Application;
|
||||
using Yi.Framework.ChatHub.Application;
|
||||
using Yi.Framework.CodeGen.Application;
|
||||
@@ -25,7 +26,8 @@ namespace Yi.Abp.Application
|
||||
typeof(YiFrameworkCodeGenApplicationModule),
|
||||
typeof (YiFrameworkSettingManagementApplicationModule),
|
||||
|
||||
typeof(YiFrameworkDddApplicationModule)
|
||||
typeof(YiFrameworkDddApplicationModule),
|
||||
typeof(YiFrameworkBackgroundWorkersHangfireModule)
|
||||
)]
|
||||
public class YiAbpApplicationModule : AbpModule
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user