123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748 |
- package new_mobile_api_controllers
-
- import (
- "Xcx_New/enums"
- "Xcx_New/models"
- "Xcx_New/service"
- "fmt"
- "strconv"
- "strings"
- "time"
- )
-
- type NewRoleApiController struct {
- NewMobileBaseAPIAuthController
- }
-
- func (this *NewRoleApiController) GetAllOrgUser() {
- adminUserInfo := this.GetMobileAdminUserInfo()
- var isSubSuperAdmin bool = false
- app_role, _ := service.GetAppRoleById(adminUserInfo.AppRole.Id)
- role_ids := strings.Split(app_role.RoleIds, ",")
-
- if len(role_ids) > 0 {
- if adminUserInfo.AdminUser.Id != adminUserInfo.Org.Creator {
- for _, item := range role_ids {
- id, _ := strconv.ParseInt(item, 10, 64)
- if id != 0 {
- role, _ := service.GetRoleByRoleID(id)
- if role != nil {
- if role.IsSystem == 1 && role.RoleName == "子管理员" {
- isSubSuperAdmin = true
- }
- }
- }
-
- }
- }
- }
- viewModels, _, _ := service.GetAllAdminUsersAndRole(adminUserInfo.Org.Id, adminUserInfo.App.Id, 1, 100)
- this.ServeSuccessJSON(map[string]interface{}{
- "admins": viewModels,
- "isSubSuperAdmin": isSubSuperAdmin,
- "org_creator": adminUserInfo.Org.Creator,
- })
- }
-
- func (this *NewRoleApiController) EditAdmin() {
- adminUserInfo := this.GetMobileAdminUserInfo()
- adminUserId, _ := this.GetInt64("uid")
- name := this.GetString("name")
- userTitle := this.GetString("title")
- roleIds := this.GetString("role_ids")
- user_type, _ := this.GetInt64("user_type", 0)
- user_title, _ := this.GetInt64("user_title", 0)
-
- department_name := this.GetString("department_name")
- department_id, _ := this.GetInt64("department_id", 0)
-
- //roleIds := this.GetString("role_ids")
-
- if adminUserId <= 0 || len(name) == 0 || len(roleIds) <= 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
- appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserId)
- if getAppRoleErr != nil {
- //beego.Error("查询管理员信息时失败:", getAppRoleErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- if appRole == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
- return
- }
- appRole.UserName = name
- appRole.UserTitleName = userTitle
- appRole.RoleIds = roleIds
- appRole.ModifyTime = time.Now().Unix()
- appRole.UserType = int8(user_type)
- appRole.UserTitle = int8(user_title)
- appRole.Department = department_name
- appRole.DepartmentId = department_id
- saveErr := service.SaveAppRole(appRole)
-
- if saveErr != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
- } else {
- this.ServeSuccessJSON(nil)
- }
- }
-
- func (this *NewRoleApiController) GetEditAdminInitData() {
- adminUserInfo := this.GetMobileAdminUserInfo()
-
- roles, _ := service.GetNewAllOrgValidRoles(adminUserInfo.Org.Id)
- this.ServeSuccessJSON(map[string]interface{}{
- "roles": roles,
- })
- }
-
- func (this *NewRoleApiController) GetAdminUserInfo() {
- adminUserInfo := this.GetMobileAdminUserInfo()
- adminUserId, _ := this.GetInt64("uid")
- var isSubSuperAdmin bool = false
- app_role, _ := service.GetAppRoleById(adminUserInfo.AppRole.Id)
- role_ids := strings.Split(app_role.RoleIds, ",")
- if len(role_ids) > 0 {
- if adminUserInfo.AdminUser.Id != adminUserInfo.Org.Creator {
- for _, item := range role_ids {
- id, _ := strconv.ParseInt(item, 10, 64)
- if id != 0 {
- role, _ := service.GetRoleByRoleID(id)
- if role != nil {
-
- if role.IsSystem == 1 && role.RoleName == "子管理员" {
- isSubSuperAdmin = true
- }
- }
- }
- }
- }
- }
-
- appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserId)
- if getAppRoleErr != nil {
- //beego.Error("查询管理员信息时失败:", getAppRoleErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- if appRole == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "user_info": appRole,
- "isSubSuperAdmin": isSubSuperAdmin,
- })
-
- }
-
- func (this *NewRoleApiController) StopAdminUser() {
- adminUserInfo := this.GetMobileAdminUserInfo()
- adminUserId, _ := this.GetInt64("uid")
- appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserId)
- if getAppRoleErr != nil {
- //beego.Error("查询管理员信息时失败:", getAppRoleErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- if appRole == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
- return
- }
-
- enable, _ := this.GetBool("enable")
-
- if enable {
- appRole.Status = 1
- } else {
- appRole.Status = 0
- }
- appRole.ModifyTime = time.Now().Unix()
- saveErr := service.SaveAppRole(appRole)
- if saveErr != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
- } else {
- this.ServeSuccessJSON(nil)
- }
-
- }
-
- func (this *NewRoleApiController) CreateAdminUser() {
- adminUserInfo := this.GetMobileAdminUserInfo()
- mobile := this.GetString("mobile")
- name := this.GetString("name")
- role_ids := this.GetString("role_ids")
- userTitle := this.GetString("title")
- department_name := this.GetString("department_name")
- department_id, _ := this.GetInt64("department_id")
-
- user_type, _ := this.GetInt("user_type", 0)
- user_title, _ := this.GetInt("user_title", 0)
- if len(mobile) == 0 || len(name) == 0 || len(role_ids) <= 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- // 判断是否已存在该手机号
- if adminUser, err := service.GetValidAdminUserByMobileReturnErr(mobile); err != nil {
- //beego.Error("查询用户是否已被添加为管理员时失败:", err)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else {
- if adminUser == nil { //新增账号和用户
-
- _, password, createErr := service.CreateGeneralAdminUser(adminUserInfo.Org.Id, adminUserInfo.App.Id, mobile, name, userTitle, role_ids, user_type, user_title, department_id, department_name)
- if createErr != nil {
- //beego.Error("创建管理员失败:", createErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
- return
-
- } else {
- sendSMSErr := service.SMSSendInviteMobileToJoinOrgAdmin(name, mobile, password)
- if sendSMSErr != nil {
- }
-
- this.ServeSuccessJSON(nil)
- return
- }
- } else {
-
- total, _ := service.FindAdminUserByID(adminUser.Id, adminUserInfo.Org.Id)
-
- if total <= 0 {
- //新增用户
- app_role := &models.App_Role{
- AdminUserId: adminUser.Id,
- OrgId: adminUserInfo.Org.Id,
- AppId: adminUserInfo.App.Id,
- Avatar: "",
- UserName: name,
- UserTitleName: userTitle,
- UserTitle: int8(user_title),
- UserType: int8(user_type),
- Status: 1,
- CreateTime: time.Now().Unix(),
- ModifyTime: time.Now().Unix(),
- RoleIds: role_ids,
- IsSort: 1,
- }
- err := service.CreateUserRole(app_role)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
- return
- }
- this.ServeSuccessJSON(nil)
- } else {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRepeatCreateStaffException)
- return
- }
-
- return
- }
- }
-
- }
-
- func (this *NewRoleApiController) GetAllOrgRole() {
- adminUserInfo := this.GetMobileAdminUserInfo()
-
- var isSubSuperAdmin bool = false
-
- app_role, _ := service.GetAppRoleById(adminUserInfo.AppRole.Id)
- role_ids := strings.Split(app_role.RoleIds, ",")
- if len(role_ids) > 0 {
-
- if adminUserInfo.AdminUser.Id != adminUserInfo.Org.Creator {
- for _, item := range role_ids {
- id, _ := strconv.ParseInt(item, 10, 64)
- if id != 0 {
- role, _ := service.GetRoleByRoleID(id)
- if role != nil {
- if role.IsSystem == 1 && role.RoleName == "子管理员" {
- isSubSuperAdmin = true
- }
- }
- }
- }
- }
- }
- fmt.Println(isSubSuperAdmin)
-
- roles, err := service.GetAllOrgValidRoles(adminUserInfo.Org.Id, isSubSuperAdmin)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "roles": roles,
- })
- }
-
- }
-
- func (this *NewRoleApiController) EditRole() {
- role_id, _ := this.GetInt64("id", 0)
- desc := this.GetString("desc")
-
- role, _ := service.GetRoleByRoleID(role_id)
-
- role.RoleIntro = desc
- role.ModifyTime = time.Now().Unix()
-
- err := service.SaveRole(role)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "role": role,
- })
- return
- }
-
- func (this *NewRoleApiController) GetOrgRoleInfo() {
- role_id, _ := this.GetInt64("id", 0)
- role, err := service.GetRoleByRoleID(role_id)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "role": role,
- })
- }
-
- }
-
- func (this *NewRoleApiController) CreateRole() {
- adminUserInfo := this.GetMobileAdminUserInfo()
- role_name := this.GetString("name")
- role_desc := this.GetString("desc")
-
- total := service.FindRoleRecordByRoleName(role_name, adminUserInfo.Org.Id)
- if total > 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleNameIsExist)
- return
-
- }
-
- role := &models.Role{
- RoleName: role_name,
- RoleIntro: role_desc,
- Creator: adminUserInfo.AdminUser.Id,
- OrgId: adminUserInfo.Org.Id,
- AppId: adminUserInfo.App.Id,
- Status: 1,
- IsSuperAdmin: false,
- CreateTime: time.Now().Unix(),
- ModifyTime: time.Now().Unix(),
- }
-
- err := service.CreateOrgRole(role)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else {
- this.ServeSuccessJSON(map[string]interface{}{
- "role": role,
- })
- }
-
- }
-
- func (this *NewRoleApiController) GetAllPermission() {
- module, _ := this.GetInt64("module")
- parent_id, _ := this.GetInt64("id")
- purviews, _ := service.GetAllPurview(module, parent_id)
- this.ServeSuccessJSON(map[string]interface{}{
- "purviews": purviews,
- })
- }
-
- func (this *NewRoleApiController) DeleteOrgRole() {
- roleID, _ := this.GetInt64("role_id")
- enable, _ := this.GetBool("enable")
- if roleID <= 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- adminUserInfo := this.GetMobileAdminUserInfo()
-
- role, getRoleErr := service.GetRoleByRoleID(roleID)
- if getRoleErr != nil {
- //beego.Error("获取角色失败:", getRoleErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else if role == nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleNotExist)
- return
- }
-
- if enable == false {
- if count, _ := service.RoleAdminUserCountTwo(adminUserInfo.Org.Id, adminUserInfo.App.Id, roleID); count != 0 {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCannotRemoveRole)
- return
- }
- }
-
- if enable {
- role.Status = 1
- } else {
- role.Status = 2
- }
- role.ModifyTime = time.Now().Unix()
- saveErr := service.ModifyRole(role)
- if saveErr != nil {
- //beego.Error("修改角色失败:", role.Id, saveErr)
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
- } else {
- this.ServeSuccessJSON(nil)
- }
-
- }
-
- func (this *NewRoleApiController) GetRolePurviews() {
- adminUserInfo := this.GetMobileAdminUserInfo()
- role_id, _ := this.GetInt64("id", 0)
- rolePurview, _ := service.GetRoleAndPurviewById(role_id, adminUserInfo.Org.Id, adminUserInfo.App.Id)
- funRolePurview, _ := service.GetRoleFuncPurview(role_id)
-
- role, _ := service.GetRoleByRoleID(role_id)
- this.ServeSuccessJSON(map[string]interface{}{
- "role_purview": rolePurview,
- "role": role,
- "func_purview": funRolePurview,
- })
- }
-
- func (this *NewRoleApiController) AddRoleStaff() {
- //adminUserInfo := this.GetMobileAdminUserInfo()
- role_id, _ := this.GetInt64("id", 0)
- staff_ids := this.GetString("ids")
- ids := strings.Split(staff_ids, ",")
- for _, item := range ids {
- id, _ := strconv.ParseInt(item, 10, 64)
- role, _ := service.FindAdminUserID(id)
- role.RoleIds = role.RoleIds + "," + strconv.FormatInt(role_id, 10)
- service.SaveAdminUser(&role)
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "msg": "添加成功",
- })
-
- }
-
- func (this *NewRoleApiController) GetFuntionPurviews() {
- pid, _ := this.GetInt64("pid")
- functionPurview, _ := service.GetFunctionPurview(pid)
- this.ServeSuccessJSON(map[string]interface{}{
- "funtion_purview": functionPurview,
- })
- }
-
- func RemoveRepeatedIDSElement(arr []string) (newArr []string) {
- newArr = make([]string, 0)
- for i := 0; i < len(arr); i++ {
- repeat := false
- for j := i + 1; j < len(arr); j++ {
- if arr[i] == arr[j] {
- repeat = true
- break
- }
- }
- if !repeat {
- newArr = append(newArr, arr[i])
- }
- }
- return
- }
-
- func (this *NewRoleApiController) EditRolePermission() {
- adminUser := this.GetMobileAdminUserInfo()
- role_id, _ := this.GetInt64("id", 0)
- purview_id := this.GetString("purview_id")
- is_open, _ := this.GetInt64("type", 0)
-
- permissions, err := service.GetRolePurviewIds(role_id)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else {
-
- if is_open == 1 { //打开
- purview, _ := service.GetRolePurview(role_id)
- if purview.Id == 0 { // 新建
-
- purview.PurviewIds = purview_id
- purview.CreateTime = time.Now().Unix()
- purview.ModifyTime = time.Now().Unix()
- purview.Status = 1
- purview.RoleId = role_id
- purview.OrgId = adminUser.Org.Id
- purview.AppId = adminUser.App.Id
- err := service.CreateRolePurview(&purview)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "is_open": 1,
- })
-
- } else { //修改
- var permission_arr []string
- purview, _ := service.GetRolePurview(role_id)
- if len(permissions) > 0 {
- permission_arr = strings.Split(permissions, ",")
- if len(purview_id) > 0 {
- permission_arr = append(permission_arr, strings.Split(purview_id, ",")...)
- }
- } else {
- if len(purview_id) > 0 {
- permission_arr = strings.Split(purview_id, ",")
- }
- }
-
- permission_arr = RemoveRepeatedIDSElement(permission_arr)
- permissions = strings.Join(permission_arr, ",")
- purview.PurviewIds = permissions
- err := service.SaveRolePurview(&purview)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "is_open": 1,
- })
-
- }
-
- } else { //关闭
- permission_arr := strings.Split(permissions, ",")
- purview_arr := strings.Split(purview_id, ",")
-
- for _, pur_id := range purview_arr {
- for index, id := range permission_arr {
- if id == pur_id {
- permission_arr = append(permission_arr[:index], permission_arr[index+1:]...)
- }
- }
- }
- purview, _ := service.GetRolePurview(role_id)
- fmt.Println(purview.CreateTime)
- purview.PurviewIds = strings.Join(permission_arr, ",")
-
- err := service.SaveRolePurview(&purview)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "is_open": 0,
- })
-
- }
- }
-
- }
-
- func (this *NewRoleApiController) EditFunctionPermission() {
- adminUser := this.GetMobileAdminUserInfo()
- role_id, _ := this.GetInt64("id", 0)
- purview_id := this.GetString("purview_id")
- is_open, _ := this.GetInt64("type", 0)
- is_all, _ := this.GetInt64("is_all", 0)
- pid := this.GetString("pid")
-
- func_permissions, err := service.GetRoleFuncPurviewIds(role_id)
- permissions, _ := service.GetRolePurviewIds(role_id)
-
- redis := service.RedisClient()
- defer redis.Close()
-
- users := service.GetAllUserRole(adminUser.Org.Id)
- for _, item := range users {
- key := "purviews_" + strconv.FormatInt(adminUser.Org.Id, 10) + strconv.FormatInt(item.AdminUserId, 10)
- redis.Set(redis.Context(),key, "", time.Second)
- }
-
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- } else {
-
- if is_open == 1 { //打开
- //处理功能权限涉及到的菜单权限
-
- purview, _ := service.GetRolePurview(role_id)
- if purview.Id == 0 { // 新建
- purview.PurviewIds = pid
- purview.CreateTime = time.Now().Unix()
- purview.ModifyTime = time.Now().Unix()
- purview.Status = 1
- purview.RoleId = role_id
- purview.OrgId = adminUser.Org.Id
- purview.AppId = adminUser.App.Id
- service.CreateRolePurview(&purview)
-
- } else { //修改
- var permission_arr []string
- purview, _ := service.GetRolePurview(role_id)
- if len(permissions) > 0 {
- permission_arr = strings.Split(permissions, ",")
- if len(pid) > 0 {
- permission_arr = append(permission_arr, strings.Split(pid, ",")...)
- }
- } else {
- if len(pid) > 0 {
- permission_arr = strings.Split(pid, ",")
- }
- }
- permission_arr = RemoveRepeatedIDSElement(permission_arr)
- permissions = strings.Join(permission_arr, ",")
- purview.PurviewIds = permissions
- service.SaveRolePurview(&purview)
- }
-
- func_purview, _ := service.GetFuncRolePurview(role_id)
- if func_purview.ID == 0 { // 新建
-
- func_purview.PurviewIds = purview_id
- func_purview.Ctime = time.Now().Unix()
- func_purview.Mtime = time.Now().Unix()
- func_purview.Status = 1
- func_purview.RoleId = role_id
- func_purview.OrgId = adminUser.Org.Id
- func_purview.AppId = adminUser.App.Id
- err := service.CreateFuncRolePurview(&func_purview)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
-
- this.ServeSuccessJSON(map[string]interface{}{
- "is_open": 1,
- })
- } else { //修改
- var permission_arr []string
- func_purview, _ := service.GetRoleFuncPurview(role_id)
- if len(func_permissions) > 0 {
- permission_arr = strings.Split(func_permissions, ",")
- if len(purview_id) > 0 {
- permission_arr = append(permission_arr, strings.Split(purview_id, ",")...)
- }
- } else {
- if len(purview_id) > 0 {
- permission_arr = strings.Split(purview_id, ",")
- }
- }
- permission_arr = RemoveRepeatedIDSElement(permission_arr)
- func_permissions = strings.Join(permission_arr, ",")
- func_purview.PurviewIds = func_permissions
-
- err := service.SaveRoleFuncPurview(&func_purview)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "is_open": 1,
- })
- }
- } else { //关闭
-
- //处理功能权限涉及到的菜单权限,当关闭到只剩下一个的时候,在将菜单权限对应的权限id清除
- func_permission_arr := strings.Split(func_permissions, ",")
- if len(func_permission_arr) == 1 {
- permission_arr := strings.Split(permissions, ",")
- pid_arr := strings.Split(pid, ",")
- for _, pur_id := range pid_arr {
- for index, id := range permission_arr {
- if id == pur_id {
- permission_arr = append(permission_arr[:index], permission_arr[index+1:]...)
- }
- }
- }
- purview, _ := service.GetRolePurview(role_id)
- purview.PurviewIds = strings.Join(permission_arr, ",")
- service.SaveRolePurview(&purview)
- }
-
- if is_all == 1 {
-
- permission_arr := strings.Split(permissions, ",")
- pid_arr := strings.Split(pid, ",")
- for _, pur_id := range pid_arr {
- for index, id := range permission_arr {
- if id == pur_id {
- permission_arr = append(permission_arr[:index], permission_arr[index+1:]...)
- }
- }
- }
- purview, _ := service.GetRolePurview(role_id)
- purview.PurviewIds = strings.Join(permission_arr, ",")
- service.SaveRolePurview(&purview)
-
- func_purview, _ := service.GetRoleFuncPurview(role_id)
- func_purview.PurviewIds = ""
- err := service.SaveRoleFuncPurview(&func_purview)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "is_open": 0,
- })
-
- } else {
- permission_arr := strings.Split(func_permissions, ",")
- purview_arr := strings.Split(purview_id, ",")
- fmt.Println(permission_arr)
- fmt.Println(purview_arr)
- for index, id := range permission_arr {
- for _, pur_id := range purview_arr {
- if id == pur_id {
- permission_arr = append(permission_arr[:index], permission_arr[index+1:]...)
- }
- }
- }
- func_purview, _ := service.GetRoleFuncPurview(role_id)
- func_purview.PurviewIds = strings.Join(permission_arr, ",")
-
- err := service.SaveRoleFuncPurview(&func_purview)
- if err != nil {
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
- return
- }
- this.ServeSuccessJSON(map[string]interface{}{
- "is_open": 0,
- })
- }
-
- }
- }
-
- }
-
- func (this *NewRoleApiController) GetFuncRolePurviews() {
- //adminUserInfo := this.GetMobileAdminUserInfo()
- role_id, _ := this.GetInt64("id", 0)
- purview, _ := service.GetRoleFuncPurview(role_id)
- this.ServeSuccessJSON(map[string]interface{}{
- "role_purview": purview,
- })
- }
-
- func (this *NewRoleApiController) GetAllNewPermission() {
- url := this.GetString("url")
- purviews, _ := service.GetNewAllPurview(url)
- this.ServeSuccessJSON(map[string]interface{}{
- "purviews": purviews,
- })
- }
|