代码下载接口

This commit is contained in:
2025-05-13 15:58:15 +08:00
parent a764794a5f
commit ace14b1728

View File

@@ -110,7 +110,7 @@ class CodeGenerationService
// 执行文件压缩 // 执行文件压缩
$zip->zip($zipFile, $path); $zip->zip($zipFile, $path);
CodeGenerationModel::create([ $insertModel = CodeGenerationModel::create([
'title' => $this->classComment, 'title' => $this->classComment,
'file_name' => "{$this->classComment}-{$this->uniqid}.zip", 'file_name' => "{$this->classComment}-{$this->uniqid}.zip",
'path' => $zipFile, 'path' => $zipFile,
@@ -118,7 +118,7 @@ class CodeGenerationService
'created_at' => time(), 'created_at' => time(),
'updated_at' => time(), 'updated_at' => time(),
]); ]);
return $zipFile; return $insertModel->id;
} catch (\Exception $e) { } catch (\Exception $e) {
return response()->json([ return response()->json([
'error' => '生成模板文件失败', 'error' => '生成模板文件失败',
@@ -158,6 +158,7 @@ class CodeGenerationService
*/ */
public function generate($params): mixed public function generate($params): mixed
{ {
ds($params);
$this->param = $params; $this->param = $params;
DB::beginTransaction(); DB::beginTransaction();
try { try {
@@ -221,7 +222,7 @@ class CodeGenerationService
if (empty($v['comment'])) $v['comment'] = "''"; if (empty($v['comment'])) $v['comment'] = "''";
// 处理是否为空 // 处理是否为空
$v['null'] = !$v['null'] ? '' : 'NOT'; $v['not_null'] = !$v['not_null'] ? '' : 'NOT';
// 处理默认值 // 处理默认值
if (array_key_exists('default', $v) && isset($v['default'])) { if (array_key_exists('default', $v) && isset($v['default'])) {
@@ -232,10 +233,10 @@ class CodeGenerationService
if (in_array($v['type'], self::TEXT_TYPE)) { if (in_array($v['type'], self::TEXT_TYPE)) {
// 编写sql语句 // 编写sql语句
$sql .= " {$v['name']} {$v['type']} {$v['null']} NULL COMMENT '{$v['comment']}', "; $sql .= " {$v['name']} {$v['type']} {$v['not_null']} NULL COMMENT '{$v['comment']}', ";
} else { } else {
// 编写sql语句 // 编写sql语句
$sql .= " {$v['name']} {$v['type']}({$v['type_number']}) {$v['default']} {$v['null']} NULL COMMENT '{$v['comment']}', "; $sql .= " {$v['name']} {$v['type']}({$v['type_number']}) {$v['default']} {$v['not_null']} NULL COMMENT '{$v['comment']}', ";
} }
} }
@@ -420,7 +421,7 @@ class CodeGenerationService
} }
// 设置表单字段 // 设置表单字段
if ($item['formShow']) { if ($item['formShow']) {
$isNull = $item['null'] == 1 ? "'required'" : "''"; $isNull = $item['not_null'] == 1 ? "'required'" : "''";
$this->insertField .= !empty($this->insertField) ? '","' . $item['name'] : $item['name']; $this->insertField .= !empty($this->insertField) ? '","' . $item['name'] : $item['name'];
$this->updateField .= !empty($this->updateField) ? '","' . $item['name'] : 'id","' . $item['name']; $this->updateField .= !empty($this->updateField) ? '","' . $item['name'] : 'id","' . $item['name'];
$this->viewForm .= "{\n fieldName: '" . $item['name'] . "',\n label: '" . $item['comment'] . "',\n component: '" . $item['formType'] . "',\n rules: " . $isNull . ",\n },\n"; $this->viewForm .= "{\n fieldName: '" . $item['name'] . "',\n label: '" . $item['comment'] . "',\n component: '" . $item['formType'] . "',\n rules: " . $isNull . ",\n },\n";