From e482833f724b1ba5f89cd3d5d11e89caf3d47f25 Mon Sep 17 00:00:00 2001 From: "DESKTOP-V763RJ7\\Administrator" <835606593@qq.com> Date: Wed, 14 Jan 2026 21:05:40 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E7=AD=94=E9=A2=98=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 2 +- go.sum | 4 +-- internal/dao/repository/records.go | 17 +++++++----- internal/grpc_server/server_question.go | 35 ++++++++++++++++++++----- 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index d6b8bef..18dda32 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.hlsq.asia/mmorpg/service-qgdzs go 1.23.1 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 google.golang.org/grpc v1.71.1 gorm.io/gen v0.3.27 diff --git a/go.sum b/go.sum index de8f283..8f23aa5 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-20260114100922-695f5e7b0497 h1:pPFMkZKNaCWbo5HHMcUaHQAj1mEvQ6JamWcXiUJ26J4= -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 h1:E459cK0l+oODUT6KWA3BxPQRboMJIKLs4TYjnWiG6iQ= +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/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= diff --git a/internal/dao/repository/records.go b/internal/dao/repository/records.go index 7a662e2..fe0d1b7 100644 --- a/internal/dao/repository/records.go +++ b/internal/dao/repository/records.go @@ -33,12 +33,14 @@ func (d *RecordDao) Create(record *model.Record) (*model.Record, error) { } type RecordItem struct { - QuestionSn string `gorm:"column:question_sn"` - Question string `gorm:"column:question"` - Difficulty int32 `gorm:"column:difficulty"` - Category string `gorm:"column:category"` - IsCorrect int32 `gorm:"column:is_correct"` - CreatedAt time.Time `gorm:"column:created_at"` + QuestionSn string `gorm:"column:question_sn"` + Question string `gorm:"column:question"` + Difficulty int32 `gorm:"column:difficulty"` + Category string `gorm:"column:category"` + IsCorrect int32 `gorm:"column:is_correct"` + QuestionAnswer string `gorm:"column:question_answer"` + Answer string `gorm:"column:answer"` + CreatedAt time.Time `gorm:"column:created_at"` } func (d *RecordDao) FindByUSN(usn string, page, pageSize int) ([]*RecordItem, int64, error) { @@ -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.Question, d.query.Question.Difficulty, + d.query.Question.Answer.As("question_answer"), d.query.Category.Category, - d.query.Record.IsCorrect, + d.query.Record.Answer, d.query.Record.CreatedAt, ). Where(d.query.Record.UserSn.Eq(usn)). diff --git a/internal/grpc_server/server_question.go b/internal/grpc_server/server_question.go index 19c3a4d..de3a639 100644 --- a/internal/grpc_server/server_question.go +++ b/internal/grpc_server/server_question.go @@ -146,6 +146,28 @@ func (s *Server) GetQuestion(ctx context.Context, req *grpc_pb.GetQuestionReq) ( }, 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 回答题目 func (s *Server) AnswerQuestion(ctx context.Context, req *grpc_pb.AnswerQuestionReq) (*grpc_pb.AnswerQuestionResp, error) { question, err := repository.NewQuestionDao(ctx).FindBySn(req.Sn) @@ -209,12 +231,13 @@ func (s *Server) GetRecord(ctx context.Context, req *grpc_pb.GetRecordReq) (*grp resp := make([]*grpc_pb.GetRecordItem, 0) for _, record := range records { resp = append(resp, &grpc_pb.GetRecordItem{ - QuestionSn: record.QuestionSn, - Question: record.Question, - Difficulty: record.Difficulty, - Category: record.Category, - IsCorrect: record.IsCorrect, - CreateTime: record.CreatedAt.Unix(), + QuestionSn: record.QuestionSn, + Question: record.Question, + Difficulty: record.Difficulty, + Category: record.Category, + QuestionAnswer: record.QuestionAnswer, + Answer: record.Answer, + CreateTime: record.CreatedAt.Unix(), }) } return &grpc_pb.GetRecordResp{