AI代码生成工具
This commit is contained in:
168
app/Http/Controllers/Api/AiConfigController.php
Normal file
168
app/Http/Controllers/Api/AiConfigController.php
Normal file
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\BaseApp\BaseController;
|
||||
use App\Service\AiConfigService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
/**
|
||||
* AI 配置控制器:运行时选用 + 密钥管理
|
||||
*/
|
||||
class AiConfigController extends BaseController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->service = AiConfigService::getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁用基类通用列表(本模块用 keyList)
|
||||
* @Method NO
|
||||
*/
|
||||
public function list(): JsonResponse
|
||||
{
|
||||
return jerr('不支持');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Method NO
|
||||
*/
|
||||
public function option(): mixed
|
||||
{
|
||||
return jerr('不支持');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Method NO
|
||||
*/
|
||||
public function detail(): JsonResponse
|
||||
{
|
||||
return jerr('不支持');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Method NO
|
||||
*/
|
||||
public function create(): JsonResponse
|
||||
{
|
||||
return jerr('不支持');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Method NO
|
||||
*/
|
||||
public function update(): JsonResponse
|
||||
{
|
||||
return jerr('不支持');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Method NO
|
||||
*/
|
||||
public function delete(): JsonResponse
|
||||
{
|
||||
return jerr('不支持');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 AI 管理页选项(平台/模型/密钥卡片数据 + 当前激活项)
|
||||
* @Method GET
|
||||
*/
|
||||
public function runtimeOptions(): JsonResponse
|
||||
{
|
||||
return jok($this->service->getRuntimeOptions(), '获取成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存默认 AI 平台/模型/密钥组合
|
||||
* @Method POST
|
||||
*/
|
||||
public function saveRuntime(): JsonResponse
|
||||
{
|
||||
$params = request()->post();
|
||||
return jok($this->service->saveRuntime($params), '保存成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 密钥列表(卡片展示)
|
||||
* @Method GET
|
||||
*/
|
||||
public function keyList(): JsonResponse
|
||||
{
|
||||
return jok($this->service->listKeys(), '获取成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 平台下拉
|
||||
* @Method GET
|
||||
*/
|
||||
public function platformOption(): JsonResponse
|
||||
{
|
||||
return jok($this->service->platformOptions(), '获取成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增密钥
|
||||
* @Method POST
|
||||
*/
|
||||
public function createKey(): JsonResponse
|
||||
{
|
||||
$params = request()->post();
|
||||
return jok($this->service->createKey($params), '创建成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新密钥
|
||||
* @Method POST
|
||||
*/
|
||||
public function updateKey(): JsonResponse
|
||||
{
|
||||
$params = request()->post();
|
||||
$id = (int) ($params['id'] ?? 0);
|
||||
if ($id <= 0) {
|
||||
return jerr('参数错误');
|
||||
}
|
||||
unset($params['id']);
|
||||
return jok($this->service->updateKey($id, $params), '更新成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除密钥
|
||||
* @Method POST
|
||||
*/
|
||||
public function deleteKey(): JsonResponse
|
||||
{
|
||||
$ids = request()->post('ids');
|
||||
if (empty($ids)) {
|
||||
return jerr('参数错误');
|
||||
}
|
||||
if (!is_array($ids)) {
|
||||
$ids = [$ids];
|
||||
}
|
||||
return jok($this->service->deleteKeys($ids), '删除成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* AI 生成历史列表
|
||||
* @Method GET
|
||||
*/
|
||||
public function generationList(): JsonResponse
|
||||
{
|
||||
return jok($this->service->generationList(), '获取成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* AI 生成历史详情
|
||||
* @Method GET
|
||||
*/
|
||||
public function generationDetail(): JsonResponse
|
||||
{
|
||||
$id = (int) request()->get('id', 0);
|
||||
if ($id <= 0) {
|
||||
return jerr('参数错误');
|
||||
}
|
||||
return jok($this->service->generationDetail($id), '获取成功');
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,9 @@
|
||||
namespace App\Http\Controllers\core;
|
||||
|
||||
use App\BaseApp\BaseController;
|
||||
use App\Service\common\ai\AiCodeGenService;
|
||||
use App\Service\common\ai\AiRequirementPromptService;
|
||||
use App\Service\core\CodeGenerationService;
|
||||
use App\Service\LoginService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class CodeGenerationController extends BaseController
|
||||
@@ -156,8 +157,34 @@ class CodeGenerationController extends BaseController
|
||||
}
|
||||
|
||||
$codeGenData = $this->service->convertTableToCodeGenData($tableName, $className, $classComment, $icon, $sort, $pid);
|
||||
|
||||
|
||||
return jok($codeGenData);
|
||||
}
|
||||
|
||||
/**
|
||||
* AI 提示词生成代码结构(调用工厂 Agent,返回可灌入表单的 JSON)
|
||||
* @Method POST
|
||||
*/
|
||||
public function aiGenerate(): JsonResponse
|
||||
{
|
||||
$params = request()->post();
|
||||
return jok(
|
||||
AiCodeGenService::getInstance()->generate($params),
|
||||
'AI 生成成功'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据模块名生成 / 优化需求概览与代码生成提示词(写入生成历史,供前端替换导入)
|
||||
* @Method POST
|
||||
*/
|
||||
public function aiRequirementPrompt(): JsonResponse
|
||||
{
|
||||
$params = request()->post();
|
||||
return jok(
|
||||
AiRequirementPromptService::getInstance()->generate($params),
|
||||
'需求概览生成成功'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user