This commit introduces several architectural improvements and optimizations across the codebase: - **Performance & Reliability**: - Implemented Redis pipelining in `ConversationCache.CacheMessage` to reduce network round-trips. - Added a circuit breaker to the JPush client to prevent cascading failures. - Introduced batch deletion and batch member addition capabilities in repositories. - Added message idempotency support using `client_msg_id` and a Redis-based cache. - Optimized WebSocket handling with connection limits (total and per-user) and improved error logging. - **Code Refactoring**: - Refactored `Router` to use a `RouterDeps` struct, simplifying the constructor and improving maintainability. - Unified model ID generation logic using new `id_helper.go` (supporting UUID and Snowflake). - Standardized JSON serialization/deserialization in models using `json_helper.go`. - Refactored DTO conversion logic, specifically for `UserResponse` (using functional options) and `Report` responses. - Removed redundant/deprecated DTOs like `PostDetailResponse` and `TradeItemDetailResponse`. - **Cache Improvements**: - Enhanced `LayeredCache` with `SetRaw` to avoid double-encoding when promoting values from Redis to local cache. - Added `DeleteBatch` support to the cache interface. - **Other Changes**: - Cleaned up `config.go` by removing redundant default values and explicit environment variable overrides. - Improved WebSocket registration flow to handle connection limits gracefully.
77 lines
2.8 KiB
Go
77 lines
2.8 KiB
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
"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 {
|
|
SetUUIDIfEmpty(&r.ID)
|
|
return nil
|
|
}
|
|
|
|
// TableName 指定表名
|
|
func (Report) TableName() string {
|
|
return "reports"
|
|
}
|
|
|
|
// ReportStats 举报统计(用于缓存或查询结果)
|
|
type ReportStats struct {
|
|
TargetType ReportTargetType
|
|
TargetID string
|
|
ReportCount int
|
|
IsHidden bool
|
|
} |