60 lines
1.8 KiB
Go
60 lines
1.8 KiB
Go
package dao
|
|
|
|
import (
|
|
"context"
|
|
"ppgo_job/consts"
|
|
"ppgo_job/model/entity"
|
|
|
|
"github.com/gogf/gf/v2/database/gdb"
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
)
|
|
|
|
var TaskLog = new(taskLogDao)
|
|
|
|
type taskLogDao struct{}
|
|
|
|
func (d *taskLogDao) Insert(ctx context.Context, data *entity.TaskLog) (id int64, err error) {
|
|
return InsertAndGetId(ctx, consts.TableTaskLog, data)
|
|
}
|
|
|
|
func (d *taskLogDao) GetById(ctx context.Context, id int) (*entity.TaskLog, error) {
|
|
var result *entity.TaskLog
|
|
err := GetById(ctx, consts.TableTaskLog, id, &result)
|
|
return result, err
|
|
}
|
|
|
|
func (d *taskLogDao) GetList(ctx context.Context, pageNum, pageSize int, filters ...interface{}) ([]*entity.TaskLog, int, error) {
|
|
m := g.DB().Model(consts.TableTaskLog).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.TaskLog
|
|
if order == "" {
|
|
order = entity.TaskLogCols.Id + " desc"
|
|
}
|
|
err = m.Limit(limit).Offset(offset).Order(order).Scan(&result)
|
|
return result, total, err
|
|
}
|
|
|
|
func (d *taskLogDao) DeleteById(ctx context.Context, id int) error {
|
|
return Delete(ctx, consts.TableTaskLog, g.Map{entity.TaskLogCols.Id: id})
|
|
}
|
|
|
|
func (d *taskLogDao) DeleteByTaskId(ctx context.Context, taskId int) error {
|
|
return Delete(ctx, consts.TableTaskLog, g.Map{entity.TaskLogCols.TaskId: taskId})
|
|
}
|
|
|
|
func (d *taskLogDao) GetLogNum(ctx context.Context) (int, error) {
|
|
return Count(ctx, consts.TableTaskLog, nil)
|
|
}
|
|
|
|
func (d *taskLogDao) SumByDays(ctx context.Context, days int) (gdb.Result, error) {
|
|
return g.DB().Model(consts.TableTaskLog).Ctx(ctx).
|
|
Fields("strftime('%Y-%m-%d', create_time, 'unixepoch') as date, COUNT(*) as total").
|
|
Where("create_time > ?", 0).Group("date").OrderAsc("date").All()
|
|
}
|