feat: 添加举报功能支持
Some checks failed
Build Backend / build (push) Failing after 5m19s
Build Backend / build-docker (push) Has been skipped

- 新增 Report 数据模型、DTO、Repository、Service 层
- 实现用户端举报 API (POST /api/v1/reports)
- 实现管理端举报管理 API (列表、详情、处理、批量处理)
- 添加举报自动隐藏机制(达到阈值自动隐藏内容)
- 集成系统通知(举报处理结果通知)
- 更新路由和 Wire 依赖注入配置

Made-with: Cursor
This commit is contained in:
lafay
2026-03-29 20:18:36 +08:00
parent 2205b8ad04
commit 5f7b02ee8e
16 changed files with 1426 additions and 0 deletions

View File

@@ -134,6 +134,9 @@ func autoMigrate(db *gorm.DB) error {
&SensitiveWord{},
&AuditLog{},
// 举报
&Report{},
// 日志相关
&OperationLog{}, // 操作日志
&LoginLog{}, // 登录日志

80
internal/model/report.go Normal file
View File

@@ -0,0 +1,80 @@
package model
import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
// ReportTargetType 举报目标类型
type ReportTargetType string
const (
ReportTargetTypePost ReportTargetType = "post" // 帖子
ReportTargetTypeComment ReportTargetType = "comment" // 评论
ReportTargetTypeMessage ReportTargetType = "message" // 消息
)
// ReportStatus 举报处理状态
type ReportStatus string
const (
ReportStatusPending ReportStatus = "pending" // 待处理
ReportStatusProcessing ReportStatus = "processing" // 处理中
ReportStatusResolved ReportStatus = "resolved" // 已确认违规
ReportStatusRejected ReportStatus = "rejected" // 已驳回
)
// ReportReason 举报原因类型
type ReportReason string
const (
ReportReasonSpam ReportReason = "spam" // 垃圾广告
ReportReasonInappropriate ReportReason = "inappropriate" // 违规内容
ReportReasonHarassment ReportReason = "harassment" // 辱骂/攻击
ReportReasonMisinformation ReportReason = "misinformation" // 虚假信息
ReportReasonOther ReportReason = "other" // 其他
)
// Report 举报实体
type Report struct {
ID string `json:"id" gorm:"type:varchar(36);primaryKey"`
ReporterID string `json:"reporter_id" gorm:"type:varchar(36);index;index:idx_reports_reporter_status,priority:1;not null"`
TargetType ReportTargetType `json:"target_type" gorm:"type:varchar(20);index;index:idx_reports_target_type_id,priority:1;index:idx_reports_target_status,priority:1;not null"`
TargetID string `json:"target_id" gorm:"type:varchar(36);index:idx_reports_target_type_id,priority:2;index:idx_reports_target,priority:1;not null"`
Reason ReportReason `json:"reason" gorm:"type:varchar(30);not null"`
Description string `json:"description" gorm:"type:text"`
Status ReportStatus `json:"status" gorm:"type:varchar(20);default:pending;index:idx_reports_status_created,priority:1;index:idx_reports_reporter_status,priority:2;index:idx_reports_target_status,priority:2"`
HandledBy *string `json:"handled_by" gorm:"type:varchar(36);index"`
HandledAt *time.Time `json:"handled_at" gorm:"type:timestamp"`
Result *string `json:"result" gorm:"type:text"`
// 软删除
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
// 时间戳
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime;index:idx_reports_status_created,priority:2,sort:desc"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
}
// BeforeCreate 创建前生成UUID
func (r *Report) BeforeCreate(tx *gorm.DB) error {
if r.ID == "" {
r.ID = uuid.New().String()
}
return nil
}
// TableName 指定表名
func (Report) TableName() string {
return "reports"
}
// ReportStats 举报统计(用于缓存或查询结果)
type ReportStats struct {
TargetType ReportTargetType
TargetID string
ReportCount int
IsHidden bool
}

View File

@@ -32,6 +32,10 @@ const (
SysNotifyGroupJoinApply SystemNotificationType = "group_join_apply" // 加群申请待审批
SysNotifyGroupJoinApproved SystemNotificationType = "group_join_approved" // 加群申请通过
SysNotifyGroupJoinRejected SystemNotificationType = "group_join_rejected" // 加群申请拒绝
// 举报相关
SysNotifyReportResolved SystemNotificationType = "report_resolved" // 举报已确认违规
SysNotifyReportRejected SystemNotificationType = "report_rejected" // 举报已驳回
)
// SystemNotificationExtra 额外数据