Help us shape the future of Go! Take the 2026 Go Developer Survey

services

package
v0.0.0-...-2c5a763 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 44 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithResumeInput

func WithResumeInput(input string) einotool.Option

WithResumeInput 创建一个包含恢复输入的工具选项

Types

type AuthService

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

func NewAuthService

func NewAuthService(db *gorm.DB, cfg *config.Config, rbac *RBACService, ca cache.Cache) *AuthService

func (*AuthService) AdminLogin

func (s *AuthService) AdminLogin(ctx context.Context, phone, password, userAgent string) (*response.WechatLoginResponse, error)

AdminLogin 后台手机号密码登录

func (*AuthService) BanUser

func (s *AuthService) BanUser(ctx context.Context, operatorUserID, targetUserID uint, durationSeconds int64, reason string) (int, error)

func (*AuthService) GetUserAuthDetail

func (s *AuthService) GetUserAuthDetail(ctx context.Context, userID uint) (*response.UserAuthDetailResponse, error)

func (*AuthService) GetUserByID

func (s *AuthService) GetUserByID(ctx context.Context, userID uint) (*models.User, error)

GetUserByID 根据ID获取用户信息

func (*AuthService) GetUserSessions

func (s *AuthService) GetUserSessions(ctx context.Context, userID uint, currentSID string) ([]response.AuthSessionSummary, error)

func (*AuthService) KickUser

func (s *AuthService) KickUser(ctx context.Context, operatorUserID, targetUserID uint) (int, error)

func (*AuthService) Logout

func (s *AuthService) Logout(ctx context.Context, userID uint, sid string) error

func (*AuthService) LogoutAll

func (s *AuthService) LogoutAll(ctx context.Context, userID uint) (int, error)

func (*AuthService) MockWechatLogin

func (s *AuthService) MockWechatLogin(ctx context.Context, testUser, userAgent string) (*response.WechatLoginResponse, error)

MockWechatLogin 模拟微信小程序登录 - 仅用于测试

func (*AuthService) RefreshToken

func (s *AuthService) RefreshToken(ctx context.Context, refreshTokenString, userAgent string) (*response.WechatLoginResponse, error)

RefreshToken 刷新 AccessToken 和 RefreshToken。

func (*AuthService) SetAdminLoginCredentials

func (s *AuthService) SetAdminLoginCredentials(ctx context.Context, operatorUserID, targetUserID uint, phone, password string) error

SetAdminLoginCredentials 设置后台登录凭据

func (*AuthService) UnbanUser

func (s *AuthService) UnbanUser(ctx context.Context, operatorUserID, targetUserID uint) error

func (*AuthService) UpdateUserProfile

func (s *AuthService) UpdateUserProfile(ctx context.Context, userID uint, updates map[string]any) error

UpdateUserProfile 更新用户资料

func (*AuthService) WechatLogin

func (s *AuthService) WechatLogin(ctx context.Context, code, userAgent string) (*response.WechatLoginResponse, error)

WechatLogin 微信小程序登录

type ChatService

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

func NewChatService

func NewChatService(db *gorm.DB, cfg *config.Config) *ChatService

func (*ChatService) AppendMessages

func (s *ChatService) AppendMessages(ctx context.Context, userID, conversationID uint, checkpointID string, messages []*schema.Message) error

AppendMessages 追加消息到对话消息表

func (*ChatService) CreateConversation

func (s *ChatService) CreateConversation(ctx context.Context, userID uint, title string) (*models.Conversation, error)

CreateConversation 创建新对话

func (*ChatService) DeleteConversation

func (s *ChatService) DeleteConversation(ctx context.Context, userID, conversationID uint) error

DeleteConversation 删除对话

func (*ChatService) ExportConversation

func (s *ChatService) ExportConversation(ctx context.Context, userID, conversationID uint) (*models.Conversation, []*schema.Message, error)

ExportConversation 导出对话

func (*ChatService) GenerateTitleFromFirstMessage

func (s *ChatService) GenerateTitleFromFirstMessage(ctx context.Context, content string) (string, error)

GenerateTitleFromFirstMessage 从第一条消息生成标题

func (*ChatService) GetConversation

func (s *ChatService) GetConversation(ctx context.Context, userID, conversationID uint) (*models.Conversation, error)

GetConversation 获取对话详情

func (*ChatService) GetMessages

func (s *ChatService) GetMessages(ctx context.Context, userID, conversationID uint) ([]*schema.Message, error)

GetMessages 获取对话的所有消息

func (*ChatService) ListConversations

func (s *ChatService) ListConversations(ctx context.Context, userID uint, page, pageSize int) ([]models.Conversation, int64, error)

ListConversations 列出用户的对话

func (*ChatService) StreamChat

func (s *ChatService) StreamChat(ctx context.Context, userID, conversationID uint, newMessage *schema.Message, userToken string, checkpointID string, resumeInput string) (<-chan string, <-chan error, error)

StreamChat 流式聊天 (返回一个通道用于 SSE) 使用 NewChatModelAgent 实现,支持中断恢复和流式传输 当 checkpointID 不为空时,执行恢复操作;否则执行新对话

func (*ChatService) UpdateConversation

func (s *ChatService) UpdateConversation(ctx context.Context, userID, conversationID uint, title string) error

UpdateConversation 更新对话标题

type ConfigService

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

func NewConfigService

func NewConfigService(db *gorm.DB) *ConfigService

func (*ConfigService) Create

func (s *ConfigService) Create(ctx context.Context, key, value, valueType, description string) (*models.SystemConfig, error)

Create 创建配置项(key唯一)

func (*ConfigService) Delete

func (s *ConfigService) Delete(ctx context.Context, key string) error

Delete 软删除(按key)

func (*ConfigService) GetByKey

func (s *ConfigService) GetByKey(ctx context.Context, key string) (*models.SystemConfig, error)

GetByKey 通过key获取配置项

func (*ConfigService) SearchConfigs

func (s *ConfigService) SearchConfigs(ctx context.Context, query string, page, size int) ([]models.SystemConfig, int64, error)

SearchConfigs 搜索配置项,支持按key搜索,空query返回全部(分页版本)

func (*ConfigService) Update

func (s *ConfigService) Update(ctx context.Context, key, value, valueType string, description *string) error

Update 根据key更新配置项

type ContributionService

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

func NewContributionService

func NewContributionService(db *gorm.DB, pointsService *PointsService) *ContributionService

func (*ContributionService) CreateContribution

func (s *ContributionService) CreateContribution(ctx context.Context, userID uint, req *request.CreateContributionRequest) error

CreateContribution 创建投稿

func (*ContributionService) GetAdminContributionStats

func (s *ContributionService) GetAdminContributionStats(ctx context.Context) (*response.AdminContributionStatsResponse, error)

GetAdminContributionStats 获取管理员投稿统计(全系统)

func (*ContributionService) GetContributionByID

func (s *ContributionService) GetContributionByID(ctx context.Context, contributionID uint, userID uint) (*response.ContributionResponse, error)

GetContributionByID 根据ID获取投稿详情

func (*ContributionService) GetContributions

GetContributions 获取投稿列表

func (*ContributionService) GetUserContributionStats

func (s *ContributionService) GetUserContributionStats(ctx context.Context, userID uint) (map[string]interface{}, error)

GetUserContributionStats 获取用户投稿统计

func (*ContributionService) ReviewContribution

func (s *ContributionService) ReviewContribution(ctx context.Context, contributionID uint, reviewerID uint, req *request.ReviewContributionRequest) error

ReviewContribution 审核投稿

type CountdownService

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

func NewCountdownService

func NewCountdownService(db *gorm.DB) *CountdownService

func (*CountdownService) CreateCountdown

CreateCountdown 创建倒数日

func (*CountdownService) DeleteCountdown

func (s *CountdownService) DeleteCountdown(ctx context.Context, countdownID uint, userID uint) error

DeleteCountdown 删除倒数日

func (*CountdownService) GetCountdownByID

func (s *CountdownService) GetCountdownByID(ctx context.Context, countdownID uint, userID uint) (*response.CountdownResponse, error)

GetCountdownByID 根据ID获取倒数日详情

func (*CountdownService) GetCountdowns

func (s *CountdownService) GetCountdowns(ctx context.Context, userID uint) ([]response.CountdownResponse, error)

GetCountdowns 获取用户倒数日列表

func (*CountdownService) UpdateCountdown

func (s *CountdownService) UpdateCountdown(ctx context.Context, countdownID uint, userID uint, req *request.UpdateCountdownRequest) (*response.CountdownResponse, error)

UpdateCountdown 更新倒数日

type CourseTableService

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

func NewCourseTableService

func NewCourseTableService(db *gorm.DB) *CourseTableService

func (*CourseTableService) CreateAdminCourseTable

func (*CourseTableService) DeleteAdminCourseTable

func (s *CourseTableService) DeleteAdminCourseTable(ctx context.Context, id uint) error

func (*CourseTableService) EditUserCourseCell

func (s *CourseTableService) EditUserCourseCell(ctx context.Context, userID uint, semester string, index string, value datatypes.JSON) error

EditUserCourseCell 编辑用户课程表的单个格子(1-35)

func (*CourseTableService) GetAdminCourseTableByID

func (s *CourseTableService) GetAdminCourseTableByID(ctx context.Context, id uint) (*response.AdminCourseTableResponse, error)

func (*CourseTableService) GetUserBindCount

func (s *CourseTableService) GetUserBindCount(ctx context.Context, userID uint) (int, error)

GetUserBindCount 获取当前用户的课表绑定次数

func (*CourseTableService) GetUserCourseTable

func (s *CourseTableService) GetUserCourseTable(ctx context.Context, userID uint, semester string) (*response.CourseTableResponse, error)

GetUserCourseTable 获取用户课程表 (保持向后兼容)

func (*CourseTableService) GetUserCourseTableWithVersion

func (s *CourseTableService) GetUserCourseTableWithVersion(ctx context.Context, userID uint, semester string, clientLastModified *int64) (*response.CourseTableResponse, error)

GetUserCourseTableWithVersion 获取用户课程表(带版本检测)

func (*CourseTableService) ListAdminCourseTables

func (*CourseTableService) ResetUserBindCount

func (s *CourseTableService) ResetUserBindCount(ctx context.Context, targetUserID uint) error

func (*CourseTableService) ResetUserBindCountToOne

func (s *CourseTableService) ResetUserBindCountToOne(ctx context.Context, targetUserID uint) error

ResetUserBindCountToOne 将指定用户的绑定次数置为1(管理员操作)

func (*CourseTableService) ResetUserSchedule

func (s *CourseTableService) ResetUserSchedule(ctx context.Context, userID uint, semester string) error

ResetUserSchedule 重置用户个人课表(删除个人编辑的数据条目)

func (*CourseTableService) SearchClasses

func (s *CourseTableService) SearchClasses(ctx context.Context, keyword string, page, size int) (*response.SearchClassResponse, error)

SearchClasses 模糊搜索班级

func (*CourseTableService) UpdateAdminCourseTable

func (*CourseTableService) UpdateUserClass

func (s *CourseTableService) UpdateUserClass(ctx context.Context, userID uint, classID string) (err error)

UpdateUserClass 更新用户班级(普通用户2次绑定限制)

type DictionaryService

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

func NewDictionaryService

func NewDictionaryService(db *gorm.DB) *DictionaryService

func (*DictionaryService) GetRandomWord

func (s *DictionaryService) GetRandomWord(ctx context.Context) (*models.Dictionary, error)

GetRandomWord 从数据库随机获取一个词

type FailRateService

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

func NewFailRateService

func NewFailRateService(db *gorm.DB) *FailRateService

func (*FailRateService) CreateAdminFailRate

func (*FailRateService) DeleteAdminFailRate

func (s *FailRateService) DeleteAdminFailRate(ctx context.Context, id uint) error

func (*FailRateService) GetAdminFailRateByID

func (s *FailRateService) GetAdminFailRateByID(ctx context.Context, id uint) (*response.AdminFailRateResponse, error)

func (*FailRateService) ListAdminFailRates

func (*FailRateService) Rand

func (s *FailRateService) Rand(ctx context.Context, limit int) ([]models.FailRate, error)

Rand 获取随机 N 条(无筛选)- 全表均匀抽样,避免使用 ORDER BY RAND()

func (*FailRateService) Search

func (s *FailRateService) Search(ctx context.Context, keyword string, page, size int) ([]models.FailRate, int64, error)

Search 按课程名关键词分页查询,默认按 failrate 降序

func (*FailRateService) UpdateAdminFailRate

type FeatureService

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

func NewFeatureService

func NewFeatureService(db *gorm.DB) *FeatureService

func (*FeatureService) BatchGrantFeatureToUsers

func (s *FeatureService) BatchGrantFeatureToUsers(ctx context.Context, userIDs []uint, featureKey string) error

BatchGrantFeatureToUsers 批量授予用户功能权限

func (*FeatureService) CheckUserFeature

func (s *FeatureService) CheckUserFeature(ctx context.Context, userID uint, featureKey string) (bool, error)

CheckUserFeature 检查用户是否有指定功能权限(带缓存)

func (*FeatureService) CreateFeature

func (s *FeatureService) CreateFeature(ctx context.Context, feature *models.Feature) error

CreateFeature 创建功能

func (*FeatureService) DB

func (s *FeatureService) DB() *gorm.DB

DB 返回数据库实例(供Handler使用)

func (*FeatureService) DeleteFeature

func (s *FeatureService) DeleteFeature(ctx context.Context, featureKey string) error

DeleteFeature 删除功能(软删除)

func (*FeatureService) GetEnabledProjectFeatures

func (s *FeatureService) GetEnabledProjectFeatures(ctx context.Context) (map[string]bool, error)

GetEnabledProjectFeatures 获取所有启用的项目灰度 feature_key 查询 SELECT ... LIKE 'review.project.%' 走 B-tree 索引前缀匹配,~1ms,无需缓存

func (*FeatureService) GetFeature

func (s *FeatureService) GetFeature(ctx context.Context, featureKey string) (*models.Feature, error)

GetFeature 获取功能详情

func (*FeatureService) GetRoleIDsByFeature

func (s *FeatureService) GetRoleIDsByFeature(ctx context.Context, featureKey string) ([]uint, error)

GetRoleIDsByFeature 查询某功能已授权的角色ID列表

func (*FeatureService) GetUserFeatures

func (s *FeatureService) GetUserFeatures(ctx context.Context, userID uint) ([]string, error)

GetUserFeatures 获取用户的所有可用功能列表(带缓存) 来源:① user_id IN user_ids ② user_role IN role_ids(一条SQL搞定)

func (*FeatureService) GetUserIDsByFeature

func (s *FeatureService) GetUserIDsByFeature(ctx context.Context, featureKey string) ([]uint, error)

GetUserIDsByFeature 查询某功能已授权的用户ID列表

func (*FeatureService) GrantFeatureToUser

func (s *FeatureService) GrantFeatureToUser(ctx context.Context, userID uint, featureKey string) error

GrantFeatureToUser 授予用户功能权限(往 UserIDs JSON 数组添加 userID)

func (*FeatureService) GrantRoleToFeature

func (s *FeatureService) GrantRoleToFeature(ctx context.Context, featureKey string, roleID uint) error

GrantRoleToFeature 给功能添加单个授权角色(追加到 role_ids)

func (*FeatureService) IsFeatureEnabled

func (s *FeatureService) IsFeatureEnabled(ctx context.Context, featureKey string) (bool, error)

IsFeatureEnabled 检查功能是否全局启用(带缓存)

func (*FeatureService) ListFeatures

func (s *FeatureService) ListFeatures(ctx context.Context) ([]models.Feature, error)

ListFeatures 获取所有功能列表

func (*FeatureService) RevokeFeatureFromUser

func (s *FeatureService) RevokeFeatureFromUser(ctx context.Context, userID uint, featureKey string) error

RevokeFeatureFromUser 撤销用户功能权限(从 UserIDs JSON 数组移除)

func (*FeatureService) RevokeRoleFromFeature

func (s *FeatureService) RevokeRoleFromFeature(ctx context.Context, featureKey string, roleID uint) error

RevokeRoleFromFeature 从功能移除单个授权角色

func (*FeatureService) SetFeatureRoles

func (s *FeatureService) SetFeatureRoles(ctx context.Context, featureKey string, roleIDs []uint) error

SetFeatureRoles 设置功能的授权角色ID列表

func (*FeatureService) UpdateFeature

func (s *FeatureService) UpdateFeature(ctx context.Context, featureKey string, updates map[string]interface{}) error

UpdateFeature 更新功能

type GPABackupService

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

func NewGPABackupService

func NewGPABackupService(db *gorm.DB) *GPABackupService

func (*GPABackupService) CreateBackup

func (s *GPABackupService) CreateBackup(ctx context.Context, userID uint, title string, rawData []byte) (*response.GPABackupResponse, error)

func (*GPABackupService) DeleteBackup

func (s *GPABackupService) DeleteBackup(ctx context.Context, userID, backupID uint) error

func (*GPABackupService) GetBackupByID

func (s *GPABackupService) GetBackupByID(ctx context.Context, userID, backupID uint) (*response.GPABackupResponse, error)

func (*GPABackupService) ListBackups

func (s *GPABackupService) ListBackups(ctx context.Context, userID uint) ([]response.GPABackupResponse, error)

type HeroService

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

func NewHeroService

func NewHeroService(db *gorm.DB) *HeroService

func (*HeroService) Create

func (s *HeroService) Create(ctx context.Context, name string, sort int, isShow bool) (*models.Hero, error)

func (*HeroService) Delete

func (s *HeroService) Delete(ctx context.Context, id uint) error

func (*HeroService) Get

func (s *HeroService) Get(ctx context.Context, id uint) (*models.Hero, error)

func (*HeroService) ListAll

func (s *HeroService) ListAll(ctx context.Context) ([]string, error)

ListAll 返回仅名称的字符串数组,按 sort 升序(只返回is_show=true的)

func (*HeroService) SearchHeroes

func (s *HeroService) SearchHeroes(ctx context.Context, query string, isShow *bool, page, size int) ([]models.Hero, int64, error)

SearchHeroes 搜索英雄,支持按名称搜索和是否显示过滤,空query返回全部(分页版本)

func (*HeroService) Update

func (s *HeroService) Update(ctx context.Context, id uint, name string, sort *int, isShow *bool) error

type MaterialService

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

func NewMaterialService

func NewMaterialService(db *gorm.DB) *MaterialService

func (*MaterialService) CalculateHotness

func (s *MaterialService) CalculateHotness(ctx context.Context) error

CalculateHotness 计算热度(定时任务调用)

func (*MaterialService) CreateMaterialLog

func (s *MaterialService) CreateMaterialLog(ctx context.Context, userID uint, req *request.MaterialLogCreateRequest) error

CreateMaterialLog 创建资料日志

func (*MaterialService) DeleteMaterial

func (s *MaterialService) DeleteMaterial(ctx context.Context, md5 string) error

DeleteMaterial 删除资料(管理员)

func (*MaterialService) GetCategoriesByParent

func (s *MaterialService) GetCategoriesByParent(ctx context.Context, parentID *uint) ([]response.MaterialCategoryResponse, error)

GetCategoriesByParent 通过上级分类ID获取分类(只获取第一层子分类)

func (*MaterialService) GetHotWords

func (s *MaterialService) GetHotWords(ctx context.Context, limit int) ([]response.HotWordsResponse, error)

GetHotWords 获取搜索热词

func (*MaterialService) GetMaterialByMD5

func (s *MaterialService) GetMaterialByMD5(ctx context.Context, md5 string, userID *uint) (*response.MaterialDetailResponse, error)

GetMaterialByMD5 根据MD5获取资料详情

func (*MaterialService) GetMaterialDesc

func (s *MaterialService) GetMaterialDesc(ctx context.Context, md5 string) (*response.MaterialDescResponse, error)

GetMaterialDesc 获取资料描述

func (*MaterialService) GetMaterialList

GetMaterialList 获取资料列表(按热度排序)

func (*MaterialService) GetTopMaterials

GetTopMaterials 获取TOP热门资料

func (*MaterialService) RateMaterial

func (s *MaterialService) RateMaterial(ctx context.Context, userID uint, md5 string, rating int) error

RateMaterial 为资料评分

func (*MaterialService) SearchMaterials

SearchMaterials 搜索资料

func (*MaterialService) UpdateMaterialDesc

func (s *MaterialService) UpdateMaterialDesc(ctx context.Context, md5 string, req *request.MaterialDescUpdateRequest) error

UpdateMaterialDesc 更新资料描述(管理员,不存在时自动创建)

type NotificationService

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

func NewNotificationService

func NewNotificationService(db *gorm.DB, rbacService *RBACService) *NotificationService

func (*NotificationService) ApproveNotification

func (s *NotificationService) ApproveNotification(ctx context.Context, notificationID uint, reviewerID uint, req *request.ApproveNotificationRequest) error

ApproveNotification 审核通知

func (*NotificationService) ConvertToSchedule

func (s *NotificationService) ConvertToSchedule(ctx context.Context, notificationID uint, req *request.ConvertToScheduleRequest) error

ConvertToSchedule 转换通知为日程

func (*NotificationService) CreateCategory

CreateCategory 创建分类

func (*NotificationService) CreateNotification

CreateNotification 创建通知(管理员专用)

func (*NotificationService) DeleteNotification

func (s *NotificationService) DeleteNotification(ctx context.Context, notificationID uint, userID uint) error

DeleteNotification 删除通知(软删除)

func (*NotificationService) GetAdminNotifications

GetAdminNotifications 获取管理员通知列表(包括所有状态的通知)

func (*NotificationService) GetCategories

GetCategories 获取所有分类

func (*NotificationService) GetNotificationAdminByID

func (s *NotificationService) GetNotificationAdminByID(ctx context.Context, notificationID uint) (*response.NotificationResponse, error)

GetNotificationByID 根据ID获取通知详情

func (*NotificationService) GetNotificationByID

func (s *NotificationService) GetNotificationByID(ctx context.Context, notificationID uint) (*response.NotificationResponse, error)

GetNotificationByID 根据ID获取通知详情

func (*NotificationService) GetNotificationStats

GetNotificationStats 获取通知统计信息

func (*NotificationService) GetNotifications

GetNotifications 获取通知列表

func (*NotificationService) PinNotification

func (s *NotificationService) PinNotification(ctx context.Context, notificationID uint) error

PinNotification 置顶通知(管理员专用)

func (*NotificationService) PublishNotification

func (s *NotificationService) PublishNotification(ctx context.Context, notificationID uint, userID uint) error

PublishNotification 发布通知

func (*NotificationService) PublishNotificationAdmin

func (s *NotificationService) PublishNotificationAdmin(ctx context.Context, notificationID uint, userID uint) error

PublishNotificationAdmin 管理员直接发布通知(跳过审核流程)

func (*NotificationService) UnpinNotification

func (s *NotificationService) UnpinNotification(ctx context.Context, notificationID uint) error

UnpinNotification 取消置顶通知(管理员专用)

func (*NotificationService) UpdateCategory

UpdateCategory 更新分类

func (*NotificationService) UpdateNotification

func (s *NotificationService) UpdateNotification(ctx context.Context, notificationID uint, userID uint, req *request.UpdateNotificationRequest) (*response.NotificationResponse, error)

UpdateNotification 更新通知

type OSSService

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

OSSService 负责生成又拍云/自建 CDN 的 Token 防盗链参数

func NewOSSService

func NewOSSService(cfg *config.Config) *OSSService

func (*OSSService) GenerateToken

func (s *OSSService) GenerateToken(uri string, ttlSeconds int64) (token string, expireAt int64, signedURL string, err error)

GenerateToken 根据 URI 生成 _upt 参数与可选的完整签名 URL 算法参考: https://help.upyun.com/knowledge-base/cdn-token-limite/

type OrganizationService

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

func NewOrganizationService

func NewOrganizationService(db *gorm.DB) *OrganizationService

func (*OrganizationService) CreateOrganization

func (*OrganizationService) DeleteOrganization

func (s *OrganizationService) DeleteOrganization(ctx context.Context, id uint) error

func (*OrganizationService) GetOrganizationByID

func (s *OrganizationService) GetOrganizationByID(ctx context.Context, id uint) (*models.Organization, error)

func (*OrganizationService) ListOrganizations

func (*OrganizationService) UpdateOrganization

type PointsService

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

func NewPointsService

func NewPointsService(db *gorm.DB) *PointsService

func (*PointsService) AddPoints

func (s *PointsService) AddPoints(ctx context.Context, tx *gorm.DB, userID uint, points int, source string, description string, relatedID *uint) error

AddPoints 增加积分(内部方法,用于其他服务调用)

func (*PointsService) GetPointsTransactions

func (s *PointsService) GetPointsTransactions(ctx context.Context, userID uint, req *request.GetPointsTransactionsRequest) (*response.PageResponse, error)

GetPointsTransactions 获取积分交易记录

func (*PointsService) GetUserPoints

func (s *PointsService) GetUserPoints(ctx context.Context, userID uint) (*response.UserPointsResponse, error)

GetUserPoints 获取用户积分信息

func (*PointsService) GetUserPointsStats

func (s *PointsService) GetUserPointsStats(ctx context.Context, userID uint) (map[string]interface{}, error)

GetUserPointsStats 获取用户积分统计

func (*PointsService) GrantPoints

func (s *PointsService) GrantPoints(ctx context.Context, userID uint, points int, description string) error

GrantPoints 管理员手动赋予积分

func (*PointsService) SpendPoints

func (s *PointsService) SpendPoints(ctx context.Context, userID uint, req *request.SpendPointsRequest) error

SpendPoints 消费积分(原RedeemPoints)

type PomodoroService

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

func NewPomodoroService

func NewPomodoroService(db *gorm.DB) *PomodoroService

func (*PomodoroService) GetPomodoroCount

func (s *PomodoroService) GetPomodoroCount(ctx context.Context, userID uint) (uint, error)

GetPomodoroCount 获取用户番茄钟次数

func (*PomodoroService) GetPomodoroRanking

func (s *PomodoroService) GetPomodoroRanking(ctx context.Context) ([]response.PomodoroRankingItem, error)

GetPomodoroRanking 获取番茄钟排名(前20名)

func (*PomodoroService) IncrementPomodoroCount

func (s *PomodoroService) IncrementPomodoroCount(ctx context.Context, userID uint) error

IncrementPomodoroCount 增加番茄钟次数

type QuestionService

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

func NewQuestionService

func NewQuestionService(db *gorm.DB, featureService *FeatureService) *QuestionService

func (*QuestionService) CreateAdminQuestion

func (*QuestionService) DeleteAdminQuestion

func (s *QuestionService) DeleteAdminQuestion(ctx context.Context, id uint) error

func (*QuestionService) DeleteAdminQuestionProject

func (s *QuestionService) DeleteAdminQuestionProject(ctx context.Context, id uint) error

func (*QuestionService) GetAdminQuestionByID

func (s *QuestionService) GetAdminQuestionByID(ctx context.Context, id uint) (*response.AdminQuestionResponse, error)

func (*QuestionService) GetAdminQuestionProjectByID

func (s *QuestionService) GetAdminQuestionProjectByID(ctx context.Context, id uint) (*response.AdminQuestionProjectResponse, error)

func (*QuestionService) GetProjectByID

func (s *QuestionService) GetProjectByID(ctx context.Context, projectID uint) (*models.QuestionProject, error)

GetProjectByID 根据ID获取项目

func (*QuestionService) GetProjects

func (s *QuestionService) GetProjects(ctx context.Context, userID uint) ([]response.QuestionProjectResponse, error)

GetProjects 获取项目列表 灰度规则:若 features 表中存在 review.project.{id} 且 is_enabled=true,则该项目灰度 feature 不存在或 is_enabled=false → 公开可见

func (*QuestionService) GetQuestionByID

func (s *QuestionService) GetQuestionByID(ctx context.Context, userID, questionID uint) (*response.QuestionResponse, error)

GetQuestionByID 获取题目详情(公开方法)

func (*QuestionService) GetQuestions

GetQuestions 获取题目列表(只返回题目ID数组,支持顺序/乱序)

func (*QuestionService) ListAdminQuestions

func (*QuestionService) RecordStudy

func (s *QuestionService) RecordStudy(ctx context.Context, userID uint, req *request.RecordStudyRequest) error

RecordStudy 记录学习(仅记录学习次数)

func (*QuestionService) SubmitPractice

func (s *QuestionService) SubmitPractice(ctx context.Context, userID uint, req *request.SubmitPracticeRequest) error

SubmitPractice 提交做题(仅记录做题次数)

func (*QuestionService) UpdateAdminQuestion

type RBACService

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

RBACService 提供角色、权限、用户授权的核心能力

func NewRBACService

func NewRBACService(db *gorm.DB) *RBACService

NewRBACService 创建 RBAC 服务

func (*RBACService) CheckPermission

func (s *RBACService) CheckPermission(ctx context.Context, userID uint, permissionTag string) (bool, error)

CheckPermission 判断用户是否拥有指定权限

func (*RBACService) CheckUserRole

func (s *RBACService) CheckUserRole(ctx context.Context, userID uint, role string) bool

CheckUserRole 检查用户是否拥有指定角色

func (*RBACService) CreatePermission

func (s *RBACService) CreatePermission(ctx context.Context, perm *models.Permission) error

CreatePermission 创建权限

func (*RBACService) CreateRole

func (s *RBACService) CreateRole(ctx context.Context, role *models.Role) error

CreateRole 创建角色

func (*RBACService) DeleteRole

func (s *RBACService) DeleteRole(ctx context.Context, id uint) error

DeleteRole 删除角色并清理关联

func (*RBACService) EnsureUserHasRoleByTag

func (s *RBACService) EnsureUserHasRoleByTag(ctx context.Context, userID uint, roleTag string) error

EnsureUserHasRoleByTag 确保用户拥有指定角色(用于新用户默认授权)

func (*RBACService) GetRolesWithPermissions

func (s *RBACService) GetRolesWithPermissions(ctx context.Context) ([]models.Role, map[uint][]models.Permission, error)

GetRolesWithPermissions 获取所有角色及其对应的权限列表

func (*RBACService) GetUserPermissionSnapshot

func (s *RBACService) GetUserPermissionSnapshot(ctx context.Context, userID uint) (*UserPermissionSnapshot, error)

GetUserPermissionSnapshot 获取用户有效权限(含缓存)

func (*RBACService) GetUserPermissions

func (s *RBACService) GetUserPermissions(ctx context.Context, userID uint) ([]string, error)

GetUserPermissions 返回用户权限标识列表

func (*RBACService) GetUserRoleTags

func (s *RBACService) GetUserRoleTags(ctx context.Context, userID uint) ([]string, error)

GetUserRoleTags 获取用户角色标签

func (*RBACService) GetUsersByRoleTags

func (s *RBACService) GetUsersByRoleTags(ctx context.Context, roleTags []string) ([]models.User, error)

GetUsersByRoleTags 根据角色标签列表获取用户数组

func (*RBACService) GrantRole

func (s *RBACService) GrantRole(ctx context.Context, userID uint, roleID uint) error

GrantRole 授予用户角色(如果不存在)

func (*RBACService) ListPermissions

func (s *RBACService) ListPermissions(ctx context.Context) ([]models.Permission, error)

ListPermissions 获取权限列表

func (*RBACService) ListRoles

func (s *RBACService) ListRoles(ctx context.Context) ([]models.Role, error)

ListRoles 获取角色列表

func (*RBACService) ListRolesWithUsers

func (s *RBACService) ListRolesWithUsers(ctx context.Context) ([]models.Role, map[uint]int, map[uint][]uint, error)

ListRolesWithUsers 获取角色列表及其用户信息

func (*RBACService) RevokeRole

func (s *RBACService) RevokeRole(ctx context.Context, userID uint, roleID uint) error

RevokeRole 撤销用户角色

func (*RBACService) SeedDefaults

func (s *RBACService) SeedDefaults(ctx context.Context) error

SeedDefaults 初始化设计文档中预置的角色/权限与绑定关系

func (*RBACService) UpdateRole

func (s *RBACService) UpdateRole(ctx context.Context, id uint, updates map[string]any) error

UpdateRole 更新角色

func (*RBACService) UpdateRolePermissions

func (s *RBACService) UpdateRolePermissions(ctx context.Context, roleID uint, permissionIDs []uint) error

UpdateRolePermissions 重置角色拥有的权限列表

func (*RBACService) UpdateUserRoles

func (s *RBACService) UpdateUserRoles(ctx context.Context, userID uint, roleIDs []uint) error

UpdateUserRoles 更新用户角色列表

type ReviewService

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

func NewReviewService

func NewReviewService(db *gorm.DB, pointsService *PointsService) *ReviewService

func (*ReviewService) ApproveReview

func (s *ReviewService) ApproveReview(ctx context.Context, reviewID uint, adminNote string) error

ApproveReview 审核通过评价

func (*ReviewService) CreateReview

func (s *ReviewService) CreateReview(ctx context.Context, userID uint, req *request.CreateReviewRequest) error

CreateReview 创建教师评价

func (*ReviewService) DeleteReview

func (s *ReviewService) DeleteReview(ctx context.Context, reviewID uint) error

DeleteReview 删除评价

func (*ReviewService) GetReviewByID

func (s *ReviewService) GetReviewByID(ctx context.Context, reviewID uint) (*models.TeacherReview, error)

GetReviewByID 根据ID获取评价

func (*ReviewService) GetReviews

func (s *ReviewService) GetReviews(ctx context.Context, page, size int, teacherName string, status models.TeacherReviewStatus) ([]models.TeacherReview, int64, error)

GetReviews 获取评价列表

func (*ReviewService) GetReviewsByTeacher

func (s *ReviewService) GetReviewsByTeacher(ctx context.Context, teacherName string, page, size int) ([]models.TeacherReview, int64, error)

GetReviewsByTeacher 获取指定教师的评价

func (*ReviewService) GetUserReviews

func (s *ReviewService) GetUserReviews(ctx context.Context, userID uint, page, size int) ([]models.TeacherReview, int64, error)

GetUserReviews 获取用户的评价记录

func (*ReviewService) RejectReview

func (s *ReviewService) RejectReview(ctx context.Context, reviewID uint, adminNote string) error

RejectReview 审核拒绝评价

type S3Service

type S3Service struct {
	S3 minio.Client
	// contains filtered or unexported fields
}

func (*S3Service) AddObject

func (s *S3Service) AddObject(ctx context.Context, data io.ReadCloser,
	fileName string, mimeType string, isAdmin bool, customPath *string, tags map[string]string) (string, error)

AddObject adds an object to S3 and returns the resource ID.

func (*S3Service) DeleteObject

func (s *S3Service) DeleteObject(ctx context.Context, resourceID string) error

DeleteObject deletes an object from S3 based on the resource ID.

func (*S3Service) GetObject

func (s *S3Service) GetObject(ctx context.Context, resourceID string) (io.ReadCloser, *models.S3Data, error)

GetObject retrieves an object from S3 based on the resource ID.

func (*S3Service) ListExpiredObjects

func (s *S3Service) ListExpiredObjects(ctx context.Context) ([]models.S3Resource, error)

ListExpiredObjects lists all expired objects in the S3Resource table.

func (*S3Service) ListObjects

func (s *S3Service) ListObjects(ctx context.Context) ([]models.S3Data, error)

ListObjects lists all objects in the S3Data table.

func (*S3Service) ShareObject

func (s *S3Service) ShareObject(ctx context.Context, openid, resourceID string, expires *time.Duration, download bool) (string, error)

ShareObject generates a presigned URL for an object.

type S3ServiceInterface

type S3ServiceInterface interface {
	AddObject(ctx context.Context, data io.ReadCloser,
		fileName string, mimeType string, isAdmin bool,
		customPath *string, tags map[string]string) (string, error)
	DeleteObject(ctx context.Context, resourceID string) error
	ShareObject(ctx context.Context, openid, resourceID string, expires *time.Duration, download bool) (string, error)
	ListObjects(ctx context.Context) ([]models.S3Data, error)
	ListExpiredObjects(ctx context.Context) ([]models.S3Resource, error)
	GetObject(ctx context.Context, resourceID string) (io.ReadCloser, *models.S3Data, error)
}

func NewS3Service

func NewS3Service(db *gorm.DB, cfg *config.Config) S3ServiceInterface

type StatService

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

func NewStatService

func NewStatService(db *gorm.DB) *StatService

func (*StatService) GetAllProjectsOnlineCount

func (s *StatService) GetAllProjectsOnlineCount(ctx context.Context) ([]response.AllProjectsOnlineStatItem, error)

GetAllProjectsOnlineCount 获取所有启用项目的在线人数

func (*StatService) GetCountdownCountsByUser

func (s *StatService) GetCountdownCountsByUser(ctx context.Context, page, pageSize int) ([]response.AdminUserCountStatResponse, int64, error)

func (*StatService) GetGPABackupCountsByUser

func (s *StatService) GetGPABackupCountsByUser(ctx context.Context, page, pageSize int) ([]response.AdminUserCountStatResponse, int64, error)

func (*StatService) GetProjectOnlineCount

func (s *StatService) GetProjectOnlineCount(ctx context.Context, projectID uint, userID ...uint) (int64, error)

GetProjectOnlineCount 获取项目在线人数 使用 Sorted Set,只统计最近1分钟内有活动的用户 不主动清理过期数据,只统计有效范围内的用户,过期数据不影响统计结果 如果传入了userID(>0),则在统计前先更新该用户的在线状态

func (*StatService) GetStudyTaskCountsByUser

func (s *StatService) GetStudyTaskCountsByUser(ctx context.Context, page, pageSize int) ([]response.AdminUserCountStatResponse, int64, error)

func (*StatService) GetSystemOnlineCount

func (s *StatService) GetSystemOnlineCount(ctx context.Context) (int64, error)

GetSystemOnlineCount 获取系统在线人数 使用 Sorted Set,只统计最近1分钟内有活动的用户 不主动清理过期数据,只统计有效范围内的用户,过期数据不影响统计结果

type StudyTaskService

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

func NewStudyTaskService

func NewStudyTaskService(db *gorm.DB) *StudyTaskService

func (*StudyTaskService) CreateStudyTask

CreateStudyTask 创建学习任务

func (*StudyTaskService) DeleteStudyTask

func (s *StudyTaskService) DeleteStudyTask(ctx context.Context, taskID uint, userID uint) error

DeleteStudyTask 删除学习任务

func (*StudyTaskService) GetCompletedTasks

func (s *StudyTaskService) GetCompletedTasks(ctx context.Context, userID uint, page, size int) (*response.PageResponse, error)

GetCompletedTasks 获取已完成的任务(历史记录)

func (*StudyTaskService) GetStudyTaskByID

func (s *StudyTaskService) GetStudyTaskByID(ctx context.Context, taskID uint, userID uint) (*response.StudyTaskResponse, error)

GetStudyTaskByID 根据ID获取学习任务详情

func (*StudyTaskService) GetStudyTaskStats

func (s *StudyTaskService) GetStudyTaskStats(ctx context.Context, userID uint) (*response.StudyTaskStatsResponse, error)

GetStudyTaskStats 获取用户学习任务统计

func (*StudyTaskService) GetStudyTasks

GetStudyTasks 获取用户学习任务列表

func (*StudyTaskService) UpdateStudyTask

func (s *StudyTaskService) UpdateStudyTask(ctx context.Context, taskID uint, userID uint, req *request.UpdateStudyTaskRequest) (*response.StudyTaskResponse, error)

UpdateStudyTask 更新学习任务

type UserActivityService

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

func NewUserActivityService

func NewUserActivityService(db *gorm.DB, rbacService *RBACService) *UserActivityService

func (*UserActivityService) GetUserLoginDays

func (s *UserActivityService) GetUserLoginDays(ctx context.Context, userID uint, pastDays int) (int64, error)

GetUserLoginDays 获取用户在过去指定天数内的登录天数

func (*UserActivityService) UpdateActiveUserRoles

func (s *UserActivityService) UpdateActiveUserRoles(ctx context.Context) error

UpdateActiveUserRoles 更新活跃用户角色 规则:100天内有25天访问次数,授予活跃角色;不满足条件则取消活跃角色

type UserPermissionSnapshot

type UserPermissionSnapshot struct {
	RoleTags       []string  `json:"role_tags"`
	PermissionTags []string  `json:"permission_tags"`
	IsAdmin        bool      `json:"is_admin"`
	CachedAt       time.Time `json:"cached_at"`
}

UserPermissionSnapshot 缓存中的用户权限快照

Jump to

Keyboard shortcuts

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