Просмотр исходного кода

♻️ (api-v13): 命令行任务不再用废弃的 ChannelApi,改用 ChannelService

app/Console/Commands 下 12 个命令:getSysChannel → systemUid、getById → summary、
getChannelByName → byNameOrFail(ChannelApi 本来就是转发到这几个方法,行为不变)。
只在 handle() 里用的注入到 handle();IndexTipitaka、UpgradeAITranslation、ExtractPaliTerm
注入到构造函数,与它们已有的写法一致。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
visuddhinanda 2 дней назад
Родитель
Сommit
9c9fd832df

+ 3 - 3
api-v13/app/Console/Commands/ExportAiTrainingData.php

@@ -2,10 +2,10 @@
 
 
 namespace App\Console\Commands;
 namespace App\Console\Commands;
 
 
-use App\Http\Api\ChannelApi;
 use App\Http\Api\MdRender;
 use App\Http\Api\MdRender;
 use App\Models\PaliSentence;
 use App\Models\PaliSentence;
 use App\Models\Sentence;
 use App\Models\Sentence;
+use App\Services\ChannelService;
 use App\Services\PaliTextService;
 use App\Services\PaliTextService;
 use Illuminate\Console\Command;
 use Illuminate\Console\Command;
 use Illuminate\Support\Facades\File;
 use Illuminate\Support\Facades\File;
@@ -45,7 +45,7 @@ class ExportAiTrainingData extends Command
      *
      *
      * @return int
      * @return int
      */
      */
-    public function handle()
+    public function handle(ChannelService $channelService)
     {
     {
         Log::info('task export offline sentence-table start');
         Log::info('task export offline sentence-table start');
         // 创建文件夹
         // 创建文件夹
@@ -95,7 +95,7 @@ class ExportAiTrainingData extends Command
                 break;
                 break;
             }
             }
             fwrite($fpIndex, "# {$channel}\n");
             fwrite($fpIndex, "# {$channel}\n");
-            $channelInfo = ChannelApi::getById($channel);
+            $channelInfo = $channelService->summary($channel);
             if ($channelInfo) {
             if ($channelInfo) {
                 fwrite($fpIndex, "- 版本名称:{$channelInfo['name']}\n");
                 fwrite($fpIndex, "- 版本名称:{$channelInfo['name']}\n");
                 fwrite($fpIndex, "- 语言:{$channelInfo['lang']}\n");
                 fwrite($fpIndex, "- 语言:{$channelInfo['lang']}\n");

+ 5 - 5
api-v13/app/Console/Commands/ExportChapter.php

@@ -2,11 +2,11 @@
 
 
 namespace App\Console\Commands;
 namespace App\Console\Commands;
 
 
-use App\Http\Api\ChannelApi;
 use App\Http\Api\MdRender;
 use App\Http\Api\MdRender;
 use App\Models\PaliText;
 use App\Models\PaliText;
 use App\Models\ProgressChapter;
 use App\Models\ProgressChapter;
 use App\Models\Sentence;
 use App\Models\Sentence;
+use App\Services\ChannelService;
 use App\Tools\Export;
 use App\Tools\Export;
 use App\Tools\ExportDownload;
 use App\Tools\ExportDownload;
 use App\Tools\Tools;
 use App\Tools\Tools;
@@ -47,7 +47,7 @@ class ExportChapter extends Command
      *
      *
      * @return int
      * @return int
      */
      */
-    public function handle()
+    public function handle(ChannelService $channelService)
     {
     {
         $this->info('task export chapter start');
         $this->info('task export chapter start');
         Log::debug('task export chapter start');
         Log::debug('task export chapter start');
@@ -79,7 +79,7 @@ class ExportChapter extends Command
         $renderFormat = 'markdown';
         $renderFormat = 'markdown';
 
 
         // 获取原文channel
         // 获取原文channel
-        $orgChannelId = ChannelApi::getSysChannel('_System_Pali_VRI_');
+        $orgChannelId = $channelService->systemUid('_System_Pali_VRI_');
 
 
         $tranChannelsId = explode('_', $this->argument('channel'));
         $tranChannelsId = explode('_', $this->argument('channel'));
 
 
@@ -88,8 +88,8 @@ class ExportChapter extends Command
         $channels = [];
         $channels = [];
         $channelsIndex = [];
         $channelsIndex = [];
         foreach ($channelsId as $key => $id) {
         foreach ($channelsId as $key => $id) {
-            $channels[] = ChannelApi::getById($id);
-            $channelsIndex[$id] = ChannelApi::getById($id);
+            $channels[] = $channelService->summary($id);
+            $channelsIndex[$id] = $channelService->summary($id);
         }
         }
 
 
         $bookMeta = [];
         $bookMeta = [];

+ 3 - 3
api-v13/app/Console/Commands/ExportDiscussion.php

@@ -2,7 +2,7 @@
 
 
 namespace App\Console\Commands;
 namespace App\Console\Commands;
 
 
-use App\Http\Api\ChannelApi;
+use App\Services\ChannelService;
 use Carbon\Carbon;
 use Carbon\Carbon;
 use Illuminate\Console\Command;
 use Illuminate\Console\Command;
 use Illuminate\Support\Collection;
 use Illuminate\Support\Collection;
@@ -33,14 +33,14 @@ class ExportDiscussion extends Command
     /**
     /**
      * Execute the console command.
      * Execute the console command.
      */
      */
-    public function handle(): int
+    public function handle(ChannelService $channelService): int
     {
     {
         $editorUid = $this->argument('editor');
         $editorUid = $this->argument('editor');
 
 
         $this->info("Fetching discussions for editor: {$editorUid}");
         $this->info("Fetching discussions for editor: {$editorUid}");
 
 
         // 1. 获取巴利原文 channel_uid
         // 1. 获取巴利原文 channel_uid
-        $this->orgChannelId = ChannelApi::getSysChannel('_System_Pali_VRI_');
+        $this->orgChannelId = $channelService->systemUid('_System_Pali_VRI_');
         if (! $this->orgChannelId) {
         if (! $this->orgChannelId) {
             $this->error('Failed to retrieve Pali source channel ID.');
             $this->error('Failed to retrieve Pali source channel ID.');
 
 

+ 4 - 4
api-v13/app/Console/Commands/ExportSentence.php

@@ -2,10 +2,10 @@
 
 
 namespace App\Console\Commands;
 namespace App\Console\Commands;
 
 
-use App\Http\Api\ChannelApi;
 use App\Http\Api\MdRender;
 use App\Http\Api\MdRender;
 use App\Models\Channel;
 use App\Models\Channel;
 use App\Models\Sentence;
 use App\Models\Sentence;
+use App\Services\ChannelService;
 use App\Tools\Markdown;
 use App\Tools\Markdown;
 use App\Tools\Tools;
 use App\Tools\Tools;
 use Illuminate\Console\Command;
 use Illuminate\Console\Command;
@@ -43,7 +43,7 @@ class ExportSentence extends Command
      *
      *
      * @return int
      * @return int
      */
      */
-    public function handle()
+    public function handle(ChannelService $channelService)
     {
     {
         Log::debug('task export offline sentence-table start');
         Log::debug('task export offline sentence-table start');
         if (Tools::isStop()) {
         if (Tools::isStop()) {
@@ -59,7 +59,7 @@ class ExportSentence extends Command
             $channel_type = $this->option('type');
             $channel_type = $this->option('type');
             $file_suf = $channel_type;
             $file_suf = $channel_type;
             if ($channel_type === 'original') {
             if ($channel_type === 'original') {
-                $pali_channel = ChannelApi::getSysChannel('_System_Pali_VRI_');
+                $pali_channel = $channelService->systemUid('_System_Pali_VRI_');
                 if ($pali_channel === false) {
                 if ($pali_channel === false) {
                     return 0;
                     return 0;
                 }
                 }
@@ -112,7 +112,7 @@ class ExportSentence extends Command
         ])->cursor();
         ])->cursor();
         foreach ($srcDb as $sent) {
         foreach ($srcDb as $sent) {
             if (Str::isUuid($sent->channel_uid)) {
             if (Str::isUuid($sent->channel_uid)) {
-                $channel = ChannelApi::getById($sent->channel_uid);
+                $channel = $channelService->summary($sent->channel_uid);
                 $currData = [
                 $currData = [
                     $sent->book_id,
                     $sent->book_id,
                     $sent->paragraph,
                     $sent->paragraph,

+ 4 - 3
api-v13/app/Console/Commands/ExtractPaliTerm.php

@@ -4,10 +4,10 @@ namespace App\Console\Commands;
 
 
 use App\Facades\RedisCache;
 use App\Facades\RedisCache;
 use App\Helpers\LlmResponseParser;
 use App\Helpers\LlmResponseParser;
-use App\Http\Api\ChannelApi;
 use App\Http\Resources\AiModelResource;
 use App\Http\Resources\AiModelResource;
 use App\Models\PaliText;
 use App\Models\PaliText;
 use App\Services\AIModelService;
 use App\Services\AIModelService;
+use App\Services\ChannelService;
 use App\Services\OpenAIService;
 use App\Services\OpenAIService;
 use App\Services\SentenceService;
 use App\Services\SentenceService;
 use App\Services\TermService;
 use App\Services\TermService;
@@ -69,6 +69,7 @@ class ExtractPaliTerm extends Command
     protected ?bool $thinking = null;
     protected ?bool $thinking = null;
 
 
     public function __construct(
     public function __construct(
+        protected ChannelService $channelService,
         protected AIModelService $modelService,
         protected AIModelService $modelService,
         protected OpenAIService $openAIService,
         protected OpenAIService $openAIService,
         protected SentenceService $sentenceService,
         protected SentenceService $sentenceService,
@@ -97,13 +98,13 @@ class ExtractPaliTerm extends Command
         }
         }
 
 
         // ---------- 保存目标 channel ----------
         // ---------- 保存目标 channel ----------
-        $channelId = ChannelApi::getSysChannel('_system_glossary_');
+        $channelId = $this->channelService->systemUid('_system_glossary_');
         if (! $channelId) {
         if (! $channelId) {
             $this->error('system glossary channel "_system_glossary_" not found');
             $this->error('system glossary channel "_system_glossary_" not found');
 
 
             return 1;
             return 1;
         }
         }
-        $this->glossaryChannel = ChannelApi::getById($channelId);
+        $this->glossaryChannel = $this->channelService->summary($channelId);
         Log::info('extract:pali.term glossary channel', ['channel' => $channelId]);
         Log::info('extract:pali.term glossary channel', ['channel' => $channelId]);
 
 
         // ---------- 完整术语表(一次性加载,所有 chapter 共用)----------
         // ---------- 完整术语表(一次性加载,所有 chapter 共用)----------

+ 4 - 3
api-v13/app/Console/Commands/IndexTipitaka.php

@@ -3,10 +3,10 @@
 namespace App\Console\Commands;
 namespace App\Console\Commands;
 
 
 use App\Facades\RedisCache;
 use App\Facades\RedisCache;
-use App\Http\Api\ChannelApi;
 use App\Models\PaliText;
 use App\Models\PaliText;
 use App\Models\ProgressChapter;
 use App\Models\ProgressChapter;
 use App\Models\Sentence;
 use App\Models\Sentence;
+use App\Services\ChannelService;
 use App\Services\OpenSearchService;
 use App\Services\OpenSearchService;
 use App\Services\PaliContentService;
 use App\Services\PaliContentService;
 use App\Services\SearchPaliDataService;
 use App\Services\SearchPaliDataService;
@@ -49,6 +49,7 @@ class IndexTipitaka extends Command
      * @return void
      * @return void
      */
      */
     public function __construct(
     public function __construct(
+        protected ChannelService $channelService,
         protected SearchPaliDataService $searchPaliDataService,
         protected SearchPaliDataService $searchPaliDataService,
         protected OpenSearchService $openSearchService,
         protected OpenSearchService $openSearchService,
         protected SummaryService $summaryService,
         protected SummaryService $summaryService,
@@ -307,7 +308,7 @@ class IndexTipitaka extends Command
             foreach ($channels as $channel) {
             foreach ($channels as $channel) {
                 $display = [];
                 $display = [];
                 $content = [];
                 $content = [];
-                $channelInfo = ChannelApi::getById($channel->channel_uid);
+                $channelInfo = $this->channelService->summary($channel->channel_uid);
                 if (! $channelInfo) {
                 if (! $channelInfo) {
                     Log::error('invalid channel', ['id' => $channel->channel_uid]);
                     Log::error('invalid channel', ['id' => $channel->channel_uid]);
 
 
@@ -364,7 +365,7 @@ class IndexTipitaka extends Command
             ->where('para', $param['para'])
             ->where('para', $param['para'])
             ->where('channel_id', $param['channel'])
             ->where('channel_id', $param['channel'])
             ->first();
             ->first();
-        $channel = ChannelApi::getById($param['channel']);
+        $channel = $this->channelService->summary($param['channel']);
         $docId = "tipitaka_chapter_{$param['book']}-{$param['para']}_{$param['channel']}";
         $docId = "tipitaka_chapter_{$param['book']}-{$param['para']}_{$param['channel']}";
         $document = [
         $document = [
             'id' => $docId,
             'id' => $docId,

+ 3 - 3
api-v13/app/Console/Commands/InitCs6sentence.php

@@ -2,10 +2,10 @@
 
 
 namespace App\Console\Commands;
 namespace App\Console\Commands;
 
 
-use App\Http\Api\ChannelApi;
 use App\Models\PaliSentence;
 use App\Models\PaliSentence;
 use App\Models\Sentence;
 use App\Models\Sentence;
 use App\Models\WbwTemplate;
 use App\Models\WbwTemplate;
+use App\Services\ChannelService;
 use App\Tools\Tools;
 use App\Tools\Tools;
 use Illuminate\Console\Command;
 use Illuminate\Console\Command;
 use Illuminate\Support\Str;
 use Illuminate\Support\Str;
@@ -41,13 +41,13 @@ class InitCs6sentence extends Command
      *
      *
      * @return int
      * @return int
      */
      */
-    public function handle()
+    public function handle(ChannelService $channelService)
     {
     {
         if (Tools::isStop()) {
         if (Tools::isStop()) {
             return 0;
             return 0;
         }
         }
         $start = time();
         $start = time();
-        $channelId = ChannelApi::getSysChannel('_System_Pali_VRI_');
+        $channelId = $channelService->systemUid('_System_Pali_VRI_');
         if ($channelId === false) {
         if ($channelId === false) {
             $this->error('no channel');
             $this->error('no channel');
 
 

+ 4 - 3
api-v13/app/Console/Commands/UpgradeAITranslation.php

@@ -4,7 +4,6 @@ namespace App\Console\Commands;
 
 
 use App\Facades\RedisCache;
 use App\Facades\RedisCache;
 use App\Helpers\LlmResponseParser;
 use App\Helpers\LlmResponseParser;
-use App\Http\Api\ChannelApi;
 use App\Http\Resources\AiModelResource;
 use App\Http\Resources\AiModelResource;
 use App\Models\PaliText;
 use App\Models\PaliText;
 use App\Models\Sentence;
 use App\Models\Sentence;
@@ -12,6 +11,7 @@ use App\Services\AIAssistant\NissayaTranslateService;
 use App\Services\AIAssistant\PaliTranslateService;
 use App\Services\AIAssistant\PaliTranslateService;
 use App\Services\AIModelService;
 use App\Services\AIModelService;
 use App\Services\AuthService;
 use App\Services\AuthService;
+use App\Services\ChannelService;
 use App\Services\OpenAIService;
 use App\Services\OpenAIService;
 use App\Services\SentenceService;
 use App\Services\SentenceService;
 use Illuminate\Console\Command;
 use Illuminate\Console\Command;
@@ -74,6 +74,7 @@ class UpgradeAITranslation extends Command
      * @return void
      * @return void
      */
      */
     public function __construct(
     public function __construct(
+        protected ChannelService $channelService,
         protected AIModelService $modelService,
         protected AIModelService $modelService,
         protected SentenceService $sentenceService,
         protected SentenceService $sentenceService,
         protected OpenAIService $openAIService,
         protected OpenAIService $openAIService,
@@ -108,7 +109,7 @@ class UpgradeAITranslation extends Command
         $this->modelToken = AuthService::getUserToken($this->model['uid']);
         $this->modelToken = AuthService::getUserToken($this->model['uid']);
 
 
         // channel
         // channel
-        $this->workChannel = ChannelApi::getById($this->argument('channel'));
+        $this->workChannel = $this->channelService->summary($this->argument('channel'));
         // 需要判断输入channel 与翻译类型是否一致 nissaya -> nissaya channel
         // 需要判断输入channel 与翻译类型是否一致 nissaya -> nissaya channel
         if ($this->workChannel['type'] !== $this->argument('type')) {
         if ($this->workChannel['type'] !== $this->argument('type')) {
             $this->error('channel type not match request '.$this->argument('type').' input is '.$this->workChannel['type']);
             $this->error('channel type not match request '.$this->argument('type').' input is '.$this->workChannel['type']);
@@ -265,7 +266,7 @@ class UpgradeAITranslation extends Command
 
 
         直接输出jsonl, 无需其他内容
         直接输出jsonl, 无需其他内容
         md;
         md;
-        $channelId = ChannelApi::getSysChannel('_System_Wbw_VRI_');
+        $channelId = $this->channelService->systemUid('_System_Wbw_VRI_');
         $sentences = Sentence::where('channel_uid', $channelId)
         $sentences = Sentence::where('channel_uid', $channelId)
             ->where('book_id', $book)
             ->where('book_id', $book)
             ->where('paragraph', $para)
             ->where('paragraph', $para)

+ 4 - 4
api-v13/app/Console/Commands/UpgradeGrammarBook.php

@@ -2,9 +2,9 @@
 
 
 namespace App\Console\Commands;
 namespace App\Console\Commands;
 
 
-use App\Http\Api\ChannelApi;
 use App\Models\DhammaTerm;
 use App\Models\DhammaTerm;
 use App\Models\Relation;
 use App\Models\Relation;
+use App\Services\ChannelService;
 use Illuminate\Console\Command;
 use Illuminate\Console\Command;
 use Illuminate\Support\Str;
 use Illuminate\Support\Str;
 
 
@@ -40,10 +40,10 @@ class UpgradeGrammarBook extends Command
      *
      *
      * @return int
      * @return int
      */
      */
-    public function handle()
+    public function handle(ChannelService $channelService)
     {
     {
         $lang = 'zh-Hans';
         $lang = 'zh-Hans';
-        $channelId = ChannelApi::getSysChannel('_System_Grammar_Term_'.strtolower($lang).'_');
+        $channelId = $channelService->systemUid('_System_Grammar_Term_'.strtolower($lang).'_');
         if ($channelId === false) {
         if ($channelId === false) {
             $this->error('no channel');
             $this->error('no channel');
 
 
@@ -120,7 +120,7 @@ class UpgradeGrammarBook extends Command
             if (empty($caseLocal)) {
             if (empty($caseLocal)) {
                 $caseLocal = $key;
                 $caseLocal = $key;
             }
             }
-            $owner = ChannelApi::getById($channelId);
+            $owner = $channelService->summary($channelId);
             if (! $owner) {
             if (! $owner) {
                 $this->error('channel id error '.$channelId);
                 $this->error('channel id error '.$channelId);
 
 

+ 3 - 3
api-v13/app/Console/Commands/UpgradeQuote.php

@@ -2,10 +2,10 @@
 
 
 namespace App\Console\Commands;
 namespace App\Console\Commands;
 
 
-use App\Http\Api\ChannelApi;
 use App\Models\PaliSentence;
 use App\Models\PaliSentence;
 use App\Models\Sentence;
 use App\Models\Sentence;
 use App\Models\WbwTemplate;
 use App\Models\WbwTemplate;
+use App\Services\ChannelService;
 use App\Tools\Tools;
 use App\Tools\Tools;
 use Illuminate\Console\Command;
 use Illuminate\Console\Command;
 use Illuminate\Support\Str;
 use Illuminate\Support\Str;
@@ -41,13 +41,13 @@ class UpgradeQuote extends Command
      *
      *
      * @return int
      * @return int
      */
      */
-    public function handle()
+    public function handle(ChannelService $channelService)
     {
     {
         if (Tools::isStop()) {
         if (Tools::isStop()) {
             return 0;
             return 0;
         }
         }
         $start = time();
         $start = time();
-        $channelId = ChannelApi::getSysChannel('_System_Quote_');
+        $channelId = $channelService->systemUid('_System_Quote_');
         if ($channelId === false) {
         if ($channelId === false) {
             $this->error('no channel');
             $this->error('no channel');
 
 

+ 3 - 3
api-v13/app/Console/Commands/UpgradeSystemCommentary.php

@@ -4,7 +4,6 @@ namespace App\Console\Commands;
 
 
 use App\Facades\RedisCache;
 use App\Facades\RedisCache;
 use App\Helpers\LlmResponseParser;
 use App\Helpers\LlmResponseParser;
-use App\Http\Api\ChannelApi;
 use App\Http\Resources\AiModelResource;
 use App\Http\Resources\AiModelResource;
 use App\Models\BookTitle;
 use App\Models\BookTitle;
 use App\Models\PaliSentence;
 use App\Models\PaliSentence;
@@ -13,6 +12,7 @@ use App\Models\RelatedParagraph;
 use App\Models\Tag;
 use App\Models\Tag;
 use App\Models\TagMap;
 use App\Models\TagMap;
 use App\Services\AIModelService;
 use App\Services\AIModelService;
+use App\Services\ChannelService;
 use App\Services\OpenAIService;
 use App\Services\OpenAIService;
 use App\Services\SearchPaliDataService;
 use App\Services\SearchPaliDataService;
 use App\Services\SentenceService;
 use App\Services\SentenceService;
@@ -99,7 +99,7 @@ class UpgradeSystemCommentary extends Command
      *
      *
      * @return int
      * @return int
      */
      */
-    public function handle()
+    public function handle(ChannelService $channelService)
     {
     {
         if ($this->option('list')) {
         if ($this->option('list')) {
             $result = RelatedParagraph::whereNotNull('book_name')
             $result = RelatedParagraph::whereNotNull('book_name')
@@ -145,7 +145,7 @@ class UpgradeSystemCommentary extends Command
             $skipPatterns = array_values(array_filter(array_map('trim', explode(',', $this->option('skip')))));
             $skipPatterns = array_values(array_filter(array_map('trim', explode(',', $this->option('skip')))));
         }
         }
 
 
-        $channel = ChannelApi::getChannelByName('_System_commentary_');
+        $channel = $channelService->byNameOrFail('_System_commentary_');
 
 
         $books = [];
         $books = [];
         if ($this->option('book')) {
         if ($this->option('book')) {

+ 3 - 3
api-v13/app/Console/Commands/UpgradeWbwTemplate.php

@@ -2,10 +2,10 @@
 
 
 namespace App\Console\Commands;
 namespace App\Console\Commands;
 
 
-use App\Http\Api\ChannelApi;
 use App\Models\PaliSentence;
 use App\Models\PaliSentence;
 use App\Models\Sentence;
 use App\Models\Sentence;
 use App\Models\WbwTemplate;
 use App\Models\WbwTemplate;
+use App\Services\ChannelService;
 use App\Tools\Tools;
 use App\Tools\Tools;
 use Illuminate\Console\Command;
 use Illuminate\Console\Command;
 use Illuminate\Support\Str;
 use Illuminate\Support\Str;
@@ -42,7 +42,7 @@ class UpgradeWbwTemplate extends Command
      *
      *
      * @return int
      * @return int
      */
      */
-    public function handle()
+    public function handle(ChannelService $channelService)
     {
     {
         if (Tools::isStop()) {
         if (Tools::isStop()) {
             return 0;
             return 0;
@@ -56,7 +56,7 @@ class UpgradeWbwTemplate extends Command
             $pali = $pali->where('paragraph', $this->argument('para'));
             $pali = $pali->where('paragraph', $this->argument('para'));
         }
         }
         $bar = $this->output->createProgressBar($pali->count());
         $bar = $this->output->createProgressBar($pali->count());
-        $channelId = ChannelApi::getSysChannel('_System_Wbw_VRI_');
+        $channelId = $channelService->systemUid('_System_Wbw_VRI_');
         if ($channelId === false) {
         if ($channelId === false) {
             $this->error('no channel');
             $this->error('no channel');