2021-09-28 11:47:19 +08:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"SciencesServer/app/common/model"
|
|
|
|
"SciencesServer/serve/orm"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SysTenant struct {
|
|
|
|
*model.SysTenant
|
|
|
|
}
|
|
|
|
|
|
|
|
type (
|
|
|
|
// SysTenantBasic 租户基本信息
|
|
|
|
SysTenantBasic struct {
|
|
|
|
}
|
|
|
|
// SysTenantInfo 租户信息
|
|
|
|
SysTenantInfo struct {
|
|
|
|
*model.SysTenant
|
|
|
|
DeviceCount int `json:"device_count"`
|
|
|
|
CustomerDeviceCount int `json:"customer_device_count"`
|
|
|
|
}
|
|
|
|
// SysTenantSubsetInfo 租户子集信息
|
|
|
|
SysTenantSubsetInfo struct {
|
|
|
|
ID uint64 `json:"id"`
|
|
|
|
ParentID uint64 `json:"parent_id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
DeviceCount int `json:"device_count"`
|
|
|
|
}
|
|
|
|
// SysTenantDeviceCount 设备数量
|
|
|
|
SysTenantDeviceCount struct {
|
|
|
|
TenantID uint64 `json:"tenant_id"`
|
|
|
|
Count int `json:"count"`
|
|
|
|
CustomerCount int `json:"customer_count"`
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// IsInvalid 判断是否有效
|
|
|
|
func (m *SysTenant) IsInvalid() bool {
|
2021-10-08 17:33:19 +08:00
|
|
|
return false
|
2021-09-28 11:47:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Tenants 租户信息
|
|
|
|
func (m *SysTenant) Tenants(page, pageSize int, count *int64, where ...*model.ModelWhere) ([]*SysTenantInfo, error) {
|
|
|
|
|
|
|
|
db := orm.GetDB().Table(m.TableName()).Where("is_deleted = ?", model.DeleteStatusForNot)
|
|
|
|
|
|
|
|
if len(where) > 0 {
|
|
|
|
for _, wo := range where {
|
|
|
|
db = db.Where(wo.Condition, wo.Value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out := make([]*SysTenantInfo, 0)
|
|
|
|
|
|
|
|
if err := db.Count(count).Error; err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err := db.Order("id " + model.OrderModeToDesc).Offset((page - 1) * pageSize).Limit(pageSize).Scan(&out).Error; err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return out, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSysTenant() *SysTenant {
|
|
|
|
return &SysTenant{SysTenant: model.NewSysTenant()}
|
|
|
|
}
|