diff --git a/internal/dto/report.go b/internal/dto/report.go index 4cc7262..3581c43 100644 --- a/internal/dto/report.go +++ b/internal/dto/report.go @@ -2,7 +2,6 @@ package dto import ( "carrot_bbs/internal/model" - "time" ) // ==================== 举报 DTOs ==================== diff --git a/internal/handler/admin_report_handler.go b/internal/handler/admin_report_handler.go index 210d846..4478d98 100644 --- a/internal/handler/admin_report_handler.go +++ b/internal/handler/admin_report_handler.go @@ -2,7 +2,7 @@ package handler import ( "carrot_bbs/internal/dto" - "carrot_bbs/internal/response" + "carrot_bbs/internal/pkg/response" "carrot_bbs/internal/service" "strconv" diff --git a/internal/handler/report_handler.go b/internal/handler/report_handler.go index e77593b..848062a 100644 --- a/internal/handler/report_handler.go +++ b/internal/handler/report_handler.go @@ -2,7 +2,7 @@ package handler import ( "carrot_bbs/internal/dto" - "carrot_bbs/internal/response" + "carrot_bbs/internal/pkg/response" "carrot_bbs/internal/service" "github.com/gin-gonic/gin" diff --git a/internal/service/admin_report_service.go b/internal/service/admin_report_service.go index c1a3906..52563df 100644 --- a/internal/service/admin_report_service.go +++ b/internal/service/admin_report_service.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "time" "carrot_bbs/internal/dto" "carrot_bbs/internal/model" @@ -32,9 +31,10 @@ type adminReportServiceImpl struct { commentRepo repository.CommentRepository messageRepo repository.MessageRepository userRepo repository.UserRepository - systemNotify SystemNotificationService + notifyRepo repository.SystemNotificationRepository + pushService PushService txManager repository.TransactionManager - logService *LogService + logService OperationLogService } // NewAdminReportService 创建管理端举报服务 @@ -44,9 +44,10 @@ func NewAdminReportService( commentRepo repository.CommentRepository, messageRepo repository.MessageRepository, userRepo repository.UserRepository, - systemNotify SystemNotificationService, + notifyRepo repository.SystemNotificationRepository, + pushService PushService, txManager repository.TransactionManager, - logService *LogService, + logService OperationLogService, ) AdminReportService { return &adminReportServiceImpl{ reportRepo: reportRepo, @@ -54,7 +55,8 @@ func NewAdminReportService( commentRepo: commentRepo, messageRepo: messageRepo, userRepo: userRepo, - systemNotify: systemNotify, + notifyRepo: notifyRepo, + pushService: pushService, txManager: txManager, logService: logService, } @@ -190,9 +192,12 @@ func (s *adminReportServiceImpl) HandleReport(ctx context.Context, id string, ac // 记录操作日志 if s.logService != nil { - s.logService.LogOperation(ctx, "handle_report", "report", id, handledBy, map[string]interface{}{ - "action": action, - "result": result, + s.logService.RecordOperation(&model.OperationLog{ + UserID: handledBy, + Operation: "handle_report", + TargetType: "report", + TargetID: id, + Module: "report", }) } @@ -274,10 +279,12 @@ func (s *adminReportServiceImpl) BatchHandle(ctx context.Context, ids []string, // 记录操作日志 if s.logService != nil { - s.logService.LogOperation(ctx, "batch_handle_reports", "report", "", handledBy, map[string]interface{}{ - "ids": ids, - "action": action, - "success_count": response.SuccessCount, + s.logService.RecordOperation(&model.OperationLog{ + UserID: handledBy, + Operation: "batch_handle_reports", + TargetType: "report", + TargetID: "", + Module: "report", }) } @@ -341,13 +348,15 @@ func (s *adminReportServiceImpl) getTargetContent(ctx context.Context, targetTyp if err != nil { return nil, err } - content.Content = msg.Content + // 从消息段中提取文本内容 + contentText := extractTextFromSegments(msg.Segments) + content.Content = contentText content.Status = string(msg.Status) content.CreatedAt = dto.FormatTime(msg.CreatedAt) // 获取发送者信息 if msg.SenderID != "" { if sender, err := s.userRepo.GetByID(msg.SenderID); err == nil { - content.Author = dto.ConvertUserToResponse(sender) + content.Author = convertUserToBrief(sender) } } } @@ -439,4 +448,30 @@ func containsID(ids []string, id string) bool { } } return false +} + +// extractTextFromSegments 从消息段中提取文本内容 +func extractTextFromSegments(segments model.MessageSegments) string { + var text string + for _, seg := range segments { + if seg.Type == "text" { + if content, ok := seg.Data["text"].(string); ok { + text += content + } + } + } + return text +} + +// convertUserToBrief 将用户模型转换为举报用的简要信息 +func convertUserToBrief(user *model.User) *dto.ReportUserBrief { + if user == nil { + return nil + } + return &dto.ReportUserBrief{ + ID: user.ID, + Username: user.Username, + Nickname: user.Nickname, + Avatar: user.Avatar, + } } \ No newline at end of file diff --git a/internal/service/report_service.go b/internal/service/report_service.go index 0fded44..15741c1 100644 --- a/internal/service/report_service.go +++ b/internal/service/report_service.go @@ -6,7 +6,6 @@ import ( "fmt" "carrot_bbs/internal/config" - "carrot_bbs/internal/dto" "carrot_bbs/internal/model" "carrot_bbs/internal/repository" @@ -28,9 +27,10 @@ type reportServiceImpl struct { commentRepo repository.CommentRepository messageRepo repository.MessageRepository userRepo repository.UserRepository - systemNotify SystemNotificationService + notifyRepo repository.SystemNotificationRepository + pushService PushService txManager repository.TransactionManager - logService *LogService + logService OperationLogService config *config.ReportConfig } @@ -41,9 +41,10 @@ func NewReportService( commentRepo repository.CommentRepository, messageRepo repository.MessageRepository, userRepo repository.UserRepository, - systemNotify SystemNotificationService, + notifyRepo repository.SystemNotificationRepository, + pushService PushService, txManager repository.TransactionManager, - logService *LogService, + logService OperationLogService, cfg *config.Config, ) ReportService { reportConfig := &cfg.Report @@ -56,7 +57,8 @@ func NewReportService( commentRepo: commentRepo, messageRepo: messageRepo, userRepo: userRepo, - systemNotify: systemNotify, + notifyRepo: notifyRepo, + pushService: pushService, txManager: txManager, logService: logService, config: reportConfig, @@ -147,10 +149,12 @@ func (s *reportServiceImpl) CreateReport(ctx context.Context, reporterID, target // 记录操作日志 if s.logService != nil { - s.logService.LogOperation(ctx, "create_report", "report", report.ID, reporterID, map[string]interface{}{ - "target_type": targetType, - "target_id": targetID, - "reason": reason, + s.logService.RecordOperation(&model.OperationLog{ + UserID: reporterID, + Operation: "create_report", + TargetType: "report", + TargetID: report.ID, + Module: "report", }) }