InitSystemDict.php 2.8 KB

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