using MiaoJiZhang.Domain.Entities; using MiaoJiZhang.Domain.Enums; using Microsoft.EntityFrameworkCore; namespace MiaoJiZhang.Infrastructure.Persistence; /// 启动种子:默认分类、AI 形象/性格、品牌配置 public static class DbSeeder { public static async Task SeedAsync(AppDbContext db) { if (!await db.AiAvatars.AnyAsync()) { db.AiAvatars.AddRange( new AiAvatar { Key = "cat", DefaultName = "小账喵", SpeechTic = "喵" }, new AiAvatar { Key = "dog", DefaultName = "阿福汪", SpeechTic = "汪" }, new AiAvatar { Key = "robot", DefaultName = "账小智", SpeechTic = "" }); } if (!await db.AiPersonas.AnyAsync()) { db.AiPersonas.AddRange( new AiPersona { Key = "sassy_cat", Name = "毒舌猫娘", Description = "嘴上嫌弃,心里关心,乱花钱会被吐槽", SampleLine = "又点外卖?你的钱包已经瘦成纸片了{tic}!", PromptTemplate = "你是用户的记账助手,性格毒舌但关心用户。回复末尾口癖:{tic}。", Version = 1 }, new AiPersona { Key = "gentle", Name = "温柔小暖", Description = "永远鼓励你,温柔提醒不施压", SampleLine = "记好啦,偶尔犒劳自己也是应该的呀", PromptTemplate = "你是用户的记账助手,性格温柔鼓励。口癖:{tic}。", Version = 1 }, new AiPersona { Key = "strict", Name = "严格管家", Description = "专业理性,盯紧预算,数据说话", SampleLine = "本笔支出使餐饮预算达到 87%,请注意。", PromptTemplate = "你是用户的记账管家,专业理性,用数据说话,不用口癖。", Version = 1 }, new AiPersona { Key = "meme", Name = "沙雕损友", Description = "玩梗高手,表情包狂魔,快乐记账", SampleLine = "家人们谁懂啊,他又双叒叕买奶茶了", PromptTemplate = "你是用户的记账损友,爱玩梗爱发表情包。口癖:{tic}。", Version = 1 }); } if (!await db.Categories.AnyAsync(c => c.UserId == null)) { string[,] expense = { { "餐饮", "food", "coral" }, { "饮品", "cup", "cyan" }, { "购物", "cart", "blue" }, { "交通", "metro", "teal" }, { "住房", "house", "sand" }, { "娱乐", "game", "violet" }, { "医疗", "pill", "red" }, { "学习", "book", "indigo" }, { "服饰", "shirt", "plum" }, { "人情", "gift", "rose" }, { "旅行", "plane", "sky" }, { "其他", "tag", "graphite" }, }; for (var i = 0; i < expense.GetLength(0); i++) db.Categories.Add(new Category { Type = TransactionType.Expense, Name = expense[i, 0], IconKey = expense[i, 1], ColorKey = expense[i, 2], SortOrder = i, }); string[,] income = { { "工资", "money", "mint" }, { "兼职", "briefcase", "forest" }, { "理财", "chart", "navy" }, { "红包", "gift", "orange" }, { "报销", "card", "amber" }, { "奖金", "sparkle", "aqua" }, { "其他", "tag", "lime" }, }; for (var i = 0; i < income.GetLength(0); i++) db.Categories.Add(new Category { Type = TransactionType.Income, Name = income[i, 0], IconKey = income[i, 1], ColorKey = income[i, 2], SortOrder = i, }); } if (!await db.Stickers.AnyAsync()) { db.Stickers.AddRange( new Sticker { Key = "salary", Label = "发工资啦", GroupKey = "ai_exclusive", TriggerTags = "salary" }, new Sticker { Key = "forgive", Label = "求原谅", GroupKey = "ai_exclusive", TriggerTags = "forgive" }, new Sticker { Key = "fire", Label = "剁手警告", GroupKey = "ai_exclusive", TriggerTags = "over_budget" }, new Sticker { Key = "empty_wallet", Label = "钱包空空", GroupKey = "ai_exclusive" }, new Sticker { Key = "angry", Label = "生气", GroupKey = "ai_exclusive" }, new Sticker { Key = "happy", Label = "开心", GroupKey = "ai_exclusive" }, new Sticker { Key = "treat", Label = "犒劳自己", GroupKey = "classic" }, new Sticker { Key = "shopping_joy", Label = "购物狂喜", GroupKey = "classic" }); } if (!await db.AppConfigs.AnyAsync()) { var now = DateTime.UtcNow; db.AppConfigs.AddRange( new AppConfig { Key = "brand.app_name", Value = "记之", Version = 1, UpdatedAt = now }, new AppConfig { Key = "brand.slogan", Value = "会聊天的记账本 · 让 AI 帮你管钱", Version = 1, UpdatedAt = now }, new AppConfig { Key = "brand.logo_url", Value = "", Version = 1, UpdatedAt = now }, new AppConfig { Key = "llm.protocol", Value = "chat_completions", Version = 1, UpdatedAt = now }, new AppConfig { Key = "llm.base_url", Value = "https://api.openai.com/v1", Version = 1, UpdatedAt = now }, new AppConfig { Key = "llm.model", Value = "gpt-4o-mini", Version = 1, UpdatedAt = now }, new AppConfig { Key = "llm.max_tokens", Value = "1024", Version = 1, UpdatedAt = now }, new AppConfig { Key = "llm.temperature", Value = "0.8", Version = 1, UpdatedAt = now }, new AppConfig { Key = "limit.daily_ai_messages", Value = "200", Version = 1, UpdatedAt = now }, new AppConfig { Key = "limit.daily_ai_messages_per_user", Value = "50", Version = 1, UpdatedAt = now }, new AppConfig { Key = "limit.max_monthly_budget", Value = "99999999", Version = 1, UpdatedAt = now }, new AppConfig { Key = "feature.ocr_enabled", Value = "true", Version = 1, UpdatedAt = now }, new AppConfig { Key = "feature.voice_enabled", Value = "true", Version = 1, UpdatedAt = now }, new AppConfig { Key = "feature.ai_auto_book", Value = "true", Version = 1, UpdatedAt = now }, new AppConfig { Key = "feature.sticker_enabled", Value = "true", Version = 1, UpdatedAt = now }, new AppConfig { Key = "system.default_ledger_name", Value = "日常账本", Version = 1, UpdatedAt = now }, new AppConfig { Key = "system.max_ledgers_per_user", Value = "10", Version = 1, UpdatedAt = now }, new AppConfig { Key = "feature.screenshot_bookkeeping_enabled", Value = "true", Version = 1, UpdatedAt = now }, new AppConfig { Key = "permission.default.ai_enabled", Value = "true", Version = 1, UpdatedAt = now }, new AppConfig { Key = "quota.default_ai_chat_limit", Value = "50", Version = 1, UpdatedAt = now }, new AppConfig { Key = "quota.default_ai_chat_period", Value = "day", Version = 1, UpdatedAt = now }); } var appName = await db.AppConfigs.FirstOrDefaultAsync(config => config.Key == "brand.app_name"); if (appName?.Value is "喵记账" or "喵记") { appName.Value = "记之"; appName.Version++; appName.UpdatedAt = DateTime.UtcNow; } await db.SaveChangesAsync(); } }