cockpit-source/backend/internal/domain/models.go
2026-04-02 14:12:43 +08:00

108 lines
3.7 KiB
Go

package domain
import (
"time"
"github.com/shopspring/decimal"
)
type BaseModel struct {
ID uint64 `gorm:"primaryKey" json:"id"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
type User struct {
BaseModel
Username string `gorm:"size:64;uniqueIndex;not null" json:"username"`
PasswordHash string `gorm:"size:255;not null" json:"-"`
DisplayName string `gorm:"size:64" json:"displayName"`
Enabled bool `gorm:"not null;default:true" json:"enabled"`
LastLoginAt *time.Time `json:"lastLoginAt"`
}
type Role struct {
BaseModel
Name string `gorm:"size:64;uniqueIndex;not null" json:"name"`
Description string `gorm:"size:255" json:"description"`
}
type Permission struct {
BaseModel
Code string `gorm:"size:128;uniqueIndex;not null" json:"code"`
Name string `gorm:"size:128;not null" json:"name"`
Type string `gorm:"size:32" json:"type"`
}
type UserRole struct {
UserID uint64 `gorm:"primaryKey"`
RoleID uint64 `gorm:"primaryKey"`
}
type RolePermission struct {
RoleID uint64 `gorm:"primaryKey"`
PermissionID uint64 `gorm:"primaryKey"`
}
type RefreshToken struct {
BaseModel
UserID uint64 `gorm:"index;not null" json:"userId"`
TokenHash string `gorm:"size:255;uniqueIndex;not null" json:"-"`
DeviceID string `gorm:"size:128" json:"deviceId"`
UserAgent string `gorm:"size:255" json:"userAgent"`
IP string `gorm:"size:64" json:"ip"`
ExpiresAt time.Time `gorm:"index;not null" json:"expiresAt"`
RevokedAt *time.Time `gorm:"index" json:"revokedAt"`
}
type Customer struct {
BaseModel
Name string `gorm:"size:128;uniqueIndex;not null" json:"name"`
Code string `gorm:"size:64;uniqueIndex" json:"code"`
Remark string `gorm:"type:text" json:"remark"`
}
type Status struct {
BaseModel
Name string `gorm:"size:64;uniqueIndex;not null" json:"name"`
SortOrder int `gorm:"not null;default:0" json:"sortOrder"`
Color string `gorm:"size:32" json:"color"`
}
type Order struct {
BaseModel
OrderNo string `gorm:"size:64;uniqueIndex;not null" json:"orderNo"`
OrderDate time.Time `gorm:"type:date;index;not null" json:"orderDate"`
ShipDate *time.Time `gorm:"type:date;index" json:"shipDate"`
AmountA decimal.Decimal `gorm:"type:decimal(18,2);not null;default:0" json:"amountA"`
AmountB decimal.Decimal `gorm:"type:decimal(18,2);not null;default:0" json:"amountB"`
CustomerID uint64 `gorm:"index;not null" json:"customerId"`
StatusID uint64 `gorm:"index;not null" json:"statusId"`
Remark string `gorm:"type:text" json:"remark"`
Source string `gorm:"size:32;not null;default:'manual'" json:"source"`
CreatedBy uint64 `gorm:"index;not null" json:"createdBy"`
}
type ImportJob struct {
BaseModel
Type string `gorm:"size:32;not null" json:"type"` // orders
InputFmt string `gorm:"size:16;not null" json:"inputFormat"` // excel/json
Status string `gorm:"size:16;not null" json:"status"` // pending/running/success/failed/partial
FileName string `gorm:"size:255" json:"fileName"`
TotalRows int `gorm:"not null;default:0" json:"totalRows"`
OKRows int `gorm:"not null;default:0" json:"successRows"`
FailRows int `gorm:"not null;default:0" json:"failedRows"`
StartedAt *time.Time `json:"startedAt"`
FinishedAt *time.Time `json:"finishedAt"`
CreatedBy uint64 `gorm:"index;not null" json:"createdBy"`
}
type ImportJobError struct {
BaseModel
JobID uint64 `gorm:"index;not null" json:"jobId"`
RowNo int `gorm:"not null" json:"rowNo"`
Field string `gorm:"size:64;not null" json:"field"`
Message string `gorm:"type:text;not null" json:"message"`
RawData string `gorm:"type:json" json:"rawData"`
}