部分API支持用户平台调用

This commit is contained in:
GoEdgeLab
2022-01-05 20:12:37 +08:00
parent 94d01de693
commit f1190623f1
4 changed files with 83 additions and 20 deletions

View File

@@ -77,10 +77,11 @@ func (this *ServerGroupDAO) FindServerGroupName(tx *dbs.Tx, id int64) (string, e
}
// CreateGroup 创建分组
func (this *ServerGroupDAO) CreateGroup(tx *dbs.Tx, name string) (groupId int64, err error) {
func (this *ServerGroupDAO) CreateGroup(tx *dbs.Tx, name string, userId int64) (groupId int64, err error) {
op := NewServerGroupOperator()
op.State = ServerGroupStateEnabled
op.Name = name
op.UserId = userId
op.IsOn = true
err = this.Save(tx, op)
if err != nil {
@@ -102,9 +103,15 @@ func (this *ServerGroupDAO) UpdateGroup(tx *dbs.Tx, groupId int64, name string)
}
// FindAllEnabledGroups 查找所有分组
func (this *ServerGroupDAO) FindAllEnabledGroups(tx *dbs.Tx) (result []*ServerGroup, err error) {
_, err = this.Query(tx).
State(ServerGroupStateEnabled).
func (this *ServerGroupDAO) FindAllEnabledGroups(tx *dbs.Tx, userId int64) (result []*ServerGroup, err error) {
var query = this.Query(tx).
State(ServerGroupStateEnabled)
if userId > 0 {
query.Attr("userId", userId)
} else {
query.Attr("userId", 0)
}
_, err = query.
Desc("order").
AscPk().
Slice(&result).
@@ -113,9 +120,13 @@ func (this *ServerGroupDAO) FindAllEnabledGroups(tx *dbs.Tx) (result []*ServerGr
}
// UpdateGroupOrders 修改分组排序
func (this *ServerGroupDAO) UpdateGroupOrders(tx *dbs.Tx, groupIds []int64) error {
func (this *ServerGroupDAO) UpdateGroupOrders(tx *dbs.Tx, groupIds []int64, userId int64) error {
for index, groupId := range groupIds {
_, err := this.Query(tx).
var query = this.Query(tx)
if userId > 0 {
query.Attr("userId", userId)
}
_, err := query.
Pk(groupId).
Set("order", len(groupIds)-index).
Update()
@@ -383,6 +394,22 @@ func (this *ServerGroupDAO) FindEnabledGroupIdWithReverseProxyId(tx *dbs.Tx, rev
FindInt64Col(0)
}
// CheckUserGroup 检查用户分组
func (this *ServerGroupDAO) CheckUserGroup(tx *dbs.Tx, userId int64, groupId int64) error {
b, err := this.Query(tx).
Pk(groupId).
Attr("userId", userId).
State(ServerGroupStateEnabled).
Exist()
if err != nil {
return err
}
if !b {
return ErrNotFound
}
return nil
}
// NotifyUpdate 通知更新
func (this *ServerGroupDAO) NotifyUpdate(tx *dbs.Tx, groupId int64) error {
serverIds, err := SharedServerDAO.FindAllEnabledServerIdsWithGroupId(tx, groupId)