Skip to content

Commit 1a70ba9

Browse files
authored
Merge pull request kvnZero#13 from kvnZero/feat/测试中修改
Feat/测试中修改
2 parents 8113307 + d0ca14c commit 1a70ba9

File tree

8 files changed

+289
-232
lines changed

8 files changed

+289
-232
lines changed

app/ApiJson/Entity/ConditionEntity.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ class ConditionEntity
1111
*/
1212
protected array $where = [];
1313

14-
protected int $limit = 0;
14+
protected int $limit = 10;
1515
protected int $offset = 0;
16-
protected array $column = ['*'];
16+
protected string $column = '*';
1717
protected array $group = [];
1818
protected array $order = [];
1919
protected array $having = [];
@@ -60,9 +60,9 @@ public function addQueryWhere(string $key, string $sql, array $bindArgs = [])
6060
}
6161

6262
/**
63-
* @param array|string[] $column
63+
* @param string $column
6464
*/
65-
public function setColumn(array $column): void
65+
public function setColumn(string $column): void
6666
{
6767
$this->column = $column;
6868
}
@@ -108,9 +108,9 @@ public function setOrder(array $order): void
108108
}
109109

110110
/**
111-
* @return array
111+
* @return string
112112
*/
113-
public function getColumn(): array
113+
public function getColumn(): string
114114
{
115115
return $this->column;
116116
}

app/ApiJson/Handle/AbstractHandle.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ protected function subTableQuery(array $data): QueryInterface
6565
{
6666
$tableName = $data['from'];
6767
$tableEntity = new TableEntity($tableName, $data);
68-
$handle = new Handle($tableEntity->getConditionEntity(), $tableEntity);
68+
$conditionEntity = $tableEntity->getConditionEntity();
69+
$conditionEntity->setLimit(0);
70+
$handle = new Handle($conditionEntity, $tableEntity);
6971
$handle->build();
7072
/** @var QueryInterface $query */
7173
return new (ApplicationContext::getContainer()->get(ConfigInterface::class)->get(QueryInterface::class))($tableEntity->getRealTableName(), $tableEntity->getConditionEntity());

app/ApiJson/Handle/FunctionColumnHandle.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function buildModel()
1616
}, ARRAY_FILTER_USE_KEY) as $key => $value)
1717
{
1818
$value = str_replace([';',':'], [',', ' AS '], $value);
19-
$this->condition->setColumn(explode(',', $value));
19+
$this->condition->setColumn($value);
2020
$this->unsetKey[] = $this->keyWord;
2121
}
2222
}

app/ApiJson/Handle/WhereSubQueryHandle.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ protected function buildModel()
1212
{
1313
$query = $this->subTableQuery($value);
1414

15-
$op = '=';
15+
$op = ' = ';
1616
if(str_ends_with($key, '>=@')) {
17-
$op = '>=';
17+
$op = ' >= ';
1818
} else if(str_ends_with($key, '<=@')) {
19-
$op = '<=';
19+
$op = ' <= ';
2020
} else if(str_ends_with($key, '>@')) {
21-
$op = '>';
21+
$op = ' > ';
2222
} else if(str_ends_with($key, '<@')) {
23-
$op = '<';
23+
$op = ' < ';
24+
} else if(str_ends_with($key, '{}@')) {
25+
$op = ' IN ';
2426
}
2527
$sql = sprintf('`%s`%s(%s)', $this->sanitizeKey($key), $op, $query->toSql());
2628
$this->condition->addQueryWhere($key, $sql, $query->getBindings());

app/ApiJson/Model/MysqlQuery.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ protected function buildQuery(bool $query = true)
102102
}
103103
if (!$query) return; //下面不再非查询操作
104104

105-
$this->db->select($this->conditionEntity->getColumn());
105+
$this->db->select(Db::raw($this->conditionEntity->getColumn()));
106106
$limit = $this->conditionEntity->getLimit();
107107
if ($limit > 0) {
108108
$this->db->limit($limit);

app/ApiJson/Parse/Parse.php

+11-3
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ public function __construct(protected array $json, protected string $method = 'G
3939

4040
public function handle(bool $isQueryMany = false, array $extendData = []): array
4141
{
42+
if (empty($extendData)) {
43+
$extendData = $this->json; //引入原json
44+
}
4245
$result = [];
4346
foreach ($this->json as $tableName => $condition) { //可以优化成协程行为(如果没有依赖赋值的前提下)
47+
if (is_null($condition)) continue;
4448
if (in_array($tableName, $this->filterKey())) {
4549
$this->tagColumn[$tableName] = $condition;
4650
continue;
@@ -56,9 +60,9 @@ public function handle(bool $isQueryMany = false, array $extendData = []): array
5660
if (str_ends_with($tableName, '[]')) {
5761
$isQueryMany = true;
5862
}
59-
// if (!preg_match("/^[A-Za-z]+$/", $tableName) || !is_array($condition)) {
60-
// continue; //不满足表名规范 跳出不往下执行
61-
// }
63+
if (!preg_match("/^[A-Z].+/", $tableName) || !is_array($condition)) {
64+
continue; //不满足表名规范 跳出不往下执行
65+
}
6266
$this->tableEntities[$tableName] = new TableEntity($tableName, $this->json, $this->getGlobalArgs(), array_merge($result, $extendData));
6367
foreach ($this->supMethod as $methodClass) {
6468
/** @var AbstractMethod $method */
@@ -93,6 +97,10 @@ protected function handleArray(array $jsonData, array $extendData = []): array
9397
{
9498
$result = [[]];
9599
foreach ($jsonData as $tableName => $condition) { //可以优化成协程行为(如果没有依赖赋值的前提下)
100+
if (is_null($condition)) continue;
101+
if (!preg_match("/^[A-Z].+/", $tableName) || !is_array($condition)) {
102+
continue; //不满足表名规范 跳出不往下执行
103+
}
96104
foreach ($result as $key => $item) {
97105
if (in_array($tableName, $this->filterKey())) {
98106
$this->tagColumn[$tableName] = $condition;

app/ApiJson/Replace/QuoteReplace.php

+15-4
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,24 @@ protected function process()
99
$condition = $this->condition->getCondition();
1010

1111
foreach (array_filter($condition, function($key){
12-
return str_ends_with($key, '@') && !str_ends_with($key, '}{@');
12+
return str_ends_with($key, '@');
1313
}, ARRAY_FILTER_USE_KEY) as $key => $value)
1414
{
15+
if (!is_string($value)) continue;
1516
$path = str_replace(['/', '[]'], ['.', 'currentItem'], $value);
16-
$newKey = substr($key, 0, strlen($key) - 1);
17-
$condition[$newKey] = data_get($this->condition->getExtendData(), $path);
18-
unset($condition[$key]);
17+
if (str_starts_with($path, '.')) {
18+
$path = 'currentItem' . $path;
19+
}
20+
$value = data_get($this->condition->getExtendData(), $path);
21+
if (!is_null($value)) { //常规情况下的引用
22+
$newKey = substr($key, 0, strlen($key) - 1);
23+
$condition[$newKey] = $value;
24+
unset($condition[$key]);
25+
} else { //非常规情况下引入 比如引入子查询等
26+
$path .= '@';
27+
$value = data_get($this->condition->getExtendData(), $path);
28+
$condition[$key] = $value;
29+
}
1930
$this->condition->setCondition($condition);
2031
}
2132
}

0 commit comments

Comments
 (0)