pg_admin_user_dao.go
1.7 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package dao
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
)
type AdminUserDao struct {
transactionContext *transaction.TransactionContext
}
func NewAdminUserDao(transactionContext *transaction.TransactionContext) (*AdminUserDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &AdminUserDao{
transactionContext: transactionContext,
}, nil
}
}
//UpdatePassword ....
func (dao *AdminUserDao) UpdatePassword(id int64, pwd string) error {
tx := dao.transactionContext.PgDd
m := &models.AdminUser{}
err := tx.Model(m).Where("id=?", id).First()
if err != nil {
return err
}
_, err = tx.Model(m).Where("id=?", id).
Set("password=?", pwd).
Update()
return err
}
//UpdatePassword ....
func (dao *AdminUserDao) UpdateIsUsable(id int64, isUsable bool) error {
tx := dao.transactionContext.PgDd
m := &models.AdminUser{}
err := tx.Model(m).Where("id=?", id).First()
if err != nil {
return err
}
_, err = tx.Model(m).Where("id=?", id).
Set("is_usable=?", isUsable).
Update()
return err
}
//AdminUserAccountExist ...
func (dao *AdminUserDao) AdminUserAccountExist(account string) (bool, error) {
tx := dao.transactionContext.PgDd
m := &models.AdminUser{}
ok, err := tx.Model(m).
Where("account=?", account).
Exists()
return ok, err
}
func (dao *AdminUserDao) AdminUserIsDefault(id int64) (bool, error) {
tx := dao.transactionContext.PgDd
m := &models.AdminUser{}
err := tx.Model(m).
Where("id=?", id).
Column("is_default").
First()
return m.IsDefault, err
}