finish tribally report logic

This commit is contained in:
2025-05-08 14:45:46 +08:00
parent 6992994065
commit 1ecac5d626
5 changed files with 57 additions and 11 deletions

View File

@@ -17,6 +17,7 @@ type (
nhTriballyUserModel
withSession(session sqlx.Session) NhTriballyUserModel
FindUpdateTriballyUsers(ctx context.Context, start, end time.Time, count int) ([]*TriballyUserChapter, error)
UpdateUserChapter(ctx context.Context, uid uint, chapter int) error
}
customNhTriballyUserModel struct {
@@ -26,14 +27,21 @@ type (
TriballyUserChapter struct {
Id uint `db:"id"`
Uid uint `db:"uid"` // 用户id
Email string `db:"email"` // 邮箱
Chapter int `db:"chapter"` // 章节
MaxChapter int `db:"max_chapter"` // 最大章节
UpdatedAt time.Time `db:"updated_at"` // 修改时间
}
)
func (m *customNhTriballyUserModel) UpdateUserChapter(ctx context.Context, uid uint, chapter int) error {
update := fmt.Sprintf("UPDATE %s SET `chapter` = ?, WHERE `uid` = ?", m.table)
_, err := m.conn.ExecCtx(ctx, update, chapter, uid)
return err
}
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 ?")
query := fmt.Sprintf("SELECT t.uid, t.email, 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, start, end, count)
if err != nil && !errors.Is(err, sqlx.ErrNotFound) {