Initial commit
This commit is contained in:
102
models/models.go
Normal file
102
models/models.go
Normal file
@@ -0,0 +1,102 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// User 模型
|
||||
type User struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
Username string `gorm:"uniqueIndex;size:255"`
|
||||
Password string `gorm:"size:255"`
|
||||
Name string `gorm:"size:255"`
|
||||
Email string `gorm:"size:255"`
|
||||
Role string `gorm:"size:50;default:'user'"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
DeletedAt gorm.DeletedAt `gorm:"index"`
|
||||
Serials []Serial `gorm:"foreignKey:CreatedBy"`
|
||||
}
|
||||
|
||||
// Company 模型
|
||||
type Company struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
CompanyName string `gorm:"uniqueIndex;size:255"`
|
||||
IsActive bool `gorm:"default:true"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
DeletedAt gorm.DeletedAt `gorm:"index"`
|
||||
Serials []Serial `gorm:"foreignKey:CompanyName;references:CompanyName"`
|
||||
}
|
||||
|
||||
// Serial 模型
|
||||
type Serial struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
SerialNumber string `gorm:"uniqueIndex;size:255"`
|
||||
CompanyName string `gorm:"index;size:255"`
|
||||
ValidUntil *time.Time
|
||||
IsActive bool `gorm:"default:true"`
|
||||
CreatedBy *uint
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
DeletedAt gorm.DeletedAt `gorm:"index"`
|
||||
User *User `gorm:"foreignKey:CreatedBy"`
|
||||
Company *Company `gorm:"foreignKey:CompanyName;references:CompanyName"`
|
||||
}
|
||||
|
||||
// UserDTO 数据传输对象
|
||||
type UserDTO struct {
|
||||
ID uint `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
Role string `json:"role"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
}
|
||||
|
||||
// LoginDTO 登录请求数据
|
||||
type LoginDTO struct {
|
||||
Username string `json:"username" validate:"required"`
|
||||
Password string `json:"password" validate:"required,min=6"`
|
||||
}
|
||||
|
||||
// ChangePasswordDTO 密码修改请求数据
|
||||
type ChangePasswordDTO struct {
|
||||
CurrentPassword string `json:"currentPassword" validate:"required"`
|
||||
NewPassword string `json:"newPassword" validate:"required,min=6"`
|
||||
}
|
||||
|
||||
// UpdateProfileDTO 个人信息更新请求数据
|
||||
type UpdateProfileDTO struct {
|
||||
Name string `json:"name" validate:"required"`
|
||||
Email string `json:"email" validate:"required,email"`
|
||||
}
|
||||
|
||||
// GenerateSerialDTO 生成序列号请求数据
|
||||
type GenerateSerialDTO struct {
|
||||
CompanyName string `json:"companyName" validate:"required"`
|
||||
Quantity int `json:"quantity" validate:"min=1,max=1000"`
|
||||
ValidDays int `json:"validDays" validate:"min=1,max=3650"`
|
||||
}
|
||||
|
||||
// GenerateWithPrefixDTO 带前缀生成序列号请求数据
|
||||
type GenerateWithPrefixDTO struct {
|
||||
CompanyName string `json:"companyName" validate:"required"`
|
||||
Quantity int `json:"quantity" validate:"min=1,max=1000"`
|
||||
ValidDays int `json:"validDays" validate:"min=1,max=3650"`
|
||||
SerialPrefix string `json:"serialPrefix" validate:"omitempty,alphanum"`
|
||||
}
|
||||
|
||||
// UpdateSerialDTO 序列号更新请求数据
|
||||
type UpdateSerialDTO struct {
|
||||
CompanyName string `json:"companyName,omitempty" validate:"omitempty"`
|
||||
ValidUntil *time.Time `json:"validUntil,omitempty"`
|
||||
IsActive *bool `json:"isActive,omitempty"`
|
||||
}
|
||||
|
||||
// QRCodeDTO 二维码生成请求数据
|
||||
type QRCodeDTO struct {
|
||||
BaseUrl string `json:"baseUrl,omitempty"`
|
||||
}
|
||||
Reference in New Issue
Block a user