diff --git a/controllers/role.go b/controllers/role.go index 35aa115..c707ada 100644 --- a/controllers/role.go +++ b/controllers/role.go @@ -13,6 +13,7 @@ import ( "time" "fmt" + "github.com/astaxie/beego" "github.com/george518/PPGo_Job/models" ) @@ -100,13 +101,18 @@ func (self *RoleController) AjaxSave() { if id, err := models.RoleAdd(role); err != nil { self.ajaxMsg(err.Error(), MSG_ERR) } else { - ra := new(models.RoleAuth) + ras := make([]models.RoleAuth, 0) authsSlice := strings.Split(auths, ",") for _, v := range authsSlice { + //ra := new(models.RoleAuth) + ra := models.RoleAuth{} aid, _ := strconv.Atoi(v) ra.AuthId = aid ra.RoleId = id - models.RoleAuthAdd(ra) + ras = append(ras, ra) + } + if len(ras) > 0 { + models.RoleAuthBatchAdd(&ras) } } self.ajaxMsg("", MSG_OK) @@ -120,15 +126,20 @@ func (self *RoleController) AjaxSave() { } else { // 删除该角色权限 models.RoleAuthDelete(role_id) - ra := new(models.RoleAuth) + + ras := make([]models.RoleAuth, 0) authsSlice := strings.Split(auths, ",") for _, v := range authsSlice { + //ra := new(models.RoleAuth) + ra := models.RoleAuth{} aid, _ := strconv.Atoi(v) ra.AuthId = aid ra.RoleId = int64(role_id) - models.RoleAuthAdd(ra) + ras = append(ras, ra) + } + if len(ras) > 0 { + models.RoleAuthBatchAdd(&ras) } - } self.ajaxMsg("", MSG_OK) } diff --git a/models/role_auth.go b/models/role_auth.go index c240f99..16f5237 100644 --- a/models/role_auth.go +++ b/models/role_auth.go @@ -28,6 +28,10 @@ func RoleAuthAdd(ra *RoleAuth) (int64, error) { return orm.NewOrm().Insert(ra) } +func RoleAuthBatchAdd(ras *[]RoleAuth) (int64, error) { + return orm.NewOrm().InsertMulti(100, ras) +} + func RoleAuthGetById(id int) ([]*RoleAuth, error) { list := make([]*RoleAuth, 0) query := orm.NewOrm().QueryTable(TableName("uc_role_auth"))