Compare commits

..

9 Commits
v0.0.3 ... main

Author SHA1 Message Date
fcl 1430943c48 ignore dependency error 2025-06-27 00:11:51 +08:00
Yavolte 4eef560649 add chart package 2025-06-26 14:14:18 +08:00
Yavolte 04053391ef update depends 2025-06-23 22:52:19 +08:00
Yavolte 9a665704b1 优化模型数据 2025-06-23 10:55:30 +08:00
Yavolte b8d5fce311 upgrade aeus version 2025-06-19 11:44:36 +08:00
Yavolte ea7f75be62 add custom gorm log 2025-06-19 11:43:05 +08:00
Yavolte ea09631d4c fix bugs 2025-06-19 11:19:58 +08:00
Yavolte 0cab1c6c61 update proto file 2025-06-19 11:06:48 +08:00
Yavolte ac9411f525 新增数据库连接器 2025-06-19 10:04:03 +08:00
36 changed files with 1713 additions and 369 deletions

View File

@ -1,53 +0,0 @@
package config
import (
"os"
"strconv"
)
type Database struct {
Driver string `json:"driver" yaml:"driver"`
DSN string `json:"dsn" yaml:"dsn"`
}
type Redis struct {
Addr string `json:"addr" yaml:"addr"`
Password string `json:"password" yaml:"password"`
DB int `json:"db" yaml:"db"`
}
type Auth struct {
TTL int64 `json:"ttl" yaml:"ttl"`
Secret string `json:"secret" yaml:"secret"`
AllowUrls []string `json:"allow_urls" yaml:"allowUrls"`
}
type Translate struct {
ClientKey string `json:"client_key" yaml:"clientKey"`
ServerKey string `json:"server_key" yaml:"serverKey"`
ValidateUrl string `json:"validate_url" yaml:"validateUrl"`
}
type Config struct {
Auth Auth `json:"auth" yaml:"auth"`
Redis Redis `json:"redis" yaml:"redis"`
Translate Translate `json:"translate" yaml:"translate"`
Database Database `json:"database" yaml:"database"`
}
func (c *Config) FromEnvironment() {
c.Auth.Secret = os.Getenv("JWT_SECRET")
c.Auth.TTL = 7200
c.Database.Driver = os.Getenv("DATABASE_DRIVER")
c.Database.DSN = os.Getenv("DATABASE_DSN")
if c.Database.Driver == "" {
c.Database.Driver = "mysql"
}
c.Redis.Addr = os.Getenv("REDIS_ADDRESS")
c.Redis.Password = os.Getenv("REDIS_PASSWORD")
if n, err := strconv.Atoi(os.Getenv("REDIS_DB")); err == nil {
c.Redis.DB = n
}
}

15
go.mod
View File

@ -5,8 +5,8 @@ go 1.23.0
toolchain go1.23.10
require (
git.nobla.cn/golang/aeus v0.0.8
git.nobla.cn/golang/rest v0.1.2
git.nobla.cn/golang/aeus v0.0.11
git.nobla.cn/golang/rest v0.1.4
github.com/envoyproxy/protoc-gen-validate v1.2.1
golang.org/x/text v0.23.0 // indirect
google.golang.org/protobuf v1.36.6
@ -20,6 +20,9 @@ require (
golang.org/x/sync v0.12.0
google.golang.org/genproto/googleapis/api v0.0.0-20250303144028-a0af3efb3deb
google.golang.org/grpc v1.72.2
gopkg.in/yaml.v3 v3.0.1
gorm.io/driver/postgres v1.6.0
gorm.io/driver/sqlite v1.6.0
)
require (
@ -38,15 +41,22 @@ require (
github.com/go-sql-driver/mysql v1.8.1 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.6.0 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-sqlite3 v1.14.22 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/rogpeppe/go-internal v1.14.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
golang.org/x/arch v0.8.0 // indirect
@ -54,5 +64,4 @@ require (
golang.org/x/net v0.38.0 // indirect
golang.org/x/sys v0.31.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250303144028-a0af3efb3deb // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

32
go.sum
View File

@ -1,11 +1,11 @@
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
git.nobla.cn/golang/aeus v0.0.8 h1:mifdMOredbOfUNnP193+IjR1gR68O+2R3DVEhi3N4GE=
git.nobla.cn/golang/aeus v0.0.8/go.mod h1:oOEwqIp6AhKKqj6sLFO8x7IycOROYHCb/2/CjF4+9CU=
git.nobla.cn/golang/aeus v0.0.11 h1:gbXIOVOQRDTIQTjw9wPVfNC9nXBaTJCABeDYmrHW2Oc=
git.nobla.cn/golang/aeus v0.0.11/go.mod h1:oOEwqIp6AhKKqj6sLFO8x7IycOROYHCb/2/CjF4+9CU=
git.nobla.cn/golang/kos v0.1.32 h1:sFVCA7vKc8dPUd0cxzwExOSPX2mmMh2IuwL6cYS1pBc=
git.nobla.cn/golang/kos v0.1.32/go.mod h1:35Z070+5oB39WcVrh5DDlnVeftL/Ccmscw2MZFe9fUg=
git.nobla.cn/golang/rest v0.1.2 h1:vF5perbveRcCF5Pb60yxHjvGpx/zX+D1qzdceqIwg+E=
git.nobla.cn/golang/rest v0.1.2/go.mod h1:4viDk7VujDokpUeHQGbnSp2bkkVZEoIkWQIs/l/TTPQ=
git.nobla.cn/golang/rest v0.1.4 h1:9/XscfNXI3aPESpy8CPtVl17VSMxU9BihhedeG+h8YY=
git.nobla.cn/golang/rest v0.1.4/go.mod h1:4viDk7VujDokpUeHQGbnSp2bkkVZEoIkWQIs/l/TTPQ=
github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0=
github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4=
github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM=
@ -14,6 +14,7 @@ github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/
github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w=
github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg=
github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@ -50,6 +51,14 @@ github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.6.0 h1:SWJzexBzPL5jb0GEsrPMLIsi/3jOo7RHlzTjcAeDrPY=
github.com/jackc/pgx/v5 v5.6.0/go.mod h1:DNZ/vlrUnhWCoFGxHAG8U2ljioxukquj7utPDgtQdTw=
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
@ -60,10 +69,16 @@ github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa02
github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM=
github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@ -75,6 +90,8 @@ github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
@ -126,13 +143,18 @@ google.golang.org/grpc v1.72.2 h1:TdbGzwb82ty4OusHWepvFWGLgIbNo1/SUynEN0ssqv8=
google.golang.org/grpc v1.72.2/go.mod h1:wH5Aktxcg25y1I3w7H69nHfXdOG3UiadoBtjh3izSDM=
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/mysql v1.6.0 h1:eNbLmNTpPpTOVZi8MMxCi2aaIm0ZpInbORNXDwyLGvg=
gorm.io/driver/mysql v1.6.0/go.mod h1:D/oCC2GWK3M/dqoLxnOlaNKmXz8WNTfcS9y5ovaSqKo=
gorm.io/driver/postgres v1.6.0 h1:2dxzU8xJ+ivvqTRph34QX+WrRaJlmfyPqXmoGVjMBa4=
gorm.io/driver/postgres v1.6.0/go.mod h1:vUw0mrGgrTK+uPHEhAdV4sfFELrByKVGnaVRkXDhtWo=
gorm.io/driver/sqlite v1.6.0 h1:WHRRrIiulaPiPFmDcod6prc4l2VGVWHz80KspNsxSfQ=
gorm.io/driver/sqlite v1.6.0/go.mod h1:AO9V1qIQddBESngQUKWL9yoH93HIeA1X6V633rBwyT8=
gorm.io/gorm v1.30.0 h1:qbT5aPv1UH8gI99OsRlvDToLxW5zR7FzS9acZDOZcgs=
gorm.io/gorm v1.30.0/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE=
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=

View File

@ -94,6 +94,6 @@ func NewDepartmentLogic(db *gorm.DB, ch cache.Cache) *Department {
return &Department{
db: db,
cache: ch,
sqlDependency: dbcache.NewSqlDependency("SELECT MAX(`updated_at`) FROM departments"),
sqlDependency: dbcache.NewSqlDependency("SELECT MAX(`updated_at`) FROM `departments`"),
}
}

View File

@ -44,6 +44,6 @@ func NewMenuLogic(db *gorm.DB, ch cache.Cache) *Menu {
return &Menu{
db: db,
cache: ch,
sqlDependency: dbcache.NewSqlDependency("SELECT MAX(`updated_at`) FROM menus"),
sqlDependency: dbcache.NewSqlDependency("SELECT MAX(`updated_at`) FROM `menus`"),
}
}

View File

@ -59,7 +59,7 @@ func NewRoleLogic(db *gorm.DB, ch cache.Cache) *Role {
return &Role{
db: db,
cache: ch,
sqlDependency: dbcache.NewSqlDependency("SELECT MAX(`updated_at`) FROM roles"),
permissionSqlDependency: dbcache.NewSqlDependency("SELECT MAX(`updated_at`) FROM permissions"),
sqlDependency: dbcache.NewSqlDependency("SELECT MAX(`updated_at`) FROM `roles`"),
permissionSqlDependency: dbcache.NewSqlDependency("SELECT MAX(`updated_at`) FROM `permissions`"),
}
}

View File

@ -17,6 +17,7 @@ type User struct {
db *gorm.DB
cache cache.Cache
sqlDependency *dbcache.SqlDependency
roleDependency *dbcache.SqlDependency
}
// GetPermissions 获取用户权限
@ -30,7 +31,8 @@ func (u *User) GetPermissions(ctx context.Context, uid string) (permissions []st
Error
return ss, err
},
dbcache.WithCacheDuration(time.Minute),
dbcache.WithDependency(u.roleDependency),
dbcache.WithCacheDuration(time.Second*20),
dbcache.WithDB(u.db),
dbcache.WithCache(u.cache),
)
@ -67,6 +69,7 @@ func NewUserLogic(db *gorm.DB, ch cache.Cache) *User {
return &User{
db: db,
cache: ch,
sqlDependency: dbcache.NewSqlDependency("SELECT MAX(`updated_at`) FROM users"),
roleDependency: dbcache.NewSqlDependency("SELECT COUNT(*) AS count FROM `role_permissions`"),
sqlDependency: dbcache.NewSqlDependency("SELECT MAX(`updated_at`) FROM `users`"),
}
}

View File

@ -48,6 +48,7 @@ func init() {
orgMenu.Name = "Organize"
orgMenu.Public = true
orgMenu.Uri = "/organize"
orgMenu.Position = 1
profileMenu := &models.Menu{}
profileMenu.Label = "个人信息"
@ -64,6 +65,7 @@ func init() {
settingMenu.Name = "System"
settingMenu.Public = true
settingMenu.Uri = "/system"
settingMenu.Position = 999
schemaMenu := &models.Menu{}
schemaMenu.Label = "字段设置"

View File

@ -8,12 +8,19 @@ import (
)
// Menu 合并菜单
func Menu(db *gorm.DB, model *models.Menu) (err error) {
if err = db.Where("name = ?", model.Name).First(model).Error; err != nil {
func Menu(db *gorm.DB, datas ...*models.Menu) (err error) {
tx := db.Begin()
for _, model := range datas {
if err = tx.Where("name = ?", model.Name).First(model).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
err = db.Create(model).Error
if err = tx.Create(model).Error; err != nil {
tx.Rollback()
return err
}
}
}
}
err = tx.Commit().Error
return
}
@ -31,6 +38,7 @@ func Permission(db *gorm.DB, menuName string, permission string, label string) (
return
}
// #2c7be5
// Default 合并初始化数据集
func Default(db *gorm.DB) (err error) {
var (

View File

@ -1,9 +1,12 @@
package models
import (
"errors"
"git.nobla.cn/golang/aeus-admin/pb"
"git.nobla.cn/golang/aeus-admin/types"
restTypes "git.nobla.cn/golang/rest/types"
"gorm.io/gorm"
)
type (
@ -53,7 +56,7 @@ func (m *Login) GetMenu() *types.Menu {
}
func (m *Login) Scenario() []string {
return []string{restTypes.ScenarioList}
return []string{restTypes.ScenarioList, restTypes.ScenarioExport}
}
func (m *Menu) GetMenu() *types.Menu {
@ -63,6 +66,17 @@ func (m *Menu) GetMenu() *types.Menu {
}
}
func (m *Menu) BeforeDelete(tx *gorm.DB) (err error) {
var count int64
if err = tx.Model(&Menu{}).Where("`parent` = ?", m.Name).Count(&count).Error; err != nil {
return
}
if count > 0 {
err = errors.New("please delete sub menus first")
}
return
}
func (m *Menu) ModelPermissions() map[string]string {
return map[string]string{
"organize:permission:list": "权限",
@ -76,6 +90,23 @@ func (m *Department) GetMenu() *types.Menu {
}
}
func (m *Department) BeforeDelete(tx *gorm.DB) (err error) {
var count int64
if err = tx.Model(&Department{}).Where("`parent_id` = ?", m.Id).Count(&count).Error; err != nil {
return
}
if count > 0 {
return errors.New("please delete sub department first")
}
if err = tx.Model(&User{}).Where("`dept_id` = ?", m.Id).Count(&count).Error; err != nil {
return
}
if count > 0 {
err = errors.New("please delete user first")
}
return
}
func (m *Role) GetMenu() *types.Menu {
return &types.Menu{
Name: "OrganizeRole",
@ -89,6 +120,17 @@ func (m *Role) ModelPermissions() map[string]string {
}
}
func (m *Role) BeforeDelete(tx *gorm.DB) (err error) {
var count int64
if err = tx.Model(&User{}).Where("`role` = ?", m.Name).Count(&count).Error; err != nil {
return
}
if count > 0 {
err = errors.New("please delete user first")
}
return
}
func (m *Permission) GetMenu() *types.Menu {
return &types.Menu{
Name: "OrganizePermission",
@ -136,7 +178,7 @@ func (m *Activity) GetMenu() *types.Menu {
}
func (m *Activity) Scenario() []string {
return []string{restTypes.ScenarioList}
return []string{restTypes.ScenarioList, restTypes.ScenarioExport}
}
func (m *Activity) ModuleName() string {

View File

@ -961,27 +961,27 @@ func (x *MenuItem) GetChildren() []*MenuItem {
}
// 获取菜单的请求
type GetMenuRequest struct {
type GetUserMenuRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
Permission bool `protobuf:"varint,1,opt,name=permission,proto3" json:"permission,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *GetMenuRequest) Reset() {
*x = GetMenuRequest{}
func (x *GetUserMenuRequest) Reset() {
*x = GetUserMenuRequest{}
mi := &file_organize_proto_msgTypes[10]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GetMenuRequest) String() string {
func (x *GetUserMenuRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetMenuRequest) ProtoMessage() {}
func (*GetUserMenuRequest) ProtoMessage() {}
func (x *GetMenuRequest) ProtoReflect() protoreflect.Message {
func (x *GetUserMenuRequest) ProtoReflect() protoreflect.Message {
mi := &file_organize_proto_msgTypes[10]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -993,12 +993,12 @@ func (x *GetMenuRequest) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x)
}
// Deprecated: Use GetMenuRequest.ProtoReflect.Descriptor instead.
func (*GetMenuRequest) Descriptor() ([]byte, []int) {
// Deprecated: Use GetUserMenuRequest.ProtoReflect.Descriptor instead.
func (*GetUserMenuRequest) Descriptor() ([]byte, []int) {
return file_organize_proto_rawDescGZIP(), []int{10}
}
func (x *GetMenuRequest) GetPermission() bool {
func (x *GetUserMenuRequest) GetPermission() bool {
if x != nil {
return x.Permission
}
@ -1006,27 +1006,27 @@ func (x *GetMenuRequest) GetPermission() bool {
}
// 获取菜单的响应
type GetMenuResponse struct {
type GetUserMenuResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
Data []*MenuItem `protobuf:"bytes,1,rep,name=data,proto3" json:"data,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *GetMenuResponse) Reset() {
*x = GetMenuResponse{}
func (x *GetUserMenuResponse) Reset() {
*x = GetUserMenuResponse{}
mi := &file_organize_proto_msgTypes[11]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GetMenuResponse) String() string {
func (x *GetUserMenuResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetMenuResponse) ProtoMessage() {}
func (*GetUserMenuResponse) ProtoMessage() {}
func (x *GetMenuResponse) ProtoReflect() protoreflect.Message {
func (x *GetUserMenuResponse) ProtoReflect() protoreflect.Message {
mi := &file_organize_proto_msgTypes[11]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
@ -1038,12 +1038,12 @@ func (x *GetMenuResponse) ProtoReflect() protoreflect.Message {
return mi.MessageOf(x)
}
// Deprecated: Use GetMenuResponse.ProtoReflect.Descriptor instead.
func (*GetMenuResponse) Descriptor() ([]byte, []int) {
// Deprecated: Use GetUserMenuResponse.ProtoReflect.Descriptor instead.
func (*GetUserMenuResponse) Descriptor() ([]byte, []int) {
return file_organize_proto_rawDescGZIP(), []int{11}
}
func (x *GetMenuResponse) GetData() []*MenuItem {
func (x *GetUserMenuResponse) GetData() []*MenuItem {
if x != nil {
return x.Data
}
@ -2500,6 +2500,162 @@ func (x *GetMenuLevelLabelsResponse) GetData() []*MenuLevelValue {
return nil
}
type MenuValue struct {
state protoimpl.MessageState `protogen:"open.v1"`
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
Parent string `protobuf:"bytes,2,opt,name=parent,proto3" json:"parent,omitempty"`
Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"`
Label string `protobuf:"bytes,4,opt,name=label,proto3" json:"label,omitempty"`
Children []*MenuValue `protobuf:"bytes,5,rep,name=children,proto3" json:"children,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *MenuValue) Reset() {
*x = MenuValue{}
mi := &file_organize_proto_msgTypes[42]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *MenuValue) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*MenuValue) ProtoMessage() {}
func (x *MenuValue) ProtoReflect() protoreflect.Message {
mi := &file_organize_proto_msgTypes[42]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use MenuValue.ProtoReflect.Descriptor instead.
func (*MenuValue) Descriptor() ([]byte, []int) {
return file_organize_proto_rawDescGZIP(), []int{42}
}
func (x *MenuValue) GetId() int64 {
if x != nil {
return x.Id
}
return 0
}
func (x *MenuValue) GetParent() string {
if x != nil {
return x.Parent
}
return ""
}
func (x *MenuValue) GetName() string {
if x != nil {
return x.Name
}
return ""
}
func (x *MenuValue) GetLabel() string {
if x != nil {
return x.Label
}
return ""
}
func (x *MenuValue) GetChildren() []*MenuValue {
if x != nil {
return x.Children
}
return nil
}
type GetMenuRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *GetMenuRequest) Reset() {
*x = GetMenuRequest{}
mi := &file_organize_proto_msgTypes[43]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GetMenuRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetMenuRequest) ProtoMessage() {}
func (x *GetMenuRequest) ProtoReflect() protoreflect.Message {
mi := &file_organize_proto_msgTypes[43]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetMenuRequest.ProtoReflect.Descriptor instead.
func (*GetMenuRequest) Descriptor() ([]byte, []int) {
return file_organize_proto_rawDescGZIP(), []int{43}
}
type GetMenuResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
Data []*MenuValue `protobuf:"bytes,1,rep,name=data,proto3" json:"data,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *GetMenuResponse) Reset() {
*x = GetMenuResponse{}
mi := &file_organize_proto_msgTypes[44]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GetMenuResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetMenuResponse) ProtoMessage() {}
func (x *GetMenuResponse) ProtoReflect() protoreflect.Message {
mi := &file_organize_proto_msgTypes[44]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetMenuResponse.ProtoReflect.Descriptor instead.
func (*GetMenuResponse) Descriptor() ([]byte, []int) {
return file_organize_proto_rawDescGZIP(), []int{44}
}
func (x *GetMenuResponse) GetData() []*MenuValue {
if x != nil {
return x.Data
}
return nil
}
type LoginRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"`
@ -2511,7 +2667,7 @@ type LoginRequest struct {
func (x *LoginRequest) Reset() {
*x = LoginRequest{}
mi := &file_organize_proto_msgTypes[42]
mi := &file_organize_proto_msgTypes[45]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -2523,7 +2679,7 @@ func (x *LoginRequest) String() string {
func (*LoginRequest) ProtoMessage() {}
func (x *LoginRequest) ProtoReflect() protoreflect.Message {
mi := &file_organize_proto_msgTypes[42]
mi := &file_organize_proto_msgTypes[45]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -2536,7 +2692,7 @@ func (x *LoginRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use LoginRequest.ProtoReflect.Descriptor instead.
func (*LoginRequest) Descriptor() ([]byte, []int) {
return file_organize_proto_rawDescGZIP(), []int{42}
return file_organize_proto_rawDescGZIP(), []int{45}
}
func (x *LoginRequest) GetUsername() string {
@ -2572,7 +2728,7 @@ type LoginResponse struct {
func (x *LoginResponse) Reset() {
*x = LoginResponse{}
mi := &file_organize_proto_msgTypes[43]
mi := &file_organize_proto_msgTypes[46]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -2584,7 +2740,7 @@ func (x *LoginResponse) String() string {
func (*LoginResponse) ProtoMessage() {}
func (x *LoginResponse) ProtoReflect() protoreflect.Message {
mi := &file_organize_proto_msgTypes[43]
mi := &file_organize_proto_msgTypes[46]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -2597,7 +2753,7 @@ func (x *LoginResponse) ProtoReflect() protoreflect.Message {
// Deprecated: Use LoginResponse.ProtoReflect.Descriptor instead.
func (*LoginResponse) Descriptor() ([]byte, []int) {
return file_organize_proto_rawDescGZIP(), []int{43}
return file_organize_proto_rawDescGZIP(), []int{46}
}
func (x *LoginResponse) GetUid() string {
@ -2637,7 +2793,7 @@ type LogoutRequest struct {
func (x *LogoutRequest) Reset() {
*x = LogoutRequest{}
mi := &file_organize_proto_msgTypes[44]
mi := &file_organize_proto_msgTypes[47]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -2649,7 +2805,7 @@ func (x *LogoutRequest) String() string {
func (*LogoutRequest) ProtoMessage() {}
func (x *LogoutRequest) ProtoReflect() protoreflect.Message {
mi := &file_organize_proto_msgTypes[44]
mi := &file_organize_proto_msgTypes[47]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -2662,7 +2818,7 @@ func (x *LogoutRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use LogoutRequest.ProtoReflect.Descriptor instead.
func (*LogoutRequest) Descriptor() ([]byte, []int) {
return file_organize_proto_rawDescGZIP(), []int{44}
return file_organize_proto_rawDescGZIP(), []int{47}
}
func (x *LogoutRequest) GetToken() string {
@ -2681,7 +2837,7 @@ type LogoutResponse struct {
func (x *LogoutResponse) Reset() {
*x = LogoutResponse{}
mi := &file_organize_proto_msgTypes[45]
mi := &file_organize_proto_msgTypes[48]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -2693,7 +2849,7 @@ func (x *LogoutResponse) String() string {
func (*LogoutResponse) ProtoMessage() {}
func (x *LogoutResponse) ProtoReflect() protoreflect.Message {
mi := &file_organize_proto_msgTypes[45]
mi := &file_organize_proto_msgTypes[48]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -2706,7 +2862,7 @@ func (x *LogoutResponse) ProtoReflect() protoreflect.Message {
// Deprecated: Use LogoutResponse.ProtoReflect.Descriptor instead.
func (*LogoutResponse) Descriptor() ([]byte, []int) {
return file_organize_proto_rawDescGZIP(), []int{45}
return file_organize_proto_rawDescGZIP(), []int{48}
}
func (x *LogoutResponse) GetUid() string {
@ -2720,7 +2876,7 @@ var File_organize_proto protoreflect.FileDescriptor
const file_organize_proto_rawDesc = "" +
"\n" +
"\x0eorganize.proto\x12\borganize\x1a\x0faeus/rest.proto\x1a\x17validate/validate.proto\x1a google/protobuf/descriptor.proto\x1a\x1cgoogle/api/annotations.proto\"\xab\b\n" +
"\x0eorganize.proto\x12\borganize\x1a\x0faeus/rest.proto\x1a\x17validate/validate.proto\x1a google/protobuf/descriptor.proto\x1a\x1cgoogle/api/annotations.proto\"\xc2\b\n" +
"\x04Menu\x12*\n" +
"\x02id\x18\x01 \x01(\x03B\x1a\xb2\xb9\x19\x16\n" +
"\n" +
@ -2729,9 +2885,9 @@ const file_organize_proto_rawDesc = "" +
"created_at\x18\x02 \x01(\x03B\x1f\xb2\xb9\x19\x1b\x12\f创建时间\x1a\vview;exportR\tcreatedAt\x12E\n" +
"\n" +
"updated_at\x18\x03 \x01(\x03B&\xb2\xb9\x19\"\n" +
"\x05index\x12\f更新时间\x1a\vview;exportR\tupdatedAt\x12v\n" +
"\x06parent\x18\x04 \x01(\tB^\xb2\xb9\x19Z\n" +
"\rindex;size:60\x12\f父级菜单*\x04menu2\x0freadonly:updateB$type:dropdown;url:/menu/level-labelsR\x06parent\x12^\n" +
"\x05index\x12\f更新时间\x1a\vview;exportR\tupdatedAt\x12\x91\x01\n" +
"\x06parent\x18\x04 \x01(\tBy\xb2\xb9\x19u\n" +
"\rindex;size:60\x12\f父级菜单\x1a\x19create;update;view;export*\x04menu2\x0freadonly:updateB$type:dropdown;url:/menu/level-labelsR\x06parent\x12^\n" +
"\x04name\x18\x05 \x01(\tBJ\xfaB\x04r\x02\x18<\xb2\xb9\x19?\n" +
"\rindex;size:60\x12\f组件名称2\x0freadonly:update:\x0funique;requiredR\x04name\x12C\n" +
"\x05label\x18\x06 \x01(\tB-\xfaB\x04r\x02\x18x\xb2\xb9\x19\"\n" +
@ -2744,11 +2900,11 @@ const file_organize_proto_rawDesc = "" +
"\asize:60\x12\f菜单图标\x1a\x19create;update;view;exportR\x04icon\x12E\n" +
"\x06hidden\x18\n" +
" \x01(\bB-\xb2\xb9\x19)\x12\f是否隐藏\x1a\x19create;update;view;exportR\x06hidden\x12E\n" +
"\x06public\x18\v \x01(\bB-\xb2\xb9\x19)\x12\f是否公开\x1a\x19create;update;view;exportR\x06public\x12q\n" +
"\vdescription\x18\f \x01(\tBO\xfaB\x05r\x03\x18\x80\b\xb2\xb9\x19C\n" +
"\tsize:1024\x12\f备注说明\x1a\x1ecreate;update;view;export;list*\btextareaR\vdescription\x127\n" +
"\x06public\x18\v \x01(\bB-\xb2\xb9\x19)\x12\f是否公开\x1a\x19create;update;view;exportR\x06public\x12l\n" +
"\vdescription\x18\f \x01(\tBJ\xfaB\x05r\x03\x18\x80\b\xb2\xb9\x19>\n" +
"\tsize:1024\x12\f备注说明\x1a\x19create;update;view;export*\btextareaR\vdescription\x127\n" +
"\bposition\x18\r \x01(\x03B\x1b\xb2\xb9\x19\x17\x12\x06排序\x1a\rcreate;updateR\bposition:\v\xba\xb9\x19\a\n" +
"\x05menus\"\xbd\x03\n" +
"\x05menus\"\xd1\x03\n" +
"\x04Role\x12*\n" +
"\x02id\x18\x01 \x01(\x03B\x1a\xb2\xb9\x19\x16\n" +
"\n" +
@ -2757,11 +2913,11 @@ const file_organize_proto_rawDesc = "" +
"created_at\x18\x02 \x01(\x03B\x1f\xb2\xb9\x19\x1b\x12\f创建时间\x1a\vview;exportR\tcreatedAt\x12E\n" +
"\n" +
"updated_at\x18\x03 \x01(\x03B&\xb2\xb9\x19\"\n" +
"\x05index\x12\f更新时间\x1a\vview;exportR\tupdatedAt\x12M\n" +
"\x04name\x18\x04 \x01(\tB9\xfaB\x04r\x02\x18<\xb2\xb9\x19.\n" +
"\rindex;size:60\x12\f角色名称2\x0freadonly:updateR\x04name\x128\n" +
"\x05label\x18\x05 \x01(\tB\"\xfaB\x04r\x02\x18<\xb2\xb9\x19\x17\n" +
"\asize:60\x12\f角色标题R\x05label\x12l\n" +
"\x05index\x12\f更新时间\x1a\vview;exportR\tupdatedAt\x12W\n" +
"\x04name\x18\x04 \x01(\tBC\xfaB\x04r\x02\x18<\xb2\xb9\x198\n" +
"\rindex;size:60\x12\f角色名称2\x0freadonly:update:\brequiredR\x04name\x12B\n" +
"\x05label\x18\x05 \x01(\tB,\xfaB\x04r\x02\x18<\xb2\xb9\x19!\n" +
"\asize:60\x12\f角色标题:\brequiredR\x05label\x12l\n" +
"\vdescription\x18\x06 \x01(\tBJ\xfaB\x05r\x03\x18\x80\b\xb2\xb9\x19>\n" +
"\tsize:1024\x12\f备注说明\x1a\x19list;create;update;export*\btextareaR\vdescription:\v\xba\xb9\x19\a\n" +
"\x05roles\"\xb1\x03\n" +
@ -2886,12 +3042,12 @@ const file_organize_proto_rawDesc = "" +
"\x05route\x18\x06 \x01(\tR\x05route\x12\x12\n" +
"\x04view\x18\a \x01(\tR\x04view\x12:\n" +
"\vpermissions\x18\b \x03(\v2\x18.organize.PermissionItemR\vpermissions\x12.\n" +
"\bchildren\x18\t \x03(\v2\x12.organize.MenuItemR\bchildren\"0\n" +
"\x0eGetMenuRequest\x12\x1e\n" +
"\bchildren\x18\t \x03(\v2\x12.organize.MenuItemR\bchildren\"4\n" +
"\x12GetUserMenuRequest\x12\x1e\n" +
"\n" +
"permission\x18\x01 \x01(\bR\n" +
"permission\"9\n" +
"\x0fGetMenuResponse\x12&\n" +
"permission\"=\n" +
"\x13GetUserMenuResponse\x12&\n" +
"\x04data\x18\x01 \x03(\v2\x12.organize.MenuItemR\x04data\"%\n" +
"\x11GetProfileRequest\x12\x10\n" +
"\x03uid\x18\x01 \x01(\tR\x03uid\"\xbc\x01\n" +
@ -2968,7 +3124,16 @@ const file_organize_proto_rawDesc = "" +
"\bchildren\x18\x04 \x03(\v2\x18.organize.MenuLevelValueR\bchildren\"\x1b\n" +
"\x19GetMenuLevelLabelsRequest\"J\n" +
"\x1aGetMenuLevelLabelsResponse\x12,\n" +
"\x04data\x18\x01 \x03(\v2\x18.organize.MenuLevelValueR\x04data\"\\\n" +
"\x04data\x18\x01 \x03(\v2\x18.organize.MenuLevelValueR\x04data\"\x8e\x01\n" +
"\tMenuValue\x12\x0e\n" +
"\x02id\x18\x01 \x01(\x03R\x02id\x12\x16\n" +
"\x06parent\x18\x02 \x01(\tR\x06parent\x12\x12\n" +
"\x04name\x18\x03 \x01(\tR\x04name\x12\x14\n" +
"\x05label\x18\x04 \x01(\tR\x05label\x12/\n" +
"\bchildren\x18\x05 \x03(\v2\x13.organize.MenuValueR\bchildren\"\x10\n" +
"\x0eGetMenuRequest\":\n" +
"\x0fGetMenuResponse\x12'\n" +
"\x04data\x18\x01 \x03(\v2\x13.organize.MenuValueR\x04data\"\\\n" +
"\fLoginRequest\x12\x1a\n" +
"\busername\x18\x01 \x01(\tR\busername\x12\x1a\n" +
"\bpassword\x18\x02 \x01(\tR\bpassword\x12\x14\n" +
@ -2981,9 +3146,9 @@ const file_organize_proto_rawDesc = "" +
"\rLogoutRequest\x12\x14\n" +
"\x05token\x18\x01 \x01(\tR\x05token\"\"\n" +
"\x0eLogoutResponse\x12\x10\n" +
"\x03uid\x18\x01 \x01(\tR\x03uid2\xd4\x05\n" +
"\vUserService\x12T\n" +
"\bGetMenus\x12\x18.organize.GetMenuRequest\x1a\x19.organize.GetMenuResponse\"\x13\x82\xd3\xe4\x93\x02\r\x12\v/user/menus\x12^\n" +
"\x03uid\x18\x01 \x01(\tR\x03uid2\xdc\x05\n" +
"\vUserService\x12\\\n" +
"\bGetMenus\x12\x1c.organize.GetUserMenuRequest\x1a\x1d.organize.GetUserMenuResponse\"\x13\x82\xd3\xe4\x93\x02\r\x12\v/user/menus\x12^\n" +
"\n" +
"GetProfile\x12\x1b.organize.GetProfileRequest\x1a\x1c.organize.GetProfileResponse\"\x15\x82\xd3\xe4\x93\x02\x0f\x12\r/user/profile\x12j\n" +
"\rUpdateProfile\x12\x1e.organize.UpdateProfileRequest\x1a\x1f.organize.UpdateProfileResponse\"\x18\x82\xd3\xe4\x93\x02\x12:\x01*\x1a\r/user/profile\x12q\n" +
@ -2999,8 +3164,10 @@ const file_organize_proto_rawDesc = "" +
"\vRoleService\x12d\n" +
"\rGetRoleLabels\x12\x1d.organize.GetRoleLabelRequest\x1a\x1e.organize.GetRoleLabelResponse\"\x14\x82\xd3\xe4\x93\x02\x0e\x12\f/role/labels\x12x\n" +
"\x12GetRolePermissions\x12\".organize.GetRolePermissionRequest\x1a#.organize.GetRolePermissionResponse\"\x19\x82\xd3\xe4\x93\x02\x13\x12\x11/role/permissions\x12}\n" +
"\x12SaveRolePermission\x12#.organize.SaveRolePermissionRequest\x1a$.organize.SaveRolePermissionResponse\"\x1c\x82\xd3\xe4\x93\x02\x16:\x01*\"\x11/role/permissions2\x8a\x01\n" +
"\vMenuService\x12{\n" +
"\x12SaveRolePermission\x12#.organize.SaveRolePermissionRequest\x1a$.organize.SaveRolePermissionResponse\"\x1c\x82\xd3\xe4\x93\x02\x16:\x01*\"\x11/role/permissions2\xdf\x01\n" +
"\vMenuService\x12S\n" +
"\bGetMenus\x12\x18.organize.GetMenuRequest\x1a\x19.organize.GetMenuResponse\"\x12\x82\xd3\xe4\x93\x02\f\x12\n" +
"/menu/list\x12{\n" +
"\x12GetMenuLevelLabels\x12#.organize.GetMenuLevelLabelsRequest\x1a$.organize.GetMenuLevelLabelsResponse\"\x1a\x82\xd3\xe4\x93\x02\x14\x12\x12/menu/level-labels2\xbd\x01\n" +
"\vAuthService\x12T\n" +
"\x05Login\x12\x16.organize.LoginRequest\x1a\x17.organize.LoginResponse\"\x1a\x82\xd3\xe4\x93\x02\x14:\x01*\"\x0f/passport/login\x12X\n" +
@ -3018,7 +3185,7 @@ func file_organize_proto_rawDescGZIP() []byte {
return file_organize_proto_rawDescData
}
var file_organize_proto_msgTypes = make([]protoimpl.MessageInfo, 46)
var file_organize_proto_msgTypes = make([]protoimpl.MessageInfo, 49)
var file_organize_proto_goTypes = []any{
(*Menu)(nil), // 0: organize.Menu
(*Role)(nil), // 1: organize.Role
@ -3030,8 +3197,8 @@ var file_organize_proto_goTypes = []any{
(*LabelValue)(nil), // 7: organize.LabelValue
(*PermissionItem)(nil), // 8: organize.PermissionItem
(*MenuItem)(nil), // 9: organize.MenuItem
(*GetMenuRequest)(nil), // 10: organize.GetMenuRequest
(*GetMenuResponse)(nil), // 11: organize.GetMenuResponse
(*GetUserMenuRequest)(nil), // 10: organize.GetUserMenuRequest
(*GetUserMenuResponse)(nil), // 11: organize.GetUserMenuResponse
(*GetProfileRequest)(nil), // 12: organize.GetProfileRequest
(*GetProfileResponse)(nil), // 13: organize.GetProfileResponse
(*ResetPasswordRequest)(nil), // 14: organize.ResetPasswordRequest
@ -3062,15 +3229,18 @@ var file_organize_proto_goTypes = []any{
(*MenuLevelValue)(nil), // 39: organize.MenuLevelValue
(*GetMenuLevelLabelsRequest)(nil), // 40: organize.GetMenuLevelLabelsRequest
(*GetMenuLevelLabelsResponse)(nil), // 41: organize.GetMenuLevelLabelsResponse
(*LoginRequest)(nil), // 42: organize.LoginRequest
(*LoginResponse)(nil), // 43: organize.LoginResponse
(*LogoutRequest)(nil), // 44: organize.LogoutRequest
(*LogoutResponse)(nil), // 45: organize.LogoutResponse
(*MenuValue)(nil), // 42: organize.MenuValue
(*GetMenuRequest)(nil), // 43: organize.GetMenuRequest
(*GetMenuResponse)(nil), // 44: organize.GetMenuResponse
(*LoginRequest)(nil), // 45: organize.LoginRequest
(*LoginResponse)(nil), // 46: organize.LoginResponse
(*LogoutRequest)(nil), // 47: organize.LogoutRequest
(*LogoutResponse)(nil), // 48: organize.LogoutResponse
}
var file_organize_proto_depIdxs = []int32{
8, // 0: organize.MenuItem.permissions:type_name -> organize.PermissionItem
9, // 1: organize.MenuItem.children:type_name -> organize.MenuItem
9, // 2: organize.GetMenuResponse.data:type_name -> organize.MenuItem
9, // 2: organize.GetUserMenuResponse.data:type_name -> organize.MenuItem
7, // 3: organize.GetUserLabelResponse.data:type_name -> organize.LabelValue
7, // 4: organize.GetUserTagResponse.data:type_name -> organize.LabelValue
25, // 5: organize.DepartmentUserValue.children:type_name -> organize.DepartmentUserValue
@ -3081,43 +3251,47 @@ var file_organize_proto_depIdxs = []int32{
7, // 10: organize.GetRoleLabelResponse.data:type_name -> organize.LabelValue
39, // 11: organize.MenuLevelValue.children:type_name -> organize.MenuLevelValue
39, // 12: organize.GetMenuLevelLabelsResponse.data:type_name -> organize.MenuLevelValue
10, // 13: organize.UserService.GetMenus:input_type -> organize.GetMenuRequest
12, // 14: organize.UserService.GetProfile:input_type -> organize.GetProfileRequest
16, // 15: organize.UserService.UpdateProfile:input_type -> organize.UpdateProfileRequest
14, // 16: organize.UserService.ResetPassword:input_type -> organize.ResetPasswordRequest
18, // 17: organize.UserService.GetPermissions:input_type -> organize.GetPermissionRequest
20, // 18: organize.UserService.GetUserLabels:input_type -> organize.GetUserLabelRequest
22, // 19: organize.UserService.GetUserTags:input_type -> organize.GetUserTagRequest
26, // 20: organize.DepartmentService.GetDepartmentLabels:input_type -> organize.GetDepartmentLabelRequest
28, // 21: organize.DepartmentService.GetDepartmentUsers:input_type -> organize.GetDepartmentUserRequest
31, // 22: organize.DepartmentService.GetDepartmentLevelLabels:input_type -> organize.GetDepartmentLevelLabelsRequest
33, // 23: organize.RoleService.GetRoleLabels:input_type -> organize.GetRoleLabelRequest
35, // 24: organize.RoleService.GetRolePermissions:input_type -> organize.GetRolePermissionRequest
37, // 25: organize.RoleService.SaveRolePermission:input_type -> organize.SaveRolePermissionRequest
40, // 26: organize.MenuService.GetMenuLevelLabels:input_type -> organize.GetMenuLevelLabelsRequest
42, // 27: organize.AuthService.Login:input_type -> organize.LoginRequest
44, // 28: organize.AuthService.Logout:input_type -> organize.LogoutRequest
11, // 29: organize.UserService.GetMenus:output_type -> organize.GetMenuResponse
13, // 30: organize.UserService.GetProfile:output_type -> organize.GetProfileResponse
17, // 31: organize.UserService.UpdateProfile:output_type -> organize.UpdateProfileResponse
15, // 32: organize.UserService.ResetPassword:output_type -> organize.ResetPasswordResponse
19, // 33: organize.UserService.GetPermissions:output_type -> organize.GetPermissionResponse
21, // 34: organize.UserService.GetUserLabels:output_type -> organize.GetUserLabelResponse
23, // 35: organize.UserService.GetUserTags:output_type -> organize.GetUserTagResponse
27, // 36: organize.DepartmentService.GetDepartmentLabels:output_type -> organize.GetDepartmentLabelResponse
29, // 37: organize.DepartmentService.GetDepartmentUsers:output_type -> organize.GetDepartmentUserResponse
32, // 38: organize.DepartmentService.GetDepartmentLevelLabels:output_type -> organize.GetDepartmentLevelLabelsResponse
34, // 39: organize.RoleService.GetRoleLabels:output_type -> organize.GetRoleLabelResponse
36, // 40: organize.RoleService.GetRolePermissions:output_type -> organize.GetRolePermissionResponse
38, // 41: organize.RoleService.SaveRolePermission:output_type -> organize.SaveRolePermissionResponse
41, // 42: organize.MenuService.GetMenuLevelLabels:output_type -> organize.GetMenuLevelLabelsResponse
43, // 43: organize.AuthService.Login:output_type -> organize.LoginResponse
45, // 44: organize.AuthService.Logout:output_type -> organize.LogoutResponse
29, // [29:45] is the sub-list for method output_type
13, // [13:29] is the sub-list for method input_type
13, // [13:13] is the sub-list for extension type_name
13, // [13:13] is the sub-list for extension extendee
0, // [0:13] is the sub-list for field type_name
42, // 13: organize.MenuValue.children:type_name -> organize.MenuValue
42, // 14: organize.GetMenuResponse.data:type_name -> organize.MenuValue
10, // 15: organize.UserService.GetMenus:input_type -> organize.GetUserMenuRequest
12, // 16: organize.UserService.GetProfile:input_type -> organize.GetProfileRequest
16, // 17: organize.UserService.UpdateProfile:input_type -> organize.UpdateProfileRequest
14, // 18: organize.UserService.ResetPassword:input_type -> organize.ResetPasswordRequest
18, // 19: organize.UserService.GetPermissions:input_type -> organize.GetPermissionRequest
20, // 20: organize.UserService.GetUserLabels:input_type -> organize.GetUserLabelRequest
22, // 21: organize.UserService.GetUserTags:input_type -> organize.GetUserTagRequest
26, // 22: organize.DepartmentService.GetDepartmentLabels:input_type -> organize.GetDepartmentLabelRequest
28, // 23: organize.DepartmentService.GetDepartmentUsers:input_type -> organize.GetDepartmentUserRequest
31, // 24: organize.DepartmentService.GetDepartmentLevelLabels:input_type -> organize.GetDepartmentLevelLabelsRequest
33, // 25: organize.RoleService.GetRoleLabels:input_type -> organize.GetRoleLabelRequest
35, // 26: organize.RoleService.GetRolePermissions:input_type -> organize.GetRolePermissionRequest
37, // 27: organize.RoleService.SaveRolePermission:input_type -> organize.SaveRolePermissionRequest
43, // 28: organize.MenuService.GetMenus:input_type -> organize.GetMenuRequest
40, // 29: organize.MenuService.GetMenuLevelLabels:input_type -> organize.GetMenuLevelLabelsRequest
45, // 30: organize.AuthService.Login:input_type -> organize.LoginRequest
47, // 31: organize.AuthService.Logout:input_type -> organize.LogoutRequest
11, // 32: organize.UserService.GetMenus:output_type -> organize.GetUserMenuResponse
13, // 33: organize.UserService.GetProfile:output_type -> organize.GetProfileResponse
17, // 34: organize.UserService.UpdateProfile:output_type -> organize.UpdateProfileResponse
15, // 35: organize.UserService.ResetPassword:output_type -> organize.ResetPasswordResponse
19, // 36: organize.UserService.GetPermissions:output_type -> organize.GetPermissionResponse
21, // 37: organize.UserService.GetUserLabels:output_type -> organize.GetUserLabelResponse
23, // 38: organize.UserService.GetUserTags:output_type -> organize.GetUserTagResponse
27, // 39: organize.DepartmentService.GetDepartmentLabels:output_type -> organize.GetDepartmentLabelResponse
29, // 40: organize.DepartmentService.GetDepartmentUsers:output_type -> organize.GetDepartmentUserResponse
32, // 41: organize.DepartmentService.GetDepartmentLevelLabels:output_type -> organize.GetDepartmentLevelLabelsResponse
34, // 42: organize.RoleService.GetRoleLabels:output_type -> organize.GetRoleLabelResponse
36, // 43: organize.RoleService.GetRolePermissions:output_type -> organize.GetRolePermissionResponse
38, // 44: organize.RoleService.SaveRolePermission:output_type -> organize.SaveRolePermissionResponse
44, // 45: organize.MenuService.GetMenus:output_type -> organize.GetMenuResponse
41, // 46: organize.MenuService.GetMenuLevelLabels:output_type -> organize.GetMenuLevelLabelsResponse
46, // 47: organize.AuthService.Login:output_type -> organize.LoginResponse
48, // 48: organize.AuthService.Logout:output_type -> organize.LogoutResponse
32, // [32:49] is the sub-list for method output_type
15, // [15:32] is the sub-list for method input_type
15, // [15:15] is the sub-list for extension type_name
15, // [15:15] is the sub-list for extension extendee
0, // [0:15] is the sub-list for field type_name
}
func init() { file_organize_proto_init() }
@ -3131,7 +3305,7 @@ func file_organize_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_organize_proto_rawDesc), len(file_organize_proto_rawDesc)),
NumEnums: 0,
NumMessages: 46,
NumMessages: 49,
NumExtensions: 0,
NumServices: 5,
},

View File

@ -1445,22 +1445,22 @@ var _ interface {
ErrorName() string
} = MenuItemValidationError{}
// Validate checks the field values on GetMenuRequest with the rules defined in
// the proto definition for this message. If any rules are violated, the first
// error encountered is returned, or nil if there are no violations.
func (m *GetMenuRequest) Validate() error {
// Validate checks the field values on GetUserMenuRequest with the rules
// defined in the proto definition for this message. If any rules are
// violated, the first error encountered is returned, or nil if there are no violations.
func (m *GetUserMenuRequest) Validate() error {
return m.validate(false)
}
// ValidateAll checks the field values on GetMenuRequest with the rules defined
// in the proto definition for this message. If any rules are violated, the
// result is a list of violation errors wrapped in GetMenuRequestMultiError,
// or nil if none found.
func (m *GetMenuRequest) ValidateAll() error {
// ValidateAll checks the field values on GetUserMenuRequest with the rules
// defined in the proto definition for this message. If any rules are
// violated, the result is a list of violation errors wrapped in
// GetUserMenuRequestMultiError, or nil if none found.
func (m *GetUserMenuRequest) ValidateAll() error {
return m.validate(true)
}
func (m *GetMenuRequest) validate(all bool) error {
func (m *GetUserMenuRequest) validate(all bool) error {
if m == nil {
return nil
}
@ -1470,19 +1470,19 @@ func (m *GetMenuRequest) validate(all bool) error {
// no validation rules for Permission
if len(errors) > 0 {
return GetMenuRequestMultiError(errors)
return GetUserMenuRequestMultiError(errors)
}
return nil
}
// GetMenuRequestMultiError is an error wrapping multiple validation errors
// returned by GetMenuRequest.ValidateAll() if the designated constraints
// GetUserMenuRequestMultiError is an error wrapping multiple validation errors
// returned by GetUserMenuRequest.ValidateAll() if the designated constraints
// aren't met.
type GetMenuRequestMultiError []error
type GetUserMenuRequestMultiError []error
// Error returns a concatenation of all the error messages it wraps.
func (m GetMenuRequestMultiError) Error() string {
func (m GetUserMenuRequestMultiError) Error() string {
msgs := make([]string, 0, len(m))
for _, err := range m {
msgs = append(msgs, err.Error())
@ -1491,11 +1491,11 @@ func (m GetMenuRequestMultiError) Error() string {
}
// AllErrors returns a list of validation violation errors.
func (m GetMenuRequestMultiError) AllErrors() []error { return m }
func (m GetUserMenuRequestMultiError) AllErrors() []error { return m }
// GetMenuRequestValidationError is the validation error returned by
// GetMenuRequest.Validate if the designated constraints aren't met.
type GetMenuRequestValidationError struct {
// GetUserMenuRequestValidationError is the validation error returned by
// GetUserMenuRequest.Validate if the designated constraints aren't met.
type GetUserMenuRequestValidationError struct {
field string
reason string
cause error
@ -1503,22 +1503,24 @@ type GetMenuRequestValidationError struct {
}
// Field function returns field value.
func (e GetMenuRequestValidationError) Field() string { return e.field }
func (e GetUserMenuRequestValidationError) Field() string { return e.field }
// Reason function returns reason value.
func (e GetMenuRequestValidationError) Reason() string { return e.reason }
func (e GetUserMenuRequestValidationError) Reason() string { return e.reason }
// Cause function returns cause value.
func (e GetMenuRequestValidationError) Cause() error { return e.cause }
func (e GetUserMenuRequestValidationError) Cause() error { return e.cause }
// Key function returns key value.
func (e GetMenuRequestValidationError) Key() bool { return e.key }
func (e GetUserMenuRequestValidationError) Key() bool { return e.key }
// ErrorName returns error name.
func (e GetMenuRequestValidationError) ErrorName() string { return "GetMenuRequestValidationError" }
func (e GetUserMenuRequestValidationError) ErrorName() string {
return "GetUserMenuRequestValidationError"
}
// Error satisfies the builtin error interface
func (e GetMenuRequestValidationError) Error() string {
func (e GetUserMenuRequestValidationError) Error() string {
cause := ""
if e.cause != nil {
cause = fmt.Sprintf(" | caused by: %v", e.cause)
@ -1530,14 +1532,14 @@ func (e GetMenuRequestValidationError) Error() string {
}
return fmt.Sprintf(
"invalid %sGetMenuRequest.%s: %s%s",
"invalid %sGetUserMenuRequest.%s: %s%s",
key,
e.field,
e.reason,
cause)
}
var _ error = GetMenuRequestValidationError{}
var _ error = GetUserMenuRequestValidationError{}
var _ interface {
Field() string
@ -1545,24 +1547,24 @@ var _ interface {
Key() bool
Cause() error
ErrorName() string
} = GetMenuRequestValidationError{}
} = GetUserMenuRequestValidationError{}
// Validate checks the field values on GetMenuResponse with the rules defined
// in the proto definition for this message. If any rules are violated, the
// first error encountered is returned, or nil if there are no violations.
func (m *GetMenuResponse) Validate() error {
// Validate checks the field values on GetUserMenuResponse with the rules
// defined in the proto definition for this message. If any rules are
// violated, the first error encountered is returned, or nil if there are no violations.
func (m *GetUserMenuResponse) Validate() error {
return m.validate(false)
}
// ValidateAll checks the field values on GetMenuResponse with the rules
// ValidateAll checks the field values on GetUserMenuResponse with the rules
// defined in the proto definition for this message. If any rules are
// violated, the result is a list of violation errors wrapped in
// GetMenuResponseMultiError, or nil if none found.
func (m *GetMenuResponse) ValidateAll() error {
// GetUserMenuResponseMultiError, or nil if none found.
func (m *GetUserMenuResponse) ValidateAll() error {
return m.validate(true)
}
func (m *GetMenuResponse) validate(all bool) error {
func (m *GetUserMenuResponse) validate(all bool) error {
if m == nil {
return nil
}
@ -1576,7 +1578,7 @@ func (m *GetMenuResponse) validate(all bool) error {
switch v := interface{}(item).(type) {
case interface{ ValidateAll() error }:
if err := v.ValidateAll(); err != nil {
errors = append(errors, GetMenuResponseValidationError{
errors = append(errors, GetUserMenuResponseValidationError{
field: fmt.Sprintf("Data[%v]", idx),
reason: "embedded message failed validation",
cause: err,
@ -1584,7 +1586,7 @@ func (m *GetMenuResponse) validate(all bool) error {
}
case interface{ Validate() error }:
if err := v.Validate(); err != nil {
errors = append(errors, GetMenuResponseValidationError{
errors = append(errors, GetUserMenuResponseValidationError{
field: fmt.Sprintf("Data[%v]", idx),
reason: "embedded message failed validation",
cause: err,
@ -1593,7 +1595,7 @@ func (m *GetMenuResponse) validate(all bool) error {
}
} else if v, ok := interface{}(item).(interface{ Validate() error }); ok {
if err := v.Validate(); err != nil {
return GetMenuResponseValidationError{
return GetUserMenuResponseValidationError{
field: fmt.Sprintf("Data[%v]", idx),
reason: "embedded message failed validation",
cause: err,
@ -1604,19 +1606,19 @@ func (m *GetMenuResponse) validate(all bool) error {
}
if len(errors) > 0 {
return GetMenuResponseMultiError(errors)
return GetUserMenuResponseMultiError(errors)
}
return nil
}
// GetMenuResponseMultiError is an error wrapping multiple validation errors
// returned by GetMenuResponse.ValidateAll() if the designated constraints
// aren't met.
type GetMenuResponseMultiError []error
// GetUserMenuResponseMultiError is an error wrapping multiple validation
// errors returned by GetUserMenuResponse.ValidateAll() if the designated
// constraints aren't met.
type GetUserMenuResponseMultiError []error
// Error returns a concatenation of all the error messages it wraps.
func (m GetMenuResponseMultiError) Error() string {
func (m GetUserMenuResponseMultiError) Error() string {
msgs := make([]string, 0, len(m))
for _, err := range m {
msgs = append(msgs, err.Error())
@ -1625,11 +1627,11 @@ func (m GetMenuResponseMultiError) Error() string {
}
// AllErrors returns a list of validation violation errors.
func (m GetMenuResponseMultiError) AllErrors() []error { return m }
func (m GetUserMenuResponseMultiError) AllErrors() []error { return m }
// GetMenuResponseValidationError is the validation error returned by
// GetMenuResponse.Validate if the designated constraints aren't met.
type GetMenuResponseValidationError struct {
// GetUserMenuResponseValidationError is the validation error returned by
// GetUserMenuResponse.Validate if the designated constraints aren't met.
type GetUserMenuResponseValidationError struct {
field string
reason string
cause error
@ -1637,22 +1639,24 @@ type GetMenuResponseValidationError struct {
}
// Field function returns field value.
func (e GetMenuResponseValidationError) Field() string { return e.field }
func (e GetUserMenuResponseValidationError) Field() string { return e.field }
// Reason function returns reason value.
func (e GetMenuResponseValidationError) Reason() string { return e.reason }
func (e GetUserMenuResponseValidationError) Reason() string { return e.reason }
// Cause function returns cause value.
func (e GetMenuResponseValidationError) Cause() error { return e.cause }
func (e GetUserMenuResponseValidationError) Cause() error { return e.cause }
// Key function returns key value.
func (e GetMenuResponseValidationError) Key() bool { return e.key }
func (e GetUserMenuResponseValidationError) Key() bool { return e.key }
// ErrorName returns error name.
func (e GetMenuResponseValidationError) ErrorName() string { return "GetMenuResponseValidationError" }
func (e GetUserMenuResponseValidationError) ErrorName() string {
return "GetUserMenuResponseValidationError"
}
// Error satisfies the builtin error interface
func (e GetMenuResponseValidationError) Error() string {
func (e GetUserMenuResponseValidationError) Error() string {
cause := ""
if e.cause != nil {
cause = fmt.Sprintf(" | caused by: %v", e.cause)
@ -1664,14 +1668,14 @@ func (e GetMenuResponseValidationError) Error() string {
}
return fmt.Sprintf(
"invalid %sGetMenuResponse.%s: %s%s",
"invalid %sGetUserMenuResponse.%s: %s%s",
key,
e.field,
e.reason,
cause)
}
var _ error = GetMenuResponseValidationError{}
var _ error = GetUserMenuResponseValidationError{}
var _ interface {
Field() string
@ -1679,7 +1683,7 @@ var _ interface {
Key() bool
Cause() error
ErrorName() string
} = GetMenuResponseValidationError{}
} = GetUserMenuResponseValidationError{}
// Validate checks the field values on GetProfileRequest with the rules defined
// in the proto definition for this message. If any rules are violated, the
@ -5149,6 +5153,381 @@ var _ interface {
ErrorName() string
} = GetMenuLevelLabelsResponseValidationError{}
// Validate checks the field values on MenuValue with the rules defined in the
// proto definition for this message. If any rules are violated, the first
// error encountered is returned, or nil if there are no violations.
func (m *MenuValue) Validate() error {
return m.validate(false)
}
// ValidateAll checks the field values on MenuValue with the rules defined in
// the proto definition for this message. If any rules are violated, the
// result is a list of violation errors wrapped in MenuValueMultiError, or nil
// if none found.
func (m *MenuValue) ValidateAll() error {
return m.validate(true)
}
func (m *MenuValue) validate(all bool) error {
if m == nil {
return nil
}
var errors []error
// no validation rules for Id
// no validation rules for Parent
// no validation rules for Name
// no validation rules for Label
for idx, item := range m.GetChildren() {
_, _ = idx, item
if all {
switch v := interface{}(item).(type) {
case interface{ ValidateAll() error }:
if err := v.ValidateAll(); err != nil {
errors = append(errors, MenuValueValidationError{
field: fmt.Sprintf("Children[%v]", idx),
reason: "embedded message failed validation",
cause: err,
})
}
case interface{ Validate() error }:
if err := v.Validate(); err != nil {
errors = append(errors, MenuValueValidationError{
field: fmt.Sprintf("Children[%v]", idx),
reason: "embedded message failed validation",
cause: err,
})
}
}
} else if v, ok := interface{}(item).(interface{ Validate() error }); ok {
if err := v.Validate(); err != nil {
return MenuValueValidationError{
field: fmt.Sprintf("Children[%v]", idx),
reason: "embedded message failed validation",
cause: err,
}
}
}
}
if len(errors) > 0 {
return MenuValueMultiError(errors)
}
return nil
}
// MenuValueMultiError is an error wrapping multiple validation errors returned
// by MenuValue.ValidateAll() if the designated constraints aren't met.
type MenuValueMultiError []error
// Error returns a concatenation of all the error messages it wraps.
func (m MenuValueMultiError) Error() string {
msgs := make([]string, 0, len(m))
for _, err := range m {
msgs = append(msgs, err.Error())
}
return strings.Join(msgs, "; ")
}
// AllErrors returns a list of validation violation errors.
func (m MenuValueMultiError) AllErrors() []error { return m }
// MenuValueValidationError is the validation error returned by
// MenuValue.Validate if the designated constraints aren't met.
type MenuValueValidationError struct {
field string
reason string
cause error
key bool
}
// Field function returns field value.
func (e MenuValueValidationError) Field() string { return e.field }
// Reason function returns reason value.
func (e MenuValueValidationError) Reason() string { return e.reason }
// Cause function returns cause value.
func (e MenuValueValidationError) Cause() error { return e.cause }
// Key function returns key value.
func (e MenuValueValidationError) Key() bool { return e.key }
// ErrorName returns error name.
func (e MenuValueValidationError) ErrorName() string { return "MenuValueValidationError" }
// Error satisfies the builtin error interface
func (e MenuValueValidationError) Error() string {
cause := ""
if e.cause != nil {
cause = fmt.Sprintf(" | caused by: %v", e.cause)
}
key := ""
if e.key {
key = "key for "
}
return fmt.Sprintf(
"invalid %sMenuValue.%s: %s%s",
key,
e.field,
e.reason,
cause)
}
var _ error = MenuValueValidationError{}
var _ interface {
Field() string
Reason() string
Key() bool
Cause() error
ErrorName() string
} = MenuValueValidationError{}
// Validate checks the field values on GetMenuRequest with the rules defined in
// the proto definition for this message. If any rules are violated, the first
// error encountered is returned, or nil if there are no violations.
func (m *GetMenuRequest) Validate() error {
return m.validate(false)
}
// ValidateAll checks the field values on GetMenuRequest with the rules defined
// in the proto definition for this message. If any rules are violated, the
// result is a list of violation errors wrapped in GetMenuRequestMultiError,
// or nil if none found.
func (m *GetMenuRequest) ValidateAll() error {
return m.validate(true)
}
func (m *GetMenuRequest) validate(all bool) error {
if m == nil {
return nil
}
var errors []error
if len(errors) > 0 {
return GetMenuRequestMultiError(errors)
}
return nil
}
// GetMenuRequestMultiError is an error wrapping multiple validation errors
// returned by GetMenuRequest.ValidateAll() if the designated constraints
// aren't met.
type GetMenuRequestMultiError []error
// Error returns a concatenation of all the error messages it wraps.
func (m GetMenuRequestMultiError) Error() string {
msgs := make([]string, 0, len(m))
for _, err := range m {
msgs = append(msgs, err.Error())
}
return strings.Join(msgs, "; ")
}
// AllErrors returns a list of validation violation errors.
func (m GetMenuRequestMultiError) AllErrors() []error { return m }
// GetMenuRequestValidationError is the validation error returned by
// GetMenuRequest.Validate if the designated constraints aren't met.
type GetMenuRequestValidationError struct {
field string
reason string
cause error
key bool
}
// Field function returns field value.
func (e GetMenuRequestValidationError) Field() string { return e.field }
// Reason function returns reason value.
func (e GetMenuRequestValidationError) Reason() string { return e.reason }
// Cause function returns cause value.
func (e GetMenuRequestValidationError) Cause() error { return e.cause }
// Key function returns key value.
func (e GetMenuRequestValidationError) Key() bool { return e.key }
// ErrorName returns error name.
func (e GetMenuRequestValidationError) ErrorName() string { return "GetMenuRequestValidationError" }
// Error satisfies the builtin error interface
func (e GetMenuRequestValidationError) Error() string {
cause := ""
if e.cause != nil {
cause = fmt.Sprintf(" | caused by: %v", e.cause)
}
key := ""
if e.key {
key = "key for "
}
return fmt.Sprintf(
"invalid %sGetMenuRequest.%s: %s%s",
key,
e.field,
e.reason,
cause)
}
var _ error = GetMenuRequestValidationError{}
var _ interface {
Field() string
Reason() string
Key() bool
Cause() error
ErrorName() string
} = GetMenuRequestValidationError{}
// Validate checks the field values on GetMenuResponse with the rules defined
// in the proto definition for this message. If any rules are violated, the
// first error encountered is returned, or nil if there are no violations.
func (m *GetMenuResponse) Validate() error {
return m.validate(false)
}
// ValidateAll checks the field values on GetMenuResponse with the rules
// defined in the proto definition for this message. If any rules are
// violated, the result is a list of violation errors wrapped in
// GetMenuResponseMultiError, or nil if none found.
func (m *GetMenuResponse) ValidateAll() error {
return m.validate(true)
}
func (m *GetMenuResponse) validate(all bool) error {
if m == nil {
return nil
}
var errors []error
for idx, item := range m.GetData() {
_, _ = idx, item
if all {
switch v := interface{}(item).(type) {
case interface{ ValidateAll() error }:
if err := v.ValidateAll(); err != nil {
errors = append(errors, GetMenuResponseValidationError{
field: fmt.Sprintf("Data[%v]", idx),
reason: "embedded message failed validation",
cause: err,
})
}
case interface{ Validate() error }:
if err := v.Validate(); err != nil {
errors = append(errors, GetMenuResponseValidationError{
field: fmt.Sprintf("Data[%v]", idx),
reason: "embedded message failed validation",
cause: err,
})
}
}
} else if v, ok := interface{}(item).(interface{ Validate() error }); ok {
if err := v.Validate(); err != nil {
return GetMenuResponseValidationError{
field: fmt.Sprintf("Data[%v]", idx),
reason: "embedded message failed validation",
cause: err,
}
}
}
}
if len(errors) > 0 {
return GetMenuResponseMultiError(errors)
}
return nil
}
// GetMenuResponseMultiError is an error wrapping multiple validation errors
// returned by GetMenuResponse.ValidateAll() if the designated constraints
// aren't met.
type GetMenuResponseMultiError []error
// Error returns a concatenation of all the error messages it wraps.
func (m GetMenuResponseMultiError) Error() string {
msgs := make([]string, 0, len(m))
for _, err := range m {
msgs = append(msgs, err.Error())
}
return strings.Join(msgs, "; ")
}
// AllErrors returns a list of validation violation errors.
func (m GetMenuResponseMultiError) AllErrors() []error { return m }
// GetMenuResponseValidationError is the validation error returned by
// GetMenuResponse.Validate if the designated constraints aren't met.
type GetMenuResponseValidationError struct {
field string
reason string
cause error
key bool
}
// Field function returns field value.
func (e GetMenuResponseValidationError) Field() string { return e.field }
// Reason function returns reason value.
func (e GetMenuResponseValidationError) Reason() string { return e.reason }
// Cause function returns cause value.
func (e GetMenuResponseValidationError) Cause() error { return e.cause }
// Key function returns key value.
func (e GetMenuResponseValidationError) Key() bool { return e.key }
// ErrorName returns error name.
func (e GetMenuResponseValidationError) ErrorName() string { return "GetMenuResponseValidationError" }
// Error satisfies the builtin error interface
func (e GetMenuResponseValidationError) Error() string {
cause := ""
if e.cause != nil {
cause = fmt.Sprintf(" | caused by: %v", e.cause)
}
key := ""
if e.key {
key = "key for "
}
return fmt.Sprintf(
"invalid %sGetMenuResponse.%s: %s%s",
key,
e.field,
e.reason,
cause)
}
var _ error = GetMenuResponseValidationError{}
var _ interface {
Field() string
Reason() string
Key() bool
Cause() error
ErrorName() string
} = GetMenuResponseValidationError{}
// Validate checks the field values on LoginRequest with the rules defined in
// the proto definition for this message. If any rules are violated, the first
// error encountered is returned, or nil if there are no violations.

View File

@ -17,7 +17,7 @@ message Menu {
int64 id = 1 [(aeus.field) = {gorm:"primaryKey",comment:"菜单ID"}];
int64 created_at = 2 [(aeus.field)={scenarios:"view;export",comment:"创建时间"}];
int64 updated_at = 3 [(aeus.field)={gorm:"index",scenarios:"view;export",comment:"更新时间"}];
string parent = 4 [(aeus.field)={gorm:"index;size:60",props:"readonly:update",live:"type:dropdown;url:/menu/level-labels",format:"menu",comment:"父级菜单"}];
string parent = 4 [(aeus.field)={gorm:"index;size:60",scenarios:"create;update;view;export",props:"readonly:update",live:"type:dropdown;url:/menu/level-labels",format:"menu",comment:"父级菜单"}];
string name = 5 [(aeus.field)={gorm:"index;size:60",props:"readonly:update",rule:"unique;required",comment: "组件名称"},(validate.rules).string = {max_len: 60}];
string label = 6 [(aeus.field)={gorm:"size:120",rule:"required",comment: "菜单标题"},(validate.rules).string = {max_len: 120}];
string uri = 7 [(aeus.field)={gorm:"size:512",rule:"required",scenarios:"create;update;view;export",comment: "菜单链接"},(validate.rules).string = {max_len: 512}];
@ -25,7 +25,7 @@ message Menu {
string icon = 9 [(aeus.field)={gorm:"size:60",scenarios:"create;update;view;export",comment: "菜单图标"},(validate.rules).string = {max_len: 60}];
bool hidden = 10 [(aeus.field)={scenarios:"create;update;view;export",comment:"是否隐藏"}];
bool public = 11 [(aeus.field)={scenarios:"create;update;view;export",comment:"是否公开"}];
string description = 12 [(aeus.field)={gorm:"size:1024",scenarios:"create;update;view;export;list",format:"textarea",comment: "备注说明"},(validate.rules).string = {max_len: 1024}];
string description = 12 [(aeus.field)={gorm:"size:1024",scenarios:"create;update;view;export",format:"textarea",comment: "备注说明"},(validate.rules).string = {max_len: 1024}];
int64 position = 13 [(aeus.field)={comment:"排序",scenarios:"create;update"}];
}
@ -37,8 +37,8 @@ message Role {
int64 id = 1 [(aeus.field) = {gorm:"primaryKey",comment: "角色ID"}];
int64 created_at = 2 [(aeus.field)={scenarios:"view;export",comment:"创建时间"}];
int64 updated_at = 3 [(aeus.field)={gorm:"index",scenarios:"view;export",comment:"更新时间"}];
string name = 4 [(aeus.field)={gorm:"index;size:60",props:"readonly:update",comment: "角色名称"},(validate.rules).string = {max_len: 60}];
string label = 5 [(aeus.field)={gorm:"size:60",comment: "角色标题"},(validate.rules).string = {max_len: 60}];
string name = 4 [(aeus.field)={gorm:"index;size:60",rule:"required",props:"readonly:update",comment: "角色名称"},(validate.rules).string = {max_len: 60}];
string label = 5 [(aeus.field)={gorm:"size:60",rule:"required",comment: "角色标题"},(validate.rules).string = {max_len: 60}];
string description = 6 [(aeus.field)={gorm:"size:1024",scenarios:"list;create;update;export",format:"textarea",comment: "备注说明"},(validate.rules).string = {max_len: 1024}];
}
@ -139,12 +139,12 @@ message MenuItem {
}
//
message GetMenuRequest {
message GetUserMenuRequest {
bool permission = 1;
}
//
message GetMenuResponse {
message GetUserMenuResponse {
repeated MenuItem data = 1;
}
@ -213,7 +213,7 @@ message GetUserTagResponse {
//
service UserService {
//
rpc GetMenus(GetMenuRequest) returns (GetMenuResponse) {
rpc GetMenus(GetUserMenuRequest) returns (GetUserMenuResponse) {
option (google.api.http) = {
get: "/user/menus"
};
@ -377,7 +377,28 @@ message GetMenuLevelLabelsResponse {
repeated MenuLevelValue data = 1;
}
message MenuValue {
int64 id = 1;
string parent = 2;
string name = 3;
string label = 4;
repeated MenuValue children = 5;
}
message GetMenuRequest{
}
message GetMenuResponse{
repeated MenuValue data = 1;
}
service MenuService {
rpc GetMenus(GetMenuRequest) returns (GetMenuResponse) {
option (google.api.http) = {
get: "/menu/list"
};
}
rpc GetMenuLevelLabels(GetMenuLevelLabelsRequest) returns (GetMenuLevelLabelsResponse) {
option (google.api.http) = {
get: "/menu/level-labels"

View File

@ -35,7 +35,7 @@ const (
// 用户服务
type UserServiceClient interface {
// 获取用户菜单
GetMenus(ctx context.Context, in *GetMenuRequest, opts ...grpc.CallOption) (*GetMenuResponse, error)
GetMenus(ctx context.Context, in *GetUserMenuRequest, opts ...grpc.CallOption) (*GetUserMenuResponse, error)
// 获取用户信息
GetProfile(ctx context.Context, in *GetProfileRequest, opts ...grpc.CallOption) (*GetProfileResponse, error)
// 更新用户信息
@ -58,9 +58,9 @@ func NewUserServiceClient(cc grpc.ClientConnInterface) UserServiceClient {
return &userServiceClient{cc}
}
func (c *userServiceClient) GetMenus(ctx context.Context, in *GetMenuRequest, opts ...grpc.CallOption) (*GetMenuResponse, error) {
func (c *userServiceClient) GetMenus(ctx context.Context, in *GetUserMenuRequest, opts ...grpc.CallOption) (*GetUserMenuResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetMenuResponse)
out := new(GetUserMenuResponse)
err := c.cc.Invoke(ctx, UserService_GetMenus_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
@ -135,7 +135,7 @@ func (c *userServiceClient) GetUserTags(ctx context.Context, in *GetUserTagReque
// 用户服务
type UserServiceServer interface {
// 获取用户菜单
GetMenus(context.Context, *GetMenuRequest) (*GetMenuResponse, error)
GetMenus(context.Context, *GetUserMenuRequest) (*GetUserMenuResponse, error)
// 获取用户信息
GetProfile(context.Context, *GetProfileRequest) (*GetProfileResponse, error)
// 更新用户信息
@ -158,7 +158,7 @@ type UserServiceServer interface {
// pointer dereference when methods are called.
type UnimplementedUserServiceServer struct{}
func (UnimplementedUserServiceServer) GetMenus(context.Context, *GetMenuRequest) (*GetMenuResponse, error) {
func (UnimplementedUserServiceServer) GetMenus(context.Context, *GetUserMenuRequest) (*GetUserMenuResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetMenus not implemented")
}
func (UnimplementedUserServiceServer) GetProfile(context.Context, *GetProfileRequest) (*GetProfileResponse, error) {
@ -201,7 +201,7 @@ func RegisterUserServiceServer(s grpc.ServiceRegistrar, srv UserServiceServer) {
}
func _UserService_GetMenus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetMenuRequest)
in := new(GetUserMenuRequest)
if err := dec(in); err != nil {
return nil, err
}
@ -213,7 +213,7 @@ func _UserService_GetMenus_Handler(srv interface{}, ctx context.Context, dec fun
FullMethod: UserService_GetMenus_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(UserServiceServer).GetMenus(ctx, req.(*GetMenuRequest))
return srv.(UserServiceServer).GetMenus(ctx, req.(*GetUserMenuRequest))
}
return interceptor(ctx, in, info, handler)
}
@ -729,6 +729,7 @@ var RoleService_ServiceDesc = grpc.ServiceDesc{
}
const (
MenuService_GetMenus_FullMethodName = "/organize.MenuService/GetMenus"
MenuService_GetMenuLevelLabels_FullMethodName = "/organize.MenuService/GetMenuLevelLabels"
)
@ -736,6 +737,7 @@ const (
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type MenuServiceClient interface {
GetMenus(ctx context.Context, in *GetMenuRequest, opts ...grpc.CallOption) (*GetMenuResponse, error)
GetMenuLevelLabels(ctx context.Context, in *GetMenuLevelLabelsRequest, opts ...grpc.CallOption) (*GetMenuLevelLabelsResponse, error)
}
@ -747,6 +749,16 @@ func NewMenuServiceClient(cc grpc.ClientConnInterface) MenuServiceClient {
return &menuServiceClient{cc}
}
func (c *menuServiceClient) GetMenus(ctx context.Context, in *GetMenuRequest, opts ...grpc.CallOption) (*GetMenuResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetMenuResponse)
err := c.cc.Invoke(ctx, MenuService_GetMenus_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *menuServiceClient) GetMenuLevelLabels(ctx context.Context, in *GetMenuLevelLabelsRequest, opts ...grpc.CallOption) (*GetMenuLevelLabelsResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetMenuLevelLabelsResponse)
@ -761,6 +773,7 @@ func (c *menuServiceClient) GetMenuLevelLabels(ctx context.Context, in *GetMenuL
// All implementations must embed UnimplementedMenuServiceServer
// for forward compatibility.
type MenuServiceServer interface {
GetMenus(context.Context, *GetMenuRequest) (*GetMenuResponse, error)
GetMenuLevelLabels(context.Context, *GetMenuLevelLabelsRequest) (*GetMenuLevelLabelsResponse, error)
mustEmbedUnimplementedMenuServiceServer()
}
@ -772,6 +785,9 @@ type MenuServiceServer interface {
// pointer dereference when methods are called.
type UnimplementedMenuServiceServer struct{}
func (UnimplementedMenuServiceServer) GetMenus(context.Context, *GetMenuRequest) (*GetMenuResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetMenus not implemented")
}
func (UnimplementedMenuServiceServer) GetMenuLevelLabels(context.Context, *GetMenuLevelLabelsRequest) (*GetMenuLevelLabelsResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetMenuLevelLabels not implemented")
}
@ -796,6 +812,24 @@ func RegisterMenuServiceServer(s grpc.ServiceRegistrar, srv MenuServiceServer) {
s.RegisterService(&MenuService_ServiceDesc, srv)
}
func _MenuService_GetMenus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetMenuRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(MenuServiceServer).GetMenus(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: MenuService_GetMenus_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MenuServiceServer).GetMenus(ctx, req.(*GetMenuRequest))
}
return interceptor(ctx, in, info, handler)
}
func _MenuService_GetMenuLevelLabels_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetMenuLevelLabelsRequest)
if err := dec(in); err != nil {
@ -821,6 +855,10 @@ var MenuService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "organize.MenuService",
HandlerType: (*MenuServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "GetMenus",
Handler: _MenuService_GetMenus_Handler,
},
{
MethodName: "GetMenuLevelLabels",
Handler: _MenuService_GetMenuLevelLabels_Handler,

View File

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go-aeus. DO NOT EDIT.
// source: organize.proto
// date: 2025-06-18 15:37:30
// date: 2025-06-22 11:09:05
package pb
@ -11,57 +11,69 @@ import (
)
type UserServiceHttpServer interface {
GetMenus(context.Context, *GetMenuRequest) (*GetMenuResponse, error)
GetProfile(context.Context, *GetProfileRequest) (*GetProfileResponse, error)
// 获取用户菜单
GetMenus(ctx context.Context, req *GetUserMenuRequest) (res *GetUserMenuResponse, err error)
UpdateProfile(context.Context, *UpdateProfileRequest) (*UpdateProfileResponse, error)
// 获取用户信息
GetProfile(ctx context.Context, req *GetProfileRequest) (res *GetProfileResponse, err error)
ResetPassword(context.Context, *ResetPasswordRequest) (*ResetPasswordResponse, error)
// 更新用户信息
UpdateProfile(ctx context.Context, req *UpdateProfileRequest) (res *UpdateProfileResponse, err error)
GetPermissions(context.Context, *GetPermissionRequest) (*GetPermissionResponse, error)
// 重置用户密码
ResetPassword(ctx context.Context, req *ResetPasswordRequest) (res *ResetPasswordResponse, err error)
GetUserLabels(context.Context, *GetUserLabelRequest) (*GetUserLabelResponse, error)
// 获取用户权限
GetPermissions(ctx context.Context, req *GetPermissionRequest) (res *GetPermissionResponse, err error)
GetUserTags(context.Context, *GetUserTagRequest) (*GetUserTagResponse, error)
// 获取用户标签
GetUserLabels(ctx context.Context, req *GetUserLabelRequest) (res *GetUserLabelResponse, err error)
// 获取用户标签
GetUserTags(ctx context.Context, req *GetUserTagRequest) (res *GetUserTagResponse, err error)
}
type DepartmentServiceHttpServer interface {
GetDepartmentLabels(context.Context, *GetDepartmentLabelRequest) (*GetDepartmentLabelResponse, error)
GetDepartmentUsers(context.Context, *GetDepartmentUserRequest) (*GetDepartmentUserResponse, error)
// 获取部门标签
GetDepartmentLabels(ctx context.Context, req *GetDepartmentLabelRequest) (res *GetDepartmentLabelResponse, err error)
GetDepartmentLevelLabels(context.Context, *GetDepartmentLevelLabelsRequest) (*GetDepartmentLevelLabelsResponse, error)
GetDepartmentUsers(ctx context.Context, req *GetDepartmentUserRequest) (res *GetDepartmentUserResponse, err error)
GetDepartmentLevelLabels(ctx context.Context, req *GetDepartmentLevelLabelsRequest) (res *GetDepartmentLevelLabelsResponse, err error)
}
type RoleServiceHttpServer interface {
GetRoleLabels(context.Context, *GetRoleLabelRequest) (*GetRoleLabelResponse, error)
GetRolePermissions(context.Context, *GetRolePermissionRequest) (*GetRolePermissionResponse, error)
// 获取角色标签
GetRoleLabels(ctx context.Context, req *GetRoleLabelRequest) (res *GetRoleLabelResponse, err error)
SaveRolePermission(context.Context, *SaveRolePermissionRequest) (*SaveRolePermissionResponse, error)
// 获取角色权限
GetRolePermissions(ctx context.Context, req *GetRolePermissionRequest) (res *GetRolePermissionResponse, err error)
SaveRolePermission(ctx context.Context, req *SaveRolePermissionRequest) (res *SaveRolePermissionResponse, err error)
}
type MenuServiceHttpServer interface {
GetMenuLevelLabels(context.Context, *GetMenuLevelLabelsRequest) (*GetMenuLevelLabelsResponse, error)
GetMenus(ctx context.Context, req *GetMenuRequest) (res *GetMenuResponse, err error)
GetMenuLevelLabels(ctx context.Context, req *GetMenuLevelLabelsRequest) (res *GetMenuLevelLabelsResponse, err error)
}
type AuthServiceHttpServer interface {
Login(context.Context, *LoginRequest) (*LoginResponse, error)
Login(ctx context.Context, req *LoginRequest) (res *LoginResponse, err error)
Logout(context.Context, *LogoutRequest) (*LogoutResponse, error)
Logout(ctx context.Context, req *LogoutRequest) (res *LogoutResponse, err error)
}
// 获取用户菜单
func handleUserServiceGetMenus(s UserServiceHttpServer) http.HandleFunc {
return func(ctx *http.Context) (err error) {
req := &GetMenuRequest{}
req := &GetUserMenuRequest{}
if err := ctx.Bind(req); err != nil {
return ctx.Error(errors.Invalid, err.Error())
}
if res, err := s.GetMenus(ctx.Context(), req); err != nil {
if er, ok := err.(*errors.Error); ok {
return ctx.Error(er.Code, er.Message)
@ -75,15 +87,12 @@ func handleUserServiceGetMenus(s UserServiceHttpServer) http.HandleFunc {
}
// 获取用户信息
func handleUserServiceGetProfile(s UserServiceHttpServer) http.HandleFunc {
return func(ctx *http.Context) (err error) {
req := &GetProfileRequest{}
if err := ctx.Bind(req); err != nil {
return ctx.Error(errors.Invalid, err.Error())
}
if res, err := s.GetProfile(ctx.Context(), req); err != nil {
if er, ok := err.(*errors.Error); ok {
return ctx.Error(er.Code, er.Message)
@ -97,15 +106,12 @@ func handleUserServiceGetProfile(s UserServiceHttpServer) http.HandleFunc {
}
// 更新用户信息
func handleUserServiceUpdateProfile(s UserServiceHttpServer) http.HandleFunc {
return func(ctx *http.Context) (err error) {
req := &UpdateProfileRequest{}
if err := ctx.Bind(req); err != nil {
return ctx.Error(errors.Invalid, err.Error())
}
if res, err := s.UpdateProfile(ctx.Context(), req); err != nil {
if er, ok := err.(*errors.Error); ok {
return ctx.Error(er.Code, er.Message)
@ -119,15 +125,12 @@ func handleUserServiceUpdateProfile(s UserServiceHttpServer) http.HandleFunc {
}
// 重置用户密码
func handleUserServiceResetPassword(s UserServiceHttpServer) http.HandleFunc {
return func(ctx *http.Context) (err error) {
req := &ResetPasswordRequest{}
if err := ctx.Bind(req); err != nil {
return ctx.Error(errors.Invalid, err.Error())
}
if res, err := s.ResetPassword(ctx.Context(), req); err != nil {
if er, ok := err.(*errors.Error); ok {
return ctx.Error(er.Code, er.Message)
@ -141,15 +144,12 @@ func handleUserServiceResetPassword(s UserServiceHttpServer) http.HandleFunc {
}
// 获取用户权限
func handleUserServiceGetPermissions(s UserServiceHttpServer) http.HandleFunc {
return func(ctx *http.Context) (err error) {
req := &GetPermissionRequest{}
if err := ctx.Bind(req); err != nil {
return ctx.Error(errors.Invalid, err.Error())
}
if res, err := s.GetPermissions(ctx.Context(), req); err != nil {
if er, ok := err.(*errors.Error); ok {
return ctx.Error(er.Code, er.Message)
@ -163,7 +163,6 @@ func handleUserServiceGetPermissions(s UserServiceHttpServer) http.HandleFunc {
}
// 获取用户标签
func handleUserServiceGetUserLabels(s UserServiceHttpServer) http.HandleFunc {
return func(ctx *http.Context) (err error) {
req := &GetUserLabelRequest{}
@ -181,7 +180,6 @@ func handleUserServiceGetUserLabels(s UserServiceHttpServer) http.HandleFunc {
}
// 获取用户标签
func handleUserServiceGetUserTags(s UserServiceHttpServer) http.HandleFunc {
return func(ctx *http.Context) (err error) {
req := &GetUserTagRequest{}
@ -199,7 +197,6 @@ func handleUserServiceGetUserTags(s UserServiceHttpServer) http.HandleFunc {
}
// 获取部门标签
func handleDepartmentServiceGetDepartmentLabels(s DepartmentServiceHttpServer) http.HandleFunc {
return func(ctx *http.Context) (err error) {
req := &GetDepartmentLabelRequest{}
@ -249,7 +246,6 @@ func handleDepartmentServiceGetDepartmentLevelLabels(s DepartmentServiceHttpServ
}
// 获取角色标签
func handleRoleServiceGetRoleLabels(s RoleServiceHttpServer) http.HandleFunc {
return func(ctx *http.Context) (err error) {
req := &GetRoleLabelRequest{}
@ -267,15 +263,12 @@ func handleRoleServiceGetRoleLabels(s RoleServiceHttpServer) http.HandleFunc {
}
// 获取角色权限
func handleRoleServiceGetRolePermissions(s RoleServiceHttpServer) http.HandleFunc {
return func(ctx *http.Context) (err error) {
req := &GetRolePermissionRequest{}
if err := ctx.Bind(req); err != nil {
return ctx.Error(errors.Invalid, err.Error())
}
if res, err := s.GetRolePermissions(ctx.Context(), req); err != nil {
if er, ok := err.(*errors.Error); ok {
return ctx.Error(er.Code, er.Message)
@ -291,11 +284,9 @@ func handleRoleServiceGetRolePermissions(s RoleServiceHttpServer) http.HandleFun
func handleRoleServiceSaveRolePermission(s RoleServiceHttpServer) http.HandleFunc {
return func(ctx *http.Context) (err error) {
req := &SaveRolePermissionRequest{}
if err := ctx.Bind(req); err != nil {
return ctx.Error(errors.Invalid, err.Error())
}
if res, err := s.SaveRolePermission(ctx.Context(), req); err != nil {
if er, ok := err.(*errors.Error); ok {
return ctx.Error(er.Code, er.Message)
@ -308,6 +299,22 @@ func handleRoleServiceSaveRolePermission(s RoleServiceHttpServer) http.HandleFun
}
}
func handleMenuServiceGetMenus(s MenuServiceHttpServer) http.HandleFunc {
return func(ctx *http.Context) (err error) {
req := &GetMenuRequest{}
if res, err := s.GetMenus(ctx.Context(), req); err != nil {
if er, ok := err.(*errors.Error); ok {
return ctx.Error(er.Code, er.Message)
} else {
return ctx.Error(errors.Unavailable, err.Error())
}
} else {
return ctx.Success(res)
}
}
}
func handleMenuServiceGetMenuLevelLabels(s MenuServiceHttpServer) http.HandleFunc {
return func(ctx *http.Context) (err error) {
req := &GetMenuLevelLabelsRequest{}
@ -327,11 +334,9 @@ func handleMenuServiceGetMenuLevelLabels(s MenuServiceHttpServer) http.HandleFun
func handleAuthServiceLogin(s AuthServiceHttpServer) http.HandleFunc {
return func(ctx *http.Context) (err error) {
req := &LoginRequest{}
if err := ctx.Bind(req); err != nil {
return ctx.Error(errors.Invalid, err.Error())
}
if res, err := s.Login(ctx.Context(), req); err != nil {
if er, ok := err.(*errors.Error); ok {
return ctx.Error(er.Code, er.Message)
@ -347,11 +352,9 @@ func handleAuthServiceLogin(s AuthServiceHttpServer) http.HandleFunc {
func handleAuthServiceLogout(s AuthServiceHttpServer) http.HandleFunc {
return func(ctx *http.Context) (err error) {
req := &LogoutRequest{}
if err := ctx.Bind(req); err != nil {
return ctx.Error(errors.Invalid, err.Error())
}
if res, err := s.Logout(ctx.Context(), req); err != nil {
if er, ok := err.(*errors.Error); ok {
return ctx.Error(er.Code, er.Message)
@ -417,6 +420,9 @@ func RegisterRoleServiceRouter(hs *http.Server, s RoleServiceHttpServer) {
func RegisterMenuServiceRouter(hs *http.Server, s MenuServiceHttpServer) {
// Register handle GetMenus route
hs.GET("/menu/list", handleMenuServiceGetMenus(s))
// Register handle GetMenuLevelLabels route
hs.GET("/menu/level-labels", handleMenuServiceGetMenuLevelLabels(s))

View File

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go-aeus. DO NOT EDIT.
// source: organize.proto
// date: 2025-06-18 15:37:30
// date: 2025-06-22 11:09:05
package pb
@ -12,7 +12,7 @@ type MenuModel struct {
Id int64 `json:"id" yaml:"id" xml:"id" gorm:"primaryKey;column:id" comment:"菜单ID"`
CreatedAt int64 `json:"created_at" yaml:"createdAt" xml:"createdAt" gorm:"column:created_at" comment:"创建时间" scenarios:"view;export"`
UpdatedAt int64 `json:"updated_at" yaml:"updatedAt" xml:"updatedAt" gorm:"index;column:updated_at" comment:"更新时间" scenarios:"view;export"`
Parent string `json:"parent" yaml:"parent" xml:"parent" gorm:"index;size:60;column:parent" comment:"父级菜单" format:"menu" props:"readonly:update" live:"type:dropdown;url:/menu/level-labels"`
Parent string `json:"parent" yaml:"parent" xml:"parent" gorm:"index;size:60;column:parent" comment:"父级菜单" scenarios:"create;update;view;export" format:"menu" props:"readonly:update" live:"type:dropdown;url:/menu/level-labels"`
Name string `json:"name" yaml:"name" xml:"name" gorm:"index;size:60;column:name" comment:"组件名称" props:"readonly:update" rule:"unique;required"`
Label string `json:"label" yaml:"label" xml:"label" gorm:"size:120;column:label" comment:"菜单标题" rule:"required"`
Uri string `json:"uri" yaml:"uri" xml:"uri" gorm:"size:512;column:uri" comment:"菜单链接" scenarios:"create;update;view;export" rule:"required"`
@ -20,7 +20,7 @@ type MenuModel struct {
Icon string `json:"icon" yaml:"icon" xml:"icon" gorm:"size:60;column:icon" comment:"菜单图标" scenarios:"create;update;view;export"`
Hidden bool `json:"hidden" yaml:"hidden" xml:"hidden" gorm:"column:hidden" comment:"是否隐藏" scenarios:"create;update;view;export"`
Public bool `json:"public" yaml:"public" xml:"public" gorm:"column:public" comment:"是否公开" scenarios:"create;update;view;export"`
Description string `json:"description" yaml:"description" xml:"description" gorm:"size:1024;column:description" comment:"备注说明" scenarios:"create;update;view;export;list" format:"textarea"`
Description string `json:"description" yaml:"description" xml:"description" gorm:"size:1024;column:description" comment:"备注说明" scenarios:"create;update;view;export" format:"textarea"`
Position int64 `json:"position" yaml:"position" xml:"position" gorm:"column:position" comment:"排序" scenarios:"create;update"`
}
@ -98,8 +98,8 @@ type RoleModel struct {
Id int64 `json:"id" yaml:"id" xml:"id" gorm:"primaryKey;column:id" comment:"角色ID"`
CreatedAt int64 `json:"created_at" yaml:"createdAt" xml:"createdAt" gorm:"column:created_at" comment:"创建时间" scenarios:"view;export"`
UpdatedAt int64 `json:"updated_at" yaml:"updatedAt" xml:"updatedAt" gorm:"index;column:updated_at" comment:"更新时间" scenarios:"view;export"`
Name string `json:"name" yaml:"name" xml:"name" gorm:"index;size:60;column:name" comment:"角色名称" props:"readonly:update"`
Label string `json:"label" yaml:"label" xml:"label" gorm:"size:60;column:label" comment:"角色标题"`
Name string `json:"name" yaml:"name" xml:"name" gorm:"index;size:60;column:name" comment:"角色名称" props:"readonly:update" rule:"required"`
Label string `json:"label" yaml:"label" xml:"label" gorm:"size:60;column:label" comment:"角色标题" rule:"required"`
Description string `json:"description" yaml:"description" xml:"description" gorm:"size:1024;column:description" comment:"备注说明" scenarios:"list;create;update;export" format:"textarea"`
}

View File

@ -355,7 +355,7 @@ const file_system_proto_rawDesc = "" +
"\vdescription\x18\x06 \x01(\tBJ\xfaB\x05r\x03\x18\x80\b\xb2\xb9\x19>\n" +
"\tsize:1024\x12\f备注说明\x1a\x19create;update;view;export*\btextareaR\vdescription:\x0e\xba\xb9\x19\n" +
"\n" +
"\bsettings\"\xd8\x05\n" +
"\bsettings\"\xe2\x05\n" +
"\bActivity\x12$\n" +
"\x02id\x18\x01 \x01(\x03B\x14\xb2\xb9\x19\x10\n" +
"\n" +
@ -363,13 +363,13 @@ const file_system_proto_rawDesc = "" +
"\n" +
"created_at\x18\x02 \x01(\x03B-\xb2\xb9\x19)\x12\f创建时间\x1a\x19search;search;view;exportR\tcreatedAt\x12W\n" +
"\x03uid\x18\x03 \x01(\tBE\xfaB\x06r\x04\x10\x05\x18\x14\xb2\xb9\x198\n" +
"\rindex;size:20\x12\x06用户*\x04user2\x0freadonly:update:\brequiredR\x03uid\x12\xbf\x01\n" +
"\x06action\x18\x04 \x01(\tB\xa6\x01\xb2\xb9\x19\xa1\x01\n" +
"!index;size:20;not null;default:''\x12\x06行为\x1a%search;list;create;update;view;export2\rmatch:exactlyR>create:新建#198754;update:更新#f09d00;delete:删除#e63757R\x06action\x12h\n" +
"\rindex;size:20\x12\x06用户*\x04user2\x0freadonly:update:\brequiredR\x03uid\x12\xc9\x01\n" +
"\x06action\x18\x04 \x01(\tB\xb0\x01\xb2\xb9\x19\xab\x01\n" +
"!index;size:20;not null;default:''\x12\x06行为\x1a%search;list;create;update;view;export2\rmatch:exactly:\brequiredR>create:新建#198754;update:更新#f09d00;delete:删除#e63757R\x06action\x12h\n" +
"\x06module\x18\x05 \x01(\tBP\xb2\xb9\x19L\n" +
"\x1bsize:60;not null;default:''\x12\x06模块\x1a%search;list;create;update;view;exportR\x06module\x12_\n" +
"\x05table\x18\x06 \x01(\tBI\xb2\xb9\x19E\n" +
"\x1bsize:60;not null;default:''\x12\x06数据\x1a\x1elist;create;update;view;exportR\x05table\x12`\n" +
"\x1bsize:60;not null;default:''\x12\x06模型\x1a\x1elist;create;update;view;exportR\x05table\x12`\n" +
"\x04data\x18\a \x01(\tBL\xb2\xb9\x19H\n" +
"\x1esize:10240;not null;default:''\x12\x06内容\x1a\x1elist;create;update;view;exportR\x04data:\x10\xba\xb9\x19\f\n" +
"\n" +

View File

@ -32,9 +32,9 @@ message Activity {
int64 id = 1 [(aeus.field) = {gorm:"primaryKey",comment:"ID"}];
int64 created_at = 2 [(aeus.field)={scenarios:"search;search;view;export",comment:"创建时间"}];
string uid = 3 [(aeus.field)={gorm:"index;size:20",rule:"required",props:"readonly:update",format:"user",comment: "用户"},(validate.rules).string = {min_len: 5, max_len: 20}];
string action = 4 [(aeus.field)={props:"match:exactly",gorm:"index;size:20;not null;default:''",comment:"行为",enum:"create:新建#198754;update:更新#f09d00;delete:删除#e63757",scenarios:"search;list;create;update;view;export"}];
string action = 4 [(aeus.field)={props:"match:exactly",rule:"required",gorm:"index;size:20;not null;default:''",comment:"行为",enum:"create:新建#198754;update:更新#f09d00;delete:删除#e63757",scenarios:"search;list;create;update;view;export"}];
string module = 5 [(aeus.field)={gorm:"size:60;not null;default:''",comment:"模块",scenarios:"search;list;create;update;view;export"}];
string table = 6 [(aeus.field)={gorm:"size:60;not null;default:''",comment:"数据",scenarios:"list;create;update;view;export"}];
string table = 6 [(aeus.field)={gorm:"size:60;not null;default:''",comment:"模型",scenarios:"list;create;update;view;export"}];
string data = 7 [(aeus.field)={gorm:"size:10240;not null;default:''",comment:"内容",scenarios:"list;create;update;view;export"}];
}

View File

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go-aeus. DO NOT EDIT.
// source: system.proto
// date: 2025-06-18 15:37:30
// date: 2025-06-22 11:09:05
package pb
@ -11,7 +11,7 @@ import (
)
type SettingServiceHttpServer interface {
GetSetting(context.Context, *GetSettingRequest) (*GetSettingResponse, error)
GetSetting(ctx context.Context, req *GetSettingRequest) (res *GetSettingResponse, err error)
}
func handleSettingServiceGetSetting(s SettingServiceHttpServer) http.HandleFunc {

View File

@ -1,6 +1,6 @@
// Code generated by protoc-gen-go-aeus. DO NOT EDIT.
// source: system.proto
// date: 2025-06-18 15:37:30
// date: 2025-06-22 11:09:05
package pb
@ -77,9 +77,9 @@ type ActivityModel struct {
Id int64 `json:"id" yaml:"id" xml:"id" gorm:"primaryKey;column:id" comment:"ID"`
CreatedAt int64 `json:"created_at" yaml:"createdAt" xml:"createdAt" gorm:"column:created_at" comment:"创建时间" scenarios:"search;search;view;export"`
Uid string `json:"uid" yaml:"uid" xml:"uid" gorm:"index;size:20;column:uid" comment:"用户" format:"user" props:"readonly:update" rule:"required"`
Action string `json:"action" yaml:"action" xml:"action" gorm:"index;size:20;not null;default:'';column:action" comment:"行为" scenarios:"search;list;create;update;view;export" props:"match:exactly" enum:"create:新建#198754;update:更新#f09d00;delete:删除#e63757"`
Action string `json:"action" yaml:"action" xml:"action" gorm:"index;size:20;not null;default:'';column:action" comment:"行为" scenarios:"search;list;create;update;view;export" props:"match:exactly" rule:"required" enum:"create:新建#198754;update:更新#f09d00;delete:删除#e63757"`
Module string `json:"module" yaml:"module" xml:"module" gorm:"size:60;not null;default:'';column:module" comment:"模块" scenarios:"search;list;create;update;view;export"`
Table string `json:"table" yaml:"table" xml:"table" gorm:"size:60;not null;default:'';column:table" comment:"数据" scenarios:"list;create;update;view;export"`
Table string `json:"table" yaml:"table" xml:"table" gorm:"size:60;not null;default:'';column:table" comment:"模型" scenarios:"list;create;update;view;export"`
Data string `json:"data" yaml:"data" xml:"data" gorm:"size:10240;not null;default:'';column:data" comment:"内容" scenarios:"list;create;update;view;export"`
}

View File

@ -5,6 +5,8 @@ import (
"slices"
"git.nobla.cn/golang/aeus-admin/internal/logic"
"git.nobla.cn/golang/aeus-admin/models"
"git.nobla.cn/golang/aeus-admin/types"
"git.nobla.cn/golang/aeus/middleware/auth"
"git.nobla.cn/golang/aeus/pkg/cache"
"git.nobla.cn/golang/aeus/pkg/errors"
@ -13,7 +15,8 @@ import (
type PermissionChecker struct {
db *gorm.DB
logic *logic.User
user *logic.User
role *logic.Role
}
func (p *PermissionChecker) CheckPermission(ctx context.Context, permission string) (err error) {
@ -21,14 +24,30 @@ func (p *PermissionChecker) CheckPermission(ctx context.Context, permission stri
uid string
ps []string
)
if claims, ok := auth.FromContext(ctx); !ok {
claims, ok := auth.FromContext(ctx)
if !ok {
return errors.ErrAccessDenied
}
if cl, ok := claims.(*types.Claims); ok {
if cl.Admin {
return
} else {
if uid, err = claims.GetSubject(); err != nil {
var pms []*models.Permission
if pms, err = p.role.GetPermissions(ctx, cl.Role); err == nil {
for _, pm := range pms {
if pm.Permission == permission {
return
}
}
if ps, err = p.logic.GetPermissions(ctx, uid); err != nil {
} else {
return errors.ErrPermissionDenied
}
}
}
if uid, err = claims.GetSubject(); err != nil {
return
}
if ps, err = p.user.GetPermissions(ctx, uid); err != nil {
return
}
if !slices.Contains(ps, permission) {
@ -40,6 +59,7 @@ func (p *PermissionChecker) CheckPermission(ctx context.Context, permission stri
func NewPermissionChecker(db *gorm.DB, ch cache.Cache) *PermissionChecker {
return &PermissionChecker{
db: db,
logic: logic.NewUserLogic(db, ch),
user: logic.NewUserLogic(db, ch),
role: logic.NewRoleLogic(db, ch),
}
}

View File

@ -0,0 +1,30 @@
package cfgload
import (
"encoding/json"
"encoding/xml"
"os"
"path"
"gopkg.in/yaml.v3"
)
// FromFile loads configuration from file
func FromFile(filepath string, cfg any) (err error) {
var (
buf []byte
)
if buf, err = os.ReadFile(filepath); err != nil {
return
}
ext := path.Ext(filepath)
switch ext {
case ".json":
err = json.Unmarshal(buf, cfg)
case ".xml":
err = xml.Unmarshal(buf, cfg)
case ".yaml", ".yml":
err = yaml.Unmarshal(buf, cfg)
}
return
}

View File

@ -0,0 +1,78 @@
package chartjs
import (
"slices"
"sync"
)
// DataCounter 计数统计, 实现类似Pie 和 Doughnut 之类的图形
type DataCounter struct {
mutex sync.Mutex
legends map[string]*counterValue
}
func (c *DataCounter) Inc(leg string, label string, value float64) {
c.mutex.Lock()
defer c.mutex.Unlock()
v, ok := c.legends[leg]
if !ok {
v = &counterValue{
Label: leg,
Values: make(map[string]float64),
}
c.legends[leg] = v
}
v.Values[label] += value
}
func (c *DataCounter) Dec(legend string, label string, value float64) {
c.mutex.Lock()
defer c.mutex.Unlock()
v, ok := c.legends[legend]
if !ok {
return
}
if _, ok := v.Values[label]; ok {
v.Values[label] -= value
}
}
func (c *DataCounter) Data() *CounterData {
c.mutex.Lock()
defer c.mutex.Unlock()
data := &CounterData{
Lables: make([]string, 0, 5),
Datasets: make([]*CounterValue, 0, len(c.legends)),
}
for _, row := range c.legends {
for k, _ := range row.Values {
if !slices.Contains(data.Lables, k) {
data.Lables = append(data.Lables, k)
}
}
}
for _, row := range c.legends {
set := &CounterValue{
Label: row.Label,
Data: make([]float64, 0, len(data.Lables)),
}
for _, label := range data.Lables {
set.Data = append(set.Data, row.Values[label])
}
data.Datasets = append(data.Datasets, set)
}
return data
}
func NewDataCounter(legends ...string) *DataCounter {
c := &DataCounter{
legends: make(map[string]*counterValue),
}
for _, legend := range legends {
c.legends[legend] = &counterValue{
Label: legend,
Values: make(map[string]float64),
}
}
return c
}

View File

@ -0,0 +1,46 @@
package chartjs
import "time"
// TimeSeriesGroup 时间计算数据, 实现类似以时间为维度的折线图
type TimeSeriesGroup struct {
step string
values map[string]*TimeSeries
}
func (g *TimeSeriesGroup) Inc(tm time.Time, key string, value float64) {
v, ok := g.values[key]
if !ok {
v = NewTimeSeries(g.step)
g.values[key] = v
}
v.Inc(tm, value)
}
func (g *TimeSeriesGroup) Dec(tm time.Time, key string, value float64) {
v, ok := g.values[key]
if !ok {
v = NewTimeSeries(g.step)
g.values[key] = v
}
v.Dec(tm, value)
}
// Data 生成chart.js 的图表dataset
func (g *TimeSeriesGroup) Data(sts, ets int64) (values []*TimeseriesData) {
for key, row := range g.values {
data := &TimeseriesData{
Label: key,
Data: row.Values(sts, ets),
}
values = append(values, data)
}
return
}
func NewTimeSeriesGroup(step string) *TimeSeriesGroup {
return &TimeSeriesGroup{
step: step,
values: make(map[string]*TimeSeries),
}
}

View File

@ -0,0 +1,126 @@
package chartjs
import (
"sync"
"time"
)
const (
Minute = "minute"
Hour = "hour"
Day = "day"
Method = "method"
)
// 时间序列值, 实现了按时间进行分组的值计算
type TimeSeries struct {
mutex sync.Mutex
step string
values []*TimeseriesValue
}
func (s *TimeSeries) cutTimeSeries(tm time.Time) int64 {
switch s.step {
case Method:
return time.Date(tm.Year(), tm.Month(), 0, 0, 0, 0, 0, time.Local).Unix()
case Day:
return time.Date(tm.Year(), tm.Month(), tm.Day(), 0, 0, 0, 0, time.Local).Unix()
case Hour:
return time.Date(tm.Year(), tm.Month(), tm.Day(), tm.Hour(), 0, 0, 0, time.Local).Unix()
default:
return time.Date(tm.Year(), tm.Month(), tm.Day(), tm.Hour(), tm.Minute(), 0, 0, time.Local).Unix()
}
}
func (s *TimeSeries) truncateTime(ts int64) int64 {
tm := time.Unix(ts, 0)
switch s.step {
case Method:
return time.Date(tm.Year(), tm.Month(), 0, 0, 0, 0, 0, time.Local).Unix()
case Day:
return time.Date(tm.Year(), tm.Month(), tm.Day(), 0, 0, 0, 0, time.Local).Unix()
case Hour:
return time.Date(tm.Year(), tm.Month(), tm.Day(), tm.Hour(), 0, 0, 0, time.Local).Unix()
default:
return time.Date(tm.Year(), tm.Month(), tm.Day(), tm.Hour(), tm.Minute(), 0, 0, time.Local).Unix()
}
return tm.Unix()
}
func (s *TimeSeries) nextTimestamp(ts int64) int64 {
tm := time.Unix(ts, 0)
switch s.step {
case Method:
return tm.AddDate(0, 1, 0).Unix()
case Day:
return tm.AddDate(0, 0, 1).Unix()
case Hour:
return ts + 3600
default:
return ts + 60
}
}
func (s *TimeSeries) Inc(tm time.Time, value float64) {
s.mutex.Lock()
defer s.mutex.Unlock()
ts := s.cutTimeSeries(tm)
for _, v := range s.values {
if v.Timestamp == ts {
v.Value += value
return
}
}
s.values = append(s.values, &TimeseriesValue{
Timestamp: ts,
Value: value,
})
}
func (s *TimeSeries) Dec(tm time.Time, value float64) {
s.mutex.Lock()
defer s.mutex.Unlock()
ts := s.cutTimeSeries(tm)
for _, v := range s.values {
if v.Timestamp == ts {
v.Value -= value
return
}
}
}
func (s *TimeSeries) Values(sts, ets int64) []*TimeseriesValue {
var (
nextStamp int64
)
sts = s.truncateTime(sts)
ets = s.truncateTime(ets)
series := make([]*TimeseriesValue, 0, len(s.values))
nextStamp = sts
for _, row := range s.values {
for row.Timestamp > nextStamp {
series = append(series, &TimeseriesValue{
Timestamp: nextStamp,
Value: 0,
})
nextStamp = s.nextTimestamp(nextStamp)
}
series = append(series, row)
nextStamp = s.nextTimestamp(nextStamp)
}
for ets > nextStamp {
series = append(series, &TimeseriesValue{
Timestamp: nextStamp,
Value: 0,
})
nextStamp = s.nextTimestamp(nextStamp)
}
return series
}
func NewTimeSeries(step string) *TimeSeries {
return &TimeSeries{
step: step,
values: make([]*TimeseriesValue, 0, 64),
}
}

View File

@ -0,0 +1,66 @@
package chartjs
/*
{
label: 'My Time Series Data',
data: [
{ x: '2025-01-01', y: 10 },
{ x: '2025-01-02', y: 15 },
{ x: '2025-01-03', y: 8 },
{ x: '2025-01-04', y: 20 },
{ x: '2025-01-05', y: 12 }
],
borderColor: 'rgb(75, 192, 192)',
tension: 0.1
}
*/
type TimeseriesValue struct {
Timestamp int64 `json:"x"`
Value float64 `json:"y"`
}
// TimeseriesData 时间序列的数据
type TimeseriesData struct {
Label string `json:"label"`
Data []*TimeseriesValue `json:"data"`
BorderColor string `json:"borderColor,omitempty"`
BackgroundColor string `json:"backgroundColor,omitempty"`
Tension float64 `json:"tension,omitempty"`
Fill bool `json:"fill,omitempty"`
}
/**
{
labels: labels,
datasets: [
{
label: 'Dataset 1',
data: Utils.numbers(NUMBER_CFG),
backgroundColor: [
Utils.transparentize(Utils.CHART_COLORS.red, 0.5),
Utils.transparentize(Utils.CHART_COLORS.orange, 0.5),
Utils.transparentize(Utils.CHART_COLORS.yellow, 0.5),
Utils.transparentize(Utils.CHART_COLORS.green, 0.5),
Utils.transparentize(Utils.CHART_COLORS.blue, 0.5),
]
}
]
}
*/
type counterValue struct {
Label string `json:"label"`
Values map[string]float64 `json:"data"`
}
type CounterValue struct {
Label string `json:"label"`
Data []float64 `json:"data"`
BackgroundColor []string `json:"backgroundColor,omitempty"`
}
type CounterData struct {
Lables []string `json:"labels"`
Datasets []*CounterValue `json:"datasets"`
}

View File

@ -23,9 +23,9 @@ type (
CacheOption func(o *CacheOptions)
cacheEntry[T any] struct {
Value T
CompareValue string
CreatedAt int64
Value T `json:"v"`
CompareValue string `json:"d"`
CreatedAt int64 `json:"t"`
}
)
@ -37,15 +37,19 @@ func WithDB(db *gorm.DB) CacheOption {
func WithCache(c cache.Cache) CacheOption {
return func(o *CacheOptions) {
if o != nil {
o.cache = c
}
}
}
func WithCacheDuration(d time.Duration) CacheOption {
return func(o *CacheOptions) {
if d > 0 {
o.cacheDuration = d
}
}
}
func WithDependency(d CacheDependency) CacheOption {
return func(o *CacheOptions) {
@ -80,7 +84,7 @@ func TryCache[T any](ctx context.Context, key string, f func(tx *gorm.DB) (T, er
if opts.dependency == nil {
return entry.Value, nil
}
if dependValue, err = opts.dependency.GetValue(ctx, opts.db); err == nil {
if dependValue, err = opts.dependency.GetValue(ctx, opts.db); err == nil && dependValue != "" {
hasDependValue = true
if entry.CompareValue == dependValue {
return entry.Value, nil
@ -94,7 +98,7 @@ func TryCache[T any](ctx context.Context, key string, f func(tx *gorm.DB) (T, er
if val, err, _ = singleInstance.Do(key, func() (any, error) {
if result, err = f(tx); err == nil {
if !hasDependValue && opts.dependency != nil {
dependValue, err = opts.dependency.GetValue(ctx, tx)
dependValue, _ = opts.dependency.GetValue(ctx, tx)
}
opts.cache.Store(ctx, key, &cacheEntry[T]{
CompareValue: dependValue,

View File

@ -0,0 +1,31 @@
package dbdialer
import (
"context"
"gorm.io/driver/mysql"
"gorm.io/driver/postgres"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
// Dialer open database
func Dialer(ctx context.Context, driver string, dsn string, cbs ...Option) (db *gorm.DB, err error) {
opts := newOptions(cbs...)
if opts.cfg == nil {
opts.cfg = &gorm.Config{}
}
opts.cfg.Logger = newLogger(opts.log)
switch driver {
case mysql.DefaultDriverName:
db, err = gorm.Open(mysql.Open(dsn), opts.cfg)
case sqlite.DriverName:
db, err = gorm.Open(sqlite.Open(dsn), opts.cfg)
case "postgres":
db, err = gorm.Open(postgres.Open(dsn), opts.cfg)
default:
err = gorm.ErrNotImplemented
}
return
}

View File

@ -0,0 +1,83 @@
package dbdialer
import (
"context"
"errors"
"fmt"
"time"
logpkg "git.nobla.cn/golang/aeus/pkg/logger"
"gorm.io/gorm/logger"
"gorm.io/gorm/utils"
)
type Logger struct {
LogLevel logger.LogLevel
SlowThreshold time.Duration
traceStr string
traceErrStr string
logger logpkg.Logger
}
func (lg *Logger) LogMode(level logger.LogLevel) logger.Interface {
lg.LogLevel = level
return lg
}
func (lg *Logger) Info(ctx context.Context, s string, i ...interface{}) {
if lg.LogLevel >= logger.Info {
lg.logger.Info(ctx, s, i...)
}
}
func (lg *Logger) Warn(ctx context.Context, s string, i ...interface{}) {
if lg.LogLevel >= logger.Warn {
lg.logger.Warn(ctx, s, i...)
}
}
func (lg *Logger) Error(ctx context.Context, s string, i ...interface{}) {
if lg.LogLevel >= logger.Error {
lg.logger.Error(ctx, s, i...)
}
}
func (lg *Logger) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error) {
if lg.LogLevel <= logger.Silent {
return
}
elapsed := time.Since(begin)
switch {
case err != nil && lg.LogLevel >= logger.Error && (!errors.Is(err, logger.ErrRecordNotFound)):
sql, rows := fc()
if rows == -1 {
lg.Warn(ctx, lg.traceErrStr, sql, err, float64(elapsed.Nanoseconds())/1e6, "-", utils.FileWithLineNum())
} else {
lg.Warn(ctx, lg.traceErrStr, sql, err, float64(elapsed.Nanoseconds())/1e6, rows, utils.FileWithLineNum())
}
case elapsed > lg.SlowThreshold && lg.SlowThreshold != 0 && lg.LogLevel >= logger.Warn:
sql, rows := fc()
slowLog := fmt.Sprintf("SLOW SQL >= %v", lg.SlowThreshold)
if rows == -1 {
lg.Warn(ctx, lg.traceErrStr, sql, slowLog, float64(elapsed.Nanoseconds())/1e6, "-", utils.FileWithLineNum())
} else {
lg.Warn(ctx, lg.traceErrStr, sql, slowLog, float64(elapsed.Nanoseconds())/1e6, rows, utils.FileWithLineNum())
}
case lg.LogLevel == logger.Info:
sql, rows := fc()
if rows == -1 {
lg.Info(ctx, lg.traceStr, sql, float64(elapsed.Nanoseconds())/1e6, "-", utils.FileWithLineNum())
} else {
lg.Info(ctx, lg.traceStr, sql, float64(elapsed.Nanoseconds())/1e6, rows, utils.FileWithLineNum())
}
}
}
func newLogger(log logpkg.Logger) *Logger {
return &Logger{
logger: log,
SlowThreshold: time.Second * 10,
traceStr: "%s [%.3fms] [rows:%v] in %s",
traceErrStr: "%s [%s] [%.3fms] [rows:%v] in %s",
}
}

View File

@ -0,0 +1,38 @@
package dbdialer
import (
"git.nobla.cn/golang/aeus/pkg/logger"
"gorm.io/gorm"
)
type (
options struct {
log logger.Logger
cfg *gorm.Config
}
Option func(o *options)
)
func WithConfig(cfg *gorm.Config) Option {
return func(o *options) {
o.cfg = cfg
}
}
func WithLogger(log logger.Logger) Option {
return func(o *options) {
o.log = log
}
}
func newOptions(opts ...Option) *options {
o := &options{
cfg: &gorm.Config{},
log: logger.Default(),
}
for _, opt := range opts {
opt(o)
}
return o
}

185
server.go
View File

@ -10,6 +10,7 @@ import (
"reflect"
"strconv"
"strings"
"time"
"git.nobla.cn/golang/aeus-admin/migrate"
"git.nobla.cn/golang/aeus-admin/models"
@ -250,23 +251,6 @@ func initModels(ctx context.Context, o *options) (err error) {
return
}
// AutoMigrate 自动生成一个模型的schema和权限的定义
func AutoMigrate(ctx context.Context, db *gorm.DB, model any, cbs ...Option) (err error) {
var (
mv *rest.Model
)
opts := newOptions(cbs...)
if mm, ok := model.(adminTypes.ModuleModel); ok {
moduleName := mm.ModuleName()
opts.restOpts = append(opts.restOpts, rest.WithModuleName(moduleName))
}
if mv, err = rest.AutoMigrate(ctx, model, opts.restOpts...); err != nil {
return
}
err = checkModel(opts, mv)
return
}
func registerRESTRoute(domain string, db *gorm.DB, hs *http.Server) {
handleListSchemas := func(ctx *http.Context) (err error) {
var (
@ -351,10 +335,177 @@ func registerRESTRoute(domain string, db *gorm.DB, hs *http.Server) {
}
}
handleKeyValues := func(ctx *http.Context) (err error) {
var (
dbDependency dbcache.CacheDependency
pairs []*restTypes.TypeValue[any]
modelValue any
)
moduleName := ctx.Param("module")
tableName := ctx.Param("table")
entities := rest.GetModels()
for _, entry := range entities {
if entry.ModuleName() == moduleName && entry.TableName() == tableName {
modelValue = reflect.New(entry.Value().Type()).Interface()
for _, field := range entry.Fields() {
if field.AutoUpdateTime > 0 {
dbDependency = dbcache.NewSqlDependency(fmt.Sprintf("SELECT MAX(`%s`) FROM `%s`", field.DBName, entry.TableName()))
break
}
}
break
}
}
if modelValue == nil {
return ctx.Error(errors.NotFound, "model not found")
}
labelColumn := ctx.Param("label")
valueColumn := ctx.Param("value")
opts := make([]dbcache.CacheOption, 0, 4)
opts = append(opts, dbcache.WithDB(db))
if dbDependency != nil {
opts = append(opts, dbcache.WithCacheDuration(time.Minute*30))
opts = append(opts, dbcache.WithDependency(dbDependency))
} else {
opts = append(opts, dbcache.WithCacheDuration(time.Minute))
}
if pairs, err = dbcache.TryCache(ctx.Context(), fmt.Sprintf("rest:kvpairs:%s:%s:%s:%s", moduleName, tableName, labelColumn, valueColumn), func(tx *gorm.DB) ([]*restTypes.TypeValue[any], error) {
return rest.ModelTypes[any](ctx.Context(), db, modelValue, "", labelColumn, valueColumn)
}, opts...); err == nil {
return ctx.Success(pairs)
} else {
return ctx.Error(errors.Unavailable, err.Error())
}
}
handleTierPairs := func(ctx *http.Context) (err error) {
var (
dbDependency dbcache.CacheDependency
pairs []*restTypes.TierValue[string]
modelValue any
)
moduleName := ctx.Param("module")
tableName := ctx.Param("table")
entities := rest.GetModels()
for _, entry := range entities {
if entry.ModuleName() == moduleName && entry.TableName() == tableName {
// 权限控制
if err = entry.HasPermission(ctx.Context(), entry.Permission(restTypes.ScenarioList)); err != nil {
return ctx.Error(errors.AccessDenied, err.Error())
}
modelValue = reflect.New(entry.Value().Type()).Interface()
for _, field := range entry.Fields() {
if field.AutoUpdateTime > 0 {
dbDependency = dbcache.NewSqlDependency(fmt.Sprintf("SELECT MAX(`%s`) FROM `%s`", field.DBName, entry.TableName()))
break
}
}
break
}
}
if modelValue == nil {
return ctx.Error(errors.NotFound, "model not found")
}
parentColumn := ctx.Param("parent")
labelColumn := ctx.Param("label")
valueColumn := ctx.Param("value")
opts := make([]dbcache.CacheOption, 0, 4)
opts = append(opts, dbcache.WithDB(db))
if dbDependency != nil {
opts = append(opts, dbcache.WithCacheDuration(time.Minute*30))
opts = append(opts, dbcache.WithDependency(dbDependency))
} else {
opts = append(opts, dbcache.WithCacheDuration(time.Minute))
}
if pairs, err = dbcache.TryCache(ctx.Context(), fmt.Sprintf("rest:tierpairs:%s:%s:%s:%s", moduleName, tableName, labelColumn, valueColumn), func(tx *gorm.DB) ([]*restTypes.TierValue[string], error) {
return rest.ModelTiers[string](ctx.Context(), db, modelValue, "", parentColumn, labelColumn, valueColumn)
}, opts...); err == nil {
return ctx.Success(pairs)
} else {
return ctx.Error(errors.Unavailable, err.Error())
}
}
handleNumberTierPairs := func(ctx *http.Context) (err error) {
var (
dbDependency dbcache.CacheDependency
pairs []*restTypes.TierValue[int64]
modelValue any
)
moduleName := ctx.Param("module")
tableName := ctx.Param("table")
entities := rest.GetModels()
for _, entry := range entities {
if entry.ModuleName() == moduleName && entry.TableName() == tableName {
// 权限控制
if err = entry.HasPermission(ctx.Context(), entry.Permission(restTypes.ScenarioList)); err != nil {
return ctx.Error(errors.AccessDenied, err.Error())
}
modelValue = reflect.New(entry.Value().Type()).Interface()
for _, field := range entry.Fields() {
if field.AutoUpdateTime > 0 {
dbDependency = dbcache.NewSqlDependency(fmt.Sprintf("SELECT MAX(`%s`) FROM `%s`", field.DBName, entry.TableName()))
break
}
}
break
}
}
if modelValue == nil {
return ctx.Error(errors.NotFound, "model not found")
}
parentColumn := ctx.Param("parent")
labelColumn := ctx.Param("label")
valueColumn := ctx.Param("value")
opts := make([]dbcache.CacheOption, 0, 4)
opts = append(opts, dbcache.WithDB(db))
if dbDependency != nil {
opts = append(opts, dbcache.WithCacheDuration(time.Minute*30))
opts = append(opts, dbcache.WithDependency(dbDependency))
} else {
opts = append(opts, dbcache.WithCacheDuration(time.Minute))
}
if pairs, err = dbcache.TryCache(ctx.Context(), fmt.Sprintf("rest:tierpairs:%s:%s:%s:%s", moduleName, tableName, labelColumn, valueColumn), func(tx *gorm.DB) ([]*restTypes.TierValue[int64], error) {
return rest.ModelTiers[int64](ctx.Context(), db, modelValue, "", parentColumn, labelColumn, valueColumn)
}, opts...); err == nil {
return ctx.Success(pairs)
} else {
return ctx.Error(errors.Unavailable, err.Error())
}
}
hs.GET("/rest/schema/:module/:table", handleListSchemas)
hs.PUT("/rest/schema/:module/:table", handleUpdateSchemas)
hs.DELETE("/rest/schema/:id", handleDeleteSchema)
hs.GET("/rest/kvpairs/:module/:table/:value/:label", handleKeyValues) //处理键值对数据
hs.GET("/rest/tierpairs/str/:module/:table/:parent/:value/:label", handleTierPairs) //处理字符串类型的层级数据
hs.GET("/rest/tierpairs/num/:module/:table/:parent/:value/:label", handleNumberTierPairs) //处理数字类型的层级数据, 只支持int64
}
// AutoMigrate 自动生成一个模型的schema和权限的定义
func AutoMigrate(ctx context.Context, db *gorm.DB, model any, cbs ...Option) (err error) {
var (
mv *rest.Model
)
opts := newOptions(cbs...)
if mm, ok := model.(adminTypes.ModuleModel); ok {
moduleName := mm.ModuleName()
opts.restOpts = append(opts.restOpts, rest.WithModuleName(moduleName))
}
if err = db.AutoMigrate(model); err != nil {
return
}
if mv, err = rest.AutoMigrate(ctx, model, opts.restOpts...); err != nil {
return
}
if err = checkModel(opts, mv); err == nil {
if opts.vuePath != "" {
if err = generateVueFile(opts.vuePath, opts.apiPrefix, mv); err != nil {
return
}
}
}
return
}
// Init 初始化模块

View File

@ -1,9 +1,7 @@
package service
import (
"bytes"
"context"
"encoding/json"
"net/http"
"time"
@ -13,6 +11,7 @@ import (
"git.nobla.cn/golang/aeus/metadata"
"git.nobla.cn/golang/aeus/pkg/cache"
"git.nobla.cn/golang/aeus/pkg/errors"
"git.nobla.cn/golang/aeus/pkg/httpclient"
jwt "github.com/golang-jwt/jwt/v5"
"github.com/mssola/useragent"
"gorm.io/gorm"
@ -101,11 +100,6 @@ func WithAuthTTL(ttl int64) AuthOption {
}
func (s *AuthService) turnstileValidate(ctx context.Context, token string) (err error) {
var (
buf []byte
req *http.Request
res *http.Response
)
if s.opts.turnstileSiteKey == "" || s.opts.turnstileValidateUrl == "" {
return nil
}
@ -113,22 +107,14 @@ func (s *AuthService) turnstileValidate(ctx context.Context, token string) (err
Secret: s.opts.turnstileSiteKey,
Response: token,
}
if buf, err = json.Marshal(payload); err != nil {
return
}
if req, err = http.NewRequestWithContext(ctx, http.MethodPost, s.opts.turnstileValidateUrl, bytes.NewReader(buf)); err != nil {
return
}
req.Header.Set("Content-Type", "application/json")
if res, err = http.DefaultClient.Do(req); err != nil {
return
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return errors.Format(errors.Unavailable, "turnstile validate failed")
}
result := &turnstileResponse{}
if err = json.NewDecoder(res.Body).Decode(result); err != nil {
if err = httpclient.Do(
ctx,
s.opts.turnstileValidateUrl,
result,
httpclient.WithMethod(http.MethodPost),
httpclient.WithBody(payload),
); err != nil {
return
}
if !result.Success {
@ -162,6 +148,7 @@ func (s *AuthService) Login(ctx context.Context, req *pb.LoginRequest) (res *pb.
claims := types.Claims{
Uid: model.Uid,
Role: model.Role,
Admin: model.Admin,
IssuedAt: time.Now().Unix(),
ExpirationAt: time.Now().Add(time.Second * time.Duration(s.opts.ttl)).Unix(),
}

View File

@ -35,6 +35,24 @@ func WithMenuDB(db *gorm.DB) MenuOption {
}
}
func (s *MenuService) recursiveMenuValue(parent string, items []*models.Menu) []*pb.MenuValue {
values := make([]*pb.MenuValue, 0, len(items))
for _, row := range items {
if row.Parent == parent {
item := &pb.MenuValue{
Id: row.Id,
Parent: row.Parent,
Name: row.Name,
Label: row.Label,
Children: make([]*pb.MenuValue, 0),
}
item.Children = append(item.Children, s.recursiveMenuValue(row.Name, items)...)
values = append(values, item)
}
}
return values
}
func (s *MenuService) recursiveMenuLevel(parent string, items []*models.Menu) []*pb.MenuLevelValue {
values := make([]*pb.MenuLevelValue, 0, len(items))
for _, row := range items {
@ -51,6 +69,19 @@ func (s *MenuService) recursiveMenuLevel(parent string, items []*models.Menu) []
return values
}
func (s *MenuService) GetMenus(ctx context.Context, req *pb.GetMenuRequest) (res *pb.GetMenuResponse, err error) {
var (
items []*models.Menu
)
if items, err = s.logic.GetMenus(ctx); err != nil {
return
}
res = &pb.GetMenuResponse{
Data: s.recursiveMenuValue("", items),
}
return
}
func (s *MenuService) GetMenuLevelLabels(ctx context.Context, req *pb.GetMenuLevelLabelsRequest) (res *pb.GetMenuLevelLabelsResponse, err error) {
var (
items []*models.Menu

View File

@ -17,6 +17,7 @@ type (
SettingOption func(o *settingOptions)
)
type SettingService struct {
opts *settingOptions
}

View File

@ -102,7 +102,7 @@ func (s *UserService) recursiveNestedMenu(ctx context.Context, parent string, pe
return values
}
func (s *UserService) GetMenus(ctx context.Context, req *pb.GetMenuRequest) (res *pb.GetMenuResponse, err error) {
func (s *UserService) GetMenus(ctx context.Context, req *pb.GetUserMenuRequest) (res *pb.GetUserMenuResponse, err error) {
var (
uid string
permissions []*models.Permission
@ -110,14 +110,14 @@ func (s *UserService) GetMenus(ctx context.Context, req *pb.GetMenuRequest) (res
if uid, err = s.getUidFromContext(ctx); err != nil {
return
}
res = &pb.GetMenuResponse{}
res = &pb.GetUserMenuResponse{}
res.Data, err = dbcache.TryCache(ctx, fmt.Sprintf("user:menu:%s:%v", uid, req.Permission), func(tx *gorm.DB) ([]*pb.MenuItem, error) {
var (
userModel *models.User
menus []*models.Menu
)
userModel = &models.User{}
if err = tx.Where("uid=?", uid).First(userModel).Error; err != nil {
if err = tx.Where("`uid`=?", uid).First(userModel).Error; err != nil {
return nil, err
}
if menus, err = s.menu.GetMenus(ctx); err != nil {

View File

@ -9,6 +9,7 @@ import (
type Claims struct {
Uid string `json:"uid"`
Role string `json:"uro"`
Admin bool `json:"uab"`
Issuer string `json:"iss"`
IssuedAt int64 `json:"iat"`
ExpirationAt int64 `json:"exp"`