Skip to content

Commit 75b51ad

Browse files
committed
update 支持一对一查询
1 parent 88318f8 commit 75b51ad

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

app/ApiJson/Method/HeadMethod.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace App\ApiJson\Method;
44

5-
use App\Constants\ResponseCode;
6-
75
class HeadMethod extends AbstractMethod
86
{
97
protected function validateCondition(): bool
@@ -16,8 +14,6 @@ protected function process()
1614
$conditionEntity = $this->tableEntity->getConditionEntity();
1715
$conditionEntity->setQueryCondition($this->query);
1816
return [
19-
'code' => ResponseCode::SUCCESS,
20-
'msg' => ResponseCode::getMessage(ResponseCode::SUCCESS),
2117
'count' => $this->query->count()
2218
];
2319
}

app/ApiJson/Method/PostMethod.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace App\ApiJson\Method;
44

5-
use App\ApiJson\Interface\QueryInterface;
65
use Hyperf\Utils\Arr;
76

87
class PostMethod extends AbstractMethod
@@ -15,9 +14,13 @@ protected function validateCondition(): bool
1514
protected function process()
1615
{
1716
$insertData = $this->tableEntity->getContent();
18-
if (!$this->isQueryMany() || Arr::isAssoc($insertData)) {
17+
$queryMany = $this->isQueryMany();
18+
if (!$queryMany && Arr::isAssoc($insertData)) {
1919
$insertData = [$insertData];
2020
}
21+
if (!$queryMany) {
22+
$insertData = [$insertData[0]];
23+
}
2124
$insertIds = [];
2225
foreach ($insertData as $insertItem) {
2326
$insertIds[] = $this->query->insertGetId($insertItem); //因为需要返回ID 直接insert($insertData)不能得到本次插入的ID 未找到相关可用方法替代

app/ApiJson/Parse/Parse.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function handle(bool $isQueryMany = false): array
3939
{
4040
$result = [];
4141
foreach ($this->json as $tableName => $condition) { //可以优化成协程行为(如果没有依赖赋值的前提下)
42+
$tableMany = false;
4243
if (in_array($tableName, $this->filterKey())) {
4344
$this->tagColumn[$tableName] = $condition;
4445
continue;
@@ -52,14 +53,21 @@ public function handle(bool $isQueryMany = false): array
5253
$result[$tableName] = $parse->handle(true); //提供行为
5354
continue; //跳出不往下执行
5455
}
56+
if (str_ends_with($tableName, '[]')) {
57+
$isQueryMany = true;
58+
$tableMany = true;
59+
}
60+
// if (!preg_match("/^[A-Za-z]+$/", $tableName) || !is_array($condition)) {
61+
// continue; //不满足表名规范 跳出不往下执行
62+
// }
5563
$this->tableEntities[$tableName] = new TableEntity($tableName, $this->json, $this->getGlobalArgs(), $result);
5664
foreach ($this->supMethod as $methodClass) {
5765
/** @var AbstractMethod $method */
5866
$method = new $methodClass($this->tableEntities[$tableName], $this->method);
5967
$method->setQueryMany($isQueryMany);
6068
$response = $method->handle();
6169
if (!is_null($response)) {
62-
if ($isQueryMany) {
70+
if ($isQueryMany && $tableMany == false) {
6371
$result = $response;
6472
} else {
6573
$result[$tableName] = $response;

0 commit comments

Comments
 (0)