InitSystemDict.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. */
  12. protected $signature = 'init:system.dict';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = 'create system dict. like sys_regular ect.';
  19. /**
  20. * name 不要修改。因为在程序其他地方,用name 查询词典id
  21. */
  22. protected $dictionary =[
  23. [
  24. "name"=>'robot_compound',
  25. 'shortname'=>'compound',
  26. 'description'=>'split compound by AI',
  27. 'src_lang'=>'pa',
  28. 'dest_lang'=>'cm',
  29. ],
  30. [
  31. "name"=>'system_regular',
  32. 'shortname'=>'regular',
  33. 'description'=>'system regular',
  34. 'src_lang'=>'pa',
  35. 'dest_lang'=>'cm',
  36. ],
  37. [
  38. "name"=>'community',
  39. 'shortname'=>'社区',
  40. 'description'=>'由用户贡献词条的社区字典',
  41. 'src_lang'=>'pa',
  42. 'dest_lang'=>'cm',
  43. ],
  44. [
  45. "name"=>'community_extract',
  46. 'shortname'=>'社区汇总',
  47. 'description'=>'由用户贡献词条的社区字典汇总统计',
  48. 'src_lang'=>'pa',
  49. 'dest_lang'=>'cm',
  50. ],
  51. ];
  52. /**
  53. * Create a new command instance.
  54. *
  55. * @return void
  56. */
  57. public function __construct()
  58. {
  59. parent::__construct();
  60. }
  61. /**
  62. * Execute the console command.
  63. *
  64. * @return int
  65. */
  66. public function handle()
  67. {
  68. $this->info("start");
  69. foreach ($this->dictionary as $key => $value) {
  70. # code...
  71. $channel = DictInfo::firstOrNew([
  72. 'name' => $value['name'],
  73. 'owner_id' => config("app.admin.root_uuid"),
  74. ]);
  75. $channel->shortname = $value['shortname'];
  76. $channel->description = $value['description'];
  77. $channel->src_lang = $value['src_lang'];
  78. $channel->dest_lang = $value['dest_lang'];
  79. $channel->meta = json_encode($value,JSON_UNESCAPED_UNICODE);
  80. $channel->save();
  81. $this->info("updated {$value['name']}");
  82. }
  83. return 0;
  84. }
  85. }