|
|
1
|
+package allied_creation_user
|
|
|
2
|
+
|
|
|
3
|
+import (
|
|
|
4
|
+ "encoding/json"
|
|
|
5
|
+ "fmt"
|
|
|
6
|
+ "strconv"
|
|
|
7
|
+
|
|
|
8
|
+ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway"
|
|
|
9
|
+ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
|
|
|
10
|
+)
|
|
|
11
|
+
|
|
|
12
|
+// MenusCreate 创建菜单
|
|
|
13
|
+func (gateway HttplibAlliedCreationUser) MenusCreate(param ReqMenus) (*DataMenus, error) {
|
|
|
14
|
+ url := gateway.baseUrL + "/menus"
|
|
|
15
|
+ method := "post"
|
|
|
16
|
+ req := gateway.CreateRequest(url, method)
|
|
|
17
|
+ log.Logger.Debug("向用户模块请求数据:创建菜单。", map[string]interface{}{
|
|
|
18
|
+ "api": method + ":" + url,
|
|
|
19
|
+ "param": param,
|
|
|
20
|
+ })
|
|
|
21
|
+ req, err := req.JSONBody(param)
|
|
|
22
|
+ if err != nil {
|
|
|
23
|
+ return nil, fmt.Errorf("请求创建菜单失败:%w", err)
|
|
|
24
|
+ }
|
|
|
25
|
+
|
|
|
26
|
+ byteResult, err := req.Bytes()
|
|
|
27
|
+ if err != nil {
|
|
|
28
|
+ return nil, fmt.Errorf("获取创建菜单失败:%w", err)
|
|
|
29
|
+ }
|
|
|
30
|
+ log.Logger.Debug("获取用户模块请求数据:创建菜单。", map[string]interface{}{
|
|
|
31
|
+ "result": string(byteResult),
|
|
|
32
|
+ })
|
|
|
33
|
+ var result service_gateway.GatewayResponse
|
|
|
34
|
+ err = json.Unmarshal(byteResult, &result)
|
|
|
35
|
+ if err != nil {
|
|
|
36
|
+ return nil, fmt.Errorf("解析创建菜单:%w", err)
|
|
|
37
|
+ }
|
|
|
38
|
+ var data DataMenus
|
|
|
39
|
+ err = gateway.GetResponseData(result, &data)
|
|
|
40
|
+ return &data, err
|
|
|
41
|
+}
|
|
|
42
|
+
|
|
|
43
|
+// MenusUpdate 更新菜单
|
|
|
44
|
+func (gateway HttplibAlliedCreationUser) MenusUpdate(param ReqMenusUpdate) (*DataMenusUpdate, error) {
|
|
|
45
|
+ url := gateway.baseUrL + "/menus/" + strconv.FormatInt(param.MenusId, 10)
|
|
|
46
|
+ method := "put"
|
|
|
47
|
+ req := gateway.CreateRequest(url, method)
|
|
|
48
|
+ log.Logger.Debug("向用户模块请求数据:更新菜单。", map[string]interface{}{
|
|
|
49
|
+ "api": method + ":" + url,
|
|
|
50
|
+ "param": param,
|
|
|
51
|
+ })
|
|
|
52
|
+ req, err := req.JSONBody(param)
|
|
|
53
|
+ if err != nil {
|
|
|
54
|
+ return nil, fmt.Errorf("请求更新菜单失败:%w", err)
|
|
|
55
|
+ }
|
|
|
56
|
+
|
|
|
57
|
+ byteResult, err := req.Bytes()
|
|
|
58
|
+ if err != nil {
|
|
|
59
|
+ return nil, fmt.Errorf("获取更新菜单失败:%w", err)
|
|
|
60
|
+ }
|
|
|
61
|
+ log.Logger.Debug("获取用户模块请求数据:更新菜单。", map[string]interface{}{
|
|
|
62
|
+ "result": string(byteResult),
|
|
|
63
|
+ })
|
|
|
64
|
+ var result service_gateway.GatewayResponse
|
|
|
65
|
+ err = json.Unmarshal(byteResult, &result)
|
|
|
66
|
+ if err != nil {
|
|
|
67
|
+ return nil, fmt.Errorf("解析更新菜单:%w", err)
|
|
|
68
|
+ }
|
|
|
69
|
+ var data DataMenusUpdate
|
|
|
70
|
+ err = gateway.GetResponseData(result, &data)
|
|
|
71
|
+ return &data, err
|
|
|
72
|
+}
|
|
|
73
|
+
|
|
|
74
|
+// MenusRemove 移除菜单
|
|
|
75
|
+func (gateway HttplibAlliedCreationUser) MenusRemove(param ReqMenusRemove) (*DataMenusRemove, error) {
|
|
|
76
|
+ url := gateway.baseUrL + "/menus/" + strconv.FormatInt(param.RoleId, 10)
|
|
|
77
|
+ method := "delete"
|
|
|
78
|
+ req := gateway.CreateRequest(url, method)
|
|
|
79
|
+ log.Logger.Debug("向用户模块请求数据:移除菜单。", map[string]interface{}{
|
|
|
80
|
+ "api": method + ":" + url,
|
|
|
81
|
+ "param": param,
|
|
|
82
|
+ })
|
|
|
83
|
+ req, err := req.JSONBody(param)
|
|
|
84
|
+ if err != nil {
|
|
|
85
|
+ return nil, fmt.Errorf("请求移除菜单失败:%w", err)
|
|
|
86
|
+ }
|
|
|
87
|
+
|
|
|
88
|
+ byteResult, err := req.Bytes()
|
|
|
89
|
+ if err != nil {
|
|
|
90
|
+ return nil, fmt.Errorf("获取移除菜单失败:%w", err)
|
|
|
91
|
+ }
|
|
|
92
|
+ log.Logger.Debug("获取用户模块请求数据:移除菜单。", map[string]interface{}{
|
|
|
93
|
+ "result": string(byteResult),
|
|
|
94
|
+ })
|
|
|
95
|
+ var result service_gateway.GatewayResponse
|
|
|
96
|
+ err = json.Unmarshal(byteResult, &result)
|
|
|
97
|
+ if err != nil {
|
|
|
98
|
+ return nil, fmt.Errorf("解析移除菜单:%w", err)
|
|
|
99
|
+ }
|
|
|
100
|
+ var data DataMenusRemove
|
|
|
101
|
+ err = gateway.GetResponseData(result, &data)
|
|
|
102
|
+ return &data, err
|
|
|
103
|
+}
|
|
|
104
|
+
|
|
|
105
|
+// MenusGet 返回菜单
|
|
|
106
|
+func (gateway HttplibAlliedCreationUser) MenusGet(param ReqMenusGet) (*DataMenusGet, error) {
|
|
|
107
|
+ url := gateway.baseUrL + "/menus/" + strconv.FormatInt(param.MenuId, 10)
|
|
|
108
|
+ method := "get"
|
|
|
109
|
+ req := gateway.CreateRequest(url, method)
|
|
|
110
|
+ log.Logger.Debug("向用户模块请求数据:返回菜单。", map[string]interface{}{
|
|
|
111
|
+ "api": method + ":" + url,
|
|
|
112
|
+ "param": param,
|
|
|
113
|
+ })
|
|
|
114
|
+ req, err := req.JSONBody(param)
|
|
|
115
|
+ if err != nil {
|
|
|
116
|
+ return nil, fmt.Errorf("请求返回菜单失败:%w", err)
|
|
|
117
|
+ }
|
|
|
118
|
+
|
|
|
119
|
+ byteResult, err := req.Bytes()
|
|
|
120
|
+ if err != nil {
|
|
|
121
|
+ return nil, fmt.Errorf("获取返回菜单失败:%w", err)
|
|
|
122
|
+ }
|
|
|
123
|
+ log.Logger.Debug("获取用户模块请求数据:返回菜单。", map[string]interface{}{
|
|
|
124
|
+ "result": string(byteResult),
|
|
|
125
|
+ })
|
|
|
126
|
+ var result service_gateway.GatewayResponse
|
|
|
127
|
+ err = json.Unmarshal(byteResult, &result)
|
|
|
128
|
+ if err != nil {
|
|
|
129
|
+ return nil, fmt.Errorf("解析返回菜单:%w", err)
|
|
|
130
|
+ }
|
|
|
131
|
+ var data DataMenusGet
|
|
|
132
|
+ err = gateway.GetResponseData(result, &data)
|
|
|
133
|
+ return &data, err
|
|
|
134
|
+}
|
|
|
135
|
+
|
|
|
136
|
+// MenusSearch 返回菜单列表
|
|
|
137
|
+func (gateway HttplibAlliedCreationUser) MenusSearch(param ReqMenusSearch) (*DataMenusSearch, error) {
|
|
|
138
|
+ url := gateway.baseUrL + "/menus/search"
|
|
|
139
|
+ method := "post"
|
|
|
140
|
+ req := gateway.CreateRequest(url, method)
|
|
|
141
|
+ log.Logger.Debug("向用户模块请求数据:返回菜单列表。", map[string]interface{}{
|
|
|
142
|
+ "api": method + ":" + url,
|
|
|
143
|
+ "param": param,
|
|
|
144
|
+ })
|
|
|
145
|
+ req, err := req.JSONBody(param)
|
|
|
146
|
+ if err != nil {
|
|
|
147
|
+ return nil, fmt.Errorf("请求返回菜单列表失败:%w", err)
|
|
|
148
|
+ }
|
|
|
149
|
+
|
|
|
150
|
+ byteResult, err := req.Bytes()
|
|
|
151
|
+ if err != nil {
|
|
|
152
|
+ return nil, fmt.Errorf("获取返回菜单列表失败:%w", err)
|
|
|
153
|
+ }
|
|
|
154
|
+ log.Logger.Debug("获取用户模块请求数据:返回菜单列表。", map[string]interface{}{
|
|
|
155
|
+ "result": string(byteResult),
|
|
|
156
|
+ })
|
|
|
157
|
+ var result service_gateway.GatewayResponse
|
|
|
158
|
+ err = json.Unmarshal(byteResult, &result)
|
|
|
159
|
+ if err != nil {
|
|
|
160
|
+ return nil, fmt.Errorf("解析返回菜单列表:%w", err)
|
|
|
161
|
+ }
|
|
|
162
|
+ var data DataMenusSearch
|
|
|
163
|
+ err = gateway.GetResponseData(result, &data)
|
|
|
164
|
+ return &data, err
|
|
|
165
|
+} |