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.
227 lines
4.5 KiB
227 lines
4.5 KiB
|
1 year ago
|
package customerApp
|
||
|
|
|
||
|
|
import (
|
||
|
|
"appPlatform/models/modelAppPlatform"
|
||
|
|
"appPlatform/models/modelshr"
|
||
|
|
"appPlatform/overall"
|
||
|
|
"appPlatform/overall/publicmethod"
|
||
|
|
"strconv"
|
||
|
|
"strings"
|
||
|
|
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
)
|
||
|
|
|
||
|
|
/*
|
||
|
|
*
|
||
|
|
@ 作者: 秦东
|
||
|
|
@ 时间: 2024-05-29 16:34:23
|
||
|
|
@ 功能: 鉴定当权人员是否有权限使用
|
||
|
|
@ 参数
|
||
|
|
|
||
|
|
#
|
||
|
|
|
||
|
|
@ 返回值
|
||
|
|
|
||
|
|
#
|
||
|
|
|
||
|
|
@ 方法原型
|
||
|
|
|
||
|
|
#
|
||
|
|
*/
|
||
|
|
func (a *ApiMethod) AppJwtPower(c *gin.Context) {
|
||
|
|
var requestData JwtPower
|
||
|
|
err := c.ShouldBindJSON(&requestData)
|
||
|
|
if err != nil {
|
||
|
|
publicmethod.Result(100, err, c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if requestData.Id == "" {
|
||
|
|
publicmethod.Result(102, err, c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
context, _ := c.Get(overall.MyContJwt)
|
||
|
|
var userCont modelshr.ManCont
|
||
|
|
userCont.GetLoginCont(context) //当前操作人
|
||
|
|
if userCont.Role != "" {
|
||
|
|
roleAry := strings.Split(userCont.Role, ",")
|
||
|
|
if len(roleAry) > 0 {
|
||
|
|
if publicmethod.IsInTrue[string]("1", roleAry) {
|
||
|
|
publicmethod.Result(0, true, c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
var custFormInfo modelAppPlatform.CustomerForm
|
||
|
|
err = custFormInfo.GetCont(map[string]interface{}{"`signCode`": requestData.Id}, "`id`", "`appManager`", "`appRoleManager`", "`appOrgMan`", "`userpermit`", "`postpermit`", "`orgpermit`")
|
||
|
|
if err != nil {
|
||
|
|
publicmethod.Result(0, false, c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if requestData.Types == 2 {
|
||
|
|
//操作权限
|
||
|
|
var jwtIsTrue TreeJwtPower
|
||
|
|
if custFormInfo.AppRoleManager != "" {
|
||
|
|
syncSeting.Add(1)
|
||
|
|
go jwtIsTrue.JwtRoleViewsIsTrue(custFormInfo.AppRoleManager, userCont.Role)
|
||
|
|
}
|
||
|
|
if custFormInfo.AppOrgMan != "" {
|
||
|
|
syncSeting.Add(1)
|
||
|
|
go jwtIsTrue.JwtOrgViewsIsTrue(custFormInfo.OrgPermit, userCont.AdminOrg)
|
||
|
|
}
|
||
|
|
if custFormInfo.AppManager != "" {
|
||
|
|
userKey := strconv.FormatInt(userCont.Key, 10)
|
||
|
|
syncSeting.Add(1)
|
||
|
|
go jwtIsTrue.JwtPeopleViewsIsTrue(custFormInfo.AppManager, userKey)
|
||
|
|
}
|
||
|
|
syncSeting.Wait()
|
||
|
|
if jwtIsTrue.Role || jwtIsTrue.Org || jwtIsTrue.People {
|
||
|
|
publicmethod.Result(0, true, c)
|
||
|
|
return
|
||
|
|
} else {
|
||
|
|
publicmethod.Result(0, false, c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
//可见范围
|
||
|
|
var jwtIsTrue TreeJwtPower
|
||
|
|
if custFormInfo.PostPermit != "" {
|
||
|
|
syncSeting.Add(1)
|
||
|
|
go jwtIsTrue.JwtRoleViewsIsTrue(custFormInfo.PostPermit, userCont.Role)
|
||
|
|
}
|
||
|
|
if custFormInfo.OrgPermit != "" {
|
||
|
|
syncSeting.Add(1)
|
||
|
|
go jwtIsTrue.JwtOrgViewsIsTrue(custFormInfo.OrgPermit, userCont.AdminOrg)
|
||
|
|
}
|
||
|
|
if custFormInfo.UserPermit != "" {
|
||
|
|
userKey := strconv.FormatInt(userCont.Key, 10)
|
||
|
|
syncSeting.Add(1)
|
||
|
|
go jwtIsTrue.JwtPeopleViewsIsTrue(custFormInfo.UserPermit, userKey)
|
||
|
|
}
|
||
|
|
syncSeting.Wait()
|
||
|
|
if jwtIsTrue.Role || jwtIsTrue.Org || jwtIsTrue.People {
|
||
|
|
publicmethod.Result(0, true, c)
|
||
|
|
return
|
||
|
|
} else {
|
||
|
|
publicmethod.Result(0, false, c)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/*
|
||
|
|
*
|
||
|
|
@ 作者: 秦东
|
||
|
|
@ 时间: 2024-05-30 08:10:32
|
||
|
|
@ 功能: 使用人鉴权
|
||
|
|
@ 参数
|
||
|
|
|
||
|
|
#jwpUser 使用人员
|
||
|
|
#userKEy 个人权限
|
||
|
|
|
||
|
|
@ 返回值
|
||
|
|
|
||
|
|
#
|
||
|
|
|
||
|
|
@ 方法原型
|
||
|
|
|
||
|
|
#
|
||
|
|
*/
|
||
|
|
func (t *TreeJwtPower) JwtPeopleViewsIsTrue(jwpUser, userKEy string) {
|
||
|
|
defer syncSeting.Done()
|
||
|
|
if jwpUser == "" {
|
||
|
|
t.People = true
|
||
|
|
} else {
|
||
|
|
if userKEy == "" {
|
||
|
|
t.People = false
|
||
|
|
} else {
|
||
|
|
jwtRoleAry := strings.Split(jwpUser, ",")
|
||
|
|
if publicmethod.IsInTrue[string](userKEy, jwtRoleAry) {
|
||
|
|
t.People = true
|
||
|
|
} else {
|
||
|
|
t.People = false
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/*
|
||
|
|
*
|
||
|
|
@ 作者: 秦东
|
||
|
|
@ 时间: 2024-05-30 08:24:55
|
||
|
|
@ 功能: 鉴定行政组织授权
|
||
|
|
@ 参数
|
||
|
|
|
||
|
|
#jwpRoel 应用行政组织
|
||
|
|
#userRole 个人行政组织
|
||
|
|
|
||
|
|
@ 返回值
|
||
|
|
|
||
|
|
#
|
||
|
|
|
||
|
|
@ 方法原型
|
||
|
|
|
||
|
|
#
|
||
|
|
*/
|
||
|
|
func (t *TreeJwtPower) JwtOrgViewsIsTrue(jwpOrg string, userOrg int64) {
|
||
|
|
if jwpOrg == "" {
|
||
|
|
t.Org = true
|
||
|
|
} else {
|
||
|
|
if userOrg == 0 {
|
||
|
|
t.Org = false
|
||
|
|
} else {
|
||
|
|
var allOrg []int64
|
||
|
|
jwtOrgAry := strings.Split(jwpOrg, ",")
|
||
|
|
for _, v := range jwtOrgAry {
|
||
|
|
orgId, _ := strconv.ParseInt(v, 10, 64)
|
||
|
|
var sunOrg publicmethod.GetOrgAllParent
|
||
|
|
sunOrg.GetOrgSonAllId(orgId)
|
||
|
|
allOrg = append(allOrg, orgId)
|
||
|
|
allOrg = append(allOrg, sunOrg.Id...)
|
||
|
|
}
|
||
|
|
if publicmethod.IsInTrue[int64](userOrg, allOrg) {
|
||
|
|
t.Org = true
|
||
|
|
} else {
|
||
|
|
t.Org = false
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/*
|
||
|
|
*
|
||
|
|
@ 作者: 秦东
|
||
|
|
@ 时间: 2024-05-30 08:10:32
|
||
|
|
@ 功能: 角色鉴权
|
||
|
|
@ 参数
|
||
|
|
|
||
|
|
#jwpRoel 应用权限
|
||
|
|
#userRole 个人权限
|
||
|
|
|
||
|
|
@ 返回值
|
||
|
|
|
||
|
|
#
|
||
|
|
|
||
|
|
@ 方法原型
|
||
|
|
|
||
|
|
#
|
||
|
|
*/
|
||
|
|
func (t *TreeJwtPower) JwtRoleViewsIsTrue(jwpRoel, userRole string) {
|
||
|
|
defer syncSeting.Done()
|
||
|
|
if jwpRoel == "" {
|
||
|
|
t.Role = true
|
||
|
|
} else {
|
||
|
|
if userRole == "" {
|
||
|
|
t.Role = false
|
||
|
|
} else {
|
||
|
|
jwtRoleAry := strings.Split(jwpRoel, ",")
|
||
|
|
userRoleAry := strings.Split(userRole, ",")
|
||
|
|
t.Role = false
|
||
|
|
for _, v := range userRoleAry {
|
||
|
|
if publicmethod.IsInTrue[string](v, jwtRoleAry) {
|
||
|
|
t.Role = true
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|