166 lines
4.7 KiB
Go
166 lines
4.7 KiB
Go
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" json:"id"`
|
|
CompanyName string `gorm:"uniqueIndex;size:255" json:"companyName"`
|
|
IsActive bool `gorm:"default:true" json:"isActive"`
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
UpdatedAt time.Time `json:"updatedAt"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
|
Serials []Serial `gorm:"foreignKey:CompanyName;references:CompanyName" json:"-"`
|
|
}
|
|
|
|
// 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"`
|
|
}
|
|
|
|
// LoginResponse 登录响应
|
|
type LoginResponse struct {
|
|
Message string `json:"message"`
|
|
AccessToken string `json:"accessToken"`
|
|
User UserDTO `json:"user"`
|
|
}
|
|
|
|
// BaseResponse 基础响应
|
|
type BaseResponse struct {
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
// ErrorResponse 错误响应
|
|
type ErrorResponse struct {
|
|
Message string `json:"message"`
|
|
Error string `json:"error,omitempty"`
|
|
}
|
|
|
|
// DataResponse 数据响应
|
|
type DataResponse struct {
|
|
Message string `json:"message"`
|
|
Data any `json:"data"`
|
|
}
|
|
|
|
// PaginationResponse 分页响应
|
|
type PaginationResponse struct {
|
|
Message string `json:"message"`
|
|
Data any `json:"data"`
|
|
Pagination Pagination `json:"pagination"`
|
|
}
|
|
|
|
// Pagination 分页信息
|
|
type Pagination struct {
|
|
Page int `json:"page"`
|
|
Limit int `json:"limit"`
|
|
Total int64 `json:"total"`
|
|
TotalPages int `json:"totalPages"`
|
|
}
|
|
|
|
// QRCodeResponse 二维码响应
|
|
type QRCodeResponse struct {
|
|
Message string `json:"message"`
|
|
QRCodeData string `json:"qrCodeData"`
|
|
QueryURL string `json:"queryUrl"`
|
|
}
|
|
|
|
// CompanyResponse 企业响应
|
|
type CompanyResponse struct {
|
|
Message string `json:"message"`
|
|
Company Company `json:"company"`
|
|
}
|
|
|
|
// CompanyDataRequest 企业数据请求
|
|
type CompanyDataRequest struct {
|
|
CompanyName string `json:"companyName" validate:"required"`
|
|
}
|
|
|
|
// CompanyUpdateRequest 企业更新请求
|
|
type CompanyUpdateRequest struct {
|
|
CompanyName string `json:"companyName"`
|
|
IsActive *bool `json:"isActive"`
|
|
}
|