diff --git a/go.mod b/go.mod index e8f9d06..849d34c 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.hlsq.asia/mmorpg/service-qgdzs go 1.24.0 require ( - git.hlsq.asia/mmorpg/service-common v0.0.0-20260130025300-427fca7ed19f + git.hlsq.asia/mmorpg/service-common v0.0.0-20260130035320-5dc5391b07ed github.com/judwhite/go-svc v1.2.1 github.com/robfig/cron/v3 v3.0.1 google.golang.org/grpc v1.77.0 diff --git a/go.sum b/go.sum index dcd759a..423e90f 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= 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/mmorpg/service-common v0.0.0-20260130025300-427fca7ed19f/go.mod h1:mMhZcumphj6gaVTppVYsMTkd+5HupmQgAc53Pd4MH9I= +git.hlsq.asia/mmorpg/service-common v0.0.0-20260130035320-5dc5391b07ed h1:O08p0egfekFqQSnc4sfEJUTI5dGiEyiDRNW/VYa/Ce4= +git.hlsq.asia/mmorpg/service-common v0.0.0-20260130035320-5dc5391b07ed/go.mod h1:mMhZcumphj6gaVTppVYsMTkd+5HupmQgAc53Pd4MH9I= github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0= github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/IBM/sarama v1.46.3 h1:njRsX6jNlnR+ClJ8XmkO+CM4unbrNr/2vB5KK6UA+IE= diff --git a/internal/dao/model/categories.gen.go b/internal/dao/model/categories.gen.go index 826de21..a9b4f0b 100644 --- a/internal/dao/model/categories.gen.go +++ b/internal/dao/model/categories.gen.go @@ -16,7 +16,7 @@ const TableNameCategory = "categories" // Category mapped from table type Category struct { 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"` // 分类 CreatedAt time.Time `gorm:"column:created_at;not null" json:"created_at"` UpdatedAt time.Time `gorm:"column:updated_at;not null" json:"updated_at"` @@ -30,8 +30,8 @@ func (*Category) TableName() string { // Auto sn func (m *Category) BeforeCreate(_ *gorm.DB) error { - if m.Sn == "" { - m.Sn = utils.SnowflakeInstance().Generate().String() + if m.Sn == 0 { + m.Sn = utils.SnowflakeInstance().Generate().Int64() } return nil } diff --git a/internal/dao/model/point_card.gen.go b/internal/dao/model/point_card.gen.go index 96dd357..a61f381 100644 --- a/internal/dao/model/point_card.gen.go +++ b/internal/dao/model/point_card.gen.go @@ -16,8 +16,8 @@ const TableNamePointCard = "point_card" // PointCard mapped from table type PointCard struct { ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"` - Sn string `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号 - UserSn string `gorm:"column:user_sn;not null;comment:用户-唯一编号" json:"user_sn"` // 用户-唯一编号 + Sn int64 `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号 + UserSn int64 `gorm:"column:user_sn;not null;comment:用户-唯一编号" json:"user_sn"` // 用户-唯一编号 Point int64 `gorm:"column:point;not null;comment:积分" json:"point"` // 积分 CreatedAt time.Time `gorm:"column:created_at;not null" json:"created_at"` UpdatedAt time.Time `gorm:"column:updated_at;not null" json:"updated_at"` @@ -31,8 +31,8 @@ func (*PointCard) TableName() string { // Auto sn func (m *PointCard) BeforeCreate(_ *gorm.DB) error { - if m.Sn == "" { - m.Sn = utils.SnowflakeInstance().Generate().String() + if m.Sn == 0 { + m.Sn = utils.SnowflakeInstance().Generate().Int64() } return nil } diff --git a/internal/dao/model/point_records.gen.go b/internal/dao/model/point_records.gen.go index 08ca56b..c191a6d 100644 --- a/internal/dao/model/point_records.gen.go +++ b/internal/dao/model/point_records.gen.go @@ -16,8 +16,8 @@ const TableNamePointRecord = "point_records" // PointRecord mapped from table type PointRecord struct { ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"` - Sn string `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号 - UserSn string `gorm:"column:user_sn;not null;comment:用户-唯一编号" json:"user_sn"` // 用户-唯一编号 + Sn int64 `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号 + UserSn int64 `gorm:"column:user_sn;not null;comment:用户-唯一编号" json:"user_sn"` // 用户-唯一编号 /* 来源: 0. 未知 @@ -39,8 +39,8 @@ func (*PointRecord) TableName() string { // Auto sn func (m *PointRecord) BeforeCreate(_ *gorm.DB) error { - if m.Sn == "" { - m.Sn = utils.SnowflakeInstance().Generate().String() + if m.Sn == 0 { + m.Sn = utils.SnowflakeInstance().Generate().Int64() } return nil } diff --git a/internal/dao/model/questions.gen.go b/internal/dao/model/questions.gen.go index 41da87f..0430876 100644 --- a/internal/dao/model/questions.gen.go +++ b/internal/dao/model/questions.gen.go @@ -16,13 +16,13 @@ const TableNameQuestion = "questions" // Question mapped from table type Question struct { 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"` // 题干 Options string `gorm:"column:options;not null;comment:选项" json:"options"` // 选项 Answer string `gorm:"column:answer;not null;comment:答案" json:"answer"` // 答案 Explanation string `gorm:"column:explanation;not null;comment:解析" json:"explanation"` // 解析 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"` UpdatedAt time.Time `gorm:"column:updated_at;not null" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at" json:"deleted_at"` @@ -35,8 +35,8 @@ func (*Question) TableName() string { // Auto sn func (m *Question) BeforeCreate(_ *gorm.DB) error { - if m.Sn == "" { - m.Sn = utils.SnowflakeInstance().Generate().String() + if m.Sn == 0 { + m.Sn = utils.SnowflakeInstance().Generate().Int64() } return nil } diff --git a/internal/dao/model/records.gen.go b/internal/dao/model/records.gen.go index f928139..9ace80f 100644 --- a/internal/dao/model/records.gen.go +++ b/internal/dao/model/records.gen.go @@ -16,9 +16,9 @@ const TableNameRecord = "records" // Record mapped from table type Record struct { ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"` - Sn string `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号 - UserSn string `gorm:"column:user_sn;not null;comment:用户-唯一编号" json:"user_sn"` // 用户-唯一编号 - QuestionSn string `gorm:"column:question_sn;not null;comment:题目-唯一编号" json:"question_sn"` // 题目-唯一编号 + Sn int64 `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号 + UserSn int64 `gorm:"column:user_sn;not null;comment:用户-唯一编号" json:"user_sn"` // 用户-唯一编号 + QuestionSn int64 `gorm:"column:question_sn;not null;comment:题目-唯一编号" json:"question_sn"` // 题目-唯一编号 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 是 CreatedAt time.Time `gorm:"column:created_at;not null" json:"created_at"` @@ -33,8 +33,8 @@ func (*Record) TableName() string { // Auto sn func (m *Record) BeforeCreate(_ *gorm.DB) error { - if m.Sn == "" { - m.Sn = utils.SnowflakeInstance().Generate().String() + if m.Sn == 0 { + m.Sn = utils.SnowflakeInstance().Generate().Int64() } return nil } diff --git a/internal/dao/query/categories.gen.go b/internal/dao/query/categories.gen.go index ec8e549..d8ad601 100644 --- a/internal/dao/query/categories.gen.go +++ b/internal/dao/query/categories.gen.go @@ -28,7 +28,7 @@ func newCategory(db *gorm.DB, opts ...gen.DOOption) category { tableName := _category.categoryDo.TableName() _category.ALL = field.NewAsterisk(tableName) _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.CreatedAt = field.NewTime(tableName, "created_at") _category.UpdatedAt = field.NewTime(tableName, "updated_at") @@ -44,7 +44,7 @@ type category struct { ALL field.Asterisk ID field.Uint64 - Sn field.String // 业务唯一编号 + Sn field.Int64 // 业务唯一编号 Category field.String // 分类 CreatedAt field.Time UpdatedAt field.Time @@ -66,7 +66,7 @@ func (c category) As(alias string) *category { func (c *category) updateTableName(table string) *category { c.ALL = field.NewAsterisk(table) 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.CreatedAt = field.NewTime(table, "created_at") c.UpdatedAt = field.NewTime(table, "updated_at") diff --git a/internal/dao/query/point_card.gen.go b/internal/dao/query/point_card.gen.go index 32aa3d0..e4f1f97 100644 --- a/internal/dao/query/point_card.gen.go +++ b/internal/dao/query/point_card.gen.go @@ -28,8 +28,8 @@ func newPointCard(db *gorm.DB, opts ...gen.DOOption) pointCard { tableName := _pointCard.pointCardDo.TableName() _pointCard.ALL = field.NewAsterisk(tableName) _pointCard.ID = field.NewUint64(tableName, "id") - _pointCard.Sn = field.NewString(tableName, "sn") - _pointCard.UserSn = field.NewString(tableName, "user_sn") + _pointCard.Sn = field.NewInt64(tableName, "sn") + _pointCard.UserSn = field.NewInt64(tableName, "user_sn") _pointCard.Point = field.NewInt64(tableName, "point") _pointCard.CreatedAt = field.NewTime(tableName, "created_at") _pointCard.UpdatedAt = field.NewTime(tableName, "updated_at") @@ -45,9 +45,9 @@ type pointCard struct { ALL field.Asterisk ID field.Uint64 - Sn field.String // 业务唯一编号 - UserSn field.String // 用户-唯一编号 - Point field.Int64 // 积分 + Sn field.Int64 // 业务唯一编号 + UserSn field.Int64 // 用户-唯一编号 + Point field.Int64 // 积分 CreatedAt field.Time UpdatedAt field.Time DeletedAt field.Field @@ -68,8 +68,8 @@ func (p pointCard) As(alias string) *pointCard { func (p *pointCard) updateTableName(table string) *pointCard { p.ALL = field.NewAsterisk(table) p.ID = field.NewUint64(table, "id") - p.Sn = field.NewString(table, "sn") - p.UserSn = field.NewString(table, "user_sn") + p.Sn = field.NewInt64(table, "sn") + p.UserSn = field.NewInt64(table, "user_sn") p.Point = field.NewInt64(table, "point") p.CreatedAt = field.NewTime(table, "created_at") p.UpdatedAt = field.NewTime(table, "updated_at") diff --git a/internal/dao/query/point_records.gen.go b/internal/dao/query/point_records.gen.go index 9e941e0..ea3205c 100644 --- a/internal/dao/query/point_records.gen.go +++ b/internal/dao/query/point_records.gen.go @@ -28,8 +28,8 @@ func newPointRecord(db *gorm.DB, opts ...gen.DOOption) pointRecord { tableName := _pointRecord.pointRecordDo.TableName() _pointRecord.ALL = field.NewAsterisk(tableName) _pointRecord.ID = field.NewUint64(tableName, "id") - _pointRecord.Sn = field.NewString(tableName, "sn") - _pointRecord.UserSn = field.NewString(tableName, "user_sn") + _pointRecord.Sn = field.NewInt64(tableName, "sn") + _pointRecord.UserSn = field.NewInt64(tableName, "user_sn") _pointRecord.Source = field.NewInt32(tableName, "source") _pointRecord.Point = field.NewInt64(tableName, "point") _pointRecord.CreatedAt = field.NewTime(tableName, "created_at") @@ -46,8 +46,8 @@ type pointRecord struct { ALL field.Asterisk ID field.Uint64 - Sn field.String // 业务唯一编号 - UserSn field.String // 用户-唯一编号 + Sn field.Int64 // 业务唯一编号 + UserSn field.Int64 // 用户-唯一编号 /* 来源: 0. 未知 @@ -77,8 +77,8 @@ func (p pointRecord) As(alias string) *pointRecord { func (p *pointRecord) updateTableName(table string) *pointRecord { p.ALL = field.NewAsterisk(table) p.ID = field.NewUint64(table, "id") - p.Sn = field.NewString(table, "sn") - p.UserSn = field.NewString(table, "user_sn") + p.Sn = field.NewInt64(table, "sn") + p.UserSn = field.NewInt64(table, "user_sn") p.Source = field.NewInt32(table, "source") p.Point = field.NewInt64(table, "point") p.CreatedAt = field.NewTime(table, "created_at") diff --git a/internal/dao/query/questions.gen.go b/internal/dao/query/questions.gen.go index 477adbf..d4da21d 100644 --- a/internal/dao/query/questions.gen.go +++ b/internal/dao/query/questions.gen.go @@ -28,13 +28,13 @@ func newQuestion(db *gorm.DB, opts ...gen.DOOption) question { tableName := _question.questionDo.TableName() _question.ALL = field.NewAsterisk(tableName) _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.Options = field.NewString(tableName, "options") _question.Answer = field.NewString(tableName, "answer") _question.Explanation = field.NewString(tableName, "explanation") _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.UpdatedAt = field.NewTime(tableName, "updated_at") _question.DeletedAt = field.NewField(tableName, "deleted_at") @@ -49,13 +49,13 @@ type question struct { ALL field.Asterisk ID field.Uint64 - Sn field.String // 业务唯一编号 + Sn field.Int64 // 业务唯一编号 Question field.String // 题干 Options field.String // 选项 Answer field.String // 答案 Explanation field.String // 解析 Difficulty field.Int32 // 难度分 0 - 100 - CategorySn field.String // 分类-唯一编号 + CategorySn field.Int64 // 分类-唯一编号 CreatedAt field.Time UpdatedAt field.Time DeletedAt field.Field @@ -76,13 +76,13 @@ func (q question) As(alias string) *question { func (q *question) updateTableName(table string) *question { q.ALL = field.NewAsterisk(table) 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.Options = field.NewString(table, "options") q.Answer = field.NewString(table, "answer") q.Explanation = field.NewString(table, "explanation") 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.UpdatedAt = field.NewTime(table, "updated_at") q.DeletedAt = field.NewField(table, "deleted_at") diff --git a/internal/dao/query/records.gen.go b/internal/dao/query/records.gen.go index 0da10d5..97266e0 100644 --- a/internal/dao/query/records.gen.go +++ b/internal/dao/query/records.gen.go @@ -28,9 +28,9 @@ func newRecord(db *gorm.DB, opts ...gen.DOOption) record { tableName := _record.recordDo.TableName() _record.ALL = field.NewAsterisk(tableName) _record.ID = field.NewUint64(tableName, "id") - _record.Sn = field.NewString(tableName, "sn") - _record.UserSn = field.NewString(tableName, "user_sn") - _record.QuestionSn = field.NewString(tableName, "question_sn") + _record.Sn = field.NewInt64(tableName, "sn") + _record.UserSn = field.NewInt64(tableName, "user_sn") + _record.QuestionSn = field.NewInt64(tableName, "question_sn") _record.Answer = field.NewString(tableName, "answer") _record.IsCorrect = field.NewInt32(tableName, "is_correct") _record.CreatedAt = field.NewTime(tableName, "created_at") @@ -47,9 +47,9 @@ type record struct { ALL field.Asterisk ID field.Uint64 - Sn field.String // 业务唯一编号 - UserSn field.String // 用户-唯一编号 - QuestionSn field.String // 题目-唯一编号 + Sn field.Int64 // 业务唯一编号 + UserSn field.Int64 // 用户-唯一编号 + QuestionSn field.Int64 // 题目-唯一编号 Answer field.String // 答案 IsCorrect field.Int32 // 是否正确 0 否 1 是 CreatedAt field.Time @@ -72,9 +72,9 @@ func (r record) As(alias string) *record { func (r *record) updateTableName(table string) *record { r.ALL = field.NewAsterisk(table) r.ID = field.NewUint64(table, "id") - r.Sn = field.NewString(table, "sn") - r.UserSn = field.NewString(table, "user_sn") - r.QuestionSn = field.NewString(table, "question_sn") + r.Sn = field.NewInt64(table, "sn") + r.UserSn = field.NewInt64(table, "user_sn") + r.QuestionSn = field.NewInt64(table, "question_sn") r.Answer = field.NewString(table, "answer") r.IsCorrect = field.NewInt32(table, "is_correct") r.CreatedAt = field.NewTime(table, "created_at") diff --git a/internal/dao/repository/categories.go b/internal/dao/repository/categories.go index c79730c..f589972 100644 --- a/internal/dao/repository/categories.go +++ b/internal/dao/repository/categories.go @@ -40,7 +40,7 @@ func (d *CategoryDao) FindAll() ([]*model.Category, error) { 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). Select(d.query.Category.Category). Where(d.query.Category.Sn.Eq(sn)). @@ -51,13 +51,13 @@ func (d *CategoryDao) FindNameBySn(sn string) (string, error) { 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). Select(d.query.Category.Sn). Where(d.query.Category.Category.Eq(category)). First() if err != nil { - return "", err + return 0, err } return first.Sn, nil } diff --git a/internal/dao/repository/define.go b/internal/dao/repository/define.go index 5fc0be5..9ed7d43 100644 --- a/internal/dao/repository/define.go +++ b/internal/dao/repository/define.go @@ -16,6 +16,6 @@ func Query() *query.Query { 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) } diff --git a/internal/dao/repository/point_card.go b/internal/dao/repository/point_card.go index 3686cf2..ec40874 100644 --- a/internal/dao/repository/point_card.go +++ b/internal/dao/repository/point_card.go @@ -32,7 +32,7 @@ func (d *PointCardDao) Create(pointCard *model.PointCard) (*model.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). Where(d.query.PointCard.UserSn.Eq(usn)). UpdateSimple(d.query.PointCard.Point.Add(point)) @@ -45,7 +45,7 @@ func (d *PointCardDao) IncrPointCard(usn string, point int64) error { return nil } -func (d *PointCardDao) FindByUserSn(usn string) (*model.PointCard, error) { +func (d *PointCardDao) FindByUserSn(usn int64) (*model.PointCard, error) { return d.query.PointCard.WithContext(d.ctx). Where(d.query.PointCard.UserSn.Eq(usn)). First() diff --git a/internal/dao/repository/questions.go b/internal/dao/repository/questions.go index 3e81612..0330f25 100644 --- a/internal/dao/repository/questions.go +++ b/internal/dao/repository/questions.go @@ -33,9 +33,9 @@ func (d *QuestionDao) Create(question *model.Question) (*model.Question, error) 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) - if categorySn != "" { + if categorySn != 0 { 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 } -func (d *QuestionDao) FindBySn(sn string) (*model.Question, error) { +func (d *QuestionDao) FindBySn(sn int64) (*model.Question, error) { if d.cache != nil { var question model.Question if ok := d.cache.Get(d.ctx, keyCacheBySn(sn, question.TableName()), &question); ok { diff --git a/internal/dao/repository/records.go b/internal/dao/repository/records.go index 3b17048..24fe989 100644 --- a/internal/dao/repository/records.go +++ b/internal/dao/repository/records.go @@ -32,7 +32,7 @@ func (d *RecordDao) Create(record *model.Record) (*model.Record, error) { } type RecordItem struct { - QuestionSn string `gorm:"column:question_sn"` + QuestionSn int64 `gorm:"column:question_sn"` Question string `gorm:"column:question"` Difficulty int32 `gorm:"column:difficulty"` Category string `gorm:"column:category"` @@ -42,7 +42,7 @@ type RecordItem struct { 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) count, err := d.query.Record.WithContext(d.ctx). Select( diff --git a/internal/grpc_server/server_category.go b/internal/grpc_server/server_category.go index ef9344f..f5ae10a 100644 --- a/internal/grpc_server/server_category.go +++ b/internal/grpc_server/server_category.go @@ -63,9 +63,9 @@ func (s *Server) CategoryAnswerQuestion(ctx context.Context, req *grpc_pb.Catego return nil, utils.ErrorsWrapF(err, "data: %v", question.Options) } // 保存答题记录 - if req.USN != "" { + if req.USN != 0 { kafka.NewProducer().Produce(ctx, &timer.TopicQuestionAnswer{ - MessageSn: utils.SnowflakeInstance().Generate().String(), + MessageSn: utils.SnowflakeInstance().Generate().Int64(), USN: req.USN, QuestionSn: question.Sn, QuestionAnswer: question.Answer, diff --git a/internal/grpc_server/server_quickly.go b/internal/grpc_server/server_quickly.go index 15f65d6..0e0b58a 100644 --- a/internal/grpc_server/server_quickly.go +++ b/internal/grpc_server/server_quickly.go @@ -14,7 +14,7 @@ import ( // QuicklyGetQuestion 获取题目 func (s *Server) QuicklyGetQuestion(ctx context.Context, req *grpc_pb.QuicklyGetQuestionReq) (*grpc_pb.QuicklyGetQuestionResp, error) { - question, err := repository.NewQuestionDao(ctx, s.query).FindByRandom("") + question, err := repository.NewQuestionDao(ctx, s.query).FindByRandom(0) if err != nil { return nil, utils.ErrorsWrap(err) } @@ -45,9 +45,9 @@ func (s *Server) QuicklyAnswerQuestion(ctx context.Context, req *grpc_pb.Quickly return nil, utils.ErrorsWrapF(err, "data: %v", question.Options) } // 保存答题记录 - if req.USN != "" { + if req.USN != 0 { kafka.NewProducer().Produce(ctx, &timer.TopicQuestionAnswer{ - MessageSn: utils.SnowflakeInstance().Generate().String(), + MessageSn: utils.SnowflakeInstance().Generate().Int64(), USN: req.USN, QuestionSn: question.Sn, QuestionAnswer: question.Answer, diff --git a/internal/grpc_server/server_random.go b/internal/grpc_server/server_random.go index 5797461..65965cb 100644 --- a/internal/grpc_server/server_random.go +++ b/internal/grpc_server/server_random.go @@ -14,7 +14,7 @@ import ( // RandomGetQuestion 获取题目 func (s *Server) RandomGetQuestion(ctx context.Context, req *grpc_pb.RandomGetQuestionReq) (*grpc_pb.RandomGetQuestionResp, error) { - question, err := repository.NewQuestionDao(ctx, s.query).FindByRandom("") + question, err := repository.NewQuestionDao(ctx, s.query).FindByRandom(0) if err != nil { return nil, utils.ErrorsWrap(err) } @@ -45,9 +45,9 @@ func (s *Server) RandomAnswerQuestion(ctx context.Context, req *grpc_pb.RandomAn return nil, utils.ErrorsWrapF(err, "data: %v", question.Options) } // 保存答题记录 - if req.USN != "" { + if req.USN != 0 { kafka.NewProducer().Produce(ctx, &timer.TopicQuestionAnswer{ - MessageSn: utils.SnowflakeInstance().Generate().String(), + MessageSn: utils.SnowflakeInstance().Generate().Int64(), USN: req.USN, QuestionSn: question.Sn, QuestionAnswer: question.Answer, @@ -57,7 +57,7 @@ func (s *Server) RandomAnswerQuestion(ctx context.Context, req *grpc_pb.RandomAn // 随机答题正确给10分,错误不得分 if req.Answer == question.Answer { kafka.NewProducer().Produce(ctx, &timer.TopicAddPoint{ - MessageSn: utils.SnowflakeInstance().Generate().String(), + MessageSn: utils.SnowflakeInstance().Generate().Int64(), Source: timer.AddPointSourceRandom, USN: req.USN, Point: 10, diff --git a/internal/timer/consumer.go b/internal/timer/consumer.go index 29f8c7e..240fcdd 100644 --- a/internal/timer/consumer.go +++ b/internal/timer/consumer.go @@ -20,9 +20,9 @@ func startConsumer() { } type TopicQuestionAnswer struct { - MessageSn string `json:"messageSn"` - USN string `json:"usn"` - QuestionSn string `json:"questionSn"` + MessageSn int64 `json:"messageSn"` + USN int64 `json:"usn"` + QuestionSn int64 `json:"questionSn"` QuestionAnswer string `json:"questionAnswer"` Answer string `json:"answer"` } @@ -33,7 +33,7 @@ func (t *TopicQuestionAnswer) Name() string { func (t *TopicQuestionAnswer) OnMessage(ctx context.Context) error { 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")) } @@ -60,9 +60,9 @@ func (t *TopicQuestionAnswer) OnMessage(ctx context.Context) error { } type TopicAddPoint struct { - MessageSn string `json:"messageSn"` + MessageSn int64 `json:"messageSn"` Source AddPointSource `json:"source"` - USN string `json:"usn"` + USN int64 `json:"usn"` Point int64 `json:"point"` } @@ -81,7 +81,7 @@ func (t *TopicAddPoint) Name() string { func (t *TopicAddPoint) OnMessage(ctx context.Context) error { 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")) }