@@ -24,6 +24,7 @@ type Node struct {
2424
2525 Data []model.Map // 需写入数据库的数据
2626 Where []model.Map // 条件
27+ Ret model.Map // 节点返回值
2728 RowKey string // 主键
2829
2930 structure * config.Structure
@@ -56,25 +57,27 @@ func (n *Node) parseReq(method string) {
5657 n .Where = append (n .Where , model.Map {})
5758
5859 for key , val := range item {
60+
5961 if key == consts .Role {
6062 n .Role = util .String (val )
61- } else {
62- key = n . action . DbFieldStyle ( n . ctx , n . tableName , key )
63+ continue
64+ }
6365
64- if method == http .MethodDelete {
66+ key = n .action .DbFieldStyle (n .ctx , n .tableName , key )
67+
68+ switch method {
69+ case http .MethodPost :
70+ n.Data [i ][key ] = val
71+ case http .MethodDelete :
72+ n.Where [i ][key ] = val
73+ case http .MethodPut :
74+ if key == n .RowKey || key == n .RowKey + "{}" {
6575 n.Where [i ][key ] = val
6676 } else {
67- if key == n .RowKey || key == n .RowKey + "{}" {
68- if method == http .MethodPut {
69- n.Where [i ][key ] = val
70- } else {
71- n.Data [i ][key ] = val
72- }
73- } else {
74- n.Data [i ][key ] = val
75- }
77+ n.Data [i ][key ] = val
7678 }
7779 }
80+
7881 }
7982 }
8083
@@ -103,10 +106,9 @@ func (n *Node) parse(ctx context.Context, method string) error {
103106 if err != nil {
104107 return err
105108 }
106-
109+ var accessRoles [] string
107110 if n .action .NoAccessVerify == false {
108111 // 1. 检查权限, 无权限就不用做参数检查了
109- var accessRoles []string
110112
111113 switch method {
112114 case http .MethodPost :
@@ -129,6 +131,8 @@ func (n *Node) parse(ctx context.Context, method string) error {
129131 return err
130132 }
131133
134+ n .whereUpdate (ctx , method , accessRoles )
135+
132136 return nil
133137}
134138
@@ -169,12 +173,18 @@ func (n *Node) checkAccess(ctx context.Context, method string, accessRoles []str
169173 return gerror .Newf ("node not access: %s with %s" , n .Key , n .Role )
170174 }
171175
176+ return nil
177+ }
178+
179+ // ? todo 整合到哪
180+ func (n * Node ) whereUpdate (ctx context.Context , method string , accessRoles []string ) error {
181+
172182 for i , item := range n .req {
173183
174184 condition := config .NewConditionRet ()
175185
176186 conditionReq := config.ConditionReq {
177- AccessName : n .tableName ,
187+ AccessName : n .Key ,
178188 TableAccessRoleList : accessRoles ,
179189 Method : method ,
180190 NodeRole : n .Role ,
@@ -252,7 +262,7 @@ func (n *Node) reqUpdate() error {
252262 }
253263 }
254264 k := key [0 : len (key )- 2 ]
255- val , err := n .action .Functions . Call (n .ctx , functionName , param )
265+ val , err := n .action .actionConfig . CallFunc (n .ctx , functionName , param )
256266 if err != nil {
257267 return err
258268 }
@@ -296,15 +306,13 @@ func (n *Node) reqUpdateBeforeDo() error {
296306 return nil
297307}
298308
299- func (n * Node ) do (ctx context.Context , method string , dataIndex int ) (ret model.Map , err error ) {
309+ func (n * Node ) do (ctx context.Context , method string ) (ret model.Map , err error ) {
300310
301311 err = EmitHook (ctx , BeforeExecutorDo , n , method )
302312 if err != nil {
303313 return nil , err
304314 }
305315
306- var count int64
307-
308316 switch method {
309317 case http .MethodPost :
310318
@@ -334,20 +342,17 @@ func (n *Node) do(ctx context.Context, method string, dataIndex int) (ret model.
334342 }
335343 }
336344
337- var id int64
338-
339- id , count , err = executor .GetActionExecutor (n .executor ).Insert (ctx , n .tableName , n .Data )
345+ ret , err := executor .GetActionExecutor (n .executor ).Do (ctx , executor.ActionExecutorReq {
346+ Method : method ,
347+ Table : n .tableName ,
348+ Data : n .Data ,
349+ Where : nil ,
350+ })
340351
341352 if err != nil {
342353 return nil , err
343354 }
344355
345- ret = model.Map {
346- "code" : 200 ,
347- "count" : count ,
348- "id" : id ,
349- }
350-
351356 if len (n .Data ) > 0 { //多条插入时返回值已经应该无意义了
352357
353358 jsonStyle := n .action .JsonFieldStyle
@@ -363,31 +368,25 @@ func (n *Node) do(ctx context.Context, method string, dataIndex int) (ret model.
363368 }
364369
365370 case http .MethodPut :
366- count , err = executor .GetActionExecutor (n .executor ).Update (ctx , n .tableName , n .Data [dataIndex ], n .Where [dataIndex ])
367- if err != nil {
368- return nil , err
369- }
370-
371- ret = model.Map {
372- "code" : 200 ,
373- "count" : count ,
374- }
375371 case http .MethodDelete :
376- count , err = executor .GetActionExecutor (n .executor ).Delete (ctx , n .tableName , n .Where [dataIndex ])
377- if err != nil {
378- return nil , err
379- }
380372
381- ret = model.Map {
382- "code" : 200 ,
383- "count" : count ,
384- }
373+ default :
374+ return nil , gerror .New ("undefined method:" + method )
385375 }
386376
387- if ret == nil {
388- return nil , gerror .New ("undefined method:" + method )
377+ ret , err = executor .GetActionExecutor (n .executor ).Do (ctx , executor.ActionExecutorReq {
378+ Method : method ,
379+ Table : n .tableName ,
380+ Data : n .Data ,
381+ Where : n .Where ,
382+ })
383+
384+ if err != nil {
385+ return nil , err
389386 }
390387
388+ n .Ret = ret
389+
391390 err = EmitHook (ctx , AfterExecutorDo , n , method )
392391 if err != nil {
393392 return nil , err
@@ -403,22 +402,11 @@ func (n *Node) execute(ctx context.Context, method string) (model.Map, error) {
403402 return nil , err
404403 }
405404
406- if method == http .MethodPost { // 新增时可以合并新增
407- ret , err := n .do (ctx , method , 0 )
408- if err != nil {
409- return nil , err
410- }
411- return ret , nil
412- } else {
413- for i , _ := range n .req {
414- _ , err := n .do (ctx , method , i )
415- if err != nil {
416- return nil , err
417- }
418- }
405+ ret , err := n .do (ctx , method )
406+ if err != nil {
407+ return nil , err
419408 }
420409
421- return model.Map {
422- "code" : 200 ,
423- }, nil
410+ n .Ret = ret
411+ return n .Ret , nil
424412}
0 commit comments