package jurisdictionpc import ( "fmt" "key_performance_indicators/models/modelshr" "key_performance_indicators/models/modelssystempermission" "key_performance_indicators/overall" "key_performance_indicators/overall/publicmethod" "strconv" "strings" "time" "github.com/gin-gonic/gin" ) /* * @ 作者: 秦东 @ 时间: 2023-05-29 13:06:32 @ 功能: 给指定岗位授权 @ 参数 # @ 返回值 # @ 方法原型 # */ func (a *ApiMethod) GrantPostSystemPowers(c *gin.Context) { var receivedValue editPowerStructNew err := c.ShouldBindJSON(&receivedValue) if err != nil { publicmethod.Result(100, err, c) return } if receivedValue.OrdId == "" || receivedValue.OrdId == "0" { publicmethod.Result(1, receivedValue, c, "未知行政组织!不可进行配权") return } if receivedValue.PostId == "" || receivedValue.PostId == "0" { publicmethod.Result(1, receivedValue, c, "未知岗位!不可进行配权") return } if receivedValue.SystemName == "" { publicmethod.Result(1, receivedValue, c, "未知配权系统!不可进行配权") return } if receivedValue.Level == 0 { receivedValue.Level = 2 } var orgIdList []int64 switch receivedValue.Level { case 2: //本部门 orgIdInt, _ := strconv.ParseInt(receivedValue.OrdId, 10, 64) _, _, departmentId, _, _ := publicmethod.GetOrgStructure(orgIdInt) // orgIdList = publicmethod.GetDepartmentSun(departmentId, orgIdList) var getSunOrg publicmethod.GetOrgAllSun getSunOrg.GetOrgSun(departmentId) orgIdList = getSunOrg.Id orgIdList = append(orgIdList, departmentId) case 3: //本分部 orgIdInt, _ := strconv.ParseInt(receivedValue.OrdId, 10, 64) _, companyId, _, _, _ := publicmethod.GetOrgStructure(orgIdInt) // orgIdList = publicmethod.GetDepartmentSun(companyId, orgIdList) var getSunOrg publicmethod.GetOrgAllSun getSunOrg.GetOrgSun(companyId) orgIdList = getSunOrg.Id orgIdList = append(orgIdList, companyId) case 4: //指定行政组织 case 5: //所有 overall.CONSTANT_DB_HR.Model(&modelshr.AdministrativeOrganization{}).Select("`id`").Where("`state` = 1").Find(&orgIdList) default: //本岗位 orgIdInt, _ := strconv.ParseInt(receivedValue.OrdId, 10, 64) orgIdList = append(orgIdList, orgIdInt) } var orgIdListAry []string //行政组织 for _, v := range orgIdList { orgIdListAry = append(orgIdListAry, strconv.FormatInt(v, 10)) } orgIdListStr := strings.Join(orgIdListAry, ",") addTime := time.Now().Unix() var empowerCont modelssystempermission.Empower err = empowerCont.GetCont(map[string]interface{}{"`ordid`": receivedValue.OrdId, "`post_id`": receivedValue.PostId, "`system`": receivedValue.SystemName}, "`id`") if len(receivedValue.PowerList) > 0 { var menuList []string //权限点位 var menuOperationList []string //操作点位 for _, v := range receivedValue.PowerList { switch receivedValue.SystemName { case "kpi": if v.Attribute != 4 { menuList = append(menuList, v.Key) } if v.Attribute == 4 { menuOperationList = append(menuOperationList, v.Key) } case "cangchu": menuList = append(menuList, v.Key) default: menuList = append(menuList, v.Key) } } menuListStr := strings.Join(menuList, ",") menuOperationListStr := strings.Join(menuOperationList, ",") fmt.Printf("操作点位-------->%v-------->%v\n", menuOperationListStr, menuOperationList) if err != nil { ordIdInt64, _ := strconv.ParseInt(receivedValue.OrdId, 10, 64) empowerCont.OrdId = ordIdInt64 //行政组织"` postIdInt64, _ := strconv.ParseInt(receivedValue.PostId, 10, 64) empowerCont.PostId = postIdInt64 //岗位ID"` empowerCont.System = receivedValue.SystemName //系统"` empowerCont.PointId = menuListStr //权限点位"` empowerCont.State = 1 //状态(1:启用;2:禁用;3:删除)"` empowerCont.Time = time.Now().Unix() //创建时间"` empowerCont.Level = receivedValue.Level empowerCont.Operation = menuOperationListStr empowerCont.Organization = orgIdListStr err = overall.CONSTANT_DB_System_Permission.Create(&empowerCont).Error } else { err = empowerCont.EiteCont(map[string]interface{}{"`id`": empowerCont.Id}, map[string]interface{}{"`point_id`": menuListStr, "`operation`": menuOperationListStr, "`level`": receivedValue.Level, "`time`": addTime, "`state`": 1, "`organization`": orgIdListStr}) if err != nil { publicmethod.Result(1, err, c, "权限配置失败") return } } } else { if err == nil { err = empowerCont.EiteCont(map[string]interface{}{"`id`": empowerCont.Id}, map[string]interface{}{"`point_id`": "", "`operation`": "", "`level`": receivedValue.Level, "`time`": addTime, "`state`": 1, "`organization`": orgIdListStr}) if err != nil { publicmethod.Result(1, err, c, "权限配置失败") return } } } publicmethod.Result(0, err, c) } /* * @ 作者: 秦东 @ 时间: 2023-05-30 14:59:12 @ 功能: @ 参数 # @ 返回值 # @ 方法原型 # */ func (a *ApiMethod) GrantRoleSystemPowers(c *gin.Context) { var receivedValue editRolePowerStructNew err := c.ShouldBindJSON(&receivedValue) if err != nil { publicmethod.Result(100, err, c) return } if receivedValue.RoleId == "" || receivedValue.RoleId == "0" { publicmethod.Result(1, receivedValue, c, "未知角色!不可进行配权") return } if receivedValue.SystemName == "" { publicmethod.Result(1, receivedValue, c, "未知配权系统!不可进行配权") return } if receivedValue.Level == 0 { receivedValue.Level = 2 } addTime := time.Now().Unix() var empowerCont modelssystempermission.RoleEmpower err = empowerCont.GetCont(map[string]interface{}{"`role_id`": receivedValue.RoleId, "`system`": receivedValue.SystemName}, "`id`") if len(receivedValue.PowerList) < 1 { if err == nil { err = empowerCont.EiteCont(map[string]interface{}{"`id`": empowerCont.Id}, map[string]interface{}{"`point_id`": "", "`operation`": "", "`level`": receivedValue.Level, "`time`": addTime, "`state`": 1}) if err != nil { publicmethod.Result(1, err, c, "权限配置失败") return } } } else { var menuList []string //权限点位 var menuOperationList []string //操作点位 for _, v := range receivedValue.PowerList { switch receivedValue.SystemName { case "kpi": if v.Attribute != 4 { menuList = append(menuList, v.Key) } if v.Attribute == 4 { menuOperationList = append(menuOperationList, v.Key) } case "cangchu": menuList = append(menuList, v.Key) default: menuList = append(menuList, v.Key) } } menuListStr := strings.Join(menuList, ",") menuOperationListStr := strings.Join(menuOperationList, ",") if err == nil { err = empowerCont.EiteCont(map[string]interface{}{"`id`": empowerCont.Id}, map[string]interface{}{"`point_id`": menuListStr, "`operation`": menuOperationListStr, "`level`": receivedValue.Level, "`time`": addTime, "`state`": 1}) if err != nil { publicmethod.Result(1, err, c, "权限配置失败") return } } else { roleIdInt, _ := strconv.ParseInt(receivedValue.RoleId, 10, 64) empowerCont.RoleId = roleIdInt //行政组织"` empowerCont.System = receivedValue.SystemName //系统"` empowerCont.PointId = menuListStr //权限点位"` empowerCont.State = 1 //状态(1:启用;2:禁用;3:删除)"` empowerCont.Time = addTime //创建时间"` empowerCont.Level = receivedValue.Level //授权范围等级(1:本部门;2:本分部;3:所有)"` empowerCont.Operation = menuOperationListStr //操作点位 err = overall.CONSTANT_DB_System_Permission.Create(&empowerCont).Error if err != nil { publicmethod.Result(1, err, c, "权限配置失败") return } } } publicmethod.Result(0, err, c) }