feat kafka
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.hlsq.asia/mmorpg/service-common/db/kafka"
|
||||
"git.hlsq.asia/mmorpg/service-common/db/redis"
|
||||
"git.hlsq.asia/mmorpg/service-common/log"
|
||||
"git.hlsq.asia/mmorpg/service-common/net/http/http_resp"
|
||||
@@ -13,6 +14,7 @@ import (
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/ai"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/model"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/repository"
|
||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/timer"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
@@ -172,16 +174,15 @@ func (s *Server) AnswerQuestion(ctx context.Context, req *grpc_pb.AnswerQuestion
|
||||
}
|
||||
// 保存答题记录
|
||||
if utils.ShouldBindUsn(ctx, &req.USN) {
|
||||
isCorrect := int32(0)
|
||||
if req.Answer == question.Answer {
|
||||
isCorrect = 1
|
||||
data := &timer.TopicQuestionAnswer{
|
||||
MessageSn: utils.SnowflakeInstance().Generate().String(),
|
||||
USN: req.USN,
|
||||
QuestionSn: question.Sn,
|
||||
QuestionAnswer: question.Answer,
|
||||
Answer: req.Answer,
|
||||
}
|
||||
_, _ = repository.NewRecordDao(ctx).Create(&model.Record{
|
||||
UserSn: req.USN,
|
||||
QuestionSn: question.Sn,
|
||||
Answer: req.Answer,
|
||||
IsCorrect: isCorrect,
|
||||
})
|
||||
marshal, _ := json.Marshal(data)
|
||||
kafka.NewProducer().Produce(ctx, "qgdzs.question.answer", string(marshal))
|
||||
}
|
||||
return &grpc_pb.AnswerQuestionResp{
|
||||
Answer: question.Answer,
|
||||
|
||||
Reference in New Issue
Block a user