You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
219 lines
6.0 KiB
219 lines
6.0 KiB
package grantpowers
|
|
|
|
import (
|
|
"appPlatform/models/modelAppPlatform"
|
|
"appPlatform/models/modelsschool"
|
|
"appPlatform/models/modelsstorage"
|
|
"appPlatform/models/modelssystempermission"
|
|
"appPlatform/overall"
|
|
"appPlatform/overall/publicmethod"
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-05-29 16:07:22
|
|
@ 功能: 获取岗位已配置的权限
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) GetPostGrantPowers(c *gin.Context) {
|
|
var requestData GetPostPowerCont
|
|
err := c.ShouldBindJSON(&requestData)
|
|
if err != nil {
|
|
publicmethod.Result(100, err, c)
|
|
return
|
|
}
|
|
if requestData.OrdId == "" || requestData.OrdId == "0" {
|
|
publicmethod.Result(1, requestData, c, "未知行政组织!不可进行配权")
|
|
return
|
|
}
|
|
if requestData.PostId == "" || requestData.PostId == "0" {
|
|
publicmethod.Result(1, requestData, c, "未知岗位!不可进行配权")
|
|
return
|
|
}
|
|
if requestData.SystemName == "" {
|
|
publicmethod.Result(1, requestData, c, "未知配权系统!不可进行配权")
|
|
return
|
|
}
|
|
var powerList []string
|
|
var empowerCont modelssystempermission.Empower
|
|
err = empowerCont.GetCont(map[string]interface{}{"`ordid`": requestData.OrdId, "`post_id`": requestData.PostId, "`system`": requestData.SystemName}, "`id`", "`point_id`", "`operation`", "`level`")
|
|
if err != nil {
|
|
publicmethod.Result(0, powerList, c)
|
|
return
|
|
}
|
|
switch requestData.SystemName {
|
|
case "kpi":
|
|
if empowerCont.PointId != "" || empowerCont.Operation != "" {
|
|
powerAry := strings.Split(empowerCont.PointId, ",")
|
|
opeartionAry := strings.Split(empowerCont.Operation, ",")
|
|
powerList = GetSysKpiMenuPower(powerAry, opeartionAry)
|
|
}
|
|
case "cangchu":
|
|
if empowerCont.PointId != "" {
|
|
powerAry := strings.Split(empowerCont.PointId, ",")
|
|
powerList = GetWmsMenuPower(powerAry)
|
|
}
|
|
default:
|
|
if empowerCont.PointId != "" {
|
|
powerAry := strings.Split(empowerCont.PointId, ",")
|
|
powerList = GetSysAppMenuPower(powerAry)
|
|
}
|
|
|
|
}
|
|
sendData := publicmethod.MapOut[string]()
|
|
sendData["powerList"] = powerList
|
|
sendData["level"] = empowerCont.Level
|
|
publicmethod.Result(0, sendData, c)
|
|
}
|
|
|
|
/*
|
|
获取平台菜单权限
|
|
@menusPower 以获得的权限
|
|
*/
|
|
func GetSysAppMenuPower(menusPower []string) (powersList []string) {
|
|
var permList []int64
|
|
err := overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.Menus{}).Select("`perm`").Where("visible IN ?", []int{1, 2}).Find(&permList).Error
|
|
if err != nil {
|
|
return
|
|
}
|
|
for _, v := range permList {
|
|
permStr := strconv.FormatInt(v, 10)
|
|
if publicmethod.IsInTrue[string](permStr, menusPower) {
|
|
powersList = append(powersList, fmt.Sprintf("m_%v", permStr))
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
获取KPI菜单权限
|
|
@menusPower 以获得的权限
|
|
@operPower 以获得的权限
|
|
*/
|
|
func GetSysKpiMenuPower(menusPower, operPower []string) (powersList []string) {
|
|
var menuList []int64
|
|
overall.CONSTANT_DB_Master.Model(&modelsschool.SystemMenuSchool{}).Select("m_id").Where("`m_steat` = 1").Order("`m_sort` ASC").Order("`m_sort` ASC").Order("`m_id` DESC").Find(&menuList)
|
|
fmt.Printf("menuList--->%v\n", menuList)
|
|
if len(menuList) > 0 {
|
|
for _, mv := range menuList {
|
|
permStr := strconv.FormatInt(mv, 10)
|
|
if publicmethod.IsInTrue[string](permStr, menusPower) {
|
|
powersList = append(powersList, fmt.Sprintf("m_%v", permStr))
|
|
}
|
|
}
|
|
}
|
|
var operList []modelsschool.MenuOperation
|
|
overall.CONSTANT_DB_Master.Order("menu_id asc").Find(&operList)
|
|
fmt.Printf("operList--->%v\n", operList)
|
|
if len(operList) > 0 {
|
|
for _, ov := range operList {
|
|
operIdStr := strconv.FormatInt(ov.OperId, 10)
|
|
menuIdStr := strconv.FormatInt(ov.MenuId, 10)
|
|
if publicmethod.IsInTrue[string](operIdStr, operPower) {
|
|
powersList = append(powersList, fmt.Sprintf("o_%v_%v", menuIdStr, operIdStr))
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
获取仓储菜单权限
|
|
@menusPower 以获得的权限
|
|
*/
|
|
func GetWmsMenuPower(menusPower []string) (powersList []string) {
|
|
var permList []int64
|
|
err := overall.CONSTANT_DB_Storage.Model(&modelsstorage.AccesstoAddress{}).Select("`id`").Where("`state` = 1").Find(&permList).Error
|
|
if err != nil {
|
|
return
|
|
}
|
|
for _, v := range permList {
|
|
permStr := strconv.FormatInt(v, 10)
|
|
if publicmethod.IsInTrue[string](permStr, menusPower) {
|
|
powersList = append(powersList, fmt.Sprintf("m_%v", permStr))
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2023-05-30 14:36:57
|
|
@ 功能: 获取角色已配置的权限
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) GetRoleGrantPowers(c *gin.Context) {
|
|
var requestData GetRolePowerCont
|
|
err := c.ShouldBindJSON(&requestData)
|
|
if err != nil {
|
|
publicmethod.Result(100, err, c)
|
|
return
|
|
}
|
|
if requestData.RoleId == "" || requestData.RoleId == "0" {
|
|
publicmethod.Result(1, requestData, c, "未知角色!不可进行配权")
|
|
return
|
|
}
|
|
if requestData.SystemName == "" {
|
|
publicmethod.Result(1, requestData, c, "未知配权系统!不可进行配权")
|
|
return
|
|
}
|
|
var powerList []string
|
|
var empowerCont modelssystempermission.RoleEmpower
|
|
err = empowerCont.GetCont(map[string]interface{}{"`role_id`": requestData.RoleId, "`system`": requestData.SystemName}, "`id`", "`point_id`", "`operation`", "`level`")
|
|
if err != nil {
|
|
publicmethod.Result(0, powerList, c)
|
|
return
|
|
}
|
|
switch requestData.SystemName {
|
|
case "kpi":
|
|
if empowerCont.PointId != "" || empowerCont.Operation != "" {
|
|
powerAry := strings.Split(empowerCont.PointId, ",")
|
|
opeartionAry := strings.Split(empowerCont.Operation, ",")
|
|
powerList = GetSysKpiMenuPower(powerAry, opeartionAry)
|
|
}
|
|
case "cangchu":
|
|
fmt.Printf("仓储--->%v\n", empowerCont.PointId)
|
|
if empowerCont.PointId != "" {
|
|
powerAry := strings.Split(empowerCont.PointId, ",")
|
|
powerList = GetWmsMenuPower(powerAry)
|
|
fmt.Printf("仓储--111->%v\n", powerList)
|
|
}
|
|
default:
|
|
if empowerCont.PointId != "" {
|
|
powerAry := strings.Split(empowerCont.PointId, ",")
|
|
powerList = GetSysAppMenuPower(powerAry)
|
|
}
|
|
|
|
}
|
|
sendData := publicmethod.MapOut[string]()
|
|
sendData["powerList"] = powerList
|
|
sendData["level"] = empowerCont.Level
|
|
publicmethod.Result(0, sendData, c)
|
|
}
|
|
|