feat 修改usn类型为string

This commit is contained in:
2026-01-11 16:16:27 +08:00
parent 1b893cad87
commit 11141edcda
17 changed files with 1019 additions and 43 deletions

View File

@@ -0,0 +1,42 @@
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package model
import (
"time"
"git.hlsq.asia/mmorpg/service-common/utils"
"gorm.io/gorm"
)
const TableNameQuestion = "questions"
// Question mapped from table <questions>
type Question struct {
ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
Sn string `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
Question string `gorm:"column:question;not null;comment:题干" json:"question"` // 题干
Options string `gorm:"column:options;not null;comment:选项" json:"options"` // 选项
Answer string `gorm:"column:answer;not null;comment:答案" json:"answer"` // 答案
Explanation string `gorm:"column:explanation;not null;comment:解析" json:"explanation"` // 解析
Difficulty int32 `gorm:"column:difficulty;not null;comment:难度分 0 - 100" json:"difficulty"` // 难度分 0 - 100
Category string `gorm:"column:category;not null;comment:分类" json:"category"` // 分类
CreatedAt time.Time `gorm:"column:created_at;not null" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at;not null" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at" json:"deleted_at"`
}
// TableName Question's table name
func (*Question) TableName() string {
return TableNameQuestion
}
// Auto sn
func (m *Question) BeforeCreate(_ *gorm.DB) error {
if m.Sn == "" {
m.Sn = utils.SnowflakeInstance().Generate().String()
}
return nil
}

View File

@@ -5,9 +5,10 @@
package model
import (
"time"
"git.hlsq.asia/mmorpg/service-common/utils"
"gorm.io/gorm"
"time"
)
const TableNameUser = "users"
@@ -15,7 +16,7 @@ const TableNameUser = "users"
// User mapped from table <users>
type User struct {
ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
Sn int64 `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
Sn string `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
Name string `gorm:"column:name;not null" json:"name"`
Phone string `gorm:"column:phone;not null" json:"phone"`
CreatedAt time.Time `gorm:"column:created_at;not null" json:"created_at"`
@@ -28,10 +29,10 @@ func (*User) TableName() string {
return TableNameUser
}
// auto sn
// Auto sn
func (m *User) BeforeCreate(_ *gorm.DB) error {
if m.Sn == 0 {
m.Sn = utils.SnowflakeInstance().Generate().Int64()
if m.Sn == "" {
m.Sn = utils.SnowflakeInstance().Generate().String()
}
return nil
}