package jurisdictionpc import ( "key_performance_indicators/models/modelssystempermission" "key_performance_indicators/overall" "key_performance_indicators/overall/publicmethod" "strconv" "strings" "time" "github.com/gin-gonic/gin" ) // 编辑权限 func (a *ApiMethod) EditPower(c *gin.Context) { var receivedValue appPowerStruct err := c.ShouldBindJSON(&receivedValue) if err != nil { publicmethod.Result(100, err, c) return } if receivedValue.OrdId == "" { publicmethod.Result(1, receivedValue, c, "请指定要配置的行政组织!") return } if receivedValue.PostId == "" { publicmethod.Result(1, receivedValue, c, "请指定要配置的岗位!") return } if receivedValue.SystemName == "" { publicmethod.Result(1, err, c, "请提交系统识别符!") return } if len(receivedValue.PointId) < 1 { publicmethod.Result(1, err, c, "请至少指定一项权限!") return } var empowerCont modelssystempermission.Empower err = empowerCont.GetCont(map[string]interface{}{"`ordid`": receivedValue.OrdId, "`post_id`": receivedValue.PostId, "`system`": receivedValue.SystemName}, "`id`") postIdStr := strings.Join(receivedValue.PointId, ",") if err == nil { err = empowerCont.EiteCont(map[string]interface{}{"`id`": empowerCont.Id}, map[string]interface{}{"`state`": 1, "`point_id`": postIdStr, "`time`": time.Now().Unix()}) } else { 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 = postIdStr //权限点位"` empowerCont.State = 1 //状态(1:启用;2:禁用;3:删除)"` empowerCont.Time = time.Now().Unix() //创建时间"` err = overall.CONSTANT_DB_System_Permission.Create(&empowerCont).Error } if err != nil { publicmethod.Result(104, err, c) return } publicmethod.Result(0, err, c) // for i := 0; i < len(receivedValue.PointId); i++ { // var empowerCont modelssystempermission.Empower // err = empowerCont.GetCont(map[string]interface{}{"`post_id`": receivedValue.PostId, "`system`": receivedValue.SystemName, "`point_id`": receivedValue.PointId[i]}) // if err == nil { // if empowerCont.State != 1 { // empowerCont.EiteCont(map[string]interface{}{"`id`": empowerCont.Id}, map[string]interface{}{"`state`": 1, "`time`": time.Now().Unix()}) // } // } else { // postIdInt64, _ := strconv.ParseInt(receivedValue.PostId, 10, 64) // empowerCont.PostId = postIdInt64 //岗位ID"` // empowerCont.System = receivedValue.SystemName //系统"` // poinIdInt64, _ := strconv.ParseInt(receivedValue.PointId[i], 10, 64) // empowerCont.PointId = poinIdInt64 //权限点位"` // empowerCont.State = 1 //状态(1:启用;2:禁用;3:删除)"` // empowerCont.Time = time.Now().Unix() //创建时间"` // saveData = append(saveData, empowerCont) // } // } // if len(saveData) > 0 { // err = overall.CONSTANT_DB_System_Permission.Create(&saveData).Error // } // if err != nil { // publicmethod.Result(104, err, c) // return // } // //清除其他权限 // otherSaveData := publicmethod.MapOut[string]() // otherSaveData["`state`"] = 2 // otherSaveData["`time`"] = time.Now().Unix() // overall.CONSTANT_DB_System_Permission.Model(&modelssystempermission.Empower{}).Where("`state` = 1 AND `post_id` = ? AND `system` = ?", receivedValue.PostId, receivedValue.SystemName).Not(map[string]interface{}{"point_id": receivedValue.PointId}).Updates(&otherSaveData) // publicmethod.Result(0, saveData, c) }