Compare commits
9 Commits
39fa373c01
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 7cf72e7897 | |||
| fde4720fcc | |||
| 6ae504818d | |||
| f73783b742 | |||
| 77cc02fc95 | |||
| 1a42e055ae | |||
| c2807b54df | |||
| 96f0919c05 | |||
| 36621140f8 |
30
app/app.go
30
app/app.go
@@ -2,11 +2,11 @@ package app
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.hlsq.asia/mmorpg/service-common/discover/common"
|
"git.hlsq.asia/alex/service-common/discover/common"
|
||||||
"git.hlsq.asia/mmorpg/service-common/log"
|
"git.hlsq.asia/alex/service-common/log"
|
||||||
"git.hlsq.asia/mmorpg/service-common/module"
|
"git.hlsq.asia/alex/service-common/module"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/config"
|
"git.hlsq.asia/alex/service-qgdzs/config"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/grpc_server"
|
"git.hlsq.asia/alex/service-qgdzs/internal/grpcserver"
|
||||||
"github.com/judwhite/go-svc"
|
"github.com/judwhite/go-svc"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
@@ -16,22 +16,16 @@ type Program struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Program) Init(_ svc.Environment) error {
|
func (p *Program) Init(_ svc.Environment) error {
|
||||||
base := &ModuleBase{}
|
p.moduleList = append(p.moduleList, &module.Log{Cfg: config.Get().Log})
|
||||||
if err := base.Init(); err != nil {
|
p.moduleList = append(p.moduleList, &module.DB{Cfg: config.Get().DB, AppName: config.Get().App.Name})
|
||||||
return err
|
p.moduleList = append(p.moduleList, &module.Snowflake{})
|
||||||
}
|
p.moduleList = append(p.moduleList, &module.Grpc{Server: grpcserver.NewServer(config.Get().Serve.Grpc)})
|
||||||
p.moduleList = append(p.moduleList, base)
|
|
||||||
p.moduleList = append(p.moduleList, (&module.DB{}).Bind(config.Get().DB, config.Get().App.Name))
|
|
||||||
p.moduleList = append(p.moduleList, (&module.Grpc{}).Bind(grpc_server.NewServer(config.Get().Serve.Grpc)))
|
|
||||||
p.moduleList = append(p.moduleList, &ModuleTimer{})
|
p.moduleList = append(p.moduleList, &ModuleTimer{})
|
||||||
p.moduleList = append(p.moduleList, (&module.Prometheus{}).Bind(config.Get().Metric))
|
p.moduleList = append(p.moduleList, &module.Prometheus{Cfg: config.Get().Metric})
|
||||||
p.moduleList = append(p.moduleList, (&module.Tracer{}).Bind(config.Get().Metric, common.KeyDiscoverServiceNameQgdzs))
|
p.moduleList = append(p.moduleList, &module.Tracer{Cfg: config.Get().Metric, ServiceName: common.KeyDiscoverServiceNameQgdzs})
|
||||||
p.moduleList = append(p.moduleList, &module.Discover{})
|
p.moduleList = append(p.moduleList, &module.Discover{})
|
||||||
|
|
||||||
for i, m := range p.moduleList {
|
for _, m := range p.moduleList {
|
||||||
if i == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err := m.Init(); err != nil {
|
if err := m.Init(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
27
app/base.go
27
app/base.go
@@ -1,27 +0,0 @@
|
|||||||
package app
|
|
||||||
|
|
||||||
import (
|
|
||||||
"git.hlsq.asia/mmorpg/service-common/log"
|
|
||||||
"git.hlsq.asia/mmorpg/service-common/module"
|
|
||||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/config"
|
|
||||||
"math/rand"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ModuleBase 基础模块,或者一些零散的模块
|
|
||||||
type ModuleBase struct {
|
|
||||||
module.DefaultModule
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ModuleBase) Init() error {
|
|
||||||
// 配置
|
|
||||||
if err := config.LoadConfig(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
cfg := config.Get()
|
|
||||||
// 日志
|
|
||||||
log.Init(cfg.Log.Debug, cfg.Log.MaxSize, cfg.Log.MaxBackups, cfg.Log.MaxAge, cfg.Log.Level)
|
|
||||||
// 雪花
|
|
||||||
utils.InitSnowflake(int64(rand.Intn(1000)))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.hlsq.asia/mmorpg/service-common/module"
|
"git.hlsq.asia/alex/service-common/module"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/timer"
|
"git.hlsq.asia/alex/service-qgdzs/internal/timer"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import "git.hlsq.asia/mmorpg/service-common/config"
|
import "git.hlsq.asia/alex/service-common/config"
|
||||||
|
|
||||||
const path = "./config"
|
const path = "./config"
|
||||||
|
|
||||||
|
|||||||
2
deploy/Jenkinsfile
vendored
2
deploy/Jenkinsfile
vendored
@@ -3,7 +3,7 @@ pipeline {
|
|||||||
|
|
||||||
environment {
|
environment {
|
||||||
// 仓库
|
// 仓库
|
||||||
REPO_URL = 'https://git.hlsq.asia/mmorpg/service-qgdzs.git'
|
REPO_URL = 'https://git.hlsq.asia/alex/service-qgdzs.git'
|
||||||
REPO_CREDENTIALS_ID = '80805ba2-f4ac-4d84-aee6-d4cce5fc0a96'
|
REPO_CREDENTIALS_ID = '80805ba2-f4ac-4d84-aee6-d4cce5fc0a96'
|
||||||
|
|
||||||
// Registry
|
// Registry
|
||||||
|
|||||||
4
go.mod
4
go.mod
@@ -1,9 +1,9 @@
|
|||||||
module git.hlsq.asia/mmorpg/service-qgdzs
|
module git.hlsq.asia/alex/service-qgdzs
|
||||||
|
|
||||||
go 1.24.0
|
go 1.24.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260130025300-427fca7ed19f
|
git.hlsq.asia/alex/service-common master
|
||||||
github.com/judwhite/go-svc v1.2.1
|
github.com/judwhite/go-svc v1.2.1
|
||||||
github.com/robfig/cron/v3 v3.0.1
|
github.com/robfig/cron/v3 v3.0.1
|
||||||
google.golang.org/grpc v1.77.0
|
google.golang.org/grpc v1.77.0
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -1,7 +1,7 @@
|
|||||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260130025300-427fca7ed19f h1:U0HnB8i3ZTKrg3XBQpwFcI64LB6mraj02yNAqV3MBws=
|
git.hlsq.asia/alex/service-common v0.0.0-20260211064821-558677bc3a2e h1:MNVS1NXNVn4DeTZPcvvA8YFM8afCzZedLPUYMffNgZs=
|
||||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260130025300-427fca7ed19f/go.mod h1:mMhZcumphj6gaVTppVYsMTkd+5HupmQgAc53Pd4MH9I=
|
git.hlsq.asia/alex/service-common v0.0.0-20260211064821-558677bc3a2e/go.mod h1:mMhZcumphj6gaVTppVYsMTkd+5HupmQgAc53Pd4MH9I=
|
||||||
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
|
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
|
||||||
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||||
github.com/IBM/sarama v1.46.3 h1:njRsX6jNlnR+ClJ8XmkO+CM4unbrNr/2vB5KK6UA+IE=
|
github.com/IBM/sarama v1.46.3 h1:njRsX6jNlnR+ClJ8XmkO+CM4unbrNr/2vB5KK6UA+IE=
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package ai
|
package ai
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.hlsq.asia/mmorpg/service-common/log"
|
"git.hlsq.asia/alex/service-common/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ package model
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
"git.hlsq.asia/alex/service-common/utils"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ const TableNameCategory = "categories"
|
|||||||
// Category mapped from table <categories>
|
// Category mapped from table <categories>
|
||||||
type Category struct {
|
type Category struct {
|
||||||
ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
|
ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
|
||||||
Sn string `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
|
Sn int64 `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
|
||||||
Category string `gorm:"column:category;not null;comment:分类" json:"category"` // 分类
|
Category string `gorm:"column:category;not null;comment:分类" json:"category"` // 分类
|
||||||
CreatedAt time.Time `gorm:"column:created_at;not null" json:"created_at"`
|
CreatedAt time.Time `gorm:"column:created_at;not null" json:"created_at"`
|
||||||
UpdatedAt time.Time `gorm:"column:updated_at;not null" json:"updated_at"`
|
UpdatedAt time.Time `gorm:"column:updated_at;not null" json:"updated_at"`
|
||||||
@@ -30,8 +30,8 @@ func (*Category) TableName() string {
|
|||||||
|
|
||||||
// Auto sn
|
// Auto sn
|
||||||
func (m *Category) BeforeCreate(_ *gorm.DB) error {
|
func (m *Category) BeforeCreate(_ *gorm.DB) error {
|
||||||
if m.Sn == "" {
|
if m.Sn == 0 {
|
||||||
m.Sn = utils.SnowflakeInstance().Generate().String()
|
m.Sn = utils.SnowflakeInstance().Generate().Int64()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ package model
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
"git.hlsq.asia/alex/service-common/utils"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,8 +16,8 @@ const TableNamePointCard = "point_card"
|
|||||||
// PointCard mapped from table <point_card>
|
// PointCard mapped from table <point_card>
|
||||||
type PointCard struct {
|
type PointCard struct {
|
||||||
ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
|
ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
|
||||||
Sn string `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
|
Sn int64 `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
|
||||||
UserSn string `gorm:"column:user_sn;not null;comment:用户-唯一编号" json:"user_sn"` // 用户-唯一编号
|
UserSn int64 `gorm:"column:user_sn;not null;comment:用户-唯一编号" json:"user_sn"` // 用户-唯一编号
|
||||||
Point int64 `gorm:"column:point;not null;comment:积分" json:"point"` // 积分
|
Point int64 `gorm:"column:point;not null;comment:积分" json:"point"` // 积分
|
||||||
CreatedAt time.Time `gorm:"column:created_at;not null" json:"created_at"`
|
CreatedAt time.Time `gorm:"column:created_at;not null" json:"created_at"`
|
||||||
UpdatedAt time.Time `gorm:"column:updated_at;not null" json:"updated_at"`
|
UpdatedAt time.Time `gorm:"column:updated_at;not null" json:"updated_at"`
|
||||||
@@ -31,8 +31,8 @@ func (*PointCard) TableName() string {
|
|||||||
|
|
||||||
// Auto sn
|
// Auto sn
|
||||||
func (m *PointCard) BeforeCreate(_ *gorm.DB) error {
|
func (m *PointCard) BeforeCreate(_ *gorm.DB) error {
|
||||||
if m.Sn == "" {
|
if m.Sn == 0 {
|
||||||
m.Sn = utils.SnowflakeInstance().Generate().String()
|
m.Sn = utils.SnowflakeInstance().Generate().Int64()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ package model
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
"git.hlsq.asia/alex/service-common/utils"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,8 +16,8 @@ const TableNamePointRecord = "point_records"
|
|||||||
// PointRecord mapped from table <point_records>
|
// PointRecord mapped from table <point_records>
|
||||||
type PointRecord struct {
|
type PointRecord struct {
|
||||||
ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
|
ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
|
||||||
Sn string `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
|
Sn int64 `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
|
||||||
UserSn string `gorm:"column:user_sn;not null;comment:用户-唯一编号" json:"user_sn"` // 用户-唯一编号
|
UserSn int64 `gorm:"column:user_sn;not null;comment:用户-唯一编号" json:"user_sn"` // 用户-唯一编号
|
||||||
/*
|
/*
|
||||||
来源:
|
来源:
|
||||||
0. 未知
|
0. 未知
|
||||||
@@ -39,8 +39,8 @@ func (*PointRecord) TableName() string {
|
|||||||
|
|
||||||
// Auto sn
|
// Auto sn
|
||||||
func (m *PointRecord) BeforeCreate(_ *gorm.DB) error {
|
func (m *PointRecord) BeforeCreate(_ *gorm.DB) error {
|
||||||
if m.Sn == "" {
|
if m.Sn == 0 {
|
||||||
m.Sn = utils.SnowflakeInstance().Generate().String()
|
m.Sn = utils.SnowflakeInstance().Generate().Int64()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ package model
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
"git.hlsq.asia/alex/service-common/utils"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,13 +16,13 @@ const TableNameQuestion = "questions"
|
|||||||
// Question mapped from table <questions>
|
// Question mapped from table <questions>
|
||||||
type Question struct {
|
type Question struct {
|
||||||
ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
|
ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
|
||||||
Sn string `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
|
Sn int64 `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
|
||||||
Question string `gorm:"column:question;not null;comment:题干" json:"question"` // 题干
|
Question string `gorm:"column:question;not null;comment:题干" json:"question"` // 题干
|
||||||
Options string `gorm:"column:options;not null;comment:选项" json:"options"` // 选项
|
Options string `gorm:"column:options;not null;comment:选项" json:"options"` // 选项
|
||||||
Answer string `gorm:"column:answer;not null;comment:答案" json:"answer"` // 答案
|
Answer string `gorm:"column:answer;not null;comment:答案" json:"answer"` // 答案
|
||||||
Explanation string `gorm:"column:explanation;not null;comment:解析" json:"explanation"` // 解析
|
Explanation string `gorm:"column:explanation;not null;comment:解析" json:"explanation"` // 解析
|
||||||
Difficulty int32 `gorm:"column:difficulty;not null;comment:难度分 0 - 100" json:"difficulty"` // 难度分 0 - 100
|
Difficulty int32 `gorm:"column:difficulty;not null;comment:难度分 0 - 100" json:"difficulty"` // 难度分 0 - 100
|
||||||
CategorySn string `gorm:"column:category_sn;not null;comment:分类-唯一编号" json:"category_sn"` // 分类-唯一编号
|
CategorySn int64 `gorm:"column:category_sn;not null;comment:分类-唯一编号" json:"category_sn"` // 分类-唯一编号
|
||||||
CreatedAt time.Time `gorm:"column:created_at;not null" json:"created_at"`
|
CreatedAt time.Time `gorm:"column:created_at;not null" json:"created_at"`
|
||||||
UpdatedAt time.Time `gorm:"column:updated_at;not null" json:"updated_at"`
|
UpdatedAt time.Time `gorm:"column:updated_at;not null" json:"updated_at"`
|
||||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at" json:"deleted_at"`
|
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at" json:"deleted_at"`
|
||||||
@@ -35,8 +35,8 @@ func (*Question) TableName() string {
|
|||||||
|
|
||||||
// Auto sn
|
// Auto sn
|
||||||
func (m *Question) BeforeCreate(_ *gorm.DB) error {
|
func (m *Question) BeforeCreate(_ *gorm.DB) error {
|
||||||
if m.Sn == "" {
|
if m.Sn == 0 {
|
||||||
m.Sn = utils.SnowflakeInstance().Generate().String()
|
m.Sn = utils.SnowflakeInstance().Generate().Int64()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ package model
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
"git.hlsq.asia/alex/service-common/utils"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,9 +16,9 @@ const TableNameRecord = "records"
|
|||||||
// Record mapped from table <records>
|
// Record mapped from table <records>
|
||||||
type Record struct {
|
type Record struct {
|
||||||
ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
|
ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
|
||||||
Sn string `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
|
Sn int64 `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
|
||||||
UserSn string `gorm:"column:user_sn;not null;comment:用户-唯一编号" json:"user_sn"` // 用户-唯一编号
|
UserSn int64 `gorm:"column:user_sn;not null;comment:用户-唯一编号" json:"user_sn"` // 用户-唯一编号
|
||||||
QuestionSn string `gorm:"column:question_sn;not null;comment:题目-唯一编号" json:"question_sn"` // 题目-唯一编号
|
QuestionSn int64 `gorm:"column:question_sn;not null;comment:题目-唯一编号" json:"question_sn"` // 题目-唯一编号
|
||||||
Answer string `gorm:"column:answer;not null;comment:答案" json:"answer"` // 答案
|
Answer string `gorm:"column:answer;not null;comment:答案" json:"answer"` // 答案
|
||||||
IsCorrect int32 `gorm:"column:is_correct;not null;comment:是否正确 0 否 1 是" json:"is_correct"` // 是否正确 0 否 1 是
|
IsCorrect int32 `gorm:"column:is_correct;not null;comment:是否正确 0 否 1 是" json:"is_correct"` // 是否正确 0 否 1 是
|
||||||
CreatedAt time.Time `gorm:"column:created_at;not null" json:"created_at"`
|
CreatedAt time.Time `gorm:"column:created_at;not null" json:"created_at"`
|
||||||
@@ -33,8 +33,8 @@ func (*Record) TableName() string {
|
|||||||
|
|
||||||
// Auto sn
|
// Auto sn
|
||||||
func (m *Record) BeforeCreate(_ *gorm.DB) error {
|
func (m *Record) BeforeCreate(_ *gorm.DB) error {
|
||||||
if m.Sn == "" {
|
if m.Sn == 0 {
|
||||||
m.Sn = utils.SnowflakeInstance().Generate().String()
|
m.Sn = utils.SnowflakeInstance().Generate().Int64()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import (
|
|||||||
|
|
||||||
"gorm.io/plugin/dbresolver"
|
"gorm.io/plugin/dbresolver"
|
||||||
|
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/model"
|
"git.hlsq.asia/alex/service-qgdzs/internal/dao/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newCategory(db *gorm.DB, opts ...gen.DOOption) category {
|
func newCategory(db *gorm.DB, opts ...gen.DOOption) category {
|
||||||
@@ -28,7 +28,7 @@ func newCategory(db *gorm.DB, opts ...gen.DOOption) category {
|
|||||||
tableName := _category.categoryDo.TableName()
|
tableName := _category.categoryDo.TableName()
|
||||||
_category.ALL = field.NewAsterisk(tableName)
|
_category.ALL = field.NewAsterisk(tableName)
|
||||||
_category.ID = field.NewUint64(tableName, "id")
|
_category.ID = field.NewUint64(tableName, "id")
|
||||||
_category.Sn = field.NewString(tableName, "sn")
|
_category.Sn = field.NewInt64(tableName, "sn")
|
||||||
_category.Category = field.NewString(tableName, "category")
|
_category.Category = field.NewString(tableName, "category")
|
||||||
_category.CreatedAt = field.NewTime(tableName, "created_at")
|
_category.CreatedAt = field.NewTime(tableName, "created_at")
|
||||||
_category.UpdatedAt = field.NewTime(tableName, "updated_at")
|
_category.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||||
@@ -44,7 +44,7 @@ type category struct {
|
|||||||
|
|
||||||
ALL field.Asterisk
|
ALL field.Asterisk
|
||||||
ID field.Uint64
|
ID field.Uint64
|
||||||
Sn field.String // 业务唯一编号
|
Sn field.Int64 // 业务唯一编号
|
||||||
Category field.String // 分类
|
Category field.String // 分类
|
||||||
CreatedAt field.Time
|
CreatedAt field.Time
|
||||||
UpdatedAt field.Time
|
UpdatedAt field.Time
|
||||||
@@ -66,7 +66,7 @@ func (c category) As(alias string) *category {
|
|||||||
func (c *category) updateTableName(table string) *category {
|
func (c *category) updateTableName(table string) *category {
|
||||||
c.ALL = field.NewAsterisk(table)
|
c.ALL = field.NewAsterisk(table)
|
||||||
c.ID = field.NewUint64(table, "id")
|
c.ID = field.NewUint64(table, "id")
|
||||||
c.Sn = field.NewString(table, "sn")
|
c.Sn = field.NewInt64(table, "sn")
|
||||||
c.Category = field.NewString(table, "category")
|
c.Category = field.NewString(table, "category")
|
||||||
c.CreatedAt = field.NewTime(table, "created_at")
|
c.CreatedAt = field.NewTime(table, "created_at")
|
||||||
c.UpdatedAt = field.NewTime(table, "updated_at")
|
c.UpdatedAt = field.NewTime(table, "updated_at")
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import (
|
|||||||
|
|
||||||
"gorm.io/plugin/dbresolver"
|
"gorm.io/plugin/dbresolver"
|
||||||
|
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/model"
|
"git.hlsq.asia/alex/service-qgdzs/internal/dao/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newPointCard(db *gorm.DB, opts ...gen.DOOption) pointCard {
|
func newPointCard(db *gorm.DB, opts ...gen.DOOption) pointCard {
|
||||||
@@ -28,8 +28,8 @@ func newPointCard(db *gorm.DB, opts ...gen.DOOption) pointCard {
|
|||||||
tableName := _pointCard.pointCardDo.TableName()
|
tableName := _pointCard.pointCardDo.TableName()
|
||||||
_pointCard.ALL = field.NewAsterisk(tableName)
|
_pointCard.ALL = field.NewAsterisk(tableName)
|
||||||
_pointCard.ID = field.NewUint64(tableName, "id")
|
_pointCard.ID = field.NewUint64(tableName, "id")
|
||||||
_pointCard.Sn = field.NewString(tableName, "sn")
|
_pointCard.Sn = field.NewInt64(tableName, "sn")
|
||||||
_pointCard.UserSn = field.NewString(tableName, "user_sn")
|
_pointCard.UserSn = field.NewInt64(tableName, "user_sn")
|
||||||
_pointCard.Point = field.NewInt64(tableName, "point")
|
_pointCard.Point = field.NewInt64(tableName, "point")
|
||||||
_pointCard.CreatedAt = field.NewTime(tableName, "created_at")
|
_pointCard.CreatedAt = field.NewTime(tableName, "created_at")
|
||||||
_pointCard.UpdatedAt = field.NewTime(tableName, "updated_at")
|
_pointCard.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||||
@@ -45,8 +45,8 @@ type pointCard struct {
|
|||||||
|
|
||||||
ALL field.Asterisk
|
ALL field.Asterisk
|
||||||
ID field.Uint64
|
ID field.Uint64
|
||||||
Sn field.String // 业务唯一编号
|
Sn field.Int64 // 业务唯一编号
|
||||||
UserSn field.String // 用户-唯一编号
|
UserSn field.Int64 // 用户-唯一编号
|
||||||
Point field.Int64 // 积分
|
Point field.Int64 // 积分
|
||||||
CreatedAt field.Time
|
CreatedAt field.Time
|
||||||
UpdatedAt field.Time
|
UpdatedAt field.Time
|
||||||
@@ -68,8 +68,8 @@ func (p pointCard) As(alias string) *pointCard {
|
|||||||
func (p *pointCard) updateTableName(table string) *pointCard {
|
func (p *pointCard) updateTableName(table string) *pointCard {
|
||||||
p.ALL = field.NewAsterisk(table)
|
p.ALL = field.NewAsterisk(table)
|
||||||
p.ID = field.NewUint64(table, "id")
|
p.ID = field.NewUint64(table, "id")
|
||||||
p.Sn = field.NewString(table, "sn")
|
p.Sn = field.NewInt64(table, "sn")
|
||||||
p.UserSn = field.NewString(table, "user_sn")
|
p.UserSn = field.NewInt64(table, "user_sn")
|
||||||
p.Point = field.NewInt64(table, "point")
|
p.Point = field.NewInt64(table, "point")
|
||||||
p.CreatedAt = field.NewTime(table, "created_at")
|
p.CreatedAt = field.NewTime(table, "created_at")
|
||||||
p.UpdatedAt = field.NewTime(table, "updated_at")
|
p.UpdatedAt = field.NewTime(table, "updated_at")
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import (
|
|||||||
|
|
||||||
"gorm.io/plugin/dbresolver"
|
"gorm.io/plugin/dbresolver"
|
||||||
|
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/model"
|
"git.hlsq.asia/alex/service-qgdzs/internal/dao/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newPointRecord(db *gorm.DB, opts ...gen.DOOption) pointRecord {
|
func newPointRecord(db *gorm.DB, opts ...gen.DOOption) pointRecord {
|
||||||
@@ -28,8 +28,8 @@ func newPointRecord(db *gorm.DB, opts ...gen.DOOption) pointRecord {
|
|||||||
tableName := _pointRecord.pointRecordDo.TableName()
|
tableName := _pointRecord.pointRecordDo.TableName()
|
||||||
_pointRecord.ALL = field.NewAsterisk(tableName)
|
_pointRecord.ALL = field.NewAsterisk(tableName)
|
||||||
_pointRecord.ID = field.NewUint64(tableName, "id")
|
_pointRecord.ID = field.NewUint64(tableName, "id")
|
||||||
_pointRecord.Sn = field.NewString(tableName, "sn")
|
_pointRecord.Sn = field.NewInt64(tableName, "sn")
|
||||||
_pointRecord.UserSn = field.NewString(tableName, "user_sn")
|
_pointRecord.UserSn = field.NewInt64(tableName, "user_sn")
|
||||||
_pointRecord.Source = field.NewInt32(tableName, "source")
|
_pointRecord.Source = field.NewInt32(tableName, "source")
|
||||||
_pointRecord.Point = field.NewInt64(tableName, "point")
|
_pointRecord.Point = field.NewInt64(tableName, "point")
|
||||||
_pointRecord.CreatedAt = field.NewTime(tableName, "created_at")
|
_pointRecord.CreatedAt = field.NewTime(tableName, "created_at")
|
||||||
@@ -46,8 +46,8 @@ type pointRecord struct {
|
|||||||
|
|
||||||
ALL field.Asterisk
|
ALL field.Asterisk
|
||||||
ID field.Uint64
|
ID field.Uint64
|
||||||
Sn field.String // 业务唯一编号
|
Sn field.Int64 // 业务唯一编号
|
||||||
UserSn field.String // 用户-唯一编号
|
UserSn field.Int64 // 用户-唯一编号
|
||||||
/*
|
/*
|
||||||
来源:
|
来源:
|
||||||
0. 未知
|
0. 未知
|
||||||
@@ -77,8 +77,8 @@ func (p pointRecord) As(alias string) *pointRecord {
|
|||||||
func (p *pointRecord) updateTableName(table string) *pointRecord {
|
func (p *pointRecord) updateTableName(table string) *pointRecord {
|
||||||
p.ALL = field.NewAsterisk(table)
|
p.ALL = field.NewAsterisk(table)
|
||||||
p.ID = field.NewUint64(table, "id")
|
p.ID = field.NewUint64(table, "id")
|
||||||
p.Sn = field.NewString(table, "sn")
|
p.Sn = field.NewInt64(table, "sn")
|
||||||
p.UserSn = field.NewString(table, "user_sn")
|
p.UserSn = field.NewInt64(table, "user_sn")
|
||||||
p.Source = field.NewInt32(table, "source")
|
p.Source = field.NewInt32(table, "source")
|
||||||
p.Point = field.NewInt64(table, "point")
|
p.Point = field.NewInt64(table, "point")
|
||||||
p.CreatedAt = field.NewTime(table, "created_at")
|
p.CreatedAt = field.NewTime(table, "created_at")
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import (
|
|||||||
|
|
||||||
"gorm.io/plugin/dbresolver"
|
"gorm.io/plugin/dbresolver"
|
||||||
|
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/model"
|
"git.hlsq.asia/alex/service-qgdzs/internal/dao/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newQuestion(db *gorm.DB, opts ...gen.DOOption) question {
|
func newQuestion(db *gorm.DB, opts ...gen.DOOption) question {
|
||||||
@@ -28,13 +28,13 @@ func newQuestion(db *gorm.DB, opts ...gen.DOOption) question {
|
|||||||
tableName := _question.questionDo.TableName()
|
tableName := _question.questionDo.TableName()
|
||||||
_question.ALL = field.NewAsterisk(tableName)
|
_question.ALL = field.NewAsterisk(tableName)
|
||||||
_question.ID = field.NewUint64(tableName, "id")
|
_question.ID = field.NewUint64(tableName, "id")
|
||||||
_question.Sn = field.NewString(tableName, "sn")
|
_question.Sn = field.NewInt64(tableName, "sn")
|
||||||
_question.Question = field.NewString(tableName, "question")
|
_question.Question = field.NewString(tableName, "question")
|
||||||
_question.Options = field.NewString(tableName, "options")
|
_question.Options = field.NewString(tableName, "options")
|
||||||
_question.Answer = field.NewString(tableName, "answer")
|
_question.Answer = field.NewString(tableName, "answer")
|
||||||
_question.Explanation = field.NewString(tableName, "explanation")
|
_question.Explanation = field.NewString(tableName, "explanation")
|
||||||
_question.Difficulty = field.NewInt32(tableName, "difficulty")
|
_question.Difficulty = field.NewInt32(tableName, "difficulty")
|
||||||
_question.CategorySn = field.NewString(tableName, "category_sn")
|
_question.CategorySn = field.NewInt64(tableName, "category_sn")
|
||||||
_question.CreatedAt = field.NewTime(tableName, "created_at")
|
_question.CreatedAt = field.NewTime(tableName, "created_at")
|
||||||
_question.UpdatedAt = field.NewTime(tableName, "updated_at")
|
_question.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||||
_question.DeletedAt = field.NewField(tableName, "deleted_at")
|
_question.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||||
@@ -49,13 +49,13 @@ type question struct {
|
|||||||
|
|
||||||
ALL field.Asterisk
|
ALL field.Asterisk
|
||||||
ID field.Uint64
|
ID field.Uint64
|
||||||
Sn field.String // 业务唯一编号
|
Sn field.Int64 // 业务唯一编号
|
||||||
Question field.String // 题干
|
Question field.String // 题干
|
||||||
Options field.String // 选项
|
Options field.String // 选项
|
||||||
Answer field.String // 答案
|
Answer field.String // 答案
|
||||||
Explanation field.String // 解析
|
Explanation field.String // 解析
|
||||||
Difficulty field.Int32 // 难度分 0 - 100
|
Difficulty field.Int32 // 难度分 0 - 100
|
||||||
CategorySn field.String // 分类-唯一编号
|
CategorySn field.Int64 // 分类-唯一编号
|
||||||
CreatedAt field.Time
|
CreatedAt field.Time
|
||||||
UpdatedAt field.Time
|
UpdatedAt field.Time
|
||||||
DeletedAt field.Field
|
DeletedAt field.Field
|
||||||
@@ -76,13 +76,13 @@ func (q question) As(alias string) *question {
|
|||||||
func (q *question) updateTableName(table string) *question {
|
func (q *question) updateTableName(table string) *question {
|
||||||
q.ALL = field.NewAsterisk(table)
|
q.ALL = field.NewAsterisk(table)
|
||||||
q.ID = field.NewUint64(table, "id")
|
q.ID = field.NewUint64(table, "id")
|
||||||
q.Sn = field.NewString(table, "sn")
|
q.Sn = field.NewInt64(table, "sn")
|
||||||
q.Question = field.NewString(table, "question")
|
q.Question = field.NewString(table, "question")
|
||||||
q.Options = field.NewString(table, "options")
|
q.Options = field.NewString(table, "options")
|
||||||
q.Answer = field.NewString(table, "answer")
|
q.Answer = field.NewString(table, "answer")
|
||||||
q.Explanation = field.NewString(table, "explanation")
|
q.Explanation = field.NewString(table, "explanation")
|
||||||
q.Difficulty = field.NewInt32(table, "difficulty")
|
q.Difficulty = field.NewInt32(table, "difficulty")
|
||||||
q.CategorySn = field.NewString(table, "category_sn")
|
q.CategorySn = field.NewInt64(table, "category_sn")
|
||||||
q.CreatedAt = field.NewTime(table, "created_at")
|
q.CreatedAt = field.NewTime(table, "created_at")
|
||||||
q.UpdatedAt = field.NewTime(table, "updated_at")
|
q.UpdatedAt = field.NewTime(table, "updated_at")
|
||||||
q.DeletedAt = field.NewField(table, "deleted_at")
|
q.DeletedAt = field.NewField(table, "deleted_at")
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import (
|
|||||||
|
|
||||||
"gorm.io/plugin/dbresolver"
|
"gorm.io/plugin/dbresolver"
|
||||||
|
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/model"
|
"git.hlsq.asia/alex/service-qgdzs/internal/dao/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newRecord(db *gorm.DB, opts ...gen.DOOption) record {
|
func newRecord(db *gorm.DB, opts ...gen.DOOption) record {
|
||||||
@@ -28,9 +28,9 @@ func newRecord(db *gorm.DB, opts ...gen.DOOption) record {
|
|||||||
tableName := _record.recordDo.TableName()
|
tableName := _record.recordDo.TableName()
|
||||||
_record.ALL = field.NewAsterisk(tableName)
|
_record.ALL = field.NewAsterisk(tableName)
|
||||||
_record.ID = field.NewUint64(tableName, "id")
|
_record.ID = field.NewUint64(tableName, "id")
|
||||||
_record.Sn = field.NewString(tableName, "sn")
|
_record.Sn = field.NewInt64(tableName, "sn")
|
||||||
_record.UserSn = field.NewString(tableName, "user_sn")
|
_record.UserSn = field.NewInt64(tableName, "user_sn")
|
||||||
_record.QuestionSn = field.NewString(tableName, "question_sn")
|
_record.QuestionSn = field.NewInt64(tableName, "question_sn")
|
||||||
_record.Answer = field.NewString(tableName, "answer")
|
_record.Answer = field.NewString(tableName, "answer")
|
||||||
_record.IsCorrect = field.NewInt32(tableName, "is_correct")
|
_record.IsCorrect = field.NewInt32(tableName, "is_correct")
|
||||||
_record.CreatedAt = field.NewTime(tableName, "created_at")
|
_record.CreatedAt = field.NewTime(tableName, "created_at")
|
||||||
@@ -47,9 +47,9 @@ type record struct {
|
|||||||
|
|
||||||
ALL field.Asterisk
|
ALL field.Asterisk
|
||||||
ID field.Uint64
|
ID field.Uint64
|
||||||
Sn field.String // 业务唯一编号
|
Sn field.Int64 // 业务唯一编号
|
||||||
UserSn field.String // 用户-唯一编号
|
UserSn field.Int64 // 用户-唯一编号
|
||||||
QuestionSn field.String // 题目-唯一编号
|
QuestionSn field.Int64 // 题目-唯一编号
|
||||||
Answer field.String // 答案
|
Answer field.String // 答案
|
||||||
IsCorrect field.Int32 // 是否正确 0 否 1 是
|
IsCorrect field.Int32 // 是否正确 0 否 1 是
|
||||||
CreatedAt field.Time
|
CreatedAt field.Time
|
||||||
@@ -72,9 +72,9 @@ func (r record) As(alias string) *record {
|
|||||||
func (r *record) updateTableName(table string) *record {
|
func (r *record) updateTableName(table string) *record {
|
||||||
r.ALL = field.NewAsterisk(table)
|
r.ALL = field.NewAsterisk(table)
|
||||||
r.ID = field.NewUint64(table, "id")
|
r.ID = field.NewUint64(table, "id")
|
||||||
r.Sn = field.NewString(table, "sn")
|
r.Sn = field.NewInt64(table, "sn")
|
||||||
r.UserSn = field.NewString(table, "user_sn")
|
r.UserSn = field.NewInt64(table, "user_sn")
|
||||||
r.QuestionSn = field.NewString(table, "question_sn")
|
r.QuestionSn = field.NewInt64(table, "question_sn")
|
||||||
r.Answer = field.NewString(table, "answer")
|
r.Answer = field.NewString(table, "answer")
|
||||||
r.IsCorrect = field.NewInt32(table, "is_correct")
|
r.IsCorrect = field.NewInt32(table, "is_correct")
|
||||||
r.CreatedAt = field.NewTime(table, "created_at")
|
r.CreatedAt = field.NewTime(table, "created_at")
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package repository
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"git.hlsq.asia/mmorpg/service-common/db/redis"
|
"git.hlsq.asia/alex/service-common/db/redis"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/model"
|
"git.hlsq.asia/alex/service-qgdzs/internal/dao/model"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/query"
|
"git.hlsq.asia/alex/service-qgdzs/internal/dao/query"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CategoryDao struct {
|
type CategoryDao struct {
|
||||||
@@ -40,7 +40,7 @@ func (d *CategoryDao) FindAll() ([]*model.Category, error) {
|
|||||||
return find, nil
|
return find, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *CategoryDao) FindNameBySn(sn string) (string, error) {
|
func (d *CategoryDao) FindNameBySn(sn int64) (string, error) {
|
||||||
first, err := d.query.Category.WithContext(d.ctx).
|
first, err := d.query.Category.WithContext(d.ctx).
|
||||||
Select(d.query.Category.Category).
|
Select(d.query.Category.Category).
|
||||||
Where(d.query.Category.Sn.Eq(sn)).
|
Where(d.query.Category.Sn.Eq(sn)).
|
||||||
@@ -51,13 +51,13 @@ func (d *CategoryDao) FindNameBySn(sn string) (string, error) {
|
|||||||
return first.Category, nil
|
return first.Category, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *CategoryDao) FindSnByName(category string) (string, error) {
|
func (d *CategoryDao) FindSnByName(category string) (int64, error) {
|
||||||
first, err := d.query.Category.WithContext(d.ctx).
|
first, err := d.query.Category.WithContext(d.ctx).
|
||||||
Select(d.query.Category.Sn).
|
Select(d.query.Category.Sn).
|
||||||
Where(d.query.Category.Category.Eq(category)).
|
Where(d.query.Category.Category.Eq(category)).
|
||||||
First()
|
First()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return 0, err
|
||||||
}
|
}
|
||||||
return first.Sn, nil
|
return first.Sn, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package repository
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.hlsq.asia/mmorpg/service-common/db/mysql"
|
"git.hlsq.asia/alex/service-common/db/mysql"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/query"
|
"git.hlsq.asia/alex/service-qgdzs/internal/dao/query"
|
||||||
)
|
)
|
||||||
|
|
||||||
var dbName mysql.DBName = "qgdzs_db"
|
var dbName mysql.DBName = "qgdzs_db"
|
||||||
@@ -16,6 +16,6 @@ func Query() *query.Query {
|
|||||||
return query.Use(mysql.GetDB(dbName))
|
return query.Use(mysql.GetDB(dbName))
|
||||||
}
|
}
|
||||||
|
|
||||||
func keyCacheBySn(sn string, tableName string) string {
|
func keyCacheBySn(sn int64, tableName string) string {
|
||||||
return fmt.Sprintf(cacheBySn, tableName, sn)
|
return fmt.Sprintf(cacheBySn, tableName, sn)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ package repository
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"git.hlsq.asia/mmorpg/service-common/db/redis"
|
"git.hlsq.asia/alex/service-common/db/redis"
|
||||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
"git.hlsq.asia/alex/service-common/utils"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/model"
|
"git.hlsq.asia/alex/service-qgdzs/internal/dao/model"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/query"
|
"git.hlsq.asia/alex/service-qgdzs/internal/dao/query"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PointCardDao struct {
|
type PointCardDao struct {
|
||||||
@@ -32,7 +32,7 @@ func (d *PointCardDao) Create(pointCard *model.PointCard) (*model.PointCard, err
|
|||||||
return pointCard, err
|
return pointCard, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *PointCardDao) IncrPointCard(usn string, point int64) error {
|
func (d *PointCardDao) IncrPointCard(usn int64, point int64) error {
|
||||||
info, err := d.query.PointCard.WithContext(d.ctx).
|
info, err := d.query.PointCard.WithContext(d.ctx).
|
||||||
Where(d.query.PointCard.UserSn.Eq(usn)).
|
Where(d.query.PointCard.UserSn.Eq(usn)).
|
||||||
UpdateSimple(d.query.PointCard.Point.Add(point))
|
UpdateSimple(d.query.PointCard.Point.Add(point))
|
||||||
@@ -45,8 +45,9 @@ func (d *PointCardDao) IncrPointCard(usn string, point int64) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *PointCardDao) FindByUserSn(usn string) (*model.PointCard, error) {
|
func (d *PointCardDao) FindPointByUserSn(usn int64) (*model.PointCard, error) {
|
||||||
return d.query.PointCard.WithContext(d.ctx).
|
return d.query.PointCard.WithContext(d.ctx).
|
||||||
|
Select(d.query.PointCard.Point).
|
||||||
Where(d.query.PointCard.UserSn.Eq(usn)).
|
Where(d.query.PointCard.UserSn.Eq(usn)).
|
||||||
First()
|
First()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ package repository
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"git.hlsq.asia/mmorpg/service-common/db/redis"
|
"git.hlsq.asia/alex/service-common/db/redis"
|
||||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
"git.hlsq.asia/alex/service-common/utils"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/model"
|
"git.hlsq.asia/alex/service-qgdzs/internal/dao/model"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/query"
|
"git.hlsq.asia/alex/service-qgdzs/internal/dao/query"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ func (d *PointRecordsDao) CreateAndIncrPointCard(pointRecord *model.PointRecord)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pcd := NewPointCardDao(d.ctx, tx)
|
pcd := NewPointCardDao(d.ctx, tx)
|
||||||
if _, err := pcd.FindByUserSn(pointRecord.UserSn); err != nil {
|
if _, err := pcd.FindPointByUserSn(pointRecord.UserSn); err != nil {
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
_, err = pcd.Create(&model.PointCard{
|
_, err = pcd.Create(&model.PointCard{
|
||||||
UserSn: pointRecord.UserSn,
|
UserSn: pointRecord.UserSn,
|
||||||
@@ -56,3 +56,20 @@ func (d *PointRecordsDao) CreateAndIncrPointCard(pointRecord *model.PointRecord)
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *PointRecordsDao) FindByUSN(usn int64, page, pageSize int) ([]*model.PointRecord, int64, error) {
|
||||||
|
result := make([]*model.PointRecord, 0)
|
||||||
|
count, err := d.query.PointRecord.WithContext(d.ctx).
|
||||||
|
Select(
|
||||||
|
d.query.PointRecord.Source,
|
||||||
|
d.query.PointRecord.Point,
|
||||||
|
d.query.PointRecord.CreatedAt,
|
||||||
|
).
|
||||||
|
Where(d.query.PointRecord.UserSn.Eq(usn)).
|
||||||
|
Order(d.query.PointRecord.CreatedAt.Desc()).
|
||||||
|
ScanByPage(&result, (page-1)*pageSize, pageSize)
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
return result, count, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ package repository
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"git.hlsq.asia/mmorpg/service-common/db/redis"
|
"git.hlsq.asia/alex/service-common/db/redis"
|
||||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
"git.hlsq.asia/alex/service-common/utils"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/model"
|
"git.hlsq.asia/alex/service-qgdzs/internal/dao/model"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/query"
|
"git.hlsq.asia/alex/service-qgdzs/internal/dao/query"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -33,9 +33,9 @@ func (d *QuestionDao) Create(question *model.Question) (*model.Question, error)
|
|||||||
return question, err
|
return question, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *QuestionDao) FindByRandom(categorySn string) (*model.Question, error) {
|
func (d *QuestionDao) FindByRandom(categorySn int64) (*model.Question, error) {
|
||||||
q := d.query.Question.WithContext(d.ctx)
|
q := d.query.Question.WithContext(d.ctx)
|
||||||
if categorySn != "" {
|
if categorySn != 0 {
|
||||||
q = q.Where(d.query.Question.CategorySn.Eq(categorySn))
|
q = q.Where(d.query.Question.CategorySn.Eq(categorySn))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ func (d *QuestionDao) FindByRandom(categorySn string) (*model.Question, error) {
|
|||||||
return first, nil
|
return first, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *QuestionDao) FindBySn(sn string) (*model.Question, error) {
|
func (d *QuestionDao) FindBySn(sn int64) (*model.Question, error) {
|
||||||
if d.cache != nil {
|
if d.cache != nil {
|
||||||
var question model.Question
|
var question model.Question
|
||||||
if ok := d.cache.Get(d.ctx, keyCacheBySn(sn, question.TableName()), &question); ok {
|
if ok := d.cache.Get(d.ctx, keyCacheBySn(sn, question.TableName()), &question); ok {
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ package repository
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"git.hlsq.asia/mmorpg/service-common/db/redis"
|
"git.hlsq.asia/alex/service-common/db/redis"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/model"
|
"git.hlsq.asia/alex/service-qgdzs/internal/dao/model"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/query"
|
"git.hlsq.asia/alex/service-qgdzs/internal/dao/query"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ func (d *RecordDao) Create(record *model.Record) (*model.Record, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RecordItem struct {
|
type RecordItem struct {
|
||||||
QuestionSn string `gorm:"column:question_sn"`
|
QuestionSn int64 `gorm:"column:question_sn"`
|
||||||
Question string `gorm:"column:question"`
|
Question string `gorm:"column:question"`
|
||||||
Difficulty int32 `gorm:"column:difficulty"`
|
Difficulty int32 `gorm:"column:difficulty"`
|
||||||
Category string `gorm:"column:category"`
|
Category string `gorm:"column:category"`
|
||||||
@@ -42,7 +42,7 @@ type RecordItem struct {
|
|||||||
CreatedAt time.Time `gorm:"column:created_at"`
|
CreatedAt time.Time `gorm:"column:created_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *RecordDao) FindByUSN(usn string, page, pageSize int) ([]*RecordItem, int64, error) {
|
func (d *RecordDao) FindByUSN(usn int64, page, pageSize int) ([]*RecordItem, int64, error) {
|
||||||
result := make([]*RecordItem, 0)
|
result := make([]*RecordItem, 0)
|
||||||
count, err := d.query.Record.WithContext(d.ctx).
|
count, err := d.query.Record.WithContext(d.ctx).
|
||||||
Select(
|
Select(
|
||||||
|
|||||||
@@ -1,37 +1,36 @@
|
|||||||
package grpc_server
|
package grpcserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"git.hlsq.asia/mmorpg/service-common/db/kafka"
|
"git.hlsq.asia/alex/service-common/db/kafka"
|
||||||
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
|
"git.hlsq.asia/alex/service-common/proto/rs/rspb"
|
||||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
"git.hlsq.asia/alex/service-common/utils"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/repository"
|
"git.hlsq.asia/alex/service-qgdzs/internal/dao/repository"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/timer"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 玩法 - 类目答题
|
// 玩法 - 类目答题
|
||||||
|
|
||||||
// GetAllCategory 获取所有类目
|
// GetAllCategory 获取所有类目
|
||||||
func (s *Server) GetAllCategory(ctx context.Context, req *grpc_pb.GetAllCategoryReq) (*grpc_pb.GetAllCategoryResp, error) {
|
func (s *Server) GetAllCategory(ctx context.Context, req *rspb.GetAllCategoryReq) (*rspb.GetAllCategoryResp, error) {
|
||||||
categoryList, err := repository.NewCategoryDao(ctx, s.query).FindAll()
|
categoryList, err := repository.NewCategoryDao(ctx, s.query).FindAll()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, utils.ErrorsWrap(err)
|
return nil, utils.ErrorsWrap(err)
|
||||||
}
|
}
|
||||||
categories := make([]*grpc_pb.GetAllCategoryItem, 0)
|
categories := make([]*rspb.GetAllCategoryItem, 0)
|
||||||
for _, category := range categoryList {
|
for _, category := range categoryList {
|
||||||
categories = append(categories, &grpc_pb.GetAllCategoryItem{
|
categories = append(categories, &rspb.GetAllCategoryItem{
|
||||||
Sn: category.Sn,
|
Sn: category.Sn,
|
||||||
Category: category.Category,
|
Category: category.Category,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return &grpc_pb.GetAllCategoryResp{
|
return &rspb.GetAllCategoryResp{
|
||||||
Categories: categories,
|
Categories: categories,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CategoryGetQuestion 获取题目
|
// CategoryGetQuestion 获取题目
|
||||||
func (s *Server) CategoryGetQuestion(ctx context.Context, req *grpc_pb.CategoryGetQuestionReq) (*grpc_pb.CategoryGetQuestionResp, error) {
|
func (s *Server) CategoryGetQuestion(ctx context.Context, req *rspb.CategoryGetQuestionReq) (*rspb.CategoryGetQuestionResp, error) {
|
||||||
question, err := repository.NewQuestionDao(ctx, s.query).FindByRandom(req.CategorySn)
|
question, err := repository.NewQuestionDao(ctx, s.query).FindByRandom(req.CategorySn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, utils.ErrorsWrap(err)
|
return nil, utils.ErrorsWrap(err)
|
||||||
@@ -41,7 +40,7 @@ func (s *Server) CategoryGetQuestion(ctx context.Context, req *grpc_pb.CategoryG
|
|||||||
return nil, utils.ErrorsWrapF(err, "data: %v", question.Options)
|
return nil, utils.ErrorsWrapF(err, "data: %v", question.Options)
|
||||||
}
|
}
|
||||||
category, _ := repository.NewCategoryDao(ctx, s.query).FindNameBySn(question.CategorySn)
|
category, _ := repository.NewCategoryDao(ctx, s.query).FindNameBySn(question.CategorySn)
|
||||||
return &grpc_pb.CategoryGetQuestionResp{
|
return &rspb.CategoryGetQuestionResp{
|
||||||
Sn: question.Sn,
|
Sn: question.Sn,
|
||||||
Question: question.Question,
|
Question: question.Question,
|
||||||
Options: options,
|
Options: options,
|
||||||
@@ -51,7 +50,7 @@ func (s *Server) CategoryGetQuestion(ctx context.Context, req *grpc_pb.CategoryG
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CategoryAnswerQuestion 回答题目
|
// CategoryAnswerQuestion 回答题目
|
||||||
func (s *Server) CategoryAnswerQuestion(ctx context.Context, req *grpc_pb.CategoryAnswerQuestionReq) (*grpc_pb.CategoryAnswerQuestionResp, error) {
|
func (s *Server) CategoryAnswerQuestion(ctx context.Context, req *rspb.CategoryAnswerQuestionReq) (*rspb.CategoryAnswerQuestionResp, error) {
|
||||||
utils.ShouldBindUsn(ctx, &req.USN)
|
utils.ShouldBindUsn(ctx, &req.USN)
|
||||||
|
|
||||||
question, err := repository.NewQuestionDao(ctx, s.query).FindBySn(req.Sn)
|
question, err := repository.NewQuestionDao(ctx, s.query).FindBySn(req.Sn)
|
||||||
@@ -63,16 +62,26 @@ func (s *Server) CategoryAnswerQuestion(ctx context.Context, req *grpc_pb.Catego
|
|||||||
return nil, utils.ErrorsWrapF(err, "data: %v", question.Options)
|
return nil, utils.ErrorsWrapF(err, "data: %v", question.Options)
|
||||||
}
|
}
|
||||||
// 保存答题记录
|
// 保存答题记录
|
||||||
if req.USN != "" {
|
if req.USN != 0 {
|
||||||
kafka.NewProducer().Produce(ctx, &timer.TopicQuestionAnswer{
|
kafka.NewProducer().Produce(ctx, &kafka.TopicQuestionAnswer{
|
||||||
MessageSn: utils.SnowflakeInstance().Generate().String(),
|
MessageSn: utils.SnowflakeInstance().Generate().Int64(),
|
||||||
USN: req.USN,
|
USN: req.USN,
|
||||||
QuestionSn: question.Sn,
|
QuestionSn: question.Sn,
|
||||||
QuestionAnswer: question.Answer,
|
QuestionAnswer: question.Answer,
|
||||||
Answer: req.Answer,
|
Answer: req.Answer,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 类目答题正确给5分,错误不得分
|
||||||
|
if req.Answer == question.Answer {
|
||||||
|
kafka.NewProducer().Produce(ctx, &kafka.TopicAddPoint{
|
||||||
|
MessageSn: utils.SnowflakeInstance().Generate().Int64(),
|
||||||
|
Source: kafka.AddPointSourceCategory,
|
||||||
|
USN: req.USN,
|
||||||
|
Point: 5,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
return &grpc_pb.CategoryAnswerQuestionResp{
|
}
|
||||||
|
return &rspb.CategoryAnswerQuestionResp{
|
||||||
Answer: question.Answer,
|
Answer: question.Answer,
|
||||||
Explanation: question.Explanation,
|
Explanation: question.Explanation,
|
||||||
}, nil
|
}, nil
|
||||||
30
internal/grpcserver/server_custom.go
Normal file
30
internal/grpcserver/server_custom.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package grpcserver
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"git.hlsq.asia/alex/service-common/proto/rs/rspb"
|
||||||
|
"git.hlsq.asia/alex/service-common/utils"
|
||||||
|
"git.hlsq.asia/alex/service-qgdzs/internal/ai"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (s *Server) CustomAnswerQuestion(ctx context.Context, req *rspb.CustomAnswerQuestionReq) (*rspb.CustomAnswerQuestionResp, error) {
|
||||||
|
answer := ""
|
||||||
|
err := ai.NewAIClient(false, "", 0.9).
|
||||||
|
RequestAI(
|
||||||
|
[]string{
|
||||||
|
fmt.Sprintf(req.Question),
|
||||||
|
},
|
||||||
|
func(content string, i int) error {
|
||||||
|
if i == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
answer = content
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, utils.ErrorsWrap(err)
|
||||||
|
}
|
||||||
|
return &rspb.CustomAnswerQuestionResp{Answer: answer}, nil
|
||||||
|
}
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
package grpc_server
|
package grpcserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.hlsq.asia/mmorpg/service-common/config"
|
"git.hlsq.asia/alex/service-common/config"
|
||||||
"git.hlsq.asia/mmorpg/service-common/discover/common"
|
"git.hlsq.asia/alex/service-common/discover/common"
|
||||||
"git.hlsq.asia/mmorpg/service-common/net/grpc/service"
|
"git.hlsq.asia/alex/service-common/net/grpc/service"
|
||||||
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
|
"git.hlsq.asia/alex/service-common/proto/rs/rspb"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/query"
|
"git.hlsq.asia/alex/service-qgdzs/internal/dao/query"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/repository"
|
"git.hlsq.asia/alex/service-qgdzs/internal/dao/repository"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
grpc_pb.UnimplementedQgdzsServer
|
rspb.UnimplementedQgdzsServer
|
||||||
service.Base
|
service.Base
|
||||||
query *query.Query
|
query *query.Query
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ func (s *Server) OnCustomGrpcServerOption() []grpc.ServerOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) OnInit(serve *grpc.Server) {
|
func (s *Server) OnInit(serve *grpc.Server) {
|
||||||
grpc_pb.RegisterQgdzsServer(serve, s)
|
rspb.RegisterQgdzsServer(serve, s)
|
||||||
s.query = repository.Query()
|
s.query = repository.Query()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package grpc_server
|
package grpcserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"git.hlsq.asia/mmorpg/service-common/db/redis"
|
"git.hlsq.asia/alex/service-common/db/redis"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 答题总数排行榜
|
// 答题总数排行榜
|
||||||
48
internal/grpcserver/server_point.go
Normal file
48
internal/grpcserver/server_point.go
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package grpcserver
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"git.hlsq.asia/alex/service-common/net/http/httpresp"
|
||||||
|
"git.hlsq.asia/alex/service-common/proto/rs/rspb"
|
||||||
|
"git.hlsq.asia/alex/service-common/utils"
|
||||||
|
"git.hlsq.asia/alex/service-qgdzs/internal/dao/repository"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 模块 - 学识分
|
||||||
|
|
||||||
|
// GetPointRecord 获取学识分获取记录
|
||||||
|
func (s *Server) GetPointRecord(ctx context.Context, req *rspb.GetPointRecordReq) (*rspb.GetPointRecordResp, error) {
|
||||||
|
if !utils.ShouldBindUsn(ctx, &req.USN) {
|
||||||
|
return nil, httpresp.ParamError
|
||||||
|
}
|
||||||
|
records, count, err := repository.NewPointRecordsDao(ctx, s.query).FindByUSN(req.USN, int(req.Page), int(req.PageSize))
|
||||||
|
if err != nil {
|
||||||
|
return nil, utils.ErrorsWrap(err)
|
||||||
|
}
|
||||||
|
resp := make([]*rspb.GetPointRecordItem, 0)
|
||||||
|
for _, record := range records {
|
||||||
|
resp = append(resp, &rspb.GetPointRecordItem{
|
||||||
|
Source: record.Source,
|
||||||
|
Point: record.Point,
|
||||||
|
CreateTime: record.CreatedAt.Unix(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return &rspb.GetPointRecordResp{
|
||||||
|
Count: int32(count),
|
||||||
|
Records: resp,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPoint 获取学识分
|
||||||
|
func (s *Server) GetPoint(ctx context.Context, req *rspb.GetPointReq) (*rspb.GetPointResp, error) {
|
||||||
|
if !utils.ShouldBindUsn(ctx, &req.USN) {
|
||||||
|
return nil, httpresp.ParamError
|
||||||
|
}
|
||||||
|
pointCard, err := repository.NewPointCardDao(ctx, s.query).FindPointByUserSn(req.USN)
|
||||||
|
if err != nil {
|
||||||
|
return nil, utils.ErrorsWrap(err)
|
||||||
|
}
|
||||||
|
return &rspb.GetPointResp{
|
||||||
|
Point: pointCard.Point,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
@@ -1,17 +1,17 @@
|
|||||||
package grpc_server
|
package grpcserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.hlsq.asia/mmorpg/service-common/db/redis"
|
"git.hlsq.asia/alex/service-common/db/redis"
|
||||||
"git.hlsq.asia/mmorpg/service-common/log"
|
"git.hlsq.asia/alex/service-common/log"
|
||||||
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
|
"git.hlsq.asia/alex/service-common/proto/rs/rspb"
|
||||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
"git.hlsq.asia/alex/service-common/utils"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/ai"
|
"git.hlsq.asia/alex/service-qgdzs/internal/ai"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/model"
|
"git.hlsq.asia/alex/service-qgdzs/internal/dao/model"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/repository"
|
"git.hlsq.asia/alex/service-qgdzs/internal/dao/repository"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -53,7 +53,7 @@ type Question struct {
|
|||||||
Difficulty int32 `json:"difficulty"` // 难度分
|
Difficulty int32 `json:"difficulty"` // 难度分
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) GenerateQuestion(ctx context.Context, req *grpc_pb.GenerateQuestionReq) (*grpc_pb.GenerateQuestionResp, error) {
|
func (s *Server) GenerateQuestion(ctx context.Context, req *rspb.GenerateQuestionReq) (*rspb.GenerateQuestionResp, error) {
|
||||||
categoryDao := repository.NewCategoryDao(ctx, s.query, redis.GetCacheClient())
|
categoryDao := repository.NewCategoryDao(ctx, s.query, redis.GetCacheClient())
|
||||||
category, err := categoryDao.FindAll()
|
category, err := categoryDao.FindAll()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1,20 +1,19 @@
|
|||||||
package grpc_server
|
package grpcserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"git.hlsq.asia/mmorpg/service-common/db/kafka"
|
"git.hlsq.asia/alex/service-common/db/kafka"
|
||||||
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
|
"git.hlsq.asia/alex/service-common/proto/rs/rspb"
|
||||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
"git.hlsq.asia/alex/service-common/utils"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/repository"
|
"git.hlsq.asia/alex/service-qgdzs/internal/dao/repository"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/timer"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 玩法 - 随机答题
|
// 玩法 - 随机答题
|
||||||
|
|
||||||
// QuicklyGetQuestion 获取题目
|
// QuicklyGetQuestion 获取题目
|
||||||
func (s *Server) QuicklyGetQuestion(ctx context.Context, req *grpc_pb.QuicklyGetQuestionReq) (*grpc_pb.QuicklyGetQuestionResp, error) {
|
func (s *Server) QuicklyGetQuestion(ctx context.Context, req *rspb.QuicklyGetQuestionReq) (*rspb.QuicklyGetQuestionResp, error) {
|
||||||
question, err := repository.NewQuestionDao(ctx, s.query).FindByRandom("")
|
question, err := repository.NewQuestionDao(ctx, s.query).FindByRandom(0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, utils.ErrorsWrap(err)
|
return nil, utils.ErrorsWrap(err)
|
||||||
}
|
}
|
||||||
@@ -23,7 +22,7 @@ func (s *Server) QuicklyGetQuestion(ctx context.Context, req *grpc_pb.QuicklyGet
|
|||||||
return nil, utils.ErrorsWrapF(err, "data: %v", question.Options)
|
return nil, utils.ErrorsWrapF(err, "data: %v", question.Options)
|
||||||
}
|
}
|
||||||
category, _ := repository.NewCategoryDao(ctx, s.query).FindNameBySn(question.CategorySn)
|
category, _ := repository.NewCategoryDao(ctx, s.query).FindNameBySn(question.CategorySn)
|
||||||
return &grpc_pb.QuicklyGetQuestionResp{
|
return &rspb.QuicklyGetQuestionResp{
|
||||||
Sn: question.Sn,
|
Sn: question.Sn,
|
||||||
Question: question.Question,
|
Question: question.Question,
|
||||||
Options: options,
|
Options: options,
|
||||||
@@ -33,7 +32,7 @@ func (s *Server) QuicklyGetQuestion(ctx context.Context, req *grpc_pb.QuicklyGet
|
|||||||
}
|
}
|
||||||
|
|
||||||
// QuicklyAnswerQuestion 回答题目
|
// QuicklyAnswerQuestion 回答题目
|
||||||
func (s *Server) QuicklyAnswerQuestion(ctx context.Context, req *grpc_pb.QuicklyAnswerQuestionReq) (*grpc_pb.QuicklyAnswerQuestionResp, error) {
|
func (s *Server) QuicklyAnswerQuestion(ctx context.Context, req *rspb.QuicklyAnswerQuestionReq) (*rspb.QuicklyAnswerQuestionResp, error) {
|
||||||
utils.ShouldBindUsn(ctx, &req.USN)
|
utils.ShouldBindUsn(ctx, &req.USN)
|
||||||
|
|
||||||
question, err := repository.NewQuestionDao(ctx, s.query).FindBySn(req.Sn)
|
question, err := repository.NewQuestionDao(ctx, s.query).FindBySn(req.Sn)
|
||||||
@@ -45,16 +44,16 @@ func (s *Server) QuicklyAnswerQuestion(ctx context.Context, req *grpc_pb.Quickly
|
|||||||
return nil, utils.ErrorsWrapF(err, "data: %v", question.Options)
|
return nil, utils.ErrorsWrapF(err, "data: %v", question.Options)
|
||||||
}
|
}
|
||||||
// 保存答题记录
|
// 保存答题记录
|
||||||
if req.USN != "" {
|
if req.USN != 0 {
|
||||||
kafka.NewProducer().Produce(ctx, &timer.TopicQuestionAnswer{
|
kafka.NewProducer().Produce(ctx, &kafka.TopicQuestionAnswer{
|
||||||
MessageSn: utils.SnowflakeInstance().Generate().String(),
|
MessageSn: utils.SnowflakeInstance().Generate().Int64(),
|
||||||
USN: req.USN,
|
USN: req.USN,
|
||||||
QuestionSn: question.Sn,
|
QuestionSn: question.Sn,
|
||||||
QuestionAnswer: question.Answer,
|
QuestionAnswer: question.Answer,
|
||||||
Answer: req.Answer,
|
Answer: req.Answer,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return &grpc_pb.QuicklyAnswerQuestionResp{
|
return &rspb.QuicklyAnswerQuestionResp{
|
||||||
Answer: question.Answer,
|
Answer: question.Answer,
|
||||||
Explanation: question.Explanation,
|
Explanation: question.Explanation,
|
||||||
}, nil
|
}, nil
|
||||||
@@ -1,20 +1,19 @@
|
|||||||
package grpc_server
|
package grpcserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"git.hlsq.asia/mmorpg/service-common/db/kafka"
|
"git.hlsq.asia/alex/service-common/db/kafka"
|
||||||
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
|
"git.hlsq.asia/alex/service-common/proto/rs/rspb"
|
||||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
"git.hlsq.asia/alex/service-common/utils"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/repository"
|
"git.hlsq.asia/alex/service-qgdzs/internal/dao/repository"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/timer"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 玩法 - 随机答题
|
// 玩法 - 随机答题
|
||||||
|
|
||||||
// RandomGetQuestion 获取题目
|
// RandomGetQuestion 获取题目
|
||||||
func (s *Server) RandomGetQuestion(ctx context.Context, req *grpc_pb.RandomGetQuestionReq) (*grpc_pb.RandomGetQuestionResp, error) {
|
func (s *Server) RandomGetQuestion(ctx context.Context, req *rspb.RandomGetQuestionReq) (*rspb.RandomGetQuestionResp, error) {
|
||||||
question, err := repository.NewQuestionDao(ctx, s.query).FindByRandom("")
|
question, err := repository.NewQuestionDao(ctx, s.query).FindByRandom(0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, utils.ErrorsWrap(err)
|
return nil, utils.ErrorsWrap(err)
|
||||||
}
|
}
|
||||||
@@ -23,7 +22,7 @@ func (s *Server) RandomGetQuestion(ctx context.Context, req *grpc_pb.RandomGetQu
|
|||||||
return nil, utils.ErrorsWrapF(err, "data: %v", question.Options)
|
return nil, utils.ErrorsWrapF(err, "data: %v", question.Options)
|
||||||
}
|
}
|
||||||
category, _ := repository.NewCategoryDao(ctx, s.query).FindNameBySn(question.CategorySn)
|
category, _ := repository.NewCategoryDao(ctx, s.query).FindNameBySn(question.CategorySn)
|
||||||
return &grpc_pb.RandomGetQuestionResp{
|
return &rspb.RandomGetQuestionResp{
|
||||||
Sn: question.Sn,
|
Sn: question.Sn,
|
||||||
Question: question.Question,
|
Question: question.Question,
|
||||||
Options: options,
|
Options: options,
|
||||||
@@ -33,7 +32,7 @@ func (s *Server) RandomGetQuestion(ctx context.Context, req *grpc_pb.RandomGetQu
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RandomAnswerQuestion 回答题目
|
// RandomAnswerQuestion 回答题目
|
||||||
func (s *Server) RandomAnswerQuestion(ctx context.Context, req *grpc_pb.RandomAnswerQuestionReq) (*grpc_pb.RandomAnswerQuestionResp, error) {
|
func (s *Server) RandomAnswerQuestion(ctx context.Context, req *rspb.RandomAnswerQuestionReq) (*rspb.RandomAnswerQuestionResp, error) {
|
||||||
utils.ShouldBindUsn(ctx, &req.USN)
|
utils.ShouldBindUsn(ctx, &req.USN)
|
||||||
|
|
||||||
question, err := repository.NewQuestionDao(ctx, s.query).FindBySn(req.Sn)
|
question, err := repository.NewQuestionDao(ctx, s.query).FindBySn(req.Sn)
|
||||||
@@ -45,9 +44,9 @@ func (s *Server) RandomAnswerQuestion(ctx context.Context, req *grpc_pb.RandomAn
|
|||||||
return nil, utils.ErrorsWrapF(err, "data: %v", question.Options)
|
return nil, utils.ErrorsWrapF(err, "data: %v", question.Options)
|
||||||
}
|
}
|
||||||
// 保存答题记录
|
// 保存答题记录
|
||||||
if req.USN != "" {
|
if req.USN != 0 {
|
||||||
kafka.NewProducer().Produce(ctx, &timer.TopicQuestionAnswer{
|
kafka.NewProducer().Produce(ctx, &kafka.TopicQuestionAnswer{
|
||||||
MessageSn: utils.SnowflakeInstance().Generate().String(),
|
MessageSn: utils.SnowflakeInstance().Generate().Int64(),
|
||||||
USN: req.USN,
|
USN: req.USN,
|
||||||
QuestionSn: question.Sn,
|
QuestionSn: question.Sn,
|
||||||
QuestionAnswer: question.Answer,
|
QuestionAnswer: question.Answer,
|
||||||
@@ -56,15 +55,15 @@ func (s *Server) RandomAnswerQuestion(ctx context.Context, req *grpc_pb.RandomAn
|
|||||||
|
|
||||||
// 随机答题正确给10分,错误不得分
|
// 随机答题正确给10分,错误不得分
|
||||||
if req.Answer == question.Answer {
|
if req.Answer == question.Answer {
|
||||||
kafka.NewProducer().Produce(ctx, &timer.TopicAddPoint{
|
kafka.NewProducer().Produce(ctx, &kafka.TopicAddPoint{
|
||||||
MessageSn: utils.SnowflakeInstance().Generate().String(),
|
MessageSn: utils.SnowflakeInstance().Generate().Int64(),
|
||||||
Source: timer.AddPointSourceRandom,
|
Source: kafka.AddPointSourceRandom,
|
||||||
USN: req.USN,
|
USN: req.USN,
|
||||||
Point: 10,
|
Point: 10,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &grpc_pb.RandomAnswerQuestionResp{
|
return &rspb.RandomAnswerQuestionResp{
|
||||||
Answer: question.Answer,
|
Answer: question.Answer,
|
||||||
Explanation: question.Explanation,
|
Explanation: question.Explanation,
|
||||||
}, nil
|
}, nil
|
||||||
@@ -1,28 +1,28 @@
|
|||||||
package grpc_server
|
package grpcserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"git.hlsq.asia/mmorpg/service-common/net/http/http_resp"
|
"git.hlsq.asia/alex/service-common/net/http/httpresp"
|
||||||
"git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb"
|
"git.hlsq.asia/alex/service-common/proto/rs/rspb"
|
||||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
"git.hlsq.asia/alex/service-common/utils"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/repository"
|
"git.hlsq.asia/alex/service-qgdzs/internal/dao/repository"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 模块 - 答题记录
|
// 模块 - 答题记录
|
||||||
|
|
||||||
// GetRecord 获取答题记录
|
// GetRecord 获取答题记录
|
||||||
func (s *Server) GetRecord(ctx context.Context, req *grpc_pb.GetRecordReq) (*grpc_pb.GetRecordResp, error) {
|
func (s *Server) GetRecord(ctx context.Context, req *rspb.GetRecordReq) (*rspb.GetRecordResp, error) {
|
||||||
if !utils.ShouldBindUsn(ctx, &req.USN) {
|
if !utils.ShouldBindUsn(ctx, &req.USN) {
|
||||||
return nil, http_resp.ParamError
|
return nil, httpresp.ParamError
|
||||||
}
|
}
|
||||||
records, count, err := repository.NewRecordDao(ctx, s.query).FindByUSN(req.USN, int(req.Page), int(req.PageSize))
|
records, count, err := repository.NewRecordDao(ctx, s.query).FindByUSN(req.USN, int(req.Page), int(req.PageSize))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, utils.ErrorsWrap(err)
|
return nil, utils.ErrorsWrap(err)
|
||||||
}
|
}
|
||||||
resp := make([]*grpc_pb.GetRecordItem, 0)
|
resp := make([]*rspb.GetRecordItem, 0)
|
||||||
for _, record := range records {
|
for _, record := range records {
|
||||||
resp = append(resp, &grpc_pb.GetRecordItem{
|
resp = append(resp, &rspb.GetRecordItem{
|
||||||
QuestionSn: record.QuestionSn,
|
QuestionSn: record.QuestionSn,
|
||||||
Question: record.Question,
|
Question: record.Question,
|
||||||
Difficulty: record.Difficulty,
|
Difficulty: record.Difficulty,
|
||||||
@@ -32,14 +32,14 @@ func (s *Server) GetRecord(ctx context.Context, req *grpc_pb.GetRecordReq) (*grp
|
|||||||
CreateTime: record.CreatedAt.Unix(),
|
CreateTime: record.CreatedAt.Unix(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return &grpc_pb.GetRecordResp{
|
return &rspb.GetRecordResp{
|
||||||
Count: int32(count),
|
Count: int32(count),
|
||||||
Records: resp,
|
Records: resp,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetQuestionInfo 获取具体的题目
|
// GetQuestionInfo 获取具体的题目
|
||||||
func (s *Server) GetQuestionInfo(ctx context.Context, req *grpc_pb.GetQuestionInfoReq) (*grpc_pb.GetQuestionInfoResp, error) {
|
func (s *Server) GetQuestionInfo(ctx context.Context, req *rspb.GetQuestionInfoReq) (*rspb.GetQuestionInfoResp, error) {
|
||||||
question, err := repository.NewQuestionDao(ctx, s.query).FindBySn(req.QuestionSn)
|
question, err := repository.NewQuestionDao(ctx, s.query).FindBySn(req.QuestionSn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, utils.ErrorsWrap(err)
|
return nil, utils.ErrorsWrap(err)
|
||||||
@@ -49,7 +49,7 @@ func (s *Server) GetQuestionInfo(ctx context.Context, req *grpc_pb.GetQuestionIn
|
|||||||
return nil, utils.ErrorsWrapF(err, "data: %v", question.Options)
|
return nil, utils.ErrorsWrapF(err, "data: %v", question.Options)
|
||||||
}
|
}
|
||||||
category, _ := repository.NewCategoryDao(ctx, s.query).FindNameBySn(question.CategorySn)
|
category, _ := repository.NewCategoryDao(ctx, s.query).FindNameBySn(question.CategorySn)
|
||||||
return &grpc_pb.GetQuestionInfoResp{
|
return &rspb.GetQuestionInfoResp{
|
||||||
Question: question.Question,
|
Question: question.Question,
|
||||||
Options: options,
|
Options: options,
|
||||||
Category: category,
|
Category: category,
|
||||||
@@ -3,11 +3,11 @@ package timer
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"git.hlsq.asia/mmorpg/service-common/db/kafka"
|
"git.hlsq.asia/alex/service-common/db/kafka"
|
||||||
"git.hlsq.asia/mmorpg/service-common/log"
|
"git.hlsq.asia/alex/service-common/log"
|
||||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
"git.hlsq.asia/alex/service-common/utils"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/model"
|
"git.hlsq.asia/alex/service-qgdzs/internal/dao/model"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/repository"
|
"git.hlsq.asia/alex/service-qgdzs/internal/dao/repository"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,20 +20,12 @@ func startConsumer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TopicQuestionAnswer struct {
|
type TopicQuestionAnswer struct {
|
||||||
MessageSn string `json:"messageSn"`
|
kafka.TopicQuestionAnswer
|
||||||
USN string `json:"usn"`
|
|
||||||
QuestionSn string `json:"questionSn"`
|
|
||||||
QuestionAnswer string `json:"questionAnswer"`
|
|
||||||
Answer string `json:"answer"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *TopicQuestionAnswer) Name() string {
|
|
||||||
return "qgdzs.question.answer"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TopicQuestionAnswer) OnMessage(ctx context.Context) error {
|
func (t *TopicQuestionAnswer) OnMessage(ctx context.Context) error {
|
||||||
log.Infof("Kafka consume topic: %v: %#+v", t.Name(), t)
|
log.Infof("Kafka consume topic: %v: %#+v", t.Name(), t)
|
||||||
if t.USN == "" || t.QuestionSn == "" {
|
if t.USN == 0 || t.QuestionSn == 0 {
|
||||||
return utils.ErrorsWrap(errors.New("invalid data"))
|
return utils.ErrorsWrap(errors.New("invalid data"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,28 +52,12 @@ func (t *TopicQuestionAnswer) OnMessage(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TopicAddPoint struct {
|
type TopicAddPoint struct {
|
||||||
MessageSn string `json:"messageSn"`
|
kafka.TopicAddPoint
|
||||||
Source AddPointSource `json:"source"`
|
|
||||||
USN string `json:"usn"`
|
|
||||||
Point int64 `json:"point"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AddPointSource int32
|
|
||||||
|
|
||||||
const (
|
|
||||||
AddPointSourceUnKnown = 0
|
|
||||||
AddPointSourceRandom = 1
|
|
||||||
AddPointSourceCategory = 2
|
|
||||||
AddPointSourceQuickly = 3
|
|
||||||
)
|
|
||||||
|
|
||||||
func (t *TopicAddPoint) Name() string {
|
|
||||||
return "qgdzs.user.point"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TopicAddPoint) OnMessage(ctx context.Context) error {
|
func (t *TopicAddPoint) OnMessage(ctx context.Context) error {
|
||||||
log.Infof("Kafka consume topic: %v: %#+v", t.Name(), t)
|
log.Infof("Kafka consume topic: %v: %#+v", t.Name(), t)
|
||||||
if t.USN == "" || t.Point == 0 {
|
if t.USN == 0 || t.Point == 0 {
|
||||||
return utils.ErrorsWrap(errors.New("invalid data"))
|
return utils.ErrorsWrap(errors.New("invalid data"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
6
main.go
6
main.go
@@ -2,12 +2,16 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/app"
|
"git.hlsq.asia/alex/service-qgdzs/app"
|
||||||
|
"git.hlsq.asia/alex/service-qgdzs/config"
|
||||||
"github.com/judwhite/go-svc"
|
"github.com/judwhite/go-svc"
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
if err := config.LoadConfig(); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
if err := svc.Run(&app.Program{}, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL); err != nil {
|
if err := svc.Run(&app.Program{}, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user