feat 废弃jwt 、 学识分

This commit is contained in:
2026-02-06 22:31:31 +08:00
parent 36621140f8
commit 96f0919c05
8 changed files with 84 additions and 39 deletions

View File

@@ -16,11 +16,10 @@ type Program struct {
}
func (p *Program) Init(_ svc.Environment) error {
base := &ModuleBase{}
if err := base.Init(); err != nil {
if err := config.LoadConfig(); err != nil {
return err
}
p.moduleList = append(p.moduleList, base)
p.moduleList = append(p.moduleList, (&module.Base{}).Bind(config.Get().Log))
p.moduleList = append(p.moduleList, (&module.DB{}).Bind(config.Get().DB, config.Get().App.Name))
p.moduleList = append(p.moduleList, (&module.Grpc{}).Bind(grpc_server.NewServer(config.Get().Serve.Grpc)))
p.moduleList = append(p.moduleList, &ModuleTimer{})
@@ -28,10 +27,7 @@ func (p *Program) Init(_ svc.Environment) error {
p.moduleList = append(p.moduleList, (&module.Tracer{}).Bind(config.Get().Metric, common.KeyDiscoverServiceNameQgdzs))
p.moduleList = append(p.moduleList, &module.Discover{})
for i, m := range p.moduleList {
if i == 0 {
continue
}
for _, m := range p.moduleList {
if err := m.Init(); err != nil {
return err
}

View File

@@ -1,27 +0,0 @@
package app
import (
"git.hlsq.asia/mmorpg/service-common/log"
"git.hlsq.asia/mmorpg/service-common/module"
"git.hlsq.asia/mmorpg/service-common/utils"
"git.hlsq.asia/mmorpg/service-qgdzs/config"
"math/rand"
)
// ModuleBase 基础模块,或者一些零散的模块
type ModuleBase struct {
module.DefaultModule
}
func (m *ModuleBase) Init() error {
// 配置
if err := config.LoadConfig(); err != nil {
return err
}
cfg := config.Get()
// 日志
log.Init(cfg.Log.Debug, cfg.Log.MaxSize, cfg.Log.MaxBackups, cfg.Log.MaxAge, cfg.Log.Level)
// 雪花
utils.InitSnowflake(int64(rand.Intn(1000)))
return nil
}

2
go.mod
View File

@@ -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-20260130035320-5dc5391b07ed
git.hlsq.asia/mmorpg/service-common v0.0.0-20260206142243-44ebbe444953
github.com/judwhite/go-svc v1.2.1
github.com/robfig/cron/v3 v3.0.1
google.golang.org/grpc v1.77.0

4
go.sum
View File

@@ -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-20260130035320-5dc5391b07ed h1:O08p0egfekFqQSnc4sfEJUTI5dGiEyiDRNW/VYa/Ce4=
git.hlsq.asia/mmorpg/service-common v0.0.0-20260130035320-5dc5391b07ed/go.mod h1:mMhZcumphj6gaVTppVYsMTkd+5HupmQgAc53Pd4MH9I=
git.hlsq.asia/mmorpg/service-common v0.0.0-20260206142243-44ebbe444953 h1:eqGH4SIEgwY7uVIiZrMwitHQEVPetDH9SFzWwIrtWzM=
git.hlsq.asia/mmorpg/service-common v0.0.0-20260206142243-44ebbe444953/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=

View File

@@ -45,8 +45,9 @@ func (d *PointCardDao) IncrPointCard(usn int64, point int64) error {
return nil
}
func (d *PointCardDao) FindByUserSn(usn int64) (*model.PointCard, error) {
func (d *PointCardDao) FindPointByUserSn(usn int64) (*model.PointCard, error) {
return d.query.PointCard.WithContext(d.ctx).
Select(d.query.PointCard.Point).
Where(d.query.PointCard.UserSn.Eq(usn)).
First()
}

View File

@@ -35,7 +35,7 @@ func (d *PointRecordsDao) CreateAndIncrPointCard(pointRecord *model.PointRecord)
}
pcd := NewPointCardDao(d.ctx, tx)
if _, err := pcd.FindByUserSn(pointRecord.UserSn); err != nil {
if _, err := pcd.FindPointByUserSn(pointRecord.UserSn); err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
_, err = pcd.Create(&model.PointCard{
UserSn: pointRecord.UserSn,
@@ -56,3 +56,20 @@ func (d *PointRecordsDao) CreateAndIncrPointCard(pointRecord *model.PointRecord)
return nil
})
}
func (d *PointRecordsDao) FindByUSN(usn int64, page, pageSize int) ([]*model.PointRecord, int64, error) {
result := make([]*model.PointRecord, 0)
count, err := d.query.PointRecord.WithContext(d.ctx).
Select(
d.query.PointRecord.Source,
d.query.PointRecord.Point,
d.query.PointRecord.CreatedAt,
).
Where(d.query.PointRecord.UserSn.Eq(usn)).
Order(d.query.PointRecord.CreatedAt.Desc()).
ScanByPage(&result, (page-1)*pageSize, pageSize)
if err != nil {
return nil, 0, err
}
return result, count, nil
}

View File

@@ -71,6 +71,16 @@ func (s *Server) CategoryAnswerQuestion(ctx context.Context, req *grpc_pb.Catego
QuestionAnswer: question.Answer,
Answer: req.Answer,
})
// 类目答题正确给5分错误不得分
if req.Answer == question.Answer {
kafka.NewProducer().Produce(ctx, &timer.TopicAddPoint{
MessageSn: utils.SnowflakeInstance().Generate().Int64(),
Source: timer.AddPointSourceCategory,
USN: req.USN,
Point: 5,
})
}
}
return &grpc_pb.CategoryAnswerQuestionResp{
Answer: question.Answer,

View File

@@ -0,0 +1,48 @@
package grpc_server
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/utils"
"git.hlsq.asia/mmorpg/service-qgdzs/internal/dao/repository"
)
// 模块 - 学识分
// GetPointRecord 获取学识分获取记录
func (s *Server) GetPointRecord(ctx context.Context, req *grpc_pb.GetPointRecordReq) (*grpc_pb.GetPointRecordResp, error) {
if !utils.ShouldBindUsn(ctx, &req.USN) {
return nil, http_resp.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)
for _, record := range records {
resp = append(resp, &grpc_pb.GetPointRecordItem{
Source: record.Source,
Point: record.Point,
CreateTime: record.CreatedAt.Unix(),
})
}
return &grpc_pb.GetPointRecordResp{
Count: int32(count),
Records: resp,
}, nil
}
// GetPoint 获取学识分
func (s *Server) GetPoint(ctx context.Context, req *grpc_pb.GetPointReq) (*grpc_pb.GetPointResp, error) {
if !utils.ShouldBindUsn(ctx, &req.USN) {
return nil, http_resp.ParamError
}
pointCard, err := repository.NewPointCardDao(ctx, s.query).FindPointByUserSn(req.USN)
if err != nil {
return nil, utils.ErrorsWrap(err)
}
return &grpc_pb.GetPointResp{
Point: pointCard.Point,
}, nil
}