45 lines
1.9 KiB
Go
45 lines
1.9 KiB
Go
package system
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"management/internal/erpserver/model/dto"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type UserRepository interface {
|
|
Initialize(ctx context.Context, departId, roleId int32) error
|
|
Create(ctx context.Context, obj *User) error
|
|
Update(ctx context.Context, obj *User) error
|
|
Get(ctx context.Context, id int32) (*User, error)
|
|
GetByEmail(ctx context.Context, email string) (*User, error)
|
|
All(ctx context.Context) ([]*User, error)
|
|
List(ctx context.Context, q dto.SearchDto) ([]*User, int64, error)
|
|
}
|
|
|
|
type User struct {
|
|
ID int32 `json:"id" gorm:"primaryKey;autoIncrement;not null"`
|
|
Uuid uuid.UUID `json:"uuid" gorm:"type:uuid;not null;uniqueIndex"`
|
|
Email string `json:"email" gorm:"type:varchar(100);not null;uniqueIndex"`
|
|
Username string `json:"username" gorm:"type:varchar(100);not null;uniqueIndex"`
|
|
HashedPassword []byte `json:"-" gorm:"type:bytea;not null;"`
|
|
Salt string `json:"-" gorm:"type:varchar(20);not null;"`
|
|
Avatar string `json:"avatar" gorm:"type:varchar(200);not null;"`
|
|
Gender int32 `json:"gender" gorm:"type:int;not null;default:0;"`
|
|
DepartmentID int32 `json:"department_id" gorm:"type:int;not null;default:0;"`
|
|
RoleID int32 `json:"role_id" gorm:"type:int;not null;default:0;"`
|
|
Status int32 `json:"status" gorm:"type:int;not null;default:0;"`
|
|
ChangePasswordAt time.Time `json:"-" gorm:"type:timestamptz;not null;default:'0001-01-01 00:00:00+8';"`
|
|
CreatedAt time.Time `json:"created_at" gorm:"type:timestamptz;not null;default:'now()'"`
|
|
UpdatedAt time.Time `json:"updated_at" gorm:"type:timestamptz;not null;default:'0001-01-01 00:00:00+8';"`
|
|
|
|
Role *Role `json:"role" gorm:"ForeignKey:RoleID"`
|
|
Department *Department `json:"department" gorm:"ForeignKey:DepartmentID"`
|
|
}
|
|
|
|
func (User) TableName() string {
|
|
return "sys_user"
|
|
}
|