package repository import ( "context" "next-terminal/server/model" ) var AccessLogRepository = new(accessLogRepository) type accessLogRepository struct { baseRepository } func (r accessLogRepository) Create(c context.Context, o *model.AccessLog) error { return r.GetDB(c).Create(o).Error } func (r accessLogRepository) FindById(c context.Context, id string) (o model.AccessLog, err error) { err = r.GetDB(c).Where("id = ?", id).First(&o).Error return } func (r accessLogRepository) FindByPage(c context.Context, pageIndex, pageSize int, domain, websiteId, accountId string) (o []model.AccessLog, total int64, err error) { db := r.GetDB(c).Model(&model.AccessLog{}) if domain != "" { db = db.Where("domain LIKE ?", "%"+domain+"%") } if websiteId != "" { db = db.Where("website_id = ?", websiteId) } if accountId != "" { db = db.Where("account_id = ?", accountId) } err = db.Count(&total).Error if err != nil { return nil, 0, err } err = db.Order("created desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&o).Error return } func (r accessLogRepository) DeleteById(c context.Context, id string) error { return r.GetDB(c).Where("id = ?", id).Delete(&model.AccessLog{}).Error } func (r accessLogRepository) DeleteAll(c context.Context) error { return r.GetDB(c).Where("1 = 1").Delete(&model.AccessLog{}).Error } func (r accessLogRepository) FindOutTimeLog(c context.Context, limit int) (o []model.AccessLog, err error) { err = r.GetDB(c).Where("strftime('%s', created) < strftime('%s', 'now', '-' || ? || ' days')", limit).Find(&o).Error return } func (r accessLogRepository) Count(c context.Context) (total int64, err error) { err = r.GetDB(c).Model(&model.AccessLog{}).Count(&total).Error return }