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
36
37
38
39
40
41
42
43
44
45
46
47
package models
 
//设备管理授权方式,此配置在集群内是共享的
type AuthConfig struct {
    AuthType         int         `gorm:"column:authType;default:0;" json:"authType"`  //0:始终允许,1:密钥校验
    Password         string         `gorm:"column:password" json:"password"`  //密码是6位数字
}
 
const (
    AuthType_Free = 0 //始终允许
    AuthType_Key = 1  //密钥校验
)
 
func (AuthConfig) TableName() string {
    return "auth_config"
}
 
func (ac *AuthConfig) Insert() bool {
    result := db.Table(ac.TableName()).Create(&ac)
    if result.Error !=nil {
        return false
    }
    return result.RowsAffected>0
}
 
func (ac *AuthConfig) Update() bool {
    result := db.Exec("update "+ac.TableName()+" set authType=?,password=?", ac.AuthType, ac.Password)
    if result.Error !=nil {
        return false
    }
    return result.RowsAffected>0
}
 
func (ac *AuthConfig) Select() (int64, error){
    result := db.Table(ac.TableName()).First(&ac)
    if result.Error != nil || result.RowsAffected == 0 {
        return 0, err
    }
    return result.RowsAffected, nil
}
 
func (ac *AuthConfig) FindAll() (list []SysMenu){
    if err:=db.Table(ac.TableName()).Scan(&list).Error;err !=nil{
        return nil
    }
    return list
}