feat 废弃jwt 、 学识分
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
48
internal/grpc_server/server_point.go
Normal file
48
internal/grpc_server/server_point.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user