UpgradeWbwParaNum.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\WbwTemplate;
  5. class UpgradeWbwParaNum extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. * php artisan upgrade:wbw.para.num 130
  10. * @var string
  11. */
  12. protected $signature = 'upgrade:wbw.para.num {book?}';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = 'Command description';
  19. /**
  20. * Create a new command instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. }
  28. /**
  29. * Execute the console command.
  30. *
  31. * @return int
  32. */
  33. public function handle()
  34. {
  35. if(empty($this->argument('book'))){
  36. $start = 1;
  37. $end = 217;
  38. }else{
  39. $start = $this->argument('book');
  40. $end = $this->argument('book');
  41. }
  42. for ($iBook=$start; $iBook <=$end ; $iBook++) {
  43. $this->info("book = {$iBook}");
  44. $startAt = time();
  45. $count = WbwTemplate::where('book',$iBook)->count();
  46. $bar = $this->output->createProgressBar($count);
  47. $rows = WbwTemplate::where('book',$iBook)
  48. ->orderBy('paragraph')
  49. ->orderBy('wid')->cursor();
  50. $start = false;
  51. $bookCode='';
  52. $count=0;
  53. $currPara = 0;
  54. $bookCodeStack = [];
  55. foreach ($rows as $key => $row) {
  56. $bar->advance();
  57. if($row->paragraph !== $currPara){
  58. $currPara = $row->paragraph;
  59. $start = false;
  60. $bookCode='';
  61. $bookCodeStack = [];
  62. }
  63. if($row->word==='('){
  64. $start = true;
  65. $bookCode='';
  66. $bookCodeStack = [];
  67. continue;
  68. }
  69. if($start){
  70. if(is_numeric(str_replace('-','',$row->word))){
  71. if(empty($bookCode) && count($bookCodeStack)>0){
  72. //继承之前的
  73. $bookCodeList=[];
  74. foreach ($bookCodeStack as $key => $value) {
  75. $bookCodeList[] = $key;
  76. }
  77. $bookCode = $bookCodeList[0];
  78. }
  79. $dot = mb_strrpos($bookCode,'.',0,'UTF-8');
  80. if($dot === false){
  81. $bookName = $bookCode;
  82. $paraNum = $row->word;
  83. }else{
  84. $bookName = mb_substr($bookCode,0,$dot+1,'UTF-8');
  85. $paraNum = mb_substr($bookCode,$dot+1,null,'UTF-8').$row->word;
  86. }
  87. $bookName = mb_strtolower(mb_substr($bookName,0,64,'UTF-8'),'UTF-8');
  88. $bookCodeStack[$bookName] = 1;
  89. if(!empty($bookName)){
  90. WbwTemplate::where('id',$row->id)->update([
  91. 'type'=>':cs.para:',
  92. 'gramma'=>$bookName,
  93. 'part'=>$paraNum,
  94. ]);
  95. }
  96. $count++;
  97. }else if($row->word===';'){
  98. $bookCode = '';
  99. continue;
  100. }else if($row->word===')'){
  101. $start = false;
  102. continue;
  103. }
  104. $bookCode .= $row->word;
  105. }
  106. }
  107. $bar->finish();
  108. $time = time() - $startAt;
  109. $this->info(" {$time}s {$count}");
  110. }
  111. return 0;
  112. }
  113. }