-
Notifications
You must be signed in to change notification settings - Fork 32
修复issue所提到的bug,重置niuniu数据库 #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
261e13d
修复issue所提到的bug,重置niuniu数据库
xyy0411 1b503b7
修lint,优化代码
xyy0411 00119bc
Merge branch 'FloatTech:main' into pppp
xyy0411 6a7c3e3
gorm修改成v1版本
xyy0411 ce484c7
Merge remote-tracking branch 'origin/pppp' into pppp
xyy0411 fdf474a
删除go.mod不使用的go-sqlite依赖
xyy0411 61f930d
修改调用processJJ方法时返回的错误err,优化jj函数的数据库操作
xyy0411 87bd28f
优化purchaseItem方法,删除Redeem函数的无用注释代码,修改牛牛商店的商品为可自定义购买数量,优化代码
xyy0411 0f75562
Merge branch 'main' into pppp
xyy0411 fd11da7
将 ensureTable 封装到钩子中,减少冗余代码
xyy0411 4604499
Merge remote-tracking branch 'origin/pppp' into pppp
xyy0411 0a3a03e
修改model -> Model
xyy0411 ed4ff6e
删除hooksMtx锁
xyy0411 d189034
修lint
xyy0411 fc90840
Table -> table
xyy0411 d81975e
直接在tableFor里创建表
xyy0411 d91ce11
修lint,logrus.Error -> logurs.Errorf
xyy0411 813938a
Merge branch 'main' into pppp
fumiama 084e194
优化代码,修改jj()返回niuID后续赎牛牛可自定义回复
xyy0411 effec85
Merge remote-tracking branch 'origin/pppp' into pppp
xyy0411 02e9667
修lint
xyy0411 635942b
完成要求的更改
xyy0411 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package niu | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "github.com/RomiChan/syncx" | ||
| "github.com/jinzhu/gorm" | ||
| "github.com/sirupsen/logrus" | ||
| ) | ||
|
|
||
| var ( | ||
| migratedGroups = syncx.Map[string, struct{}]{} // key: string, value: struct{} | ||
| ) | ||
|
|
||
| func ensureTable[T userInfo | AuctionInfo](gid int64, prefix string) error { | ||
| table := fmt.Sprintf("group_%d_%s_info", gid, prefix) | ||
| if _, ok := migratedGroups.Load(table); ok { | ||
| return nil | ||
| } | ||
| err := db.Table(table).AutoMigrate(new(T)).Error | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // 设置为已迁移 | ||
| migratedGroups.Store(table, struct{}{}) | ||
| return nil | ||
| } | ||
|
|
||
| func tableFor(gid int64, prefix string) *gorm.DB { | ||
|
|
||
| switch prefix { | ||
| case usr: | ||
| err := ensureTable[userInfo](gid, usr) | ||
| if err != nil { | ||
| logrus.Errorf("ensureTable error: %v", err) | ||
| return nil | ||
| } | ||
| case auct: | ||
| err := ensureTable[AuctionInfo](gid, auct) | ||
| if err != nil { | ||
| logrus.Errorf("ensureTable error: %v", err) | ||
| return nil | ||
| } | ||
| } | ||
|
|
||
| return db.Table(fmt.Sprintf("group_%d_%s_info", gid, prefix)) | ||
| } | ||
|
|
||
| func listUsers(gid int64) (users, error) { | ||
| var users users | ||
| err := tableFor(gid, usr).Find(&users).Error | ||
| return users, err | ||
| } | ||
|
|
||
| func listAuction(gid int64) ([]AuctionInfo, error) { | ||
| var as []AuctionInfo | ||
| err := tableFor(gid, auct).Order("money DESC").Find(&as).Error | ||
| return as, err | ||
| } | ||
|
|
||
| func createUser(gid int64, user *userInfo, fix string) error { | ||
| return tableFor(gid, fix).Create(user).Error | ||
| } | ||
|
|
||
| func getUserByID(gid int64, uid int64) (*userInfo, error) { | ||
| var user userInfo | ||
| err := tableFor(gid, usr).Where("user_id = ?", uid).First(&user).Error | ||
| return &user, err | ||
| } | ||
|
|
||
| func updatesUserByID(gid int64, id int64, fields map[string]interface{}) error { | ||
| return tableFor(gid, usr).Where("user_id = ?", id).Updates(fields).Error | ||
| } | ||
|
|
||
| func deleteUserByID(gid int64, id int64) error { | ||
| return tableFor(gid, usr).Where("user_id = ?", id).Delete(&userInfo{}).Error | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.