gogs 1 рік тому
батько
коміт
9b52c111c3

+ 40 - 0
app/Console/Commands/LsTest.php

@@ -0,0 +1,40 @@
+<?php
+
+namespace App\Console\Commands;
+
+
+use App\Service\ThirdService;
+use Illuminate\Console\Command;
+use Illuminate\Support\Facades\DB;
+
+class LsTest extends Command
+{
+
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+
+    protected $signature = 'set:lsTest';
+
+    protected $description = '';
+
+    protected $process;
+    protected $key = 'lsTest';
+
+    public function __construct()
+    {
+        parent::__construct();
+
+    }
+
+    public function handle()
+    {
+
+            $service = new ThirdService();
+            $service->pushThird();
+
+    }
+}

+ 2 - 0
app/Console/Kernel.php

@@ -14,6 +14,7 @@ class Kernel extends ConsoleKernel
      */
     protected $commands = [
        //
+        \App\Console\Commands\LsTest::class
     ];
 
     /**
@@ -24,6 +25,7 @@ class Kernel extends ConsoleKernel
      */
     protected function schedule(Schedule $schedule)
     {
+
         // $schedule->command('inspire')
         //          ->hourly();
     }

+ 3 - 1
app/Http/Controllers/Api/TestController.php

@@ -6,6 +6,7 @@ namespace App\Http\Controllers\Api;
 use App\Model\BoxDetail;
 use App\Service\FinishedOrderService;
 use App\Service\MeasureService;
+use App\Service\ThirdService;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\DB;
 
@@ -14,7 +15,8 @@ class TestController extends BaseController
 {
 
     public function tt(){
-        die('123132');
+        $a = new ThirdService();
+        $a->pushThird();
     }
 
     public function aa(){

+ 99 - 0
app/Service/ThirdService.php

@@ -0,0 +1,99 @@
+<?php
+
+namespace App\Service;
+
+use App\Model\Area;
+use App\Model\Device;
+use App\Model\DeviceType;
+use App\Model\Screen;
+use App\Model\SystemL;
+
+/**
+ * 区域相关
+ * @package App\Models
+ */
+class ThirdService extends Service
+{
+    public function pushThird(){
+        $list = Device::where('del_time',0)->select('*')->get()->toArray();
+
+        while (true) {
+            sleep(3);
+            $insert = [];
+            $jwkey = [];
+            foreach ($list as $k=>$v){
+                $value = 0;
+                $point_name = '';
+                switch ($v['device_type_id']){
+                    case 1:
+                        $value = $this->cgq_rand();
+                        $point_name = strpos($v['title'], '温度') !== false ? '温度' : '湿度';
+                        if($this->zt_rand()) $point_name1 = $point_name.'异常';
+                        break;
+                    case 2:
+                        $value = $this->kg_rand();
+                        $point_name = '仓门行程开关';
+                        break;
+                    case 3:
+                        $value = $this->yj_rand();
+                        $point_name = '预警';
+                        break;
+                    case 4:
+                        if(!isset($jwkey[$v['id']])) $jwkey[$v['id']] = [
+                            'j' => 120,
+                            'w' => 30
+                        ];
+                        $point_name = 'GPS';
+                        $jwkey[$v['id']]['j'] = $jwkey[$v['id']]['j']+$this->j_rand();
+                        $jwkey[$v['id']]['w'] = $jwkey[$v['id']]['w']+$this->w_rand();
+                        $value = (string)$jwkey[$v['id']]['j'].','.(string)$jwkey[$v['id']]['w'];
+                        break;
+                    default:
+                        break;
+                }
+                //获取节点名称
+
+                $detail = [
+                    'device_name' => $v['title'],
+                    'time' => time(),
+                    'value' => $value,
+                    'device_no' => $v['code'],
+                    'data_point_id' => $k,
+                    'data_point_name' => $point_name,
+                    'push_time' => time(),
+                    'slave_name' => '',
+                ];
+                $insert[] = $detail;
+                if(isset($point_name1)){
+                    $detail['data_point_id'] = $k.$k;
+                    $detail['data_point_name'] = $point_name1;
+                    $detail['value'] = 1;
+                    $insert[] = $detail;
+                }
+            }
+//            var_dump($insert);die;
+            $a = SystemL::insert($insert);
+//            var_dump($a);die;
+        }
+
+    }
+
+    public function j_rand(){
+        return rand(0,2)+(rand(0,100)/100);
+    }
+    public function w_rand(){
+        return rand(0,2)+(rand(0,100)/100);
+    }
+    public function cgq_rand(){
+        return rand(0,20)+(rand(0,100)/100);
+    }
+    public function kg_rand(){
+        return rand(0,1);
+    }
+    public function yj_rand(){
+        return rand(0,1);
+    }
+    public function zt_rand(){
+        return rand(0,1);
+    }
+}

+ 1 - 1
routes/api.php

@@ -12,12 +12,12 @@ use Illuminate\Http\Request;
 | is assigned the "api" middleware group. Enjoy building your API!
 |
 */
-
 Route::middleware('auth:api')->get('/user', function (Request $request) {
     return $request->user();
 });
 
 Route::any('login', 'Api\LoginController@login');
+Route::any('tt', 'Api\TestController@tt');
 Route::any('getHeaderWord', 'Api\HeaderWordController@getHeaderWord');
 Route::any('getHeaderSetting', 'Api\HeaderWordController@getHeaderSettings');
 Route::any('screen/{file_name}', 'Api\ScreenController@getFile');