finish tribally report logic
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -40,6 +40,7 @@ type (
|
||||
NhTriballyUser struct {
|
||||
Id uint `db:"id"`
|
||||
Uid uint `db:"uid"` // 用户id
|
||||
Email string `db:"email"` // 邮箱
|
||||
Chapter int `db:"chapter"` // 章节
|
||||
CreatedAt time.Time `db:"created_at"` // 创建时间
|
||||
UpdatedAt time.Time `db:"updated_at"` // 修改时间
|
||||
@@ -88,14 +89,14 @@ func (m *defaultNhTriballyUserModel) FindOneByUid(ctx context.Context, uid uint)
|
||||
}
|
||||
|
||||
func (m *defaultNhTriballyUserModel) Insert(ctx context.Context, data *NhTriballyUser) (sql.Result, error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?)", m.table, nhTriballyUserRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.Uid, data.Chapter)
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?)", m.table, nhTriballyUserRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.Uid, data.Email, data.Chapter)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultNhTriballyUserModel) Update(ctx context.Context, newData *NhTriballyUser) error {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, nhTriballyUserRowsWithPlaceHolder)
|
||||
_, err := m.conn.ExecCtx(ctx, query, newData.Uid, newData.Chapter, newData.Id)
|
||||
_, err := m.conn.ExecCtx(ctx, query, newData.Uid, newData.Email, newData.Chapter, newData.Id)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user