diff --git a/app/Service/core/CodeGenerationService.php b/app/Service/core/CodeGenerationService.php index ea83fb73..3bb0764e 100644 --- a/app/Service/core/CodeGenerationService.php +++ b/app/Service/core/CodeGenerationService.php @@ -110,7 +110,7 @@ class CodeGenerationService // 执行文件压缩 $zip->zip($zipFile, $path); - CodeGenerationModel::create([ + $insertModel = CodeGenerationModel::create([ 'title' => $this->classComment, 'file_name' => "{$this->classComment}-{$this->uniqid}.zip", 'path' => $zipFile, @@ -118,7 +118,7 @@ class CodeGenerationService 'created_at' => time(), 'updated_at' => time(), ]); - return $zipFile; + return $insertModel->id; } catch (\Exception $e) { return response()->json([ 'error' => '生成模板文件失败', @@ -158,6 +158,7 @@ class CodeGenerationService */ public function generate($params): mixed { + ds($params); $this->param = $params; DB::beginTransaction(); try { @@ -221,7 +222,7 @@ class CodeGenerationService 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'])) { @@ -232,10 +233,10 @@ class CodeGenerationService if (in_array($v['type'], self::TEXT_TYPE)) { // 编写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 { // 编写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']) { - $isNull = $item['null'] == 1 ? "'required'" : "''"; + $isNull = $item['not_null'] == 1 ? "'required'" : "''"; $this->insertField .= !empty($this->insertField) ? '","' . $item['name'] : $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";