using MiaoJiZhang.Domain.Entities; using MiaoJiZhang.Infrastructure.Persistence; using Microsoft.EntityFrameworkCore; namespace MiaoJiZhang.Api.Services; public static class AppConfigDefaults { public static readonly IReadOnlyDictionary Values = new Dictionary(StringComparer.OrdinalIgnoreCase) { ["brand.app_name"] = "记之", ["brand.slogan"] = "会聊天的记账本 · 让 AI 帮你管钱", ["brand.logo_url"] = "", ["llm.protocol"] = "responses", ["llm.base_url"] = "https://api.openai.com/v1", ["llm.model"] = "gpt-4o-mini", ["llm.max_tokens"] = "1024", ["llm.temperature"] = "0.7", ["limit.daily_ai_messages"] = "200", ["limit.daily_ai_messages_per_user"] = "50", ["limit.max_monthly_budget"] = "99999999", ["feature.ocr_enabled"] = "true", ["feature.voice_enabled"] = "true", ["feature.ai_auto_book"] = "true", ["feature.sticker_enabled"] = "true", ["feature.screenshot_bookkeeping_enabled"] = "true", ["permission.default.ai_enabled"] = "true", ["quota.default_ai_chat_limit"] = "50", ["quota.default_ai_chat_period"] = "day", ["system.default_ledger_name"] = "日常账本", ["system.max_ledgers_per_user"] = "10", }; public static async Task EnsureAsync( AppDbContext db, CancellationToken ct = default) { var existing = await db.AppConfigs .Select(config => config.Key) .ToListAsync(ct); var keys = existing.ToHashSet(StringComparer.OrdinalIgnoreCase); var now = DateTime.UtcNow; var added = 0; foreach (var (key, value) in Values) { if (keys.Contains(key)) continue; db.AppConfigs.Add(new AppConfig { Key = key, Value = value, Version = 1, UpdatedAt = now, }); added++; } if (added > 0) await db.SaveChangesAsync(ct); return added; } }