feat:完善项目信息
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
||||
"SciencesServer/app/common/model"
|
||||
"SciencesServer/serve/orm"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type SysAuth struct {
|
||||
@ -12,20 +13,25 @@ type SysAuth struct {
|
||||
|
||||
// SysAuthScene 信息
|
||||
type SysAuthScene struct {
|
||||
*model.SysAuth
|
||||
SceneID uint64 `json:"scene_id"`
|
||||
model.Model
|
||||
ParentID uint64 `json:"parent_id"`
|
||||
Kind model.SysAuthKind `json:"kind"`
|
||||
Name string `json:"name"`
|
||||
SceneID uint64 `json:"scene_id"`
|
||||
}
|
||||
|
||||
func (m *SysAuth) FilterAuth() string {
|
||||
return "/" + strings.ReplaceAll(m.Auth, ":", "/")
|
||||
}
|
||||
|
||||
// TenantAuth 租户权限
|
||||
func (m *SysAuth) TenantAuth(tenantID uint64) ([]*SysAuthScene, error) {
|
||||
mSysTenantAuth := NewSysTenantAuth()
|
||||
|
||||
out := make([]*SysAuthScene, 0)
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()+" AS a").
|
||||
Select("a.*, r_a.id AS scene_id").
|
||||
Select("a.id", "a.parent_id", "a.kind", "a.name", "r_a.id AS scene_id").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS t_a ON t_a.auth_id = a.id AND t_a.tenant_id = %d AND t_a.is_deleted = %d",
|
||||
mSysTenantAuth.TableName(), tenantID, model.DeleteStatusForNot)).
|
||||
model.NewSysTenantAuth().TableName(), tenantID, model.DeleteStatusForNot)).
|
||||
Where("a.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if err := db.Scan(&out).Error; err != nil {
|
||||
@ -36,21 +42,18 @@ func (m *SysAuth) TenantAuth(tenantID uint64) ([]*SysAuthScene, error) {
|
||||
|
||||
// RoleAuth 角色权限
|
||||
func (m *SysAuth) RoleAuth(tenantID, roleID uint64) ([]*SysAuthScene, error) {
|
||||
mSysTenantAuth := NewSysTenantAuth()
|
||||
|
||||
mSysRoleAuth := NewSysRoleAuth()
|
||||
|
||||
out := make([]*SysAuthScene, 0)
|
||||
|
||||
db := orm.GetDB().Table(m.TableName()+" AS a").
|
||||
Select("a.*, r_a.id AS scene_id").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS t_a ON t_a.auth_id = a.id AND t_a.tenant_id = %d AND t_a.is_deleted = %d",
|
||||
mSysTenantAuth.TableName(), tenantID, model.DeleteStatusForNot)).
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS r_a ON r_a.auth_id = a.id AND r_a.role_id = %d AND r_a.is_deleted = %d",
|
||||
mSysRoleAuth.TableName(), roleID, model.DeleteStatusForNot)).
|
||||
Where("a.is_deleted = ?", model.DeleteStatusForNot).
|
||||
Where("t_a.id > ?", 0)
|
||||
Select("a.id", "a.parent_id", "a.kind", "a.name", "r_a.id AS scene_id").
|
||||
Joins(fmt.Sprintf("LEFT JOIN %s AS r_a ON a.id = r_a.auth_id AND r_a.role_id = %d AND r_a.is_deleted = %d",
|
||||
model.NewSysRoleAuth().TableName(), roleID, model.DeleteStatusForNot)).
|
||||
Where("a.is_deleted = ?", model.DeleteStatusForNot)
|
||||
|
||||
if tenantID > 0 {
|
||||
db = db.Joins(fmt.Sprintf("RIGHT JOIN %s AS t_a ON a.id = t_a.auth_id AND t_a.tenant_id = %d AND t_a.is_deleted = %d",
|
||||
model.NewSysTenantAuth().TableName(), tenantID, model.DeleteStatusForNot))
|
||||
}
|
||||
if err := db.Scan(&out).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user