@@ -37,18 +37,15 @@ public function handle(): array
3737 'code ' => ResponseCode::SUCCESS ,
3838 'msg ' => ResponseCode::getMessage (ResponseCode::SUCCESS ),
3939 ];
40- foreach ($ this ->json as $ tableName => $ condition ) {
41- if (in_array ($ tableName , $ this ->filterKey ())) {
42- $ this ->tagColumn [$ tableName ] = $ condition ; //特殊
43- break ;
44- }
45- $ this ->tableEntities [$ tableName ] = new TableEntity ($ tableName , $ this ->json );
40+ $ this ->jsonParse ();
41+ foreach ($ this ->json as $ tableName => $ condition ) { //可以优化成协程行为(如果没有依赖赋值的前提下)
42+ $ this ->tableEntities [$ tableName ] = new TableEntity ($ tableName , $ this ->json , $ result );
4643 foreach ($ this ->supMethod as $ methodClass ) {
4744 /** @var AbstractMethod $method */
4845 $ method = new $ methodClass ($ this ->tableEntities [$ tableName ], $ this ->method );
4946 $ response = $ method ->handle ();
5047 if (!is_null ($ response )) {
51- $ result [$ tableName ] = $ response ;
48+ $ result [$ condition [ ' * ' ] ?? $ tableName ] = $ response ;
5249 break ;
5350 }
5451 }
@@ -57,6 +54,32 @@ public function handle(): array
5754 return $ result ;
5855 }
5956
57+ /**
58+ * 整理不同形式的json数据到统一格式再处理
59+ */
60+ protected function jsonParse ()
61+ {
62+ foreach ($ this ->json as $ tableName => $ condition ) { //可以优化成协程行为(如果没有依赖赋值的前提下)
63+ if (in_array ($ tableName , $ this ->filterKey ())) {
64+ $ this ->tagColumn [$ tableName ] = $ condition ; //特殊
65+ unset($ this ->json [$ tableName ]);
66+ break ;
67+ }
68+ if ($ tableName == '[] ' ) {
69+ $ count = (int )$ condition ['count ' ] ?? 10 ;
70+ $ page = (int )$ condition ['page ' ] ?? 1 ; //赋予默认值
71+ $ tableName = array_key_first ($ condition ); //剩下的值为table
72+ $ condition = $ condition [$ tableName ]; //替换条件
73+ $ condition = array_merge ($ condition , [
74+ '@limit ' => $ count , //查询长度
75+ '@offset ' => $ page * $ count , //查询起始长度
76+ '* ' => '[] ' //赋予替换表明的标志
77+ ]);
78+ $ this ->json [$ tableName . '[] ' ] = $ condition ;
79+ }
80+ }
81+ }
82+
6083 protected function filterKey (): array
6184 {
6285 return array_keys ($ this ->tagColumn );
0 commit comments