1
0
mirror of synced 2024-12-18 17:25:54 +01:00
GC-local-server-rewrite/Application/Jobs/MaintainNullValuesJob.cs

74 lines
3.0 KiB
C#
Raw Normal View History

2023-02-16 08:26:13 +01:00
using System.Diagnostics.CodeAnalysis;
2023-03-03 12:03:13 +01:00
using Domain.Config;
using Domain.Enums;
2023-02-16 08:26:13 +01:00
using Microsoft.Extensions.Logging;
2023-03-03 12:03:13 +01:00
using Microsoft.Extensions.Options;
2023-02-16 08:26:13 +01:00
using Quartz;
namespace Application.Jobs;
2023-02-22 18:15:53 +01:00
public class MaintainNullValuesJob : IJob
2023-02-16 08:26:13 +01:00
{
2023-02-22 18:15:53 +01:00
private readonly ILogger<MaintainNullValuesJob> logger;
2023-02-16 08:26:13 +01:00
private readonly ICardDbContext cardDbContext;
2023-03-03 12:03:13 +01:00
private readonly GameConfig config;
2023-02-22 18:15:53 +01:00
public static readonly JobKey KEY = new("MaintainNullValuesJob");
2023-02-16 08:26:13 +01:00
2023-03-03 12:03:13 +01:00
public MaintainNullValuesJob(ILogger<MaintainNullValuesJob> logger, ICardDbContext cardDbContext, IOptions<GameConfig> options)
2023-02-16 08:26:13 +01:00
{
this.logger = logger;
this.cardDbContext = cardDbContext;
2023-03-03 12:03:13 +01:00
config = options.Value;
2023-02-16 08:26:13 +01:00
}
[SuppressMessage("ReSharper.DPA", "DPA0007: Large number of DB records",
Justification = "All details might be read")]
2023-02-16 09:04:38 +01:00
[SuppressMessage("ReSharper.DPA", "DPA0006: Large number of DB commands")]
2023-02-16 08:26:13 +01:00
public async Task Execute(IJobExecutionContext context)
{
logger.LogInformation("Starting changing null values in card detail table");
2023-02-16 09:04:38 +01:00
var details = await cardDbContext.CardDetails.Where(detail => detail.LastPlayTenpoId == null ||
2023-02-22 18:15:53 +01:00
detail.LastPlayTenpoId == "GC local server"
|| detail.LastPlayTime == null).ToListAsync();
details.ForEach(detail =>
{
detail.LastPlayTenpoId = "1337";
detail.LastPlayTime = DateTime.MinValue;
});
2023-02-16 08:26:13 +01:00
cardDbContext.CardDetails.UpdateRange(details);
var count = await cardDbContext.SaveChangesAsync(new CancellationToken());
logger.LogInformation("Updated {Count} entries in card detail table", count);
2023-02-26 19:43:13 +01:00
logger.LogInformation("Starting closing unfinished matches");
var matches = await cardDbContext.OnlineMatches.Where(match => match.IsOpen == true).ToListAsync();
matches.ForEach(match => match.IsOpen = false);
cardDbContext.OnlineMatches.UpdateRange(matches);
count = await cardDbContext.SaveChangesAsync(new CancellationToken());
logger.LogInformation("Closed {Count} matches", count);
2023-03-03 12:03:13 +01:00
logger.LogInformation("Starting to remove previously new songs");
var unlockables = config.UnlockRewards
.Where(c => c.RewardType == RewardType.Music).ToDictionary(rewardConfig => rewardConfig.TargetId);
var targets = await cardDbContext.CardDetails.Where(detail => detail.Pcol1 == 10).ToListAsync();
foreach (var target in targets)
{
if (unlockables.ContainsKey((int)target.Pcol2))
{
continue;
}
target.ScoreUi2 = 0;
target.ScoreUi6 = 0;
}
cardDbContext.CardDetails.UpdateRange(targets);
count = await cardDbContext.SaveChangesAsync(new CancellationToken());
logger.LogInformation("Fixed {Count} records", count);
2023-02-16 08:26:13 +01:00
}
}