ResetSql.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\command;
  4. use think\console\Command;
  5. use think\console\Input;
  6. use think\console\input\Argument;
  7. use think\console\input\Option;
  8. use think\console\Output;
  9. use think\facade\Db;
  10. class ResetSql extends Command
  11. {
  12. private $delete_tables = [
  13. 'lab_data',
  14. 'inspect_report',
  15. 'exam_report',
  16. 'medical_orders',
  17. 'exam_application',
  18. 'medical_information',
  19. 'patient',
  20. 'diagnose',
  21. 'middle_storage',
  22. 'mpi',
  23. 'hospital_patient',
  24. 'hospital_hrpatient',
  25. 'bi_inspect_report',
  26. 'hr_record',
  27. 'admin_log',
  28. 'call_record',
  29. 'crud_log',
  30. 'del_bi_inspect_report',
  31. 'del_inspect_report',
  32. 'del_lab_data',
  33. 'del_medical_information',
  34. 'del_exam_report',
  35. 'del_patient',
  36. 'repeat_post',
  37. 'migrations',
  38. 'token',
  39. 'zskk_test'
  40. ];
  41. protected function configure()
  42. {
  43. // 指令配置
  44. $this->setName('resetsql')
  45. ->setDescription('清空表数据:
  46. '.implode(',
  47. ', $this->delete_tables));
  48. }
  49. protected function execute(Input $input, Output $output)
  50. {
  51. // 指令输出
  52. $output->writeln('删除表任务开始');
  53. foreach($this->delete_tables as $table) {
  54. $this->_deleteTable($output, $table);
  55. }
  56. $output->writeln('删除表任务结束');
  57. }
  58. protected function _deleteTable(Output $output, string $table)
  59. {
  60. $output->writeln('删除表 '.$table.' 数据开始');
  61. // Db::table($table)->query(true);
  62. Db::execute("TRUNCATE TABLE $table");
  63. $output->writeln('删除表 '.$table.' 数据结束');
  64. }
  65. }