|
|
package rbac
|
|
|
|
|
|
import (
|
|
|
"oppmg/common/log"
|
|
|
"oppmg/models"
|
|
|
"oppmg/protocol"
|
|
|
"oppmg/utils"
|
|
|
"encoding/json"
|
|
|
)
|
|
|
|
|
|
//获取全部的权限菜单
|
|
|
func GetMenuAll() ([]protocol.PermissionItem, error) {
|
|
|
const datasql string = `SELECT id,name,icon,parent_id,senior_status,sort,code
|
|
|
FROM menu WHERE enabled=1 ORDER BY sort `
|
|
|
var (
|
|
|
list []protocol.PermissionItem
|
|
|
err error
|
|
|
)
|
|
|
err = utils.ExecuteQueryAll(&list, datasql)
|
|
|
if err != nil {
|
|
|
log.Error("EXECUTE SQL err:%s", err)
|
|
|
return nil, protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
return list, nil
|
|
|
//PermissionBase 路由对应的权限
|
|
|
type PermissionBase struct {
|
|
|
CodeName string //模块标识
|
|
|
ActionName string
|
|
|
// MethodMap map[string]func()
|
|
|
}
|
|
|
|
|
|
//
|
|
|
func GetRoleHasMenu(roleid int64, companyid int64) (*protocol.ResponseRoleMenus, error) {
|
|
|
var (
|
|
|
roleData *models.Role
|
|
|
err error
|
|
|
)
|
|
|
roleData, err = models.GetRoleById(roleid)
|
|
|
if err != nil {
|
|
|
log.Error("获取角色数据失败:%s", err)
|
|
|
return nil, err
|
|
|
}
|
|
|
if roleData.Types != models.ROLETYPES_ROLE {
|
|
|
log.Error("角色类型错误")
|
|
|
return nil, protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
if roleData.CompanyId != companyid {
|
|
|
log.Error("角色的公司id不匹配")
|
|
|
return nil, protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
var (
|
|
|
rolemenu []models.RoleMenu
|
|
|
ids []int64
|
|
|
)
|
|
|
rolemenu, err = models.GetRoleMenuByRole(roleid)
|
|
|
var routerPermission = map[string]PermissionBase{
|
|
|
"/v1/department/list": PermissionBase{CodeName: "OPPMG_DEPARTMENT", ActionName: "check"},
|
|
|
"/v1/department/add": PermissionBase{CodeName: "OPPMG_DEPARTMENT", ActionName: "add"},
|
|
|
"/v1/department/edit": PermissionBase{CodeName: "OPPMG_DEPARTMENT", ActionName: "edit"},
|
|
|
"/v1/department/delete": PermissionBase{CodeName: "OPPMG_DEPARTMENT", ActionName: "delete"},
|
|
|
}
|
|
|
|
|
|
var permissionObject = map[string]interface{}{
|
|
|
"": 0,
|
|
|
}
|
|
|
|
|
|
//模块编号
|
|
|
const (
|
|
|
MENU_DEPARTMENT string = "OPPMG_DEPARTMENT" //公司部门管理模块
|
|
|
MENU_POSITION string = "OPPMG_POSITION" //公司职务管理
|
|
|
MENU_RBAC string = "OPPMG_RBAC" //员工角色/权限设置
|
|
|
MENU_USER string = "OPPMG_USER" //公司员工管理
|
|
|
MENU_ENTERPRISE_BASIC string = "OPPMG_ENTERPRISE_BASIC" //企业基础设置(大节点)
|
|
|
MENU_SYSTEM_FUNCTION string = "OPPMG_SYSTEM_FUNCTION" //系统功能(大节点)
|
|
|
MENU_CONMPANY string = "OPPMG_CONMPANY" //企业信息维护
|
|
|
MENU_CHANCE_TEMP string = "OPPMG_CHANCE_TEMP" //机会模板管理
|
|
|
MENU_SORCE string = "OPPMG_SORCE" //评分模式
|
|
|
MENU_CHANCE string = "OPPMG_CHANCE" //机会管理
|
|
|
)
|
|
|
|
|
|
type PermissionContentObject interface {
|
|
|
StringUnmarshal(string) error
|
|
|
ObjectMarshal() (string, error)
|
|
|
}
|
|
|
|
|
|
type PermissionContentBase struct {
|
|
|
Check int8 `json:"check"`
|
|
|
}
|
|
|
|
|
|
func NewPermissionContentBase() PermissionContentObject {
|
|
|
return &PermissionContentBase{}
|
|
|
}
|
|
|
|
|
|
func (p *PermissionContentBase) StringUnmarshal(s string) error {
|
|
|
err := json.Unmarshal([]byte(s), p)
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
func (p *PermissionContentBase) ObjectMarshal() (string, error) {
|
|
|
bt, err := json.Marshal(p)
|
|
|
if err != nil {
|
|
|
log.Error("获取角色下的菜单数据失败:%s", err)
|
|
|
return nil, protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
for _, v := range rolemenu {
|
|
|
ids = append(ids, v.MenuId)
|
|
|
return "", err
|
|
|
}
|
|
|
data := &protocol.ResponseRoleMenus{
|
|
|
RoleId: roleData.Id,
|
|
|
RoleName: roleData.Name,
|
|
|
MenuId: ids,
|
|
|
}
|
|
|
return data, nil
|
|
|
return string(bt), err
|
|
|
}
|
|
|
|
|
|
func RoleMenuEdit(companyid int64, roleid int64, menuids []int64) {
|
|
|
|
|
|
type CodeToObject func() PermissionContentObject
|
|
|
|
|
|
var CodePermissionObject = map[string]CodeToObject{
|
|
|
MENU_DEPARTMENT: NewPermissionContentBase, //公司部门管理模块
|
|
|
MENU_POSITION: NewPermissionContentBase, //公司职务管理
|
|
|
MENU_RBAC: NewPermissionContentBase, //员工角色/权限设置
|
|
|
MENU_USER: NewPermissionContentBase, //公司员工管理
|
|
|
MENU_ENTERPRISE_BASIC: NewPermissionContentBase, //企业基础设置(大节点)
|
|
|
MENU_SYSTEM_FUNCTION: NewPermissionContentBase, //系统功能(大节点)
|
|
|
MENU_CONMPANY: NewPermissionContentBase, //企业信息维护
|
|
|
MENU_CHANCE_TEMP: NewPermissionContentBase, //机会模板管理
|
|
|
MENU_SORCE: NewPermissionContentBase, //评分模式
|
|
|
MENU_CHANCE: NewPermissionContentBase, //机会管理
|
|
|
} |
...
|
...
|
|