优化角色创建,新增批量方法
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
"github.com/george518/PPGo_Job/models"
|
"github.com/george518/PPGo_Job/models"
|
||||||
)
|
)
|
||||||
@@ -100,13 +101,18 @@ func (self *RoleController) AjaxSave() {
|
|||||||
if id, err := models.RoleAdd(role); err != nil {
|
if id, err := models.RoleAdd(role); err != nil {
|
||||||
self.ajaxMsg(err.Error(), MSG_ERR)
|
self.ajaxMsg(err.Error(), MSG_ERR)
|
||||||
} else {
|
} else {
|
||||||
ra := new(models.RoleAuth)
|
ras := make([]models.RoleAuth, 0)
|
||||||
authsSlice := strings.Split(auths, ",")
|
authsSlice := strings.Split(auths, ",")
|
||||||
for _, v := range authsSlice {
|
for _, v := range authsSlice {
|
||||||
|
//ra := new(models.RoleAuth)
|
||||||
|
ra := models.RoleAuth{}
|
||||||
aid, _ := strconv.Atoi(v)
|
aid, _ := strconv.Atoi(v)
|
||||||
ra.AuthId = aid
|
ra.AuthId = aid
|
||||||
ra.RoleId = id
|
ra.RoleId = id
|
||||||
models.RoleAuthAdd(ra)
|
ras = append(ras, ra)
|
||||||
|
}
|
||||||
|
if len(ras) > 0 {
|
||||||
|
models.RoleAuthBatchAdd(&ras)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.ajaxMsg("", MSG_OK)
|
self.ajaxMsg("", MSG_OK)
|
||||||
@@ -120,15 +126,20 @@ func (self *RoleController) AjaxSave() {
|
|||||||
} else {
|
} else {
|
||||||
// 删除该角色权限
|
// 删除该角色权限
|
||||||
models.RoleAuthDelete(role_id)
|
models.RoleAuthDelete(role_id)
|
||||||
ra := new(models.RoleAuth)
|
|
||||||
|
ras := make([]models.RoleAuth, 0)
|
||||||
authsSlice := strings.Split(auths, ",")
|
authsSlice := strings.Split(auths, ",")
|
||||||
for _, v := range authsSlice {
|
for _, v := range authsSlice {
|
||||||
|
//ra := new(models.RoleAuth)
|
||||||
|
ra := models.RoleAuth{}
|
||||||
aid, _ := strconv.Atoi(v)
|
aid, _ := strconv.Atoi(v)
|
||||||
ra.AuthId = aid
|
ra.AuthId = aid
|
||||||
ra.RoleId = int64(role_id)
|
ra.RoleId = int64(role_id)
|
||||||
models.RoleAuthAdd(ra)
|
ras = append(ras, ra)
|
||||||
|
}
|
||||||
|
if len(ras) > 0 {
|
||||||
|
models.RoleAuthBatchAdd(&ras)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
self.ajaxMsg("", MSG_OK)
|
self.ajaxMsg("", MSG_OK)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ func RoleAuthAdd(ra *RoleAuth) (int64, error) {
|
|||||||
return orm.NewOrm().Insert(ra)
|
return orm.NewOrm().Insert(ra)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RoleAuthBatchAdd(ras *[]RoleAuth) (int64, error) {
|
||||||
|
return orm.NewOrm().InsertMulti(100, ras)
|
||||||
|
}
|
||||||
|
|
||||||
func RoleAuthGetById(id int) ([]*RoleAuth, error) {
|
func RoleAuthGetById(id int) ([]*RoleAuth, error) {
|
||||||
list := make([]*RoleAuth, 0)
|
list := make([]*RoleAuth, 0)
|
||||||
query := orm.NewOrm().QueryTable(TableName("uc_role_auth"))
|
query := orm.NewOrm().QueryTable(TableName("uc_role_auth"))
|
||||||
|
|||||||
Reference in New Issue
Block a user