database

package
v0.0.0-...-c5f0c88 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockLogRepository

type BlockLogRepository struct {
	// contains filtered or unexported fields
}

BlockLogRepository 拦截日志数据访问层

func NewBlockLogRepository

func NewBlockLogRepository(db *DB) *BlockLogRepository

NewBlockLogRepository 创建拦截日志仓库

func (*BlockLogRepository) Count

func (r *BlockLogRepository) Count() (int, error)

Count 获取拦截日志总数

func (*BlockLogRepository) CountByBotID

func (r *BlockLogRepository) CountByBotID(botID int64) (int, error)

CountByBotID 获取Bot的拦截日志数量

func (*BlockLogRepository) CountByReason

func (r *BlockLogRepository) CountByReason(botID int64) (map[string]int, error)

CountByReason 按原因统计拦截日志

func (*BlockLogRepository) Create

func (r *BlockLogRepository) Create(log *models.BlockLog) error

Create 创建拦截日志

func (*BlockLogRepository) DeleteOldLogs

func (r *BlockLogRepository) DeleteOldLogs(days int) (int, error)

DeleteOldLogs 删除旧的拦截日志

func (*BlockLogRepository) GetByBotID

func (r *BlockLogRepository) GetByBotID(botID int64) ([]*models.BlockLog, error)

GetByBotID 获取Bot的所有拦截日志

func (*BlockLogRepository) GetByID

func (r *BlockLogRepository) GetByID(id int64) (*models.BlockLog, error)

GetByID 根据ID获取拦截日志

func (*BlockLogRepository) GetByTelegramID

func (r *BlockLogRepository) GetByTelegramID(botID, telegramID int64) ([]*models.BlockLog, error)

GetByTelegramID 获取特定用户的拦截日志

func (*BlockLogRepository) GetRecent

func (r *BlockLogRepository) GetRecent(botID int64, limit int) ([]*models.BlockLog, error)

GetRecent 获取最近的拦截日志

func (*BlockLogRepository) MarkAsFalsePositive

func (r *BlockLogRepository) MarkAsFalsePositive(id int64) error

MarkAsFalsePositive 标记为误判

type BotConfigRepository

type BotConfigRepository struct {
	// contains filtered or unexported fields
}

BotConfigRepository Bot配置数据访问层

func NewBotConfigRepository

func NewBotConfigRepository(db *DB) *BotConfigRepository

NewBotConfigRepository 创建Bot配置仓库

func (*BotConfigRepository) CountBlacklisted

func (r *BotConfigRepository) CountBlacklisted(botID int64) (int, error)

CountBlacklisted 统计黑名单客户数量

func (*BotConfigRepository) CountBlockLogs

func (r *BotConfigRepository) CountBlockLogs(botID int64) (int, error)

CountBlockLogs 统计拦截日志

func (*BotConfigRepository) CountCustomers

func (r *BotConfigRepository) CountCustomers(botID int64) (int, error)

CountCustomers 统计客户数量

func (*BotConfigRepository) CountWhitelisted

func (r *BotConfigRepository) CountWhitelisted(botID int64) (int, error)

CountWhitelisted 统计白名单客户数量

func (*BotConfigRepository) Create

func (r *BotConfigRepository) Create(config *models.BotConfig) error

Create 创建Bot配置

func (*BotConfigRepository) GetBlacklist

func (r *BotConfigRepository) GetBlacklist(botID int64) ([]*models.Customer, error)

GetBlacklist 获取黑名单列表

func (*BotConfigRepository) GetBlockLogs

func (r *BotConfigRepository) GetBlockLogs(botID int64, limit int) ([]*models.BlockLog, error)

GetBlockLogs 获取拦截日志

func (*BotConfigRepository) GetByBotID

func (r *BotConfigRepository) GetByBotID(botID int64) (*models.BotConfig, error)

GetByBotID 根据Bot ID获取配置

func (*BotConfigRepository) GetStats

func (r *BotConfigRepository) GetStats(botID int64) (map[string]interface{}, error)

GetStats 获取统计信息

func (*BotConfigRepository) GetWhitelist

func (r *BotConfigRepository) GetWhitelist(botID int64) ([]*models.Customer, error)

GetWhitelist 获取白名单列表

func (*BotConfigRepository) SetAIEnabled

func (r *BotConfigRepository) SetAIEnabled(botID int64, enabled bool) error

SetAIEnabled 设置AI启用状态

func (*BotConfigRepository) SetCustomAI

func (r *BotConfigRepository) SetCustomAI(botID int64, endpoint, key, model string) error

SetCustomAI 设置自定义AI配置

func (*BotConfigRepository) SetDefaultAI

func (r *BotConfigRepository) SetDefaultAI(botID int64) error

SetDefaultAI 设置使用默认AI配置

func (*BotConfigRepository) SetThreshold

func (r *BotConfigRepository) SetThreshold(botID int64, threshold int) error

SetThreshold 设置白名单阈值

func (*BotConfigRepository) Update

func (r *BotConfigRepository) Update(config *models.BotConfig) error

Update 更新Bot配置

type CustomerRepository

type CustomerRepository struct {
	// contains filtered or unexported fields
}

CustomerRepository 客户数据仓库

func NewCustomerRepository

func NewCustomerRepository(db *DB) *CustomerRepository

NewCustomerRepository 创建客户仓库

func (*CustomerRepository) Blacklist

func (r *CustomerRepository) Blacklist(botID, telegramID int64, reason string) error

Blacklist 拉黑客户

func (*CustomerRepository) Create

func (r *CustomerRepository) Create(botID, telegramID int64, username, firstName, lastName string) (*models.Customer, error)

Create 创建新客户

func (*CustomerRepository) GetBlacklist

func (r *CustomerRepository) GetBlacklist(botID int64) ([]*models.Customer, error)

GetBlacklist 获取黑名单列表

func (*CustomerRepository) GetByTelegramID

func (r *CustomerRepository) GetByTelegramID(botID, telegramID int64) (*models.Customer, error)

GetByTelegramID 通过Telegram ID获取客户

func (*CustomerRepository) GetOrCreate

func (r *CustomerRepository) GetOrCreate(botID, telegramID int64, username, firstName, lastName string) (*models.Customer, error)

GetOrCreate 获取或创建客户记录

func (*CustomerRepository) GetWhitelist

func (r *CustomerRepository) GetWhitelist(botID int64) ([]*models.Customer, error)

GetWhitelist 获取白名单列表

func (*CustomerRepository) IncrementMessageCount

func (r *CustomerRepository) IncrementMessageCount(botID, telegramID int64) error

IncrementMessageCount 增加消息计数

func (*CustomerRepository) IncrementVerifiedCount

func (r *CustomerRepository) IncrementVerifiedCount(botID, telegramID int64, threshold int) error

IncrementVerifiedCount 增加已验证消息计数

func (*CustomerRepository) Unblacklist

func (r *CustomerRepository) Unblacklist(botID, telegramID int64) error

Unblacklist 解除拉黑

func (*CustomerRepository) Update

func (r *CustomerRepository) Update(customer *models.Customer) error

Update 更新客户信息

func (*CustomerRepository) Whitelist

func (r *CustomerRepository) Whitelist(botID, telegramID int64) error

Whitelist 信任客户(手动白名单)

type DB

type DB struct {
	*sql.DB
}

DB 数据库连接封装

func New

func New(dbPath string) (*DB, error)

New 创建新的数据库连接

func (*DB) Close

func (db *DB) Close() error

Close 关闭数据库连接

func (*DB) RunMigrations

func (db *DB) RunMigrations(migrationPath string) error

RunMigrations 运行数据库迁移

type PlanRepository

type PlanRepository struct {
	// contains filtered or unexported fields
}

PlanRepository 套餐数据访问层

func NewPlanRepository

func NewPlanRepository(db *DB) *PlanRepository

NewPlanRepository 创建套餐仓库

func (*PlanRepository) Count

func (r *PlanRepository) Count() (int, error)

Count 获取套餐总数

func (*PlanRepository) Create

func (r *PlanRepository) Create(plan *models.Plan) error

Create 创建套餐

func (*PlanRepository) Delete

func (r *PlanRepository) Delete(id int64) error

Delete 删除套餐(实际是标记为不可用)

func (*PlanRepository) GetActive

func (r *PlanRepository) GetActive() ([]*models.Plan, error)

GetActive 获取所有有效套餐

func (*PlanRepository) GetAll

func (r *PlanRepository) GetAll() ([]*models.Plan, error)

GetAll 获取所有套餐

func (*PlanRepository) GetByID

func (r *PlanRepository) GetByID(id int64) (*models.Plan, error)

GetByID 根据ID获取套餐

func (*PlanRepository) Update

func (r *PlanRepository) Update(plan *models.Plan) error

Update 更新套餐

type RedeemCodeRepository

type RedeemCodeRepository struct {
	// contains filtered or unexported fields
}

RedeemCodeRepository 兑换码数据访问层

func NewRedeemCodeRepository

func NewRedeemCodeRepository(db *DB) *RedeemCodeRepository

NewRedeemCodeRepository 创建兑换码仓库

func (*RedeemCodeRepository) Count

func (r *RedeemCodeRepository) Count() (int, error)

Count 获取兑换码总数

func (*RedeemCodeRepository) CountUnused

func (r *RedeemCodeRepository) CountUnused() (int, error)

CountUnused 获取未使用的兑换码数量

func (*RedeemCodeRepository) Create

func (r *RedeemCodeRepository) Create(code *models.RedeemCode) error

Create 创建兑换码

func (*RedeemCodeRepository) Delete

func (r *RedeemCodeRepository) Delete(id int64) error

Delete 删除兑换码

func (*RedeemCodeRepository) GetAll

func (r *RedeemCodeRepository) GetAll(limit, offset int) ([]*models.RedeemCode, error)

GetAll 获取所有兑换码

func (*RedeemCodeRepository) GetByCode

func (r *RedeemCodeRepository) GetByCode(codeStr string) (*models.RedeemCode, error)

GetByCode 根据兑换码获取记录

func (*RedeemCodeRepository) GetByPlanID

func (r *RedeemCodeRepository) GetByPlanID(planID int64) ([]*models.RedeemCode, error)

GetByPlanID 获取某个套餐的所有兑换码

func (*RedeemCodeRepository) GetUnused

func (r *RedeemCodeRepository) GetUnused() ([]*models.RedeemCode, error)

GetUnused 获取所有未使用的兑换码

func (*RedeemCodeRepository) UseCode

func (r *RedeemCodeRepository) UseCode(id, userID int64) error

UseCode 使用兑换码

type SubscriptionRepository

type SubscriptionRepository struct {
	// contains filtered or unexported fields
}

SubscriptionRepository 订阅数据访问层

func NewSubscriptionRepository

func NewSubscriptionRepository(db *DB) *SubscriptionRepository

NewSubscriptionRepository 创建订阅仓库

func (*SubscriptionRepository) Count

func (r *SubscriptionRepository) Count() (int, error)

Count 获取总订阅数

func (*SubscriptionRepository) CountActive

func (r *SubscriptionRepository) CountActive() (int, error)

CountActive 获取有效订阅数

func (*SubscriptionRepository) Create

Create 创建订阅

func (*SubscriptionRepository) ExpireOldSubscriptions

func (r *SubscriptionRepository) ExpireOldSubscriptions() (int, error)

ExpireOldSubscriptions 使过期订阅失效

func (*SubscriptionRepository) ExtendExpiration

func (r *SubscriptionRepository) ExtendExpiration(id int64, days int) error

ExtendExpiration 延长订阅

func (*SubscriptionRepository) GetActiveByUserID

func (r *SubscriptionRepository) GetActiveByUserID(userID int64) (*models.Subscription, error)

GetActiveByUserID 获取用户的有效订阅

func (*SubscriptionRepository) GetAllByUserID

func (r *SubscriptionRepository) GetAllByUserID(userID int64) ([]*models.Subscription, error)

GetAllByUserID 获取用户所有订阅记录

func (*SubscriptionRepository) GetByID

GetByID 根据ID获取订阅

func (*SubscriptionRepository) UpdateStatus

func (r *SubscriptionRepository) UpdateStatus(id int64, status string) error

UpdateStatus 更新订阅状态

type SystemConfigRepository

type SystemConfigRepository struct {
	// contains filtered or unexported fields
}

SystemConfigRepository 系统配置数据访问层

func NewSystemConfigRepository

func NewSystemConfigRepository(db *DB) *SystemConfigRepository

NewSystemConfigRepository 创建系统配置仓库

func (*SystemConfigRepository) Delete

func (r *SystemConfigRepository) Delete(key string) error

Delete 删除配置项

func (*SystemConfigRepository) Get

func (r *SystemConfigRepository) Get(key string) (string, error)

Get 获取配置项

func (*SystemConfigRepository) GetAll

func (r *SystemConfigRepository) GetAll() ([]*models.SystemConfig, error)

GetAll 获取所有配置

func (*SystemConfigRepository) GetByPrefix

func (r *SystemConfigRepository) GetByPrefix(prefix string) ([]*models.SystemConfig, error)

GetByPrefix 根据前缀获取配置

func (*SystemConfigRepository) GetWithDefault

func (r *SystemConfigRepository) GetWithDefault(key, defaultValue string) string

GetWithDefault 获取配置项,如果不存在则返回默认值

func (*SystemConfigRepository) Set

func (r *SystemConfigRepository) Set(key, value string) error

Set 设置配置项

type UserRepository

type UserRepository struct {
	// contains filtered or unexported fields
}

UserRepository 用户数据访问层

func NewUserRepository

func NewUserRepository(db *DB) *UserRepository

NewUserRepository 创建用户仓库

func (*UserRepository) Count

func (r *UserRepository) Count() (int, error)

Count 获取用户总数

func (*UserRepository) Create

func (r *UserRepository) Create(user *models.User) error

Create 创建用户

func (*UserRepository) GetAll

func (r *UserRepository) GetAll(limit, offset int) ([]*models.User, error)

GetAll 获取所有用户(分页)

func (*UserRepository) GetAllAdmins

func (r *UserRepository) GetAllAdmins() ([]*models.User, error)

GetAllAdmins 获取所有管理员

func (*UserRepository) GetByID

func (r *UserRepository) GetByID(id int64) (*models.User, error)

GetByID 根据ID获取用户

func (*UserRepository) GetByTelegramID

func (r *UserRepository) GetByTelegramID(telegramID int64) (*models.User, error)

GetByTelegramID 根据Telegram ID获取用户

func (*UserRepository) GetOrCreate

func (r *UserRepository) GetOrCreate(telegramID int64, username, firstName, lastName string) (*models.User, error)

GetOrCreate 获取或创建用户

func (*UserRepository) SetAdmin

func (r *UserRepository) SetAdmin(telegramID int64, isAdmin bool) error

SetAdmin 设置管理员

func (*UserRepository) Update

func (r *UserRepository) Update(user *models.User) error

Update 更新用户信息

type WorkerBotRepository

type WorkerBotRepository struct {
	// contains filtered or unexported fields
}

WorkerBotRepository 子Bot数据访问层

func NewWorkerBotRepository

func NewWorkerBotRepository(db *DB) *WorkerBotRepository

NewWorkerBotRepository 创建子Bot仓库

func (*WorkerBotRepository) Count

func (r *WorkerBotRepository) Count() (int, error)

Count 获取所有子Bot数量

func (*WorkerBotRepository) CountByUserID

func (r *WorkerBotRepository) CountByUserID(userID int64) (int, error)

CountByUserID 获取用户的子Bot数量

func (*WorkerBotRepository) CountRunning

func (r *WorkerBotRepository) CountRunning() (int, error)

CountRunning 获取运行中的子Bot数量

func (*WorkerBotRepository) Create

func (r *WorkerBotRepository) Create(bot *models.WorkerBot) error

Create 创建子Bot

func (*WorkerBotRepository) Delete

func (r *WorkerBotRepository) Delete(id int64) error

Delete 删除子Bot

func (*WorkerBotRepository) GetByID

func (r *WorkerBotRepository) GetByID(id int64) (*models.WorkerBot, error)

GetByID 根据ID获取子Bot

func (*WorkerBotRepository) GetByUserID

func (r *WorkerBotRepository) GetByUserID(userID int64) ([]*models.WorkerBot, error)

GetByUserID 获取用户的所有子Bot

func (*WorkerBotRepository) Update

func (r *WorkerBotRepository) Update(bot *models.WorkerBot) error

Update 更新子Bot信息

func (*WorkerBotRepository) UpdateStatus

func (r *WorkerBotRepository) UpdateStatus(id int64, status string) error

UpdateStatus 更新子Bot状态

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL