feat:完善项目
This commit is contained in:
47
app/api/model/sys_role_auth.go
Normal file
47
app/api/model/sys_role_auth.go
Normal file
@ -0,0 +1,47 @@
|
||||
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()}
|
||||
}
|
Reference in New Issue
Block a user