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.
268 lines
8.5 KiB
268 lines
8.5 KiB
|
4 days ago
|
package setupRoule
|
||
|
|
|
||
|
|
import (
|
||
|
|
"appPlatform/models/modelssystempermission"
|
||
|
|
"appPlatform/overall"
|
||
|
|
"appPlatform/overall/publicmethod"
|
||
|
|
"encoding/json"
|
||
|
|
"strconv"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
)
|
||
|
|
|
||
|
|
/*
|
||
|
|
*
|
||
|
|
@ 作者: 秦东
|
||
|
|
@ 时间: 2025-11-19 09:05:13
|
||
|
|
@ 功能: 授权
|
||
|
|
*/
|
||
|
|
func (a *ApiMethod) SystemAppAuthorization(c *gin.Context) {
|
||
|
|
var requestData AppSystemInfo
|
||
|
|
c.ShouldBindJSON(&requestData)
|
||
|
|
if requestData.PowerType == "" {
|
||
|
|
publicmethod.Result(1, requestData, c, "未知赋权分类!请明确!")
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if requestData.AppSystem == "" {
|
||
|
|
publicmethod.Result(2, requestData, c, "未知系统分类!请明确!")
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if requestData.RoleId == "" {
|
||
|
|
publicmethod.Result(3, requestData, c, "未知赋权项目!请明确!")
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
var powerMastInfo modelssystempermission.AuthPower
|
||
|
|
gormDb := overall.CONSTANT_DB_System_Permission.Model(&powerMastInfo).Where("`orgPowerType` = ? AND `orgOrUserKey` = ? AND `appType` = ?", requestData.PowerType, requestData.RoleId, requestData.AppSystem)
|
||
|
|
var powerInfo interface{}
|
||
|
|
istrue := 0
|
||
|
|
if requestData.IsPick {
|
||
|
|
istrue = 1
|
||
|
|
}
|
||
|
|
switch requestData.AppSystem {
|
||
|
|
case "app":
|
||
|
|
if requestData.AppId == "" {
|
||
|
|
publicmethod.Result(4, requestData, c, "未知赋权系统!请明确!")
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if len(requestData.CustomizeApp) < 1 {
|
||
|
|
publicmethod.Result(5, requestData, c, "为对任何项目赋权!请明确!")
|
||
|
|
return
|
||
|
|
}
|
||
|
|
powerInfo = requestData.CustomizeApp
|
||
|
|
gormDb = gormDb.Where("`appKey` = ?", requestData.AppId)
|
||
|
|
case "system":
|
||
|
|
if len(requestData.SystemPower) < 1 {
|
||
|
|
publicmethod.Result(6, requestData, c, "为对任何项目赋权!请明确!")
|
||
|
|
return
|
||
|
|
}
|
||
|
|
powerInfo = requestData.SystemPower
|
||
|
|
gormDb = gormDb.Where("`appKey` = 0")
|
||
|
|
default:
|
||
|
|
}
|
||
|
|
jsonPowerInfo, _ := json.Marshal(powerInfo)
|
||
|
|
err := gormDb.First(&powerMastInfo).Error
|
||
|
|
uuid := publicmethod.GetUUid(1)
|
||
|
|
oukId, _ := strconv.ParseInt(requestData.RoleId, 10, 64)
|
||
|
|
appId, _ := strconv.ParseInt(requestData.AppId, 10, 64)
|
||
|
|
if err != nil {
|
||
|
|
powerMastInfo.Id = uuid //
|
||
|
|
powerMastInfo.OrgPowerType = requestData.PowerType //赋权类型(org:组织;job:岗位;role:角色;person:个人)"
|
||
|
|
powerMastInfo.OrgOrUserKey = oukId // unsigned;default:0;comment:行政组织或角色、人员识别符
|
||
|
|
powerMastInfo.AppType = requestData.AppSystem //ment:系统类型(system:系统平台;app:自定义表单与应用)"
|
||
|
|
powerMastInfo.AppKey = appId //ned;default:0;comment:自定义应用App"
|
||
|
|
powerMastInfo.Time = time.Now().Unix() //编辑时间
|
||
|
|
powerMastInfo.IsTrue = istrue //是否有权(1:有;非1:无)
|
||
|
|
powerMastInfo.PowerInfo = string(jsonPowerInfo) //权限结构体"
|
||
|
|
err = overall.CONSTANT_DB_System_Permission.Create(&powerMastInfo).Error
|
||
|
|
} else {
|
||
|
|
uuid = powerMastInfo.Id
|
||
|
|
saveData := publicmethod.MapOut[string]()
|
||
|
|
saveData["`isTrue`"] = istrue
|
||
|
|
saveData["`powerInfo`"] = string(jsonPowerInfo)
|
||
|
|
saveData["`time`"] = time.Now().Unix()
|
||
|
|
var saveInfo modelssystempermission.AuthPower
|
||
|
|
err = saveInfo.EiteCont(map[string]interface{}{"`id`": uuid}, saveData)
|
||
|
|
}
|
||
|
|
if err != nil {
|
||
|
|
publicmethod.Result(7, requestData, c, "授权失败!请重新提交授权数据!")
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
//权限拆分
|
||
|
|
err = requestData.SplitPermissions(uuid)
|
||
|
|
if err != nil {
|
||
|
|
publicmethod.Result(8, err, c, "授权失败!请重新提交授权数据!")
|
||
|
|
return
|
||
|
|
}
|
||
|
|
publicmethod.Result(0, err, c)
|
||
|
|
}
|
||
|
|
|
||
|
|
/*
|
||
|
|
*
|
||
|
|
@ 作者: 秦东
|
||
|
|
@ 时间: 2025-11-20 10:08:09
|
||
|
|
@ 功能: 拆分权限
|
||
|
|
*/
|
||
|
|
func (a *AppSystemInfo) SplitPermissions(uuid int64) error {
|
||
|
|
var oldPower modelssystempermission.PowerInfo
|
||
|
|
err := oldPower.DelCont(map[string]interface{}{"`authId`": uuid})
|
||
|
|
var insterAry []modelssystempermission.PowerInfo
|
||
|
|
switch a.AppSystem {
|
||
|
|
case "app":
|
||
|
|
|
||
|
|
for _, v := range a.CustomizeApp {
|
||
|
|
isPick := 0
|
||
|
|
if v.ListIsAll {
|
||
|
|
isPick = 1
|
||
|
|
}
|
||
|
|
var saveInfo modelssystempermission.PowerInfo
|
||
|
|
saveInfo.AuthId = uuid //归属权限
|
||
|
|
saveInfo.ItemId, _ = strconv.ParseInt(v.Id, 10, 64) //项目ID
|
||
|
|
saveInfo.IsPick = isPick //是否有权(1:有;非1:无)
|
||
|
|
tpAry := MyCreateTablePower(v.TablePower)
|
||
|
|
if tpAry == "null" {
|
||
|
|
tpAry = "[]"
|
||
|
|
}
|
||
|
|
saveInfo.TablePower = tpAry //表单权限
|
||
|
|
lpAry := MyCreateTablePower(v.ListPower)
|
||
|
|
if lpAry == "null" {
|
||
|
|
lpAry = "[]"
|
||
|
|
}
|
||
|
|
saveInfo.ListPower = lpAry //列表权限
|
||
|
|
saveInfo.VisibleRange = v.DatePower.Types //可见范围(1:本人;2:本岗位;3:本部门;4:本分部;5:指定行政组织;6:所有)
|
||
|
|
visibleOrgStr, _ := json.Marshal(v.DatePower.Attribute)
|
||
|
|
saveInfo.VisibleOrg = string(visibleOrgStr) //可见范围辅助参数
|
||
|
|
saveInfo.ButPower = "[]" //按钮权限
|
||
|
|
saveInfo.Time = time.Now().Unix() //编辑时间
|
||
|
|
insterAry = append(insterAry, saveInfo)
|
||
|
|
}
|
||
|
|
case "system":
|
||
|
|
for _, v := range a.SystemPower {
|
||
|
|
isPick := 0
|
||
|
|
if v.IsTrue {
|
||
|
|
isPick = 1
|
||
|
|
}
|
||
|
|
var saveInfo modelssystempermission.PowerInfo
|
||
|
|
saveInfo.AuthId = uuid //归属权限
|
||
|
|
saveInfo.ItemId = int64(v.Id) //项目ID
|
||
|
|
saveInfo.IsPick = isPick //是否有权(1:有;非1:无)
|
||
|
|
saveInfo.TablePower = "[]" //表单权限
|
||
|
|
saveInfo.ListPower = "[]" //列表权限
|
||
|
|
saveInfo.VisibleRange = v.VisibleRange.Types //可见范围(1:本人;2:本岗位;3:本部门;4:本分部;5:指定行政组织;6:所有)
|
||
|
|
visibleOrgStr, _ := json.Marshal(v.VisibleRange.Val)
|
||
|
|
// fmt.Printf("\n\n转换福泉击缶提---------------->%v\n\n", fsdfsd)
|
||
|
|
saveInfo.VisibleOrg = string(visibleOrgStr) //可见范围辅助参数
|
||
|
|
jieguo := ButPower(v.ButtenPower)
|
||
|
|
if jieguo == "null" {
|
||
|
|
jieguo = "[]"
|
||
|
|
}
|
||
|
|
saveInfo.ButPower = jieguo //按钮权限
|
||
|
|
saveInfo.Time = time.Now().Unix() //编辑时间
|
||
|
|
insterAry = append(insterAry, saveInfo)
|
||
|
|
if len(v.Children) > 0 {
|
||
|
|
var childAry SystemTreePower
|
||
|
|
childAry.WriteSystemInfo(uuid, v.Children)
|
||
|
|
if len(childAry.WriteInfo) > 0 {
|
||
|
|
insterAry = append(insterAry, childAry.WriteInfo...)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
default:
|
||
|
|
}
|
||
|
|
if len(insterAry) > 0 {
|
||
|
|
err = overall.CONSTANT_DB_System_Permission.Create(&insterAry).Error
|
||
|
|
}
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
|
||
|
|
func (s *SystemTreePower) WriteSystemInfo(uuid int64, list []AppPowerTree) {
|
||
|
|
if len(list) > 0 {
|
||
|
|
for _, v := range list {
|
||
|
|
isPick := 0
|
||
|
|
if v.IsTrue {
|
||
|
|
isPick = 1
|
||
|
|
}
|
||
|
|
var saveInfo modelssystempermission.PowerInfo
|
||
|
|
saveInfo.AuthId = uuid //归属权限
|
||
|
|
saveInfo.ItemId = int64(v.Id) //项目ID
|
||
|
|
saveInfo.IsPick = isPick //是否有权(1:有;非1:无)
|
||
|
|
saveInfo.TablePower = "[]" //表单权限
|
||
|
|
saveInfo.ListPower = "[]" //列表权限
|
||
|
|
saveInfo.VisibleRange = v.VisibleRange.Types //可见范围(1:本人;2:本岗位;3:本部门;4:本分部;5:指定行政组织;6:所有)
|
||
|
|
visibleOrgStr, _ := json.Marshal(v.VisibleRange.Val)
|
||
|
|
saveInfo.VisibleOrg = string(visibleOrgStr) //可见范围辅助参数
|
||
|
|
jieguo := ButPower(v.ButtenPower)
|
||
|
|
if jieguo == "null" {
|
||
|
|
jieguo = "[]"
|
||
|
|
}
|
||
|
|
saveInfo.ButPower = jieguo //按钮权限
|
||
|
|
saveInfo.Time = time.Now().Unix() //编辑时间
|
||
|
|
s.WriteInfo = append(s.WriteInfo, saveInfo)
|
||
|
|
if len(v.Children) > 0 {
|
||
|
|
s.WriteSystemInfo(uuid, v.Children)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/*
|
||
|
|
*
|
||
|
|
@ 作者: 秦东
|
||
|
|
@ 时间: 2025-11-20 11:39:52
|
||
|
|
@ 功能: 解释自定义表单权限
|
||
|
|
*/
|
||
|
|
func MyCreateTablePower(powerList []string) string {
|
||
|
|
if len(powerList) <= 0 {
|
||
|
|
return "[]"
|
||
|
|
}
|
||
|
|
var powerAry []string
|
||
|
|
for _, v := range powerList {
|
||
|
|
if !publicmethod.IsInTrue[string](v, powerAry) {
|
||
|
|
powerAry = append(powerAry, v)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
jsonStr, _ := json.Marshal(powerAry)
|
||
|
|
return string(jsonStr)
|
||
|
|
}
|
||
|
|
|
||
|
|
/*
|
||
|
|
*
|
||
|
|
@ 作者: 秦东
|
||
|
|
@ 时间: 2025-11-20 11:28:56
|
||
|
|
@ 功能: 按钮列表处理
|
||
|
|
*/
|
||
|
|
func ButPower(butList []AppPowerInfo) string {
|
||
|
|
if len(butList) <= 0 {
|
||
|
|
return "[]"
|
||
|
|
}
|
||
|
|
var powerAry []int
|
||
|
|
for _, v := range butList {
|
||
|
|
if v.IsTrue {
|
||
|
|
if !publicmethod.IsInTrue[int](v.Id, powerAry) {
|
||
|
|
powerAry = append(powerAry, v.Id)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
jsonStr, _ := json.Marshal(powerAry)
|
||
|
|
return string(jsonStr)
|
||
|
|
}
|
||
|
|
|
||
|
|
/*
|
||
|
|
*
|
||
|
|
@ 作者: 秦东
|
||
|
|
@ 时间: 2025-11-20 14:31:23
|
||
|
|
@ 功能: 数据范围转换格式
|
||
|
|
*/
|
||
|
|
func PowerOrg(orgAry []int) string {
|
||
|
|
// if len(orgAry) <= 0{
|
||
|
|
return "[]"
|
||
|
|
// }
|
||
|
|
// var orgStr []string
|
||
|
|
// for _,v := range orgAry{
|
||
|
|
// vStr := strconv.Itoa(v)
|
||
|
|
// // if
|
||
|
|
// }
|
||
|
|
}
|