visuddhinanda 11 ヶ月 前
コミット
976bc90641

+ 93 - 0
api-v8/app/Console/Commands/InitCommentary.php

@@ -0,0 +1,93 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+use App\Models\Tag;
+use App\Models\TagMap;
+use App\Models\PaliText;
+use App\Models\PaliSentence;
+use App\Models\Commentary;
+use App\Models\RelatedParagraph;
+
+class InitCommentary extends Command
+{
+    /**
+     * The name and signature of the console command.
+     * php artisan init:commentary
+     * @var string
+     */
+    protected $signature = 'init:commentary {--book=}';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'init commentary sentences';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return int
+     */
+    public function handle()
+    {
+        //查询注释书标签
+        $tags = Tag::whereIn('name', ['aṭṭhakathā', 'ṭīkā'])->select('id')->get();
+        //查询段落编号
+        $paliId = TagMap::whereIn('tag_id', $tags)
+            ->where('table_name', 'pali_texts')
+            ->cursor();
+        foreach ($paliId as $key => $paraId) {
+            $book = PaliText::where('uid', $paraId->anchor_id)
+                ->where('level', 1)->first();
+            if (!$book) {
+                continue;
+            }
+            $paragraphs = PaliText::where('book', $book->book)
+                ->whereBetween('paragraph', [$book->paragraph, $book->paragraph + $book->chapter_len - 1])
+                ->get();
+            foreach ($paragraphs as $key => $para) {
+                $this->info($para->book . '-' . $para->paragraph);
+                $sentences = PaliSentence::where('book', $para->book)
+                    ->where('paragraph', $para->paragraph)
+                    ->get();
+                $del = Commentary::where('book1', $para->book)
+                    ->where('paragraph1', $para->paragraph)
+                    ->where('owner_id', config("mint.admin.root_uuid"))
+                    ->delete();
+                $csPara = RelatedParagraph::where('book', $para->book)
+                    ->where('para', $para->paragraph)
+                    ->first();
+                if ($csPara) {
+                    foreach ($sentences as $key => $sentence) {
+                        $new = new Commentary();
+                        $new->book1 = $sentence->book;
+                        $new->paragraph1 = $sentence->paragraph;
+                        $new->start1 = $sentence->word_begin;
+                        $new->end1 = $sentence->word_end;
+                        $new->editor_id = config("mint.admin.root_uuid");
+                        $new->owner_id = config("mint.admin.root_uuid");
+                        $new->p_number = $csPara->book_name . '-' . $csPara->para;
+                        $new->save();
+                    }
+                } else {
+                    $this->error('no relation paragraph');
+                }
+            }
+        }
+        $this->info('all done');
+        return 0;
+    }
+}

+ 85 - 0
api-v8/app/Http/Controllers/CommentaryController.php

@@ -0,0 +1,85 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\Models\Commentary;
+use Illuminate\Http\Request;
+
+class CommentaryController extends Controller
+{
+    /**
+     * Display a listing of the resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function index()
+    {
+        //
+    }
+
+    /**
+     * Show the form for creating a new resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function create()
+    {
+        //
+    }
+
+    /**
+     * Store a newly created resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return \Illuminate\Http\Response
+     */
+    public function store(Request $request)
+    {
+        //
+    }
+
+    /**
+     * Display the specified resource.
+     *
+     * @param  \App\Models\Commentary  $commentary
+     * @return \Illuminate\Http\Response
+     */
+    public function show(Commentary $commentary)
+    {
+        //
+    }
+
+    /**
+     * Show the form for editing the specified resource.
+     *
+     * @param  \App\Models\Commentary  $commentary
+     * @return \Illuminate\Http\Response
+     */
+    public function edit(Commentary $commentary)
+    {
+        //
+    }
+
+    /**
+     * Update the specified resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \App\Models\Commentary  $commentary
+     * @return \Illuminate\Http\Response
+     */
+    public function update(Request $request, Commentary $commentary)
+    {
+        //
+    }
+
+    /**
+     * Remove the specified resource from storage.
+     *
+     * @param  \App\Models\Commentary  $commentary
+     * @return \Illuminate\Http\Response
+     */
+    public function destroy(Commentary $commentary)
+    {
+        //
+    }
+}

+ 11 - 0
api-v8/app/Models/Commentary.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+class Commentary extends Model
+{
+    use HasFactory;
+}

+ 42 - 0
api-v8/database/migrations/2025_03_20_141911_create_commentaries_table.php

@@ -0,0 +1,42 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateCommentariesTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('commentaries', function (Blueprint $table) {
+            $table->id();
+            $table->integer('book1')->index()->comment('注释书号');
+            $table->integer('paragraph1')->index()->comment('注释书段落');
+            $table->integer('start1')->index()->comment('注释书句子单词起始');
+            $table->integer('end1')->index()->comment('注释书句子单词结束');
+            $table->integer('book2')->nullable()->index();
+            $table->integer('paragraph2')->nullable()->index();
+            $table->integer('start2')->nullable()->index();
+            $table->integer('end2')->nullable()->index();
+            $table->string('p_number')->index()->comment('段落号');
+            $table->uuid('owner_id')->index();
+            $table->uuid('editor_id')->index();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('commentaries');
+    }
+}