feat kafka 改版 2
This commit is contained in:
@@ -2,7 +2,6 @@ package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.hlsq.asia/mmorpg/service-common/db/mysql"
|
||||
"git.hlsq.asia/mmorpg/service-common/db/redis"
|
||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/model"
|
||||
@@ -17,10 +16,10 @@ type QuestionDao struct {
|
||||
cache *redis.CacheClient
|
||||
}
|
||||
|
||||
func NewQuestionDao(ctx context.Context, cache ...*redis.CacheClient) *QuestionDao {
|
||||
func NewQuestionDao(ctx context.Context, query *query.Query, cache ...*redis.CacheClient) *QuestionDao {
|
||||
dao := &QuestionDao{
|
||||
ctx: ctx,
|
||||
query: query.Use(mysql.GetDB(dbName)),
|
||||
query: query,
|
||||
}
|
||||
if len(cache) > 0 {
|
||||
dao.cache = cache[0]
|
||||
@@ -73,23 +72,3 @@ func (d *QuestionDao) FindBySn(sn string) (*model.Question, error) {
|
||||
}
|
||||
return first, nil
|
||||
}
|
||||
|
||||
func (d *QuestionDao) FindByCategory(categorySn string) (*model.Question, error) {
|
||||
count, err := d.query.Question.WithContext(d.ctx).
|
||||
Where(d.query.Question.CategorySn.Eq(categorySn)).
|
||||
Count()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if count == 0 {
|
||||
return nil, gorm.ErrRecordNotFound
|
||||
}
|
||||
first, err := d.query.Question.WithContext(d.ctx).
|
||||
Where(d.query.Question.CategorySn.Eq(categorySn)).
|
||||
Offset(utils.RandInt(0, int(count-1))).
|
||||
First()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return first, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user