35 lines
983 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package model
import (
"github.com/bwmarrin/snowflake"
"gorm.io/gorm"
"hospital-admin-api/config"
)
// AdminRole 后台-角色表
type AdminRole struct {
RoleId int64 `gorm:"column:role_id;type:bigint(19);primary_key;comment:主键id" json:"role_id"`
RoleName string `gorm:"column:role_name;type:varchar(100);comment:角色名称" json:"role_name"`
RoleStatus int `gorm:"column:role_status;type:tinyint(1);default:1;comment:角色状态1:正常 2:禁用)" json:"role_status"`
IsAdmin int `gorm:"column:is_admin;type:tinyint(1);default:0;comment:是否管理员0:否 1:是)" json:"is_admin"`
Model
}
func (m *AdminRole) TableName() string {
return "gdxz_admin_role"
}
func (m *AdminRole) BeforeCreate(tx *gorm.DB) error {
if m.RoleId == 0 {
// 创建雪花算法实例
sf, err := snowflake.NewNode(config.C.Snowflake)
if err != nil {
return err
}
// 生成新的雪花算法 ID
m.RoleId = sf.Generate().Int64()
}
return nil
}