InsertDeviceData.php 1.6 KB

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