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(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,
	})
}
