UpgradeQuote.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. if(\App\Tools\Tools::isStop()){
  40. return 0;
  41. }
  42. $start = time();
  43. $channelId = ChannelApi::getSysChannel('_System_Quote_');
  44. if($channelId===false){
  45. $this->error('no channel');
  46. return 1;
  47. }
  48. for ($i=1; $i <= 217; $i++) {
  49. if(!empty($this->argument('book'))){
  50. if($i != $this->argument('book')){
  51. continue;
  52. }
  53. }
  54. $pts_book=0;
  55. $pts_page=0;
  56. $myanmar_book=0;
  57. $myanmar_page=0;
  58. $cs_para=0;
  59. $pali = PaliSentence::where('book',$i);
  60. $bar = $this->output->createProgressBar(PaliSentence::where('book',$i)->count());
  61. $pali = $pali->select('book','paragraph','word_begin','word_end')->cursor();
  62. foreach ($pali as $value) {
  63. # code...
  64. $wbwContent=[];
  65. $words = WbwTemplate::where("book",$value->book)
  66. ->where("paragraph",$value->paragraph)
  67. ->where("wid",">=",$value->word_begin)
  68. ->where("wid","<=",$value->word_end)
  69. ->orderBy('wid','asc')
  70. ->get();
  71. $sent = '';
  72. foreach ($words as $wbw_word) {
  73. # code...
  74. if($wbw_word->type === '.ctl.'){
  75. if(substr($wbw_word->word,0,1) === 'M'){
  76. $m = explode('.',substr($wbw_word->word,1));
  77. $myanmar_book=(int)$m[0];
  78. $myanmar_page=(int)$m[1];
  79. }
  80. if(substr($wbw_word->word,0,1) === 'P'){
  81. $m = explode('.',substr($wbw_word->word,1));
  82. $pts_book=(int)$m[0];
  83. $pts_page=(int)$m[1];
  84. }
  85. }
  86. if($wbw_word->style === 'paranum'){
  87. $cs_para=(int)$wbw_word->word;
  88. }
  89. }
  90. $wbwContent = [
  91. 'pts_book'=>$pts_book,
  92. 'pts_page'=>$pts_page,
  93. 'myanmar_book'=> $myanmar_book,
  94. 'myanmar_page'=> $myanmar_page,
  95. 'cs_para'=> $cs_para,
  96. ];
  97. $sent = \json_encode($wbwContent,JSON_UNESCAPED_UNICODE);
  98. $newRow = Sentence::firstOrNew(
  99. [
  100. "book_id" => $value->book,
  101. "paragraph" => $value->paragraph,
  102. "word_start" => $value->word_begin,
  103. "word_end" => $value->word_end,
  104. "channel_uid" => $channelId,
  105. ],
  106. [
  107. 'id' =>app('snowflake')->id(),
  108. 'uid' =>Str::uuid(),
  109. ]
  110. );
  111. $newRow->editor_uid = config("mint.admin.root_uuid");
  112. $newRow->content = trim($sent);
  113. $newRow->content_type = "json";
  114. $newRow->strlen = mb_strlen($sent,"UTF-8");
  115. $newRow->status = 10;
  116. $newRow->create_time = time()*1000;
  117. $newRow->modify_time = time()*1000;
  118. $newRow->language = 'en';
  119. $newRow->save();
  120. $bar->advance();
  121. }
  122. $bar->finish();
  123. }
  124. $this->info("finished ".(time()-$start)."s");
  125. return 0;
  126. }
  127. }