|
|
@@ -3,10 +3,12 @@
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
use Illuminate\Console\Command;
|
|
|
+use Illuminate\Support\Str;
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
+
|
|
|
use App\Http\Api\ChannelApi;
|
|
|
use App\Models\DhammaTerm;
|
|
|
-use Illuminate\Support\Str;
|
|
|
+use App\Models\Relation;
|
|
|
use App\Tools\Tools;
|
|
|
|
|
|
class UpgradeGrammarBook extends Command
|
|
|
@@ -48,71 +50,90 @@ class UpgradeGrammarBook extends Command
|
|
|
$this->error('no channel');
|
|
|
return 1;
|
|
|
}
|
|
|
- $cases = ['nom','acc','gen','dat','abl','inst','loc'];
|
|
|
- foreach ($cases as $key => $case) {
|
|
|
- $this->info('case='.$case);
|
|
|
- $title = "**[[{$case}]]** 用法表\n\n";
|
|
|
+
|
|
|
+ $relations = Relation::get();
|
|
|
+ $result = [];
|
|
|
+ foreach ($relations as $key => $relation) {
|
|
|
+ $from = json_decode($relation->from,true);
|
|
|
+ $words = [];
|
|
|
+ if(isset($from['spell']) && !empty($from['spell'])){
|
|
|
+ $words[] = $from['spell'];
|
|
|
+ }
|
|
|
+ if(isset($from['case']) && count($from['case'])>0){
|
|
|
+ $words = array_merge($words,$from['case']);
|
|
|
+ }
|
|
|
+ if(count($words)===0){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $word = implode('.',$words);
|
|
|
+ if(!isset($result[$word])){
|
|
|
+ $result[$word] = array();
|
|
|
+ }
|
|
|
+ $result[$word][] = $relation;
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($result as $key => $rows) {
|
|
|
+ $this->info('## '.$key);
|
|
|
+
|
|
|
$caseLocal = DhammaTerm::where('channal',$channelId)
|
|
|
- ->where('word',$case)
|
|
|
+ ->where('word',$key)
|
|
|
->value('meaning');
|
|
|
-
|
|
|
- $url = config('app.url')."/api/v2/relation?ui-lang={$lang}&from={$case}";
|
|
|
- $response = Http::get($url);
|
|
|
- if($response->successful()){
|
|
|
- $this->info("get data ok");
|
|
|
- $data = $response['data']['rows'];
|
|
|
- $relations = [];
|
|
|
- foreach ($data as $key => $row) {
|
|
|
- if(!isset($relations[$row['name']])){
|
|
|
- $relations[$row['name']] = array();
|
|
|
- $local = DhammaTerm::where('channal',$channelId)
|
|
|
- ->where('word',$row['name'])
|
|
|
- ->first();
|
|
|
- if($local){
|
|
|
- $relations[$row['name']]['meaning']=$local->meaning;
|
|
|
- $relations[$row['name']]['note']=$local->note;
|
|
|
- }else{
|
|
|
- $relations[$row['name']]['meaning']='';
|
|
|
- $relations[$row['name']]['note']='';
|
|
|
- }
|
|
|
- $relations[$row['name']]['to']=array();
|
|
|
+ if($caseLocal){
|
|
|
+ $title = "**[[{$key}]]** 用法表\n\n";
|
|
|
+ }else{
|
|
|
+ $title = "**{$key}** 用法表\n\n";
|
|
|
+ }
|
|
|
+ $relations = [];
|
|
|
+ foreach ($rows as $row) {
|
|
|
+ if(!isset($relations[$row['name']])){
|
|
|
+ $relations[$row['name']] = array();
|
|
|
+ $local = DhammaTerm::where('channal',$channelId)
|
|
|
+ ->where('word',$row['name'])
|
|
|
+ ->first();
|
|
|
+ if($local){
|
|
|
+ $relations[$row['name']]['meaning']=$local->meaning;
|
|
|
+ $relations[$row['name']]['note']=$local->note;
|
|
|
+ }else{
|
|
|
+ $relations[$row['name']]['meaning']='';
|
|
|
+ $relations[$row['name']]['note']='';
|
|
|
}
|
|
|
- $relations[$row['name']]['to'][] = $row['to'];
|
|
|
- }
|
|
|
- $table = "|名称|解释|\n";
|
|
|
- $table .= "| -- | -- |\n";
|
|
|
- foreach ($relations as $relation => $value) {
|
|
|
- $table .= "| [[{$relation}]] | ". $value['note']." |\n";
|
|
|
- }
|
|
|
- $table .= "\n\n";
|
|
|
- echo $title.$table;
|
|
|
- //更新字典
|
|
|
- $newWord = $case.'.relations';
|
|
|
- $new = DhammaTerm::firstOrNew([
|
|
|
- 'channal' => $channelId,
|
|
|
- 'word' => $newWord,
|
|
|
- ],[
|
|
|
- 'id'=>app('snowflake')->id(),
|
|
|
- 'guid'=>Str::uuid(),
|
|
|
- 'create_time'=>time()*1000,
|
|
|
- ]);
|
|
|
- if(empty($caseLocal)){
|
|
|
- $caseLocal = $case;
|
|
|
+ $relations[$row['name']]['to']=array();
|
|
|
}
|
|
|
- $owner = ChannelApi::getById($channelId);
|
|
|
- if(!$owner){
|
|
|
- $this->error('channel id error '.$channelId);
|
|
|
- continue;
|
|
|
- }
|
|
|
- $new->word_en = strtolower($newWord);
|
|
|
- $new->meaning =$caseLocal.'用法表';
|
|
|
- $new->note = $table;
|
|
|
- $new->language = $lang;
|
|
|
- $new->editor_id = 1;
|
|
|
- $new->owner = $owner['studio_id'];
|
|
|
- $new->modify_time = time()*1000;
|
|
|
- $new->save();
|
|
|
+ $relations[$row['name']]['to'][] = $row['to'];
|
|
|
+ }
|
|
|
+ $table = "|名称|解释|\n";
|
|
|
+ $table .= "| -- | -- |\n";
|
|
|
+ foreach ($relations as $relation => $value) {
|
|
|
+ $table .= "| [[{$relation}]] | ". $value['note']." |\n";
|
|
|
+ }
|
|
|
+ $table .= "\n\n";
|
|
|
+ echo $title.$table;
|
|
|
+ //更新字典
|
|
|
+ $newWord = $key.'.relations';
|
|
|
+ $new = DhammaTerm::firstOrNew([
|
|
|
+ 'channal' => $channelId,
|
|
|
+ 'word' => $newWord,
|
|
|
+ ],[
|
|
|
+ 'id'=>app('snowflake')->id(),
|
|
|
+ 'guid'=>Str::uuid(),
|
|
|
+ 'create_time'=>time()*1000,
|
|
|
+ ]);
|
|
|
+ if(empty($caseLocal)){
|
|
|
+ $caseLocal = $key;
|
|
|
+ }
|
|
|
+ $owner = ChannelApi::getById($channelId);
|
|
|
+ if(!$owner){
|
|
|
+ $this->error('channel id error '.$channelId);
|
|
|
+ continue;
|
|
|
}
|
|
|
+ $new->word_en = strtolower($newWord);
|
|
|
+ $new->meaning =$caseLocal.'用法表';
|
|
|
+ $new->note = $table;
|
|
|
+ $new->language = $lang;
|
|
|
+ $new->editor_id = 1;
|
|
|
+ $new->owner = $owner['studio_id'];
|
|
|
+ $new->modify_time = time()*1000;
|
|
|
+ $new->save();
|
|
|
}
|
|
|
|
|
|
return 0;
|