feat 答题记录

This commit is contained in:
2026-01-14 21:05:40 +08:00
parent b16bd8960a
commit e482833f72
4 changed files with 42 additions and 16 deletions

2
go.mod
View File

@@ -3,7 +3,7 @@ module git.hlsq.asia/mmorpg/service-qgdzs
go 1.23.1 go 1.23.1
require ( require (
git.hlsq.asia/mmorpg/service-common v0.0.0-20260114100922-695f5e7b0497 git.hlsq.asia/mmorpg/service-common v0.0.0-20260114110346-7cb057fc916e
github.com/judwhite/go-svc v1.2.1 github.com/judwhite/go-svc v1.2.1
google.golang.org/grpc v1.71.1 google.golang.org/grpc v1.71.1
gorm.io/gen v0.3.27 gorm.io/gen v0.3.27

4
go.sum
View File

@@ -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-20260114100922-695f5e7b0497 h1:pPFMkZKNaCWbo5HHMcUaHQAj1mEvQ6JamWcXiUJ26J4= git.hlsq.asia/mmorpg/service-common v0.0.0-20260114110346-7cb057fc916e h1:E459cK0l+oODUT6KWA3BxPQRboMJIKLs4TYjnWiG6iQ=
git.hlsq.asia/mmorpg/service-common v0.0.0-20260114100922-695f5e7b0497/go.mod h1:xv6m1I2jUA6mudKVznygpnzMoshBQarthHD1QnkW4qc= git.hlsq.asia/mmorpg/service-common v0.0.0-20260114110346-7cb057fc916e/go.mod h1:xv6m1I2jUA6mudKVznygpnzMoshBQarthHD1QnkW4qc=
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/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=

View File

@@ -38,6 +38,8 @@ type RecordItem struct {
Difficulty int32 `gorm:"column:difficulty"` Difficulty int32 `gorm:"column:difficulty"`
Category string `gorm:"column:category"` Category string `gorm:"column:category"`
IsCorrect int32 `gorm:"column:is_correct"` IsCorrect int32 `gorm:"column:is_correct"`
QuestionAnswer string `gorm:"column:question_answer"`
Answer string `gorm:"column:answer"`
CreatedAt time.Time `gorm:"column:created_at"` CreatedAt time.Time `gorm:"column:created_at"`
} }
@@ -48,8 +50,9 @@ func (d *RecordDao) FindByUSN(usn string, page, pageSize int) ([]*RecordItem, in
d.query.Question.Sn.As("question_sn"), d.query.Question.Sn.As("question_sn"),
d.query.Question.Question, d.query.Question.Question,
d.query.Question.Difficulty, d.query.Question.Difficulty,
d.query.Question.Answer.As("question_answer"),
d.query.Category.Category, d.query.Category.Category,
d.query.Record.IsCorrect, d.query.Record.Answer,
d.query.Record.CreatedAt, d.query.Record.CreatedAt,
). ).
Where(d.query.Record.UserSn.Eq(usn)). Where(d.query.Record.UserSn.Eq(usn)).

View File

@@ -146,6 +146,28 @@ func (s *Server) GetQuestion(ctx context.Context, req *grpc_pb.GetQuestionReq) (
}, nil }, nil
} }
// GetQuestionInfo 获取具体的题目
func (s *Server) GetQuestionInfo(ctx context.Context, req *grpc_pb.GetQuestionInfoReq) (*grpc_pb.GetQuestionInfoResp, error) {
question, err := repository.NewQuestionDao(ctx).FindBySn(req.QuestionSn)
if err != nil {
log.Errorf("GetQuestionInfo error: %v", err)
return nil, err
}
options := make([]string, 0)
if err = json.Unmarshal([]byte(question.Options), &options); err != nil {
log.Errorf("GetQuestionInfo json.Unmarshal error: %v, data: %v", err, question.Options)
return nil, err
}
category, _ := repository.NewCategoryDao(ctx).FindNameBySn(question.CategorySn)
return &grpc_pb.GetQuestionInfoResp{
Question: question.Question,
Options: options,
Category: category,
Difficulty: question.Difficulty,
Explanation: question.Explanation,
}, nil
}
// AnswerQuestion 回答题目 // AnswerQuestion 回答题目
func (s *Server) AnswerQuestion(ctx context.Context, req *grpc_pb.AnswerQuestionReq) (*grpc_pb.AnswerQuestionResp, error) { func (s *Server) AnswerQuestion(ctx context.Context, req *grpc_pb.AnswerQuestionReq) (*grpc_pb.AnswerQuestionResp, error) {
question, err := repository.NewQuestionDao(ctx).FindBySn(req.Sn) question, err := repository.NewQuestionDao(ctx).FindBySn(req.Sn)
@@ -213,7 +235,8 @@ func (s *Server) GetRecord(ctx context.Context, req *grpc_pb.GetRecordReq) (*grp
Question: record.Question, Question: record.Question,
Difficulty: record.Difficulty, Difficulty: record.Difficulty,
Category: record.Category, Category: record.Category,
IsCorrect: record.IsCorrect, QuestionAnswer: record.QuestionAnswer,
Answer: record.Answer,
CreateTime: record.CreatedAt.Unix(), CreateTime: record.CreatedAt.Unix(),
}) })
} }