UpgradeQuote.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\PaliSentence;
  5. use App\Models\WbwTemplate;
  6. use App\Models\Sentence;
  7. use App\Http\Api\ChannelApi;
  8. use Illuminate\Support\Str;
  9. class UpgradeQuote extends Command
  10. {
  11. /**
  12. * The name and signature of the console command.
  13. *
  14. * @var string
  15. */
  16. protected $signature = 'upgrade:quote {book?}';
  17. /**
  18. * The console command description.
  19. *
  20. * @var string
  21. */
  22. protected $description = 'Command description';
  23. /**
  24. * Create a new command instance.
  25. *
  26. * @return void
  27. */
  28. public function __construct()
  29. {
  30. parent::__construct();
  31. }
  32. /**
  33. * Execute the console command.
  34. *
  35. * @return int
  36. */
  37. public function handle()
  38. {
  39. $start = time();
  40. $channelId = ChannelApi::getSysChannel('_System_Quote_');
  41. if($channelId===false){
  42. $this->error('no channel');
  43. return 1;
  44. }
  45. for ($i=1; $i <= 217; $i++) {
  46. if(!empty($this->argument('book'))){
  47. if($i != $this->argument('book')){
  48. continue;
  49. }
  50. }
  51. $pts_book=0;
  52. $pts_page=0;
  53. $myanmar_book=0;
  54. $myanmar_page=0;
  55. $cs_para=0;
  56. $pali = PaliSentence::where('book',$i);
  57. $bar = $this->output->createProgressBar(PaliSentence::where('book',$i)->count());
  58. $pali = $pali->select('book','paragraph','word_begin','word_end')->cursor();
  59. foreach ($pali as $value) {
  60. # code...
  61. $wbwContent=[];
  62. $words = WbwTemplate::where("book",$value->book)
  63. ->where("paragraph",$value->paragraph)
  64. ->where("wid",">=",$value->word_begin)
  65. ->where("wid","<=",$value->word_end)
  66. ->orderBy('wid','asc')
  67. ->get();
  68. $sent = '';
  69. foreach ($words as $wbw_word) {
  70. # code...
  71. if($wbw_word->type === '.ctl.'){
  72. if(substr($wbw_word->word,0,1) === 'M'){
  73. $m = explode('.',substr($wbw_word->word,1));
  74. $myanmar_book=(int)$m[0];
  75. $myanmar_page=(int)$m[1];
  76. }
  77. if(substr($wbw_word->word,0,1) === 'P'){
  78. $m = explode('.',substr($wbw_word->word,1));
  79. $pts_book=(int)$m[0];
  80. $pts_page=(int)$m[1];
  81. }
  82. }
  83. if($wbw_word->style === 'paranum'){
  84. $cs_para=(int)$wbw_word->word;
  85. }
  86. }
  87. $wbwContent = [
  88. 'pts_book'=>$pts_book,
  89. 'pts_page'=>$pts_page,
  90. 'myanmar_book'=> $myanmar_book,
  91. 'myanmar_page'=> $myanmar_page,
  92. 'cs_para'=> $cs_para,
  93. ];
  94. $sent = \json_encode($wbwContent,JSON_UNESCAPED_UNICODE);
  95. $newRow = Sentence::firstOrNew(
  96. [
  97. "book_id" => $value->book,
  98. "paragraph" => $value->paragraph,
  99. "word_start" => $value->word_begin,
  100. "word_end" => $value->word_end,
  101. "channel_uid" => $channelId,
  102. ],
  103. [
  104. 'id' =>app('snowflake')->id(),
  105. 'uid' =>Str::uuid(),
  106. ]
  107. );
  108. $newRow->editor_uid = config("mint.admin.root_uuid");
  109. $newRow->content = trim($sent);
  110. $newRow->content_type = "json";
  111. $newRow->strlen = mb_strlen($sent,"UTF-8");
  112. $newRow->status = 10;
  113. $newRow->create_time = time()*1000;
  114. $newRow->modify_time = time()*1000;
  115. $newRow->language = 'en';
  116. $newRow->save();
  117. $bar->advance();
  118. }
  119. $bar->finish();
  120. }
  121. $this->info("finished ".(time()-$start)."s");
  122. return 0;
  123. }
  124. }