49 lines
1.7 KiB
Go
49 lines
1.7 KiB
Go
package dao
|
|
|
|
import (
|
|
"context"
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"ppgo_job/consts"
|
|
"ppgo_job/model/entity"
|
|
)
|
|
|
|
var NotifyTpl = new(notifyTplDao)
|
|
|
|
type notifyTplDao struct{}
|
|
|
|
func (d *notifyTplDao) Insert(ctx context.Context, data *entity.NotifyTpl) (id int64, err error) {
|
|
return InsertAndGetId(ctx, consts.TableNotifyTpl, data)
|
|
}
|
|
func (d *notifyTplDao) GetById(ctx context.Context, id int) (*entity.NotifyTpl, error) {
|
|
var result *entity.NotifyTpl
|
|
err := GetById(ctx, consts.TableNotifyTpl, id, &result)
|
|
return result, err
|
|
}
|
|
func (d *notifyTplDao) GetByTplType(ctx context.Context, tplType int, tplTypeName string) (*entity.NotifyTpl, error) {
|
|
var result *entity.NotifyTpl
|
|
err := g.DB().Model(consts.TableNotifyTpl).Ctx(ctx).Where(entity.NotifyTplCols.TplType, tplType).Where(entity.NotifyTplCols.Type, tplTypeName).Where(entity.NotifyTplCols.Status, 1).Scan(&result)
|
|
return result, err
|
|
}
|
|
func (d *notifyTplDao) GetList(ctx context.Context, pageNum, pageSize int, filters ...interface{}) ([]*entity.NotifyTpl, int, error) {
|
|
m := g.DB().Model(consts.TableNotifyTpl).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.NotifyTpl
|
|
if order == "" {
|
|
order = entity.NotifyTplCols.Id + " desc"
|
|
}
|
|
err = m.Limit(limit).Offset(offset).Order(order).Scan(&result)
|
|
return result, total, err
|
|
}
|
|
func (d *notifyTplDao) Update(ctx context.Context, data *entity.NotifyTpl) error {
|
|
return Update(ctx, consts.TableNotifyTpl, data, g.Map{entity.NotifyTplCols.Id: data.Id})
|
|
}
|
|
func (d *notifyTplDao) Delete(ctx context.Context, id int) error {
|
|
return Delete(ctx, consts.TableNotifyTpl, g.Map{entity.NotifyTplCols.Id: id})
|
|
}
|