refactor: 重构SQL基础实体并集成雪花ID生成器
将主键ID类型从uint64改为int64,移除Bid和Deleter字段;在insertHook中集成Snowflake算法自动生成ID;更新ModuleAssetId为int64类型。
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"gitea.com/red-future/common/utils"
|
||||
"github.com/bwmarrin/snowflake"
|
||||
"github.com/gogf/gf/v2/crypto/gmd5"
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/database/gredis"
|
||||
@@ -158,14 +159,20 @@ func catchSQLHook() gdb.HookHandler {
|
||||
// ==================== Insert钩子 ====================
|
||||
|
||||
func insertHook(ctx context.Context, in *gdb.HookInsertInput) (result sql.Result, err error) {
|
||||
// 1. 自动赋值租户字段
|
||||
userInfo, _ := utils.GetUserInfo(ctx)
|
||||
|
||||
//if !g.IsEmpty(userInfo.UserName) {
|
||||
// in.Model.Data("creator", userInfo.UserName)
|
||||
// in.Model.Data("updater", userInfo.UserName)
|
||||
//}
|
||||
userInfo, err := utils.GetUserInfo(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
node, err := snowflake.NewNode(g.Cfg().MustGet(ctx, "server.workerId").Int64())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := range in.Data {
|
||||
if _, ok := in.Data[i]["id"]; ok {
|
||||
in.Data[i]["id"] = node.Generate().Int64()
|
||||
}
|
||||
if !g.IsEmpty(userInfo.UserName) {
|
||||
if _, ok := in.Data[i]["creator"]; ok {
|
||||
in.Data[i]["creator"] = userInfo.UserName
|
||||
@@ -198,11 +205,6 @@ func updateHook(ctx context.Context, in *gdb.HookUpdateInput) (result sql.Result
|
||||
// 1. 自动赋值修改人
|
||||
userInfo, _ := utils.GetUserInfo(ctx)
|
||||
|
||||
//if !g.IsEmpty(userInfo.UserName) {
|
||||
// in.Model.Data("creator", userInfo.UserName)
|
||||
// in.Model.Data("updater", userInfo.UserName)
|
||||
//}
|
||||
|
||||
switch data := in.Data.(type) {
|
||||
case gdb.Map:
|
||||
if !g.IsEmpty(userInfo.UserName) {
|
||||
|
||||
Reference in New Issue
Block a user