InsertDeviceData.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Http\Controllers\Api\FeederDataGenerator;
  4. use App\Model\ForDeviceData;
  5. use App\Model\SystemL;
  6. use Illuminate\Console\Command;
  7. class InsertDeviceData extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'command:insert_device_data';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'Command description';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. /**
  31. * Execute the console command.
  32. *
  33. * @return mixed
  34. */
  35. public function handle()
  36. {
  37. echo '生成设备数据--------start---------------';
  38. $dispatch = ForDeviceData::where("del_time",0)
  39. ->select('id','finished_num','start_time as upd_time','device_id')
  40. ->get()->toArray();
  41. if(! empty($dispatch)){
  42. $first_id = SystemL::max('id');
  43. list($status, $msg) = (new FeederDataGenerator)->generateData($dispatch);
  44. if($status){
  45. $end_id = SystemL::max('id');
  46. ForDeviceData::whereIn('id',array_column($dispatch,'id'))
  47. ->update(['del_time' => time(), 'systeml_id_str' => $first_id . '|' . $end_id]);
  48. }else{
  49. echo $msg . "\n";
  50. }
  51. }
  52. echo '生成设备数据--------end---------------';
  53. }
  54. }