feat sn 改成 int64

This commit is contained in:
2026-01-30 11:56:12 +08:00
parent 39fa373c01
commit 36621140f8
21 changed files with 81 additions and 81 deletions

View File

@@ -40,7 +40,7 @@ func (d *CategoryDao) FindAll() ([]*model.Category, error) {
return find, nil
}
func (d *CategoryDao) FindNameBySn(sn string) (string, error) {
func (d *CategoryDao) FindNameBySn(sn int64) (string, error) {
first, err := d.query.Category.WithContext(d.ctx).
Select(d.query.Category.Category).
Where(d.query.Category.Sn.Eq(sn)).
@@ -51,13 +51,13 @@ func (d *CategoryDao) FindNameBySn(sn string) (string, error) {
return first.Category, nil
}
func (d *CategoryDao) FindSnByName(category string) (string, error) {
func (d *CategoryDao) FindSnByName(category string) (int64, error) {
first, err := d.query.Category.WithContext(d.ctx).
Select(d.query.Category.Sn).
Where(d.query.Category.Category.Eq(category)).
First()
if err != nil {
return "", err
return 0, err
}
return first.Sn, nil
}

View File

@@ -16,6 +16,6 @@ func Query() *query.Query {
return query.Use(mysql.GetDB(dbName))
}
func keyCacheBySn(sn string, tableName string) string {
func keyCacheBySn(sn int64, tableName string) string {
return fmt.Sprintf(cacheBySn, tableName, sn)
}

View File

@@ -32,7 +32,7 @@ func (d *PointCardDao) Create(pointCard *model.PointCard) (*model.PointCard, err
return pointCard, err
}
func (d *PointCardDao) IncrPointCard(usn string, point int64) error {
func (d *PointCardDao) IncrPointCard(usn int64, point int64) error {
info, err := d.query.PointCard.WithContext(d.ctx).
Where(d.query.PointCard.UserSn.Eq(usn)).
UpdateSimple(d.query.PointCard.Point.Add(point))
@@ -45,7 +45,7 @@ func (d *PointCardDao) IncrPointCard(usn string, point int64) error {
return nil
}
func (d *PointCardDao) FindByUserSn(usn string) (*model.PointCard, error) {
func (d *PointCardDao) FindByUserSn(usn int64) (*model.PointCard, error) {
return d.query.PointCard.WithContext(d.ctx).
Where(d.query.PointCard.UserSn.Eq(usn)).
First()

View File

@@ -33,9 +33,9 @@ func (d *QuestionDao) Create(question *model.Question) (*model.Question, error)
return question, err
}
func (d *QuestionDao) FindByRandom(categorySn string) (*model.Question, error) {
func (d *QuestionDao) FindByRandom(categorySn int64) (*model.Question, error) {
q := d.query.Question.WithContext(d.ctx)
if categorySn != "" {
if categorySn != 0 {
q = q.Where(d.query.Question.CategorySn.Eq(categorySn))
}
@@ -54,7 +54,7 @@ func (d *QuestionDao) FindByRandom(categorySn string) (*model.Question, error) {
return first, nil
}
func (d *QuestionDao) FindBySn(sn string) (*model.Question, error) {
func (d *QuestionDao) FindBySn(sn int64) (*model.Question, error) {
if d.cache != nil {
var question model.Question
if ok := d.cache.Get(d.ctx, keyCacheBySn(sn, question.TableName()), &question); ok {

View File

@@ -32,7 +32,7 @@ func (d *RecordDao) Create(record *model.Record) (*model.Record, error) {
}
type RecordItem struct {
QuestionSn string `gorm:"column:question_sn"`
QuestionSn int64 `gorm:"column:question_sn"`
Question string `gorm:"column:question"`
Difficulty int32 `gorm:"column:difficulty"`
Category string `gorm:"column:category"`
@@ -42,7 +42,7 @@ type RecordItem struct {
CreatedAt time.Time `gorm:"column:created_at"`
}
func (d *RecordDao) FindByUSN(usn string, page, pageSize int) ([]*RecordItem, int64, error) {
func (d *RecordDao) FindByUSN(usn int64, page, pageSize int) ([]*RecordItem, int64, error) {
result := make([]*RecordItem, 0)
count, err := d.query.Record.WithContext(d.ctx).
Select(