77 lines
2.3 KiB
Go
77 lines
2.3 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"gitea.youtukeji.com.cn/youtu/youtu_grpc/app/ranking_management/internal/gen/dao/model"
|
||
|
"gitea.youtukeji.com.cn/youtu/youtu_grpc/pkg/my_gorm/gen/querier"
|
||
|
"gorm.io/driver/mysql"
|
||
|
"gorm.io/gen"
|
||
|
"gorm.io/gorm"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
g := gen.NewGenerator(gen.Config{
|
||
|
OutPath: "./app/ranking_management/internal/gen/dao/query",
|
||
|
Mode: gen.WithoutContext | gen.WithDefaultQuery | gen.WithQueryInterface, // generate mode
|
||
|
WithUnitTest: true,
|
||
|
})
|
||
|
dsn := "root:youtu!0113@tcp(192.168.0.47:3306)/ecpm?charset=utf8&parseTime=True&loc=Local"
|
||
|
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
// gormdb, _ := gorm.Open(mysql.Open("root:@(127.0.0.1:3306)/demo?charset=utf8mb4&parseTime=True&loc=Local"))
|
||
|
g.UseDB(db) // reuse your gorm db
|
||
|
|
||
|
//g.ApplyBasic(model.AppAccount{}, model.AppUser{}, model.DouyinEcpmConfig{}, model.GameScore{})
|
||
|
// Generate Type Safe API with Dynamic SQL defined on Querier interface for `model.User` and `model.Company`
|
||
|
g.ApplyInterface(func(querier.GameScoreQuerier) {}, model.GameScore{})
|
||
|
|
||
|
g.ApplyBasic(model.GameScore{})
|
||
|
|
||
|
// Generate the code
|
||
|
g.Execute()
|
||
|
|
||
|
}
|
||
|
|
||
|
type GameScoreQuerier interface {
|
||
|
/*
|
||
|
|
||
|
SELECT
|
||
|
app_user.nickname,
|
||
|
app_user.avatar,
|
||
|
gs.score,
|
||
|
gs.app_user_id,
|
||
|
gs.t_rank
|
||
|
FROM
|
||
|
(
|
||
|
SELECT
|
||
|
game_score.score,
|
||
|
game_score.app_user_id,
|
||
|
game_score.app_account,
|
||
|
rank() OVER (ORDER BY game_score.score DESC) t_rank
|
||
|
FROM
|
||
|
game_score
|
||
|
WHERE
|
||
|
game_score.t = @t
|
||
|
AND game_score.app_account = @appId
|
||
|
) AS gs
|
||
|
LEFT JOIN app_user ON app_user.id = gs.app_user_id
|
||
|
WHERE
|
||
|
gs.app_user_id = @userId
|
||
|
LIMIT 1;
|
||
|
*/
|
||
|
GetUserRank(appId uint32, userId uint64, t uint32) (resp RankingData, err error)
|
||
|
|
||
|
//select DISTINCT app_account,t from game_score
|
||
|
FindDistinctRanking() (resp []*gen.T, err error)
|
||
|
}
|
||
|
|
||
|
type RankingData struct {
|
||
|
Nickname string `json:"nickname" db:"nickname"` // 昵称
|
||
|
Avatar string `json:"avatar" db:"avatar"` // 头像
|
||
|
Score uint32 `json:"score" db:"score"` // 得分
|
||
|
UserId uint64 `json:"userId" db:"app_user_id"` // 用户 ID
|
||
|
Rank uint32 `json:"rank" db:"t_rank"` // 排名
|
||
|
Self bool `json:"self" db:"-"` // 是否是自己
|
||
|
}
|