package models import ( "time" "gorm.io/gorm" ) // Ticket 工单模型 type Ticket struct { ID uint `gorm:"primaryKey;autoIncrement" json:"id"` TicketNumber string `gorm:"unique;size:50;not null;comment:工单编号" json:"ticket_number"` TenantID uint `gorm:"not null;index;comment:租户 ID" json:"tenant_id"` UserID *uint `gorm:"index;comment:用户 ID" json:"user_id"` Title string `gorm:"size:500;not null;comment:工单标题" json:"title"` Description string `gorm:"type:text;not null;comment:工单描述" json:"description"` Category *string `gorm:"size:100;comment:工单分类" json:"category"` Priority string `gorm:"default:'medium';index;comment:优先级 (low/medium/high/urgent)" json:"priority"` Status string `gorm:"default:'open';index;comment:状态 (open/pending/in_progress/resolved/closed)" json:"status"` AssignedTo *uint `gorm:"index;comment:指配给" json:"assigned_to"` DueDate *time.Time `gorm:"comment:截止日期" json:"due_date"` Resolution *string `gorm:"type:text;comment:解决方案" json:"resolution"` Metadata *string `gorm:"type:text;comment:元数据 (JSON)" json:"metadata"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"` // 关联 User *User `gorm:"foreignKey:UserID" json:"user,omitempty"` Assignee *User `gorm:"foreignKey:AssignedTo" json:"assignee,omitempty"` Tenat *Tenant `gorm:"foreignKey:TenatID" json:"tenant,omitempty"` Messages []TicketMessage `json:"messages,omitempty"` Attachments []Attachment `json:"attachments,omitempty"` } // TableName 指定表名 func (Ticket) TableName() string { return "tickets" } // TicketMessage 工单消息 type TicketMessage struct { ID uint `gorm:"primaryKey;autoIncrement" json:"id"` TicketID uint `gorm:"not null;index;comment:工单 ID" json:"ticket_id"` UserID uint `gorm:"not null;comment:发送者 ID" json:"user_id"` Content string `gorm:"type:text;not null;comment:消息内容" json:"content"` ContentType string `gorm:"default:'text';comment:类型 (text/image/file)" json:"content_type"` ContentURL *string `gorm:"size:1000;comment:内容 URL" json:"content_url"` IsInternal bool `gorm:"default:false;comment:是否内部备注" json:"is_internal"` Metadata *string `gorm:"type:text;comment:元数据" json:"metadata"` CreatedAt time.Time `json:"created_at"` DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"` Ticket *Ticket `gorm:"foreignKey:TicketID" json:"ticket,omitempty"` } // TableName 指定表名 func (TicketMessage) TableName() string { return "ticket_messages" } // Attachment 附件 type Attachment struct { ID uint `gorm:"primaryKey;autoIncrement" json:"id"` TenantID uint `gorm:"not null;index;comment:租户 ID" json:"tenant_id"` TicketID uint `gorm:"not null;index;comment:工单 ID" json:"ticket_id"` FileName string `gorm:"size:500;not null;comment:文件名" json:"file_name"` FileURL string `gorm:"not null;comment:文件 URL" json:"file_url"` FileSize uint64 `gorm:"comment:文件大小 (字节)" json:"file_size"` MIMEType string `gorm:"size:100;comment:MIME 类型" json:"mime_type"` Description *string `gorm:"comment:描述" json:"description"` CreatedAt time.Time `json:"created_at"` DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"` Ticket *Ticket `gorm:"foreignKey:TicketID" json:"ticket,omitempty"` } // TableName 指定表名 func (Attachment) TableName() string { return "attachments" } // 工单状态枚举 const ( TicketStatusOpen = "open" TicketStatusPending = "pending" TicketStatusInProgress = "in_progress" TicketStatusResolved = "resolved" TicketStatusClosed = "closed" ) // 工单优先级枚举 const ( TicketPriorityLow = "low" TicketPriorityMedium = "medium" TicketPriorityHigh = "high" TicketPriorityUrgent = "urgent" ) // 工单分类枚举 const ( TicketCategoryTechnical = "technical" // 技术问题 TicketCategoryBug = "bug" // Bug 报告 TicketCategoryFeature = "feature" // 功能请求 TicketCategorySupport = "support" // 技术支持 TicketCategoryBilling = "billing" // 计费问题 TicketCategoryOther = "other" // 其他 )