feat:完善项目

This commit is contained in:
henry
2021-11-04 11:59:33 +08:00
parent 0234324e60
commit 288c74dc41
4 changed files with 46 additions and 4 deletions

View File

@ -2,6 +2,7 @@ package model
import (
"ArmedPolice/app/common/model"
"ArmedPolice/serve/orm"
)
type SysTenant struct {
@ -11,6 +12,8 @@ type SysTenant struct {
type (
// SysTenantBasic 租户基本信息
SysTenantBasic struct {
ID uint64 `json:"id"`
Name string `json:"name"`
}
// SysTenantInfo 租户信息
SysTenantInfo struct {
@ -20,6 +23,22 @@ type (
}
)
// Parent 父集元素,包含自己
func (m *SysTenant) Parent(tenantID uint64) ([]*SysTenantBasic, error) {
sql := `SELECT T2.id, T2.name FROM
(SELECT @r AS _id, (SELECT @r := parent_id FROM ? WHERE id = _id) AS parent_id,
@l := @l + 1 AS lvl
FROM (SELECT @r := ?, @l := 0 ) vars, ? h WHERE @r <> 0) T1
JOIN ? T2 ON T1._id = T2.id
ORDER BY T1.lvl DESC`
out := make([]*SysTenantBasic, 0)
err := orm.GetDB().Raw(sql, m.TableName(), tenantID, m.TableName(), m.TableName()).Scan(&out).Error
return out, err
}
func NewSysTenant() *SysTenant {
return &SysTenant{SysTenant: model.NewSysTenant()}
}