Przeglądaj źródła

Merge remote-tracking branch 'origin/debug' into debug

Roc 11 miesięcy temu
rodzic
commit
c2344a1136

+ 14 - 3
controllers/fe_calendar/fe_calendar_matter.go

@@ -343,16 +343,27 @@ func (this *FeCalendarMatterController) PermissionList() {
 		this.ServeJSON()
 	}()
 
-	list, e := models.GetSecondaryChartPermissions()
+	permissions, e := models.GetChartPermissionsByProductId()
 	if e != nil {
 		br.Msg = "获取失败"
-		br.ErrMsg = "获取二级品种列表失败, Err: " + e.Error()
+		br.ErrMsg = "获取品种列表失败, Err: " + e.Error()
 		return
 	}
 	resp := make([]*models.SimpleChartPermission, 0)
-	for _, v := range list {
+	parentPermissions := make(map[int][]*models.SimpleChartPermission, 0)
+	for _, v := range permissions {
+		if v.ParentId > 0 {
+			if parentPermissions[v.ParentId] == nil {
+				parentPermissions[v.ParentId] = make([]*models.SimpleChartPermission, 0)
+			}
+			parentPermissions[v.ParentId] = append(parentPermissions[v.ParentId], models.FormatChartPermission2Simple(v))
+			continue
+		}
 		resp = append(resp, models.FormatChartPermission2Simple(v))
 	}
+	for _, v := range resp {
+		v.Children = parentPermissions[v.ChartPermissionId]
+	}
 
 	br.Data = resp
 	br.Ret = 200

+ 13 - 2
models/chart_permission.go

@@ -240,8 +240,10 @@ func GetSecondaryChartPermissions() (list []*ChartPermission, err error) {
 }
 
 type SimpleChartPermission struct {
-	ChartPermissionId   int    `description:"品种ID"`
-	ChartPermissionName string `description:"品种名称"`
+	ChartPermissionId   int                      `description:"品种ID"`
+	ChartPermissionName string                   `description:"品种名称"`
+	Sort                int                      `description:"排序"`
+	Children            []*SimpleChartPermission `description:"子分类"`
 }
 
 func FormatChartPermission2Simple(origin *ChartPermission) (item *SimpleChartPermission) {
@@ -251,5 +253,14 @@ func FormatChartPermission2Simple(origin *ChartPermission) (item *SimpleChartPer
 	item = new(SimpleChartPermission)
 	item.ChartPermissionId = origin.ChartPermissionId
 	item.ChartPermissionName = origin.PermissionName
+	item.Sort = origin.Sort
+	return
+}
+
+// GetChartPermissionsByProductId 获取权限列表
+func GetChartPermissionsByProductId() (list []*ChartPermission, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM chart_permission WHERE product_id = ? AND enabled = 1 ORDER BY parent_id ASC, sort ASC, created_time ASC`
+	_, err = o.Raw(sql, FiccProductId).QueryRows(&list)
 	return
 }