update service
This commit is contained in:
parent
7ea74836aa
commit
c40bf36de3
|
@ -0,0 +1,93 @@
|
|||
package aeusadmin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.nobla.cn/golang/aeus/pkg/cache"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type (
|
||||
CachingFunc func(tx *gorm.DB) (any, error)
|
||||
|
||||
CacheOptions struct {
|
||||
db *gorm.DB
|
||||
cache cache.Cache
|
||||
dependSQL string
|
||||
dependArgs []any
|
||||
cacheDuration time.Duration
|
||||
}
|
||||
|
||||
CacheOption func(o *CacheOptions)
|
||||
|
||||
cacheEntry struct {
|
||||
storeValue any
|
||||
compareValue string
|
||||
createdAt time.Time
|
||||
lastChecked time.Time
|
||||
}
|
||||
)
|
||||
|
||||
func WithDepend(s string, args ...any) CacheOption {
|
||||
return func(o *CacheOptions) {
|
||||
o.dependSQL = s
|
||||
o.dependArgs = args
|
||||
}
|
||||
}
|
||||
func TryCache(ctx context.Context, key string, f CachingFunc, cbs ...CacheOption) (value any, err error) {
|
||||
var (
|
||||
hasDependValue bool
|
||||
dependValue string
|
||||
)
|
||||
opts := &CacheOptions{
|
||||
cacheDuration: time.Minute * 10,
|
||||
}
|
||||
for _, cb := range cbs {
|
||||
cb(opts)
|
||||
}
|
||||
//从缓存加载数据
|
||||
if value, _, err = opts.cache.Get(ctx, key); err == nil {
|
||||
entry := value.(*cacheEntry)
|
||||
if opts.dependSQL == "" {
|
||||
return entry.storeValue, nil
|
||||
}
|
||||
//如果频繁访问,不检查依赖
|
||||
if time.Since(entry.lastChecked) < time.Millisecond*500 {
|
||||
return entry.storeValue, nil
|
||||
}
|
||||
//对比依赖值
|
||||
if err = opts.db.Raw(opts.dependSQL, opts.dependArgs...).Scan(&dependValue).Error; err == nil {
|
||||
hasDependValue = true
|
||||
if entry.compareValue == dependValue {
|
||||
entry.lastChecked = time.Now()
|
||||
return entry.storeValue, nil
|
||||
} else {
|
||||
opts.cache.Delete(ctx, key)
|
||||
}
|
||||
}
|
||||
}
|
||||
//从数据库加载数据
|
||||
if value, err = f(opts.db.WithContext(ctx)); err == nil {
|
||||
if !hasDependValue {
|
||||
if err = opts.db.WithContext(ctx).Raw(opts.dependSQL, opts.dependArgs...).Scan(&dependValue).Error; err == nil {
|
||||
opts.cache.Put(ctx, key, &cacheEntry{
|
||||
compareValue: dependValue,
|
||||
storeValue: value,
|
||||
createdAt: time.Now(),
|
||||
lastChecked: time.Now(),
|
||||
}, opts.cacheDuration)
|
||||
}
|
||||
} else {
|
||||
opts.cache.Put(ctx, key, &cacheEntry{
|
||||
compareValue: dependValue,
|
||||
storeValue: value,
|
||||
createdAt: time.Now(),
|
||||
lastChecked: time.Now(),
|
||||
}, opts.cacheDuration)
|
||||
}
|
||||
return value, nil
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
|
@ -1,13 +1,17 @@
|
|||
package defaults
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.nobla.cn/golang/aeus-admin/models"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var (
|
||||
defaultRoles = []*models.Role{}
|
||||
defaultUsers = []*models.User{}
|
||||
defaultRoles = []*models.Role{}
|
||||
defaultUsers = []*models.User{}
|
||||
defaultMenus = []*models.Menu{}
|
||||
defaultDepartments = []*models.Department{}
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -19,20 +23,67 @@ func init() {
|
|||
|
||||
adminUser := &models.User{}
|
||||
adminUser.Uid = "admin"
|
||||
adminUser.Username = "admin"
|
||||
adminUser.Username = "管理员"
|
||||
adminUser.Password = "admin"
|
||||
adminUser.Role = "admin"
|
||||
adminUser.Admin = true
|
||||
adminUser.DeptId = 1
|
||||
|
||||
guestUser := &models.User{}
|
||||
guestUser.Uid = "guest"
|
||||
guestUser.Username = "guest"
|
||||
guestUser.Password = "guest"
|
||||
guestUser.Uid = "test"
|
||||
guestUser.Username = "测试人员"
|
||||
guestUser.Password = "test"
|
||||
guestUser.Role = "admin"
|
||||
guestUser.DeptId = 1
|
||||
defaultUsers = append(defaultUsers, adminUser, guestUser)
|
||||
|
||||
dashboardMenu := &models.Menu{}
|
||||
dashboardMenu.Icon = "org"
|
||||
dashboardMenu.Label = "控制面板"
|
||||
dashboardMenu.Name = "Dashboard"
|
||||
dashboardMenu.Public = true
|
||||
dashboardMenu.Uri = "/dashboard"
|
||||
|
||||
orgMenu := &models.Menu{}
|
||||
orgMenu.Icon = "org"
|
||||
orgMenu.Label = "组织机构"
|
||||
orgMenu.Name = "Organize"
|
||||
orgMenu.Public = true
|
||||
orgMenu.Uri = "/organize"
|
||||
|
||||
settingMenu := &models.Menu{}
|
||||
settingMenu.Icon = "connect"
|
||||
settingMenu.Label = "系统设置"
|
||||
settingMenu.Name = "System"
|
||||
settingMenu.Public = true
|
||||
settingMenu.Uri = "/system"
|
||||
defaultMenus = append(defaultMenus, dashboardMenu, orgMenu, settingMenu)
|
||||
|
||||
systemDepartment := &models.Department{}
|
||||
systemDepartment.Name = "系统部门"
|
||||
systemDepartment.Description = ""
|
||||
defaultDepartments = append(defaultDepartments, systemDepartment)
|
||||
}
|
||||
|
||||
func Init(db *gorm.DB) (err error) {
|
||||
func MergeMenu(db *gorm.DB, model *models.Menu) (err error) {
|
||||
if err = db.Where("name = ?", model.Name).First(model).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
err = db.Create(model).Error
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func Menu(db *gorm.DB) (err error) {
|
||||
for _, row := range defaultMenus {
|
||||
if err = MergeMenu(db, row); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func Data(db *gorm.DB) (err error) {
|
||||
var (
|
||||
n int64
|
||||
)
|
||||
|
@ -51,6 +102,10 @@ func Init(db *gorm.DB) (err error) {
|
|||
db.Save(items)
|
||||
}
|
||||
}
|
||||
|
||||
if db.Model(&models.Department{}).Count(&n); n == 0 {
|
||||
db.Create(defaultDepartments)
|
||||
}
|
||||
if db.Model(&models.User{}).Count(&n); n == 0 {
|
||||
db.Create(defaultUsers)
|
||||
}
|
||||
|
|
|
@ -28,6 +28,9 @@ func (t *ZH) Menu(model *rest.Model, label string) string {
|
|||
if _, ok := model.Value().Interface().(models.RolePermission); ok {
|
||||
return "角色权限"
|
||||
}
|
||||
if _, ok := model.Value().Interface().(models.Setting); ok {
|
||||
return "系统设置"
|
||||
}
|
||||
return label
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package models
|
||||
|
||||
import "git.nobla.cn/golang/aeus-admin/pb"
|
||||
import (
|
||||
"git.nobla.cn/golang/aeus-admin/pb"
|
||||
"git.nobla.cn/golang/aeus-admin/types"
|
||||
)
|
||||
|
||||
type (
|
||||
User struct {
|
||||
|
@ -21,4 +24,63 @@ type (
|
|||
RolePermission struct {
|
||||
pb.RolePermissionModel
|
||||
}
|
||||
|
||||
Setting struct {
|
||||
pb.SettingModel
|
||||
}
|
||||
)
|
||||
|
||||
func (m *User) GetMenu() *types.Menu {
|
||||
return &types.Menu{
|
||||
Name: "OrganizeUser",
|
||||
Parent: "Organize",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Menu) GetMenu() *types.Menu {
|
||||
return &types.Menu{
|
||||
Name: "OrganizeMenu",
|
||||
Parent: "Organize",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Department) GetMenu() *types.Menu {
|
||||
return &types.Menu{
|
||||
Name: "OrganizeDepartment",
|
||||
Parent: "Organize",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Role) GetMenu() *types.Menu {
|
||||
return &types.Menu{
|
||||
Name: "OrganizeRole",
|
||||
Parent: "Organize",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Permission) GetMenu() *types.Menu {
|
||||
return &types.Menu{
|
||||
Name: "OrganizePermission",
|
||||
Parent: "Organize",
|
||||
Hidden: true,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *RolePermission) GetMenu() *types.Menu {
|
||||
return &types.Menu{
|
||||
Name: "OrganizeRolePermission",
|
||||
Parent: "Organize",
|
||||
Hidden: true,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Setting) GetMenu() *types.Menu {
|
||||
return &types.Menu{
|
||||
Name: "SystemSetting",
|
||||
Parent: "System",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Setting) ModuleName() string {
|
||||
return "system"
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.nobla.cn/golang/aeus-admin/types"
|
||||
)
|
||||
|
||||
func TestModel(t *testing.T) {
|
||||
var m any
|
||||
m = &User{}
|
||||
if _, ok := m.(types.Model); ok {
|
||||
t.Log("ok")
|
||||
} else {
|
||||
t.Error("error")
|
||||
}
|
||||
}
|
1265
pb/organize.pb.go
1265
pb/organize.pb.go
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -14,15 +14,16 @@ message Menu {
|
|||
option (aeus.rest) = {
|
||||
table: "menus"
|
||||
};
|
||||
int64 id = 1 [(aeus.field) = {gorm:"primaryKey"}];
|
||||
int64 parent_id = 2;
|
||||
string name = 3 [(aeus.field)={gorm:"index;size:60"},(validate.rules).string = {max_len: 60}];
|
||||
string label = 4 [(aeus.field)={gorm:"size:120"},(validate.rules).string = {max_len: 120}];
|
||||
string uri = 5 [(aeus.field)={gorm:"size:512"},(validate.rules).string = {max_len: 512}];
|
||||
string view_path = 6 [(aeus.field)={gorm:"size:512"},(validate.rules).string = {max_len: 512}];
|
||||
string icon = 7 [(aeus.field)={gorm:"size:60"},(validate.rules).string = {max_len: 60}];
|
||||
bool hidden = 8;
|
||||
bool public = 9;
|
||||
int64 id = 1 [(aeus.field) = {gorm:"primaryKey",comment:"菜单ID"}];
|
||||
int64 parent_id = 2 [(aeus.field)={comment:"父级菜单"}];
|
||||
string name = 3 [(aeus.field)={gorm:"index;size:60",props:"readonly:update",rule:"required",comment: "组件名称"},(validate.rules).string = {max_len: 60}];
|
||||
string label = 4 [(aeus.field)={gorm:"size:120",rule:"required",comment: "菜单标题"},(validate.rules).string = {max_len: 120}];
|
||||
string uri = 5 [(aeus.field)={gorm:"size:512",rule:"required",scenarios:"create;update;view;export",comment: "菜单链接"},(validate.rules).string = {max_len: 512}];
|
||||
string view_path = 6 [(aeus.field)={gorm:"size:512",scenarios:"create;update;view;export",comment: "视图路径"},(validate.rules).string = {max_len: 512}];
|
||||
string icon = 7 [(aeus.field)={gorm:"size:60",scenarios:"create;update;view;export",comment: "菜单图标"},(validate.rules).string = {max_len: 60}];
|
||||
bool hidden = 8 [(aeus.field)={scenarios:"create;update;view;export",comment:"是否隐藏"}];
|
||||
bool public = 9 [(aeus.field)={scenarios:"create;update;view;export",comment:"是否公开"}];
|
||||
string description = 10 [(aeus.field)={gorm:"size:1024",scenarios:"create;update;view;export;list",format:"textarea",comment: "备注说明"},(validate.rules).string = {max_len: 1024}];
|
||||
}
|
||||
|
||||
// Role 角色模型定义
|
||||
|
@ -30,10 +31,10 @@ message Role {
|
|||
option (aeus.rest) = {
|
||||
table: "roles"
|
||||
};
|
||||
int64 id = 1 [(aeus.field) = {gorm:"primaryKey"}];
|
||||
string name = 2 [(aeus.field)={gorm:"index;size:60"},(validate.rules).string = {max_len: 60}];
|
||||
string label = 3 [(aeus.field)={gorm:"size:60"},(validate.rules).string = {max_len: 60}];
|
||||
string description = 4 [(aeus.field)={gorm:"size:1024"},(validate.rules).string = {max_len: 1024}];
|
||||
int64 id = 1 [(aeus.field) = {gorm:"primaryKey",comment: "角色ID"}];
|
||||
string name = 2 [(aeus.field)={gorm:"index;size:60",props:"readonly:update",comment: "角色名称"},(validate.rules).string = {max_len: 60}];
|
||||
string label = 3 [(aeus.field)={gorm:"size:60",comment: "角色标题"},(validate.rules).string = {max_len: 60}];
|
||||
string description = 4 [(aeus.field)={gorm:"size:1024",scenarios:"list;create;update;export",format:"textarea",comment: "备注说明"},(validate.rules).string = {max_len: 1024}];
|
||||
}
|
||||
|
||||
// Permission 权限模型定义
|
||||
|
@ -41,10 +42,10 @@ message Permission {
|
|||
option (aeus.rest) = {
|
||||
table: "permissions"
|
||||
};
|
||||
int64 id = 1 [(aeus.field) = {gorm:"primaryKey"}];
|
||||
int64 menu_id = 2 [(aeus.field)={gorm:"index"}];
|
||||
string permission = 3 [(aeus.field)={gorm:"index;size:60"},(validate.rules).string = {max_len: 60}];
|
||||
string label = 4 [(aeus.field)={gorm:"size:60"},(validate.rules).string = {max_len: 60}];
|
||||
int64 id = 1 [(aeus.field) = {gorm:"primaryKey",comment: "权限ID"}];
|
||||
int64 menu_id = 2 [(aeus.field)={gorm:"index",rule:"required",comment: "所属菜单"}];
|
||||
string permission = 3 [(aeus.field)={gorm:"index;size:60",rule:"required",comment: "权限名称"},(validate.rules).string = {max_len: 60}];
|
||||
string label = 4 [(aeus.field)={gorm:"size:60",rule:"required",comment: "权限标题"},(validate.rules).string = {max_len: 60}];
|
||||
}
|
||||
|
||||
// RolePermission 角色权限关联表
|
||||
|
@ -52,9 +53,9 @@ message RolePermission {
|
|||
option (aeus.rest) = {
|
||||
table: "role_permissions"
|
||||
};
|
||||
int64 id = 1 [(aeus.field) = {gorm:"primaryKey"}];
|
||||
string role = 2 [(aeus.field)={gorm:"size:60"},(validate.rules).string = {max_len: 60}];
|
||||
int64 permission_id = 3;
|
||||
int64 id = 1 [(aeus.field) = {gorm:"primaryKey",comment: "ID"}];
|
||||
string role = 2 [(aeus.field)={gorm:"size:60",rule:"required",comment: "角色名称"},(validate.rules).string = {max_len: 60}];
|
||||
int64 permission_id = 3 [(aeus.field)={rule:"required",comment: "权限ID"}];
|
||||
}
|
||||
|
||||
// User 用户模型定义
|
||||
|
@ -62,20 +63,20 @@ message User {
|
|||
option (aeus.rest) = {
|
||||
table: "users"
|
||||
};
|
||||
int64 id = 1 [(aeus.field) = {gorm:"primaryKey"}];
|
||||
int64 created_at = 2;
|
||||
int64 updated_at = 3;
|
||||
string uid = 4 [(aeus.field) = {gorm:"index;size:20"},(validate.rules).string = {min_len: 5, max_len: 20}];
|
||||
string username = 5 [(aeus.field)={gorm:"size:20"},(validate.rules).string = {min_len: 5, max_len: 20}];
|
||||
string role = 6 [(aeus.field)={gorm:"size:60"},(validate.rules).string = {max_len: 60}];
|
||||
bool admin = 7;
|
||||
int64 dept_id = 8 [(aeus.field) = {gorm:"not null;default:0"}];
|
||||
string tag = 9 [ (aeus.field)={gorm:"size:60"},(validate.rules).string = {max_len: 60}];
|
||||
string password = 10 [(aeus.field)={gorm:"size:60"},(validate.rules).string = {max_len: 60}];
|
||||
string email = 11 [(aeus.field)={gorm:"size:60"},(validate.rules).string = {max_len: 60}];
|
||||
string avatar = 12 [(aeus.field)={gorm:"size:1024"},(validate.rules).string = {max_len: 1024}];
|
||||
string gender = 13 [(aeus.field)={gorm:"size:20;default:man"},(validate.rules).string = {max_len: 20}];
|
||||
string description = 14 [(aeus.field)={gorm:"size:1024"},(validate.rules).string = {max_len: 1024}];
|
||||
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)={scenarios:"view;export",comment:"更新时间"}];
|
||||
string uid = 4 [(aeus.field) = {gorm:"index;size:20",rule:"required;unique;regexp:^[a-zA-Z0-9]{3,8}$",props:"readonly:update",comment: "用户工号"},(validate.rules).string = {min_len: 5, max_len: 20}];
|
||||
string username = 5 [(aeus.field)={gorm:"size:20",rule:"required",comment: "用户名称"},(validate.rules).string = {min_len: 5, max_len: 20}];
|
||||
string role = 6 [(aeus.field)={gorm:"size:60",rule:"required",format:"role",comment: "所属角色"},(validate.rules).string = {max_len: 60}];
|
||||
bool admin = 7 [(aeus.field)={scenarios:"create",comment:"管理员"}];
|
||||
int64 dept_id = 8 [(aeus.field) = {gorm:"not null;default:0",rule:"required",format:"department",comment: "所属部门"}];
|
||||
string tag = 9 [ (aeus.field)={gorm:"size:60",scenarios:"list;create;update",comment: "用户标签"},(validate.rules).string = {max_len: 60}];
|
||||
string password = 10 [(aeus.field)={gorm:"size:60",rule:"required",scenarios:"create",comment: "用户密码"},(validate.rules).string = {max_len: 60}];
|
||||
string email = 11 [(aeus.field)={gorm:"size:60",scenarios:"create;update;view;list;export",comment: "用户邮箱"},(validate.rules).string = {max_len: 60}];
|
||||
string avatar = 12 [(aeus.field)={gorm:"size:1024",scenarios:"view",comment: "用户头像"},(validate.rules).string = {max_len: 1024}];
|
||||
string gender = 13 [(aeus.field)={gorm:"size:20;default:man",rule:"required",scenarios:"list;create;update;view;export",comment: "用户性别"},(validate.rules).string = {max_len: 20}];
|
||||
string description = 14 [(aeus.field)={gorm:"size:1024",format:"textarea",scenarios:"create;update;view;export",comment: "备注说明"},(validate.rules).string = {max_len: 1024}];
|
||||
}
|
||||
|
||||
// Department 部门模型定义
|
||||
|
@ -83,14 +84,32 @@ message Department {
|
|||
option (aeus.rest) = {
|
||||
table: "departments"
|
||||
};
|
||||
int64 id = 1 [(aeus.field) = {gorm:"primaryKey"}];
|
||||
int64 created_at = 2;
|
||||
int64 updated_at = 3;
|
||||
int64 parent_id = 4;
|
||||
string name = 5 [(aeus.field)={gorm:"size:20"},(validate.rules).string = {max_len: 20}];
|
||||
string description = 6 [(aeus.field)={gorm:"size:1024"},(validate.rules).string = {max_len: 1024}];
|
||||
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)={scenarios:"view;export",comment:"更新时间"}];
|
||||
int64 parent_id = 4 [(aeus.field)={format:"department",comment:"父级部门"}];
|
||||
string name = 5 [(aeus.field)={gorm:"size:20",rule:"required",comment: "部门名称"},(validate.rules).string = {max_len: 20}];
|
||||
string description = 6 [(aeus.field)={gorm:"size:1024",scenarios:"create;update;view;export;list",format:"textarea",comment: "备注说明"},(validate.rules).string = {max_len: 1024}];
|
||||
}
|
||||
|
||||
// Setting 参数设置表
|
||||
message Setting {
|
||||
option (aeus.rest) = {
|
||||
table: "settings"
|
||||
};
|
||||
int64 id = 1 [(aeus.field) = {gorm:"primaryKey",comment:"ID"}];
|
||||
int64 created_at = 2 [(aeus.field)={scenarios:"search;view;export",comment:"创建时间"}];
|
||||
int64 updated_at = 3 [(aeus.field)={scenarios:"search;view;export",comment:"更新时间"}];
|
||||
string name = 4 [(aeus.field)={gorm:"size:60",rule:"required",props:"readonly:update",comment: "配置项"},(validate.rules).string = {max_len: 20}];
|
||||
string value = 5 [(aeus.field)={gorm:"size:512",rule:"required",format:"textarea",comment: "配置值"},(validate.rules).string = {max_len: 512}];
|
||||
string description = 6 [(aeus.field)={gorm:"size:1024",format:"textarea",scenarios:"create;update;view;export",comment: "备注说明"},(validate.rules).string = {max_len: 1024}];
|
||||
}
|
||||
|
||||
|
||||
message LabelValue {
|
||||
string label = 1;
|
||||
string value = 2;
|
||||
}
|
||||
|
||||
message PermissionItem {
|
||||
string value = 1;
|
||||
|
@ -105,8 +124,9 @@ message MenuItem {
|
|||
bool hidden = 4;
|
||||
bool public = 5;
|
||||
string route = 6;
|
||||
repeated PermissionItem permissions = 7;
|
||||
repeated MenuItem children = 8;
|
||||
string view = 7;
|
||||
repeated PermissionItem permissions = 8;
|
||||
repeated MenuItem children = 9;
|
||||
}
|
||||
|
||||
// 获取菜单的请求
|
||||
|
@ -119,15 +139,6 @@ message GetMenuResponse {
|
|||
repeated MenuItem data = 1;
|
||||
}
|
||||
|
||||
// 菜单服务
|
||||
service MenuService {
|
||||
rpc GetMenus(GetMenuRequest) returns (GetMenuResponse) {
|
||||
option (google.api.http) = {
|
||||
get: "/api/menu"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 获取用户信息
|
||||
message GetProfileRequest {
|
||||
|
@ -167,25 +178,123 @@ message UpdateProfileResponse {
|
|||
string uid = 1;
|
||||
}
|
||||
|
||||
message GetPermissionRequest {
|
||||
string uid = 1;
|
||||
}
|
||||
|
||||
message GetPermissionResponse {
|
||||
string uid = 1;
|
||||
repeated string permissions = 2;
|
||||
}
|
||||
|
||||
message GetUserLabelRequest {
|
||||
}
|
||||
|
||||
message GetUserLabelResponse {
|
||||
repeated LabelValue data = 1;
|
||||
}
|
||||
|
||||
message GetUserTagRequest {
|
||||
}
|
||||
|
||||
message GetUserTagResponse {
|
||||
repeated LabelValue data = 1;
|
||||
}
|
||||
|
||||
// 用户服务
|
||||
service ProfileService {
|
||||
service UserService {
|
||||
// 获取用户菜单
|
||||
rpc GetMenus(GetMenuRequest) returns (GetMenuResponse) {
|
||||
option (google.api.http) = {
|
||||
get: "/user/menus"
|
||||
};
|
||||
}
|
||||
// 获取用户信息
|
||||
rpc GetProfile(GetProfileRequest) returns (GetProfileResponse) {
|
||||
option (google.api.http) = {
|
||||
get: "/user/profile"
|
||||
};
|
||||
}
|
||||
// 更新用户信息
|
||||
rpc UpdateProfile(UpdateProfileRequest) returns (UpdateProfileResponse) {
|
||||
option (google.api.http) = {
|
||||
put: "/user/profile"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// 重置用户密码
|
||||
rpc ResetPassword(ResetPasswordRequest) returns (ResetPasswordResponse) {
|
||||
option (google.api.http) = {
|
||||
post: "/user/reset-password"
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
// 获取用户权限
|
||||
rpc GetPermissions(GetPermissionRequest) returns (GetPermissionResponse) {
|
||||
option (google.api.http) = {
|
||||
get: "/user/permissions"
|
||||
};
|
||||
}
|
||||
// 获取用户标签
|
||||
rpc GetUserLabels(GetUserLabelRequest) returns (GetUserLabelResponse) {
|
||||
option (google.api.http) = {
|
||||
get: "/user/labels"
|
||||
};
|
||||
}
|
||||
// 获取用户标签
|
||||
rpc GetUserTags(GetUserTagRequest) returns (GetUserTagResponse) {
|
||||
option (google.api.http) = {
|
||||
get: "/user/tags"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
message GetDepartmentLabelRequest {
|
||||
}
|
||||
|
||||
message GetDepartmentLabelResponse {
|
||||
repeated LabelValue data = 1;
|
||||
}
|
||||
|
||||
service DepartmentService {
|
||||
// 获取部门标签
|
||||
rpc GetDepartmentLabels(GetDepartmentLabelRequest) returns (GetDepartmentLabelResponse) {
|
||||
option (google.api.http) = {
|
||||
get: "/department/labels"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
message GetRoleLabelRequest {
|
||||
}
|
||||
|
||||
message GetRoleLabelResponse {
|
||||
repeated LabelValue data = 1;
|
||||
}
|
||||
|
||||
message GetRolePermissionRequest {
|
||||
string role = 1;
|
||||
}
|
||||
|
||||
message GetRolePermissionResponse {
|
||||
string role = 1;
|
||||
repeated string permissions = 2;
|
||||
}
|
||||
|
||||
service RoleService {
|
||||
// 获取角色标签
|
||||
rpc GetRoleLabels(GetRoleLabelRequest) returns (GetRoleLabelResponse) {
|
||||
option (google.api.http) = {
|
||||
get: "/role/labels"
|
||||
};
|
||||
}
|
||||
// 获取角色权限
|
||||
rpc GetRolePermissions(GetRolePermissionRequest) returns (GetRolePermissionResponse) {
|
||||
option (google.api.http) = {
|
||||
get: "/role/permissions"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -225,3 +334,22 @@ service AuthService {
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
message SettingItem {
|
||||
string name = 1;
|
||||
string value = 2;
|
||||
}
|
||||
|
||||
message GetSettingRequest{}
|
||||
|
||||
message GetSettingResponse{
|
||||
repeated SettingItem data = 1;
|
||||
}
|
||||
|
||||
service SettingService {
|
||||
rpc GetSetting(GetSettingRequest) returns (GetSettingResponse) {
|
||||
option (google.api.http) = {
|
||||
get: "/system/setting"
|
||||
};
|
||||
}
|
||||
}
|
|
@ -19,105 +19,347 @@ import (
|
|||
const _ = grpc.SupportPackageIsVersion9
|
||||
|
||||
const (
|
||||
MenuService_GetMenus_FullMethodName = "/organize.MenuService/GetMenus"
|
||||
UserService_GetMenus_FullMethodName = "/organize.UserService/GetMenus"
|
||||
UserService_GetProfile_FullMethodName = "/organize.UserService/GetProfile"
|
||||
UserService_UpdateProfile_FullMethodName = "/organize.UserService/UpdateProfile"
|
||||
UserService_ResetPassword_FullMethodName = "/organize.UserService/ResetPassword"
|
||||
UserService_GetPermissions_FullMethodName = "/organize.UserService/GetPermissions"
|
||||
UserService_GetUserLabels_FullMethodName = "/organize.UserService/GetUserLabels"
|
||||
UserService_GetUserTags_FullMethodName = "/organize.UserService/GetUserTags"
|
||||
)
|
||||
|
||||
// MenuServiceClient is the client API for MenuService service.
|
||||
// UserServiceClient is the client API for UserService service.
|
||||
//
|
||||
// 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 {
|
||||
// 用户服务
|
||||
type UserServiceClient interface {
|
||||
// 获取用户菜单
|
||||
GetMenus(ctx context.Context, in *GetMenuRequest, opts ...grpc.CallOption) (*GetMenuResponse, error)
|
||||
// 获取用户信息
|
||||
GetProfile(ctx context.Context, in *GetProfileRequest, opts ...grpc.CallOption) (*GetProfileResponse, error)
|
||||
// 更新用户信息
|
||||
UpdateProfile(ctx context.Context, in *UpdateProfileRequest, opts ...grpc.CallOption) (*UpdateProfileResponse, error)
|
||||
// 重置用户密码
|
||||
ResetPassword(ctx context.Context, in *ResetPasswordRequest, opts ...grpc.CallOption) (*ResetPasswordResponse, error)
|
||||
// 获取用户权限
|
||||
GetPermissions(ctx context.Context, in *GetPermissionRequest, opts ...grpc.CallOption) (*GetPermissionResponse, error)
|
||||
// 获取用户标签
|
||||
GetUserLabels(ctx context.Context, in *GetUserLabelRequest, opts ...grpc.CallOption) (*GetUserLabelResponse, error)
|
||||
// 获取用户标签
|
||||
GetUserTags(ctx context.Context, in *GetUserTagRequest, opts ...grpc.CallOption) (*GetUserTagResponse, error)
|
||||
}
|
||||
|
||||
type menuServiceClient struct {
|
||||
type userServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewMenuServiceClient(cc grpc.ClientConnInterface) MenuServiceClient {
|
||||
return &menuServiceClient{cc}
|
||||
func NewUserServiceClient(cc grpc.ClientConnInterface) UserServiceClient {
|
||||
return &userServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *menuServiceClient) GetMenus(ctx context.Context, in *GetMenuRequest, opts ...grpc.CallOption) (*GetMenuResponse, error) {
|
||||
func (c *userServiceClient) 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...)
|
||||
err := c.cc.Invoke(ctx, UserService_GetMenus_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// MenuServiceServer is the server API for MenuService service.
|
||||
// All implementations must embed UnimplementedMenuServiceServer
|
||||
// for forward compatibility.
|
||||
//
|
||||
// 菜单服务
|
||||
type MenuServiceServer interface {
|
||||
GetMenus(context.Context, *GetMenuRequest) (*GetMenuResponse, error)
|
||||
mustEmbedUnimplementedMenuServiceServer()
|
||||
func (c *userServiceClient) GetProfile(ctx context.Context, in *GetProfileRequest, opts ...grpc.CallOption) (*GetProfileResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(GetProfileResponse)
|
||||
err := c.cc.Invoke(ctx, UserService_GetProfile_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// UnimplementedMenuServiceServer must be embedded to have
|
||||
func (c *userServiceClient) UpdateProfile(ctx context.Context, in *UpdateProfileRequest, opts ...grpc.CallOption) (*UpdateProfileResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(UpdateProfileResponse)
|
||||
err := c.cc.Invoke(ctx, UserService_UpdateProfile_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *userServiceClient) ResetPassword(ctx context.Context, in *ResetPasswordRequest, opts ...grpc.CallOption) (*ResetPasswordResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(ResetPasswordResponse)
|
||||
err := c.cc.Invoke(ctx, UserService_ResetPassword_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *userServiceClient) GetPermissions(ctx context.Context, in *GetPermissionRequest, opts ...grpc.CallOption) (*GetPermissionResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(GetPermissionResponse)
|
||||
err := c.cc.Invoke(ctx, UserService_GetPermissions_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *userServiceClient) GetUserLabels(ctx context.Context, in *GetUserLabelRequest, opts ...grpc.CallOption) (*GetUserLabelResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(GetUserLabelResponse)
|
||||
err := c.cc.Invoke(ctx, UserService_GetUserLabels_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *userServiceClient) GetUserTags(ctx context.Context, in *GetUserTagRequest, opts ...grpc.CallOption) (*GetUserTagResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(GetUserTagResponse)
|
||||
err := c.cc.Invoke(ctx, UserService_GetUserTags_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// UserServiceServer is the server API for UserService service.
|
||||
// All implementations must embed UnimplementedUserServiceServer
|
||||
// for forward compatibility.
|
||||
//
|
||||
// 用户服务
|
||||
type UserServiceServer interface {
|
||||
// 获取用户菜单
|
||||
GetMenus(context.Context, *GetMenuRequest) (*GetMenuResponse, error)
|
||||
// 获取用户信息
|
||||
GetProfile(context.Context, *GetProfileRequest) (*GetProfileResponse, error)
|
||||
// 更新用户信息
|
||||
UpdateProfile(context.Context, *UpdateProfileRequest) (*UpdateProfileResponse, error)
|
||||
// 重置用户密码
|
||||
ResetPassword(context.Context, *ResetPasswordRequest) (*ResetPasswordResponse, error)
|
||||
// 获取用户权限
|
||||
GetPermissions(context.Context, *GetPermissionRequest) (*GetPermissionResponse, error)
|
||||
// 获取用户标签
|
||||
GetUserLabels(context.Context, *GetUserLabelRequest) (*GetUserLabelResponse, error)
|
||||
// 获取用户标签
|
||||
GetUserTags(context.Context, *GetUserTagRequest) (*GetUserTagResponse, error)
|
||||
mustEmbedUnimplementedUserServiceServer()
|
||||
}
|
||||
|
||||
// UnimplementedUserServiceServer must be embedded to have
|
||||
// forward compatible implementations.
|
||||
//
|
||||
// NOTE: this should be embedded by value instead of pointer to avoid a nil
|
||||
// pointer dereference when methods are called.
|
||||
type UnimplementedMenuServiceServer struct{}
|
||||
type UnimplementedUserServiceServer struct{}
|
||||
|
||||
func (UnimplementedMenuServiceServer) GetMenus(context.Context, *GetMenuRequest) (*GetMenuResponse, error) {
|
||||
func (UnimplementedUserServiceServer) GetMenus(context.Context, *GetMenuRequest) (*GetMenuResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetMenus not implemented")
|
||||
}
|
||||
func (UnimplementedMenuServiceServer) mustEmbedUnimplementedMenuServiceServer() {}
|
||||
func (UnimplementedMenuServiceServer) testEmbeddedByValue() {}
|
||||
func (UnimplementedUserServiceServer) GetProfile(context.Context, *GetProfileRequest) (*GetProfileResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetProfile not implemented")
|
||||
}
|
||||
func (UnimplementedUserServiceServer) UpdateProfile(context.Context, *UpdateProfileRequest) (*UpdateProfileResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method UpdateProfile not implemented")
|
||||
}
|
||||
func (UnimplementedUserServiceServer) ResetPassword(context.Context, *ResetPasswordRequest) (*ResetPasswordResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ResetPassword not implemented")
|
||||
}
|
||||
func (UnimplementedUserServiceServer) GetPermissions(context.Context, *GetPermissionRequest) (*GetPermissionResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetPermissions not implemented")
|
||||
}
|
||||
func (UnimplementedUserServiceServer) GetUserLabels(context.Context, *GetUserLabelRequest) (*GetUserLabelResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetUserLabels not implemented")
|
||||
}
|
||||
func (UnimplementedUserServiceServer) GetUserTags(context.Context, *GetUserTagRequest) (*GetUserTagResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetUserTags not implemented")
|
||||
}
|
||||
func (UnimplementedUserServiceServer) mustEmbedUnimplementedUserServiceServer() {}
|
||||
func (UnimplementedUserServiceServer) testEmbeddedByValue() {}
|
||||
|
||||
// UnsafeMenuServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to MenuServiceServer will
|
||||
// UnsafeUserServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to UserServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeMenuServiceServer interface {
|
||||
mustEmbedUnimplementedMenuServiceServer()
|
||||
type UnsafeUserServiceServer interface {
|
||||
mustEmbedUnimplementedUserServiceServer()
|
||||
}
|
||||
|
||||
func RegisterMenuServiceServer(s grpc.ServiceRegistrar, srv MenuServiceServer) {
|
||||
// If the following call pancis, it indicates UnimplementedMenuServiceServer was
|
||||
func RegisterUserServiceServer(s grpc.ServiceRegistrar, srv UserServiceServer) {
|
||||
// If the following call pancis, it indicates UnimplementedUserServiceServer was
|
||||
// embedded by pointer and is nil. This will cause panics if an
|
||||
// unimplemented method is ever invoked, so we test this at initialization
|
||||
// time to prevent it from happening at runtime later due to I/O.
|
||||
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
|
||||
t.testEmbeddedByValue()
|
||||
}
|
||||
s.RegisterService(&MenuService_ServiceDesc, srv)
|
||||
s.RegisterService(&UserService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _MenuService_GetMenus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
func _UserService_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)
|
||||
return srv.(UserServiceServer).GetMenus(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: MenuService_GetMenus_FullMethodName,
|
||||
FullMethod: UserService_GetMenus_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(MenuServiceServer).GetMenus(ctx, req.(*GetMenuRequest))
|
||||
return srv.(UserServiceServer).GetMenus(ctx, req.(*GetMenuRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// MenuService_ServiceDesc is the grpc.ServiceDesc for MenuService service.
|
||||
func _UserService_GetProfile_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetProfileRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(UserServiceServer).GetProfile(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: UserService_GetProfile_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(UserServiceServer).GetProfile(ctx, req.(*GetProfileRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _UserService_UpdateProfile_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(UpdateProfileRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(UserServiceServer).UpdateProfile(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: UserService_UpdateProfile_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(UserServiceServer).UpdateProfile(ctx, req.(*UpdateProfileRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _UserService_ResetPassword_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ResetPasswordRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(UserServiceServer).ResetPassword(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: UserService_ResetPassword_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(UserServiceServer).ResetPassword(ctx, req.(*ResetPasswordRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _UserService_GetPermissions_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetPermissionRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(UserServiceServer).GetPermissions(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: UserService_GetPermissions_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(UserServiceServer).GetPermissions(ctx, req.(*GetPermissionRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _UserService_GetUserLabels_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetUserLabelRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(UserServiceServer).GetUserLabels(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: UserService_GetUserLabels_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(UserServiceServer).GetUserLabels(ctx, req.(*GetUserLabelRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _UserService_GetUserTags_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetUserTagRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(UserServiceServer).GetUserTags(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: UserService_GetUserTags_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(UserServiceServer).GetUserTags(ctx, req.(*GetUserTagRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// UserService_ServiceDesc is the grpc.ServiceDesc for UserService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var MenuService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "organize.MenuService",
|
||||
HandlerType: (*MenuServiceServer)(nil),
|
||||
var UserService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "organize.UserService",
|
||||
HandlerType: (*UserServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "GetMenus",
|
||||
Handler: _MenuService_GetMenus_Handler,
|
||||
Handler: _UserService_GetMenus_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetProfile",
|
||||
Handler: _UserService_GetProfile_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "UpdateProfile",
|
||||
Handler: _UserService_UpdateProfile_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ResetPassword",
|
||||
Handler: _UserService_ResetPassword_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetPermissions",
|
||||
Handler: _UserService_GetPermissions_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetUserLabels",
|
||||
Handler: _UserService_GetUserLabels_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetUserTags",
|
||||
Handler: _UserService_GetUserTags_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
|
@ -125,181 +367,247 @@ var MenuService_ServiceDesc = grpc.ServiceDesc{
|
|||
}
|
||||
|
||||
const (
|
||||
ProfileService_GetProfile_FullMethodName = "/organize.ProfileService/GetProfile"
|
||||
ProfileService_UpdateProfile_FullMethodName = "/organize.ProfileService/UpdateProfile"
|
||||
ProfileService_ResetPassword_FullMethodName = "/organize.ProfileService/ResetPassword"
|
||||
DepartmentService_GetDepartmentLabels_FullMethodName = "/organize.DepartmentService/GetDepartmentLabels"
|
||||
)
|
||||
|
||||
// ProfileServiceClient is the client API for ProfileService service.
|
||||
// DepartmentServiceClient is the client API for DepartmentService service.
|
||||
//
|
||||
// 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 ProfileServiceClient interface {
|
||||
GetProfile(ctx context.Context, in *GetProfileRequest, opts ...grpc.CallOption) (*GetProfileResponse, error)
|
||||
UpdateProfile(ctx context.Context, in *UpdateProfileRequest, opts ...grpc.CallOption) (*UpdateProfileResponse, error)
|
||||
ResetPassword(ctx context.Context, in *ResetPasswordRequest, opts ...grpc.CallOption) (*ResetPasswordResponse, error)
|
||||
type DepartmentServiceClient interface {
|
||||
// 获取部门标签
|
||||
GetDepartmentLabels(ctx context.Context, in *GetDepartmentLabelRequest, opts ...grpc.CallOption) (*GetDepartmentLabelResponse, error)
|
||||
}
|
||||
|
||||
type profileServiceClient struct {
|
||||
type departmentServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewProfileServiceClient(cc grpc.ClientConnInterface) ProfileServiceClient {
|
||||
return &profileServiceClient{cc}
|
||||
func NewDepartmentServiceClient(cc grpc.ClientConnInterface) DepartmentServiceClient {
|
||||
return &departmentServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *profileServiceClient) GetProfile(ctx context.Context, in *GetProfileRequest, opts ...grpc.CallOption) (*GetProfileResponse, error) {
|
||||
func (c *departmentServiceClient) GetDepartmentLabels(ctx context.Context, in *GetDepartmentLabelRequest, opts ...grpc.CallOption) (*GetDepartmentLabelResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(GetProfileResponse)
|
||||
err := c.cc.Invoke(ctx, ProfileService_GetProfile_FullMethodName, in, out, cOpts...)
|
||||
out := new(GetDepartmentLabelResponse)
|
||||
err := c.cc.Invoke(ctx, DepartmentService_GetDepartmentLabels_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *profileServiceClient) UpdateProfile(ctx context.Context, in *UpdateProfileRequest, opts ...grpc.CallOption) (*UpdateProfileResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(UpdateProfileResponse)
|
||||
err := c.cc.Invoke(ctx, ProfileService_UpdateProfile_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *profileServiceClient) ResetPassword(ctx context.Context, in *ResetPasswordRequest, opts ...grpc.CallOption) (*ResetPasswordResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(ResetPasswordResponse)
|
||||
err := c.cc.Invoke(ctx, ProfileService_ResetPassword_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// ProfileServiceServer is the server API for ProfileService service.
|
||||
// All implementations must embed UnimplementedProfileServiceServer
|
||||
// DepartmentServiceServer is the server API for DepartmentService service.
|
||||
// All implementations must embed UnimplementedDepartmentServiceServer
|
||||
// for forward compatibility.
|
||||
//
|
||||
// 用户服务
|
||||
type ProfileServiceServer interface {
|
||||
GetProfile(context.Context, *GetProfileRequest) (*GetProfileResponse, error)
|
||||
UpdateProfile(context.Context, *UpdateProfileRequest) (*UpdateProfileResponse, error)
|
||||
ResetPassword(context.Context, *ResetPasswordRequest) (*ResetPasswordResponse, error)
|
||||
mustEmbedUnimplementedProfileServiceServer()
|
||||
type DepartmentServiceServer interface {
|
||||
// 获取部门标签
|
||||
GetDepartmentLabels(context.Context, *GetDepartmentLabelRequest) (*GetDepartmentLabelResponse, error)
|
||||
mustEmbedUnimplementedDepartmentServiceServer()
|
||||
}
|
||||
|
||||
// UnimplementedProfileServiceServer must be embedded to have
|
||||
// UnimplementedDepartmentServiceServer must be embedded to have
|
||||
// forward compatible implementations.
|
||||
//
|
||||
// NOTE: this should be embedded by value instead of pointer to avoid a nil
|
||||
// pointer dereference when methods are called.
|
||||
type UnimplementedProfileServiceServer struct{}
|
||||
type UnimplementedDepartmentServiceServer struct{}
|
||||
|
||||
func (UnimplementedProfileServiceServer) GetProfile(context.Context, *GetProfileRequest) (*GetProfileResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetProfile not implemented")
|
||||
func (UnimplementedDepartmentServiceServer) GetDepartmentLabels(context.Context, *GetDepartmentLabelRequest) (*GetDepartmentLabelResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetDepartmentLabels not implemented")
|
||||
}
|
||||
func (UnimplementedProfileServiceServer) UpdateProfile(context.Context, *UpdateProfileRequest) (*UpdateProfileResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method UpdateProfile not implemented")
|
||||
}
|
||||
func (UnimplementedProfileServiceServer) ResetPassword(context.Context, *ResetPasswordRequest) (*ResetPasswordResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ResetPassword not implemented")
|
||||
}
|
||||
func (UnimplementedProfileServiceServer) mustEmbedUnimplementedProfileServiceServer() {}
|
||||
func (UnimplementedProfileServiceServer) testEmbeddedByValue() {}
|
||||
func (UnimplementedDepartmentServiceServer) mustEmbedUnimplementedDepartmentServiceServer() {}
|
||||
func (UnimplementedDepartmentServiceServer) testEmbeddedByValue() {}
|
||||
|
||||
// UnsafeProfileServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to ProfileServiceServer will
|
||||
// UnsafeDepartmentServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to DepartmentServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeProfileServiceServer interface {
|
||||
mustEmbedUnimplementedProfileServiceServer()
|
||||
type UnsafeDepartmentServiceServer interface {
|
||||
mustEmbedUnimplementedDepartmentServiceServer()
|
||||
}
|
||||
|
||||
func RegisterProfileServiceServer(s grpc.ServiceRegistrar, srv ProfileServiceServer) {
|
||||
// If the following call pancis, it indicates UnimplementedProfileServiceServer was
|
||||
func RegisterDepartmentServiceServer(s grpc.ServiceRegistrar, srv DepartmentServiceServer) {
|
||||
// If the following call pancis, it indicates UnimplementedDepartmentServiceServer was
|
||||
// embedded by pointer and is nil. This will cause panics if an
|
||||
// unimplemented method is ever invoked, so we test this at initialization
|
||||
// time to prevent it from happening at runtime later due to I/O.
|
||||
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
|
||||
t.testEmbeddedByValue()
|
||||
}
|
||||
s.RegisterService(&ProfileService_ServiceDesc, srv)
|
||||
s.RegisterService(&DepartmentService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _ProfileService_GetProfile_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetProfileRequest)
|
||||
func _DepartmentService_GetDepartmentLabels_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetDepartmentLabelRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ProfileServiceServer).GetProfile(ctx, in)
|
||||
return srv.(DepartmentServiceServer).GetDepartmentLabels(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: ProfileService_GetProfile_FullMethodName,
|
||||
FullMethod: DepartmentService_GetDepartmentLabels_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ProfileServiceServer).GetProfile(ctx, req.(*GetProfileRequest))
|
||||
return srv.(DepartmentServiceServer).GetDepartmentLabels(ctx, req.(*GetDepartmentLabelRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _ProfileService_UpdateProfile_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(UpdateProfileRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ProfileServiceServer).UpdateProfile(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: ProfileService_UpdateProfile_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ProfileServiceServer).UpdateProfile(ctx, req.(*UpdateProfileRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _ProfileService_ResetPassword_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ResetPasswordRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(ProfileServiceServer).ResetPassword(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: ProfileService_ResetPassword_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(ProfileServiceServer).ResetPassword(ctx, req.(*ResetPasswordRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// ProfileService_ServiceDesc is the grpc.ServiceDesc for ProfileService service.
|
||||
// DepartmentService_ServiceDesc is the grpc.ServiceDesc for DepartmentService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var ProfileService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "organize.ProfileService",
|
||||
HandlerType: (*ProfileServiceServer)(nil),
|
||||
var DepartmentService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "organize.DepartmentService",
|
||||
HandlerType: (*DepartmentServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "GetProfile",
|
||||
Handler: _ProfileService_GetProfile_Handler,
|
||||
MethodName: "GetDepartmentLabels",
|
||||
Handler: _DepartmentService_GetDepartmentLabels_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "organize.proto",
|
||||
}
|
||||
|
||||
const (
|
||||
RoleService_GetRoleLabels_FullMethodName = "/organize.RoleService/GetRoleLabels"
|
||||
RoleService_GetRolePermissions_FullMethodName = "/organize.RoleService/GetRolePermissions"
|
||||
)
|
||||
|
||||
// RoleServiceClient is the client API for RoleService service.
|
||||
//
|
||||
// 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 RoleServiceClient interface {
|
||||
// 获取角色标签
|
||||
GetRoleLabels(ctx context.Context, in *GetRoleLabelRequest, opts ...grpc.CallOption) (*GetRoleLabelResponse, error)
|
||||
// 获取角色权限
|
||||
GetRolePermissions(ctx context.Context, in *GetRolePermissionRequest, opts ...grpc.CallOption) (*GetRolePermissionResponse, error)
|
||||
}
|
||||
|
||||
type roleServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewRoleServiceClient(cc grpc.ClientConnInterface) RoleServiceClient {
|
||||
return &roleServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *roleServiceClient) GetRoleLabels(ctx context.Context, in *GetRoleLabelRequest, opts ...grpc.CallOption) (*GetRoleLabelResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(GetRoleLabelResponse)
|
||||
err := c.cc.Invoke(ctx, RoleService_GetRoleLabels_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *roleServiceClient) GetRolePermissions(ctx context.Context, in *GetRolePermissionRequest, opts ...grpc.CallOption) (*GetRolePermissionResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(GetRolePermissionResponse)
|
||||
err := c.cc.Invoke(ctx, RoleService_GetRolePermissions_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// RoleServiceServer is the server API for RoleService service.
|
||||
// All implementations must embed UnimplementedRoleServiceServer
|
||||
// for forward compatibility.
|
||||
type RoleServiceServer interface {
|
||||
// 获取角色标签
|
||||
GetRoleLabels(context.Context, *GetRoleLabelRequest) (*GetRoleLabelResponse, error)
|
||||
// 获取角色权限
|
||||
GetRolePermissions(context.Context, *GetRolePermissionRequest) (*GetRolePermissionResponse, error)
|
||||
mustEmbedUnimplementedRoleServiceServer()
|
||||
}
|
||||
|
||||
// UnimplementedRoleServiceServer must be embedded to have
|
||||
// forward compatible implementations.
|
||||
//
|
||||
// NOTE: this should be embedded by value instead of pointer to avoid a nil
|
||||
// pointer dereference when methods are called.
|
||||
type UnimplementedRoleServiceServer struct{}
|
||||
|
||||
func (UnimplementedRoleServiceServer) GetRoleLabels(context.Context, *GetRoleLabelRequest) (*GetRoleLabelResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetRoleLabels not implemented")
|
||||
}
|
||||
func (UnimplementedRoleServiceServer) GetRolePermissions(context.Context, *GetRolePermissionRequest) (*GetRolePermissionResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetRolePermissions not implemented")
|
||||
}
|
||||
func (UnimplementedRoleServiceServer) mustEmbedUnimplementedRoleServiceServer() {}
|
||||
func (UnimplementedRoleServiceServer) testEmbeddedByValue() {}
|
||||
|
||||
// UnsafeRoleServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to RoleServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeRoleServiceServer interface {
|
||||
mustEmbedUnimplementedRoleServiceServer()
|
||||
}
|
||||
|
||||
func RegisterRoleServiceServer(s grpc.ServiceRegistrar, srv RoleServiceServer) {
|
||||
// If the following call pancis, it indicates UnimplementedRoleServiceServer was
|
||||
// embedded by pointer and is nil. This will cause panics if an
|
||||
// unimplemented method is ever invoked, so we test this at initialization
|
||||
// time to prevent it from happening at runtime later due to I/O.
|
||||
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
|
||||
t.testEmbeddedByValue()
|
||||
}
|
||||
s.RegisterService(&RoleService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _RoleService_GetRoleLabels_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetRoleLabelRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(RoleServiceServer).GetRoleLabels(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: RoleService_GetRoleLabels_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(RoleServiceServer).GetRoleLabels(ctx, req.(*GetRoleLabelRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _RoleService_GetRolePermissions_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetRolePermissionRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(RoleServiceServer).GetRolePermissions(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: RoleService_GetRolePermissions_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(RoleServiceServer).GetRolePermissions(ctx, req.(*GetRolePermissionRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// RoleService_ServiceDesc is the grpc.ServiceDesc for RoleService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var RoleService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "organize.RoleService",
|
||||
HandlerType: (*RoleServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "GetRoleLabels",
|
||||
Handler: _RoleService_GetRoleLabels_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "UpdateProfile",
|
||||
Handler: _ProfileService_UpdateProfile_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ResetPassword",
|
||||
Handler: _ProfileService_ResetPassword_Handler,
|
||||
MethodName: "GetRolePermissions",
|
||||
Handler: _RoleService_GetRolePermissions_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
|
@ -449,3 +757,105 @@ var AuthService_ServiceDesc = grpc.ServiceDesc{
|
|||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "organize.proto",
|
||||
}
|
||||
|
||||
const (
|
||||
SettingService_GetSetting_FullMethodName = "/organize.SettingService/GetSetting"
|
||||
)
|
||||
|
||||
// SettingServiceClient is the client API for SettingService service.
|
||||
//
|
||||
// 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 SettingServiceClient interface {
|
||||
GetSetting(ctx context.Context, in *GetSettingRequest, opts ...grpc.CallOption) (*GetSettingResponse, error)
|
||||
}
|
||||
|
||||
type settingServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewSettingServiceClient(cc grpc.ClientConnInterface) SettingServiceClient {
|
||||
return &settingServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *settingServiceClient) GetSetting(ctx context.Context, in *GetSettingRequest, opts ...grpc.CallOption) (*GetSettingResponse, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(GetSettingResponse)
|
||||
err := c.cc.Invoke(ctx, SettingService_GetSetting_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// SettingServiceServer is the server API for SettingService service.
|
||||
// All implementations must embed UnimplementedSettingServiceServer
|
||||
// for forward compatibility.
|
||||
type SettingServiceServer interface {
|
||||
GetSetting(context.Context, *GetSettingRequest) (*GetSettingResponse, error)
|
||||
mustEmbedUnimplementedSettingServiceServer()
|
||||
}
|
||||
|
||||
// UnimplementedSettingServiceServer must be embedded to have
|
||||
// forward compatible implementations.
|
||||
//
|
||||
// NOTE: this should be embedded by value instead of pointer to avoid a nil
|
||||
// pointer dereference when methods are called.
|
||||
type UnimplementedSettingServiceServer struct{}
|
||||
|
||||
func (UnimplementedSettingServiceServer) GetSetting(context.Context, *GetSettingRequest) (*GetSettingResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetSetting not implemented")
|
||||
}
|
||||
func (UnimplementedSettingServiceServer) mustEmbedUnimplementedSettingServiceServer() {}
|
||||
func (UnimplementedSettingServiceServer) testEmbeddedByValue() {}
|
||||
|
||||
// UnsafeSettingServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to SettingServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeSettingServiceServer interface {
|
||||
mustEmbedUnimplementedSettingServiceServer()
|
||||
}
|
||||
|
||||
func RegisterSettingServiceServer(s grpc.ServiceRegistrar, srv SettingServiceServer) {
|
||||
// If the following call pancis, it indicates UnimplementedSettingServiceServer was
|
||||
// embedded by pointer and is nil. This will cause panics if an
|
||||
// unimplemented method is ever invoked, so we test this at initialization
|
||||
// time to prevent it from happening at runtime later due to I/O.
|
||||
if t, ok := srv.(interface{ testEmbeddedByValue() }); ok {
|
||||
t.testEmbeddedByValue()
|
||||
}
|
||||
s.RegisterService(&SettingService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _SettingService_GetSetting_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetSettingRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(SettingServiceServer).GetSetting(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: SettingService_GetSetting_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(SettingServiceServer).GetSetting(ctx, req.(*GetSettingRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// SettingService_ServiceDesc is the grpc.ServiceDesc for SettingService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var SettingService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "organize.SettingService",
|
||||
HandlerType: (*SettingServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "GetSetting",
|
||||
Handler: _SettingService_GetSetting_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "organize.proto",
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by protoc-gen-go-aeus. DO NOT EDIT.
|
||||
// source: organize.proto
|
||||
// date: 2025-06-13 11:10:07
|
||||
// date: 2025-06-16 11:37:44
|
||||
|
||||
package pb
|
||||
|
||||
|
@ -10,16 +10,30 @@ import (
|
|||
"git.nobla.cn/golang/aeus/pkg/errors"
|
||||
)
|
||||
|
||||
type MenuServiceHttpServer interface {
|
||||
type UserServiceHttpServer interface {
|
||||
GetMenus(context.Context, *GetMenuRequest) (*GetMenuResponse, error)
|
||||
}
|
||||
|
||||
type ProfileServiceHttpServer interface {
|
||||
GetProfile(context.Context, *GetProfileRequest) (*GetProfileResponse, error)
|
||||
|
||||
UpdateProfile(context.Context, *UpdateProfileRequest) (*UpdateProfileResponse, error)
|
||||
|
||||
ResetPassword(context.Context, *ResetPasswordRequest) (*ResetPasswordResponse, error)
|
||||
|
||||
GetPermissions(context.Context, *GetPermissionRequest) (*GetPermissionResponse, error)
|
||||
|
||||
GetUserLabels(context.Context, *GetUserLabelRequest) (*GetUserLabelResponse, error)
|
||||
|
||||
GetUserTags(context.Context, *GetUserTagRequest) (*GetUserTagResponse, error)
|
||||
}
|
||||
|
||||
type DepartmentServiceHttpServer interface {
|
||||
GetDepartmentLabels(context.Context, *GetDepartmentLabelRequest) (*GetDepartmentLabelResponse, error)
|
||||
}
|
||||
|
||||
type RoleServiceHttpServer interface {
|
||||
GetRoleLabels(context.Context, *GetRoleLabelRequest) (*GetRoleLabelResponse, error)
|
||||
|
||||
GetRolePermissions(context.Context, *GetRolePermissionRequest) (*GetRolePermissionResponse, error)
|
||||
}
|
||||
|
||||
type AuthServiceHttpServer interface {
|
||||
|
@ -28,7 +42,13 @@ type AuthServiceHttpServer interface {
|
|||
Logout(context.Context, *LogoutRequest) (*LogoutResponse, error)
|
||||
}
|
||||
|
||||
func handleMenuServiceGetMenus(s MenuServiceHttpServer) http.HandleFunc {
|
||||
type SettingServiceHttpServer interface {
|
||||
GetSetting(context.Context, *GetSettingRequest) (*GetSettingResponse, error)
|
||||
}
|
||||
|
||||
// 获取用户菜单
|
||||
|
||||
func handleUserServiceGetMenus(s UserServiceHttpServer) http.HandleFunc {
|
||||
return func(ctx *http.Context) (err error) {
|
||||
req := &GetMenuRequest{}
|
||||
|
||||
|
@ -48,7 +68,9 @@ func handleMenuServiceGetMenus(s MenuServiceHttpServer) http.HandleFunc {
|
|||
}
|
||||
}
|
||||
|
||||
func handleProfileServiceGetProfile(s ProfileServiceHttpServer) http.HandleFunc {
|
||||
// 获取用户信息
|
||||
|
||||
func handleUserServiceGetProfile(s UserServiceHttpServer) http.HandleFunc {
|
||||
return func(ctx *http.Context) (err error) {
|
||||
req := &GetProfileRequest{}
|
||||
|
||||
|
@ -68,7 +90,9 @@ func handleProfileServiceGetProfile(s ProfileServiceHttpServer) http.HandleFunc
|
|||
}
|
||||
}
|
||||
|
||||
func handleProfileServiceUpdateProfile(s ProfileServiceHttpServer) http.HandleFunc {
|
||||
// 更新用户信息
|
||||
|
||||
func handleUserServiceUpdateProfile(s UserServiceHttpServer) http.HandleFunc {
|
||||
return func(ctx *http.Context) (err error) {
|
||||
req := &UpdateProfileRequest{}
|
||||
|
||||
|
@ -88,7 +112,9 @@ func handleProfileServiceUpdateProfile(s ProfileServiceHttpServer) http.HandleFu
|
|||
}
|
||||
}
|
||||
|
||||
func handleProfileServiceResetPassword(s ProfileServiceHttpServer) http.HandleFunc {
|
||||
// 重置用户密码
|
||||
|
||||
func handleUserServiceResetPassword(s UserServiceHttpServer) http.HandleFunc {
|
||||
return func(ctx *http.Context) (err error) {
|
||||
req := &ResetPasswordRequest{}
|
||||
|
||||
|
@ -108,6 +134,122 @@ func handleProfileServiceResetPassword(s ProfileServiceHttpServer) http.HandleFu
|
|||
}
|
||||
}
|
||||
|
||||
// 获取用户权限
|
||||
|
||||
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)
|
||||
} else {
|
||||
return ctx.Error(errors.Unavailable, err.Error())
|
||||
}
|
||||
} else {
|
||||
return ctx.Success(res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取用户标签
|
||||
|
||||
func handleUserServiceGetUserLabels(s UserServiceHttpServer) http.HandleFunc {
|
||||
return func(ctx *http.Context) (err error) {
|
||||
req := &GetUserLabelRequest{}
|
||||
|
||||
if res, err := s.GetUserLabels(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 handleUserServiceGetUserTags(s UserServiceHttpServer) http.HandleFunc {
|
||||
return func(ctx *http.Context) (err error) {
|
||||
req := &GetUserTagRequest{}
|
||||
|
||||
if res, err := s.GetUserTags(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 handleDepartmentServiceGetDepartmentLabels(s DepartmentServiceHttpServer) http.HandleFunc {
|
||||
return func(ctx *http.Context) (err error) {
|
||||
req := &GetDepartmentLabelRequest{}
|
||||
|
||||
if res, err := s.GetDepartmentLabels(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 handleRoleServiceGetRoleLabels(s RoleServiceHttpServer) http.HandleFunc {
|
||||
return func(ctx *http.Context) (err error) {
|
||||
req := &GetRoleLabelRequest{}
|
||||
|
||||
if res, err := s.GetRoleLabels(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 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)
|
||||
} else {
|
||||
return ctx.Error(errors.Unavailable, err.Error())
|
||||
}
|
||||
} else {
|
||||
return ctx.Success(res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func handleAuthServiceLogin(s AuthServiceHttpServer) http.HandleFunc {
|
||||
return func(ctx *http.Context) (err error) {
|
||||
req := &LoginRequest{}
|
||||
|
@ -148,23 +290,61 @@ func handleAuthServiceLogout(s AuthServiceHttpServer) http.HandleFunc {
|
|||
}
|
||||
}
|
||||
|
||||
func RegisterMenuServiceRouter(hs *http.Server, s MenuServiceHttpServer) {
|
||||
func handleSettingServiceGetSetting(s SettingServiceHttpServer) http.HandleFunc {
|
||||
return func(ctx *http.Context) (err error) {
|
||||
req := &GetSettingRequest{}
|
||||
|
||||
if res, err := s.GetSetting(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 RegisterUserServiceRouter(hs *http.Server, s UserServiceHttpServer) {
|
||||
|
||||
// Register handle GetMenus route
|
||||
hs.GET("/api/menu", handleMenuServiceGetMenus(s))
|
||||
hs.GET("/user/menus", handleUserServiceGetMenus(s))
|
||||
|
||||
// Register handle GetProfile route
|
||||
hs.GET("/user/profile", handleUserServiceGetProfile(s))
|
||||
|
||||
// Register handle UpdateProfile route
|
||||
hs.PUT("/user/profile", handleUserServiceUpdateProfile(s))
|
||||
|
||||
// Register handle ResetPassword route
|
||||
hs.POST("/user/reset-password", handleUserServiceResetPassword(s))
|
||||
|
||||
// Register handle GetPermissions route
|
||||
hs.GET("/user/permissions", handleUserServiceGetPermissions(s))
|
||||
|
||||
// Register handle GetUserLabels route
|
||||
hs.GET("/user/labels", handleUserServiceGetUserLabels(s))
|
||||
|
||||
// Register handle GetUserTags route
|
||||
hs.GET("/user/tags", handleUserServiceGetUserTags(s))
|
||||
|
||||
}
|
||||
|
||||
func RegisterProfileServiceRouter(hs *http.Server, s ProfileServiceHttpServer) {
|
||||
func RegisterDepartmentServiceRouter(hs *http.Server, s DepartmentServiceHttpServer) {
|
||||
|
||||
// Register handle GetProfile route
|
||||
hs.GET("/user/profile", handleProfileServiceGetProfile(s))
|
||||
// Register handle GetDepartmentLabels route
|
||||
hs.GET("/department/labels", handleDepartmentServiceGetDepartmentLabels(s))
|
||||
|
||||
// Register handle UpdateProfile route
|
||||
hs.PUT("/user/profile", handleProfileServiceUpdateProfile(s))
|
||||
}
|
||||
|
||||
// Register handle ResetPassword route
|
||||
hs.POST("/user/reset-password", handleProfileServiceResetPassword(s))
|
||||
func RegisterRoleServiceRouter(hs *http.Server, s RoleServiceHttpServer) {
|
||||
|
||||
// Register handle GetRoleLabels route
|
||||
hs.GET("/role/labels", handleRoleServiceGetRoleLabels(s))
|
||||
|
||||
// Register handle GetRolePermissions route
|
||||
hs.GET("/role/permissions", handleRoleServiceGetRolePermissions(s))
|
||||
|
||||
}
|
||||
|
||||
|
@ -177,3 +357,10 @@ func RegisterAuthServiceRouter(hs *http.Server, s AuthServiceHttpServer) {
|
|||
hs.POST("/passport/logout", handleAuthServiceLogout(s))
|
||||
|
||||
}
|
||||
|
||||
func RegisterSettingServiceRouter(hs *http.Server, s SettingServiceHttpServer) {
|
||||
|
||||
// Register handle GetSetting route
|
||||
hs.GET("/system/setting", handleSettingServiceGetSetting(s))
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by protoc-gen-go-aeus. DO NOT EDIT.
|
||||
// source: organize.proto
|
||||
// date: 2025-06-13 11:10:07
|
||||
// date: 2025-06-16 11:37:44
|
||||
|
||||
package pb
|
||||
|
||||
|
@ -9,15 +9,16 @@ import (
|
|||
)
|
||||
|
||||
type MenuModel struct {
|
||||
Id int64 `json:"id" yaml:"id" xml:"id" gorm:"primaryKey"`
|
||||
ParentId int64 `json:"parent_id" yaml:"parentId" xml:"parentId" gorm:"column:parent_id"`
|
||||
Name string `json:"name" yaml:"name" xml:"name" gorm:"index;size:60"`
|
||||
Label string `json:"label" yaml:"label" xml:"label" gorm:"size:120"`
|
||||
Uri string `json:"uri" yaml:"uri" xml:"uri" gorm:"size:512"`
|
||||
ViewPath string `json:"view_path" yaml:"viewPath" xml:"viewPath" gorm:"size:512"`
|
||||
Icon string `json:"icon" yaml:"icon" xml:"icon" gorm:"size:60"`
|
||||
Hidden bool `json:"hidden" yaml:"hidden" xml:"hidden" gorm:"column:hidden"`
|
||||
Public bool `json:"public" yaml:"public" xml:"public" gorm:"column:public"`
|
||||
Id int64 `json:"id" yaml:"id" xml:"id" gorm:"primaryKey" comment:"菜单ID"`
|
||||
ParentId int64 `json:"parent_id" yaml:"parentId" xml:"parentId" comment:"父级菜单"`
|
||||
Name string `json:"name" yaml:"name" xml:"name" gorm:"index;size:60" comment:"组件名称" props:"readonly:update" rule:"required"`
|
||||
Label string `json:"label" yaml:"label" xml:"label" gorm:"size:120" comment:"菜单标题" rule:"required"`
|
||||
Uri string `json:"uri" yaml:"uri" xml:"uri" gorm:"size:512" comment:"菜单链接" scenarios:"create;update;view;export" rule:"required"`
|
||||
ViewPath string `json:"view_path" yaml:"viewPath" xml:"viewPath" gorm:"size:512" comment:"视图路径" scenarios:"create;update;view;export"`
|
||||
Icon string `json:"icon" yaml:"icon" xml:"icon" gorm:"size:60" comment:"菜单图标" scenarios:"create;update;view;export"`
|
||||
Hidden bool `json:"hidden" yaml:"hidden" xml:"hidden" comment:"是否隐藏" scenarios:"create;update;view;export"`
|
||||
Public bool `json:"public" yaml:"public" xml:"public" comment:"是否公开" scenarios:"create;update;view;export"`
|
||||
Description string `json:"description" yaml:"description" xml:"description" gorm:"size:1024" comment:"备注说明" format:"textarea" scenarios:"create;update;view;export;list"`
|
||||
}
|
||||
|
||||
func (m *MenuModel) TableName() string {
|
||||
|
@ -34,6 +35,7 @@ func (m *MenuModel) FromValue(x *Menu) {
|
|||
m.Icon = x.Icon
|
||||
m.Hidden = x.Hidden
|
||||
m.Public = x.Public
|
||||
m.Description = x.Description
|
||||
}
|
||||
|
||||
func (m *MenuModel) ToValue() (x *Menu) {
|
||||
|
@ -47,6 +49,7 @@ func (m *MenuModel) ToValue() (x *Menu) {
|
|||
x.Icon = m.Icon
|
||||
x.Hidden = m.Hidden
|
||||
x.Public = m.Public
|
||||
x.Description = m.Description
|
||||
return x
|
||||
}
|
||||
|
||||
|
@ -67,7 +70,7 @@ func (m *MenuModel) Delete(db *gorm.DB) (err error) {
|
|||
}
|
||||
|
||||
func (m *MenuModel) Find(db *gorm.DB, pk any) (err error) {
|
||||
return db.Where("icon=?", pk).First(m).Error
|
||||
return db.Where("description=?", pk).First(m).Error
|
||||
}
|
||||
|
||||
func (m *MenuModel) FindOne(db *gorm.DB, query any, args ...any) (err error) {
|
||||
|
@ -83,10 +86,10 @@ func NewMenuModel() *MenuModel {
|
|||
}
|
||||
|
||||
type RoleModel struct {
|
||||
Id int64 `json:"id" yaml:"id" xml:"id" gorm:"primaryKey"`
|
||||
Name string `json:"name" yaml:"name" xml:"name" gorm:"index;size:60"`
|
||||
Label string `json:"label" yaml:"label" xml:"label" gorm:"size:60"`
|
||||
Description string `json:"description" yaml:"description" xml:"description" gorm:"size:1024"`
|
||||
Id int64 `json:"id" yaml:"id" xml:"id" gorm:"primaryKey" comment:"角色ID"`
|
||||
Name string `json:"name" yaml:"name" xml:"name" gorm:"index;size:60" comment:"角色名称" props:"readonly:update"`
|
||||
Label string `json:"label" yaml:"label" xml:"label" gorm:"size:60" comment:"角色标题"`
|
||||
Description string `json:"description" yaml:"description" xml:"description" gorm:"size:1024" comment:"备注说明" format:"textarea" scenarios:"list;create;update;export"`
|
||||
}
|
||||
|
||||
func (m *RoleModel) TableName() string {
|
||||
|
@ -142,10 +145,10 @@ func NewRoleModel() *RoleModel {
|
|||
}
|
||||
|
||||
type PermissionModel struct {
|
||||
Id int64 `json:"id" yaml:"id" xml:"id" gorm:"primaryKey"`
|
||||
MenuId int64 `json:"menu_id" yaml:"menuId" xml:"menuId" gorm:"index"`
|
||||
Permission string `json:"permission" yaml:"permission" xml:"permission" gorm:"index;size:60"`
|
||||
Label string `json:"label" yaml:"label" xml:"label" gorm:"size:60"`
|
||||
Id int64 `json:"id" yaml:"id" xml:"id" gorm:"primaryKey" comment:"权限ID"`
|
||||
MenuId int64 `json:"menu_id" yaml:"menuId" xml:"menuId" gorm:"index" comment:"所属菜单" rule:"required"`
|
||||
Permission string `json:"permission" yaml:"permission" xml:"permission" gorm:"index;size:60" comment:"权限名称" rule:"required"`
|
||||
Label string `json:"label" yaml:"label" xml:"label" gorm:"size:60" comment:"权限标题" rule:"required"`
|
||||
}
|
||||
|
||||
func (m *PermissionModel) TableName() string {
|
||||
|
@ -201,9 +204,9 @@ func NewPermissionModel() *PermissionModel {
|
|||
}
|
||||
|
||||
type RolePermissionModel struct {
|
||||
Id int64 `json:"id" yaml:"id" xml:"id" gorm:"primaryKey"`
|
||||
Role string `json:"role" yaml:"role" xml:"role" gorm:"size:60"`
|
||||
PermissionId int64 `json:"permission_id" yaml:"permissionId" xml:"permissionId" gorm:"column:permission_id"`
|
||||
Id int64 `json:"id" yaml:"id" xml:"id" gorm:"primaryKey" comment:"ID"`
|
||||
Role string `json:"role" yaml:"role" xml:"role" gorm:"size:60" comment:"角色名称" rule:"required"`
|
||||
PermissionId int64 `json:"permission_id" yaml:"permissionId" xml:"permissionId" comment:"权限ID" rule:"required"`
|
||||
}
|
||||
|
||||
func (m *RolePermissionModel) TableName() string {
|
||||
|
@ -241,7 +244,7 @@ func (m *RolePermissionModel) Delete(db *gorm.DB) (err error) {
|
|||
}
|
||||
|
||||
func (m *RolePermissionModel) Find(db *gorm.DB, pk any) (err error) {
|
||||
return db.Where("role=?", pk).First(m).Error
|
||||
return db.Where("permission_id=?", pk).First(m).Error
|
||||
}
|
||||
|
||||
func (m *RolePermissionModel) FindOne(db *gorm.DB, query any, args ...any) (err error) {
|
||||
|
@ -257,20 +260,20 @@ func NewRolePermissionModel() *RolePermissionModel {
|
|||
}
|
||||
|
||||
type UserModel struct {
|
||||
Id int64 `json:"id" yaml:"id" xml:"id" gorm:"primaryKey"`
|
||||
CreatedAt int64 `json:"created_at" yaml:"createdAt" xml:"createdAt" gorm:"column:created_at"`
|
||||
UpdatedAt int64 `json:"updated_at" yaml:"updatedAt" xml:"updatedAt" gorm:"column:updated_at"`
|
||||
Uid string `json:"uid" yaml:"uid" xml:"uid" gorm:"index;size:20"`
|
||||
Username string `json:"username" yaml:"username" xml:"username" gorm:"size:20"`
|
||||
Role string `json:"role" yaml:"role" xml:"role" gorm:"size:60"`
|
||||
Admin bool `json:"admin" yaml:"admin" xml:"admin" gorm:"column:admin"`
|
||||
DeptId int64 `json:"dept_id" yaml:"deptId" xml:"deptId" gorm:"not null;default:0"`
|
||||
Tag string `json:"tag" yaml:"tag" xml:"tag" gorm:"size:60"`
|
||||
Password string `json:"password" yaml:"password" xml:"password" gorm:"size:60"`
|
||||
Email string `json:"email" yaml:"email" xml:"email" gorm:"size:60"`
|
||||
Avatar string `json:"avatar" yaml:"avatar" xml:"avatar" gorm:"size:1024"`
|
||||
Gender string `json:"gender" yaml:"gender" xml:"gender" gorm:"size:20;default:man"`
|
||||
Description string `json:"description" yaml:"description" xml:"description" gorm:"size:1024"`
|
||||
Id int64 `json:"id" yaml:"id" xml:"id" gorm:"primaryKey" comment:"ID"`
|
||||
CreatedAt int64 `json:"created_at" yaml:"createdAt" xml:"createdAt" comment:"创建时间" scenarios:"view;export"`
|
||||
UpdatedAt int64 `json:"updated_at" yaml:"updatedAt" xml:"updatedAt" comment:"更新时间" scenarios:"view;export"`
|
||||
Uid string `json:"uid" yaml:"uid" xml:"uid" gorm:"index;size:20" comment:"用户工号" props:"readonly:update" rule:"required;unique;regexp:^[a-zA-Z0-9]{3,8}$"`
|
||||
Username string `json:"username" yaml:"username" xml:"username" gorm:"size:20" comment:"用户名称" rule:"required"`
|
||||
Role string `json:"role" yaml:"role" xml:"role" gorm:"size:60" comment:"所属角色" format:"role" rule:"required"`
|
||||
Admin bool `json:"admin" yaml:"admin" xml:"admin" comment:"管理员" scenarios:"create"`
|
||||
DeptId int64 `json:"dept_id" yaml:"deptId" xml:"deptId" gorm:"not null;default:0" comment:"所属部门" format:"department" rule:"required"`
|
||||
Tag string `json:"tag" yaml:"tag" xml:"tag" gorm:"size:60" comment:"用户标签" scenarios:"list;create;update"`
|
||||
Password string `json:"password" yaml:"password" xml:"password" gorm:"size:60" comment:"用户密码" scenarios:"create" rule:"required"`
|
||||
Email string `json:"email" yaml:"email" xml:"email" gorm:"size:60" comment:"用户邮箱" scenarios:"create;update;view;list;export"`
|
||||
Avatar string `json:"avatar" yaml:"avatar" xml:"avatar" gorm:"size:1024" comment:"用户头像" scenarios:"view"`
|
||||
Gender string `json:"gender" yaml:"gender" xml:"gender" gorm:"size:20;default:man" comment:"用户性别" scenarios:"list;create;update;view;export" rule:"required"`
|
||||
Description string `json:"description" yaml:"description" xml:"description" gorm:"size:1024" comment:"备注说明" format:"textarea" scenarios:"create;update;view;export"`
|
||||
}
|
||||
|
||||
func (m *UserModel) TableName() string {
|
||||
|
@ -346,12 +349,12 @@ func NewUserModel() *UserModel {
|
|||
}
|
||||
|
||||
type DepartmentModel struct {
|
||||
Id int64 `json:"id" yaml:"id" xml:"id" gorm:"primaryKey"`
|
||||
CreatedAt int64 `json:"created_at" yaml:"createdAt" xml:"createdAt" gorm:"column:created_at"`
|
||||
UpdatedAt int64 `json:"updated_at" yaml:"updatedAt" xml:"updatedAt" gorm:"column:updated_at"`
|
||||
ParentId int64 `json:"parent_id" yaml:"parentId" xml:"parentId" gorm:"column:parent_id"`
|
||||
Name string `json:"name" yaml:"name" xml:"name" gorm:"size:20"`
|
||||
Description string `json:"description" yaml:"description" xml:"description" gorm:"size:1024"`
|
||||
Id int64 `json:"id" yaml:"id" xml:"id" gorm:"primaryKey" comment:"ID"`
|
||||
CreatedAt int64 `json:"created_at" yaml:"createdAt" xml:"createdAt" comment:"创建时间" scenarios:"view;export"`
|
||||
UpdatedAt int64 `json:"updated_at" yaml:"updatedAt" xml:"updatedAt" comment:"更新时间" scenarios:"view;export"`
|
||||
ParentId int64 `json:"parent_id" yaml:"parentId" xml:"parentId" comment:"父级部门" format:"department"`
|
||||
Name string `json:"name" yaml:"name" xml:"name" gorm:"size:20" comment:"部门名称" rule:"required"`
|
||||
Description string `json:"description" yaml:"description" xml:"description" gorm:"size:1024" comment:"备注说明" format:"textarea" scenarios:"create;update;view;export;list"`
|
||||
}
|
||||
|
||||
func (m *DepartmentModel) TableName() string {
|
||||
|
@ -409,3 +412,68 @@ func (m *DepartmentModel) FindAll(db *gorm.DB, query any, args ...any) (err erro
|
|||
func NewDepartmentModel() *DepartmentModel {
|
||||
return &DepartmentModel{}
|
||||
}
|
||||
|
||||
type SettingModel struct {
|
||||
Id int64 `json:"id" yaml:"id" xml:"id" gorm:"primaryKey" comment:"ID"`
|
||||
CreatedAt int64 `json:"created_at" yaml:"createdAt" xml:"createdAt" comment:"创建时间" scenarios:"search;view;export"`
|
||||
UpdatedAt int64 `json:"updated_at" yaml:"updatedAt" xml:"updatedAt" comment:"更新时间" scenarios:"search;view;export"`
|
||||
Name string `json:"name" yaml:"name" xml:"name" gorm:"size:60" comment:"配置项" props:"readonly:update" rule:"required"`
|
||||
Value string `json:"value" yaml:"value" xml:"value" gorm:"size:512" comment:"配置值" format:"textarea" rule:"required"`
|
||||
Description string `json:"description" yaml:"description" xml:"description" gorm:"size:1024" comment:"备注说明" format:"textarea" scenarios:"create;update;view;export"`
|
||||
}
|
||||
|
||||
func (m *SettingModel) TableName() string {
|
||||
return "settings"
|
||||
}
|
||||
|
||||
func (m *SettingModel) FromValue(x *Setting) {
|
||||
m.Id = x.Id
|
||||
m.CreatedAt = x.CreatedAt
|
||||
m.UpdatedAt = x.UpdatedAt
|
||||
m.Name = x.Name
|
||||
m.Value = x.Value
|
||||
m.Description = x.Description
|
||||
}
|
||||
|
||||
func (m *SettingModel) ToValue() (x *Setting) {
|
||||
x = &Setting{}
|
||||
x.Id = m.Id
|
||||
x.CreatedAt = m.CreatedAt
|
||||
x.UpdatedAt = m.UpdatedAt
|
||||
x.Name = m.Name
|
||||
x.Value = m.Value
|
||||
x.Description = m.Description
|
||||
return x
|
||||
}
|
||||
|
||||
func (m *SettingModel) Create(db *gorm.DB) (err error) {
|
||||
return db.Create(m).Error
|
||||
}
|
||||
|
||||
func (m *SettingModel) UpdateColumn(db *gorm.DB, column string, value any) (err error) {
|
||||
return db.Model(m).UpdateColumn(column, value).Error
|
||||
}
|
||||
|
||||
func (m *SettingModel) Save(db *gorm.DB) (err error) {
|
||||
return db.Save(m).Error
|
||||
}
|
||||
|
||||
func (m *SettingModel) Delete(db *gorm.DB) (err error) {
|
||||
return db.Delete(m).Error
|
||||
}
|
||||
|
||||
func (m *SettingModel) Find(db *gorm.DB, pk any) (err error) {
|
||||
return db.Where("description=?", pk).First(m).Error
|
||||
}
|
||||
|
||||
func (m *SettingModel) FindOne(db *gorm.DB, query any, args ...any) (err error) {
|
||||
return db.Where(query, args...).First(m).Error
|
||||
}
|
||||
|
||||
func (m *SettingModel) FindAll(db *gorm.DB, query any, args ...any) (err error) {
|
||||
return db.Where(query, args...).Find(m).Error
|
||||
}
|
||||
|
||||
func NewSettingModel() *SettingModel {
|
||||
return &SettingModel{}
|
||||
}
|
||||
|
|
229
server.go
229
server.go
|
@ -2,44 +2,92 @@ package aeusadmin
|
|||
|
||||
import (
|
||||
"context"
|
||||
"html/template"
|
||||
"os"
|
||||
"path"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"git.nobla.cn/golang/aeus-admin/defaults"
|
||||
"git.nobla.cn/golang/aeus-admin/models"
|
||||
adminTypes "git.nobla.cn/golang/aeus-admin/types"
|
||||
"git.nobla.cn/golang/aeus/pkg/errors"
|
||||
"git.nobla.cn/golang/aeus/pkg/pool"
|
||||
"git.nobla.cn/golang/aeus/transport/http"
|
||||
"git.nobla.cn/golang/rest"
|
||||
"git.nobla.cn/golang/rest/inflector"
|
||||
"git.nobla.cn/golang/rest/types"
|
||||
restTypes "git.nobla.cn/golang/rest/types"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// getModels 获取预定义的模型列表
|
||||
func getModels() []any {
|
||||
return []any{
|
||||
&models.User{},
|
||||
&models.Role{},
|
||||
&models.Menu{},
|
||||
&models.Department{},
|
||||
&models.Role{},
|
||||
&models.User{},
|
||||
&models.Menu{},
|
||||
&models.Permission{},
|
||||
&models.RolePermission{},
|
||||
&models.Setting{},
|
||||
}
|
||||
}
|
||||
|
||||
// checkModelMenu 检查模型菜单
|
||||
func checkModelMenu(db *gorm.DB, viewPath string, model *rest.Model, translate Translate) (value *models.Menu, err error) {
|
||||
menuName := inflector.Camelize(model.Naming().ModuleName) + inflector.Camelize(model.Naming().Singular)
|
||||
value = &models.Menu{}
|
||||
if err = db.Where("name = ?", menuName).First(value).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
value.Name = menuName
|
||||
value.ParentId = 0
|
||||
value.ViewPath = path.Join(viewPath, model.ModuleName(), model.Naming().Singular, "Index.vue")
|
||||
value.Label = inflector.Camel2words(model.Naming().Pluralize)
|
||||
if translate != nil {
|
||||
value.Label = translate.Menu(model, value.Label)
|
||||
func checkModelMenu(db *gorm.DB, viewPath string, apiPrefix string, model *rest.Model, translate Translate) (value *models.Menu, err error) {
|
||||
refVal := reflect.New(model.Value().Type()).Interface()
|
||||
if v, ok := refVal.(adminTypes.MenuModel); ok {
|
||||
row := v.GetMenu()
|
||||
value = &models.Menu{}
|
||||
if row.Name == "" {
|
||||
row.Name = inflector.Camelize(model.Naming().ModuleName) + inflector.Camelize(model.Naming().Singular)
|
||||
}
|
||||
if err = db.Where("name = ?", row.Name).First(value).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
if row.Parent != "" {
|
||||
parentModel := &models.Menu{}
|
||||
if err = parentModel.FindOne(db, "name = ?", row.Parent); err == nil {
|
||||
value.ParentId = parentModel.Id
|
||||
}
|
||||
}
|
||||
value.Name = row.Name
|
||||
value.Hidden = row.Hidden
|
||||
value.Icon = row.Icon
|
||||
value.Label = row.Label
|
||||
value.Uri = row.Uri
|
||||
value.ViewPath = row.ViewPath
|
||||
if value.Label == "" {
|
||||
value.Label = inflector.Camel2words(model.Naming().Pluralize)
|
||||
if translate != nil {
|
||||
value.Label = translate.Menu(model, value.Label)
|
||||
}
|
||||
}
|
||||
if value.Uri == "" {
|
||||
value.Uri = strings.TrimPrefix(model.Uri(types.ScenarioList), apiPrefix)
|
||||
}
|
||||
if value.ViewPath == "" {
|
||||
value.ViewPath = path.Join(viewPath, model.ModuleName(), model.Naming().Singular, "Index.vue")
|
||||
}
|
||||
err = db.Create(value).Error
|
||||
}
|
||||
}
|
||||
} else {
|
||||
menuName := inflector.Camelize(model.Naming().ModuleName) + inflector.Camelize(model.Naming().Singular)
|
||||
value = &models.Menu{}
|
||||
if err = db.Where("name = ?", menuName).First(value).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
value.Name = menuName
|
||||
value.ParentId = 0
|
||||
value.Label = inflector.Camel2words(model.Naming().Pluralize)
|
||||
if translate != nil {
|
||||
value.Label = translate.Menu(model, value.Label)
|
||||
}
|
||||
value.Uri = strings.TrimPrefix(model.Uri(types.ScenarioList), apiPrefix)
|
||||
value.ViewPath = path.Join(viewPath, model.ModuleName(), model.Naming().Singular, "Index.vue")
|
||||
err = db.Create(value).Error
|
||||
}
|
||||
value.Uri = model.Uri(types.ScenarioList)
|
||||
err = db.Create(value).Error
|
||||
}
|
||||
}
|
||||
return
|
||||
|
@ -69,7 +117,7 @@ func checkModel(opts *options, model *rest.Model) (err error) {
|
|||
menuModel *models.Menu
|
||||
)
|
||||
tx := opts.db.Begin()
|
||||
if menuModel, err = checkModelMenu(tx, opts.viewPath, model, opts.translate); err != nil {
|
||||
if menuModel, err = checkModelMenu(tx, opts.viewPrefix, opts.apiPrefix, model, opts.translate); err != nil {
|
||||
tx.Rollback()
|
||||
return
|
||||
}
|
||||
|
@ -85,6 +133,44 @@ func checkModel(opts *options, model *rest.Model) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
// generateVueFile 生成Vue文件
|
||||
func generateVueFile(prefix string, apiPrefix string, mv *rest.Model) (err error) {
|
||||
filename := path.Join(prefix, mv.Naming().ModuleName, mv.Naming().Singular, "Index.vue")
|
||||
if _, err = os.Stat(filename); err == nil {
|
||||
return
|
||||
}
|
||||
dirname := path.Dir(filename)
|
||||
if _, err = os.Stat(dirname); err != nil {
|
||||
if err = os.MkdirAll(dirname, os.ModePerm); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
var (
|
||||
temp *template.Template
|
||||
)
|
||||
if temp, err = template.New("vue").Parse(vueTemplate); err != nil {
|
||||
return
|
||||
}
|
||||
permissions := make(map[string]string)
|
||||
for _, s := range defaultScenarios {
|
||||
if mv.HasScenario(s) {
|
||||
permissions[s] = mv.Permission(s)
|
||||
}
|
||||
}
|
||||
data := &vueTemplateData{
|
||||
ModuleName: mv.ModuleName(),
|
||||
TableName: mv.TableName(),
|
||||
Permissions: permissions,
|
||||
ApiPrefix: strings.TrimPrefix(apiPrefix, "/"),
|
||||
}
|
||||
writer := pool.GetBuffer()
|
||||
defer pool.PutBuffer(writer)
|
||||
if err = temp.Execute(writer, data); err != nil {
|
||||
return
|
||||
}
|
||||
return os.WriteFile(filename, writer.Bytes(), 0644)
|
||||
}
|
||||
|
||||
// initREST 初始化REST模块
|
||||
func initREST(ctx context.Context, o *options) (err error) {
|
||||
tx := o.db
|
||||
|
@ -94,6 +180,9 @@ func initREST(ctx context.Context, o *options) (err error) {
|
|||
opts := make([]rest.Option, 0)
|
||||
opts = append(opts, o.restOpts...)
|
||||
opts = append(opts, rest.WithDB(tx))
|
||||
if o.apiPrefix != "" {
|
||||
opts = append(opts, rest.WithUriPrefix(o.apiPrefix))
|
||||
}
|
||||
if err = rest.Init(opts...); err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -104,15 +193,24 @@ func initREST(ctx context.Context, o *options) (err error) {
|
|||
}
|
||||
|
||||
// initRBAC 初始化权限控制, 用于生成角色权限相关的信息
|
||||
func initRBAC(ctx context.Context, o *options) (err error) {
|
||||
func initModels(ctx context.Context, o *options) (err error) {
|
||||
var mv *rest.Model
|
||||
for _, v := range getModels() {
|
||||
if mv, err = rest.AutoMigrate(ctx, v); err != nil {
|
||||
moduleName := o.moduleName
|
||||
if mm, ok := v.(adminTypes.ModuleModel); ok {
|
||||
moduleName = mm.ModuleName()
|
||||
}
|
||||
if mv, err = rest.AutoMigrate(ctx, v, rest.WithModuleName(moduleName)); err != nil {
|
||||
return
|
||||
} else {
|
||||
if err = checkModel(o, mv); err != nil {
|
||||
return
|
||||
}
|
||||
if o.vuePath != "" {
|
||||
if err = generateVueFile(o.vuePath, o.apiPrefix, mv); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
|
@ -124,22 +222,109 @@ func AutoMigrate(ctx context.Context, db *gorm.DB, model any, cbs ...Option) (er
|
|||
mv *rest.Model
|
||||
)
|
||||
opts := newOptions(cbs...)
|
||||
if mv, err = rest.AutoMigrate(ctx, model); err != nil {
|
||||
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 (
|
||||
schemas []*restTypes.Schema
|
||||
)
|
||||
scenario := ctx.Request().URL.Query().Get("scenario")
|
||||
if scenario == "" {
|
||||
schemas, err = rest.GetSchemas(
|
||||
ctx.Request().Context(),
|
||||
db.WithContext(ctx.Request().Context()),
|
||||
"",
|
||||
ctx.Param("module"),
|
||||
ctx.Param("table"),
|
||||
)
|
||||
} else {
|
||||
schemas, err = rest.VisibleSchemas(
|
||||
ctx.Request().Context(),
|
||||
db.WithContext(ctx.Request().Context()),
|
||||
"",
|
||||
ctx.Param("module"),
|
||||
ctx.Param("table"),
|
||||
scenario,
|
||||
)
|
||||
}
|
||||
if err != nil {
|
||||
return ctx.Error(errors.NotFound, err.Error())
|
||||
} else {
|
||||
return ctx.Success(schemas)
|
||||
}
|
||||
}
|
||||
|
||||
handleUpdateSchemas := func(ctx *http.Context) (err error) {
|
||||
schemas := make([]*restTypes.Schema, 0)
|
||||
if err = ctx.Bind(&schemas); err != nil {
|
||||
return ctx.Error(errors.Invalid, err.Error())
|
||||
}
|
||||
for i := range schemas {
|
||||
schemas[i].Domain = domain
|
||||
}
|
||||
if err = db.WithContext(ctx.Request().Context()).Transaction(func(tx *gorm.DB) (errTx error) {
|
||||
for _, row := range schemas {
|
||||
if errTx = tx.Save(row).Error; errTx != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}); err == nil {
|
||||
return ctx.Success(map[string]interface{}{
|
||||
"count": len(schemas),
|
||||
"state": "success",
|
||||
})
|
||||
} else {
|
||||
return ctx.Error(errors.Unavailable, err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
handleDeleteSchema := func(ctx *http.Context) (err error) {
|
||||
id, _ := strconv.Atoi(ctx.Param("id"))
|
||||
model := &restTypes.Schema{Id: uint64(id)}
|
||||
if err = db.WithContext(ctx.Request().Context()).Delete(model).Error; err == nil {
|
||||
return ctx.Success(map[string]any{
|
||||
"id": id,
|
||||
})
|
||||
} 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)
|
||||
|
||||
}
|
||||
|
||||
// Init 初始化模块
|
||||
func Init(ctx context.Context, cbs ...Option) (err error) {
|
||||
opts := newOptions(cbs...)
|
||||
if err = initREST(ctx, opts); err != nil {
|
||||
return
|
||||
}
|
||||
if err = initRBAC(ctx, opts); err != nil {
|
||||
if err = defaults.Menu(opts.db); err != nil {
|
||||
return
|
||||
}
|
||||
if err = initModels(ctx, opts); err != nil {
|
||||
return
|
||||
}
|
||||
if opts.httpServer != nil {
|
||||
registerRESTRoute(opts.domain, opts.db, opts.httpServer)
|
||||
}
|
||||
if err = defaults.Data(opts.db); err != nil {
|
||||
return
|
||||
}
|
||||
err = defaults.Init(opts.db)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"git.nobla.cn/golang/aeus-admin/models"
|
||||
"git.nobla.cn/golang/aeus-admin/pb"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type (
|
||||
departmentOptions struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
DepartmentOption func(o *departmentOptions)
|
||||
|
||||
DepartmentService struct {
|
||||
opts *departmentOptions
|
||||
}
|
||||
)
|
||||
|
||||
func WithDepartmentDB(db *gorm.DB) DepartmentOption {
|
||||
return func(o *departmentOptions) {
|
||||
o.db = db
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DepartmentService) GetDepartmentLabels(ctx context.Context, req *pb.GetDepartmentLabelRequest) (res *pb.GetDepartmentLabelResponse, err error) {
|
||||
values := make([]*models.Department, 0)
|
||||
if err = s.opts.db.WithContext(ctx).Find(&values).Error; err == nil {
|
||||
res = &pb.GetDepartmentLabelResponse{
|
||||
Data: make([]*pb.LabelValue, 0, len(values)),
|
||||
}
|
||||
for _, v := range values {
|
||||
res.Data = append(res.Data, &pb.LabelValue{
|
||||
Label: v.Name,
|
||||
Value: strconv.FormatInt(v.Id, 10),
|
||||
})
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func NewDepartmentService(cbs ...DepartmentOption) *DepartmentService {
|
||||
opts := &departmentOptions{}
|
||||
for _, cb := range cbs {
|
||||
cb(opts)
|
||||
}
|
||||
return &DepartmentService{
|
||||
opts: opts,
|
||||
}
|
||||
}
|
113
service/menu.go
113
service/menu.go
|
@ -1,113 +0,0 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.nobla.cn/golang/aeus-admin/models"
|
||||
"git.nobla.cn/golang/aeus-admin/pb"
|
||||
"git.nobla.cn/golang/aeus-admin/types"
|
||||
"git.nobla.cn/golang/aeus/middleware/auth"
|
||||
"git.nobla.cn/golang/aeus/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type (
|
||||
menuOptions struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
MenuOption func(o *menuOptions)
|
||||
|
||||
MenuService struct {
|
||||
opts *menuOptions
|
||||
}
|
||||
)
|
||||
|
||||
func WithMenuDB(db *gorm.DB) MenuOption {
|
||||
return func(o *menuOptions) {
|
||||
o.db = db
|
||||
}
|
||||
}
|
||||
|
||||
func (s *MenuService) hasPermission(menuID int64, permissions []*models.Permission) bool {
|
||||
for _, permission := range permissions {
|
||||
if permission.MenuId == menuID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *MenuService) getPermissions(menuID int64, permissions []*models.Permission) []*pb.PermissionItem {
|
||||
ss := make([]*pb.PermissionItem, 0, 10)
|
||||
for _, permission := range permissions {
|
||||
if permission.MenuId == menuID {
|
||||
ss = append(ss, &pb.PermissionItem{
|
||||
Value: permission.Permission,
|
||||
Label: permission.Label,
|
||||
})
|
||||
}
|
||||
}
|
||||
return ss
|
||||
}
|
||||
|
||||
func (s *MenuService) recursiveNestedMenu(ctx context.Context, parent int64, perm bool, menus []*models.Menu, permissions []*models.Permission) []*pb.MenuItem {
|
||||
values := make([]*pb.MenuItem, 0)
|
||||
for _, row := range menus {
|
||||
if row.ParentId == parent {
|
||||
if !row.Public && !s.hasPermission(row.Id, permissions) {
|
||||
continue
|
||||
}
|
||||
v := &pb.MenuItem{
|
||||
Label: row.Label,
|
||||
Name: row.Name,
|
||||
Icon: row.Icon,
|
||||
Hidden: row.Hidden,
|
||||
Route: row.Uri,
|
||||
Children: s.recursiveNestedMenu(ctx, row.Id, perm, menus, permissions),
|
||||
}
|
||||
if perm {
|
||||
v.Permissions = s.getPermissions(row.Id, permissions)
|
||||
}
|
||||
values = append(values, v)
|
||||
}
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
||||
func (s *MenuService) GetRolePermissions(ctx context.Context, db *gorm.DB, role string) (permissions []*models.Permission, err error) {
|
||||
permissions = make([]*models.Permission, 0)
|
||||
err = db.Where("id IN (SELECT permission_id FROM role_permissions WHERE role = ?)", role).Find(&permissions).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (s *MenuService) GetMenus(ctx context.Context, req *pb.GetMenuRequest) (res *pb.GetMenuResponse, err error) {
|
||||
claims, ok := auth.FromContext(ctx)
|
||||
if !ok {
|
||||
return nil, errors.ErrAccessDenied
|
||||
}
|
||||
var (
|
||||
permissions []*models.Permission
|
||||
)
|
||||
tx := s.opts.db.WithContext(ctx)
|
||||
if claims, ok := claims.(*types.Claims); ok {
|
||||
permissions, err = s.GetRolePermissions(ctx, tx, claims.Role)
|
||||
}
|
||||
values := make([]*models.Menu, 0)
|
||||
if err = tx.Find(&values).Error; err != nil {
|
||||
return
|
||||
}
|
||||
res = &pb.GetMenuResponse{
|
||||
Data: s.recursiveNestedMenu(ctx, 0, req.Permission, values, permissions),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func NewMenuService(cbs ...MenuOption) *MenuService {
|
||||
opts := &menuOptions{}
|
||||
for _, cb := range cbs {
|
||||
cb(opts)
|
||||
}
|
||||
return &MenuService{
|
||||
opts: opts,
|
||||
}
|
||||
}
|
|
@ -1,113 +0,0 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.nobla.cn/golang/aeus-admin/models"
|
||||
"git.nobla.cn/golang/aeus-admin/pb"
|
||||
"git.nobla.cn/golang/aeus/middleware/auth"
|
||||
"git.nobla.cn/golang/aeus/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type (
|
||||
profileOptions struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
ProfileOption func(o *profileOptions)
|
||||
|
||||
ProfileService struct {
|
||||
opts *profileOptions
|
||||
}
|
||||
)
|
||||
|
||||
func WithProfileDB(db *gorm.DB) ProfileOption {
|
||||
return func(o *profileOptions) {
|
||||
o.db = db
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ProfileService) getUidFromContext(ctx context.Context) (string, error) {
|
||||
if claims, ok := auth.FromContext(ctx); !ok {
|
||||
return "", errors.ErrAccessDenied
|
||||
} else {
|
||||
return claims.GetSubject()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ProfileService) GetProfile(ctx context.Context, req *pb.GetProfileRequest) (res *pb.GetProfileResponse, err error) {
|
||||
if req.Uid == "" {
|
||||
if req.Uid, err = s.getUidFromContext(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
res = &pb.GetProfileResponse{}
|
||||
tx := s.opts.db.WithContext(ctx)
|
||||
err = tx.Table("users AS u").Select("u.uid as uid", "u.username", "u.avatar", "u.email", "u.description", "u.role_id as role").Where("u.uid=? ", req.Uid).First(res).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (s *ProfileService) UpdateProfile(ctx context.Context, req *pb.UpdateProfileRequest) (res *pb.UpdateProfileResponse, err error) {
|
||||
if req.Uid == "" {
|
||||
if req.Uid, err = s.getUidFromContext(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
userModel := &models.User{}
|
||||
tx := s.opts.db.WithContext(ctx)
|
||||
if err = tx.Where("uid=?", req.Uid).First(userModel).Error; err != nil {
|
||||
return
|
||||
}
|
||||
if req.Avatar != "" {
|
||||
userModel.Avatar = req.Avatar
|
||||
}
|
||||
if req.Email != "" {
|
||||
userModel.Email = req.Email
|
||||
}
|
||||
if req.Username != "" {
|
||||
userModel.Username = req.Username
|
||||
}
|
||||
if req.Description != "" {
|
||||
userModel.Description = req.Description
|
||||
}
|
||||
if err = tx.Save(userModel).Error; err == nil {
|
||||
res = &pb.UpdateProfileResponse{
|
||||
Uid: userModel.Uid,
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *ProfileService) ResetPassword(ctx context.Context, req *pb.ResetPasswordRequest) (res *pb.ResetPasswordResponse, err error) {
|
||||
if req.Uid == "" {
|
||||
if req.Uid, err = s.getUidFromContext(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
userModel := &models.User{}
|
||||
tx := s.opts.db.WithContext(ctx)
|
||||
if err = tx.Where("uid=?", req.Uid).First(userModel).Error; err != nil {
|
||||
return
|
||||
}
|
||||
if userModel.Password == req.OldPassword {
|
||||
if err = tx.Where("uid=?", req.Uid).Model(&models.User{}).UpdateColumn("password", req.NewPassword).Error; err == nil {
|
||||
res = &pb.ResetPasswordResponse{
|
||||
Uid: userModel.Uid,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err = errors.Format(errors.AccessDenied, "invalid old password")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func NewProfileService(cbs ...ProfileOption) *ProfileService {
|
||||
opts := &profileOptions{}
|
||||
for _, cb := range cbs {
|
||||
cb(opts)
|
||||
}
|
||||
return &ProfileService{
|
||||
opts: opts,
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.nobla.cn/golang/aeus-admin/models"
|
||||
"git.nobla.cn/golang/aeus-admin/pb"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type (
|
||||
roleOptions struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
RoleOption func(o *roleOptions)
|
||||
|
||||
RoleService struct {
|
||||
opts *roleOptions
|
||||
}
|
||||
)
|
||||
|
||||
func WithRoleDB(db *gorm.DB) RoleOption {
|
||||
return func(o *roleOptions) {
|
||||
o.db = db
|
||||
}
|
||||
}
|
||||
|
||||
func (s *RoleService) GetRoleLabels(ctx context.Context, req *pb.GetRoleLabelRequest) (res *pb.GetRoleLabelResponse, err error) {
|
||||
values := make([]*models.Role, 0)
|
||||
if err = s.opts.db.WithContext(ctx).Find(&values).Error; err == nil {
|
||||
res = &pb.GetRoleLabelResponse{
|
||||
Data: make([]*pb.LabelValue, 0, len(values)),
|
||||
}
|
||||
for _, v := range values {
|
||||
res.Data = append(res.Data, &pb.LabelValue{
|
||||
Label: v.Label,
|
||||
Value: v.Name,
|
||||
})
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *RoleService) GetRolePermissions(ctx context.Context, req *pb.GetRolePermissionRequest) (res *pb.GetRolePermissionResponse, err error) {
|
||||
permissions := make([]*models.Permission, 0)
|
||||
if err = s.opts.db.WithContext(ctx).Where("id IN (SELECT permission_id FROM role_permissions WHERE role = ?)", req.Role).Find(&permissions).Error; err != nil {
|
||||
return
|
||||
}
|
||||
res = &pb.GetRolePermissionResponse{
|
||||
Role: req.Role,
|
||||
Permissions: make([]string, 0, len(permissions)),
|
||||
}
|
||||
for _, permission := range permissions {
|
||||
res.Permissions = append(res.Permissions, permission.Permission)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func NewRoleService(cbs ...RoleOption) *RoleService {
|
||||
opts := &roleOptions{}
|
||||
for _, cb := range cbs {
|
||||
cb(opts)
|
||||
}
|
||||
return &RoleService{
|
||||
opts: opts,
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.nobla.cn/golang/aeus-admin/models"
|
||||
"git.nobla.cn/golang/aeus-admin/pb"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type (
|
||||
settingOptions struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
SettingOption func(o *settingOptions)
|
||||
)
|
||||
type SettingService struct {
|
||||
opts *settingOptions
|
||||
}
|
||||
|
||||
func (s *SettingService) GetSetting(ctx context.Context, req *pb.GetSettingRequest) (res *pb.GetSettingResponse, err error) {
|
||||
tx := s.opts.db.WithContext(ctx)
|
||||
values := make([]*models.Setting, 0)
|
||||
if err = tx.Find(&values).Error; err != nil {
|
||||
return
|
||||
}
|
||||
res = &pb.GetSettingResponse{
|
||||
Data: make([]*pb.SettingItem, 0, len(values)),
|
||||
}
|
||||
for _, v := range values {
|
||||
res.Data = append(res.Data, &pb.SettingItem{
|
||||
Name: v.Name,
|
||||
Value: v.Value,
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
func NewSettingService(cbs ...SettingOption) *SettingService {
|
||||
opts := &settingOptions{}
|
||||
for _, cb := range cbs {
|
||||
cb(opts)
|
||||
}
|
||||
return &SettingService{}
|
||||
}
|
|
@ -0,0 +1,244 @@
|
|||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.nobla.cn/golang/aeus-admin/models"
|
||||
"git.nobla.cn/golang/aeus-admin/pb"
|
||||
"git.nobla.cn/golang/aeus-admin/types"
|
||||
"git.nobla.cn/golang/aeus/middleware/auth"
|
||||
"git.nobla.cn/golang/aeus/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type (
|
||||
userOptions struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
UserOption func(o *userOptions)
|
||||
|
||||
UserService struct {
|
||||
opts *userOptions
|
||||
}
|
||||
)
|
||||
|
||||
func WithUserDB(db *gorm.DB) UserOption {
|
||||
return func(o *userOptions) {
|
||||
o.db = db
|
||||
}
|
||||
}
|
||||
|
||||
func (s *UserService) getUidFromContext(ctx context.Context) (string, error) {
|
||||
if claims, ok := auth.FromContext(ctx); !ok {
|
||||
return "", errors.ErrAccessDenied
|
||||
} else {
|
||||
return claims.GetSubject()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *UserService) hasPermission(menuID int64, permissions []*models.Permission) bool {
|
||||
for _, permission := range permissions {
|
||||
if permission.MenuId == menuID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *UserService) getPermissions(menuID int64, permissions []*models.Permission) []*pb.PermissionItem {
|
||||
ss := make([]*pb.PermissionItem, 0, 10)
|
||||
for _, permission := range permissions {
|
||||
if permission.MenuId == menuID {
|
||||
ss = append(ss, &pb.PermissionItem{
|
||||
Value: permission.Permission,
|
||||
Label: permission.Label,
|
||||
})
|
||||
}
|
||||
}
|
||||
return ss
|
||||
}
|
||||
|
||||
func (s *UserService) recursiveNestedMenu(ctx context.Context, parent int64, perm bool, menus []*models.Menu, permissions []*models.Permission) []*pb.MenuItem {
|
||||
values := make([]*pb.MenuItem, 0)
|
||||
for _, row := range menus {
|
||||
if row.ParentId == parent {
|
||||
if !row.Public && !s.hasPermission(row.Id, permissions) {
|
||||
continue
|
||||
}
|
||||
v := &pb.MenuItem{
|
||||
Label: row.Label,
|
||||
Name: row.Name,
|
||||
Icon: row.Icon,
|
||||
Hidden: row.Hidden,
|
||||
Route: row.Uri,
|
||||
Public: row.Public,
|
||||
View: row.ViewPath,
|
||||
Children: s.recursiveNestedMenu(ctx, row.Id, perm, menus, permissions),
|
||||
}
|
||||
if perm {
|
||||
v.Permissions = s.getPermissions(row.Id, permissions)
|
||||
}
|
||||
values = append(values, v)
|
||||
}
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
||||
func (s *UserService) getRolePermissions(ctx context.Context, db *gorm.DB, role string) (permissions []*models.Permission, err error) {
|
||||
permissions = make([]*models.Permission, 0)
|
||||
err = db.Where("id IN (SELECT permission_id FROM role_permissions WHERE role = ?)", role).Find(&permissions).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (s *UserService) GetMenus(ctx context.Context, req *pb.GetMenuRequest) (res *pb.GetMenuResponse, err error) {
|
||||
claims, ok := auth.FromContext(ctx)
|
||||
if !ok {
|
||||
return nil, errors.ErrAccessDenied
|
||||
}
|
||||
var (
|
||||
permissions []*models.Permission
|
||||
)
|
||||
tx := s.opts.db.WithContext(ctx)
|
||||
if claims, ok := claims.(*types.Claims); ok {
|
||||
permissions, err = s.GetRolePermissions(ctx, tx, claims.Role)
|
||||
}
|
||||
values := make([]*models.Menu, 0)
|
||||
if err = tx.Find(&values).Error; err != nil {
|
||||
return
|
||||
}
|
||||
res = &pb.GetMenuResponse{
|
||||
Data: s.recursiveNestedMenu(ctx, 0, req.Permission, values, permissions),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *UserService) GetProfile(ctx context.Context, req *pb.GetProfileRequest) (res *pb.GetProfileResponse, err error) {
|
||||
if req.Uid == "" {
|
||||
if req.Uid, err = s.getUidFromContext(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
res = &pb.GetProfileResponse{}
|
||||
tx := s.opts.db.WithContext(ctx)
|
||||
err = tx.Table("users AS u").
|
||||
Select("u.uid as uid", "u.username", "u.avatar", "u.email", "u.description", "u.role", "u.admin").
|
||||
Where("u.uid=? ", req.Uid).
|
||||
First(res).Error
|
||||
return
|
||||
}
|
||||
|
||||
func (s *UserService) UpdateProfile(ctx context.Context, req *pb.UpdateProfileRequest) (res *pb.UpdateProfileResponse, err error) {
|
||||
if req.Uid == "" {
|
||||
if req.Uid, err = s.getUidFromContext(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
userModel := &models.User{}
|
||||
tx := s.opts.db.WithContext(ctx)
|
||||
if err = tx.Where("uid=?", req.Uid).First(userModel).Error; err != nil {
|
||||
return
|
||||
}
|
||||
if req.Avatar != "" {
|
||||
userModel.Avatar = req.Avatar
|
||||
}
|
||||
if req.Email != "" {
|
||||
userModel.Email = req.Email
|
||||
}
|
||||
if req.Username != "" {
|
||||
userModel.Username = req.Username
|
||||
}
|
||||
if req.Description != "" {
|
||||
userModel.Description = req.Description
|
||||
}
|
||||
if err = tx.Save(userModel).Error; err == nil {
|
||||
res = &pb.UpdateProfileResponse{
|
||||
Uid: userModel.Uid,
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *UserService) ResetPassword(ctx context.Context, req *pb.ResetPasswordRequest) (res *pb.ResetPasswordResponse, err error) {
|
||||
if req.Uid == "" {
|
||||
if req.Uid, err = s.getUidFromContext(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
userModel := &models.User{}
|
||||
tx := s.opts.db.WithContext(ctx)
|
||||
if err = tx.Where("uid=?", req.Uid).First(userModel).Error; err != nil {
|
||||
return
|
||||
}
|
||||
if userModel.Password == req.OldPassword {
|
||||
if err = tx.Where("uid=?", req.Uid).Model(&models.User{}).UpdateColumn("password", req.NewPassword).Error; err == nil {
|
||||
res = &pb.ResetPasswordResponse{
|
||||
Uid: userModel.Uid,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err = errors.Format(errors.AccessDenied, "invalid old password")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *UserService) GetPermissions(ctx context.Context, req *pb.GetPermissionRequest) (res *pb.GetPermissionResponse, err error) {
|
||||
if req.Uid == "" {
|
||||
if req.Uid, err = s.getUidFromContext(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
userModel := &models.User{}
|
||||
tx := s.opts.db.WithContext(ctx)
|
||||
if err = userModel.FindOne(tx, "uid=?", req.Uid); err != nil {
|
||||
return
|
||||
}
|
||||
var permissions []string
|
||||
tx.Select("permission").Where("id IN (SELECT permission_id FROM role_permissions WHERE role =?)", userModel.Role).Model(&models.Permission{}).Pluck("permission", &permissions)
|
||||
res = &pb.GetPermissionResponse{
|
||||
Uid: userModel.Uid,
|
||||
Permissions: permissions,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *UserService) GetUserLabels(ctx context.Context, req *pb.GetUserLabelRequest) (res *pb.GetUserLabelResponse, err error) {
|
||||
values := make([]*models.User, 0)
|
||||
if err = s.opts.db.WithContext(ctx).Find(&values).Error; err == nil {
|
||||
res = &pb.GetUserLabelResponse{
|
||||
Data: make([]*pb.LabelValue, 0, len(values)),
|
||||
}
|
||||
for _, v := range values {
|
||||
res.Data = append(res.Data, &pb.LabelValue{
|
||||
Label: v.Username,
|
||||
Value: v.Uid,
|
||||
})
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *UserService) GetUserTags(ctx context.Context, req *pb.GetUserTagRequest) (res *pb.GetUserTagResponse, err error) {
|
||||
values := make([]*models.User, 0)
|
||||
if err = s.opts.db.WithContext(ctx).Select("DISTINCT(`tag`) AS `tag`").Find(&values).Error; err == nil {
|
||||
res = &pb.GetUserTagResponse{
|
||||
Data: make([]*pb.LabelValue, 0, len(values)),
|
||||
}
|
||||
for _, v := range values {
|
||||
res.Data = append(res.Data, &pb.LabelValue{
|
||||
Label: v.Tag,
|
||||
Value: v.Tag,
|
||||
})
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func NewUserService(cbs ...UserOption) *UserService {
|
||||
opts := &userOptions{}
|
||||
for _, cb := range cbs {
|
||||
cb(opts)
|
||||
}
|
||||
return &UserService{
|
||||
opts: opts,
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package aeusadmin
|
||||
|
||||
var (
|
||||
vueTemplate = `
|
||||
<template>
|
||||
<viewer
|
||||
:title="title"
|
||||
:module-name="moduleName"
|
||||
:table-name="tableName"
|
||||
:apiPrefix="apiPrefix"
|
||||
:permissions="permissions"
|
||||
:disable-toolbar="false"
|
||||
default-sortable="id"
|
||||
>
|
||||
</viewer>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import Viewer from '@/components/fragment/Viewer.vue';
|
||||
import { computed } from 'vue';
|
||||
|
||||
const props = defineProps({
|
||||
title: {
|
||||
type: String,
|
||||
}
|
||||
})
|
||||
|
||||
const permissions = computed(() => {
|
||||
return {
|
||||
{{range $key, $value := .Permissions}}{{$key}}: "{{$value}}",
|
||||
{{end}}
|
||||
}
|
||||
})
|
||||
|
||||
const apiPrefix = computed(() => {
|
||||
return '{{.ApiPrefix}}'
|
||||
})
|
||||
|
||||
const moduleName = computed(() => {
|
||||
return '{{.ModuleName}}'
|
||||
})
|
||||
|
||||
const tableName = computed(() => {
|
||||
return '{{.TableName}}'
|
||||
})
|
||||
|
||||
</script>
|
||||
`
|
||||
)
|
48
types.go
48
types.go
|
@ -1,6 +1,7 @@
|
|||
package aeusadmin
|
||||
|
||||
import (
|
||||
"git.nobla.cn/golang/aeus/transport/http"
|
||||
"git.nobla.cn/golang/rest"
|
||||
"git.nobla.cn/golang/rest/types"
|
||||
"gorm.io/gorm"
|
||||
|
@ -21,9 +22,13 @@ var (
|
|||
type (
|
||||
options struct {
|
||||
db *gorm.DB
|
||||
domain string
|
||||
moduleName string
|
||||
viewPath string
|
||||
apiPrefix string //接口前缀
|
||||
viewPrefix string //生成菜单View的前缀路径
|
||||
vuePath string //生成Vue文件的路径,如果指定了启动的时候会自动生成Vue的文件
|
||||
translate Translate
|
||||
httpServer *http.Server
|
||||
restOpts []rest.Option
|
||||
}
|
||||
|
||||
|
@ -33,6 +38,21 @@ type (
|
|||
Menu(model *rest.Model, label string) string
|
||||
Permission(model *rest.Model, scene string, label string) string
|
||||
}
|
||||
|
||||
MenuBuild interface {
|
||||
Label(model *rest.Model) string
|
||||
Title(model *rest.Model) string
|
||||
Icon(model *rest.Model) string
|
||||
Uri(model *rest.Model) string
|
||||
ViewPath(model *rest.Model) string
|
||||
}
|
||||
|
||||
vueTemplateData struct {
|
||||
ModuleName string
|
||||
TableName string
|
||||
ApiPrefix string
|
||||
Permissions map[string]string
|
||||
}
|
||||
)
|
||||
|
||||
func WithDB(db *gorm.DB) Option {
|
||||
|
@ -41,15 +61,27 @@ func WithDB(db *gorm.DB) Option {
|
|||
}
|
||||
}
|
||||
|
||||
func WithHttpServer(server *http.Server) Option {
|
||||
return func(o *options) {
|
||||
o.httpServer = server
|
||||
}
|
||||
}
|
||||
|
||||
func WithApiPrefix(apiPrefix string) Option {
|
||||
return func(o *options) {
|
||||
o.apiPrefix = apiPrefix
|
||||
}
|
||||
}
|
||||
|
||||
func WithModuleName(moduleName string) Option {
|
||||
return func(o *options) {
|
||||
o.moduleName = moduleName
|
||||
}
|
||||
}
|
||||
|
||||
func WithViewPath(viewPath string) Option {
|
||||
func WithViewPrefix(viewPath string) Option {
|
||||
return func(o *options) {
|
||||
o.viewPath = viewPath
|
||||
o.viewPrefix = viewPath
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,9 +97,17 @@ func WithRestOptions(opts ...rest.Option) Option {
|
|||
}
|
||||
}
|
||||
|
||||
func WithVuePath(path string) Option {
|
||||
return func(o *options) {
|
||||
o.vuePath = path
|
||||
}
|
||||
}
|
||||
|
||||
func newOptions(opts ...Option) *options {
|
||||
o := &options{
|
||||
viewPath: "views",
|
||||
viewPrefix: "views",
|
||||
moduleName: "organize",
|
||||
domain: "localhost",
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(o)
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package types
|
||||
|
||||
type Menu struct {
|
||||
Parent string `json:"parent"`
|
||||
Name string `json:"name"`
|
||||
Label string `json:"label"`
|
||||
Uri string `json:"uri"`
|
||||
ViewPath string `json:"view_path"`
|
||||
Icon string `json:"icon"`
|
||||
Hidden bool `json:"hidden"`
|
||||
}
|
||||
|
||||
type MenuModel interface {
|
||||
GetMenu() *Menu
|
||||
}
|
||||
|
||||
type ModuleModel interface {
|
||||
ModuleName() string
|
||||
}
|
Loading…
Reference in New Issue