From dbcc43aab2ebda97e7a0437d255cc97cfcae829e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=9D=E5=A4=A7=E5=85=A8?= Date: Thu, 30 Aug 2018 00:01:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=A7=92=E8=89=B2=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=EF=BC=8C=E6=96=B0=E5=A2=9E=E6=89=B9=E9=87=8F=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/role.go | 21 ++++++++++++++++----- models/role_auth.go | 4 ++++ 2 files changed, 20 insertions(+), 5 deletions(-) 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"))