tribally report
This commit is contained in:
54
internal/model/nh_tribally_user_model.go
Executable file
54
internal/model/nh_tribally_user_model.go
Executable file
@@ -0,0 +1,54 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"time"
|
||||
)
|
||||
|
||||
var _ NhTriballyUserModel = (*customNhTriballyUserModel)(nil)
|
||||
|
||||
type (
|
||||
// NhTriballyUserModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customNhTriballyUserModel.
|
||||
NhTriballyUserModel interface {
|
||||
nhTriballyUserModel
|
||||
withSession(session sqlx.Session) NhTriballyUserModel
|
||||
FindUpdateTriballyUsers(ctx context.Context, t time.Time, count int) ([]*TriballyUserChapter, error)
|
||||
}
|
||||
|
||||
customNhTriballyUserModel struct {
|
||||
*defaultNhTriballyUserModel
|
||||
}
|
||||
|
||||
TriballyUserChapter struct {
|
||||
Id uint `db:"id"`
|
||||
Uid uint `db:"uid"` // 用户id
|
||||
Chapter int `db:"chapter"` // 章节
|
||||
MaxChapter int `db:"max_chapter"` // 最大章节
|
||||
UpdatedAt time.Time `db:"updated_at"` // 修改时间
|
||||
}
|
||||
)
|
||||
|
||||
func (m *customNhTriballyUserModel) FindUpdateTriballyUsers(ctx context.Context, t time.Time, count int) ([]*TriballyUserChapter, error) {
|
||||
query := fmt.Sprintf("SELECT t.uid, t.chapter, MAX(g.chapter) as max_chapter, g.updated_at FROM nh_tribally_user t JOIN nh_game_report g ON t.uid = g.uid WHERE g.updated_at >= ? GROUP BY uid LIMIT ?")
|
||||
var result []*TriballyUserChapter
|
||||
err := m.conn.QueryRowsCtx(ctx, &result, query, t, count)
|
||||
if err != nil && !errors.Is(err, sqlx.ErrNotFound) {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// NewNhTriballyUserModel returns a model for the database table.
|
||||
func NewNhTriballyUserModel(conn sqlx.SqlConn) NhTriballyUserModel {
|
||||
return &customNhTriballyUserModel{
|
||||
defaultNhTriballyUserModel: newNhTriballyUserModel(conn),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *customNhTriballyUserModel) withSession(session sqlx.Session) NhTriballyUserModel {
|
||||
return NewNhTriballyUserModel(sqlx.NewSqlConnFromSession(session))
|
||||
}
|
||||
Reference in New Issue
Block a user