likang 2 years ago
parent
commit
5a7be96e2c

+ 10 - 0
catch/api/controller/Api.php

@@ -1,4 +1,12 @@
 <?php
+/*
+ * @Descripttion: 
+ * @version: 1.0.0
+ * @Author: likang
+ * @Date: 2022-08-12 10:33:24
+ * @LastEditors: likang
+ * @LastEditTime: 2022-10-09 14:16:28
+ */
 
 
 
@@ -41,6 +49,8 @@ class Api extends CatchController
                 'move' => $item['move'],
                 'step' => empty($item['step']) ? 0 : $item['step'],
                 'temperature' => empty($item['temperature']) ? 0 : $item['temperature'],
+                //告警
+                'temperWarn' => empty($item['temperWarn']) ? 00 : $item['temperWarn'],
             ];
         }
         $tage = new TagHistory();

+ 40 - 43
catch/tag_history/controller/TagHistory.php

@@ -122,6 +122,13 @@ class TagHistory extends CatchController
             $list[$key]['temperature'] = $da['temperature'];
             $list[$key]['addTime'] = date('Y-m-d H:i:s', $value['addTime']);
             $list[$key]['time'] = date('Y-m-d H:i:s', $da['time']);
+            if ($da['temperWarn'] == '00') {
+                $list[$key]['temperWarn'] = '正常';
+            } elseif ($da['temperWarn'] == '01') {
+                $list[$key]['temperWarn'] = '低温告警';
+            } elseif ($da['temperWarn'] == '10') {
+                $list[$key]['temperWarn'] = '高温告警';
+            }
         }
         return CatchResponse::success($list);
     }
@@ -263,6 +270,13 @@ class TagHistory extends CatchController
         foreach ($list as $key => $value) {
             $list[$key]['time'] = date('Y-m-d H:i:s', $value['time']);
             $list[$key]['addTime'] = date('Y-m-d H:i:s', $value['addTime']);
+            if ($value['temperWarn'] == '00') {
+                $list[$key]['temperWarn'] = '正常';
+            } elseif ($value['temperWarn'] == '01') {
+                $list[$key]['temperWarn'] = '低温告警';
+            } elseif ($value['temperWarn'] == '10') {
+                $list[$key]['temperWarn'] = '高温告警';
+            }
         }
         return json([
             'code'    => Code::SUCCESS,
@@ -273,79 +287,62 @@ class TagHistory extends CatchController
             'data'    => $list,
         ]);
     }
-    //随机生成温度
-    public function randomTemperature()
-    {
 
-        $resout = 38.5;
-        return $resout;
-    }
-    //生成随机步数
-    public function randomStep()
-    {
-        $intage = 10;
-        $resout = $intage;
-        return $resout;
-    }
     /**
      * 折现图
      */
     public function lineChart(Request $request)
     {
         $data = $request->get();
-        $start_time = $data['start_time'];
+        $mac = null;
+        $lable = null;
+        if (!empty($data['start_time'])) {
+            $start_time = strtotime($data['start_time'][0]);
+            $end_time = strtotime($data['start_time'][1]);
+        }
 
         if (empty($start_time)) {
             $start_time = strtotime(date('Y-m-d'));
         }
-
+        if (!empty($data['mac'])) {
+            $mac = $data['mac'];
+        }
+        if (!empty($data['lable'])) {
+            $lable = $data['lable'];
+        }
         $end_time = null;
         if (!$end_time) {
             $end_time = time();
         }
 
         $where = [];
-        $where[] = [$start_time, '>=', 'addTime'];
-        $where[] = [$end_time, '=<', 'addTime'];
-        $where[] = ['mac', 'in', '30B5F10138ED'];
-        $where[] = ['lable', 'in', "000000880002,000000880003"];
+        $where[] = ['addTime', '>=', $start_time];
+        $where[] = ['addTime', '<', $end_time];
+        $where[] = ['mac', '=', $mac];
+        $where[] = ['lable', '=', $lable];
+
+        $list = $this->tagHistoryModel->where($where)->order('addTime asc')->select();
 
-        $list = $this->tagHistoryModel->where($where)->order('addTime desc')->select()->toArray();
 
         $time = [];
         $lable1 = [];
-        $lable2 = [];
+
         foreach ($list as $item) {
-            $time[] = $item['addTime'];
-            if ($item['lable'] == '000000880002') {
-                $lable1[$item['addTime']] = $item['temperature'];
-                if (!$lable2[$item['addTime']]) {
-                    $lable2[$item['addTime']] = null;
-                }
-            } else if ($item['lable'] == '000000880003') {
-                $lable2[] = $item['temperature'];
-                if (!$lable1[$item['addTime']]) {
-                    $lable1[$item['addTime']] = null;
-                }
-            }
+            $time[] = date('Y-m-d H:i:s', $item['addTime']);
+            $lable1[] = $item['temperature'];
         }
         $renData = [];
         $renData = [
-            'xAxis' => array_unique($time),
-            'legend' => ['000000880002', '000000880003'],
+            'xAxis' => $time,
+            'legend' => [$lable],
             'series' => [
                 [
-                    'name' => '000000880002',
+                    'name' => $lable,
                     'type' => 'line',
                     'stack' => 'Total',
-                    'data' => array_values($lable1)
+                    'data' => $lable1
                 ],
-                [
-                    'name' => '000000880003',
-                    'type' => 'line',
-                    'stack' => 'Total',
-                    'data' => array_values($lable2)
-                ]
+
             ]
 
         ];

+ 3 - 0
catch/tag_history/model/TagHistory.php

@@ -1,5 +1,6 @@
 <?php
 
+
 namespace catchAdmin\tag_history\model;
 
 use catcher\base\CatchModel as Model;
@@ -24,6 +25,8 @@ class TagHistory extends Model
         'move',
         'step',
         'temperature',
+        //告警
+        'temperWarn',
         // 创建人ID
         'creator_id',
         // 创建时间