zhangzengfei
2023-09-04 e8e536d1cb52d2126c8c7ce2ba1c7a76f7208678
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
36
37
38
39
40
41
42
43
44
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
}