2
0

InitSystemDict.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\DictInfo;
  4. use Illuminate\Console\Command;
  5. class InitSystemDict extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. * php artisan init:system.dict
  12. */
  13. protected $signature = 'init:system.dict';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = 'create system dict. like sys_regular ect.';
  20. /**
  21. * name 不要修改。因为在程序其他地方,用name 查询词典id
  22. */
  23. protected $dictionary =[
  24. [
  25. "name"=>'robot_compound',
  26. 'shortname'=>'compound',
  27. 'description'=>'split compound by AI',
  28. 'src_lang'=>'pa',
  29. 'dest_lang'=>'cm',
  30. ],
  31. [
  32. "name"=>'system_regular',
  33. 'shortname'=>'regular',
  34. 'description'=>'system regular',
  35. 'src_lang'=>'pa',
  36. 'dest_lang'=>'cm',
  37. ],
  38. [
  39. "name"=>'community',
  40. 'shortname'=>'社区',
  41. 'description'=>'由用户贡献词条的社区字典',
  42. 'src_lang'=>'pa',
  43. 'dest_lang'=>'cm',
  44. ],
  45. [
  46. "name"=>'community_extract',
  47. 'shortname'=>'社区汇总',
  48. 'description'=>'由用户贡献词条的社区字典汇总统计',
  49. 'src_lang'=>'pa',
  50. 'dest_lang'=>'cm',
  51. ],
  52. [
  53. "name"=>'system_preference',
  54. 'shortname'=>'系统单词首选项',
  55. 'description'=>'通过系统筛选出的首选项,只包含语法信息',
  56. 'src_lang'=>'pa',
  57. 'dest_lang'=>'cm',
  58. ],
  59. ];
  60. /**
  61. * Create a new command instance.
  62. *
  63. * @return void
  64. */
  65. public function __construct()
  66. {
  67. parent::__construct();
  68. }
  69. /**
  70. * Execute the console command.
  71. *
  72. * @return int
  73. */
  74. public function handle()
  75. {
  76. if(\App\Tools\Tools::isStop()){
  77. return 0;
  78. }
  79. $this->info("start");
  80. foreach ($this->dictionary as $key => $value) {
  81. # code...
  82. $channel = DictInfo::firstOrNew([
  83. 'name' => $value['name'],
  84. 'owner_id' => config("mint.admin.root_uuid"),
  85. ]);
  86. $channel->shortname = $value['shortname'];
  87. $channel->description = $value['description'];
  88. $channel->src_lang = $value['src_lang'];
  89. $channel->dest_lang = $value['dest_lang'];
  90. $channel->meta = json_encode($value,JSON_UNESCAPED_UNICODE);
  91. $channel->save();
  92. $this->info("updated {$value['name']}");
  93. }
  94. return 0;
  95. }
  96. }