From 77cc02fc95e7f50c4c6e1a1b023a65a1f95c8d39 Mon Sep 17 00:00:00 2001 From: "DESKTOP-V763RJ7\\Administrator" <835606593@qq.com> Date: Wed, 11 Feb 2026 14:49:46 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E5=8C=85=E5=91=BD=E5=90=8D=E8=A7=84?= =?UTF-8?q?=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/app.go | 4 +-- go.mod | 2 +- go.sum | 4 +-- .../server_category.go | 27 +++++++++--------- .../server_init.go | 8 +++--- .../server_leaderboard.go | 2 +- .../server_point.go | 22 +++++++-------- .../server_question.go | 6 ++-- .../server_quickly.go | 15 +++++----- .../server_random.go | 19 ++++++------- .../server_record.go | 20 ++++++------- internal/timer/consumer.go | 28 ++----------------- 12 files changed, 65 insertions(+), 92 deletions(-) rename internal/{grpc_server => grpcserver}/server_category.go (70%) rename internal/{grpc_server => grpcserver}/server_init.go (85%) rename internal/{grpc_server => grpcserver}/server_leaderboard.go (96%) rename internal/{grpc_server => grpcserver}/server_point.go (59%) rename internal/{grpc_server => grpcserver}/server_question.go (95%) rename internal/{grpc_server => grpcserver}/server_quickly.go (76%) rename internal/{grpc_server => grpcserver}/server_random.go (75%) rename internal/{grpc_server => grpcserver}/server_record.go (71%) diff --git a/app/app.go b/app/app.go index 1036677..fac32cb 100644 --- a/app/app.go +++ b/app/app.go @@ -6,7 +6,7 @@ import ( "git.hlsq.asia/mmorpg/service-common/log" "git.hlsq.asia/mmorpg/service-common/module" "git.hlsq.asia/mmorpg/service-qgdzs/config" - "git.hlsq.asia/mmorpg/service-qgdzs/internal/grpc_server" + "git.hlsq.asia/mmorpg/service-qgdzs/internal/grpcserver" "github.com/judwhite/go-svc" "sync" ) @@ -19,7 +19,7 @@ func (p *Program) Init(_ svc.Environment) error { p.moduleList = append(p.moduleList, &module.Log{Cfg: config.Get().Log}) p.moduleList = append(p.moduleList, &module.DB{Cfg: config.Get().DB, AppName: config.Get().App.Name}) p.moduleList = append(p.moduleList, &module.Snowflake{}) - p.moduleList = append(p.moduleList, &module.Grpc{Server: grpc_server.NewServer(config.Get().Serve.Grpc)}) + p.moduleList = append(p.moduleList, &module.Grpc{Server: grpcserver.NewServer(config.Get().Serve.Grpc)}) p.moduleList = append(p.moduleList, &ModuleTimer{}) p.moduleList = append(p.moduleList, &module.Prometheus{Cfg: config.Get().Metric}) p.moduleList = append(p.moduleList, &module.Tracer{Cfg: config.Get().Metric, ServiceName: common.KeyDiscoverServiceNameQgdzs}) diff --git a/go.mod b/go.mod index 6c54cdf..4750191 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module git.hlsq.asia/mmorpg/service-qgdzs go 1.24.0 require ( - git.hlsq.asia/mmorpg/service-common v0.0.0-20260207051302-0ca8a0ccbb14 + git.hlsq.asia/mmorpg/service-common v0.0.0-20260211064821-558677bc3a2e github.com/judwhite/go-svc v1.2.1 github.com/robfig/cron/v3 v3.0.1 google.golang.org/grpc v1.77.0 diff --git a/go.sum b/go.sum index f6c43c7..600e07d 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-20260207051302-0ca8a0ccbb14 h1:4r3tNWRzGVY3Xx6UiGjJJnwoMoWlVqbyGrljxl5d/nQ= -git.hlsq.asia/mmorpg/service-common v0.0.0-20260207051302-0ca8a0ccbb14/go.mod h1:mMhZcumphj6gaVTppVYsMTkd+5HupmQgAc53Pd4MH9I= +git.hlsq.asia/mmorpg/service-common v0.0.0-20260211064821-558677bc3a2e h1:MNVS1NXNVn4DeTZPcvvA8YFM8afCzZedLPUYMffNgZs= +git.hlsq.asia/mmorpg/service-common v0.0.0-20260211064821-558677bc3a2e/go.mod h1:mMhZcumphj6gaVTppVYsMTkd+5HupmQgAc53Pd4MH9I= github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0= github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/IBM/sarama v1.46.3 h1:njRsX6jNlnR+ClJ8XmkO+CM4unbrNr/2vB5KK6UA+IE= diff --git a/internal/grpc_server/server_category.go b/internal/grpcserver/server_category.go similarity index 70% rename from internal/grpc_server/server_category.go rename to internal/grpcserver/server_category.go index 885f37a..65a9eb2 100644 --- a/internal/grpc_server/server_category.go +++ b/internal/grpcserver/server_category.go @@ -1,37 +1,36 @@ -package grpc_server +package grpcserver import ( "context" "encoding/json" "git.hlsq.asia/mmorpg/service-common/db/kafka" - "git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb" + "git.hlsq.asia/mmorpg/service-common/proto/rs/rspb" "git.hlsq.asia/mmorpg/service-common/utils" "git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/repository" - "git.hlsq.asia/mmorpg/service-qgdzs/internal/timer" ) // 玩法 - 类目答题 // GetAllCategory 获取所有类目 -func (s *Server) GetAllCategory(ctx context.Context, req *grpc_pb.GetAllCategoryReq) (*grpc_pb.GetAllCategoryResp, error) { +func (s *Server) GetAllCategory(ctx context.Context, req *rspb.GetAllCategoryReq) (*rspb.GetAllCategoryResp, error) { categoryList, err := repository.NewCategoryDao(ctx, s.query).FindAll() if err != nil { return nil, utils.ErrorsWrap(err) } - categories := make([]*grpc_pb.GetAllCategoryItem, 0) + categories := make([]*rspb.GetAllCategoryItem, 0) for _, category := range categoryList { - categories = append(categories, &grpc_pb.GetAllCategoryItem{ + categories = append(categories, &rspb.GetAllCategoryItem{ Sn: category.Sn, Category: category.Category, }) } - return &grpc_pb.GetAllCategoryResp{ + return &rspb.GetAllCategoryResp{ Categories: categories, }, nil } // CategoryGetQuestion 获取题目 -func (s *Server) CategoryGetQuestion(ctx context.Context, req *grpc_pb.CategoryGetQuestionReq) (*grpc_pb.CategoryGetQuestionResp, error) { +func (s *Server) CategoryGetQuestion(ctx context.Context, req *rspb.CategoryGetQuestionReq) (*rspb.CategoryGetQuestionResp, error) { question, err := repository.NewQuestionDao(ctx, s.query).FindByRandom(req.CategorySn) if err != nil { return nil, utils.ErrorsWrap(err) @@ -41,7 +40,7 @@ func (s *Server) CategoryGetQuestion(ctx context.Context, req *grpc_pb.CategoryG return nil, utils.ErrorsWrapF(err, "data: %v", question.Options) } category, _ := repository.NewCategoryDao(ctx, s.query).FindNameBySn(question.CategorySn) - return &grpc_pb.CategoryGetQuestionResp{ + return &rspb.CategoryGetQuestionResp{ Sn: question.Sn, Question: question.Question, Options: options, @@ -51,7 +50,7 @@ func (s *Server) CategoryGetQuestion(ctx context.Context, req *grpc_pb.CategoryG } // CategoryAnswerQuestion 回答题目 -func (s *Server) CategoryAnswerQuestion(ctx context.Context, req *grpc_pb.CategoryAnswerQuestionReq) (*grpc_pb.CategoryAnswerQuestionResp, error) { +func (s *Server) CategoryAnswerQuestion(ctx context.Context, req *rspb.CategoryAnswerQuestionReq) (*rspb.CategoryAnswerQuestionResp, error) { utils.ShouldBindUsn(ctx, &req.USN) question, err := repository.NewQuestionDao(ctx, s.query).FindBySn(req.Sn) @@ -64,7 +63,7 @@ func (s *Server) CategoryAnswerQuestion(ctx context.Context, req *grpc_pb.Catego } // 保存答题记录 if req.USN != 0 { - kafka.NewProducer().Produce(ctx, &timer.TopicQuestionAnswer{ + kafka.NewProducer().Produce(ctx, &kafka.TopicQuestionAnswer{ MessageSn: utils.SnowflakeInstance().Generate().Int64(), USN: req.USN, QuestionSn: question.Sn, @@ -74,15 +73,15 @@ func (s *Server) CategoryAnswerQuestion(ctx context.Context, req *grpc_pb.Catego // 类目答题正确给5分,错误不得分 if req.Answer == question.Answer { - kafka.NewProducer().Produce(ctx, &timer.TopicAddPoint{ + kafka.NewProducer().Produce(ctx, &kafka.TopicAddPoint{ MessageSn: utils.SnowflakeInstance().Generate().Int64(), - Source: timer.AddPointSourceCategory, + Source: kafka.AddPointSourceCategory, USN: req.USN, Point: 5, }) } } - return &grpc_pb.CategoryAnswerQuestionResp{ + return &rspb.CategoryAnswerQuestionResp{ Answer: question.Answer, Explanation: question.Explanation, }, nil diff --git a/internal/grpc_server/server_init.go b/internal/grpcserver/server_init.go similarity index 85% rename from internal/grpc_server/server_init.go rename to internal/grpcserver/server_init.go index 025315b..86e6e73 100644 --- a/internal/grpc_server/server_init.go +++ b/internal/grpcserver/server_init.go @@ -1,17 +1,17 @@ -package grpc_server +package grpcserver import ( "git.hlsq.asia/mmorpg/service-common/config" "git.hlsq.asia/mmorpg/service-common/discover/common" "git.hlsq.asia/mmorpg/service-common/net/grpc/service" - "git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb" + "git.hlsq.asia/mmorpg/service-common/proto/rs/rspb" "git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/query" "git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/repository" "google.golang.org/grpc" ) type Server struct { - grpc_pb.UnimplementedQgdzsServer + rspb.UnimplementedQgdzsServer service.Base query *query.Query } @@ -35,7 +35,7 @@ func (s *Server) OnCustomGrpcServerOption() []grpc.ServerOption { } func (s *Server) OnInit(serve *grpc.Server) { - grpc_pb.RegisterQgdzsServer(serve, s) + rspb.RegisterQgdzsServer(serve, s) s.query = repository.Query() } diff --git a/internal/grpc_server/server_leaderboard.go b/internal/grpcserver/server_leaderboard.go similarity index 96% rename from internal/grpc_server/server_leaderboard.go rename to internal/grpcserver/server_leaderboard.go index 19edd31..7f83781 100644 --- a/internal/grpc_server/server_leaderboard.go +++ b/internal/grpcserver/server_leaderboard.go @@ -1,4 +1,4 @@ -package grpc_server +package grpcserver import ( "context" diff --git a/internal/grpc_server/server_point.go b/internal/grpcserver/server_point.go similarity index 59% rename from internal/grpc_server/server_point.go rename to internal/grpcserver/server_point.go index 556f64b..37ac2ca 100644 --- a/internal/grpc_server/server_point.go +++ b/internal/grpcserver/server_point.go @@ -1,9 +1,9 @@ -package grpc_server +package grpcserver import ( "context" - "git.hlsq.asia/mmorpg/service-common/net/http/http_resp" - "git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb" + "git.hlsq.asia/mmorpg/service-common/net/http/httpresp" + "git.hlsq.asia/mmorpg/service-common/proto/rs/rspb" "git.hlsq.asia/mmorpg/service-common/utils" "git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/repository" ) @@ -11,38 +11,38 @@ import ( // 模块 - 学识分 // GetPointRecord 获取学识分获取记录 -func (s *Server) GetPointRecord(ctx context.Context, req *grpc_pb.GetPointRecordReq) (*grpc_pb.GetPointRecordResp, error) { +func (s *Server) GetPointRecord(ctx context.Context, req *rspb.GetPointRecordReq) (*rspb.GetPointRecordResp, error) { if !utils.ShouldBindUsn(ctx, &req.USN) { - return nil, http_resp.ParamError + return nil, httpresp.ParamError } records, count, err := repository.NewPointRecordsDao(ctx, s.query).FindByUSN(req.USN, int(req.Page), int(req.PageSize)) if err != nil { return nil, utils.ErrorsWrap(err) } - resp := make([]*grpc_pb.GetPointRecordItem, 0) + resp := make([]*rspb.GetPointRecordItem, 0) for _, record := range records { - resp = append(resp, &grpc_pb.GetPointRecordItem{ + resp = append(resp, &rspb.GetPointRecordItem{ Source: record.Source, Point: record.Point, CreateTime: record.CreatedAt.Unix(), }) } - return &grpc_pb.GetPointRecordResp{ + return &rspb.GetPointRecordResp{ Count: int32(count), Records: resp, }, nil } // GetPoint 获取学识分 -func (s *Server) GetPoint(ctx context.Context, req *grpc_pb.GetPointReq) (*grpc_pb.GetPointResp, error) { +func (s *Server) GetPoint(ctx context.Context, req *rspb.GetPointReq) (*rspb.GetPointResp, error) { if !utils.ShouldBindUsn(ctx, &req.USN) { - return nil, http_resp.ParamError + return nil, httpresp.ParamError } pointCard, err := repository.NewPointCardDao(ctx, s.query).FindPointByUserSn(req.USN) if err != nil { return nil, utils.ErrorsWrap(err) } - return &grpc_pb.GetPointResp{ + return &rspb.GetPointResp{ Point: pointCard.Point, }, nil } diff --git a/internal/grpc_server/server_question.go b/internal/grpcserver/server_question.go similarity index 95% rename from internal/grpc_server/server_question.go rename to internal/grpcserver/server_question.go index ef97845..ec4c8dc 100644 --- a/internal/grpc_server/server_question.go +++ b/internal/grpcserver/server_question.go @@ -1,4 +1,4 @@ -package grpc_server +package grpcserver import ( "context" @@ -7,7 +7,7 @@ import ( "fmt" "git.hlsq.asia/mmorpg/service-common/db/redis" "git.hlsq.asia/mmorpg/service-common/log" - "git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb" + "git.hlsq.asia/mmorpg/service-common/proto/rs/rspb" "git.hlsq.asia/mmorpg/service-common/utils" "git.hlsq.asia/mmorpg/service-qgdzs/internal/ai" "git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/model" @@ -53,7 +53,7 @@ type Question struct { Difficulty int32 `json:"difficulty"` // 难度分 } -func (s *Server) GenerateQuestion(ctx context.Context, req *grpc_pb.GenerateQuestionReq) (*grpc_pb.GenerateQuestionResp, error) { +func (s *Server) GenerateQuestion(ctx context.Context, req *rspb.GenerateQuestionReq) (*rspb.GenerateQuestionResp, error) { categoryDao := repository.NewCategoryDao(ctx, s.query, redis.GetCacheClient()) category, err := categoryDao.FindAll() if err != nil { diff --git a/internal/grpc_server/server_quickly.go b/internal/grpcserver/server_quickly.go similarity index 76% rename from internal/grpc_server/server_quickly.go rename to internal/grpcserver/server_quickly.go index 0e0b58a..61acec9 100644 --- a/internal/grpc_server/server_quickly.go +++ b/internal/grpcserver/server_quickly.go @@ -1,19 +1,18 @@ -package grpc_server +package grpcserver import ( "context" "encoding/json" "git.hlsq.asia/mmorpg/service-common/db/kafka" - "git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb" + "git.hlsq.asia/mmorpg/service-common/proto/rs/rspb" "git.hlsq.asia/mmorpg/service-common/utils" "git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/repository" - "git.hlsq.asia/mmorpg/service-qgdzs/internal/timer" ) // 玩法 - 随机答题 // QuicklyGetQuestion 获取题目 -func (s *Server) QuicklyGetQuestion(ctx context.Context, req *grpc_pb.QuicklyGetQuestionReq) (*grpc_pb.QuicklyGetQuestionResp, error) { +func (s *Server) QuicklyGetQuestion(ctx context.Context, req *rspb.QuicklyGetQuestionReq) (*rspb.QuicklyGetQuestionResp, error) { question, err := repository.NewQuestionDao(ctx, s.query).FindByRandom(0) if err != nil { return nil, utils.ErrorsWrap(err) @@ -23,7 +22,7 @@ func (s *Server) QuicklyGetQuestion(ctx context.Context, req *grpc_pb.QuicklyGet return nil, utils.ErrorsWrapF(err, "data: %v", question.Options) } category, _ := repository.NewCategoryDao(ctx, s.query).FindNameBySn(question.CategorySn) - return &grpc_pb.QuicklyGetQuestionResp{ + return &rspb.QuicklyGetQuestionResp{ Sn: question.Sn, Question: question.Question, Options: options, @@ -33,7 +32,7 @@ func (s *Server) QuicklyGetQuestion(ctx context.Context, req *grpc_pb.QuicklyGet } // QuicklyAnswerQuestion 回答题目 -func (s *Server) QuicklyAnswerQuestion(ctx context.Context, req *grpc_pb.QuicklyAnswerQuestionReq) (*grpc_pb.QuicklyAnswerQuestionResp, error) { +func (s *Server) QuicklyAnswerQuestion(ctx context.Context, req *rspb.QuicklyAnswerQuestionReq) (*rspb.QuicklyAnswerQuestionResp, error) { utils.ShouldBindUsn(ctx, &req.USN) question, err := repository.NewQuestionDao(ctx, s.query).FindBySn(req.Sn) @@ -46,7 +45,7 @@ func (s *Server) QuicklyAnswerQuestion(ctx context.Context, req *grpc_pb.Quickly } // 保存答题记录 if req.USN != 0 { - kafka.NewProducer().Produce(ctx, &timer.TopicQuestionAnswer{ + kafka.NewProducer().Produce(ctx, &kafka.TopicQuestionAnswer{ MessageSn: utils.SnowflakeInstance().Generate().Int64(), USN: req.USN, QuestionSn: question.Sn, @@ -54,7 +53,7 @@ func (s *Server) QuicklyAnswerQuestion(ctx context.Context, req *grpc_pb.Quickly Answer: req.Answer, }) } - return &grpc_pb.QuicklyAnswerQuestionResp{ + return &rspb.QuicklyAnswerQuestionResp{ Answer: question.Answer, Explanation: question.Explanation, }, nil diff --git a/internal/grpc_server/server_random.go b/internal/grpcserver/server_random.go similarity index 75% rename from internal/grpc_server/server_random.go rename to internal/grpcserver/server_random.go index 65965cb..0fc480b 100644 --- a/internal/grpc_server/server_random.go +++ b/internal/grpcserver/server_random.go @@ -1,19 +1,18 @@ -package grpc_server +package grpcserver import ( "context" "encoding/json" "git.hlsq.asia/mmorpg/service-common/db/kafka" - "git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb" + "git.hlsq.asia/mmorpg/service-common/proto/rs/rspb" "git.hlsq.asia/mmorpg/service-common/utils" "git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/repository" - "git.hlsq.asia/mmorpg/service-qgdzs/internal/timer" ) // 玩法 - 随机答题 // RandomGetQuestion 获取题目 -func (s *Server) RandomGetQuestion(ctx context.Context, req *grpc_pb.RandomGetQuestionReq) (*grpc_pb.RandomGetQuestionResp, error) { +func (s *Server) RandomGetQuestion(ctx context.Context, req *rspb.RandomGetQuestionReq) (*rspb.RandomGetQuestionResp, error) { question, err := repository.NewQuestionDao(ctx, s.query).FindByRandom(0) if err != nil { return nil, utils.ErrorsWrap(err) @@ -23,7 +22,7 @@ func (s *Server) RandomGetQuestion(ctx context.Context, req *grpc_pb.RandomGetQu return nil, utils.ErrorsWrapF(err, "data: %v", question.Options) } category, _ := repository.NewCategoryDao(ctx, s.query).FindNameBySn(question.CategorySn) - return &grpc_pb.RandomGetQuestionResp{ + return &rspb.RandomGetQuestionResp{ Sn: question.Sn, Question: question.Question, Options: options, @@ -33,7 +32,7 @@ func (s *Server) RandomGetQuestion(ctx context.Context, req *grpc_pb.RandomGetQu } // RandomAnswerQuestion 回答题目 -func (s *Server) RandomAnswerQuestion(ctx context.Context, req *grpc_pb.RandomAnswerQuestionReq) (*grpc_pb.RandomAnswerQuestionResp, error) { +func (s *Server) RandomAnswerQuestion(ctx context.Context, req *rspb.RandomAnswerQuestionReq) (*rspb.RandomAnswerQuestionResp, error) { utils.ShouldBindUsn(ctx, &req.USN) question, err := repository.NewQuestionDao(ctx, s.query).FindBySn(req.Sn) @@ -46,7 +45,7 @@ func (s *Server) RandomAnswerQuestion(ctx context.Context, req *grpc_pb.RandomAn } // 保存答题记录 if req.USN != 0 { - kafka.NewProducer().Produce(ctx, &timer.TopicQuestionAnswer{ + kafka.NewProducer().Produce(ctx, &kafka.TopicQuestionAnswer{ MessageSn: utils.SnowflakeInstance().Generate().Int64(), USN: req.USN, QuestionSn: question.Sn, @@ -56,15 +55,15 @@ func (s *Server) RandomAnswerQuestion(ctx context.Context, req *grpc_pb.RandomAn // 随机答题正确给10分,错误不得分 if req.Answer == question.Answer { - kafka.NewProducer().Produce(ctx, &timer.TopicAddPoint{ + kafka.NewProducer().Produce(ctx, &kafka.TopicAddPoint{ MessageSn: utils.SnowflakeInstance().Generate().Int64(), - Source: timer.AddPointSourceRandom, + Source: kafka.AddPointSourceRandom, USN: req.USN, Point: 10, }) } } - return &grpc_pb.RandomAnswerQuestionResp{ + return &rspb.RandomAnswerQuestionResp{ Answer: question.Answer, Explanation: question.Explanation, }, nil diff --git a/internal/grpc_server/server_record.go b/internal/grpcserver/server_record.go similarity index 71% rename from internal/grpc_server/server_record.go rename to internal/grpcserver/server_record.go index 11cb1e1..b9363f6 100644 --- a/internal/grpc_server/server_record.go +++ b/internal/grpcserver/server_record.go @@ -1,10 +1,10 @@ -package grpc_server +package grpcserver import ( "context" "encoding/json" - "git.hlsq.asia/mmorpg/service-common/net/http/http_resp" - "git.hlsq.asia/mmorpg/service-common/proto/rs/grpc_pb" + "git.hlsq.asia/mmorpg/service-common/net/http/httpresp" + "git.hlsq.asia/mmorpg/service-common/proto/rs/rspb" "git.hlsq.asia/mmorpg/service-common/utils" "git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/repository" ) @@ -12,17 +12,17 @@ import ( // 模块 - 答题记录 // GetRecord 获取答题记录 -func (s *Server) GetRecord(ctx context.Context, req *grpc_pb.GetRecordReq) (*grpc_pb.GetRecordResp, error) { +func (s *Server) GetRecord(ctx context.Context, req *rspb.GetRecordReq) (*rspb.GetRecordResp, error) { if !utils.ShouldBindUsn(ctx, &req.USN) { - return nil, http_resp.ParamError + return nil, httpresp.ParamError } records, count, err := repository.NewRecordDao(ctx, s.query).FindByUSN(req.USN, int(req.Page), int(req.PageSize)) if err != nil { return nil, utils.ErrorsWrap(err) } - resp := make([]*grpc_pb.GetRecordItem, 0) + resp := make([]*rspb.GetRecordItem, 0) for _, record := range records { - resp = append(resp, &grpc_pb.GetRecordItem{ + resp = append(resp, &rspb.GetRecordItem{ QuestionSn: record.QuestionSn, Question: record.Question, Difficulty: record.Difficulty, @@ -32,14 +32,14 @@ func (s *Server) GetRecord(ctx context.Context, req *grpc_pb.GetRecordReq) (*grp CreateTime: record.CreatedAt.Unix(), }) } - return &grpc_pb.GetRecordResp{ + return &rspb.GetRecordResp{ Count: int32(count), Records: resp, }, nil } // GetQuestionInfo 获取具体的题目 -func (s *Server) GetQuestionInfo(ctx context.Context, req *grpc_pb.GetQuestionInfoReq) (*grpc_pb.GetQuestionInfoResp, error) { +func (s *Server) GetQuestionInfo(ctx context.Context, req *rspb.GetQuestionInfoReq) (*rspb.GetQuestionInfoResp, error) { question, err := repository.NewQuestionDao(ctx, s.query).FindBySn(req.QuestionSn) if err != nil { return nil, utils.ErrorsWrap(err) @@ -49,7 +49,7 @@ func (s *Server) GetQuestionInfo(ctx context.Context, req *grpc_pb.GetQuestionIn return nil, utils.ErrorsWrapF(err, "data: %v", question.Options) } category, _ := repository.NewCategoryDao(ctx, s.query).FindNameBySn(question.CategorySn) - return &grpc_pb.GetQuestionInfoResp{ + return &rspb.GetQuestionInfoResp{ Question: question.Question, Options: options, Category: category, diff --git a/internal/timer/consumer.go b/internal/timer/consumer.go index 240fcdd..9bb75f0 100644 --- a/internal/timer/consumer.go +++ b/internal/timer/consumer.go @@ -20,15 +20,7 @@ func startConsumer() { } type TopicQuestionAnswer struct { - MessageSn int64 `json:"messageSn"` - USN int64 `json:"usn"` - QuestionSn int64 `json:"questionSn"` - QuestionAnswer string `json:"questionAnswer"` - Answer string `json:"answer"` -} - -func (t *TopicQuestionAnswer) Name() string { - return "qgdzs.question.answer" + kafka.TopicQuestionAnswer } func (t *TopicQuestionAnswer) OnMessage(ctx context.Context) error { @@ -60,23 +52,7 @@ func (t *TopicQuestionAnswer) OnMessage(ctx context.Context) error { } type TopicAddPoint struct { - MessageSn int64 `json:"messageSn"` - Source AddPointSource `json:"source"` - USN int64 `json:"usn"` - Point int64 `json:"point"` -} - -type AddPointSource int32 - -const ( - AddPointSourceUnKnown = 0 - AddPointSourceRandom = 1 - AddPointSourceCategory = 2 - AddPointSourceQuickly = 3 -) - -func (t *TopicAddPoint) Name() string { - return "qgdzs.user.point" + kafka.TopicAddPoint } func (t *TopicAddPoint) OnMessage(ctx context.Context) error {