Initial backend repository commit.
Set up project files and add .gitignore to exclude local build/runtime artifacts. Made-with: Cursor
This commit is contained in:
77
internal/model/sensitive_word.go
Normal file
77
internal/model/sensitive_word.go
Normal file
@@ -0,0 +1,77 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"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 {
|
||||
if sw.ID == "" {
|
||||
sw.ID = uuid.New().String()
|
||||
}
|
||||
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"`
|
||||
}
|
||||
Reference in New Issue
Block a user