forked from xinliangnote/go-gin-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service_mymenu.go
69 lines (58 loc) · 1.63 KB
/
service_mymenu.go
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
package admin
import (
"github.com/imlida/go-gin-api/internal/pkg/core"
"github.com/imlida/go-gin-api/internal/repository/mysql"
"github.com/imlida/go-gin-api/internal/repository/mysql/admin_menu"
"github.com/imlida/go-gin-api/internal/repository/mysql/menu"
)
type SearchMyMenuData struct {
AdminId int32 `json:"admin_id"` // 管理员ID
}
type ListMyMenuData struct {
Id int32 `json:"id"` // ID
Pid int32 `json:"pid"` // 父类ID
Name string `json:"name"` // 菜单名称
Link string `json:"link"` // 链接地址
Icon string `json:"icon"` // 图标
}
func (s *service) MyMenu(ctx core.Context, searchData *SearchMyMenuData) (menuData []ListMyMenuData, err error) {
adminMenuQb := admin_menu.NewQueryBuilder()
if searchData.AdminId != 0 {
adminMenuQb.WhereAdminId(mysql.EqualPredicate, searchData.AdminId)
}
adminMenuListData, err := adminMenuQb.
OrderById(false).
QueryAll(s.db.GetDb("default").WithContext(ctx.RequestContext()))
if err != nil {
return nil, err
}
if len(adminMenuListData) <= 0 {
return
}
menuQb := menu.NewQueryBuilder()
menuQb.WhereIsDeleted(mysql.EqualPredicate, -1)
menuListData, err := menuQb.
OrderBySort(true).
QueryAll(s.db.GetDb("default").WithContext(ctx.RequestContext()))
if err != nil {
return nil, err
}
if len(menuListData) <= 0 {
return
}
for _, menuAllV := range menuListData {
for _, v := range adminMenuListData {
if menuAllV.Id == v.MenuId {
data := ListMyMenuData{
Id: menuAllV.Id,
Pid: menuAllV.Pid,
Name: menuAllV.Name,
Link: menuAllV.Link,
Icon: menuAllV.Icon,
}
menuData = append(menuData, data)
}
}
}
return
}