package models
|
|
type Operations struct {
|
Method string `gorm:"column:method;not null;default:''" json:"method"` //请求方法,POST,GET...
|
Path string `gorm:"column:path;not null;default:''" json:"path"` //请求路径,如/data/api-u/sys/login
|
Name string `gorm:"column:name;not null;default:''" json:"name"` //接口名称,如/data/api-u/sys/login
|
Exclude bool `gorm:"column:exclude;not null;default:0;" json:"exclude"` //是否排除
|
Module string `gorm:"column:module;not null;default:0;" json:"module"` //所属模块
|
ApiEnable bool `gorm:"column:api_enable;not null;default:0;" json:"api_enable"` //是否开启API
|
}
|
|
type AllOperations struct {
|
Operations []Operations
|
}
|
|
func (Operations) TableName() string {
|
return "t_operations"
|
}
|
|
func (a *Operations) FindAll(module string) (rows []Operations, err error) {
|
LogSelectDB := GetLogSetsDb()
|
if module != "" {
|
LogSelectDB = LogSelectDB.Where("module = ?", module)
|
}
|
if err := LogSelectDB.Table(a.TableName()).Find(&rows).Error; err != nil {
|
return nil, err
|
}
|
|
return rows, nil
|
}
|
|
func (a *Operations) Insert() bool {
|
var count int64 = 0
|
logSetsDb = GetLogSetsDb()
|
result := logSetsDb.Table(a.TableName()).Where("path=?", a.Path).Count(&count)
|
if count > 0 {
|
logSetsDb.Table(a.TableName()).Where("path=?", a.Path).Update("name", a.Name).Update("exclude", a.Exclude).Update("api_enable", a.ApiEnable)
|
}
|
result = logSetsDb.Table(a.TableName()).Create(&a)
|
if result.Error != nil {
|
return false
|
}
|
return result.RowsAffected > 0
|
}
|