Files
ppgo_job/dao/task_group.go
2026-07-10 11:28:16 +08:00

44 lines
1.3 KiB
Go

package dao
import (
"context"
"github.com/gogf/gf/v2/frame/g"
"ppgo_job/consts"
"ppgo_job/model/entity"
)
var Group = new(groupDao)
type groupDao struct{}
func (d *groupDao) Insert(ctx context.Context, data *entity.Group) (id int64, err error) {
return InsertAndGetId(ctx, consts.TableTaskGroup, data)
}
func (d *groupDao) GetById(ctx context.Context, id int) (*entity.Group, error) {
var result *entity.Group
err := GetById(ctx, consts.TableTaskGroup, id, &result)
return result, err
}
func (d *groupDao) GetList(ctx context.Context, pageNum, pageSize int, filters ...interface{}) ([]*entity.Group, int, error) {
m := g.DB().Model(consts.TableTaskGroup).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.Group
if order == "" {
order = entity.GroupCols.Id + " desc"
}
err = m.Limit(limit).Offset(offset).Order(order).Scan(&result)
return result, total, err
}
func (d *groupDao) Update(ctx context.Context, data *entity.Group) error {
return Update(ctx, consts.TableTaskGroup, data, g.Map{entity.GroupCols.Id: data.Id})
}
func (d *groupDao) Delete(ctx context.Context, id int) error {
return Delete(ctx, consts.TableTaskGroup, g.Map{entity.GroupCols.Id: id})
}