Files
Telegram-Panel/src/TelegramPanel.Data/Repositories/AccountRepository.cs
T
meoacgxandClaude 02c10cf2bb 完善数据持久层和文件上传功能
本次更新内容:
- 创建所有数据库实体类(Account, AccountCategory, Channel, ChannelGroup, Group, BatchTask)
- 实现AppDbContext和EF Core配置
- 实现完整的Repository层(通用Repository + 专用Repository)
- 创建数据管理Service层(AccountManagementService等)
- 创建数据库迁移文件
- 实现Session文件上传功能(AccountImportService)
- 完善AccountImport页面,支持批量文件上传和StringSession导入
- 配置数据库连接和服务注册

数据库设计:
- SQLite数据库,支持账号、频道、群组、分类、批量任务等
- 完整的关系映射和外键约束
- 索引优化查询性能

服务架构:
- Repository层:数据访问抽象
- Management Service层:业务逻辑和数据管理
- Telegram Service层:Telegram API操作
- 导入协调服务:整合Session导入和数据库保存

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-19 02:57:05 +08:00

61 lines
1.6 KiB
C#

using Microsoft.EntityFrameworkCore;
using TelegramPanel.Data.Entities;
namespace TelegramPanel.Data.Repositories;
/// <summary>
/// 账号仓储实现
/// </summary>
public class AccountRepository : Repository<Account>, IAccountRepository
{
public AccountRepository(AppDbContext context) : base(context)
{
}
public override async Task<Account?> GetByIdAsync(int id)
{
return await _dbSet
.Include(a => a.Category)
.Include(a => a.Channels)
.Include(a => a.Groups)
.FirstOrDefaultAsync(a => a.Id == id);
}
public override async Task<IEnumerable<Account>> GetAllAsync()
{
return await _dbSet
.Include(a => a.Category)
.ToListAsync();
}
public async Task<Account?> GetByPhoneAsync(string phone)
{
return await _dbSet
.Include(a => a.Category)
.FirstOrDefaultAsync(a => a.Phone == phone);
}
public async Task<Account?> GetByUserIdAsync(long userId)
{
return await _dbSet
.Include(a => a.Category)
.FirstOrDefaultAsync(a => a.UserId == userId);
}
public async Task<IEnumerable<Account>> GetByCategoryAsync(int categoryId)
{
return await _dbSet
.Include(a => a.Category)
.Where(a => a.CategoryId == categoryId)
.ToListAsync();
}
public async Task<IEnumerable<Account>> GetActiveAccountsAsync()
{
return await _dbSet
.Include(a => a.Category)
.Where(a => a.IsActive)
.ToListAsync();
}
}