|
|
|
@ -52,10 +52,10 @@ func (r *FrontendBackendRouteRepository) FindByModule(module string) ([]*model.F
@@ -52,10 +52,10 @@ func (r *FrontendBackendRouteRepository) FindByModule(module string) ([]*model.F
|
|
|
|
|
return relations, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// FindByAuthGroup 根据权限分组查找关系
|
|
|
|
|
func (r *FrontendBackendRouteRepository) FindByAuthGroup(authGroup string) ([]*model.FrontendBackendRoute, error) { |
|
|
|
|
// FindByComponent 根据组件名称查找关系
|
|
|
|
|
func (r *FrontendBackendRouteRepository) FindByComponent(component string) ([]*model.FrontendBackendRoute, error) { |
|
|
|
|
var relations []*model.FrontendBackendRoute |
|
|
|
|
err := r.db.Where("auth_group = ?", authGroup).Order("sort ASC").Find(&relations).Error |
|
|
|
|
err := r.db.Where("component = ?", component).Order("sort ASC").Find(&relations).Error |
|
|
|
|
return relations, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -86,15 +86,14 @@ func (r *FrontendBackendRouteRepository) Upsert(relation *model.FrontendBackendR
@@ -86,15 +86,14 @@ func (r *FrontendBackendRouteRepository) Upsert(relation *model.FrontendBackendR
|
|
|
|
|
// 使用 PostgreSQL 的 ON CONFLICT 语法处理唯一索引冲突
|
|
|
|
|
sql := ` |
|
|
|
|
INSERT INTO frontend_backend_routes
|
|
|
|
|
(frontend_route_id, backend_route, http_method, auth_group, module, description, is_default, sort, status, updated_at) |
|
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, NOW()) |
|
|
|
|
(frontend_route_id, backend_route, http_method, component, module, description, sort, status, updated_at) |
|
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, NOW()) |
|
|
|
|
ON CONFLICT (frontend_route_id, backend_route)
|
|
|
|
|
DO UPDATE SET |
|
|
|
|
http_method = EXCLUDED.http_method, |
|
|
|
|
auth_group = EXCLUDED.auth_group, |
|
|
|
|
component = EXCLUDED.component, |
|
|
|
|
module = EXCLUDED.module, |
|
|
|
|
description = EXCLUDED.description, |
|
|
|
|
is_default = EXCLUDED.is_default, |
|
|
|
|
sort = EXCLUDED.sort, |
|
|
|
|
status = EXCLUDED.status, |
|
|
|
|
updated_at = NOW() |
|
|
|
@ -106,10 +105,9 @@ func (r *FrontendBackendRouteRepository) Upsert(relation *model.FrontendBackendR
@@ -106,10 +105,9 @@ func (r *FrontendBackendRouteRepository) Upsert(relation *model.FrontendBackendR
|
|
|
|
|
relation.FrontendRouteID, |
|
|
|
|
relation.BackendRoute, |
|
|
|
|
relation.HTTPMethod, |
|
|
|
|
relation.AuthGroup, |
|
|
|
|
relation.Component, |
|
|
|
|
relation.Module, |
|
|
|
|
relation.Description, |
|
|
|
|
relation.IsDefault, |
|
|
|
|
relation.Sort, |
|
|
|
|
relation.Status, |
|
|
|
|
).Scan(&id).Error |
|
|
|
@ -126,8 +124,8 @@ func (r *FrontendBackendRouteRepository) Upsert(relation *model.FrontendBackendR
@@ -126,8 +124,8 @@ func (r *FrontendBackendRouteRepository) Upsert(relation *model.FrontendBackendR
|
|
|
|
|
// GetStats 获取前后台路由关系统计信息
|
|
|
|
|
func (r *FrontendBackendRouteRepository) GetStats() (map[string]interface{}, error) { |
|
|
|
|
var total int64 |
|
|
|
|
var authGroupStats []struct { |
|
|
|
|
AuthGroup string `json:"auth_group"` |
|
|
|
|
var componentStats []struct { |
|
|
|
|
Component string `json:"component"` |
|
|
|
|
Count int64 `json:"count"` |
|
|
|
|
} |
|
|
|
|
var moduleStats []struct { |
|
|
|
@ -140,9 +138,9 @@ func (r *FrontendBackendRouteRepository) GetStats() (map[string]interface{}, err
@@ -140,9 +138,9 @@ func (r *FrontendBackendRouteRepository) GetStats() (map[string]interface{}, err
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if err := r.db.Model(&model.FrontendBackendRoute{}). |
|
|
|
|
Select("auth_group, count(*) as count"). |
|
|
|
|
Group("auth_group"). |
|
|
|
|
Scan(&authGroupStats).Error; err != nil { |
|
|
|
|
Select("component, count(*) as count"). |
|
|
|
|
Group("component"). |
|
|
|
|
Scan(&componentStats).Error; err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -155,7 +153,7 @@ func (r *FrontendBackendRouteRepository) GetStats() (map[string]interface{}, err
@@ -155,7 +153,7 @@ func (r *FrontendBackendRouteRepository) GetStats() (map[string]interface{}, err
|
|
|
|
|
|
|
|
|
|
return map[string]interface{}{ |
|
|
|
|
"total": total, |
|
|
|
|
"auth_group_stats": authGroupStats, |
|
|
|
|
"component_stats": componentStats, |
|
|
|
|
"module_stats": moduleStats, |
|
|
|
|
}, nil |
|
|
|
|
} |
|
|
|
|