应用集成平台服务端
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.
 
 
 

487 lines
17 KiB

package user
import (
"appPlatform/models/modelAppPlatform"
"appPlatform/models/modelssystempermission"
"appPlatform/overall"
"appPlatform/overall/publicmethod"
"encoding/json"
"fmt"
"strconv"
)
/*
*
@ 作者: 秦东
@ 时间: 2025-11-24 08:30:44
@ 功能: 获取个人系统权限
*/
func GetMyPower(powerType string, oupk, org, poetId int64) (allPower SendAllPower, err error) {
//获取系统权限
var systemPower []modelssystempermission.AuthPowerList
err = overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.AuthPowerList{}).Where("`appType` = 'system' AND `orgPowerType` = 'person' AND `orgOrUserKey` = ? AND `appKey` = 0", oupk).Find(&systemPower).Error
fmt.Printf("\n\nsystemPower--------->%v----->%v\n\n", oupk, systemPower)
if len(systemPower) > 0 { //首先判断个人是否已经赋权
for _, v := range systemPower {
var sysPower SystemInfoPower
sysPower.AppId = strconv.FormatInt(v.ItemId, 10)
if v.IsPick == 1 {
sysPower.IsPick = true
if !publicmethod.IsInTrue[int64](v.ItemId, allPower.MenuIdAry) {
allPower.MenuIdAry = append(allPower.MenuIdAry, v.ItemId)
}
} else {
sysPower.IsPick = false
}
if v.ButPower != "" && v.ButPower != "null" {
json.Unmarshal([]byte(v.ButPower), &sysPower.ButIdAry)
}
sysPower.Scope = v.VisibleRange
if v.VisibleRange == 5 && v.ButPower != "" && v.ButPower != "null" {
json.Unmarshal([]byte(v.VisibleOrg), &sysPower.ScopeManAry)
}
allPower.SystemPower = append(allPower.SystemPower, sysPower)
}
} else {
// var systemPower []modelssystempermission.AuthPowerList
// err = overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.AuthPowerList{}).Where("`appType` = 'system' AND `orgPowerType` IN ('org','job','role') AND `orgOrUserKey` = ? AND `appKey` = 0", oupk).Find(&systemPower).Error
var mySysMenuPower XieChengPowerSys
mySysMenuPower.GetPowerSystem(systemPower)
allPower.MenuIdAry = mySysMenuPower.MenuId
allPower.SystemPower = mySysMenuPower.SystemPower
syncSeting.Add(1)
go mySysMenuPower.GetOrgSysPower("system", "org", org)
syncSeting.Add(1)
go mySysMenuPower.GetOrgSysPower("system", "job", poetId)
syncSeting.Add(1)
go mySysMenuPower.GetOrgSysPower("system", "role", oupk)
syncSeting.Wait()
mySysMenuPower.GetPowerSystem(mySysMenuPower.SysTemList)
allPower.MenuIdAry = mySysMenuPower.MenuId
var menuList []modelAppPlatform.Menus
if len(mySysMenuPower.MenuId) > 0 {
overall.CONSTANT_DB_AppPlatform.Model(&modelAppPlatform.Menus{}).Select("`id`,`name`").Where("`id` IN ?", mySysMenuPower.MenuId).Find(&menuList)
}
for _, v := range menuList {
for si, sv := range mySysMenuPower.SystemPower {
if strconv.Itoa(v.Id) == sv.AppId {
mySysMenuPower.SystemPower[si].Name = v.Name
}
}
}
allPower.SystemPower = mySysMenuPower.SystemPower
}
//获取自定义表单权限
var appPower []modelssystempermission.AuthPower
overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.AuthPower{}).Where("`appType` = 'app' AND `orgPowerType` = 'person' AND `orgOrUserKey` = ?", oupk).Find(&appPower)
if len(appPower) > 0 { //首先判断个人是否已经赋权
for _, v := range appPower {
var myAppInfo AppMyPower
myAppInfo.AppId = strconv.FormatInt(v.AppKey, 10)
if v.IsTrue == 1 {
allPower.AppKeyAry = append(allPower.AppKeyAry, strconv.FormatInt(v.AppKey, 10))
myAppInfo.IsPick = true
} else {
myAppInfo.IsPick = false
}
myAppInfo.FormTrue, myAppInfo.FormPower = GetTablePower(v.Id)
allPower.AppSystemPower = append(allPower.AppSystemPower, myAppInfo)
}
} else {
var myAppPower XieChengPowerSys
syncSeting.Add(1)
go myAppPower.GetAppFormPower("app", "org", org)
syncSeting.Add(1)
go myAppPower.GetAppFormPower("app", "job", poetId)
syncSeting.Add(1)
go myAppPower.GetAppFormPower("app", "role", oupk)
syncSeting.Wait()
var tableId []string
for _, v := range myAppPower.AppUUID {
if !publicmethod.IsInTrue[string](v, tableId) {
tableId = append(tableId, v)
}
}
allPower.AppKeyAry = tableId
allPower.AppSystemPower = MergePower(myAppPower.FormTable)
}
return
}
// 合并组织、角色、岗位权限
func MergePower(FormTable []AppMyPower) (list []AppMyPower) {
for _, v := range FormTable { //循环所有授权
isNewApp := true
for li, lv := range list { //循环已合并过的授权
if v.AppId == lv.AppId { //判断在已合并中是否已经存在
isNewApp = false
for _, fv := range v.FormTrue { //合并App中已经授权的表单
if !publicmethod.IsInTrue[string](fv, lv.FormTrue) {
list[li].FormTrue = append(list[li].FormTrue, fv)
}
}
for _, pv := range v.FormPower { //相应表单权限细节整合
if pv.IsPick {
if !publicmethod.IsInTrue[string](pv.AppId, list[li].FormTrue) {
list[li].FormTrue = append(list[li].FormTrue, pv.AppId)
}
}
isNewTable := true
for fpi, fpv := range lv.FormPower {
if pv.AppId == fpv.AppId {
isNewTable = false
list[li].FormPower[fpi].ListPower = publicmethod.MergeStruct[string](pv.ListPower, fpv.ListPower)
list[li].FormPower[fpi].TablePower = publicmethod.MergeStruct[string](pv.TablePower, fpv.TablePower)
if pv.Scope < 1 {
pv.Scope = 1
}
if pv.Scope >= fpv.Scope {
list[li].FormPower[fpi].Scope = pv.Scope
list[li].FormPower[fpi].ScopeManAry = publicmethod.MergeStruct[int](pv.ScopeManAry, fpv.ScopeManAry)
}
}
}
if isNewTable {
list[li].FormPower = append(list[li].FormPower, pv)
}
}
}
}
if isNewApp {
list = append(list, v)
}
}
return
}
// 自定义App
func (x *XieChengPowerSys) GetAppFormPower(sysType, powerType string, key int64) {
defer syncSeting.Done()
switch powerType {
case "org":
//Step 1:获取可见App
var appAuthPower []modelssystempermission.AuthPower
overall.CONSTANT_DB_System_Permission.Where("`appType` = ? AND `orgPowerType` = ? AND `orgOrUserKey` = ? AND `appKey` <> 0", sysType, powerType, key).Find(&appAuthPower)
if len(appAuthPower) > 0 {
for _, v := range appAuthPower {
appKeyStr := strconv.FormatInt(v.AppKey, 10)
var appSetUpPower AppMyPower
appSetUpPower.AppId = appKeyStr
if v.IsTrue == 1 {
appSetUpPower.IsPick = true
if !publicmethod.IsInTrue[string](appKeyStr, x.AppUUID) {
x.AppUUID = append(x.AppUUID, appKeyStr)
}
} else {
appSetUpPower.IsPick = false
}
appSetUpPower.FormTrue, appSetUpPower.FormPower = GetMyAppTableForm(v.Id)
x.FormTable = append(x.FormTable, appSetUpPower)
}
} else {
var allFirstOrgId publicmethod.GetOrgAllParent
allFirstOrgId.GetOrgFirst(key)
if len(allFirstOrgId.Id) > 0 { //继承最近父级授权
for _, v := range allFirstOrgId.Id {
var appAuthFirstPower []modelssystempermission.AuthPower
overall.CONSTANT_DB_System_Permission.Where("`appType` = ? AND `orgPowerType` = ? AND `orgOrUserKey` = ? AND `appKey` <> 0", sysType, powerType, v).Find(&appAuthFirstPower)
if len(appAuthFirstPower) > 0 {
for _, v := range appAuthFirstPower {
appKeyStr := strconv.FormatInt(v.AppKey, 10)
var appSetUpPower AppMyPower
appSetUpPower.AppId = appKeyStr
if v.IsTrue == 1 {
appSetUpPower.IsPick = true
if !publicmethod.IsInTrue[string](appKeyStr, x.AppUUID) {
x.AppUUID = append(x.AppUUID, appKeyStr)
}
} else {
appSetUpPower.IsPick = false
}
appSetUpPower.FormTrue, appSetUpPower.FormPower = GetMyAppTableForm(v.Id)
x.FormTable = append(x.FormTable, appSetUpPower)
}
}
}
}
}
case "role":
var roleId []int64
overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.SystemRole{}).Select("`id`").Where("FIND_IN_SET(?, `superior`)", key).Find(&roleId)
if len(roleId) > 0 {
var appAuthPower []modelssystempermission.AuthPower
overall.CONSTANT_DB_System_Permission.Where("`appType` = ? AND `orgPowerType` = ? AND `orgOrUserKey` IN ? AND `appKey` <> 0", sysType, powerType, roleId).Find(&appAuthPower)
if len(appAuthPower) > 0 {
for _, v := range appAuthPower {
appKeyStr := strconv.FormatInt(v.AppKey, 10)
var appSetUpPower AppMyPower
appSetUpPower.AppId = appKeyStr
if v.IsTrue == 1 {
appSetUpPower.IsPick = true
if !publicmethod.IsInTrue[string](appKeyStr, x.AppUUID) {
x.AppUUID = append(x.AppUUID, appKeyStr)
}
} else {
appSetUpPower.IsPick = false
}
appSetUpPower.FormTrue, appSetUpPower.FormPower = GetMyAppTableForm(v.Id)
x.FormTable = append(x.FormTable, appSetUpPower)
}
}
}
default:
var appAuthPower []modelssystempermission.AuthPower
overall.CONSTANT_DB_System_Permission.Where("`appType` = ? AND `orgPowerType` = ? AND `orgOrUserKey` = ? AND `appKey` <> 0", sysType, powerType, key).Find(&appAuthPower)
if len(appAuthPower) > 0 {
for _, v := range appAuthPower {
appKeyStr := strconv.FormatInt(v.AppKey, 10)
var appSetUpPower AppMyPower
appSetUpPower.AppId = appKeyStr
if v.IsTrue == 1 {
appSetUpPower.IsPick = true
if !publicmethod.IsInTrue[string](appKeyStr, x.AppUUID) {
x.AppUUID = append(x.AppUUID, appKeyStr)
}
} else {
appSetUpPower.IsPick = false
}
appSetUpPower.FormTrue, appSetUpPower.FormPower = GetMyAppTableForm(v.Id)
x.FormTable = append(x.FormTable, appSetUpPower)
}
}
}
}
// 获取自定义App表单
func GetMyAppTableForm(authid int64) (formId []string, list []AppMyPowerTable) {
var formListPow []modelssystempermission.PowerInfo
overall.CONSTANT_DB_System_Permission.Where("`authId` = ? ", authid).Find(&formListPow)
for _, v := range formListPow {
idStr := strconv.FormatInt(v.ItemId, 10)
var formInfo AppMyPowerTable
formInfo.AppId = idStr
if v.IsPick == 1 {
formInfo.IsPick = true
if !publicmethod.IsInTrue[string](idStr, formId) {
formId = append(formId, idStr)
}
} else {
formInfo.IsPick = false
}
if v.ListPower != "" && v.ListPower != "null" {
json.Unmarshal([]byte(v.ListPower), &formInfo.ListPower)
}
if v.TablePower != "" && v.TablePower != "null" {
json.Unmarshal([]byte(v.TablePower), &formInfo.TablePower)
}
if v.VisibleRange == 0 {
v.VisibleRange = 1
}
formInfo.Scope = v.VisibleRange
if v.VisibleOrg != "" && v.VisibleOrg != "null" {
json.Unmarshal([]byte(v.VisibleOrg), &formInfo.ScopeManAry)
}
list = append(list, formInfo)
}
return
}
// 系统菜单
func (x *XieChengPowerSys) GetOrgSysPower(sysType, powerType string, key int64) {
defer syncSeting.Done()
// var systemPower []modelssystempermission.AuthPowerList
goromDb := overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.AuthPowerList{}).Where("`appType` = ? AND `orgPowerType` = ? AND `appKey` = 0", sysType, powerType)
switch powerType {
case "org":
var orgPowList []modelssystempermission.AuthPowerList
overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.AuthPowerList{}).Where("`appType` = ? AND `orgPowerType` = ? AND `appKey` = 0 AND `orgOrUserKey` = ? ", sysType, powerType, key).Find(&orgPowList)
if len(orgPowList) > 0 {
x.SysTemList = append(x.SysTemList, orgPowList...)
} else {
var allFirstOrgId publicmethod.GetOrgAllParent
allFirstOrgId.GetOrgFirst(key)
if len(allFirstOrgId.Id) > 0 {
for _, v := range allFirstOrgId.Id {
var fatherOrgPower []modelssystempermission.AuthPowerList
overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.AuthPowerList{}).Where("`appType` = ? AND `orgPowerType` = ? AND `appKey` = 0 AND `orgOrUserKey` = ?", sysType, powerType, v).Find(&fatherOrgPower)
if len(fatherOrgPower) > 0 {
fmt.Printf("Org--%v--->%v\n\n", v, len(fatherOrgPower))
x.SysTemList = append(x.SysTemList, fatherOrgPower...)
break
}
}
}
}
// var allFirstOrgId publicmethod.GetOrgAllParent
// allFirstOrgId.GetOrgFirst(key)
// allFirstOrgId.Id = append(allFirstOrgId.Id, key)
// goromDb = goromDb.Where("`orgOrUserKey` IN ?", allFirstOrgId.Id)
// goromDb.Find(&x.SysTemList)
case "role":
var roleId []int64
overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.SystemRole{}).Select("`id`").Where("FIND_IN_SET(?, `roleuser`)", key).Find(&roleId)
fmt.Printf("role----->%v----->%v\n\n", roleId, len(roleId))
if len(roleId) > 0 {
goromDb = goromDb.Where("`orgOrUserKey` IN ?", roleId)
goromDb.Find(&x.SysTemList)
}
default:
// fmt.Printf("post----->%v\n\n", key)
goromDb = goromDb.Where("`orgOrUserKey` = ?", key)
goromDb.Find(&x.SysTemList)
}
// if len(systemPower) > 0 {
// x.GetPowerSystem(systemPower)
// }
}
func (x *XieChengPowerSys) GetPowerSystem(list []modelssystempermission.AuthPowerList) {
// fmt.Printf("管理范围----list--->%v--->%v\n\n\n", len(list), len(x.SystemPower))
for _, v := range list {
// fmt.Printf("管理范围----list--->%v--->%v--->%v\n\n\n", len(list), v.VisibleRange, len(v.VisibleOrg))
appId := strconv.FormatInt(v.ItemId, 10)
if len(x.SystemPower) > 0 { //判断是否已经存在该项赋值
isWrite := true
for xi, xv := range x.SystemPower {
if appId == xv.AppId { //存在赋值,修改
// fmt.Printf("管理范围-----%v----->%v----->%v\n\n\n", appId, v.VisibleRange, xv.Scope)
isWrite = false
if v.IsPick == 1 {
x.SystemPower[xi].IsPick = true
}
if v.ButPower != "" && v.ButPower != "null" {
var butPow []int64
json.Unmarshal([]byte(v.ButPower), &butPow)
for _, bv := range butPow {
if !publicmethod.IsInTrue[int64](bv, x.SystemPower[xi].ButIdAry) {
x.SystemPower[xi].ButIdAry = append(x.SystemPower[xi].ButIdAry, bv)
}
}
}
if v.VisibleRange == 0 {
v.VisibleRange = 1
}
if v.VisibleRange > xv.Scope {
x.SystemPower[xi].Scope = v.VisibleRange
if v.VisibleOrg != "" && v.VisibleOrg != "null" {
var visAry []int
json.Unmarshal([]byte(v.VisibleOrg), &visAry)
for _, vv := range visAry {
if !publicmethod.IsInTrue[int](vv, x.SystemPower[xi].ScopeManAry) {
x.SystemPower[xi].ScopeManAry = append(x.SystemPower[xi].ScopeManAry, vv)
}
}
}
}
}
}
if isWrite { //没有赋值新增
var menuPower SystemInfoPower
menuPower.AppId = appId
if v.IsPick == 1 {
menuPower.IsPick = true
} else {
menuPower.IsPick = false
}
if v.ButPower != "" && v.ButPower != "null" {
json.Unmarshal([]byte(v.ButPower), &menuPower.ButIdAry)
} else {
menuPower.ButIdAry = []int64{}
}
if v.VisibleRange == 0 {
v.VisibleRange = 1
}
menuPower.Scope = v.VisibleRange
if v.VisibleOrg != "" && v.VisibleOrg != "null" {
json.Unmarshal([]byte(v.VisibleOrg), &menuPower.ScopeManAry)
} else {
menuPower.ScopeManAry = []int{}
}
x.SystemPower = append(x.SystemPower, menuPower)
}
} else { //没有赋值新增
var menuPower SystemInfoPower
menuPower.AppId = appId
if v.IsPick == 1 {
menuPower.IsPick = true
} else {
menuPower.IsPick = false
}
if v.ButPower != "" && v.ButPower != "null" {
json.Unmarshal([]byte(v.ButPower), &menuPower.ButIdAry)
} else {
menuPower.ButIdAry = []int64{}
}
menuPower.Scope = 1
if v.VisibleRange > menuPower.Scope {
menuPower.Scope = v.VisibleRange
}
if v.VisibleOrg != "" && v.VisibleOrg != "null" {
json.Unmarshal([]byte(v.VisibleOrg), &menuPower.ScopeManAry)
} else {
menuPower.ScopeManAry = []int{}
}
x.SystemPower = append(x.SystemPower, menuPower)
}
if v.IsPick == 1 {
// idStr := strconv.FormatInt(v.ItemId, 10)
if !publicmethod.IsInTrue[int64](v.ItemId, x.MenuId) {
x.MenuId = append(x.MenuId, v.ItemId)
}
}
}
}
/*
*
@ 作者: 秦东
@ 时间: 2025-11-24 14:55:49
@ 功能: 获取自定义表单权限解析
*/
func GetTablePower(authId int64) (itenIdAry []string, TableList []AppMyPowerTable) {
var tableInfo []modelssystempermission.PowerInfo
overall.CONSTANT_DB_System_Permission.Where("`authId` = ?", authId).Find(&tableInfo)
for _, v := range tableInfo {
var formPwInfo AppMyPowerTable
itemIdSte := strconv.FormatInt(v.ItemId, 10)
formPwInfo.AppId = itemIdSte
if v.IsPick == 1 {
if !publicmethod.IsInTrue[string](itemIdSte, itenIdAry) {
itenIdAry = append(itenIdAry, itemIdSte)
}
formPwInfo.IsPick = true
} else {
formPwInfo.IsPick = false
}
formPwInfo.Scope = v.VisibleRange
if v.VisibleRange == 5 && v.ButPower != "" && v.ButPower != "null" {
json.Unmarshal([]byte(v.VisibleOrg), &formPwInfo.ScopeManAry)
}
if v.TablePower != "" && v.TablePower != "null" {
json.Unmarshal([]byte(v.TablePower), &formPwInfo.TablePower)
}
if v.ListPower != "" && v.ListPower != "null" {
json.Unmarshal([]byte(v.ListPower), &formPwInfo.ListPower)
}
TableList = append(TableList, formPwInfo)
}
return
}