Refactor employee management
This commit is contained in:
+53
-37
@@ -8,16 +8,20 @@ import (
|
||||
|
||||
// User 模型
|
||||
type User struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
Username string `gorm:"uniqueIndex;size:255" json:"username"`
|
||||
Password string `gorm:"size:255" json:"-"`
|
||||
Name string `gorm:"size:255" json:"name"`
|
||||
Email string `gorm:"size:255" json:"email"`
|
||||
Role string `gorm:"size:50;default:'user'" json:"role"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
Serials []Serial `gorm:"foreignKey:CreatedBy" json:"-"`
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
Username string `gorm:"uniqueIndex;size:255" json:"username"`
|
||||
Password string `gorm:"size:255" json:"-"`
|
||||
Name string `gorm:"size:255" json:"name"`
|
||||
Email string `gorm:"size:255" json:"email"`
|
||||
Phone string `gorm:"size:50" json:"phone"`
|
||||
EmployeeNo string `gorm:"uniqueIndex;size:100" json:"employeeNo"`
|
||||
Position string `gorm:"size:255" json:"position"`
|
||||
Role string `gorm:"size:50;default:'employee'" json:"role"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
Serials []Serial `gorm:"foreignKey:CreatedBy" json:"-"`
|
||||
EmployeeSerials []EmployeeSerial `gorm:"foreignKey:EmployeeID" json:"employeeSerials,omitempty"`
|
||||
}
|
||||
|
||||
// Company 模型
|
||||
@@ -48,12 +52,16 @@ type Serial struct {
|
||||
|
||||
// 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"`
|
||||
ID uint `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
Phone string `json:"phone"`
|
||||
EmployeeNo string `json:"employeeNo"`
|
||||
Position string `json:"position"`
|
||||
Role string `json:"role"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
EmployeeSerials []EmployeeSerial `json:"employeeSerials,omitempty"`
|
||||
}
|
||||
|
||||
// LoginDTO 登录请求数据
|
||||
@@ -76,18 +84,24 @@ type UpdateProfileDTO struct {
|
||||
|
||||
// CreateUserDTO 管理员创建用户请求
|
||||
type CreateUserDTO struct {
|
||||
Username string `json:"username" validate:"required,min=3,max=50"`
|
||||
Password string `json:"password" validate:"required,min=6"`
|
||||
Name string `json:"name" validate:"required"`
|
||||
Email string `json:"email" validate:"omitempty,email"`
|
||||
Role string `json:"role" validate:"required,oneof=admin technician employee user"`
|
||||
Username string `json:"username,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
Name string `json:"name" validate:"required"`
|
||||
Email string `json:"email" validate:"omitempty,email"`
|
||||
Phone string `json:"phone" validate:"required"`
|
||||
EmployeeNo string `json:"employeeNo" validate:"required"`
|
||||
Position string `json:"position" validate:"required"`
|
||||
Role string `json:"role" validate:"required,oneof=admin technician employee"`
|
||||
}
|
||||
|
||||
// UpdateUserDTO 管理员更新用户信息请求
|
||||
type UpdateUserDTO struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Email string `json:"email,omitempty" validate:"omitempty,email"`
|
||||
Role string `json:"role,omitempty" validate:"omitempty,oneof=admin technician employee user"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Email string `json:"email,omitempty" validate:"omitempty,email"`
|
||||
Phone string `json:"phone,omitempty"`
|
||||
EmployeeNo string `json:"employeeNo,omitempty"`
|
||||
Position string `json:"position,omitempty"`
|
||||
Role string `json:"role,omitempty" validate:"omitempty,oneof=admin technician employee"`
|
||||
}
|
||||
|
||||
// AdminResetPasswordDTO 管理员重置用户密码
|
||||
@@ -187,19 +201,19 @@ type CompanyUpdateRequest struct {
|
||||
|
||||
// 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"`
|
||||
TotalAftersales int64 `json:"totalAftersales"`
|
||||
PendingConfirmation int64 `json:"pendingConfirmation"`
|
||||
ClosedAftersales int64 `json:"closedAftersales"`
|
||||
RejectedAftersales int64 `json:"rejectedAftersales"`
|
||||
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"`
|
||||
TotalAftersales int64 `json:"totalAftersales"`
|
||||
PendingConfirmation int64 `json:"pendingConfirmation"`
|
||||
ClosedAftersales int64 `json:"closedAftersales"`
|
||||
RejectedAftersales int64 `json:"rejectedAftersales"`
|
||||
}
|
||||
|
||||
// EmployeeSerial 员工序列号模型
|
||||
@@ -209,12 +223,14 @@ type EmployeeSerial struct {
|
||||
CompanyName string `gorm:"index;size:255" json:"companyName"`
|
||||
Position string `gorm:"size:255" json:"position"`
|
||||
EmployeeName string `gorm:"size:255" json:"employeeName"`
|
||||
EmployeeID *uint `gorm:"index" json:"employeeId,omitempty"`
|
||||
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"`
|
||||
Employee *User `gorm:"foreignKey:EmployeeID" json:"employee,omitempty"`
|
||||
Company *Company `gorm:"foreignKey:CompanyName;references:CompanyName" json:"company,omitempty"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user