feat usn 类型改成int64

This commit is contained in:
2026-01-30 14:48:38 +08:00
parent 7eae358996
commit 30864dbc40
29 changed files with 3032 additions and 854 deletions

View File

@@ -10,11 +10,11 @@ param(
Get-ChildItem ./${dbName}/model/*.gen.go | ForEach-Object {
$c = Get-Content $_.FullName -Raw -Encoding UTF8
if ($c -match '\bSn\s+string\b' -and $c -notmatch 'BeforeCreate') {
if ($c -match '\bSn\s+int64\b' -and $c -notmatch 'BeforeCreate') {
$c -match 'type\s+(\w+)\s+struct' | Out-Null
$n = $matches[1]
$c = $c -replace '(?s)(import\s*\([^)]*)', "`$1`t`"git.hlsq.asia/mmorpg/service-common/utils`"`n"
$hook = "`n`n// Auto sn`nfunc (m *$n) BeforeCreate(_ *gorm.DB) error {`n`tif m.Sn == `"`" {`n`t`tm.Sn = utils.SnowflakeInstance().Generate().String()`n`t}`n`treturn nil`n}"
$hook = "`n`n// Auto sn`nfunc (m *$n) BeforeCreate(_ *gorm.DB) error {`n`tif m.Sn == 0 {`n`t`tm.Sn = utils.SnowflakeInstance().Generate().Int64()`n`t}`n`treturn nil`n}"
Set-Content $_.FullName ($c.TrimEnd() + $hook) -Encoding UTF8
}
}

View File

@@ -16,7 +16,7 @@ const TableNameCategory = "categories"
// Category mapped from table <categories>
type Category struct {
ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
Sn string `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
Sn int64 `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
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"`
@@ -30,8 +30,8 @@ func (*Category) TableName() string {
// Auto sn
func (m *Category) BeforeCreate(_ *gorm.DB) error {
if m.Sn == "" {
m.Sn = utils.SnowflakeInstance().Generate().String()
if m.Sn == 0 {
m.Sn = utils.SnowflakeInstance().Generate().Int64()
}
return nil
}

View File

@@ -0,0 +1,38 @@
// 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 TableNamePointCard = "point_card"
// PointCard mapped from table <point_card>
type PointCard struct {
ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
Sn int64 `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
UserSn int64 `gorm:"column:user_sn;not null;comment:用户-唯一编号" json:"user_sn"` // 用户-唯一编号
Point int64 `gorm:"column:point;not null;comment:积分" json:"point"` // 积分
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 PointCard's table name
func (*PointCard) TableName() string {
return TableNamePointCard
}
// Auto sn
func (m *PointCard) BeforeCreate(_ *gorm.DB) error {
if m.Sn == 0 {
m.Sn = utils.SnowflakeInstance().Generate().Int64()
}
return nil
}

View File

@@ -0,0 +1,46 @@
// 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 TableNamePointRecord = "point_records"
// PointRecord mapped from table <point_records>
type PointRecord struct {
ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
Sn int64 `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
UserSn int64 `gorm:"column:user_sn;not null;comment:用户-唯一编号" json:"user_sn"` // 用户-唯一编号
/*
来源:
0. 未知
1. 随机答题
2. 类目答题
3. 限时答题
*/
Source int32 `gorm:"column:source;not null;comment:来源:\n0. 未知\n1. 随机答题\n2. 类目答题\n3. 限时答题" json:"source"`
Point int64 `gorm:"column:point;not null;comment:积分" json:"point"` // 积分
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 PointRecord's table name
func (*PointRecord) TableName() string {
return TableNamePointRecord
}
// Auto sn
func (m *PointRecord) BeforeCreate(_ *gorm.DB) error {
if m.Sn == 0 {
m.Sn = utils.SnowflakeInstance().Generate().Int64()
}
return nil
}

View File

@@ -16,13 +16,13 @@ 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"` // 业务唯一编号
Sn int64 `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
CategorySn string `gorm:"column:category_sn;not null;comment:分类-唯一编号" json:"category_sn"` // 分类-唯一编号
CategorySn int64 `gorm:"column:category_sn;not null;comment:分类-唯一编号" json:"category_sn"` // 分类-唯一编号
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"`
@@ -35,8 +35,8 @@ func (*Question) TableName() string {
// Auto sn
func (m *Question) BeforeCreate(_ *gorm.DB) error {
if m.Sn == "" {
m.Sn = utils.SnowflakeInstance().Generate().String()
if m.Sn == 0 {
m.Sn = utils.SnowflakeInstance().Generate().Int64()
}
return nil
}

View File

@@ -16,9 +16,9 @@ const TableNameRecord = "records"
// Record mapped from table <records>
type Record struct {
ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
Sn string `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
UserSn string `gorm:"column:user_sn;not null;comment:用户-唯一编号" json:"user_sn"` // 用户-唯一编号
QuestionSn string `gorm:"column:question_sn;not null;comment:题目-唯一编号" json:"question_sn"` // 题目-唯一编号
Sn int64 `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
UserSn int64 `gorm:"column:user_sn;not null;comment:用户-唯一编号" json:"user_sn"` // 用户-唯一编号
QuestionSn int64 `gorm:"column:question_sn;not null;comment:题目-唯一编号" json:"question_sn"` // 题目-唯一编号
Answer string `gorm:"column:answer;not null;comment:答案" json:"answer"` // 答案
IsCorrect int32 `gorm:"column:is_correct;not null;comment:是否正确 0 否 1 是" json:"is_correct"` // 是否正确 0 否 1 是
CreatedAt time.Time `gorm:"column:created_at;not null" json:"created_at"`
@@ -33,8 +33,8 @@ func (*Record) TableName() string {
// Auto sn
func (m *Record) BeforeCreate(_ *gorm.DB) error {
if m.Sn == "" {
m.Sn = utils.SnowflakeInstance().Generate().String()
if m.Sn == 0 {
m.Sn = utils.SnowflakeInstance().Generate().Int64()
}
return nil
}

View File

@@ -28,7 +28,7 @@ func newCategory(db *gorm.DB, opts ...gen.DOOption) category {
tableName := _category.categoryDo.TableName()
_category.ALL = field.NewAsterisk(tableName)
_category.ID = field.NewUint64(tableName, "id")
_category.Sn = field.NewString(tableName, "sn")
_category.Sn = field.NewInt64(tableName, "sn")
_category.Category = field.NewString(tableName, "category")
_category.CreatedAt = field.NewTime(tableName, "created_at")
_category.UpdatedAt = field.NewTime(tableName, "updated_at")
@@ -44,7 +44,7 @@ type category struct {
ALL field.Asterisk
ID field.Uint64
Sn field.String // 业务唯一编号
Sn field.Int64 // 业务唯一编号
Category field.String // 分类
CreatedAt field.Time
UpdatedAt field.Time
@@ -66,7 +66,7 @@ func (c category) As(alias string) *category {
func (c *category) updateTableName(table string) *category {
c.ALL = field.NewAsterisk(table)
c.ID = field.NewUint64(table, "id")
c.Sn = field.NewString(table, "sn")
c.Sn = field.NewInt64(table, "sn")
c.Category = field.NewString(table, "category")
c.CreatedAt = field.NewTime(table, "created_at")
c.UpdatedAt = field.NewTime(table, "updated_at")

View File

@@ -17,29 +17,35 @@ import (
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
return &Query{
db: db,
Category: newCategory(db, opts...),
Question: newQuestion(db, opts...),
Record: newRecord(db, opts...),
db: db,
Category: newCategory(db, opts...),
PointCard: newPointCard(db, opts...),
PointRecord: newPointRecord(db, opts...),
Question: newQuestion(db, opts...),
Record: newRecord(db, opts...),
}
}
type Query struct {
db *gorm.DB
Category category
Question question
Record record
Category category
PointCard pointCard
PointRecord pointRecord
Question question
Record record
}
func (q *Query) Available() bool { return q.db != nil }
func (q *Query) clone(db *gorm.DB) *Query {
return &Query{
db: db,
Category: q.Category.clone(db),
Question: q.Question.clone(db),
Record: q.Record.clone(db),
db: db,
Category: q.Category.clone(db),
PointCard: q.PointCard.clone(db),
PointRecord: q.PointRecord.clone(db),
Question: q.Question.clone(db),
Record: q.Record.clone(db),
}
}
@@ -53,24 +59,30 @@ func (q *Query) WriteDB() *Query {
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
return &Query{
db: db,
Category: q.Category.replaceDB(db),
Question: q.Question.replaceDB(db),
Record: q.Record.replaceDB(db),
db: db,
Category: q.Category.replaceDB(db),
PointCard: q.PointCard.replaceDB(db),
PointRecord: q.PointRecord.replaceDB(db),
Question: q.Question.replaceDB(db),
Record: q.Record.replaceDB(db),
}
}
type queryCtx struct {
Category *categoryDo
Question *questionDo
Record *recordDo
Category *categoryDo
PointCard *pointCardDo
PointRecord *pointRecordDo
Question *questionDo
Record *recordDo
}
func (q *Query) WithContext(ctx context.Context) *queryCtx {
return &queryCtx{
Category: q.Category.WithContext(ctx),
Question: q.Question.WithContext(ctx),
Record: q.Record.WithContext(ctx),
Category: q.Category.WithContext(ctx),
PointCard: q.PointCard.WithContext(ctx),
PointRecord: q.PointRecord.WithContext(ctx),
Question: q.Question.WithContext(ctx),
Record: q.Record.WithContext(ctx),
}
}

View File

@@ -0,0 +1,353 @@
// 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 query
import (
"context"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"git.hlsq.asia/mmorpg/qgdzs_db/model"
)
func newPointCard(db *gorm.DB, opts ...gen.DOOption) pointCard {
_pointCard := pointCard{}
_pointCard.pointCardDo.UseDB(db, opts...)
_pointCard.pointCardDo.UseModel(&model.PointCard{})
tableName := _pointCard.pointCardDo.TableName()
_pointCard.ALL = field.NewAsterisk(tableName)
_pointCard.ID = field.NewUint64(tableName, "id")
_pointCard.Sn = field.NewInt64(tableName, "sn")
_pointCard.UserSn = field.NewInt64(tableName, "user_sn")
_pointCard.Point = field.NewInt64(tableName, "point")
_pointCard.CreatedAt = field.NewTime(tableName, "created_at")
_pointCard.UpdatedAt = field.NewTime(tableName, "updated_at")
_pointCard.DeletedAt = field.NewField(tableName, "deleted_at")
_pointCard.fillFieldMap()
return _pointCard
}
type pointCard struct {
pointCardDo pointCardDo
ALL field.Asterisk
ID field.Uint64
Sn field.Int64 // 业务唯一编号
UserSn field.Int64 // 用户-唯一编号
Point field.Int64 // 积分
CreatedAt field.Time
UpdatedAt field.Time
DeletedAt field.Field
fieldMap map[string]field.Expr
}
func (p pointCard) Table(newTableName string) *pointCard {
p.pointCardDo.UseTable(newTableName)
return p.updateTableName(newTableName)
}
func (p pointCard) As(alias string) *pointCard {
p.pointCardDo.DO = *(p.pointCardDo.As(alias).(*gen.DO))
return p.updateTableName(alias)
}
func (p *pointCard) updateTableName(table string) *pointCard {
p.ALL = field.NewAsterisk(table)
p.ID = field.NewUint64(table, "id")
p.Sn = field.NewInt64(table, "sn")
p.UserSn = field.NewInt64(table, "user_sn")
p.Point = field.NewInt64(table, "point")
p.CreatedAt = field.NewTime(table, "created_at")
p.UpdatedAt = field.NewTime(table, "updated_at")
p.DeletedAt = field.NewField(table, "deleted_at")
p.fillFieldMap()
return p
}
func (p *pointCard) WithContext(ctx context.Context) *pointCardDo {
return p.pointCardDo.WithContext(ctx)
}
func (p pointCard) TableName() string { return p.pointCardDo.TableName() }
func (p pointCard) Alias() string { return p.pointCardDo.Alias() }
func (p pointCard) Columns(cols ...field.Expr) gen.Columns { return p.pointCardDo.Columns(cols...) }
func (p *pointCard) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := p.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (p *pointCard) fillFieldMap() {
p.fieldMap = make(map[string]field.Expr, 7)
p.fieldMap["id"] = p.ID
p.fieldMap["sn"] = p.Sn
p.fieldMap["user_sn"] = p.UserSn
p.fieldMap["point"] = p.Point
p.fieldMap["created_at"] = p.CreatedAt
p.fieldMap["updated_at"] = p.UpdatedAt
p.fieldMap["deleted_at"] = p.DeletedAt
}
func (p pointCard) clone(db *gorm.DB) pointCard {
p.pointCardDo.ReplaceConnPool(db.Statement.ConnPool)
return p
}
func (p pointCard) replaceDB(db *gorm.DB) pointCard {
p.pointCardDo.ReplaceDB(db)
return p
}
type pointCardDo struct{ gen.DO }
func (p pointCardDo) Debug() *pointCardDo {
return p.withDO(p.DO.Debug())
}
func (p pointCardDo) WithContext(ctx context.Context) *pointCardDo {
return p.withDO(p.DO.WithContext(ctx))
}
func (p pointCardDo) ReadDB() *pointCardDo {
return p.Clauses(dbresolver.Read)
}
func (p pointCardDo) WriteDB() *pointCardDo {
return p.Clauses(dbresolver.Write)
}
func (p pointCardDo) Session(config *gorm.Session) *pointCardDo {
return p.withDO(p.DO.Session(config))
}
func (p pointCardDo) Clauses(conds ...clause.Expression) *pointCardDo {
return p.withDO(p.DO.Clauses(conds...))
}
func (p pointCardDo) Returning(value interface{}, columns ...string) *pointCardDo {
return p.withDO(p.DO.Returning(value, columns...))
}
func (p pointCardDo) Not(conds ...gen.Condition) *pointCardDo {
return p.withDO(p.DO.Not(conds...))
}
func (p pointCardDo) Or(conds ...gen.Condition) *pointCardDo {
return p.withDO(p.DO.Or(conds...))
}
func (p pointCardDo) Select(conds ...field.Expr) *pointCardDo {
return p.withDO(p.DO.Select(conds...))
}
func (p pointCardDo) Where(conds ...gen.Condition) *pointCardDo {
return p.withDO(p.DO.Where(conds...))
}
func (p pointCardDo) Order(conds ...field.Expr) *pointCardDo {
return p.withDO(p.DO.Order(conds...))
}
func (p pointCardDo) Distinct(cols ...field.Expr) *pointCardDo {
return p.withDO(p.DO.Distinct(cols...))
}
func (p pointCardDo) Omit(cols ...field.Expr) *pointCardDo {
return p.withDO(p.DO.Omit(cols...))
}
func (p pointCardDo) Join(table schema.Tabler, on ...field.Expr) *pointCardDo {
return p.withDO(p.DO.Join(table, on...))
}
func (p pointCardDo) LeftJoin(table schema.Tabler, on ...field.Expr) *pointCardDo {
return p.withDO(p.DO.LeftJoin(table, on...))
}
func (p pointCardDo) RightJoin(table schema.Tabler, on ...field.Expr) *pointCardDo {
return p.withDO(p.DO.RightJoin(table, on...))
}
func (p pointCardDo) Group(cols ...field.Expr) *pointCardDo {
return p.withDO(p.DO.Group(cols...))
}
func (p pointCardDo) Having(conds ...gen.Condition) *pointCardDo {
return p.withDO(p.DO.Having(conds...))
}
func (p pointCardDo) Limit(limit int) *pointCardDo {
return p.withDO(p.DO.Limit(limit))
}
func (p pointCardDo) Offset(offset int) *pointCardDo {
return p.withDO(p.DO.Offset(offset))
}
func (p pointCardDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *pointCardDo {
return p.withDO(p.DO.Scopes(funcs...))
}
func (p pointCardDo) Unscoped() *pointCardDo {
return p.withDO(p.DO.Unscoped())
}
func (p pointCardDo) Create(values ...*model.PointCard) error {
if len(values) == 0 {
return nil
}
return p.DO.Create(values)
}
func (p pointCardDo) CreateInBatches(values []*model.PointCard, batchSize int) error {
return p.DO.CreateInBatches(values, batchSize)
}
// Save : !!! underlying implementation is different with GORM
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
func (p pointCardDo) Save(values ...*model.PointCard) error {
if len(values) == 0 {
return nil
}
return p.DO.Save(values)
}
func (p pointCardDo) First() (*model.PointCard, error) {
if result, err := p.DO.First(); err != nil {
return nil, err
} else {
return result.(*model.PointCard), nil
}
}
func (p pointCardDo) Take() (*model.PointCard, error) {
if result, err := p.DO.Take(); err != nil {
return nil, err
} else {
return result.(*model.PointCard), nil
}
}
func (p pointCardDo) Last() (*model.PointCard, error) {
if result, err := p.DO.Last(); err != nil {
return nil, err
} else {
return result.(*model.PointCard), nil
}
}
func (p pointCardDo) Find() ([]*model.PointCard, error) {
result, err := p.DO.Find()
return result.([]*model.PointCard), err
}
func (p pointCardDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.PointCard, err error) {
buf := make([]*model.PointCard, 0, batchSize)
err = p.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
defer func() { results = append(results, buf...) }()
return fc(tx, batch)
})
return results, err
}
func (p pointCardDo) FindInBatches(result *[]*model.PointCard, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return p.DO.FindInBatches(result, batchSize, fc)
}
func (p pointCardDo) Attrs(attrs ...field.AssignExpr) *pointCardDo {
return p.withDO(p.DO.Attrs(attrs...))
}
func (p pointCardDo) Assign(attrs ...field.AssignExpr) *pointCardDo {
return p.withDO(p.DO.Assign(attrs...))
}
func (p pointCardDo) Joins(fields ...field.RelationField) *pointCardDo {
for _, _f := range fields {
p = *p.withDO(p.DO.Joins(_f))
}
return &p
}
func (p pointCardDo) Preload(fields ...field.RelationField) *pointCardDo {
for _, _f := range fields {
p = *p.withDO(p.DO.Preload(_f))
}
return &p
}
func (p pointCardDo) FirstOrInit() (*model.PointCard, error) {
if result, err := p.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*model.PointCard), nil
}
}
func (p pointCardDo) FirstOrCreate() (*model.PointCard, error) {
if result, err := p.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*model.PointCard), nil
}
}
func (p pointCardDo) FindByPage(offset int, limit int) (result []*model.PointCard, count int64, err error) {
result, err = p.Offset(offset).Limit(limit).Find()
if err != nil {
return
}
if size := len(result); 0 < limit && 0 < size && size < limit {
count = int64(size + offset)
return
}
count, err = p.Offset(-1).Limit(-1).Count()
return
}
func (p pointCardDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = p.Count()
if err != nil {
return
}
err = p.Offset(offset).Limit(limit).Scan(result)
return
}
func (p pointCardDo) Scan(result interface{}) (err error) {
return p.DO.Scan(result)
}
func (p pointCardDo) Delete(models ...*model.PointCard) (result gen.ResultInfo, err error) {
return p.DO.Delete(models)
}
func (p *pointCardDo) withDO(do gen.Dao) *pointCardDo {
p.DO = *do.(*gen.DO)
return p
}

View File

@@ -0,0 +1,364 @@
// 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 query
import (
"context"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"git.hlsq.asia/mmorpg/qgdzs_db/model"
)
func newPointRecord(db *gorm.DB, opts ...gen.DOOption) pointRecord {
_pointRecord := pointRecord{}
_pointRecord.pointRecordDo.UseDB(db, opts...)
_pointRecord.pointRecordDo.UseModel(&model.PointRecord{})
tableName := _pointRecord.pointRecordDo.TableName()
_pointRecord.ALL = field.NewAsterisk(tableName)
_pointRecord.ID = field.NewUint64(tableName, "id")
_pointRecord.Sn = field.NewInt64(tableName, "sn")
_pointRecord.UserSn = field.NewInt64(tableName, "user_sn")
_pointRecord.Source = field.NewInt32(tableName, "source")
_pointRecord.Point = field.NewInt64(tableName, "point")
_pointRecord.CreatedAt = field.NewTime(tableName, "created_at")
_pointRecord.UpdatedAt = field.NewTime(tableName, "updated_at")
_pointRecord.DeletedAt = field.NewField(tableName, "deleted_at")
_pointRecord.fillFieldMap()
return _pointRecord
}
type pointRecord struct {
pointRecordDo pointRecordDo
ALL field.Asterisk
ID field.Uint64
Sn field.Int64 // 业务唯一编号
UserSn field.Int64 // 用户-唯一编号
/*
来源:
0. 未知
1. 随机答题
2. 类目答题
3. 限时答题
*/
Source field.Int32
Point field.Int64 // 积分
CreatedAt field.Time
UpdatedAt field.Time
DeletedAt field.Field
fieldMap map[string]field.Expr
}
func (p pointRecord) Table(newTableName string) *pointRecord {
p.pointRecordDo.UseTable(newTableName)
return p.updateTableName(newTableName)
}
func (p pointRecord) As(alias string) *pointRecord {
p.pointRecordDo.DO = *(p.pointRecordDo.As(alias).(*gen.DO))
return p.updateTableName(alias)
}
func (p *pointRecord) updateTableName(table string) *pointRecord {
p.ALL = field.NewAsterisk(table)
p.ID = field.NewUint64(table, "id")
p.Sn = field.NewInt64(table, "sn")
p.UserSn = field.NewInt64(table, "user_sn")
p.Source = field.NewInt32(table, "source")
p.Point = field.NewInt64(table, "point")
p.CreatedAt = field.NewTime(table, "created_at")
p.UpdatedAt = field.NewTime(table, "updated_at")
p.DeletedAt = field.NewField(table, "deleted_at")
p.fillFieldMap()
return p
}
func (p *pointRecord) WithContext(ctx context.Context) *pointRecordDo {
return p.pointRecordDo.WithContext(ctx)
}
func (p pointRecord) TableName() string { return p.pointRecordDo.TableName() }
func (p pointRecord) Alias() string { return p.pointRecordDo.Alias() }
func (p pointRecord) Columns(cols ...field.Expr) gen.Columns { return p.pointRecordDo.Columns(cols...) }
func (p *pointRecord) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := p.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (p *pointRecord) fillFieldMap() {
p.fieldMap = make(map[string]field.Expr, 8)
p.fieldMap["id"] = p.ID
p.fieldMap["sn"] = p.Sn
p.fieldMap["user_sn"] = p.UserSn
p.fieldMap["source"] = p.Source
p.fieldMap["point"] = p.Point
p.fieldMap["created_at"] = p.CreatedAt
p.fieldMap["updated_at"] = p.UpdatedAt
p.fieldMap["deleted_at"] = p.DeletedAt
}
func (p pointRecord) clone(db *gorm.DB) pointRecord {
p.pointRecordDo.ReplaceConnPool(db.Statement.ConnPool)
return p
}
func (p pointRecord) replaceDB(db *gorm.DB) pointRecord {
p.pointRecordDo.ReplaceDB(db)
return p
}
type pointRecordDo struct{ gen.DO }
func (p pointRecordDo) Debug() *pointRecordDo {
return p.withDO(p.DO.Debug())
}
func (p pointRecordDo) WithContext(ctx context.Context) *pointRecordDo {
return p.withDO(p.DO.WithContext(ctx))
}
func (p pointRecordDo) ReadDB() *pointRecordDo {
return p.Clauses(dbresolver.Read)
}
func (p pointRecordDo) WriteDB() *pointRecordDo {
return p.Clauses(dbresolver.Write)
}
func (p pointRecordDo) Session(config *gorm.Session) *pointRecordDo {
return p.withDO(p.DO.Session(config))
}
func (p pointRecordDo) Clauses(conds ...clause.Expression) *pointRecordDo {
return p.withDO(p.DO.Clauses(conds...))
}
func (p pointRecordDo) Returning(value interface{}, columns ...string) *pointRecordDo {
return p.withDO(p.DO.Returning(value, columns...))
}
func (p pointRecordDo) Not(conds ...gen.Condition) *pointRecordDo {
return p.withDO(p.DO.Not(conds...))
}
func (p pointRecordDo) Or(conds ...gen.Condition) *pointRecordDo {
return p.withDO(p.DO.Or(conds...))
}
func (p pointRecordDo) Select(conds ...field.Expr) *pointRecordDo {
return p.withDO(p.DO.Select(conds...))
}
func (p pointRecordDo) Where(conds ...gen.Condition) *pointRecordDo {
return p.withDO(p.DO.Where(conds...))
}
func (p pointRecordDo) Order(conds ...field.Expr) *pointRecordDo {
return p.withDO(p.DO.Order(conds...))
}
func (p pointRecordDo) Distinct(cols ...field.Expr) *pointRecordDo {
return p.withDO(p.DO.Distinct(cols...))
}
func (p pointRecordDo) Omit(cols ...field.Expr) *pointRecordDo {
return p.withDO(p.DO.Omit(cols...))
}
func (p pointRecordDo) Join(table schema.Tabler, on ...field.Expr) *pointRecordDo {
return p.withDO(p.DO.Join(table, on...))
}
func (p pointRecordDo) LeftJoin(table schema.Tabler, on ...field.Expr) *pointRecordDo {
return p.withDO(p.DO.LeftJoin(table, on...))
}
func (p pointRecordDo) RightJoin(table schema.Tabler, on ...field.Expr) *pointRecordDo {
return p.withDO(p.DO.RightJoin(table, on...))
}
func (p pointRecordDo) Group(cols ...field.Expr) *pointRecordDo {
return p.withDO(p.DO.Group(cols...))
}
func (p pointRecordDo) Having(conds ...gen.Condition) *pointRecordDo {
return p.withDO(p.DO.Having(conds...))
}
func (p pointRecordDo) Limit(limit int) *pointRecordDo {
return p.withDO(p.DO.Limit(limit))
}
func (p pointRecordDo) Offset(offset int) *pointRecordDo {
return p.withDO(p.DO.Offset(offset))
}
func (p pointRecordDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *pointRecordDo {
return p.withDO(p.DO.Scopes(funcs...))
}
func (p pointRecordDo) Unscoped() *pointRecordDo {
return p.withDO(p.DO.Unscoped())
}
func (p pointRecordDo) Create(values ...*model.PointRecord) error {
if len(values) == 0 {
return nil
}
return p.DO.Create(values)
}
func (p pointRecordDo) CreateInBatches(values []*model.PointRecord, batchSize int) error {
return p.DO.CreateInBatches(values, batchSize)
}
// Save : !!! underlying implementation is different with GORM
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
func (p pointRecordDo) Save(values ...*model.PointRecord) error {
if len(values) == 0 {
return nil
}
return p.DO.Save(values)
}
func (p pointRecordDo) First() (*model.PointRecord, error) {
if result, err := p.DO.First(); err != nil {
return nil, err
} else {
return result.(*model.PointRecord), nil
}
}
func (p pointRecordDo) Take() (*model.PointRecord, error) {
if result, err := p.DO.Take(); err != nil {
return nil, err
} else {
return result.(*model.PointRecord), nil
}
}
func (p pointRecordDo) Last() (*model.PointRecord, error) {
if result, err := p.DO.Last(); err != nil {
return nil, err
} else {
return result.(*model.PointRecord), nil
}
}
func (p pointRecordDo) Find() ([]*model.PointRecord, error) {
result, err := p.DO.Find()
return result.([]*model.PointRecord), err
}
func (p pointRecordDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.PointRecord, err error) {
buf := make([]*model.PointRecord, 0, batchSize)
err = p.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
defer func() { results = append(results, buf...) }()
return fc(tx, batch)
})
return results, err
}
func (p pointRecordDo) FindInBatches(result *[]*model.PointRecord, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return p.DO.FindInBatches(result, batchSize, fc)
}
func (p pointRecordDo) Attrs(attrs ...field.AssignExpr) *pointRecordDo {
return p.withDO(p.DO.Attrs(attrs...))
}
func (p pointRecordDo) Assign(attrs ...field.AssignExpr) *pointRecordDo {
return p.withDO(p.DO.Assign(attrs...))
}
func (p pointRecordDo) Joins(fields ...field.RelationField) *pointRecordDo {
for _, _f := range fields {
p = *p.withDO(p.DO.Joins(_f))
}
return &p
}
func (p pointRecordDo) Preload(fields ...field.RelationField) *pointRecordDo {
for _, _f := range fields {
p = *p.withDO(p.DO.Preload(_f))
}
return &p
}
func (p pointRecordDo) FirstOrInit() (*model.PointRecord, error) {
if result, err := p.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*model.PointRecord), nil
}
}
func (p pointRecordDo) FirstOrCreate() (*model.PointRecord, error) {
if result, err := p.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*model.PointRecord), nil
}
}
func (p pointRecordDo) FindByPage(offset int, limit int) (result []*model.PointRecord, count int64, err error) {
result, err = p.Offset(offset).Limit(limit).Find()
if err != nil {
return
}
if size := len(result); 0 < limit && 0 < size && size < limit {
count = int64(size + offset)
return
}
count, err = p.Offset(-1).Limit(-1).Count()
return
}
func (p pointRecordDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = p.Count()
if err != nil {
return
}
err = p.Offset(offset).Limit(limit).Scan(result)
return
}
func (p pointRecordDo) Scan(result interface{}) (err error) {
return p.DO.Scan(result)
}
func (p pointRecordDo) Delete(models ...*model.PointRecord) (result gen.ResultInfo, err error) {
return p.DO.Delete(models)
}
func (p *pointRecordDo) withDO(do gen.Dao) *pointRecordDo {
p.DO = *do.(*gen.DO)
return p
}

View File

@@ -28,13 +28,13 @@ func newQuestion(db *gorm.DB, opts ...gen.DOOption) question {
tableName := _question.questionDo.TableName()
_question.ALL = field.NewAsterisk(tableName)
_question.ID = field.NewUint64(tableName, "id")
_question.Sn = field.NewString(tableName, "sn")
_question.Sn = field.NewInt64(tableName, "sn")
_question.Question = field.NewString(tableName, "question")
_question.Options = field.NewString(tableName, "options")
_question.Answer = field.NewString(tableName, "answer")
_question.Explanation = field.NewString(tableName, "explanation")
_question.Difficulty = field.NewInt32(tableName, "difficulty")
_question.CategorySn = field.NewString(tableName, "category_sn")
_question.CategorySn = field.NewInt64(tableName, "category_sn")
_question.CreatedAt = field.NewTime(tableName, "created_at")
_question.UpdatedAt = field.NewTime(tableName, "updated_at")
_question.DeletedAt = field.NewField(tableName, "deleted_at")
@@ -49,13 +49,13 @@ type question struct {
ALL field.Asterisk
ID field.Uint64
Sn field.String // 业务唯一编号
Sn field.Int64 // 业务唯一编号
Question field.String // 题干
Options field.String // 选项
Answer field.String // 答案
Explanation field.String // 解析
Difficulty field.Int32 // 难度分 0 - 100
CategorySn field.String // 分类-唯一编号
CategorySn field.Int64 // 分类-唯一编号
CreatedAt field.Time
UpdatedAt field.Time
DeletedAt field.Field
@@ -76,13 +76,13 @@ func (q question) As(alias string) *question {
func (q *question) updateTableName(table string) *question {
q.ALL = field.NewAsterisk(table)
q.ID = field.NewUint64(table, "id")
q.Sn = field.NewString(table, "sn")
q.Sn = field.NewInt64(table, "sn")
q.Question = field.NewString(table, "question")
q.Options = field.NewString(table, "options")
q.Answer = field.NewString(table, "answer")
q.Explanation = field.NewString(table, "explanation")
q.Difficulty = field.NewInt32(table, "difficulty")
q.CategorySn = field.NewString(table, "category_sn")
q.CategorySn = field.NewInt64(table, "category_sn")
q.CreatedAt = field.NewTime(table, "created_at")
q.UpdatedAt = field.NewTime(table, "updated_at")
q.DeletedAt = field.NewField(table, "deleted_at")

View File

@@ -28,9 +28,9 @@ func newRecord(db *gorm.DB, opts ...gen.DOOption) record {
tableName := _record.recordDo.TableName()
_record.ALL = field.NewAsterisk(tableName)
_record.ID = field.NewUint64(tableName, "id")
_record.Sn = field.NewString(tableName, "sn")
_record.UserSn = field.NewString(tableName, "user_sn")
_record.QuestionSn = field.NewString(tableName, "question_sn")
_record.Sn = field.NewInt64(tableName, "sn")
_record.UserSn = field.NewInt64(tableName, "user_sn")
_record.QuestionSn = field.NewInt64(tableName, "question_sn")
_record.Answer = field.NewString(tableName, "answer")
_record.IsCorrect = field.NewInt32(tableName, "is_correct")
_record.CreatedAt = field.NewTime(tableName, "created_at")
@@ -47,9 +47,9 @@ type record struct {
ALL field.Asterisk
ID field.Uint64
Sn field.String // 业务唯一编号
UserSn field.String // 用户-唯一编号
QuestionSn field.String // 题目-唯一编号
Sn field.Int64 // 业务唯一编号
UserSn field.Int64 // 用户-唯一编号
QuestionSn field.Int64 // 题目-唯一编号
Answer field.String // 答案
IsCorrect field.Int32 // 是否正确 0 否 1 是
CreatedAt field.Time
@@ -72,9 +72,9 @@ func (r record) As(alias string) *record {
func (r *record) updateTableName(table string) *record {
r.ALL = field.NewAsterisk(table)
r.ID = field.NewUint64(table, "id")
r.Sn = field.NewString(table, "sn")
r.UserSn = field.NewString(table, "user_sn")
r.QuestionSn = field.NewString(table, "question_sn")
r.Sn = field.NewInt64(table, "sn")
r.UserSn = field.NewInt64(table, "user_sn")
r.QuestionSn = field.NewInt64(table, "question_sn")
r.Answer = field.NewString(table, "answer")
r.IsCorrect = field.NewInt32(table, "is_correct")
r.CreatedAt = field.NewTime(table, "created_at")

View File

@@ -16,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 string `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
Sn int64 `gorm:"column:sn;not null;comment:业务唯一编号" json:"sn"` // 业务唯一编号
Name string `gorm:"column:name;not null" json:"name"`
Phone string `gorm:"column:phone" json:"phone"`
WxUnionID string `gorm:"column:wx_union_id;comment:微信用户唯一标识" json:"wx_union_id"` // 微信用户唯一标识
@@ -33,8 +33,8 @@ func (*User) TableName() string {
// Auto sn
func (m *User) BeforeCreate(_ *gorm.DB) error {
if m.Sn == "" {
m.Sn = utils.SnowflakeInstance().Generate().String()
if m.Sn == 0 {
m.Sn = utils.SnowflakeInstance().Generate().Int64()
}
return nil
}

View File

@@ -28,7 +28,7 @@ func newUser(db *gorm.DB, opts ...gen.DOOption) user {
tableName := _user.userDo.TableName()
_user.ALL = field.NewAsterisk(tableName)
_user.ID = field.NewUint64(tableName, "id")
_user.Sn = field.NewString(tableName, "sn")
_user.Sn = field.NewInt64(tableName, "sn")
_user.Name = field.NewString(tableName, "name")
_user.Phone = field.NewString(tableName, "phone")
_user.WxUnionID = field.NewString(tableName, "wx_union_id")
@@ -47,7 +47,7 @@ type user struct {
ALL field.Asterisk
ID field.Uint64
Sn field.String // 业务唯一编号
Sn field.Int64 // 业务唯一编号
Name field.String
Phone field.String
WxUnionID field.String // 微信用户唯一标识
@@ -72,7 +72,7 @@ func (u user) As(alias string) *user {
func (u *user) updateTableName(table string) *user {
u.ALL = field.NewAsterisk(table)
u.ID = field.NewUint64(table, "id")
u.Sn = field.NewString(table, "sn")
u.Sn = field.NewInt64(table, "sn")
u.Name = field.NewString(table, "name")
u.Phone = field.NewString(table, "phone")
u.WxUnionID = field.NewString(table, "wx_union_id")