44 lines
1.4 KiB
Go
44 lines
1.4 KiB
Go
package dao
|
|
|
|
import (
|
|
"context"
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"ppgo_job/consts"
|
|
"ppgo_job/model/entity"
|
|
)
|
|
|
|
var ServerGroup = new(serverGroupDao)
|
|
|
|
type serverGroupDao struct{}
|
|
|
|
func (d *serverGroupDao) Insert(ctx context.Context, data *entity.ServerGroup) (id int64, err error) {
|
|
return InsertAndGetId(ctx, consts.TableServerGroup, data)
|
|
}
|
|
func (d *serverGroupDao) GetById(ctx context.Context, id int) (*entity.ServerGroup, error) {
|
|
var result *entity.ServerGroup
|
|
err := GetById(ctx, consts.TableServerGroup, id, &result)
|
|
return result, err
|
|
}
|
|
func (d *serverGroupDao) GetList(ctx context.Context, pageNum, pageSize int, filters ...interface{}) ([]*entity.ServerGroup, int, error) {
|
|
m := g.DB().Model(consts.TableServerGroup).Ctx(ctx)
|
|
m = buildFilters(m, filters)
|
|
order := extractOrder(filters)
|
|
total, err := m.Count()
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
offset, limit := ParsePage(pageNum, pageSize)
|
|
var result []*entity.ServerGroup
|
|
if order == "" {
|
|
order = entity.ServerGroupCols.Id + " desc"
|
|
}
|
|
err = m.Limit(limit).Offset(offset).Order(order).Scan(&result)
|
|
return result, total, err
|
|
}
|
|
func (d *serverGroupDao) Update(ctx context.Context, data *entity.ServerGroup) error {
|
|
return Update(ctx, consts.TableServerGroup, data, g.Map{entity.ServerGroupCols.Id: data.Id})
|
|
}
|
|
func (d *serverGroupDao) Delete(ctx context.Context, id int) error {
|
|
return Delete(ctx, consts.TableServerGroup, g.Map{entity.ServerGroupCols.Id: id})
|
|
}
|