23 changed files with 1070 additions and 18 deletions
@ -0,0 +1,62 @@ |
|||
package modelssystempermission |
|||
|
|||
import ( |
|||
"hr_server/overall" |
|||
"strings" |
|||
) |
|||
|
|||
// 应用系统
|
|||
type Appsystem struct { |
|||
Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:Id;index"` |
|||
Title string `json:"title" gorm:"column:title;type:varchar(255) ;comment:系统名称"` |
|||
Coder string `json:"coder" gorm:"column:coder;type:varchar(255) ;comment:识别符"` |
|||
State int `json:"state" gorm:"column:state;type:tinyint(1) unsigned;default:1;not null;comment:状态(1:启用;2:禁用;3:删除)"` |
|||
Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` |
|||
Sort int `json:"sort" gorm:"column:sort;type:int(5) unsigned;default:50;not null;comment:排序"` |
|||
ApiUrl string `json:"apiurl" gorm:"column:api_url;type:varchar(255) ;comment:菜单访问权限列表"` |
|||
} |
|||
|
|||
func (Appsystem *Appsystem) TableName() string { |
|||
return "appsystem" |
|||
} |
|||
|
|||
// 编辑内容
|
|||
func (cont *Appsystem) EiteCont(whereMap interface{}, saveData interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_System_Permission.Model(&cont).Where(whereMap).Updates(saveData).Error |
|||
return |
|||
} |
|||
|
|||
// 获取内容
|
|||
func (cont *Appsystem) GetCont(whereMap interface{}, field ...string) (err error) { |
|||
gormDb := overall.CONSTANT_DB_System_Permission.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
gormDb = gormDb.Where(whereMap) |
|||
err = gormDb.First(&cont).Error |
|||
return |
|||
} |
|||
|
|||
// 根据条件获取总数
|
|||
func (cont *Appsystem) CountCont(whereMap interface{}) (countId int64) { |
|||
overall.CONSTANT_DB_System_Permission.Model(&cont).Where(whereMap).Count(&countId) |
|||
return |
|||
} |
|||
|
|||
// 读取全部信息
|
|||
func (cont *Appsystem) ContMap(whereMap interface{}, field ...string) (countAry []Appsystem, err error) { |
|||
gormDb := overall.CONSTANT_DB_System_Permission.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
err = gormDb.Where(whereMap).Find(&countAry).Error |
|||
return |
|||
} |
|||
|
|||
// 删除内容
|
|||
func (cont *Appsystem) DelCont(whereMap interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_System_Permission.Where(whereMap).Delete(&cont).Error |
|||
return |
|||
} |
|||
@ -0,0 +1,69 @@ |
|||
package modelssystempermission |
|||
|
|||
import ( |
|||
"hr_server/overall" |
|||
"strings" |
|||
) |
|||
|
|||
/* |
|||
* |
|||
@ 作者: 秦东 |
|||
@ 时间: 2025-05-19 14:01:12 |
|||
@ 功能: 自定义表单权限设置 |
|||
*/ |
|||
type CustomTableAuthorize struct { |
|||
Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:Id;index"` // 编辑时间
|
|||
Roleid int64 `json:"role_id" gorm:"column:role_id;type:bigint(20) unsigned;default:0;not null;comment:角色ID"` // 角色ID
|
|||
TableSignCode int64 `json:"table_sign_code" gorm:"column:table_sign_code;type:bigint(20) unsigned;default:0;not null;comment:app表格唯一识别符"` // app表格唯一识别符
|
|||
AppCignCode int64 `json:"app_sign_code" gorm:"column:app_sign_code;type:bigint(20) unsigned;default:0;not null;comment:归谁哪个App"` // 归谁哪个App
|
|||
TablePower string `json:"table_power" gorm:column:table_power;type:varchar(255) ;comment:表格权限"` // 表格权限
|
|||
ListPower string `json:"list_power" gorm:"column:list_power;type:varchar(255) ;comment:列表权限"` // 列表权限
|
|||
PowerLerver int `json:"power_lerver" gorm:"column:power_lerver;type:tinyint(1) unsigned;default:1;not null;comment:授权范围等级(1:本岗位;2:本部门;3:本分部;4:指定行政组织;5:所有)"` // 授权范围等级(1:本岗位;2:本部门;3:本分部;4:指定行政组织;5:所有)
|
|||
Organization string `json:"organization" gorm:"column:organization;type:text;comment:授权范围属性"` // 授权范围属性
|
|||
Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` // 编辑时间
|
|||
} |
|||
|
|||
func (CustomTableAuthorize *CustomTableAuthorize) TableName() string { |
|||
return "custom_table_authorize" |
|||
} |
|||
|
|||
// 编辑内容
|
|||
func (cont *CustomTableAuthorize) EiteCont(whereMap interface{}, saveData interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_System_Permission.Model(&cont).Where(whereMap).Updates(saveData).Error |
|||
return |
|||
} |
|||
|
|||
// 获取内容
|
|||
func (cont *CustomTableAuthorize) GetCont(whereMap interface{}, field ...string) (err error) { |
|||
gormDb := overall.CONSTANT_DB_System_Permission.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
gormDb = gormDb.Where(whereMap) |
|||
err = gormDb.First(&cont).Error |
|||
return |
|||
} |
|||
|
|||
// 根据条件获取总数
|
|||
func (cont *CustomTableAuthorize) CountCont(whereMap interface{}) (countId int64) { |
|||
overall.CONSTANT_DB_System_Permission.Model(&cont).Where(whereMap).Count(&countId) |
|||
return |
|||
} |
|||
|
|||
// 读取全部信息
|
|||
func (cont *CustomTableAuthorize) ContMap(whereMap interface{}, field ...string) (countAry []CustomTableAuthorize, err error) { |
|||
gormDb := overall.CONSTANT_DB_System_Permission.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
err = gormDb.Where(whereMap).Find(&countAry).Error |
|||
return |
|||
} |
|||
|
|||
// 删除内容
|
|||
func (cont *CustomTableAuthorize) DelCont(whereMap interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_System_Permission.Where(whereMap).Delete(&cont).Error |
|||
return |
|||
} |
|||
@ -0,0 +1,65 @@ |
|||
package modelssystempermission |
|||
|
|||
import ( |
|||
"hr_server/overall" |
|||
"strings" |
|||
) |
|||
|
|||
// 权限配置
|
|||
type Empower struct { |
|||
Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:Id;index"` |
|||
OrdId int64 `json:"ordid" gorm:"column:ordid;type:bigint(20) unsigned;default:0;not null;comment:行政组织"` |
|||
PostId int64 `json:"postid" gorm:"column:post_id;type:bigint(20) unsigned;default:0;not null;comment:岗位ID"` |
|||
System string `json:"system" gorm:"column:system;type:varchar(255) ;comment:系统"` |
|||
PointId string `json:"pointid" gorm:"column:point_id;type:longtext;comment:权限点位"` |
|||
State int `json:"state" gorm:"column:state;type:tinyint(1) unsigned;default:1;not null;comment:状态(1:启用;2:禁用;3:删除)"` |
|||
Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` |
|||
Level int `json:"level" gorm:"column:level;type:int(1) unsigned;default:1;not null;comment:授权范围等级(1:本部门;2:本分部;3:所有)"` |
|||
Organization string `json:"organization" gorm:"column:organization;type:longtext;comment:行政组织"` |
|||
Operation string `json:"operation" gorm:"column:operation;type:longtext;comment:操作点位"` |
|||
} |
|||
|
|||
func (Empower *Empower) TableName() string { |
|||
return "empower" |
|||
} |
|||
|
|||
// 编辑内容
|
|||
func (cont *Empower) EiteCont(whereMap interface{}, saveData interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_System_Permission.Model(&cont).Where(whereMap).Updates(saveData).Error |
|||
return |
|||
} |
|||
|
|||
// 获取内容
|
|||
func (cont *Empower) GetCont(whereMap interface{}, field ...string) (err error) { |
|||
gormDb := overall.CONSTANT_DB_System_Permission.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
gormDb = gormDb.Where(whereMap) |
|||
err = gormDb.First(&cont).Error |
|||
return |
|||
} |
|||
|
|||
// 根据条件获取总数
|
|||
func (cont *Empower) CountCont(whereMap interface{}) (countId int64) { |
|||
overall.CONSTANT_DB_System_Permission.Model(&cont).Where(whereMap).Count(&countId) |
|||
return |
|||
} |
|||
|
|||
// 读取全部信息
|
|||
func (cont *Empower) ContMap(whereMap interface{}, field ...string) (countAry []Empower, err error) { |
|||
gormDb := overall.CONSTANT_DB_System_Permission.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
err = gormDb.Where(whereMap).Find(&countAry).Error |
|||
return |
|||
} |
|||
|
|||
// 删除内容
|
|||
func (cont *Empower) DelCont(whereMap interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_System_Permission.Where(whereMap).Delete(&cont).Error |
|||
return |
|||
} |
|||
@ -0,0 +1,64 @@ |
|||
package modelssystempermission |
|||
|
|||
import ( |
|||
"hr_server/overall" |
|||
"strings" |
|||
) |
|||
|
|||
// 权限配置
|
|||
type RoleEmpower struct { |
|||
Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:Id;index"` |
|||
RoleId int64 `json:"roleid" gorm:"column:role_id;type:bigint(20) unsigned;default:0;not null;comment:行政组织"` |
|||
System string `json:"system" gorm:"column:system;type:varchar(255) ;comment:系统"` |
|||
PointId string `json:"pointid" gorm:"column:point_id;type:longtext;comment:权限点位"` |
|||
Operation string `json:"operation" gorm:"column:operation;type:longtext;comment:操作点位"` |
|||
State int `json:"state" gorm:"column:state;type:tinyint(1) unsigned;default:1;not null;comment:状态(1:启用;2:禁用;3:删除)"` |
|||
Level int `json:"level" gorm:"column:level;type:int(1) unsigned;default:1;not null;comment:授权范围等级(1:本部门;2:本分部;3:所有)"` |
|||
Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` |
|||
Organization string `json:"organization" gorm:"column:organization;type:longtext;comment:行政组织列表"` |
|||
} |
|||
|
|||
func (RoleEmpower *RoleEmpower) TableName() string { |
|||
return "role_empower" |
|||
} |
|||
|
|||
// 编辑内容
|
|||
func (cont *RoleEmpower) EiteCont(whereMap interface{}, saveData interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_System_Permission.Model(&cont).Where(whereMap).Updates(saveData).Error |
|||
return |
|||
} |
|||
|
|||
// 获取内容
|
|||
func (cont *RoleEmpower) GetCont(whereMap interface{}, field ...string) (err error) { |
|||
gormDb := overall.CONSTANT_DB_System_Permission.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
gormDb = gormDb.Where(whereMap) |
|||
err = gormDb.First(&cont).Error |
|||
return |
|||
} |
|||
|
|||
// 根据条件获取总数
|
|||
func (cont *RoleEmpower) CountCont(whereMap interface{}) (countId int64) { |
|||
overall.CONSTANT_DB_System_Permission.Model(&cont).Where(whereMap).Count(&countId) |
|||
return |
|||
} |
|||
|
|||
// 读取全部信息
|
|||
func (cont *RoleEmpower) ContMap(whereMap interface{}, field ...string) (countAry []RoleEmpower, err error) { |
|||
gormDb := overall.CONSTANT_DB_System_Permission.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
err = gormDb.Where(whereMap).Find(&countAry).Error |
|||
return |
|||
} |
|||
|
|||
// 删除内容
|
|||
func (cont *RoleEmpower) DelCont(whereMap interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_System_Permission.Where(whereMap).Delete(&cont).Error |
|||
return |
|||
} |
|||
@ -0,0 +1,60 @@ |
|||
package modelssystempermission |
|||
|
|||
import ( |
|||
"hr_server/overall" |
|||
"strings" |
|||
) |
|||
|
|||
// 系统角色表
|
|||
type SystemRole struct { |
|||
Id int64 `json:"id" gorm:"primaryKey;column:id;type:bigint(20) unsigned;not null;comment:Id;index"` |
|||
Name string `json:"name" gorm:"column:name;type:varchar(255) ;comment:系统名称"` |
|||
State int `json:"state" gorm:"column:state;type:tinyint(1) unsigned;default:1;not null;comment:状态(1:启用;2:禁用;3:删除)"` |
|||
Time int64 `json:"time" gorm:"column:time;type:bigint(20) unsigned;default:0;not null;comment:创建时间"` |
|||
Sort int `json:"sort" gorm:"column:sort;type:int(5) unsigned;default:50;not null;comment:排序"` |
|||
} |
|||
|
|||
func (SystemRole *SystemRole) TableName() string { |
|||
return "system_role" |
|||
} |
|||
|
|||
// 编辑内容
|
|||
func (cont *SystemRole) EiteCont(whereMap interface{}, saveData interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_System_Permission.Model(&cont).Where(whereMap).Updates(saveData).Error |
|||
return |
|||
} |
|||
|
|||
// 获取内容
|
|||
func (cont *SystemRole) GetCont(whereMap interface{}, field ...string) (err error) { |
|||
gormDb := overall.CONSTANT_DB_System_Permission.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
gormDb = gormDb.Where(whereMap) |
|||
err = gormDb.First(&cont).Error |
|||
return |
|||
} |
|||
|
|||
// 根据条件获取总数
|
|||
func (cont *SystemRole) CountCont(whereMap interface{}) (countId int64) { |
|||
overall.CONSTANT_DB_System_Permission.Model(&cont).Where(whereMap).Count(&countId) |
|||
return |
|||
} |
|||
|
|||
// 读取全部信息
|
|||
func (cont *SystemRole) ContMap(whereMap interface{}, field ...string) (countAry []SystemRole, err error) { |
|||
gormDb := overall.CONSTANT_DB_System_Permission.Model(&cont) |
|||
if len(field) > 0 { |
|||
fieldStr := strings.Join(field, ",") |
|||
gormDb = gormDb.Select(fieldStr) |
|||
} |
|||
err = gormDb.Where(whereMap).Find(&countAry).Error |
|||
return |
|||
} |
|||
|
|||
// 删除内容
|
|||
func (cont *SystemRole) DelCont(whereMap interface{}) (err error) { |
|||
err = overall.CONSTANT_DB_System_Permission.Where(whereMap).Delete(&cont).Error |
|||
return |
|||
} |
|||
@ -1,18 +1,421 @@ |
|||
package overallhandle |
|||
|
|||
import "github.com/gin-gonic/gin" |
|||
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 |
|||
} |
|||
|
|||
Loading…
Reference in new issue