models

package
v0.0.0-...-8e399c3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB

Functions

func CloseDB

func CloseDB() error

func GetAllPermission

func GetAllPermission() *[]Permission

func GetPermissionByUser

func GetPermissionByUser(user *User) *[]Permission

func InitDatabase

func InitDatabase(password string)

func Setup

func Setup() (err error)

Types

type BaseModel

type BaseModel struct {
	Id uint `json:"id" gorm:"primaryKey;autoIncrement;comment:主键ID"`
}

type BaseModelNoUpdateTime

type BaseModelNoUpdateTime struct {
	CreatedAt time.Time      `json:"createdAt" gorm:"comment:创建时间"`
	DeletedAt gorm.DeletedAt `json:"-" gorm:"index;comment:删除时间"`
}

type BaseModelTime

type BaseModelTime struct {
	CreatedAt time.Time      `json:"createdAt" gorm:"comment:创建时间"`
	UpdatedAt time.Time      `json:"updatedAt" gorm:"comment:更新时间"`
	DeletedAt gorm.DeletedAt `json:"-" gorm:"index;comment:删除时间"`
}

type ControlBy

type ControlBy struct {
	CreateBy uint `json:"createBy" gorm:"index;comment:创建者"`
	UpdateBy uint `json:"updateBy" gorm:"index;comment:更新者"`
}

func (*ControlBy) SetCreateBy

func (e *ControlBy) SetCreateBy(createBy uint)

SetCreateBy 设置创建人id

func (*ControlBy) SetUpdateBy

func (e *ControlBy) SetUpdateBy(updateBy uint)

SetUpdateBy 设置修改人id

type Department

type Department struct {
	BaseModel
	Name     string `json:"name" gorm:"unique;not null;type:varchar(32);comment:部门名称"`
	ParentId uint   `json:"parentId" gorm:"comment:上级部门"`
	ControlBy
	BaseModelTime
}

func (Department) TableName

func (Department) TableName() string

type GormLogger

type GormLogger struct {
	gormLogger.Interface

	SlowThreshold             time.Duration
	IgnoreRecordNotFoundError bool
	// contains filtered or unexported fields
}

func NewGormLogger

func NewGormLogger(logger *zap.Logger, logLevel gormLogger.LogLevel, slowThreshold time.Duration, ignoreRecordNotFoundError bool) *GormLogger

func (*GormLogger) Error

func (gl *GormLogger) Error(ctx context.Context, msg string, values ...interface{})

func (*GormLogger) Info

func (gl *GormLogger) Info(ctx context.Context, msg string, values ...interface{})

func (*GormLogger) LogMode

func (gl *GormLogger) LogMode(level gormLogger.LogLevel) gormLogger.Interface

func (*GormLogger) Trace

func (gl *GormLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error)

func (*GormLogger) Warn

func (gl *GormLogger) Warn(ctx context.Context, msg string, values ...interface{})

type LoginLog

type LoginLog struct {
	BaseModel
	// IPV6最大长度 39 位
	Ip       string `json:"ip" gorm:"type:varchar(40);comment:IP地址"`
	Location string `json:"location" gorm:"type:varchar(64);comment:地点"`
	Client   string `json:"client" gorm:"type:varchar(255);comment:客户端"`
	Os       string `json:"os" gorm:"type:varchar(255);comment:操作系统"`
	Status   bool   `json:"status" gorm:"type:bool;comment:成功或者失败"`
	Kind     string `json:"kind" gorm:"type:varchar(32);comment:日志类型"`
	Detail   string `json:"detail" gorm:"type:varchar(255);comment:操作详情"`
	DeptId   uint   `json:"deptId" gorm:"comment:部门ID"`
	ControlBy
	BaseModelNoUpdateTime
}

func (LoginLog) TableName

func (LoginLog) TableName() string

type Permission

type Permission struct {
	BaseModel
	Name string `json:"name" gorm:"unique;not null;type:varchar(32);comment:'权限名称'"`
	// 前端验证用
	Sign     string `json:"sign" gorm:"unique;not null;type:varchar(32);comment:'权限标识'"`
	Menu     bool   `json:"menu" gorm:"not null;type:bool;comment:'是否为左侧菜单'"`
	Method   string `json:"method" gorm:"not null;type:varchar(8);comment:'HTTP请求方法'"`
	Path     string `json:"path" gorm:"not null;type:varchar(256);comment:'HTTP请求路径正则'"`
	ParentId uint   `json:"parentId" gorm:"comment:上级权限"`
	BaseModelTime
	Roles []Role `json:"roles" gorm:"many2many:role_permission"`
}

func (Permission) TableName

func (Permission) TableName() string

type Role

type Role struct {
	BaseModel
	Name   string `json:"name" gorm:"unique;not null;type:varchar(32);comment:角色名称"`
	DeptId uint   `json:"deptId" gorm:"comment:部门ID"`
	ControlBy
	BaseModelTime
	Permissions []Permission `json:"permissions" gorm:"many2many:role_permission"`
}

func (Role) TableName

func (Role) TableName() string

type Tree

type Tree struct {
	Id       uint    `json:"id"`
	Label    string  `json:"label"`
	Children []*Tree `json:"children"`
}

func GetPerm

func GetPerm(from uint, permissions *[]Permission) (perms []Tree)

type User

type User struct {
	BaseModel
	Username string `json:"username" gorm:"unique;not null;type:varchar(32);comment:用户名"`
	Name     string `json:"name" gorm:"type:varchar(32);comment:姓名"`
	Avatar   string `json:"avatar" gorm:"type:varchar(255);comment:头像"`
	// sha256 加密,固定64位
	Password string `json:"-" gorm:"not null;type:char(64);comment:密码"`
	IsSuper  bool   `json:"isSuper" gorm:"not null;type:bool;comment:是否为超级管理员"`
	Status   bool   `json:"status" gorm:"not null;type:bool;comment:是否启用"`
	Mobile   string `json:"mobile" gorm:"type:char(11);comment:'手机'"`
	Email    string `json:"email" gorm:"type:varchar(255);comment:'邮箱'"`
	// 未使用 gorm 自带的一对多实现
	// 采用了在一对多的两个实体间,在“多”的实体表(即用户)中新增一个字段,该字段是“一”实体表(即部门)的主键。
	DeptId  uint   `json:"deptId" gorm:"comment:部门ID"`
	RoleId  uint   `json:"roleId" gorm:"comment:角色ID"`
	DeptIds []uint `json:"-" gorm:"-"`
	RoleIds []uint `json:"-" gorm:"-"`
	// 权限标识
	Permissions []string `json:"permissions" gorm:"-"`
	ControlBy
	BaseModelTime
}

func (*User) AfterFind

func (u *User) AfterFind(_ *gorm.DB) error

func (*User) GetPermissions

func (u *User) GetPermissions()

func (User) TableName

func (User) TableName() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL