customize_menu.go
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/utils"
)
type CustomizeMenuDto struct {
}
func (dto *CustomizeMenuDto) LoadDto(menus []*domain.Menu, customizeMenus []*domain.CustomizeMenu, rootMenu *domain.Menu) (interface{}, error) {
var ret []interface{}
ret = append(ret, rootMenu)
menusMap := make(map[int64]*domain.Menu)
menusMap[rootMenu.MenuId] = rootMenu
for i := range menus {
menusMap[menus[i].MenuId] = menus[i]
}
for i := range customizeMenus {
m := customizeMenus[i]
if menu, ok := menusMap[m.MenuId]; ok {
menu.MenuAlias = m.MenuAlias
menu.Sort = m.Sort
}
}
for i := range menus {
fieldMenu := utils.LoadCustomFieldToMap(menus[i], "MenuId", "ParentId", "MenuName", "Code", "Icon", "MenuAlias", "MenuType", "Remark", "Sort", "EnableStatus")
fieldMenu["parentMenuName"] = ""
if menu, ok := menusMap[menus[i].ParentId]; ok {
fieldMenu["parentMenuName"] = menu.MenuName
}
ret = append(ret, fieldMenu)
}
return ret, nil
}