Files
iqudo-top1/internal/model/models.go
2026-08-20 21:58:04 +08:00

230 lines
9.9 KiB
Go

package model
import (
"time"
"gorm.io/datatypes"
)
type Base struct {
ID uint64 `json:"id" gorm:"primaryKey;autoIncrement"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type Tenant struct {
Base
Name string `json:"name" gorm:"size:128;not null"`
Slug string `json:"slug" gorm:"size:64;not null;uniqueIndex"`
Status string `json:"status" gorm:"size:24;not null"`
}
type User struct {
Base
Username string `json:"username" gorm:"size:64;not null;uniqueIndex"`
PasswordHash string `json:"-" gorm:"size:255;not null"`
DisplayName string `json:"display_name" gorm:"size:128;not null"`
Status string `json:"status" gorm:"size:24;not null"`
}
type Role struct {
Base
TenantID uint64 `json:"tenant_id" gorm:"not null;index"`
Name string `json:"name" gorm:"size:64;not null"`
Code string `json:"code" gorm:"size:64;not null"`
Permissions datatypes.JSON `json:"permissions" gorm:"type:json;not null"`
}
type TenantMember struct {
Base
TenantID uint64 `json:"tenant_id" gorm:"not null;index"`
UserID uint64 `json:"user_id" gorm:"not null;index"`
RoleID uint64 `json:"role_id" gorm:"not null;index"`
Status string `json:"status" gorm:"size:24;not null"`
}
type Scenario struct {
Base
TenantID uint64 `json:"tenant_id" gorm:"not null;index"`
ScenarioKey string `json:"scenario_key" gorm:"size:128;not null;index"`
PublicKey string `json:"public_key" gorm:"size:128;not null;index"`
AllowedOrigins datatypes.JSON `json:"allowed_origins" gorm:"type:json;not null"`
Name string `json:"name" gorm:"size:128;not null"`
Industry string `json:"industry" gorm:"size:64;not null"`
RoleName string `json:"role_name" gorm:"size:64;not null"`
Goal string `json:"goal" gorm:"type:text;not null"`
TriggerText string `json:"trigger_text" gorm:"type:text;not null"`
Visibility string `json:"visibility" gorm:"size:24;not null"`
Status string `json:"status" gorm:"size:24;not null"`
CreatedBy uint64 `json:"created_by" gorm:"not null"`
InputSchema datatypes.JSON `json:"input_schema" gorm:"type:json;not null"`
OutputSchema datatypes.JSON `json:"output_schema" gorm:"type:json;not null"`
ResultSchema datatypes.JSON `json:"result_schema" gorm:"type:json;not null"`
}
type ScenarioField struct {
Base
TenantID uint64 `json:"tenant_id" gorm:"not null;index"`
ScenarioID uint64 `json:"scenario_id" gorm:"not null;index"`
FieldKey string `json:"field_key" gorm:"size:64;not null"`
FieldName string `json:"field_name" gorm:"size:128;not null"`
SourcePath string `json:"source_path" gorm:"size:255;not null"`
FieldType string `json:"field_type" gorm:"size:32;not null"`
Required bool `json:"required" gorm:"not null"`
Options datatypes.JSON `json:"options" gorm:"type:json;not null"`
Validation datatypes.JSON `json:"validation" gorm:"type:json;not null"`
SortOrder int `json:"sort_order" gorm:"not null"`
}
type ScenarioRule struct {
Base
TenantID uint64 `json:"tenant_id" gorm:"not null;index"`
ScenarioID uint64 `json:"scenario_id" gorm:"not null;index"`
RuleKey string `json:"rule_key" gorm:"size:64;not null"`
Name string `json:"name" gorm:"size:128;not null"`
Condition datatypes.JSON `json:"condition" gorm:"type:json;not null"`
Actions datatypes.JSON `json:"actions" gorm:"type:json;not null"`
Priority int `json:"priority" gorm:"not null"`
Status string `json:"status" gorm:"size:24;not null"`
}
type SOP struct {
Base
TenantID uint64 `json:"tenant_id" gorm:"not null;index"`
ScenarioID uint64 `json:"scenario_id" gorm:"not null;index"`
Name string `json:"name" gorm:"size:128;not null"`
Description string `json:"description" gorm:"type:text;not null"`
Status string `json:"status" gorm:"size:24;not null"`
CreatedBy uint64 `json:"created_by" gorm:"not null"`
StartNodeKey string `json:"start_node_key" gorm:"size:64;not null"`
}
type SOPNode struct {
Base
TenantID uint64 `json:"tenant_id" gorm:"not null;index"`
SOPID uint64 `json:"sop_id" gorm:"not null;index"`
NodeKey string `json:"node_key" gorm:"size:64;not null"`
Type string `json:"type" gorm:"size:32;not null"`
Title string `json:"title" gorm:"size:128;not null"`
Content string `json:"content" gorm:"type:text;not null"`
Config datatypes.JSON `json:"config" gorm:"type:json;not null"`
PositionX int `json:"position_x" gorm:"not null"`
PositionY int `json:"position_y" gorm:"not null"`
}
type SOPEdge struct {
Base
TenantID uint64 `json:"tenant_id" gorm:"not null;index"`
SOPID uint64 `json:"sop_id" gorm:"not null;index"`
SourceNodeKey string `json:"source_node_key" gorm:"size:64;not null"`
TargetNodeKey string `json:"target_node_key" gorm:"size:64;not null"`
Condition datatypes.JSON `json:"condition" gorm:"type:json;not null"`
Priority int `json:"priority" gorm:"not null"`
}
type KnowledgeItem struct {
Base
TenantID uint64 `json:"tenant_id" gorm:"not null;index"`
ScenarioID uint64 `json:"scenario_id" gorm:"not null;index"`
ItemKey string `json:"key" gorm:"size:64;not null"`
Name string `json:"name" gorm:"size:128;not null"`
Type string `json:"type" gorm:"size:64;not null"`
Content datatypes.JSON `json:"content" gorm:"type:json;not null"`
Status string `json:"status" gorm:"size:24;not null"`
SortOrder int `json:"sort_order" gorm:"not null"`
}
type KnowledgeRelation struct {
Base
TenantID uint64 `json:"tenant_id" gorm:"not null;index"`
ScenarioID uint64 `json:"scenario_id" gorm:"not null;index"`
FromKnowledgeID uint64 `json:"from_knowledge_id" gorm:"not null;index"`
RelationType string `json:"relation_type" gorm:"size:64;not null"`
ToKnowledgeID uint64 `json:"to_knowledge_id" gorm:"not null;index"`
Condition datatypes.JSON `json:"condition" gorm:"type:json;not null"`
SortOrder int `json:"sort_order" gorm:"not null"`
}
type SOPRun struct {
Base
TenantID uint64 `json:"tenant_id" gorm:"not null;index"`
SOPID uint64 `json:"sop_id" gorm:"not null;index"`
OperatorID uint64 `json:"operator_id" gorm:"not null;index"`
ExternalRef string `json:"external_ref" gorm:"size:191;not null;index"`
CurrentNodeKey string `json:"current_node_key" gorm:"size:64;not null"`
Status string `json:"status" gorm:"size:24;not null"`
Answers datatypes.JSON `json:"answers" gorm:"type:json;not null"`
Input datatypes.JSON `json:"input" gorm:"type:json;not null"`
Derived datatypes.JSON `json:"derived" gorm:"type:json;not null"`
Outputs datatypes.JSON `json:"outputs" gorm:"type:json;not null"`
KnowledgeSnapshot datatypes.JSON `json:"knowledge_snapshot" gorm:"type:json;not null"`
Result string `json:"result" gorm:"size:64;not null"`
FinalResult datatypes.JSON `json:"final_result" gorm:"type:json"`
StartedAt time.Time `json:"started_at"`
CompletedAt *time.Time `json:"completed_at"`
}
type SOPRunEvent struct {
Base
TenantID uint64 `json:"tenant_id" gorm:"not null;index"`
RunID uint64 `json:"run_id" gorm:"not null;index"`
NodeKey string `json:"node_key" gorm:"size:64;not null"`
Action string `json:"action" gorm:"size:64;not null"`
Payload datatypes.JSON `json:"payload" gorm:"type:json;not null"`
}
type PublicRunSession struct {
Base
TenantID uint64 `json:"tenant_id" gorm:"not null;index"`
RunID uint64 `json:"run_id" gorm:"not null;index"`
TokenHash string `json:"-" gorm:"size:64;not null;uniqueIndex"`
ExpiresAt time.Time `json:"expires_at" gorm:"not null"`
}
type SOPFeedback struct {
Base
TenantID uint64 `json:"tenant_id" gorm:"not null;index"`
RunID uint64 `json:"run_id" gorm:"not null;index"`
UserID uint64 `json:"user_id" gorm:"not null;index"`
Score int `json:"score" gorm:"not null"`
Comment string `json:"comment" gorm:"type:text;not null"`
}
func (SOPFeedback) TableName() string { return "sop_feedback" }
type AuditLog struct {
Base
TenantID uint64 `json:"tenant_id" gorm:"not null;index"`
UserID uint64 `json:"user_id" gorm:"not null;index"`
Action string `json:"action" gorm:"size:64;not null"`
Resource string `json:"resource" gorm:"size:64;not null"`
ResourceID uint64 `json:"resource_id" gorm:"not null"`
Payload datatypes.JSON `json:"payload" gorm:"type:json;not null"`
}
type MultiTableOutbox struct {
Base
TenantID uint64 `gorm:"not null;index"`
AuditLogID *uint64 `gorm:"uniqueIndex"`
Resource string `gorm:"size:64;not null;index"`
ResourceID uint64 `gorm:"not null;index"`
Action string `gorm:"size:64;not null"`
Payload datatypes.JSON `gorm:"type:json;not null"`
DedupeKey string `gorm:"size:191;not null;uniqueIndex"`
Status string `gorm:"size:24;not null;index"`
Attempts int `gorm:"not null"`
AvailableAt time.Time `gorm:"not null;index"`
LastError string `gorm:"type:text;not null"`
}
func (MultiTableOutbox) TableName() string { return "multitable_outbox" }
type RefreshToken struct {
Base
TenantID uint64 `json:"tenant_id" gorm:"not null;index"`
UserID uint64 `json:"user_id" gorm:"not null;index"`
TokenHash string `json:"-" gorm:"size:64;not null;uniqueIndex"`
ExpiresAt time.Time `json:"expires_at" gorm:"not null"`
RevokedAt *time.Time `json:"revoked_at"`
}