package publicmethod
import (
"appPlatform/models/modelshr"
"appPlatform/models/modelssystempermission"
"appPlatform/overall"
"encoding/json"
"fmt"
"strconv"
"strings"
"gorm.io/gorm"
)
/ *
*
@ 作者 : 秦东
@ 时间 : 2025 - 05 - 21 0 8 : 44 : 35
@ 功能 : 获取用户权限
@ 参数
#
@ 返回值
#
@ 方法原型
#
* /
func ( g * GainUserPower ) GetUserPower ( ) ( powerInfo SendUserPower ) {
//正常系统权限配置
orgLook := [ ] int64 { }
if g . RoleId != "" {
roleAry := strings . Split ( g . RoleId , "," )
if len ( roleAry ) > 0 {
var rolePowerList [ ] modelssystempermission . RoleEmpower
overall . CONSTANT_DB_System_Permission . Model ( & modelssystempermission . RoleEmpower { } ) . Where ( "`state` = 1 AND `system` = ? AND `role_id` IN ?" , g . SystemName , roleAry ) . Find ( & rolePowerList )
for _ , v := range rolePowerList {
fmt . Printf ( "Level------------->%v\n\n" , v . Level )
if v . Level >= powerInfo . System . Level {
powerInfo . System . Level = v . Level
}
if v . PointId != "" {
pointIdAry := strings . Split ( v . PointId , "," )
for _ , pv := range pointIdAry {
if ! IsInTrue [ string ] ( pv , powerInfo . System . PointId ) {
powerInfo . System . PointId = append ( powerInfo . System . PointId , pv )
}
}
}
if v . Operation != "" {
operationAry := strings . Split ( v . Operation , "," )
for _ , ov := range operationAry {
if ! IsInTrue [ string ] ( ov , powerInfo . System . Operation ) {
powerInfo . System . Operation = append ( powerInfo . System . Operation , ov )
}
}
}
if v . Organization != "" {
orgtionAry := strings . Split ( v . Organization , "," )
for _ , pv := range orgtionAry {
pvInt , _ := strconv . ParseInt ( pv , 10 , 64 )
if ! IsInTrue [ int64 ] ( pvInt , orgLook ) {
orgLook = append ( orgLook , pvInt )
}
}
}
}
}
}
if g . PostId != 0 && g . OrgId != 0 {
var postPower modelssystempermission . Empower
postPower . GetCont ( map [ string ] interface { } { "`state`" : 1 , "`ordid`" : g . OrgId , "`post_id`" : g . PostId , "`system`" : g . SystemName } )
if postPower . Level >= powerInfo . System . Level {
powerInfo . System . Level = postPower . Level
}
if postPower . PointId != "" {
pointIdAry := strings . Split ( postPower . PointId , "," )
for _ , pv := range pointIdAry {
if ! IsInTrue [ string ] ( pv , powerInfo . System . PointId ) {
powerInfo . System . PointId = append ( powerInfo . System . PointId , pv )
}
}
}
if postPower . Operation != "" {
operationAry := strings . Split ( postPower . Operation , "," )
for _ , ov := range operationAry {
if ! IsInTrue [ string ] ( ov , powerInfo . System . Operation ) {
powerInfo . System . Operation = append ( powerInfo . System . Operation , ov )
}
}
}
if postPower . Organization != "" {
orgtionAry := strings . Split ( postPower . Organization , "," )
for _ , pv := range orgtionAry {
pvInt , _ := strconv . ParseInt ( pv , 10 , 64 )
if ! IsInTrue [ int64 ] ( pvInt , orgLook ) {
orgLook = append ( orgLook , pvInt )
}
}
}
}
_ , companyId , departmentId , _ , workShopId := GetOrgStructure ( g . OrgId )
switch powerInfo . System . Level {
case 1 :
powerInfo . System . OrgList = [ ] int64 { }
var sunOrg GetOrgAllParent
sunOrg . GetOrgSun ( workShopId )
sunOrg . Id = append ( sunOrg . Id , workShopId )
powerInfo . System . OrgList = append ( powerInfo . System . OrgList , sunOrg . Id ... )
case 2 :
powerInfo . System . OrgList = [ ] int64 { }
var sunOrgDepart GetOrgAllParent
sunOrgDepart . GetOrgSun ( departmentId )
sunOrgDepart . Id = append ( sunOrgDepart . Id , departmentId )
powerInfo . System . OrgList = append ( powerInfo . System . OrgList , sunOrgDepart . Id ... )
case 3 :
powerInfo . System . OrgList = [ ] int64 { }
var sunOrgCompan GetOrgAllParent
sunOrgCompan . GetOrgSun ( companyId )
sunOrgCompan . Id = append ( sunOrgCompan . Id , companyId )
powerInfo . System . OrgList = append ( powerInfo . System . OrgList , sunOrgCompan . Id ... )
case 4 :
powerInfo . System . OrgList = orgLook
case 5 :
powerInfo . System . OrgList = [ ] int64 { }
default :
}
//低代码权限系统配置
if g . RoleId != "" {
orgLookApp := [ ] int64 { }
roleAry := strings . Split ( g . RoleId , "," )
if len ( roleAry ) > 0 {
var tablePower [ ] modelssystempermission . CustomTableAuthorize
overall . CONSTANT_DB_System_Permission . Model ( & modelssystempermission . CustomTableAuthorize { } ) . Where ( "`app_sign_code` = ? AND `table_sign_code` = ? AND `role_id` IN ?" , g . AppKey , g . TableId , roleAry ) . Find ( & tablePower )
for _ , v := range tablePower {
if v . PowerLerver >= powerInfo . System . Level {
powerInfo . AppSystem . Level = v . PowerLerver
}
if v . TablePower != "" {
tableAry := strings . Split ( v . TablePower , "," )
for _ , tv := range tableAry {
if ! IsInTrue [ string ] ( tv , powerInfo . AppSystem . PointId ) {
powerInfo . AppSystem . PointId = append ( powerInfo . AppSystem . PointId , tv )
}
}
}
if v . ListPower != "" {
listAry := strings . Split ( v . ListPower , "," )
for _ , lv := range listAry {
if ! IsInTrue [ string ] ( lv , powerInfo . AppSystem . Operation ) {
powerInfo . AppSystem . Operation = append ( powerInfo . AppSystem . Operation , lv )
}
}
}
if v . Organization != "" {
orgtionAry := strings . Split ( v . Organization , "," )
for _ , pv := range orgtionAry {
pvInt , _ := strconv . ParseInt ( pv , 10 , 64 )
if ! IsInTrue [ int64 ] ( pvInt , orgLookApp ) {
orgLookApp = append ( orgLookApp , pvInt )
}
}
}
}
switch powerInfo . AppSystem . Level {
case 2 :
powerInfo . AppSystem . OrgList = [ ] int64 { }
var sunOrg GetOrgAllParent
sunOrg . GetOrgSun ( workShopId )
sunOrg . Id = append ( sunOrg . Id , workShopId )
powerInfo . AppSystem . OrgList = append ( powerInfo . AppSystem . OrgList , sunOrg . Id ... )
case 3 :
powerInfo . AppSystem . OrgList = [ ] int64 { }
var sunOrgDepart GetOrgAllParent
sunOrgDepart . GetOrgSun ( departmentId )
sunOrgDepart . Id = append ( sunOrgDepart . Id , departmentId )
powerInfo . AppSystem . OrgList = append ( powerInfo . AppSystem . OrgList , sunOrgDepart . Id ... )
case 4 :
powerInfo . AppSystem . OrgList = [ ] int64 { }
var sunOrgCompan GetOrgAllParent
sunOrgCompan . GetOrgSun ( companyId )
sunOrgCompan . Id = append ( sunOrgCompan . Id , companyId )
powerInfo . AppSystem . OrgList = append ( powerInfo . AppSystem . OrgList , sunOrgCompan . Id ... )
case 5 :
powerInfo . AppSystem . OrgList = orgLookApp
case 6 :
powerInfo . AppSystem . OrgList = [ ] int64 { }
default :
}
}
}
fmt . Printf ( "powerInfo.System.Level------------->%v\n\n" , powerInfo . System . Level )
return
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2025 - 05 - 22 13 : 53 : 17
@ 功能 : 权限结构查询语句
@ 参数
授权范围等级 ( 1 : 本人 ; 2 : 本岗位 ; 3 : 本部门 ; 4 : 本分部 ; 5 : 指定行政组织 ; 6 : 所有 )
#
@ 返回值
#
@ 方法原型
#
* /
func ( g * GainUserPower ) MakeSearchSql ( gormDb * gorm . DB , userCont modelshr . ManCont , isOdeb string ) * gorm . DB {
powerInfo := g . GetUserPower ( )
// js, _ := json.Marshal(powerInfo)
fmt . Printf ( "\n\n\n等级-----%v--- ---->%v\n\n\n" , isOdeb , powerInfo )
if isOdeb == "yes" {
switch powerInfo . AppSystem . Level {
case 2 , 3 , 4 , 5 :
if len ( powerInfo . AppSystem . OrgList ) > 0 {
gormDb = gormDb . Where ( "`createrOrg` IN ?" , powerInfo . AppSystem . OrgList )
} else {
gormDb = gormDb . Where ( "`creater` = ?" , userCont . Key )
}
case 6 :
default :
gormDb = gormDb . Where ( "`creater` = ?" , userCont . Key )
}
} else {
switch powerInfo . AppSystem . Level {
case 2 , 3 , 4 , 5 :
if len ( powerInfo . AppSystem . OrgList ) > 0 {
gormDb = gormDb . Where ( "f.`createrOrg` IN ?" , powerInfo . AppSystem . OrgList )
} else {
gormDb = gormDb . Where ( "f.`creater` = ?" , userCont . Key )
}
fmt . Printf ( "语句7===》%v\n" , powerInfo . AppSystem )
case 6 :
fmt . Printf ( "语句8===》%v\n" , powerInfo . AppSystem )
default :
fmt . Printf ( "语句9===》%v\n" , powerInfo . AppSystem )
// gormDb = gormDb.Where("f.`creater` = ?", userCont.Key)
}
}
return gormDb
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2025 - 11 - 21 0 9 : 38 : 23
@ 功能 : 根据系统参数获取权限
* /
func GetSystemPower ( powerType , systemTyep , powerId , systemId string ) ( powerInfo SendSystemPower ) {
powerInfo . PowerType = powerType
powerInfo . SystemTyep = systemTyep
powerInfo . PowerId = powerId
powerInfo . SystemId = systemId
powerInfo . SystemIsPick = false
if powerType == "" || systemTyep == "" || powerId == "" {
return
}
if systemId != "system" && systemId == "" {
return
}
var masterPower modelssystempermission . AuthPower
gormDb := overall . CONSTANT_DB_System_Permission . Model ( & masterPower ) . Where ( "`orgPowerType` = ? AND `orgOrUserKey` = ? AND `appType` = ?" , powerType , powerId , systemTyep )
switch systemTyep {
case "app" :
gormDb = gormDb . Where ( "`appKey` = ?" , systemId )
case "system" :
gormDb = gormDb . Where ( "`appKey` = 0" )
default :
}
err := gormDb . First ( & masterPower ) . Error
if err != nil {
return
}
if masterPower . IsTrue == 1 {
powerInfo . SystemIsPick = true
}
var poserList [ ] modelssystempermission . PowerInfo
overall . CONSTANT_DB_System_Permission . Model ( & modelssystempermission . PowerInfo { } ) . Where ( "`authId` = ?" , masterPower . Id ) . Find ( & poserList )
if len ( poserList ) > 0 {
for _ , v := range poserList {
var itemContent ItemInfo
itemContent . ItemId = v . ItemId
itemContent . IsPick = false
if v . IsPick == 1 {
itemContent . IsPick = true
}
if v . TablePower != "" && v . TablePower != "null" {
json . Unmarshal ( [ ] byte ( v . TablePower ) , & itemContent . TablePower )
}
if v . ListPower != "" && v . ListPower != "null" {
json . Unmarshal ( [ ] byte ( v . ListPower ) , & itemContent . ListPower )
}
if v . ButPower != "" && v . ButPower != "null" {
json . Unmarshal ( [ ] byte ( v . ButPower ) , & itemContent . ButPower )
}
itemContent . VisibleRange = v . VisibleRange
if v . VisibleOrg != "" && v . VisibleOrg != "null" {
json . Unmarshal ( [ ] byte ( v . VisibleOrg ) , & itemContent . VisibleOrg )
}
powerInfo . PowerList = append ( powerInfo . PowerList , itemContent )
}
}
return
}
/ *
*
@ 作者 : 秦东
@ 时间 : 2025 - 11 - 21 16 : 34 : 31
@ 功能 : 自定义应用权限
* /
func GetSystemAppPower ( powerType , systemTyep , powerId string ) ( powerAry [ ] SendSystemAppPower ) {
// powerInfo.PowerType = powerType
// powerInfo.SystemTyep = systemTyep
// powerInfo.PowerId = powerId
// powerInfo.SystemId = systemId
// powerInfo.SystemIsPick = false
if powerType == "" || systemTyep == "" || powerId == "" {
return
}
var masterPower [ ] modelssystempermission . AuthPower
err := overall . CONSTANT_DB_System_Permission . Where ( "`orgPowerType` = ? AND `orgOrUserKey` = ? AND `appType` = ?" , powerType , powerId , systemTyep ) . Find ( & masterPower ) . Error
if err != nil {
return
}
for _ , v := range masterPower {
var powerInfo SendSystemAppPower
powerInfo . PowerType = powerType
powerInfo . SystemTyep = systemTyep
powerInfo . PowerId = powerId
powerInfo . SystemId = v . AppKey
powerInfo . SystemIsPick = false
if v . IsTrue == 1 {
powerInfo . SystemIsPick = true
}
powerAry = append ( powerAry , powerInfo )
}
return
}