feat 环境

This commit is contained in:
2026-01-24 11:15:41 +08:00
parent 4aa48a822e
commit 30ba2e8994
27 changed files with 3783 additions and 930 deletions

View File

@@ -1,42 +0,0 @@
// 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"
"gorm.io/gorm"
"git.hlsq.asia/mmorpg/service-common/utils"
)
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

@@ -1,4 +1,4 @@
// 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.
// Code generated by gorm.io/gen. DO NOT EDIT.
@@ -7,21 +7,23 @@ package model
import (
"time"
"gorm.io/gorm"
"git.hlsq.asia/mmorpg/service-common/utils"
"gorm.io/gorm"
)
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"` // 业务唯一编号
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"`
UpdatedAt time.Time `gorm:"column:updated_at;not null" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at" json:"deleted_at"`
ID uint64 `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
Sn string `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"` // 微信用户唯一标识
WxMiniOpenID string `gorm:"column:wx_mini_open_id;comment:微信小程序的openID" json:"wx_mini_open_id"` // 微信小程序的openID
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 User's table name

View File

@@ -17,26 +17,23 @@ import (
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
return &Query{
db: db,
Question: newQuestion(db, opts...),
User: newUser(db, opts...),
db: db,
User: newUser(db, opts...),
}
}
type Query struct {
db *gorm.DB
Question question
User user
User user
}
func (q *Query) Available() bool { return q.db != nil }
func (q *Query) clone(db *gorm.DB) *Query {
return &Query{
db: db,
Question: q.Question.clone(db),
User: q.User.clone(db),
db: db,
User: q.User.clone(db),
}
}
@@ -50,21 +47,18 @@ func (q *Query) WriteDB() *Query {
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
return &Query{
db: db,
Question: q.Question.replaceDB(db),
User: q.User.replaceDB(db),
db: db,
User: q.User.replaceDB(db),
}
}
type queryCtx struct {
Question *questionDo
User *userDo
User *userDo
}
func (q *Query) WithContext(ctx context.Context) *queryCtx {
return &queryCtx{
Question: q.Question.WithContext(ctx),
User: q.User.WithContext(ctx),
User: q.User.WithContext(ctx),
}
}

View File

@@ -1,367 +0,0 @@
// 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/user_db/model"
)
func newQuestion(db *gorm.DB, opts ...gen.DOOption) question {
_question := question{}
_question.questionDo.UseDB(db, opts...)
_question.questionDo.UseModel(&model.Question{})
tableName := _question.questionDo.TableName()
_question.ALL = field.NewAsterisk(tableName)
_question.ID = field.NewUint64(tableName, "id")
_question.Sn = field.NewString(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.Category = field.NewString(tableName, "category")
_question.CreatedAt = field.NewTime(tableName, "created_at")
_question.UpdatedAt = field.NewTime(tableName, "updated_at")
_question.DeletedAt = field.NewField(tableName, "deleted_at")
_question.fillFieldMap()
return _question
}
type question struct {
questionDo questionDo
ALL field.Asterisk
ID field.Uint64
Sn field.String // 业务唯一编号
Question field.String // 题干
Options field.String // 选项
Answer field.String // 答案
Explanation field.String // 解析
Difficulty field.Int32 // 难度分 0 - 100
Category field.String // 分类
CreatedAt field.Time
UpdatedAt field.Time
DeletedAt field.Field
fieldMap map[string]field.Expr
}
func (q question) Table(newTableName string) *question {
q.questionDo.UseTable(newTableName)
return q.updateTableName(newTableName)
}
func (q question) As(alias string) *question {
q.questionDo.DO = *(q.questionDo.As(alias).(*gen.DO))
return q.updateTableName(alias)
}
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.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.Category = field.NewString(table, "category")
q.CreatedAt = field.NewTime(table, "created_at")
q.UpdatedAt = field.NewTime(table, "updated_at")
q.DeletedAt = field.NewField(table, "deleted_at")
q.fillFieldMap()
return q
}
func (q *question) WithContext(ctx context.Context) *questionDo { return q.questionDo.WithContext(ctx) }
func (q question) TableName() string { return q.questionDo.TableName() }
func (q question) Alias() string { return q.questionDo.Alias() }
func (q question) Columns(cols ...field.Expr) gen.Columns { return q.questionDo.Columns(cols...) }
func (q *question) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := q.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (q *question) fillFieldMap() {
q.fieldMap = make(map[string]field.Expr, 11)
q.fieldMap["id"] = q.ID
q.fieldMap["sn"] = q.Sn
q.fieldMap["question"] = q.Question
q.fieldMap["options"] = q.Options
q.fieldMap["answer"] = q.Answer
q.fieldMap["explanation"] = q.Explanation
q.fieldMap["difficulty"] = q.Difficulty
q.fieldMap["category"] = q.Category
q.fieldMap["created_at"] = q.CreatedAt
q.fieldMap["updated_at"] = q.UpdatedAt
q.fieldMap["deleted_at"] = q.DeletedAt
}
func (q question) clone(db *gorm.DB) question {
q.questionDo.ReplaceConnPool(db.Statement.ConnPool)
return q
}
func (q question) replaceDB(db *gorm.DB) question {
q.questionDo.ReplaceDB(db)
return q
}
type questionDo struct{ gen.DO }
func (q questionDo) Debug() *questionDo {
return q.withDO(q.DO.Debug())
}
func (q questionDo) WithContext(ctx context.Context) *questionDo {
return q.withDO(q.DO.WithContext(ctx))
}
func (q questionDo) ReadDB() *questionDo {
return q.Clauses(dbresolver.Read)
}
func (q questionDo) WriteDB() *questionDo {
return q.Clauses(dbresolver.Write)
}
func (q questionDo) Session(config *gorm.Session) *questionDo {
return q.withDO(q.DO.Session(config))
}
func (q questionDo) Clauses(conds ...clause.Expression) *questionDo {
return q.withDO(q.DO.Clauses(conds...))
}
func (q questionDo) Returning(value interface{}, columns ...string) *questionDo {
return q.withDO(q.DO.Returning(value, columns...))
}
func (q questionDo) Not(conds ...gen.Condition) *questionDo {
return q.withDO(q.DO.Not(conds...))
}
func (q questionDo) Or(conds ...gen.Condition) *questionDo {
return q.withDO(q.DO.Or(conds...))
}
func (q questionDo) Select(conds ...field.Expr) *questionDo {
return q.withDO(q.DO.Select(conds...))
}
func (q questionDo) Where(conds ...gen.Condition) *questionDo {
return q.withDO(q.DO.Where(conds...))
}
func (q questionDo) Order(conds ...field.Expr) *questionDo {
return q.withDO(q.DO.Order(conds...))
}
func (q questionDo) Distinct(cols ...field.Expr) *questionDo {
return q.withDO(q.DO.Distinct(cols...))
}
func (q questionDo) Omit(cols ...field.Expr) *questionDo {
return q.withDO(q.DO.Omit(cols...))
}
func (q questionDo) Join(table schema.Tabler, on ...field.Expr) *questionDo {
return q.withDO(q.DO.Join(table, on...))
}
func (q questionDo) LeftJoin(table schema.Tabler, on ...field.Expr) *questionDo {
return q.withDO(q.DO.LeftJoin(table, on...))
}
func (q questionDo) RightJoin(table schema.Tabler, on ...field.Expr) *questionDo {
return q.withDO(q.DO.RightJoin(table, on...))
}
func (q questionDo) Group(cols ...field.Expr) *questionDo {
return q.withDO(q.DO.Group(cols...))
}
func (q questionDo) Having(conds ...gen.Condition) *questionDo {
return q.withDO(q.DO.Having(conds...))
}
func (q questionDo) Limit(limit int) *questionDo {
return q.withDO(q.DO.Limit(limit))
}
func (q questionDo) Offset(offset int) *questionDo {
return q.withDO(q.DO.Offset(offset))
}
func (q questionDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *questionDo {
return q.withDO(q.DO.Scopes(funcs...))
}
func (q questionDo) Unscoped() *questionDo {
return q.withDO(q.DO.Unscoped())
}
func (q questionDo) Create(values ...*model.Question) error {
if len(values) == 0 {
return nil
}
return q.DO.Create(values)
}
func (q questionDo) CreateInBatches(values []*model.Question, batchSize int) error {
return q.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 (q questionDo) Save(values ...*model.Question) error {
if len(values) == 0 {
return nil
}
return q.DO.Save(values)
}
func (q questionDo) First() (*model.Question, error) {
if result, err := q.DO.First(); err != nil {
return nil, err
} else {
return result.(*model.Question), nil
}
}
func (q questionDo) Take() (*model.Question, error) {
if result, err := q.DO.Take(); err != nil {
return nil, err
} else {
return result.(*model.Question), nil
}
}
func (q questionDo) Last() (*model.Question, error) {
if result, err := q.DO.Last(); err != nil {
return nil, err
} else {
return result.(*model.Question), nil
}
}
func (q questionDo) Find() ([]*model.Question, error) {
result, err := q.DO.Find()
return result.([]*model.Question), err
}
func (q questionDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Question, err error) {
buf := make([]*model.Question, 0, batchSize)
err = q.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 (q questionDo) FindInBatches(result *[]*model.Question, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return q.DO.FindInBatches(result, batchSize, fc)
}
func (q questionDo) Attrs(attrs ...field.AssignExpr) *questionDo {
return q.withDO(q.DO.Attrs(attrs...))
}
func (q questionDo) Assign(attrs ...field.AssignExpr) *questionDo {
return q.withDO(q.DO.Assign(attrs...))
}
func (q questionDo) Joins(fields ...field.RelationField) *questionDo {
for _, _f := range fields {
q = *q.withDO(q.DO.Joins(_f))
}
return &q
}
func (q questionDo) Preload(fields ...field.RelationField) *questionDo {
for _, _f := range fields {
q = *q.withDO(q.DO.Preload(_f))
}
return &q
}
func (q questionDo) FirstOrInit() (*model.Question, error) {
if result, err := q.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*model.Question), nil
}
}
func (q questionDo) FirstOrCreate() (*model.Question, error) {
if result, err := q.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*model.Question), nil
}
}
func (q questionDo) FindByPage(offset int, limit int) (result []*model.Question, count int64, err error) {
result, err = q.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 = q.Offset(-1).Limit(-1).Count()
return
}
func (q questionDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = q.Count()
if err != nil {
return
}
err = q.Offset(offset).Limit(limit).Scan(result)
return
}
func (q questionDo) Scan(result interface{}) (err error) {
return q.DO.Scan(result)
}
func (q questionDo) Delete(models ...*model.Question) (result gen.ResultInfo, err error) {
return q.DO.Delete(models)
}
func (q *questionDo) withDO(do gen.Dao) *questionDo {
q.DO = *do.(*gen.DO)
return q
}

View File

@@ -31,6 +31,8 @@ func newUser(db *gorm.DB, opts ...gen.DOOption) user {
_user.Sn = field.NewString(tableName, "sn")
_user.Name = field.NewString(tableName, "name")
_user.Phone = field.NewString(tableName, "phone")
_user.WxUnionID = field.NewString(tableName, "wx_union_id")
_user.WxMiniOpenID = field.NewString(tableName, "wx_mini_open_id")
_user.CreatedAt = field.NewTime(tableName, "created_at")
_user.UpdatedAt = field.NewTime(tableName, "updated_at")
_user.DeletedAt = field.NewField(tableName, "deleted_at")
@@ -43,14 +45,16 @@ func newUser(db *gorm.DB, opts ...gen.DOOption) user {
type user struct {
userDo userDo
ALL field.Asterisk
ID field.Uint64
Sn field.String // 业务唯一编号
Name field.String
Phone field.String
CreatedAt field.Time
UpdatedAt field.Time
DeletedAt field.Field
ALL field.Asterisk
ID field.Uint64
Sn field.String // 业务唯一编号
Name field.String
Phone field.String
WxUnionID field.String // 微信用户唯一标识
WxMiniOpenID field.String // 微信小程序的openID
CreatedAt field.Time
UpdatedAt field.Time
DeletedAt field.Field
fieldMap map[string]field.Expr
}
@@ -71,6 +75,8 @@ func (u *user) updateTableName(table string) *user {
u.Sn = field.NewString(table, "sn")
u.Name = field.NewString(table, "name")
u.Phone = field.NewString(table, "phone")
u.WxUnionID = field.NewString(table, "wx_union_id")
u.WxMiniOpenID = field.NewString(table, "wx_mini_open_id")
u.CreatedAt = field.NewTime(table, "created_at")
u.UpdatedAt = field.NewTime(table, "updated_at")
u.DeletedAt = field.NewField(table, "deleted_at")
@@ -98,11 +104,13 @@ func (u *user) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
}
func (u *user) fillFieldMap() {
u.fieldMap = make(map[string]field.Expr, 7)
u.fieldMap = make(map[string]field.Expr, 9)
u.fieldMap["id"] = u.ID
u.fieldMap["sn"] = u.Sn
u.fieldMap["name"] = u.Name
u.fieldMap["phone"] = u.Phone
u.fieldMap["wx_union_id"] = u.WxUnionID
u.fieldMap["wx_mini_open_id"] = u.WxMiniOpenID
u.fieldMap["created_at"] = u.CreatedAt
u.fieldMap["updated_at"] = u.UpdatedAt
u.fieldMap["deleted_at"] = u.DeletedAt