Files
cas_tt_cloud_backend/app/api/model/sys_role_auth.go

48 lines
1.1 KiB
Go
Raw Normal View History

2021-09-28 11:47:19 +08:00
package model
import (
"SciencesServer/app/common/model"
"SciencesServer/serve/orm"
"fmt"
)
type SysRoleAuth struct {
*model.SysRoleAuth
}
// SysRoleAuths 权限信息
type SysRoleAuths struct {
ID uint64 `json:"id"`
RoleID uint64 `json:"role_id"`
Auth string `json:"auth"`
}
// Auths 权限信息
func (m *SysRoleAuth) Auths(where ...*model.ModelWhere) ([]*SysRoleAuths, error) {
mSysRole := NewSysRole()
mSysAuth := NewSysAuth()
db := orm.GetDB().Table(m.TableName()+" AS r_a").
Select("r_a.id, r_a.role_id, a.auth").
Joins(fmt.Sprintf("LEFT JOIN %s AS r ON r_a.role_id = r.id", mSysRole.TableName())).
Joins(fmt.Sprintf("LEFT JOIN %s AS a ON r_a.auth_id = a.id", mSysAuth.TableName())).
Where("r_a.is_deleted = ?", model.DeleteStatusForNot)
out := make([]*SysRoleAuths, 0)
if len(where) > 0 {
for _, wo := range where {
db = db.Where(wo.Condition, wo.Value)
}
}
if err := db.Order("r_a.id " + model.OrderModeToDesc).Scan(&out).Error; err != nil {
return nil, err
}
return out, nil
}
func NewSysRoleAuth() *SysRoleAuth {
return &SysRoleAuth{SysRoleAuth: model.NewSysRoleAuth()}
}