Set up project files and add .gitignore to exclude local build/runtime artifacts. Made-with: Cursor
119 lines
5.1 KiB
Go
119 lines
5.1 KiB
Go
package model
|
||
|
||
import (
|
||
"time"
|
||
|
||
"github.com/google/uuid"
|
||
"gorm.io/gorm"
|
||
)
|
||
|
||
// AuditTargetType 审核对象类型
|
||
type AuditTargetType string
|
||
|
||
const (
|
||
AuditTargetTypePost AuditTargetType = "post" // 帖子
|
||
AuditTargetTypeComment AuditTargetType = "comment" // 评论
|
||
AuditTargetTypeMessage AuditTargetType = "message" // 私信
|
||
AuditTargetTypeUser AuditTargetType = "user" // 用户资料
|
||
AuditTargetTypeImage AuditTargetType = "image" // 图片
|
||
)
|
||
|
||
// AuditResult 审核结果
|
||
type AuditResult string
|
||
|
||
const (
|
||
AuditResultPass AuditResult = "pass" // 通过
|
||
AuditResultReview AuditResult = "review" // 需人工复审
|
||
AuditResultBlock AuditResult = "block" // 违规拦截
|
||
AuditResultUnknown AuditResult = "unknown" // 未知
|
||
)
|
||
|
||
// AuditRiskLevel 风险等级
|
||
type AuditRiskLevel string
|
||
|
||
const (
|
||
AuditRiskLevelLow AuditRiskLevel = "low" // 低风险
|
||
AuditRiskLevelMedium AuditRiskLevel = "medium" // 中风险
|
||
AuditRiskLevelHigh AuditRiskLevel = "high" // 高风险
|
||
)
|
||
|
||
// AuditSource 审核来源
|
||
type AuditSource string
|
||
|
||
const (
|
||
AuditSourceAuto AuditSource = "auto" // 自动审核
|
||
AuditSourceManual AuditSource = "manual" // 人工审核
|
||
AuditSourceCallback AuditSource = "callback" // 回调审核
|
||
)
|
||
|
||
// AuditLog 审核日志实体
|
||
type AuditLog struct {
|
||
ID string `json:"id" gorm:"type:varchar(36);primaryKey"`
|
||
TargetType AuditTargetType `json:"target_type" gorm:"type:varchar(50);index"`
|
||
TargetID string `json:"target_id" gorm:"type:varchar(255);index"`
|
||
Content string `json:"content" gorm:"type:text"` // 待审核内容
|
||
ContentType string `json:"content_type" gorm:"type:varchar(50)"` // 内容类型: text, image
|
||
ContentURL string `json:"content_url" gorm:"type:text"` // 图片/文件URL
|
||
AuditType string `json:"audit_type" gorm:"type:varchar(50)"` // 审核类型: porn, violence, ad, political, fraud, gamble
|
||
Result AuditResult `json:"result" gorm:"type:varchar(50);index"`
|
||
RiskLevel AuditRiskLevel `json:"risk_level" gorm:"type:varchar(20)"`
|
||
Labels string `json:"labels" gorm:"type:text"` // JSON数组,标签列表
|
||
Suggestion string `json:"suggestion" gorm:"type:varchar(50)"` // pass, review, block
|
||
Detail string `json:"detail" gorm:"type:text"` // 详细说明
|
||
ThirdPartyID string `json:"third_party_id" gorm:"type:varchar(255)"` // 第三方审核服务返回的ID
|
||
Source AuditSource `json:"source" gorm:"type:varchar(20);default:auto"`
|
||
ReviewerID string `json:"reviewer_id" gorm:"type:varchar(255)"` // 审核人ID(人工审核时使用)
|
||
ReviewerName string `json:"reviewer_name" gorm:"type:varchar(100)"` // 审核人名称
|
||
ReviewTime *time.Time `json:"review_time" gorm:"index"` // 审核时间
|
||
UserID string `json:"user_id" gorm:"type:varchar(255);index"` // 内容发布者ID
|
||
UserIP string `json:"user_ip" gorm:"type:varchar(45)"` // 用户IP
|
||
Status string `json:"status" gorm:"type:varchar(20);default:pending"` // pending, completed, failed
|
||
RejectReason string `json:"reject_reason" gorm:"type:text"` // 拒绝原因(人工审核时使用)
|
||
ExtraData string `json:"extra_data" gorm:"type:text"` // 额外数据,JSON格式
|
||
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
|
||
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
|
||
DeletedAt gorm.DeletedAt `json:"-" gorm:"index"`
|
||
}
|
||
|
||
// BeforeCreate 创建前生成UUID
|
||
func (al *AuditLog) BeforeCreate(tx *gorm.DB) error {
|
||
if al.ID == "" {
|
||
al.ID = uuid.New().String()
|
||
}
|
||
return nil
|
||
}
|
||
|
||
func (AuditLog) TableName() string {
|
||
return "audit_logs"
|
||
}
|
||
|
||
// AuditLogRequest 创建审核日志请求
|
||
type AuditLogRequest struct {
|
||
TargetType AuditTargetType `json:"target_type" validate:"required"`
|
||
TargetID string `json:"target_id" validate:"required"`
|
||
Content string `json:"content"`
|
||
ContentType string `json:"content_type"`
|
||
ContentURL string `json:"content_url"`
|
||
AuditType string `json:"audit_type"`
|
||
UserID string `json:"user_id"`
|
||
UserIP string `json:"user_ip"`
|
||
}
|
||
|
||
// AuditLogListItem 审核日志列表项
|
||
type AuditLogListItem struct {
|
||
ID string `json:"id"`
|
||
TargetType AuditTargetType `json:"target_type"`
|
||
TargetID string `json:"target_id"`
|
||
Content string `json:"content"`
|
||
ContentType string `json:"content_type"`
|
||
Result AuditResult `json:"result"`
|
||
RiskLevel AuditRiskLevel `json:"risk_level"`
|
||
Suggestion string `json:"suggestion"`
|
||
Source AuditSource `json:"source"`
|
||
ReviewerID string `json:"reviewer_id"`
|
||
ReviewTime *time.Time `json:"review_time"`
|
||
UserID string `json:"user_id"`
|
||
Status string `json:"status"`
|
||
CreatedAt time.Time `json:"created_at"`
|
||
}
|