zhangzengfei
2023-11-28 3a706d3378aa3626501370352963883fd2783558
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
}
 
func (Operations) TableName() string {
    return "t_operations"
}
 
func (a *Operations) FindAll(module string) (rows []Operations, err error) {
    if err := db.Where("module = ?", module).Table(a.TableName()).Find(&rows).Error; err != nil {
        return nil, err
    }
 
    return rows, nil
}
 
func (a *Operations) Insert() bool {
    count := 0
    result := db.Table(a.TableName()).Where("path=?", a.Path).Count(&count)
    if count > 0 {
        return true
    }
    result = db.Table(a.TableName()).Create(&a)
    if result.Error !=nil {
        return false
    }
    return result.RowsAffected>0
}