This commit is contained in:
oneao committed 2026-04-20 17:20:47 +08:00
1 parent 89aaef1d6b
commit 6d54a9e407
192 files changed
+971 -51708

No files matched your search

@@ -0,0 +1,42 @@
package db
import (
"allapp-go/internal/middleware"
"context"
"time"
)
var auditExcludeTables = map[string]bool{
"b_user": true,
"b_user_oauth": true,
}
// 返回新 map(避免修改入参)
func applyMetaFields(ctx context.Context, table string, data map[string]any, isInsert bool) map[string]any {
if auditExcludeTables[table] {
return data
}
now := time.Now()
newData := make(map[string]any, len(data)+2)
for k, v := range data {
newData[k] = v
}
if isInsert {
newData["create_time"] = now
newData["update_time"] = now
} else {
newData["update_time"] = now
}
if userID, ok := middleware.GetUserID(ctx); ok {
if isInsert {
newData["create_by"] = userID
}
newData["update_by"] = userID
}
return newData
}