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 }