212 lines
7.2 KiB
Go
212 lines
7.2 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" json:"id"`
|
|
SerialNumber string `gorm:"uniqueIndex;size:255" json:"serialNumber"`
|
|
CompanyName string `gorm:"index;size:255" json:"companyName"`
|
|
ValidUntil *time.Time `json:"validUntil"`
|
|
IsActive bool `gorm:"default:true" json:"isActive"`
|
|
CreatedBy *uint `json:"createdBy"`
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
UpdatedAt time.Time `json:"updatedAt"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
|
User *User `gorm:"foreignKey:CreatedBy" json:"user,omitempty"`
|
|
Company *Company `gorm:"foreignKey:CompanyName;references:CompanyName" json:"company,omitempty"`
|
|
}
|
|
|
|
// 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"`
|
|
}
|
|
|
|
// CompanyStatsOverviewDTO 企业统计概览
|
|
type CompanyStatsOverviewDTO struct {
|
|
TotalCompanies int64 `json:"totalCompanies"`
|
|
ActiveCompanies int64 `json:"activeCompanies"`
|
|
InactiveCompanies int64 `json:"inactiveCompanies"`
|
|
TotalSerials int64 `json:"totalSerials"`
|
|
ActiveSerials int64 `json:"activeSerials"`
|
|
RevokedSerials int64 `json:"revokedSerials"`
|
|
TotalEmployeeSerials int64 `json:"totalEmployeeSerials"`
|
|
ActiveEmployeeSerials int64 `json:"activeEmployeeSerials"`
|
|
RevokedEmployeeSerials int64 `json:"revokedEmployeeSerials"`
|
|
}
|
|
|
|
// EmployeeSerial 员工序列号模型
|
|
type EmployeeSerial struct {
|
|
ID uint `gorm:"primaryKey" json:"id"`
|
|
SerialNumber string `gorm:"uniqueIndex;size:255" json:"serialNumber"`
|
|
CompanyName string `gorm:"index;size:255" json:"companyName"`
|
|
Department string `gorm:"size:255" json:"department"`
|
|
EmployeeName string `gorm:"size:255" json:"employeeName"`
|
|
IsActive bool `gorm:"default:true" json:"isActive"`
|
|
CreatedBy *uint `json:"createdBy"`
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
UpdatedAt time.Time `json:"updatedAt"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
|
User *User `gorm:"foreignKey:CreatedBy" json:"user,omitempty"`
|
|
Company *Company `gorm:"foreignKey:CompanyName;references:CompanyName" json:"company,omitempty"`
|
|
}
|
|
|
|
// GenerateEmployeeSerialDTO 生成员工序列号请求数据
|
|
type GenerateEmployeeSerialDTO struct {
|
|
CompanyName string `json:"companyName" validate:"required"`
|
|
Department string `json:"department" validate:"required"`
|
|
EmployeeName string `json:"employeeName" validate:"required"`
|
|
Quantity int `json:"quantity" validate:"min=1,max=1000"`
|
|
SerialPrefix string `json:"serialPrefix,omitempty"`
|
|
}
|
|
|
|
// UpdateEmployeeSerialDTO 员工序列号更新请求数据
|
|
type UpdateEmployeeSerialDTO struct {
|
|
CompanyName string `json:"companyName,omitempty" validate:"omitempty"`
|
|
Department string `json:"department,omitempty" validate:"omitempty"`
|
|
EmployeeName string `json:"employeeName,omitempty" validate:"omitempty"`
|
|
IsActive *bool `json:"isActive,omitempty"`
|
|
}
|