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.
421 lines
12 KiB
421 lines
12 KiB
package overallhandle
|
|
|
|
import (
|
|
"fmt"
|
|
"hr_server/grocerystore"
|
|
"hr_server/models"
|
|
"hr_server/models/modelssystempermission"
|
|
"hr_server/overall"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-03-08 13:38:51
|
|
@ 功能: 人员操作记录
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func WritePeopleLog(c *gin.Context, class string, errmsg ...any) {
|
|
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2022-11-19 15:03:42
|
|
@ 功能: 获取系统授权
|
|
@ 参数
|
|
|
|
#roleId 角色ID
|
|
#systemName 系统名称
|
|
#userKey 人员识别码
|
|
#orgId 行政组织
|
|
#postId 岗位
|
|
|
|
@ 返回值
|
|
|
|
#roleName 角色名称
|
|
#pointId 菜单权限
|
|
#operation 操作权限
|
|
#level 操作等级
|
|
|
|
@ 方法原型
|
|
|
|
#func GetNewAccredit(systemName, roleId string, userKey, orgId, postId int64) (roleName, pointId, operation string, level int)
|
|
*/
|
|
func GetNewAccredit(systemName, roleId string, userKey, orgId, postId int64) (roleName, pointId, operation string, level int) {
|
|
redisFileKey := fmt.Sprintf("Licence:PowerLoginApi_%v_%v_%v_%v", systemName, userKey, orgId, postId)
|
|
redisClient := grocerystore.RunRedis(overall.CONSTANT_REDIS3)
|
|
userRedisToken, isTrue := redisClient.HashGetAll(redisFileKey)
|
|
if isTrue == false {
|
|
var pointIdAry []string
|
|
var operationAry []string
|
|
if roleId != "" {
|
|
roleIdAry := strings.Split(roleId, ",")
|
|
var roleCont []modelssystempermission.SystemRole
|
|
if len(roleIdAry) > 0 {
|
|
err := overall.CONSTANT_DB_Master.Model(&modelssystempermission.SystemRole{}).Select("`name`").Where("`id` IN ?", roleIdAry).Find(&roleCont).Error
|
|
if err == nil && len(roleCont) > 0 {
|
|
var roleNameAry []string
|
|
for _, rnv := range roleCont {
|
|
if IsInTrue[string](rnv.Name, roleNameAry) == false {
|
|
roleNameAry = append(roleNameAry, rnv.Name)
|
|
}
|
|
}
|
|
roleName = strings.Join(roleNameAry, "|")
|
|
}
|
|
//获取配置的所有角色权限
|
|
var roleEmpowerCont []modelssystempermission.RoleEmpower
|
|
err = overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.RoleEmpower{}).Select("`point_id`,`operation`,`level`").Where("`system` = ? AND `role_id` IN ?", systemName, roleIdAry).Find(&roleEmpowerCont).Error
|
|
if err == nil && len(roleEmpowerCont) > 0 {
|
|
for _, rev := range roleEmpowerCont {
|
|
menuList := strings.Split(rev.PointId, ",")
|
|
for _, mv := range menuList { //菜单权限
|
|
if mv != "" && IsInTrue[string](mv, pointIdAry) == false {
|
|
pointIdAry = append(pointIdAry, mv)
|
|
}
|
|
}
|
|
operList := strings.Split(rev.Operation, ",")
|
|
for _, ov := range operList { //操作权限
|
|
if ov != "" && IsInTrue[string](ov, operationAry) == false {
|
|
operationAry = append(operationAry, ov)
|
|
}
|
|
}
|
|
if level < rev.Level {
|
|
level = rev.Level //等级
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//获取行政组织授权
|
|
if orgId > 0 && postId > 0 {
|
|
var orgEmpowerCont modelssystempermission.Empower
|
|
orgEmpowerCont.GetCont(map[string]interface{}{"`ordid`": orgId, "`post_id`": postId, "`system`": systemName}, "`point_id`", "`operation`", "`level`")
|
|
if len(pointIdAry) < 1 { //判断是否已经配过权限
|
|
pointIdAry = strings.Split(orgEmpowerCont.PointId, ",")
|
|
} else {
|
|
guoduPoin := strings.Split(orgEmpowerCont.PointId, ",")
|
|
for _, pv := range guoduPoin { //合并权限
|
|
if pv != "" && IsInTrue[string](pv, pointIdAry) == false {
|
|
pointIdAry = append(pointIdAry, pv)
|
|
}
|
|
}
|
|
|
|
}
|
|
if len(operationAry) < 1 { //判断是否已经配过权限
|
|
operationAry = strings.Split(orgEmpowerCont.Operation, ",")
|
|
} else {
|
|
guoduOper := strings.Split(orgEmpowerCont.Operation, ",")
|
|
for _, gpv := range guoduOper { //合并权限
|
|
if gpv != "" && IsInTrue[string](gpv, operationAry) == false {
|
|
operationAry = append(operationAry, gpv)
|
|
}
|
|
}
|
|
|
|
}
|
|
if level < orgEmpowerCont.Level {
|
|
level = orgEmpowerCont.Level
|
|
}
|
|
}
|
|
pointId = strings.Join(pointIdAry, ",")
|
|
operation = strings.Join(operationAry, ",")
|
|
|
|
var powerCont EmpowerCont
|
|
powerCont.RoleName = roleName
|
|
powerCont.PointId = pointId
|
|
powerCont.Operation = operation
|
|
powerCont.Level = level
|
|
//组转写入redis
|
|
myContRedis := MapOut()
|
|
myContRedis["roleName"] = roleName
|
|
myContRedis["pointid"] = pointId
|
|
myContRedis["operation"] = operation
|
|
myContRedis["level"] = level
|
|
redisClient.SetRedisTime(10800)
|
|
redisClient.HashMsetAdd(redisFileKey, myContRedis)
|
|
} else {
|
|
roleName = userRedisToken["roleName"]
|
|
pointId = userRedisToken["pointid"]
|
|
operation = userRedisToken["operation"]
|
|
level, _ = strconv.Atoi(userRedisToken["level"])
|
|
//组转写入redis
|
|
writeRedisData := MapOut()
|
|
for i, v := range userRedisToken {
|
|
writeRedisData[i] = v
|
|
}
|
|
redisClient.SetRedisTime(10800)
|
|
redisClient.HashMsetAdd(redisFileKey, writeRedisData)
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2025-05-21 08:44:35
|
|
@ 功能: 获取用户权限
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (g *GainUserPower) GetUserPower() (powerInfo SendUserPower) {
|
|
//正常系统权限配置
|
|
orgLook := []int64{}
|
|
if g.RoleId != "" {
|
|
roleAry := strings.Split(g.RoleId, ",")
|
|
fmt.Printf("\n\n\n角色----------->%v----------->%v\n\n\n", roleAry, len(roleAry) > 0)
|
|
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 {
|
|
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)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
fmt.Printf("\n\n\n角色权限----------->%v\n\n\n", powerInfo.System.Level)
|
|
|
|
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)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
fmt.Printf("\n\n\n职务权限----------->%v\n\n\n", powerInfo.System.Level)
|
|
|
|
_, companyId, departmentId, _, workShopId := GetOrgStructure(g.OrgId)
|
|
switch powerInfo.System.Level {
|
|
case 1:
|
|
powerInfo.System.OrgList = []int64{}
|
|
var sunOrg GetOrgAllParent
|
|
sunOrg.GetGCSOrgSonAllId(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.GetGCSOrgSonAllId(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.GetGCSOrgSonAllId(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.GetGCSOrgSonAllId(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.GetGCSOrgSonAllId(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.GetGCSOrgSonAllId(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:
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2025-05-22 13:53:17
|
|
@ 功能: 权限结构查询语句
|
|
@ 参数
|
|
授权范围等级(1:本人;2:本岗位;3:本部门;4:本分部;5:指定行政组织;6:所有)
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (g *GainUserPower) MakeSearchSql(gormDb *gorm.DB, userCont models.ManCont, isOdeb string) *gorm.DB {
|
|
powerInfo := g.GetUserPower()
|
|
fmt.Printf("\n\n\n等级-----%v------->%v\n\n\n", powerInfo.System.Level, g)
|
|
if isOdeb == "yes" {
|
|
switch powerInfo.AppSystem.Level {
|
|
case 2, 3, 4:
|
|
if len(powerInfo.AppSystem.OrgList) > 0 {
|
|
gormDb = gormDb.Where("`admin_org` IN ?", powerInfo.AppSystem.OrgList)
|
|
} else {
|
|
if userCont.Key != 0 {
|
|
gormDb = gormDb.Where("`key` = ?", userCont.Key)
|
|
}
|
|
}
|
|
case 6:
|
|
|
|
default:
|
|
if userCont.Key != 0 {
|
|
gormDb = gormDb.Where("`key` = ?", userCont.Key)
|
|
}
|
|
}
|
|
} else {
|
|
switch powerInfo.System.Level {
|
|
case 1, 2, 3, 4:
|
|
if len(powerInfo.AppSystem.OrgList) > 0 {
|
|
gormDb = gormDb.Where("`admin_org` IN ?", powerInfo.AppSystem.OrgList)
|
|
} else {
|
|
if userCont.Key != 0 {
|
|
gormDb = gormDb.Where("`key` = ?", userCont.Key)
|
|
}
|
|
|
|
}
|
|
case 5:
|
|
|
|
default:
|
|
if userCont.Key != 0 {
|
|
gormDb = gormDb.Where("`key` = ?", userCont.Key)
|
|
}
|
|
}
|
|
}
|
|
|
|
return gormDb
|
|
}
|
|
|