123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- package models
- import (
- "errors"
- "eta/eta_mini_crm_ht/utils"
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- // MetaInfo 表示 meta_infos 表的模型
- // Permission 表示权限表的结构
- type Permission struct {
- Id int `description:"column:id;primary_key;autoIncrement"`
- PermissionId int `description:"column:permission_id"`
- Name string `description:"column:name"`
- ParentId int `description:"column:parent_id"`
- RiskLevel string `description:"column:risk_level"`
- Sort int `description:"column:sort"`
- CreateTime time.Time `description:"column:create_time"`
- UpdateTime time.Time `description:"column:update_time"`
- }
- func (p *Permission) TableName() string {
- return "permissions"
- }
- func (p *Permission) Insert() (insert int64, err error) {
- o := orm.NewOrm()
- insert, err = o.Insert(p)
- return
- }
- func GetPermissionList() (items []*Permission, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM permissions ORDER BY sort ASC`
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- func GetPermissionByPermissionId(permissionId int) (items *Permission, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM permissions where permission_id =?`
- err = o.Raw(sql, permissionId).QueryRow(&items)
- return
- }
- func (p *Permission) SetPermissionRiskLevel() (err error) {
- o := orm.NewOrm()
- _, err = o.Update(p, "RiskLevel")
- return
- }
- func GetPermissionNames(ids []int) (permissionNameList []string, err error) {
- o := orm.NewOrm()
- if len(ids) == 0 {
- err = errors.New("品种id列表为空")
- return
- }
- condition := " permission_id in (" + utils.GetOrmReplaceHolder(len(ids)) + ")"
- sql := `SELECT name FROM permissions where ` + condition + ` order by permission_id asc`
- _, err = o.Raw(sql, ids).QueryRows(&permissionNameList)
- if err != nil {
- return
- }
- return
- }
- func GetPermissionNamesWithRiskLevel(ids []int) (permissionNameList []string, err error) {
- o := orm.NewOrm()
- var sql string
- if len(ids) == 0 {
- sql = `SELECT distinct name FROM permissions where risk_level !='' order by permission_id asc`
- } else {
- condition := " permission_id in (" + utils.GetOrmReplaceHolder(len(ids)) + ")"
- sql = `SELECT distinct name FROM permissions where risk_level !='' and ` + condition + ` order by permission_id asc`
- }
- _, err = o.Raw(sql, ids).QueryRows(&permissionNameList)
- if err != nil {
- return
- }
- return
- }
- func GetPermissionsWithRiskLevel(ids []int) (permissionList []Permission, err error) {
- o := orm.NewOrm()
- var sql string
- if len(ids) == 0 {
- sql = `SELECT * FROM permissions where risk_level !='' order by permission_id asc`
- } else {
- condition := " permission_id in (" + utils.GetOrmReplaceHolder(len(ids)) + ")"
- sql = `SELECT * FROM permissions where risk_level !='' and ` + condition + ` order by permission_id asc`
- }
- _, err = o.Raw(sql, ids).QueryRows(&permissionList)
- if err != nil {
- return
- }
- return
- }
- func GetClassifyIdByPermissionIds(permissionIds []int) (classifyIds []int, err error) {
- o := orm.NewOrm()
- if len(permissionIds) == 0 {
- return
- }
- sql := `SELECT distinct classify_id FROM permission_classify_mapping where permission_id in (` + utils.GetOrmReplaceHolder(len(permissionIds)) + `) order by permission_id asc`
- _, err = o.Raw(sql, permissionIds).QueryRows(&classifyIds)
- return
- }
- func FilterPermissionIdsWithRiskLevel(ids []int) (permissionIds []int, err error) {
- o := orm.NewOrm()
- var sql string
- if len(ids) == 0 {
- sql = `SELECT distinct permission_id FROM permissions where risk_level!='' order by permission_id asc`
- } else {
- sql = `SELECT distinct permission_id FROM permissions where risk_level!='' and permission_id in (` + utils.GetOrmReplaceHolder(len(ids)) + `) order by permission_id asc`
- }
- _, err = o.Raw(sql, ids).QueryRows(&permissionIds)
- return
- }
- func GetPermissionByName(name string) (permission Permission, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM permissions where name = ?`
- err = o.Raw(sql, name).QueryRow(&permission)
- return
- }
|