package user import ( "appPlatform/models/modelshr" "appPlatform/models/modelssystempermission" "appPlatform/overall" "appPlatform/overall/publicmethod" "encoding/json" "strconv" "strings" "github.com/gin-gonic/gin" ) /* * @ 作者: 秦东 @ 时间: 2023-05-22 10:54:15 @ 功能: 获取当前登录用户信息 @ 参数 # @ 返回值 # @ 方法原型 # */ func (a *ApiMethod) GetUserCont(c *gin.Context) { context, _ := c.Get(overall.MyContJwt) var myContInfo modelshr.ManCont jsonCont, _ := json.Marshal(context) jsonUnErr := json.Unmarshal(jsonCont, &myContInfo) outMap := publicmethod.MapOut[string]() outMap["context"] = context outMap["exi"] = jsonUnErr outMap["myContInfo"] = myContInfo var sendData SendUserCont sendData.UserId = strconv.FormatInt(myContInfo.Key, 10) sendData.Number = myContInfo.Number sendData.NickName = myContInfo.Name sendData.Company = strconv.FormatInt(myContInfo.Company, 10) //公司 var companyCont modelshr.AdministrativeOrganization companyCont.GetCont(map[string]interface{}{"`id`": myContInfo.Company}, "`name`") sendData.CompanyName = companyCont.Name //公司名称 sendData.Department = strconv.FormatInt(myContInfo.MainDeparment, 10) //主部门 var departCont modelshr.AdministrativeOrganization departCont.GetCont(map[string]interface{}{"`id`": myContInfo.MainDeparment}, "`name`") sendData.DepartmentName = departCont.Name //主部门名称 sendData.Organization = strconv.FormatInt(myContInfo.AdminOrg, 10) //行政组织 var orgCont modelshr.AdministrativeOrganization orgCont.GetCont(map[string]interface{}{"`id`": myContInfo.MainDeparment}, "`name`") sendData.OrganizationName = orgCont.Name //行政组织名称 sendData.Avatar = myContInfo.Icon roleList := strings.Split(myContInfo.Role, ",") // roleList = append(roleList, "ROOT") sendData.Roles = roleList //获取权限 menuPoint, _, _ := GetUserPower("appsystem", myContInfo.Position, roleList) // menuPoint, opeart, orgList := GetUserPower("appsystem", myContInfo.Position, roleList) // fmt.Printf("menuPoint======>%v\nopeart======>%v\norgList======>%v\n", menuPoint, opeart, orgList) sendData.Perms = menuPoint publicmethod.Result(0, sendData, c) } /* * @ 作者: 秦东 @ 时间: 2023-05-22 11:30:44 @ 功能: 获取用户权限 @ 参数 #appType 系统标识 #postId 职务 #roleList 角色列表 @ 返回值 #menuPoint 菜单操作列表 #opeart 点位 #orgList 行政组织 @ 方法原型 #func GetUserPower(appType string, postId int64, roleList []string) (menuPoint []string, opeart []string, orgList []string) */ func GetUserPower(appType string, postId int64, roleList []string) (menuPoint, opeart, orgList []string) { //获取职务权限 var emPower modelssystempermission.Empower err := emPower.GetCont(map[string]interface{}{"`post_id`": postId, "`system`": appType}) if err == nil { if emPower.PointId != "" { pointIdList := strings.Split(emPower.PointId, ",") menuPoint = publicmethod.MergeStruct[string](pointIdList, menuPoint) } if emPower.Operation != "" { operationIdList := strings.Split(emPower.Operation, ",") opeart = publicmethod.MergeStruct[string](operationIdList, opeart) } if emPower.Organization != "" { orgIdList := strings.Split(emPower.Organization, ",") orgList = publicmethod.MergeStruct[string](orgIdList, orgList) } } //获取角色权限 if len(roleList) > 0 { var roleId []int64 err = overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.SystemRole{}).Select("`id`").Where("`state` = 1 AND `id` IN ?", roleList).Find(&roleId).Error if err == nil && len(roleId) > 0 { for _, v := range roleId { var roleEmpower modelssystempermission.RoleEmpower err = roleEmpower.GetCont(map[string]interface{}{"`role_id`": v, "`system`": appType}) if err == nil { if roleEmpower.PointId != "" { pointIdList := strings.Split(roleEmpower.PointId, ",") menuPoint = publicmethod.MergeStruct[string](pointIdList, menuPoint) } if roleEmpower.Operation != "" { operationIdList := strings.Split(roleEmpower.Operation, ",") opeart = publicmethod.MergeStruct[string](operationIdList, opeart) } if roleEmpower.Organization != "" { orgIdList := strings.Split(roleEmpower.Organization, ",") orgList = publicmethod.MergeStruct[string](orgIdList, orgList) } } } } // for _, v := range roleList { // var roleEmpower modelssystempermission.RoleEmpower // err = roleEmpower.GetCont(map[string]interface{}{"`role_id`": v, "`system`": appType}) // if err == nil { // if roleEmpower.PointId != "" { // pointIdList := strings.Split(roleEmpower.PointId, ",") // menuPoint = publicmethod.MergeStruct[string](pointIdList, menuPoint) // } // if roleEmpower.Operation != "" { // operationIdList := strings.Split(roleEmpower.Operation, ",") // opeart = publicmethod.MergeStruct[string](operationIdList, opeart) // } // if roleEmpower.Organization != "" { // orgIdList := strings.Split(roleEmpower.Organization, ",") // orgList = publicmethod.MergeStruct[string](orgIdList, orgList) // } // } // } } return }