tribally report logic

This commit is contained in:
2025-05-08 10:27:30 +08:00
parent 5cbce1e3c9
commit b002ae3ad2
4 changed files with 127 additions and 11 deletions

View File

@@ -16,7 +16,7 @@ type (
NhTriballyUserModel interface {
nhTriballyUserModel
withSession(session sqlx.Session) NhTriballyUserModel
FindUpdateTriballyUsers(ctx context.Context, t time.Time, count int) ([]*TriballyUserChapter, error)
FindUpdateTriballyUsers(ctx context.Context, start, end time.Time, count int) ([]*TriballyUserChapter, error)
}
customNhTriballyUserModel struct {
@@ -32,10 +32,10 @@ type (
}
)
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 ?")
func (m *customNhTriballyUserModel) FindUpdateTriballyUsers(ctx context.Context, start, end 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 >= ? AND g.updated_at < ? AND g.chapter > t.chapter GROUP BY uid LIMIT ?")
var result []*TriballyUserChapter
err := m.conn.QueryRowsCtx(ctx, &result, query, t, count)
err := m.conn.QueryRowsCtx(ctx, &result, query, start, end, count)
if err != nil && !errors.Is(err, sqlx.ErrNotFound) {
return nil, err
}