mirror of
https://gitea.tendokyu.moe/Kayori/MedusaPluginChargeMachine.git
synced 2026-09-28 10:07:58 +03:00
Introduce ChargeMachineDbContext (SQLite) with ArticleContent and ChargeHistory entities, plus migrations, and wire it up via ConfigurePluginServices/OnAppInitialize with startup migration and article-content seeding. - ChargeEaChargeHandler now records each charge to ChargeHistory - GetConfigEaChargeHandler serves article config from the DB instead of hardcoded values, and adds multibills/readagreement fields - GetLastLogEaChargeHandler returns real daily totals and recent charge items from history, keyed by session card - Add GetRecentChargeEaChargeHandler (paginated charge history) and OpChPassEaChargeHandler (PIN change) - Update handlers to the new HandleAsync/primary-constructor style, file-scoped namespaces - Bump EF Core/Identity packages and Abstractions reference to net10.0/10.0.10
65 lines
2.7 KiB
C#
65 lines
2.7 KiB
C#
using Abstractions;
|
|
using MedusaPluginChargeMachine.Entities;
|
|
using MedusaPluginChargeMachine.Services;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using System.Text;
|
|
|
|
namespace MedusaPluginChargeMachine;
|
|
|
|
public class ChargeMachinePlugin : IMedusaPlugin
|
|
{
|
|
public string Name => "Charge Machine";
|
|
public string Version => "1.0.0";
|
|
public string Description => "Plugin for the paseli charge machine";
|
|
public string GameCode => "LA9";
|
|
public int? MinVer => null;
|
|
public int? MaxVer => null;
|
|
public Encoding? ForcedEncoding => null;
|
|
public Delegate DoesProfileExist => () => false;
|
|
|
|
public Task OnBuilderInitialize(WebApplicationBuilder builder) => Task.CompletedTask;
|
|
|
|
public void ConfigurePluginServices(IServiceCollection services)
|
|
{
|
|
services.AddSingleton<ISessionService, SessionService>();
|
|
services.AddDbContext<ChargeMachineDbContext>(o =>
|
|
o.UseSqlite("Data Source=database/ChargeMachine.db;"));
|
|
}
|
|
|
|
public async Task OnAppInitialize(WebApplication app, IServiceProvider pluginServices)
|
|
{
|
|
await using var scope = pluginServices.CreateAsyncScope();
|
|
var db = scope.ServiceProvider.GetRequiredService<ChargeMachineDbContext>();
|
|
await db.Database.MigrateAsync();
|
|
await SeedArticleContentsAsync(db);
|
|
}
|
|
|
|
private static async Task SeedArticleContentsAsync(ChargeMachineDbContext db)
|
|
{
|
|
if (await db.ArticleContents.AnyAsync())
|
|
return;
|
|
|
|
var defaults = new List<ArticleContent>
|
|
{
|
|
new() { ArticleType = "DOCMT_0000", ArticleDoc = "" },
|
|
new() { ArticleType = "DOCMT_0001", ArticleDoc = "PASELI Charge Machine" },
|
|
new() { ArticleType = "DOCMT_0002", ArticleDoc = "" },
|
|
new() { ArticleType = "DOCMT_0003", ArticleDoc = "" },
|
|
new() { ArticleType = "URL_0001_A", ArticleDoc = "https://localhost:5173/" },
|
|
new() { ArticleType = "URL_0001_B", ArticleDoc = "https://localhost:5173/" },
|
|
new() { ArticleType = "URL_0002_A", ArticleDoc = "https://localhost:5173/" },
|
|
new() { ArticleType = "URL_0002_B", ArticleDoc = "https://localhost:5173/" },
|
|
new() { ArticleType = "URL_0003_A", ArticleDoc = "https://localhost:5173/" },
|
|
new() { ArticleType = "URL_0003_B", ArticleDoc = "https://localhost:5173/" },
|
|
new() { ArticleType = "URL_0004_A", ArticleDoc = "https://localhost:5173/" },
|
|
new() { ArticleType = "URL_0041_B", ArticleDoc = "https://localhost:5173/" },
|
|
new() { ArticleType = "PASELIUNIT", ArticleDoc = "P" },
|
|
};
|
|
|
|
db.ArticleContents.AddRange(defaults);
|
|
await db.SaveChangesAsync();
|
|
}
|
|
}
|