@@ -37,6 +37,7 @@ type Action struct {
3737 err error
3838
3939 children map [string ]Node
40+ keyNode map [string ]* Node
4041}
4142
4243func New (ctx context.Context , method string , req g.Map ) * Action {
@@ -54,6 +55,7 @@ func New(ctx context.Context, method string, req g.Map) *Action {
5455 method : method ,
5556 req : req ,
5657 children : map [string ]Node {},
58+ keyNode : map [string ]* Node {},
5759 }
5860 return a
5961}
@@ -64,9 +66,15 @@ func (a *Action) parse() error {
6466
6567 for key , v := range a .req {
6668
69+ structuresKey := key
70+ if strings .HasSuffix (key , "[]" ) {
71+ structuresKey = structuresKey [0 : len (structuresKey )- 2 ]
72+ }
6773 structureMap , ok := structures [key ]
6874 if ! ok {
69- return gerror .New ("structure错误: 400, 缺少" + key )
75+ if structureMap , ok = structures [structuresKey ]; ! ok { //User[]可读取User或者User[]
76+ return gerror .New ("structure错误: 400, 缺少" + key )
77+ }
7078 }
7179
7280 structure := Structure {}
@@ -75,10 +83,22 @@ func (a *Action) parse() error {
7583 return err
7684 }
7785
86+ // todo 初始化时完成map2struct,不用每次都scan生成
7887 structure .Must = strings .Split (structure .Must [0 ], "," )
7988 structure .Refuse = strings .Split (structure .Refuse [0 ], "," )
8089
81- node := newNode (key , v .(g.Map ), structure )
90+ var list []g.Map
91+ _v , ok := v .(g.Map )
92+ if ok { // 将所有node都假设成列表, 如果单个则看成一个元素的批量
93+ list = []g.Map {_v }
94+ } else {
95+ list = v .([]g.Map )
96+ }
97+
98+ node := newNode (key , list , structure )
99+ node .ctx = a .ctx
100+ a .keyNode [key ] = & node
101+ node .keyNode = a .keyNode
82102 err = node .parse (a .ctx , a .method )
83103 if err != nil {
84104 return err
@@ -100,7 +120,9 @@ func (a *Action) Result() (g.Map, error) {
100120 ret := g.Map {}
101121
102122 err = g .DB ().Transaction (a .ctx , func (ctx context.Context , tx * gdb.TX ) error {
103- for k , node := range a .children {
123+ for _ , k := range a .tagRequest .ExecQueue {
124+
125+ node := a .children [k ]
104126 ret [k ], err = node .execute (ctx , a .method )
105127 if err != nil {
106128 return err
0 commit comments