feat: 添加日志管理和敏感词过滤功能

- 新增日志管理模块:操作日志、登录日志、数据变更日志
- 新增敏感词过滤器 (sanitizer)
- 新增日志异步写入管理器
- 新增日志定时清理服务
- 优化帖子相关服务和上传服务
This commit is contained in:
2026-03-15 02:25:10 +08:00
parent d3065b30cc
commit ebd9cb8b04
31 changed files with 2753 additions and 60 deletions

View File

@@ -59,6 +59,9 @@ type PostService interface {
// 其他
IncrementViews(ctx context.Context, postID, userID string) error
// 日志服务设置
SetLogService(logService *LogService)
}
// postServiceImpl 帖子服务实现
@@ -68,7 +71,8 @@ type postServiceImpl struct {
cache cache.Cache
gorseClient gorse.Client
postAIService *PostAIService
txManager repository.TransactionManager // 事务管理器
txManager repository.TransactionManager
logService *LogService
}
// NewPostService 创建帖子服务
@@ -80,9 +84,15 @@ func NewPostService(postRepo *repository.PostRepository, systemMessageService Sy
gorseClient: gorseClient,
postAIService: postAIService,
txManager: txManager,
logService: nil,
}
}
// SetLogService 设置日志服务
func (s *postServiceImpl) SetLogService(logService *LogService) {
s.logService = logService
}
// PostListResult 帖子列表缓存结果
type PostListResult struct {
Posts []*model.Post
@@ -103,6 +113,18 @@ func (s *postServiceImpl) Create(ctx context.Context, userID, title, content str
return nil, err
}
// 记录操作日志
if s.logService != nil {
s.logService.OperationLog.RecordOperation(&model.OperationLog{
UserID: userID,
Operation: string(model.OpPostCreate),
Module: "post",
TargetType: "post",
TargetID: post.ID,
Status: "success",
})
}
// 失效帖子列表缓存
cache.InvalidatePostList(s.cache)