11 changed files with 278 additions and 23 deletions
@ -0,0 +1,150 @@ |
|||||
|
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`") |
||||
|
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) |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
publicmethod.Result(0, powerList, 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_AppPlatform.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 |
||||
|
} |
||||
@ -0,0 +1,41 @@ |
|||||
|
package grantpowers |
||||
|
|
||||
|
import ( |
||||
|
"appPlatform/overall/publicmethod" |
||||
|
|
||||
|
"github.com/gin-gonic/gin" |
||||
|
) |
||||
|
|
||||
|
type ApiMethod struct{} |
||||
|
|
||||
|
/* |
||||
|
* |
||||
|
@ 作者: 秦东 |
||||
|
@ 时间: 2023-05-29 11:57:53 |
||||
|
@ 功能: 系统授权 |
||||
|
@ 参数 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 返回值 |
||||
|
|
||||
|
# |
||||
|
|
||||
|
@ 方法原型 |
||||
|
|
||||
|
# |
||||
|
*/ |
||||
|
func (a *ApiMethod) Index(c *gin.Context) { |
||||
|
outputCont := publicmethod.MapOut[string]() |
||||
|
outputCont["index"] = "系统授权" |
||||
|
publicmethod.Result(0, outputCont, c) |
||||
|
} |
||||
|
|
||||
|
/* |
||||
|
根据系统获取岗位已配置的权限 |
||||
|
*/ |
||||
|
type GetPostPowerCont struct { |
||||
|
OrdId string `json:"ordid"` //行政组织
|
||||
|
PostId string `json:"postid"` //岗位
|
||||
|
SystemName string `json:"name"` //系统识别符
|
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
package grantsystempower |
||||
|
|
||||
|
import ( |
||||
|
"appPlatform/api/version1" |
||||
|
|
||||
|
"github.com/gin-gonic/gin" |
||||
|
) |
||||
|
|
||||
|
// 权力配置
|
||||
|
func (a *ApiRouter) RouterGroupPc(router *gin.RouterGroup) { |
||||
|
apiRouter := router.Group("grant") |
||||
|
|
||||
|
var methodBinding = version1.AppApiEntry.GranSystemPowerApi |
||||
|
{ |
||||
|
apiRouter.GET("", methodBinding.Index) //入口
|
||||
|
apiRouter.POST("", methodBinding.Index) //入口
|
||||
|
apiRouter.POST("get_post_grant_powers", methodBinding.GetPostGrantPowers) //获取岗位已配置的权限
|
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,4 @@ |
|||||
|
package grantsystempower |
||||
|
|
||||
|
//菜单路由
|
||||
|
type ApiRouter struct{} |
||||
Loading…
Reference in new issue