feat kafka 改版 2

This commit is contained in:
2026-01-30 11:02:53 +08:00
parent defe0b8fff
commit 39fa373c01
22 changed files with 1297 additions and 236 deletions

View File

@@ -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
}