menu.go
4.4 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package service
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/menu/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/background/menu/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
)
// 菜单服务
type MenuService struct {
}
// 创建菜单服务
func (menuService *MenuService) CreateMenu(createMenuCommand *command.CreateMenuCommand) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
createMenuCommand.Operator)
result, err := creationUserGateway.MenusCreate(allied_creation_user.ReqMenus{
ParentId: createMenuCommand.ParentId,
MenuName: createMenuCommand.MenuName,
Code: createMenuCommand.Code,
AccessCode: createMenuCommand.AccessCode,
MenuType: createMenuCommand.MenuType,
Icon: createMenuCommand.Icon,
Sort: createMenuCommand.Sort,
Desc: createMenuCommand.Desc,
IsPublish: createMenuCommand.IsPublish,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return result, nil
}
// 返回菜单服务
func (menuService *MenuService) GetMenu(getMenuQuery *query.GetMenuQuery) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
getMenuQuery.Operator)
result, err := creationUserGateway.MenusGet(allied_creation_user.ReqMenusGet{
MenuId: getMenuQuery.MenuId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return result, nil
}
// 返回菜单服务列表
func (menuService *MenuService) ListMenu(listMenuQuery *query.ListMenuQuery) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
listMenuQuery.Operator)
result, err := creationUserGateway.MenusSearch(allied_creation_user.ReqMenusSearch{
MenuCategory: listMenuQuery.MenuCategory,
ParentId: listMenuQuery.ParentId,
MenuName: listMenuQuery.MenuName,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return result, nil
}
// 移除菜单服务
func (menuService *MenuService) RemoveMenu(removeMenuCommand *command.RemoveMenuCommand) (interface{}, error) {
return struct{}{}, nil
}
// 更新菜单服务
func (menuService *MenuService) UpdateMenu(updateMenuCommand *command.UpdateMenuCommand) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
updateMenuCommand.Operator)
result, err := creationUserGateway.MenusUpdate(allied_creation_user.ReqMenusUpdate{
MenuId: updateMenuCommand.MenuId,
ParentId: updateMenuCommand.ParentId,
MenuName: updateMenuCommand.MenuName,
Code: updateMenuCommand.Code,
AccessCode: updateMenuCommand.AccessCode,
MenuType: updateMenuCommand.MenuType,
Icon: updateMenuCommand.Icon,
Sort: updateMenuCommand.Sort,
Desc: updateMenuCommand.Remark,
IsPublish: updateMenuCommand.IsPublish,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return result, nil
}
// 批量删除菜单
func (menuService *MenuService) BatchDeleteMenu(batchDeleteMenu *command.BatchDeleteMenuCommand) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
batchDeleteMenu.Operator)
result, err := creationUserGateway.MenusBatchDelete(allied_creation_user.ReqMenusBatchDelete{
MenuIds: batchDeleteMenu.MenuIds,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return result, nil
}
// 批量启用菜单
func (menuService *MenuService) BatchEnableMenu(batchEnableMenu *command.BatchEnableMenuCommand) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
batchEnableMenu.Operator)
result, err := creationUserGateway.MenusBatchEnable(allied_creation_user.ReqMenusBatchEnable{
MenuIds: batchEnableMenu.MenuIds,
Status: batchEnableMenu.Status,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return result, nil
}
func NewMenuService(options map[string]interface{}) *MenuService {
newMenuService := &MenuService{}
return newMenuService
}