mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-06 10:02:49 +08:00
feat: 发布智能体版
This commit is contained in:
@@ -3,8 +3,8 @@
|
||||
namespace base\common\command;
|
||||
|
||||
use app\admin\service\curd\BuildCurdService;
|
||||
use app\common\console\Command;
|
||||
use app\common\tools\PathTools;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\input\Option;
|
||||
use think\console\Output;
|
||||
@@ -15,6 +15,8 @@ class CurdBase extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this->setName('curd')
|
||||
->addOption('table', 't', Option::VALUE_REQUIRED, '主表名', null)
|
||||
->addOption('controllerFilename', 'c', Option::VALUE_REQUIRED, '控制器文件名', null)
|
||||
@@ -22,12 +24,55 @@ class CurdBase extends Command
|
||||
//
|
||||
->addOption('force', 'f', Option::VALUE_NONE, '强制覆盖模式')
|
||||
->addOption('delete', 'd', Option::VALUE_NONE, '删除模式')
|
||||
->addOption('runtime', 'r', Option::VALUE_NONE, '临时生成')
|
||||
->setDescription('一键curd命令服务');
|
||||
->addOption('runtime', 'r', Option::VALUE_NONE, '临时生成(生成到 runtime 目录)')
|
||||
->addOption('examples', null, Option::VALUE_NONE, '显示使用示例')
|
||||
->setDescription('一键生成 CURD 代码(控制器、模型、视图、JS)');
|
||||
}
|
||||
|
||||
protected function getExamplesText(): string
|
||||
{
|
||||
return <<<'EXAMPLES'
|
||||
<info>CURD 命令使用示例</info>
|
||||
|
||||
<comment>示例 1:首次生成(基本用法)</comment>
|
||||
<info>php think curd -t daka_record</info>
|
||||
说明:直接生成到项目目录,如文件已存在会跳过
|
||||
|
||||
<comment>示例 2:增量更新(已有业务代码)</comment>
|
||||
<info>php think curd -t daka_record -r</info>
|
||||
说明:生成到 runtime 临时目录,用于手动对比并合并新增字段代码(避免覆盖业务逻辑)
|
||||
|
||||
<comment>示例 3:带前缀的表名</comment>
|
||||
<info>php think curd -t ul_daka_record</info>
|
||||
说明:自动识别并去除前缀
|
||||
|
||||
<comment>示例 4:强制覆盖(谨慎使用)</comment>
|
||||
<info>php think curd -t daka_record -f</info>
|
||||
说明:覆盖已存在的文件,<error>会丢失手动修改的内容</error>
|
||||
|
||||
<comment>示例 5:删除已生成的文件</comment>
|
||||
<info>php think curd -t daka_record -d</info>
|
||||
说明:删除之前生成的所有文件(会要求确认)
|
||||
注意:<error>这是删除文件,不是删除数据库记录</error>
|
||||
|
||||
<comment>常见错误及解决:</comment>
|
||||
错误:表不存在
|
||||
→ 先创建表:php think scheme:sync
|
||||
→ 或使用迁移:php think migrate:run
|
||||
|
||||
错误:Scheme 与数据库不一致
|
||||
→ 同步 Scheme:php think scheme:sync
|
||||
EXAMPLES;
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
// 显示使用示例
|
||||
if ($input->hasOption('examples')) {
|
||||
$output->writeln($this->getExamplesText());
|
||||
return true;
|
||||
}
|
||||
|
||||
$table = $input->getOption('table');
|
||||
$controllerFilename = $input->getOption('controllerFilename');
|
||||
$modelFilename = $input->getOption('modelFilename');
|
||||
@@ -49,11 +94,15 @@ class CurdBase extends Command
|
||||
return false;
|
||||
}
|
||||
|
||||
// 收集警告信息
|
||||
$warnings = [];
|
||||
|
||||
try {
|
||||
$build = (new BuildCurdService())
|
||||
->setTable($table)
|
||||
->setForce($force);
|
||||
|
||||
$runtime_path = '';
|
||||
if ($input->hasOption('runtime')) {
|
||||
$runtime_path = App::getRuntimePath() . 'source' . DS . 'build' . DS . date('YmdHis') . DS;
|
||||
PathTools::intiDir($runtime_path . 'a.temp');
|
||||
@@ -70,8 +119,9 @@ class CurdBase extends Command
|
||||
$define = $column['define'];
|
||||
|
||||
if (!isset($define['table'])) {
|
||||
$output->error("关联字段{$field}没有设置关联表名称");
|
||||
|
||||
$error = "关联字段{$field}没有设置关联表名称";
|
||||
$output->error($error);
|
||||
$warnings[] = ['message' => $error];
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -96,6 +146,7 @@ class CurdBase extends Command
|
||||
$build = $build->render();
|
||||
$fileList = $build->getFileList();
|
||||
|
||||
$result = [];
|
||||
if (!$delete) {
|
||||
if ($force) {
|
||||
$output->writeln('>>>>>>>>>>>>>>>');
|
||||
@@ -104,10 +155,9 @@ class CurdBase extends Command
|
||||
}
|
||||
$output->writeln('>>>>>>>>>>>>>>>');
|
||||
|
||||
$ask_force_delete_result = $output->confirm($input, '确定强制生成上方所有文件? 如果文件存在会直接覆盖。');
|
||||
|
||||
if (!$ask_force_delete_result) {
|
||||
throw new Exception('取消文件CURD生成操作');
|
||||
if (!$output->confirm($input, '确定强制生成上方所有文件? 如果文件存在会直接覆盖。', true)) {
|
||||
$output->comment('已取消。');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$result = $build->create();
|
||||
@@ -119,10 +169,9 @@ class CurdBase extends Command
|
||||
}
|
||||
$output->writeln('>>>>>>>>>>>>>>>');
|
||||
|
||||
$ask_force_delete_result = $output->confirm($input, '确定删除上方所有文件? ');
|
||||
|
||||
if (!$ask_force_delete_result) {
|
||||
throw new Exception('取消删除文件操作');
|
||||
if (!$output->confirm($input, '确定删除上方所有文件? ', true)) {
|
||||
$output->comment('已取消。');
|
||||
return false;
|
||||
}
|
||||
$result = $build->delete();
|
||||
$output->info('>>>>>>>>>>>>>>>');
|
||||
|
||||
Reference in New Issue
Block a user