63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
package model
|
|
|
|
import (
|
|
"SciencesServer/app/common/model"
|
|
"SciencesServer/serve/orm"
|
|
"fmt"
|
|
)
|
|
|
|
type SysAuth struct {
|
|
*model.SysAuth
|
|
}
|
|
|
|
// SysAuthScene 信息
|
|
type SysAuthScene struct {
|
|
*model.SysAuth
|
|
SceneID uint64 `json:"scene_id"`
|
|
}
|
|
|
|
// 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").
|
|
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)).
|
|
Where("a.is_deleted = ?", model.DeleteStatusForNot)
|
|
|
|
if err := db.Scan(&out).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// 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)
|
|
|
|
if err := db.Scan(&out).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func NewSysAuth() *SysAuth {
|
|
return &SysAuth{SysAuth: model.NewSysAuth()}
|
|
}
|