|
@@ -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);
|
|
|
+ }
|
|
|
+}
|