浏览代码

Merge branch 'bzq/dev' of eta_mini/eta_mini_crm into debug

鲍自强 9 月之前
父节点
当前提交
1a681fedef
共有 4 个文件被更改,包括 50 次插入10 次删除
  1. 4 7
      controllers/chart_permission.go
  2. 17 1
      models/chart_permission.go
  3. 1 2
      models/response/chart_permission.go
  4. 28 0
      services/chart_permission.go

+ 4 - 7
controllers/chart_permission.go

@@ -24,12 +24,14 @@ func (this *ChartPermissionController) List() {
 	}()
 	userId, _ := this.GetInt("UserId")
 
-	publicMap, privateMap, err := services.GetChartPermissionList()
+	items, err := models.GetChartPermissionList()
 	if err != nil {
 		br.Msg = "权限列表获取失败"
 		br.ErrMsg = "权限列表获取失败,系统错误,Err:" + err.Error()
 		return
 	}
+	treeList := services.GetChartPermissionListTree(items, 0)
+	// publicMap, privateMap, err := services.GetChartPermissionList()
 	resp := new(response.ChartPermissionListresp)
 	if userId > 0 {
 		ids, err := models.GetChartPermissionIdByUserId(userId)
@@ -39,12 +41,7 @@ func (this *ChartPermissionController) List() {
 		}
 		resp.SelectedList = ids
 	}
-	for _, per := range publicMap {
-		resp.PublicList = append(resp.PublicList, per)
-	}
-	for _, per := range privateMap {
-		resp.PrivateList = append(resp.PrivateList, per)
-	}
+	resp.List = treeList
 
 	br.Ret = 200
 	br.Data = resp

+ 17 - 1
models/chart_permission.go

@@ -68,7 +68,16 @@ type ChartPermissionView struct {
 	PermissionName string `description:"权限名" json:"permission_name"`
 }
 
-func GetChartPermissionList(condition string, pars []interface{}) (items []*ChartPermission, err error) {
+type ChartPermissionListTree struct {
+	ChartPermissionId int                        `description:"权限ID"`
+	PermissionName    string                     `description:"权限名"`
+	ParentId          int                        `description:"父权限ID"`
+	IsPublic          int                        `description:"是否是公有权限"`
+	PublicChild       []*ChartPermissionListTree `description:"公有权限"`
+	PrivateChild      []*ChartPermissionListTree `description:"私有权限"`
+}
+
+func GetChartPermissionListByCondition(condition string, pars []interface{}) (items []*ChartPermission, err error) {
 	o := orm.NewOrmUsingDB("rddp")
 	sql := `SELECT * FROM chart_permission WHERE enabled=1 `
 	if condition != "" {
@@ -104,6 +113,13 @@ func GetChildChartPermissionListById(chartPermissionId int) (items []*ChartPermi
 	return
 }
 
+func GetChartPermissionList() (items []*ChartPermissionListTree, err error) {
+	o := orm.NewOrmUsingDB("rddp")
+	sql := `SELECT * FROM chart_permission WHERE enabled=1 `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
 func GetChartPermissionByParentId(parentId int) (items []*ChartPermissionList, err error) {
 	o := orm.NewOrmUsingDB("rddp")
 	sql := `SELECT * FROM chart_permission WHERE enabled=1 AND chart_permission_id=?`

+ 1 - 2
models/response/chart_permission.go

@@ -3,7 +3,6 @@ package response
 import "eta/eta_mini_crm/models"
 
 type ChartPermissionListresp struct {
-	PublicList   []*models.ChartPermissionList
-	PrivateList  []*models.ChartPermissionList
+	List         []*models.ChartPermissionListTree
 	SelectedList []int
 }

+ 28 - 0
services/chart_permission.go

@@ -37,6 +37,34 @@ func GetChartPermissionList() (publicMap, privateMap map[string]*models.ChartPer
 	return
 }
 
+// 获得全部的权限结构列表树形结构
+func GetChartPermissionListTree(list []*models.ChartPermissionListTree, parentId int) []*models.ChartPermissionListTree {
+	res := make([]*models.ChartPermissionListTree, 0)
+	for _, v := range list {
+		if v.ParentId == parentId {
+			t := new(models.ChartPermissionListTree)
+			t.ChartPermissionId = v.ChartPermissionId
+			t.PermissionName = v.PermissionName
+			t.ParentId = v.ParentId
+			for _, j := range list {
+				if j.ParentId == v.ChartPermissionId {
+					c := new(models.ChartPermissionListTree)
+					c.ChartPermissionId = j.ChartPermissionId
+					c.PermissionName = j.PermissionName
+					c.ParentId = j.ParentId
+					if j.IsPublic == 1 {
+						t.PublicChild = append(t.PublicChild, c)
+					} else {
+						t.PrivateChild = append(t.PrivateChild, c)
+					}
+				}
+			}
+			res = append(res, t)
+		}
+	}
+	return res
+}
+
 func copyChartPermissionList(src *models.ChartPermissionList) *models.ChartPermissionList {
 	tmp := &models.ChartPermissionList{
 		ChartPermissionId:     src.ChartPermissionId,