model

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TimeZone   = "Asia/Shanghai"
	TimeFormat = "2006-01-02 15:04:05"
)

Variables

This section is empty.

Functions

func Find

func Find(tx *gorm.DB) (data []map[string]interface{}, err error)

func LoadEnforce

func LoadEnforce() *casbin.SyncedEnforcer

func RewriteWelcome

func RewriteWelcome(title, scPath string)

Types

type AuthDetail

type AuthDetail struct {
	Id         int            `json:"id"`
	Module     string         `json:"module"`
	RecordName string         `json:"record_name"`
	List       map[string]int `json:"list"`
}

type ExaFile

type ExaFile struct {
	Model
	FileName   string
	FileMd5    string
	FilePath   string
	ChunkTotal int
	IsFinish   bool
}

file struct, 文件结构体

type JWT

type JWT struct {
	Data jwtUserInfo
	// contains filtered or unexported fields
}

func NewJWT

func NewJWT(signingKey []byte) *JWT

func (*JWT) Create

func (j *JWT) Create(user SysUser, config config.JWT) (string, error)

func (*JWT) Parse

func (j *JWT) Parse(token string) (jud *jwtUserInfo, err error)

type LocalTime

type LocalTime time.Time

func (LocalTime) Day

func (t LocalTime) Day() int

func (LocalTime) Format

func (t LocalTime) Format(layout ...string) string

func (*LocalTime) GobDecode

func (lt *LocalTime) GobDecode(data []byte) error

func (LocalTime) GobEncode

func (lt LocalTime) GobEncode() ([]byte, error)

func (LocalTime) MarshalJSON

func (t LocalTime) MarshalJSON() ([]byte, error)

func (LocalTime) Month

func (t LocalTime) Month() time.Month

func (LocalTime) Now

func (t LocalTime) Now() *LocalTime

func (*LocalTime) Scan

func (t *LocalTime) Scan(v interface{}) error

func (*LocalTime) UnmarshalJSON

func (t *LocalTime) UnmarshalJSON(data []byte) (err error)

func (LocalTime) Value

func (t LocalTime) Value() (driver.Value, error)

func (LocalTime) Year

func (t LocalTime) Year() int

type M

type M interface {
	GetId() int
	TableName() string
}

type Meta

type Meta struct {
	Title       string                 `json:"title" gorm:"size:50;comment:菜单名"`
	KeepAlive   bool                   `json:"keep_alive" gorm:"comment:是否缓存"`
	DefaultMenu bool                   `json:"default_menu" gorm:"comment:是否是基础路由"`
	Icon        string                 `json:"icon" gorm:"size:255;comment:菜单图标"`
	AutoClose   bool                   `json:"auto_close" gorm:"comment:自动关闭tab"`
	SCPath      string                 `json:"sc_path" gorm:"size:255;comment:服务端模版地址"`
	ActionList  map[string]interface{} `json:"action_list" gorm:"serializer:json;comment:动作列表"` // 列举了当前模块下所有按钮是否展示,对应前端应该从当前路由的 meta 数据中读取当前用户权限下的列表,并在页面的按钮上使用 v-if="$router.currenRouter.actionList['edit'] != false"
	ApiList     []SysApi               `json:"api_list" gorm:"-"`                               // Api 列表
}

type Model

type Model struct {
	ID int `json:"id" gorm:"type:int(11);primaryKey;comment:主键" uri:"id"`

	Cb int `json:"cb,omitempty" gorm:"type:int(11);comment:创建者"`
	Ub int `json:"ub,omitempty" gorm:"type:int(11);comment:更新者"`
	Db int `json:"-" gorm:"type:int(11);comment:删除者"`

	Ct *LocalTime     `json:"ct,omitempty" gorm:"type:datetime;default:CURRENT_TIMESTAMP;autoCreateTime;comment:创建时间"`
	Ut *LocalTime     `json:"ut,omitempty" gorm:"type:datetime;default:NULL ON UPDATE CURRENT_TIMESTAMP;autoUpdateTime;comment:更新时间"`
	Dt gorm.DeletedAt `json:"-" gorm:"type:datetime;index;comment:删除时间"`

	CbName string `json:"cb_name,omitempty" gorm:"-:all"` // 创建者
	UbName string `json:"ub_name,omitempty" gorm:"-:all"` // 更新者
	DbName string `json:"db_name,omitempty" gorm:"-:all"` // 删除者
}

func (Model) GetId

func (m Model) GetId() int

func (Model) SQLQuery

func (Model) SQLQuery(driver, sql string) (data []map[string]interface{}, err error)

指定 driver 直接执行 sql 并将结果作为 map 返回

type ModelWithoutID

type ModelWithoutID struct {
	ID int `json:"-" gorm:"type:int(11);primaryKey;comment:主键" uri:"id"`

	Cb int `json:"cb,omitempty" gorm:"type:int(11);comment:创建者"`
	Ub int `json:"ub,omitempty" gorm:"type:int(11);comment:更新者"`
	Db int `json:"-" gorm:"type:int(11);comment:删除者"`

	Ct *LocalTime     `json:"ct,omitempty" gorm:"type:datetime;default:CURRENT_TIMESTAMP;autoCreateTime;comment:创建时间"`
	Ut *LocalTime     `json:"ut,omitempty" gorm:"type:datetime;default:NULL ON UPDATE CURRENT_TIMESTAMP;autoUpdateTime;comment:更新时间"`
	Dt gorm.DeletedAt `json:"-" gorm:"type:datetime;index;comment:删除时间"`

	CbName string `json:"cb_name,omitempty" gorm:"-:all"` // 创建者
	UbName string `json:"ub_name,omitempty" gorm:"-:all"` // 更新者
	DbName string `json:"db_name,omitempty" gorm:"-:all"` // 删除者
}

func (ModelWithoutID) GetId

func (m ModelWithoutID) GetId() int

func (ModelWithoutID) SQLQuery

func (ModelWithoutID) SQLQuery(driver, sql string) (data []map[string]interface{}, err error)

指定 driver 直接执行 sql 并将结果作为 map 返回

type SysApi

type SysApi struct {
	Model
	MenuId      int    `json:"menu_id" gorm:"type:int(11);comment:菜单Id"`
	MenuName    string `json:"menu_name" gorm:"-"`
	Name        string `json:"name" gorm:"size:50;comment:api名称"`
	Description string `json:"description" gorm:"size:255;comment:api简介"`
	Path        string `json:"path" gorm:"size:255;comment:api路径"`
	Method      string `json:"method" gorm:"default:POST;comment:方法:创建POST(默认)|查看GET|更新PUT|删除DELETE"`

	Premiss int `json:"premiss,omitempty" gorm:"-"` // 权限列表展示使用
}

func (SysApi) All

func (s SysApi) All(loadSystem bool) []SysApi

func (SysApi) SysApi

func (s SysApi) SysApi() []SysApi

func (SysApi) TableName

func (SysApi) TableName() string

type SysAuth

type SysAuth struct {
	Model
	TableId     int    `json:"table_id" gorm:"type:int(11);comment:表ID"`
	TableModule string `json:"table_module" gorm:"size:100;comment:表模块"`
	Type        string `json:"type" gorm:"size:100;comment:类型: menu,api,action"`
	Key         string `json:"key" gorm:"size:50;comment:数据标记: menu: id, api: id, action: mapKey"`
	SetValue    int    `json:"set_value" gorm:"type:int(11);comment:设置值"`
}

func (SysAuth) LoadApiDetailByUserId

func (s SysAuth) LoadApiDetailByUserId(id int) (list [][]string, err error)

func (SysAuth) LoadDetail

func (s SysAuth) LoadDetail(id int, module string) (curSet, resultSet AuthDetail, otherSetList []AuthDetail, err error)

func (SysAuth) LoadMenuIdListByUserId

func (s SysAuth) LoadMenuIdListByUserId(id int) (list []int, err error)

func (SysAuth) SplitStr

func (SysAuth) SplitStr() string

func (SysAuth) TableName

func (SysAuth) TableName() string

type SysCasbinRole

type SysCasbinRole struct{}

func (SysCasbinRole) ClearCasbin

func (s SysCasbinRole) ClearCasbin(v int, p ...string) bool

func (SysCasbinRole) UpdateCasbin

func (s SysCasbinRole) UpdateCasbin(authorityId int) error

type SysDepartment

type SysDepartment struct {
	Model
	Pid         int             `json:"pid" gorm:"type:int(11);comment:父级Id"`
	Name        string          `json:"name" gorm:"size:50;comment:角色名称"`
	Description string          `json:"description" gorm:"size:255;comment:角色简介"`
	Children    []SysDepartment `json:"children" gorm:"-"`
	UserList    []*SysUser      `json:"user_list,omitempty" gorm:"many2many:sys_user_department"`
}

func (SysDepartment) All

func (s SysDepartment) All() ([]SysDepartment, error)

func (SysDepartment) TableName

func (SysDepartment) TableName() string

type SysFile

type SysFile struct {
	Model
	GroupId   int          `json:"group_id" gorm:"comment:路径id"` // 路径id
	GroupInfo SysFileGroup `json:"group_info" gorm:"foreignKey:GroupId;references:ID"`
	Name      string       `json:"name" gorm:"comment:文件名"`    // 文件名
	Url       string       `json:"url" gorm:"comment:文件地址"`    // 文件地址
	Tag       string       `json:"tag" gorm:"comment:文件标签"`    // 文件标签
	Key       string       `json:"key" gorm:"comment:编号"`      // 编号
	UUID      string       `json:"uuid" gorm:"comment:回调uuid"` // 回调uuid
	Size      int64        `json:"size" gorm:"comment:文件大小"`   // 文件大小
}

func (SysFile) DeleteFile

func (s SysFile) DeleteFile(file SysFile) (err error)

func (SysFile) EditFileName

func (s SysFile) EditFileName(file SysFile) (err error)

func (SysFile) FindFile

func (s SysFile) FindFile(id int) (SysFile, error)

func (SysFile) FindOrCreateFile

func (s SysFile) FindOrCreateFile(fileMd5 string, fileName string, chunkTotal int) (file ExaFile, err error)

func (SysFile) TableName

func (SysFile) TableName() string

func (SysFile) Upload

func (s SysFile) Upload(file *SysFile) error

type SysFileGroup

type SysFileGroup struct {
	Model
	ParentId int            `json:"parent_id" gorm:"comment:父级id"` // 父级id
	Name     string         `json:"name" gorm:"comment:路径"`        // 路径
	Desc     string         `json:"desc" gorm:"comment:描述"`        // 描述
	Files    []SysFile      `json:"files" gorm:"foreignKey:GroupId;references:ID"`
	Children []SysFileGroup `json:"children,omitempty" gorm:"-"`
}

func (SysFileGroup) TableName

func (SysFileGroup) TableName() string

func (SysFileGroup) Tree

func (s SysFileGroup) Tree(userId int) ([]SysFileGroup, error)

type SysMenu

type SysMenu struct {
	Model
	Pid       int       `json:"pid" gorm:"type:int(11);comment:父级Id"`
	Name      string    `json:"name" gorm:"unique;size:50;comment:菜单名称"`
	Path      string    `json:"path" gorm:"size:50;comment:路由地址"`
	Hidden    bool      `json:"hidden" gorm:"comment:是否隐藏"`
	Component string    `json:"component" gorm:"size:255;comment:模版地址"`
	Sort      int       `json:"sort" gorm:"type:int(11);comment:排序"`
	Children  []SysMenu `json:"children" gorm:"-"`
	Meta      `json:"meta" gorm:"embedded;comment:附加属性"`

	Premiss int `json:"premiss,omitempty" gorm:"-"` // 权限列表展示使用
}

func (SysMenu) All

func (s SysMenu) All(loadSystem bool) []SysMenu

func (*SysMenu) BeforeSave

func (s *SysMenu) BeforeSave(tx *gorm.DB) error

func (SysMenu) SystemMenu

func (s SysMenu) SystemMenu() []SysMenu

func (SysMenu) TableName

func (s SysMenu) TableName() string

func (SysMenu) TranMap

func (s SysMenu) TranMap() map[int]string

func (SysMenu) Tree

func (s SysMenu) Tree(loadSystem, withApi, buildTree, loadHidden, sort bool, userid ...int) ([]SysMenu, error)

type SysRole

type SysRole struct {
	Model
	Name        string     `json:"name" gorm:"size:50;comment:角色名称"`
	Description string     `json:"description" gorm:"size:255;comment:角色简介"`
	UserList    []*SysUser `json:"user_list,omitempty" gorm:"many2many:sys_user_role"`
}

func (SysRole) TableName

func (SysRole) TableName() string

type SysUser

type SysUser struct {
	Model
	UUID           uuid.UUID        `json:"uuid" gorm:"index;size:60;comment:用户UUID"`
	Username       string           `json:"username" gorm:"index;size:30;uniqueIndex:idx_username;comment:用户登录名"`
	Phone          string           `json:"phone"  gorm:"size:30;comment:用户手机号"`
	Email          string           `json:"email"  gorm:"size:60;comment:用户邮箱"`
	Salt           string           `json:"-" gorm:"size:16;comment:密码混淆"`
	Password       string           `json:"-" gorm:"size:255;comment:用户登录密码"`
	NickName       string           `json:"nick_name" gorm:"size:30;default:系统用户;comment:用户昵称"`
	Avatar         string           `json:"avatar" gorm:"size:255;comment:用户头像"`
	Enable         bool             `json:"enable" gorm:"default:true;comment:用户是否有效"`
	UserConfig     UserConfig       `json:"user_config" gorm:"serializer:json;comment:用户配置文件"`
	ExtendConfig   string           `json:"extend_config" gorm:"comment:扩展配置,保存自定义使用的配置"`
	LastLoginAt    *LocalTime       `json:"last_login_at" gorm:"type:datetime;comment:最后登录时间"`
	DepartmentList []*SysDepartment `json:"department_list" gorm:"many2many:sys_user_department;"` // 用户部门
	DepartmentIds  []int            `json:"department_ids" gorm:"-"`                               // 用户部门 Id 集合
	RoleList       []*SysRole       `json:"role_list" gorm:"many2many:sys_user_role;"`             // 用户角色
	RoleIds        []int            `json:"role_ids" gorm:"-"`                                     // 用户角色 Id 集合
	JwtToken       string           `json:"jwt_token,omitempty" gorm:"-"`
}

func (*SysUser) Create

func (s *SysUser) Create() error

func (SysUser) Detail

func (s SysUser) Detail(id int) (user SysUser, err error)

func (SysUser) Login

func (s SysUser) Login(username, password string) (user SysUser, err error)

func (SysUser) PasswordConfound

func (s SysUser) PasswordConfound(p string) string

func (SysUser) TableName

func (s SysUser) TableName() string

func (*SysUser) UnmarshalJSON

func (u *SysUser) UnmarshalJSON(data []byte) error

func (SysUser) Update

func (s SysUser) Update(data SysUser) error

type SysUserDepartment

type SysUserDepartment struct {
	SysUserId       int `json:"user_id" gorm:"type:int(11)"`
	SysDepartmentId int `json:"department_id" gorm:"type:int(11)"`
}

func (SysUserDepartment) TableName

func (SysUserDepartment) TableName() string

type SysUserRole

type SysUserRole struct {
	SysUserId int `json:"user_id" gorm:"type:int(11)"`
	SysRoleId int `json:"role_id" gorm:"type:int(11)"`
}

func (SysUserRole) TableName

func (SysUserRole) TableName() string

type UserConfig

type UserConfig struct {
	SideMode    string `json:"side_mode"`
	BaseColor   string `json:"base_color"`
	ActiveColor string `json:"active_color"`
	HomePage    string `json:"home_page"`
	Theme       string `json:"theme"`
}

Jump to

Keyboard shortcuts

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