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.
75 lines
2.6 KiB
Go
75 lines
2.6 KiB
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// SensitiveWordLevel 敏感词级别
|
|
type SensitiveWordLevel int
|
|
|
|
const (
|
|
SensitiveWordLevelLow SensitiveWordLevel = 1 // 低危
|
|
SensitiveWordLevelMedium SensitiveWordLevel = 2 // 中危
|
|
SensitiveWordLevelHigh SensitiveWordLevel = 3 // 高危
|
|
)
|
|
|
|
// SensitiveWordCategory 敏感词分类
|
|
type SensitiveWordCategory string
|
|
|
|
const (
|
|
SensitiveWordCategoryPolitical SensitiveWordCategory = "political" // 政治
|
|
SensitiveWordCategoryPorn SensitiveWordCategory = "porn" // 色情
|
|
SensitiveWordCategoryViolence SensitiveWordCategory = "violence" // 暴力
|
|
SensitiveWordCategoryAd SensitiveWordCategory = "ad" // 广告
|
|
SensitiveWordCategoryGamble SensitiveWordCategory = "gamble" // 赌博
|
|
SensitiveWordCategoryFraud SensitiveWordCategory = "fraud" // 诈骗
|
|
SensitiveWordCategoryOther SensitiveWordCategory = "other" // 其他
|
|
)
|
|
|
|
// SensitiveWord 敏感词实体
|
|
type SensitiveWord struct {
|
|
ID string `gorm:"type:varchar(36);primaryKey"`
|
|
Word string `gorm:"type:varchar(255);uniqueIndex;not null"`
|
|
Category SensitiveWordCategory `gorm:"type:varchar(50);index"`
|
|
Level SensitiveWordLevel `gorm:"type:int;default:1"`
|
|
IsActive bool `gorm:"default:true"`
|
|
CreatedBy string `gorm:"type:varchar(255)"`
|
|
UpdatedBy string `gorm:"type:varchar(255)"`
|
|
Remark string `gorm:"type:text"`
|
|
CreatedAt time.Time `gorm:"autoCreateTime"`
|
|
UpdatedAt time.Time `gorm:"autoUpdateTime"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index"`
|
|
}
|
|
|
|
// BeforeCreate 创建前生成UUID
|
|
func (sw *SensitiveWord) BeforeCreate(tx *gorm.DB) error {
|
|
SetUUIDIfEmpty(&sw.ID)
|
|
return nil
|
|
}
|
|
|
|
func (SensitiveWord) TableName() string {
|
|
return "sensitive_words"
|
|
}
|
|
|
|
// SensitiveWordRequest 创建/更新敏感词请求
|
|
type SensitiveWordRequest struct {
|
|
Word string `json:"word" validate:"required,min=1,max=255"`
|
|
Category SensitiveWordCategory `json:"category"`
|
|
Level SensitiveWordLevel `json:"level"`
|
|
Remark string `json:"remark"`
|
|
CreatedBy string `json:"-"`
|
|
}
|
|
|
|
// SensitiveWordListItem 敏感词列表项(用于列表展示)
|
|
type SensitiveWordListItem struct {
|
|
ID string `json:"id"`
|
|
Word string `json:"word"`
|
|
Category SensitiveWordCategory `json:"category"`
|
|
Level SensitiveWordLevel `json:"level"`
|
|
IsActive bool `json:"is_active"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
Remark string `json:"remark"`
|
|
}
|