36 lines
1.1 KiB
Go
36 lines
1.1 KiB
Go
package model
|
||
|
||
import (
|
||
"github.com/bwmarrin/snowflake"
|
||
"gorm.io/gorm"
|
||
"hospital-admin-api/config"
|
||
)
|
||
|
||
// AdminAPI 后台-接口表
|
||
type AdminAPI struct {
|
||
Model
|
||
APIID int64 `gorm:"column:api_id;type:bigint(19);primary_key;AUTO_INCREMENT;comment:主键id" json:"api_id"`
|
||
APIName string `gorm:"column:api_name;type:varchar(100);comment:api名称;NOT NULL" json:"api_name"`
|
||
APIPath string `gorm:"column:api_path;type:varchar(255);comment:接口路径(全路径 id为:id);NOT NULL" json:"api_path"`
|
||
APIMethod string `gorm:"column:api_method;type:varchar(10);comment:请求类型(put:修改 post:新增 get:获取 );NOT NULL" json:"api_method"`
|
||
IsAuth int `gorm:"column:is_auth;type:tinyint(1);default:1;comment:是否验证权限(0:否 1:是)" json:"is_auth"`
|
||
}
|
||
|
||
func (m *AdminAPI) TableName() string {
|
||
return "gdxz_admin_api"
|
||
}
|
||
|
||
func (m *AdminAPI) BeforeCreate(tx *gorm.DB) error {
|
||
if m.APIID == 0 {
|
||
// 创建雪花算法实例
|
||
sf, err := snowflake.NewNode(config.C.Snowflake)
|
||
if err != nil {
|
||
return err
|
||
}
|
||
|
||
// 生成新的雪花算法 ID
|
||
m.APIID = sf.Generate().Int64()
|
||
}
|
||
return nil
|
||
}
|