Kaynağa Gözat

Merge branch 'master' of http://gogs.renlianiot.com:4000/zmcoding/smart-tool-api

weich 2 yıl önce
ebeveyn
işleme
1d1db8693d

+ 1 - 0
catch/device/model/Device.php

@@ -96,4 +96,5 @@ class Device extends Model
             ->select();
         return $res;
     }
+   
 }

+ 12 - 1
catch/fan/controller/Fan.php

@@ -6,6 +6,7 @@ use catcher\base\CatchRequest as Request;
 use catcher\CatchResponse;
 use catcher\base\CatchController;
 use catchAdmin\fan\model\Fan as fanModel;
+use think\facade\Db;
 
 class Fan extends CatchController
 {
@@ -13,6 +14,7 @@ class Fan extends CatchController
     
     public function __construct(FanModel $fanModel)
     {
+        
         $this->fanModel = $fanModel;
     }
     
@@ -23,6 +25,7 @@ class Fan extends CatchController
      */
     public function index(Request $request) : \think\Response
     {
+
         return CatchResponse::paginate($this->fanModel->getList());
     }
     
@@ -33,7 +36,14 @@ class Fan extends CatchController
      */
     public function save(Request $request) : \think\Response
     {
-        return CatchResponse::success($this->fanModel->storeBy($request->post()));
+        $data = $request->post();
+        if($data['production_date']){
+            $data['production_date'] = date('Y-m-d',$data['production_date']);
+        }
+        if($data['install_date']){
+            $data['install_date'] = date('Y-m-d',$data['install_date']);
+        }
+        return CatchResponse::success($this->fanModel->storeBy($data));
     }
     
     /**
@@ -66,4 +76,5 @@ class Fan extends CatchController
     {
         return CatchResponse::success($this->fanModel->deleteBy($id));
     }
+    
 }

+ 14 - 1
catch/fan/model/Fan.php

@@ -3,9 +3,13 @@
 namespace catchAdmin\fan\model;
 
 use catcher\base\CatchModel as Model;
-
+use think\facade\Db;
+use catchAdmin\fan\model\get\FanGet;
+use catchAdmin\fan\model\search\FanSearch;
 class Fan extends Model
 {
+     use FanGet;
+     use FanSearch;
     // 表名
     public $name = 'fan';
     // 数据库字段映射
@@ -36,4 +40,13 @@ class Fan extends Model
         // 软删除
         'deleted_at',
     );
+    public function getList()
+    {
+        return $this->catchSearch()
+        ->append(['wind_name'])
+        ->field('*')
+        ->catchOrder()
+        ->creator()
+        ->paginate();
+    }
 }

+ 17 - 0
catch/fan/model/get/FanGet.php

@@ -0,0 +1,17 @@
+<?php
+namespace catchAdmin\fan\model\get;
+
+use think\facade\Db;
+
+trait FanGet
+{
+
+    public function getWindNameAttr()
+    {
+        $wind_id = $this->wind_id;
+        $wind_name =  Db::name('wind')->where('id',$wind_id)->value('name');
+        return $wind_name;
+    }    
+
+
+}

+ 19 - 0
catch/fan/model/search/FanSearch.php

@@ -0,0 +1,19 @@
+<?php
+namespace catchAdmin\fan\model\search;
+trait FanSearch
+{
+
+    public function searchNumberAttr($query, $value, $data)
+    {
+        return $query->where('number', 'like', '%'.$value.'%');
+    }
+    public function searchWindIdAttr($query, $value, $data)
+    {
+        return $query->where('wind_id',$value);
+    }
+
+
+
+
+
+}

+ 41 - 0
catch/hydraulic/database/migrations/20220504142809_hydraulic_add_Fields.php

@@ -0,0 +1,41 @@
+<?php
+
+use think\migration\Migrator;
+use think\migration\db\Column;
+use Phinx\Db\Adapter\MysqlAdapter;
+
+class HydraulicAddFields extends Migrator
+{
+    /**
+     * Change Method.
+     *
+     * Write your reversible migrations using this method.
+     *
+     * More information on writing migrations is available here:
+     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
+     *
+     * The following commands can be used in this method and Phinx will
+     * automatically reverse them when rolling back:
+     *
+     *    createTable
+     *    renameTable
+     *    addColumn
+     *    renameColumn
+     *    addIndex
+     *    addForeignKey
+     *
+     * Remember to call "create()" or "update()" and NOT "save()" when working
+     * with the Table class.
+     */
+    public function change()
+    {
+        if ($this->hasTable('hydraulic')) {
+            $table = $this->table('hydraulic');
+
+            $table  ->addColumn('longitude', 'decimal', ['precision' => 10,'scale' => 6,'null' => true,'signed' => true,'comment' => '经度',])
+                    ->addColumn('latitude', 'decimal', ['precision' => 10,'scale' => 6,'null' => true,'signed' => true,'comment' => '纬度',])
+                    ->update();
+        }
+      
+    }
+}

+ 22 - 0
catch/hydraulic/model/Hydraulic.php

@@ -59,6 +59,17 @@ class Hydraulic extends Model
         return $res;
     }
      /**
+     * 获取轨迹地图列表定位不分页 只查询有定位时间的
+     */
+    public function queryLocationList()
+    {
+        $res = $this->dataRange()
+                    ->catchSearch()
+                   
+                    ->select();
+        return $res;
+    }
+     /**
      * 获取导入用户(文本)
      */
     public function getCreatorUserAttr($value)
@@ -76,6 +87,17 @@ class Hydraulic extends Model
         return Db::table('departments')->where('id', $id)->value('department_name');
     }
     /**
+     * 获取部门名称(文本)
+     */
+    public function getOnlineTimeAttr($value)
+    {
+       if($value){
+            return date('Y-m-d H:i:s',$value);
+       }else{
+           return '-';
+       }
+    }
+    /**
      * 获取告警状态文本
      */
     public function getAlarmStateTextAttr($value)

+ 4 - 29
catch/map/controller/RouteMap.php

@@ -7,7 +7,8 @@ use catcher\CatchResponse;
 use catcher\base\CatchController;
 use Aliyun\OTS\OTSClient;
 
-use catchAdmin\device\model\Device as deviceModel;
+
+use catchAdmin\hydraulic\model\Hydraulic as deviceModel;
 use catchAdmin\fences\model\Fences as fencesModel;
 use think\facade\Db;
 use think\facade\Env;
@@ -55,25 +56,7 @@ class RouteMap extends CatchController
         // var_dump($list);
         return CatchResponse::success($list);
     }
-    /**
-     * 查询告警列表
-     * @time 2021年05月24日
-     * @return \think\response\Json
-     */
-    public function queryAlarmList(Request $request): \think\Response
-    {
-        $list=$this->deviceModel->queryAlarmList();
-
-
-        foreach($list as &$item){
-            if($item['online_time']<$item['wifi_online_time']){
-                $item['longitude']=$item['wifi_longitude'];
-                $item['latitude']=$item['wifi_latitude'];
-            }
-           
-        }
-        return CatchResponse::paginate($list);
-    }
+    
     /**
      *
      * @time  2021年05月24日
@@ -84,15 +67,7 @@ class RouteMap extends CatchController
         return CatchResponse::success($this->deviceModel->queryLocationList());
     }
     
-    /**
-     *
-     * @time  2021年05月24日
-     * @return \think\response\Json
-     */
-    public function queryAlarmLocationList(Request $request): \think\Response
-    {
-        return CatchResponse::success($this->deviceModel->queryAlarmLocationList());
-    }
+    
     
     
     /**

+ 5 - 0
catch/wind/model/Wind.php

@@ -90,4 +90,9 @@ class Wind extends Model
         $id=$this->department_id;
         return Db::table('departments')->where('id', $id)->value('department_name');
     }
+    public function searchNameAttr($query, $value, $data)
+    {
+        return $query->where('name','like','%'.$value.'%');
+    }
+    
 }