package publicmethod import ( "appPlatform/models/modelshr" "appPlatform/models/modelssystempermission" "appPlatform/overall" "fmt" "strconv" "strings" "gorm.io/gorm" ) /* * @ 作者: 秦东 @ 时间: 2025-05-21 08:44:35 @ 功能: 获取用户权限 @ 参数 # @ 返回值 # @ 方法原型 # */ func (g *GainUserPower) GetUserPower() (powerInfo SendUserPower) { //正常系统权限配置 orgLook := []int64{} if g.RoleId != "" { roleAry := strings.Split(g.RoleId, ",") 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) } } } } } } 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) } } } } _, companyId, departmentId, _, workShopId := GetOrgStructure(g.OrgId) switch powerInfo.System.Level { case 1: powerInfo.System.OrgList = []int64{} var sunOrg GetOrgAllParent sunOrg.GetOrgSun(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.GetOrgSun(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.GetOrgSun(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.GetOrgSun(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.GetOrgSun(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.GetOrgSun(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 modelshr.ManCont, isOdeb string) *gorm.DB { powerInfo := g.GetUserPower() fmt.Printf("\n\n\n等级-----%v------->%v\n\n\n", powerInfo.AppSystem.Level, g) if isOdeb == "yes" { switch powerInfo.AppSystem.Level { case 2, 3, 4, 5: if len(powerInfo.AppSystem.OrgList) > 0 { gormDb = gormDb.Where("`createrOrg` IN ?", powerInfo.AppSystem.OrgList) } else { gormDb = gormDb.Where("`creater` = ?", userCont.Key) } case 6: default: gormDb = gormDb.Where("`creater` = ?", userCont.Key) } } else { switch powerInfo.AppSystem.Level { case 2, 3, 4, 5: if len(powerInfo.AppSystem.OrgList) > 0 { gormDb = gormDb.Where("f.`createrOrg` IN ?", powerInfo.AppSystem.OrgList) } else { gormDb = gormDb.Where("f.`creater` = ?", userCont.Key) } case 6: default: gormDb = gormDb.Where("f.`creater` = ?", userCont.Key) } } return gormDb }