Files
novatask/internal/model/nh_game_report_model.go
2025-01-17 21:08:18 +08:00

71 lines
2.0 KiB
Go
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package model
import (
"context"
"errors"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ NhGameReportModel = (*customNhGameReportModel)(nil)
type (
// NhGameReportModel is an interface to be customized, add more methods here,
// and implement the added methods in customNhGameReportModel.
NhGameReportModel interface {
nhGameReportModel
withSession(session sqlx.Session) NhGameReportModel
FindMaxByEmail(ctx context.Context, email string) (*GameReport, error)
}
GameReport struct {
Account string `db:"account"` // 账号
IsHaveTwoHero int8 `db:"is_have_two_hero"` // 是否拥有两个以上的英雄1=是
IsUsedSummon int8 `db:"is_used_summon"` // 是否已使用了召唤1=是
IsHaveHero31 int `db:"is_have_hero_31"` // 是否拥有31级以上的英雄1=是
Chapter int `db:"chapter"` // 完成的章节
}
customNhGameReportModel struct {
*defaultNhGameReportModel
}
)
func (m *customNhGameReportModel) FindMaxByEmail(ctx context.Context, email string) (*GameReport, error) {
query := `SELECT
r.account,
MAX(g.is_have_two_hero) AS is_have_two_hero,
MAX(g.is_used_summon) AS is_used_summon,
MAX(g.is_have_hero_31) AS is_have_hero_31,
MAX(g.chapter) AS chapter
FROM
nh_game_report g
JOIN
nh_role r ON g.role_id = r.role_id
WHERE
r.account = ?
GROUP BY
r.account;
`
var resp GameReport
err := m.conn.QueryRowCtx(ctx, &resp, query, email)
switch {
case err == nil:
return &resp, nil
case errors.Is(err, sqlx.ErrNotFound):
return nil, ErrNotFound
default:
return nil, err
}
}
// NewNhGameReportModel returns a model for the database table.
func NewNhGameReportModel(conn sqlx.SqlConn) NhGameReportModel {
return &customNhGameReportModel{
defaultNhGameReportModel: newNhGameReportModel(conn),
}
}
func (m *customNhGameReportModel) withSession(session sqlx.Session) NhGameReportModel {
return NewNhGameReportModel(sqlx.NewSqlConnFromSession(session))
}