CronAction.class.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. class CronAction extends Action {
  3. public function createEplate_index( ){
  4. $this->createElectronicPlate();
  5. }
  6. private function createElectronicPlate( ){
  7. $start = time();
  8. $pendingElectricPlate = Redis('jyzl_wait_create_eplate');
  9. $plateLocalPath = Redis('jyzl_wait_upload2oss_eplate', 'queue');
  10. while( (time() - $start) < 60 ){
  11. $licensPlate = $pendingElectricPlate->pop();
  12. if($licensPlate){
  13. echo 'pop licensPlate:'.$licensPlate.PHP_EOL;
  14. $field = 'LicensPlate,VehicleColor, FullName, Address, FrameNumber, MotorNumber, VehicleBrand';
  15. $vehicleInfo = M('jms_vehicle')->where('LicensPlate' => $licensPlate)->field($field);
  16. $localPath = '生成函数';
  17. $up2ossWait = json_encode(array('licensPlate' => $licensPlate, 'localPath' => $localPath));
  18. $plateLocalPath->push($up2ossWait);
  19. }
  20. sleep(1);
  21. }
  22. }
  23. private function uploadElectronicPlate2Oss( ){
  24. $config = array(
  25. 'OssDsn' => C('OSS_DSN'),
  26. 'filePathDir' => '/data/wwwroot/czapp.rltest.cn/1.0.0//uploadimage/',
  27. "SaveRule" => "/electronic_plate/{Y}{m}{d}/{uid}.{ext}",
  28. "AllowExts" => array('jpg', 'png', 'jpeg'), // 允许上传的文件后缀(留空为不限制)
  29. "ResizeImage" => true, // 是否自动压缩
  30. "MaxImageWidth" => 1024,
  31. "MaxImageHeight" => 1024,
  32. "IsCheckRgb" => true,
  33. "MinImgAverageRgb" => 70
  34. );
  35. $upload = new \Jms\File\Oss2($config);
  36. $start = time();
  37. $plateLocalPath = Redis('jyzl_wait_upload2oss_eplate');
  38. while( (time() - $start) < 60 ){
  39. $data = $plateLocalPath->pop();
  40. var_dump($data);
  41. json_decode($data,true);
  42. var_dump($data);
  43. if($data){
  44. //TEST
  45. $fileName = 'gravatar.jpg';
  46. //$fileName = $data['localPath'];
  47. $uploadRes = $upload->localFileUpload($fileName);
  48. if(!$uploadRes['success']){
  49. echo $uploadRes['message'].PHP_EOL;
  50. continue;
  51. }
  52. $frontImageUrl = $uploadRes['objectname'];
  53. $updateRes = M('jms_vehicle')->where(array('LicensePlate' => $data['licensPlate']))->setField('FrontElectronicPlateUrl',$frontImageUrl);
  54. if(!$updateRes){
  55. echo 'update failed'.PHP_EOL;
  56. continue;
  57. }
  58. if(file_exists($filename)){
  59. unlink($filename);
  60. }
  61. }
  62. sleep(1);
  63. }
  64. }
  65. public function uploadEplate_index( ){
  66. $this->uploadElectronicPlate2Oss();
  67. }
  68. public function test_function( ){
  69. $plate = 'BJ000100';
  70. $pendingElectricPlate = Redis("jyzl_wait_create_eplate","queue");
  71. $licensePlate = $plate;
  72. $pendingElectricPlate->push($licensePlate);
  73. }
  74. public function acrossAlarm2Kafka( ){
  75. // 从 topic :gps_location_data 取轨迹
  76. // 存入 topic:gps_alarm_msg_queue
  77. }
  78. }