using Jiaowu.Plugin.Abstractions; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; namespace Jiaowu.SamplePlugin; public sealed class SamplePluginModule : IJiaowuPluginModule { public void ConfigureServices( IServiceCollection services, IConfiguration configuration) { services.AddSingleton(); } } public sealed class SampleGreetingService { public string BuildGreeting() => "签名示例插件已由宿主成功装载。"; } [ApiController] [Authorize(Roles = "SuperAdmin")] [Route("api/plugin-extensions/sample.hello")] public sealed class SamplePluginController(SampleGreetingService greetings) : ControllerBase { [HttpGet("greeting")] public IActionResult GetGreeting() => Ok(new { message = greetings.BuildGreeting() }); } public sealed class SamplePluginMigration : IPluginDatabaseMigration { public string PluginId => "sample.hello"; public string MigrationId => "001_initial"; public IReadOnlyList GetStatements(PluginDatabaseProvider provider) => provider == PluginDatabaseProvider.Sqlite ? ["CREATE TABLE IF NOT EXISTS SamplePluginNotes (Id TEXT NOT NULL PRIMARY KEY, Content TEXT NOT NULL);"] : ["CREATE TABLE IF NOT EXISTS `SamplePluginNotes` (`Id` char(36) NOT NULL, `Content` varchar(500) NOT NULL, PRIMARY KEY (`Id`)) CHARACTER SET utf8mb4;"]; } public sealed class SamplePluginBackgroundTask( ILogger logger) : IPluginBackgroundTask { public string PluginId => "sample.hello"; public string Name => "sample-heartbeat"; public TimeSpan Interval => TimeSpan.FromHours(1); public Task ExecuteAsync( IServiceProvider services, CancellationToken cancellationToken) { logger.LogInformation("示例插件后台任务正常运行。"); return Task.CompletedTask; } }