Skip to content

Commit d1d2389

Browse files
committed
update
1 parent 3863c3d commit d1d2389

File tree

2 files changed

+67
-18
lines changed

2 files changed

+67
-18
lines changed

server/app/Api/Controller/ItemController.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -739,27 +739,11 @@ public function update(Request $request, Response $response): Response
739739
return $this->error($response, 10303, '您没有管理权限');
740740
}
741741

742-
// 检查个性域名
743-
if (!empty($itemDomain)) {
744-
if (!ctype_alnum($itemDomain) || is_numeric($itemDomain)) {
745-
return $this->error($response, 10305, '个性域名只能是字母或数字的组合');
746-
}
747-
748-
$existing = DB::table('item')
749-
->where('item_domain', $itemDomain)
750-
->where('item_id', '!=', $itemId)
751-
->first();
752-
753-
if ($existing) {
754-
return $this->error($response, 10304, '个性域名已经存在');
755-
}
756-
}
757742

758743
// 准备更新数据
759744
$saveData = [
760745
'item_name' => $itemName,
761746
'item_description' => $itemDescription,
762-
'item_domain' => $itemDomain,
763747
'password' => $password,
764748
];
765749

server/app/Api/Controller/OpenController.php

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public function updateDbItem(Request $request, Response $response): Response
9191
$apiToken = $this->getParam($request, 'api_token', '');
9292
$tableInfo = $this->getParam($request, 'table_info', '');
9393
$tableDetail = $this->getParam($request, 'table_detail', '');
94+
$tableIndex = $this->getParam($request, 'table_index', '');
9495
$sNumber = $this->getParam($request, 's_number', 99);
9596
$catName = $this->getParam($request, 'cat_name', '');
9697

@@ -110,7 +111,8 @@ public function updateDbItem(Request $request, Response $response): Response
110111
$catName = str_replace(PHP_EOL, '', $catName);
111112
$tableInfo = str_replace("_this_and_change_", "&", $tableInfo);
112113
$tableDetail = str_replace("_this_and_change_", "&", $tableDetail);
113-
$tables = $this->analyzeDbStructureToArray($tableInfo, $tableDetail);
114+
$tableIndex = str_replace("_this_and_change_", "&", $tableIndex);
115+
$tables = $this->analyzeDbStructureToArray($tableInfo, $tableDetail, $tableIndex);
114116

115117
$result = false;
116118
if (!empty($tables)) {
@@ -136,7 +138,7 @@ public function updateDbItem(Request $request, Response $response): Response
136138
/**
137139
* 解析数据库结构为数组
138140
*/
139-
private function analyzeDbStructureToArray(string $tableInfo, string $tableDetail): array
141+
private function analyzeDbStructureToArray(string $tableInfo, string $tableDetail, string $tableIndex = ''): array
140142
{
141143
$tables = [];
142144

@@ -186,18 +188,81 @@ private function analyzeDbStructureToArray(string $tableInfo, string $tableDetai
186188
}
187189
}
188190

191+
// 解析 table_index
192+
if (!empty($tableIndex)) {
193+
$array = explode("\n", $tableIndex);
194+
if (!empty($array)) {
195+
foreach ($array as $key => $value) {
196+
if ($key == 0) {
197+
continue; // 跳过表头
198+
}
199+
$array2 = explode("\t", $value);
200+
if (empty($array2[0]) || empty($array2[1])) {
201+
continue;
202+
}
203+
$tableName = str_replace(PHP_EOL, '', $array2[0]);
204+
$indexName = str_replace(PHP_EOL, '', $array2[1]);
205+
$columnName = str_replace(PHP_EOL, '', $array2[2] ?? '');
206+
$seqInIndex = (int)($array2[3] ?? 0);
207+
$nonUnique = (int)($array2[4] ?? 1);
208+
$indexType = str_replace(PHP_EOL, '', $array2[5] ?? '');
209+
$indexComment = str_replace(PHP_EOL, '', $array2[6] ?? '');
210+
211+
if (!isset($tables[$tableName])) {
212+
$tables[$tableName] = [
213+
'table_name' => $tableName,
214+
'table_comment' => '',
215+
];
216+
}
217+
if (!isset($tables[$tableName]['indexes'])) {
218+
$tables[$tableName]['indexes'] = [];
219+
}
220+
if (!isset($tables[$tableName]['indexes'][$indexName])) {
221+
$tables[$tableName]['indexes'][$indexName] = [
222+
'index_name' => $indexName,
223+
'non_unique' => $nonUnique,
224+
'index_type' => $indexType,
225+
'index_comment' => $indexComment,
226+
'columns' => [],
227+
];
228+
}
229+
// 按序号添加列
230+
$tables[$tableName]['indexes'][$indexName]['columns'][$seqInIndex] = $columnName;
231+
}
232+
}
233+
}
234+
189235
// 生成 markdown 内容
190236
if (!empty($tables)) {
191237
foreach ($tables as $key => $value) {
192238
$markdown = '';
193239
$markdown .= "- {$value['table_comment']} \n \n";
240+
241+
// 字段表格
242+
$markdown .= "## 字段说明 \n \n";
194243
$markdown .= "|字段|类型|允许空|默认|注释| \n ";
195244
$markdown .= "|:---- |:------- |:--- |----|------ | \n ";
196245
if (!empty($value['columns'])) {
197246
foreach ($value['columns'] as $value2) {
198247
$markdown .= "|{$value2['column_name']} |{$value2['column_type']} |{$value2['is_nullable']} | {$value2['default']} | {$value2['column_comment']} | \n ";
199248
}
200249
}
250+
251+
// 索引表格
252+
if (!empty($value['indexes'])) {
253+
$markdown .= " \n \n## 索引说明 \n \n";
254+
$markdown .= "|索引名|类型|唯一|字段|注释| \n ";
255+
$markdown .= "|:---- |:------- |:--- |----|------ | \n ";
256+
foreach ($value['indexes'] as $index) {
257+
// 按序号排序列
258+
ksort($index['columns']);
259+
$columnsStr = implode(', ', $index['columns']);
260+
$uniqueStr = $index['non_unique'] == 0 ? '' : '';
261+
$indexComment = !empty($index['index_comment']) ? $index['index_comment'] : '';
262+
$markdown .= "|{$index['index_name']} |{$index['index_type']} |{$uniqueStr} | {$columnsStr} | {$indexComment} | \n ";
263+
}
264+
}
265+
201266
$tables[$key]['markdown'] = $markdown;
202267
}
203268
}

0 commit comments

Comments
 (0)