-
Notifications
You must be signed in to change notification settings - Fork 66
/
sys-agent.go
66 lines (50 loc) · 1.64 KB
/
sys-agent.go
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
package repo
import (
"fmt"
v1 "github.com/aaronchen2k/deeptest/cmd/server/v1/domain"
"github.com/aaronchen2k/deeptest/internal/pkg/consts"
"github.com/aaronchen2k/deeptest/internal/server/modules/model"
"gorm.io/gorm"
)
type SysAgentRepo struct {
*BaseRepo `inject:""`
DB *gorm.DB `inject:""`
}
func (r *SysAgentRepo) List(tenantId consts.TenantId, keywords string) (pos []model.SysAgent, err error) {
db := r.GetDB(tenantId).Model(&model.SysAgent{}).
Where("NOT deleted")
if keywords != "" {
db.Where("name LIKE ?", fmt.Sprintf("%%%s%%", keywords))
}
err = db.Find(&pos).Error
return
}
func (r *SysAgentRepo) Get(tenantId consts.TenantId, id uint) (po model.SysAgent, err error) {
err = r.GetDB(tenantId).
Where("id = ?", id).
First(&po).Error
return
}
func (r *SysAgentRepo) Save(tenantId consts.TenantId, po *model.SysAgent) (err error) {
err = r.GetDB(tenantId).Model(po).
Save(&po).Error
return
}
func (r *SysAgentRepo) UpdateName(tenantId consts.TenantId, to v1.AgentReq) (err error) {
err = r.GetDB(tenantId).Model(&model.SysAgent{}).
Where("id = ?", to.Id).
Updates(map[string]interface{}{"name": to.Name, "update_user": to.UpdateUser}).Error
return
}
func (r *SysAgentRepo) Delete(tenantId consts.TenantId, id uint) (err error) {
err = r.GetDB(tenantId).Model(&model.SysAgent{}).
Where("id = ?", id).
Updates(map[string]interface{}{"deleted": true}).Error
return
}
func (r *SysAgentRepo) Disable(tenantId consts.TenantId, id uint) (err error) {
err = r.GetDB(tenantId).Model(&model.SysAgent{}).
Where("id = ?", id).
Updates(map[string]interface{}{"disabled": gorm.Expr("NOT disabled")}).Error
return
}