tongshanglei %!s(int64=2) %!d(string=hai) anos
pai
achega
b22d133bef

+ 87 - 27
app/common.php

@@ -6,6 +6,7 @@ use Aliyun\OTS\Consts\OperationTypeConst;
 use Aliyun\OTS\Consts\PrimaryKeyTypeConst;
 use Aliyun\OTS\Consts\RowExistenceExpectationConst;
 use Aliyun\OTS\OTSClient;
+use PDO;
     /**
      * 查询Gps股轨迹 表格存储
      */
@@ -1254,11 +1255,12 @@ use Aliyun\OTS\OTSClient;
 
 
     /**
-     * 查询oracle数据库
+     * 查询oracle数据库 select
      * @time 2021年05月18日 10:15
      * @param Request $request 
      */
     function queryOracleSelect($tableName,$cond){
+        $conn = null;
         if(!isset($cond['page'])){
             $cond['page']=1;
         }
@@ -1273,43 +1275,101 @@ use Aliyun\OTS\OTSClient;
            
         $conn = new PDO("oci:dbname=//".$host.":".$port."/".$instance_name,$username,$password);// PDO方式
         $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
-        // $conn->query("set names utf8");
+       
         $start=($cond['page']-1)*$cond['limit'];
         $end=$cond['page']*$cond['limit'];
-        $countQuery='SELECT count(*) as count FROM  '.$tableName;
-        $countRes= $conn -> query($countQuery)->fetch(PDO::FETCH_ASSOC);
-
-        $sql = 'SELECT * FROM (SELECT a.*, ROWNUM rn FROM '.$tableName.' a)   WHERE rn >= '. $start.' AND rn <= '.$end;
 
+        $whereStr=buildQueryCond($cond);
+        
+        $sql = 'SELECT * FROM ( SELECT a.*, ROWNUM RN FROM (SELECT * FROM '.$tableName.' '.$whereStr.' ORDER BY ID DESC) a WHERE ROWNUM <='.$end.' ) WHERE RN >='. $start;
         $res = $conn -> query($sql);
-        // var_dump($res);
         $rows = $res -> fetchAll(PDO::FETCH_ASSOC);
-        $res=[
-            'count'=>(int)$countRes['COUNT'],
-            'data'=>$rows,
-            'current'=>$cond['page'],
-            'limit'=>$cond['limit'],
-        ];
         if ($conn){
             $conn = null;
         }
-        return $res;
+        // $rows=[];
+        return $rows;
     }
-    function ascii_decode($sacii)
-
-    {
-
-        $asc = str_split(strtolower($sacii), 2);
-        // var_dump($asc);
-        $str ='';
-
-        for ($i = 0; $i < count($asc); $i++) {
+    /**
+     * 查询oracle数据库 count
+     * @time 2021年05月18日 10:15
+     * @param Request $request 
+     */
+    function queryOracleFind($tableName,$cond){
+        $conn = null;
+        if(!$cond){
+            return [];
+        }
+        $host=    Env::get('oracle.hostname',  '127.0.0.1');
+        $port=    Env::get('oracle.hostport',  '1521');
+        $instance_name=    Env::get('oracle.instance',  'ORCL');
+        $username=    Env::get('oracle.username',  'root');
+        $password=    Env::get('oracle.password',  'root');
+           
+        $conn = new PDO("oci:dbname=//".$host.":".$port."/".$instance_name,$username,$password);// PDO方式
+        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+       
 
-            $str.= chr(hexdec($asc[$i][0].$asc[$i][1]));
+        $sql='SELECT *  FROM  '.$tableName.' WHERE ';
+        foreach($cond as $key=>$val){
+            $sql .=$key.' '.$val[0].' '.$val[1];
+        }
+        
+        $res= $conn -> query($sql)->fetch(PDO::FETCH_ASSOC);
+        if ($conn){
+            $conn = null;
+        }
+        // $response=[];
+        return $res;
+    }
+    /**
+     * 查询oracle数据库 count
+     * @time 2021年05月18日 10:15
+     * @param Request $request 
+     */
+    function queryOracleCount($tableName,$cond){
+        $conn = null;
+        $host=    Env::get('oracle.hostname',  '127.0.0.1');
+        $port=    Env::get('oracle.hostport',  '1521');
+        $instance_name=    Env::get('oracle.instance',  'ORCL');
+        $username=    Env::get('oracle.username',  'root');
+        $password=    Env::get('oracle.password',  'root');
+        
+        $conn = new PDO("oci:dbname=//".$host.":".$port."/".$instance_name,$username,$password);// PDO方式
+        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+       
+        $whereStr=buildQueryCond($cond);
+        $countQuery='SELECT count(*) as count FROM  '.$tableName.' '.$whereStr;
+        $countRes= $conn -> query($countQuery)->fetch(PDO::FETCH_ASSOC);
 
+        if ($conn){
+            $conn = null;
+        }
+        // $response=[];
+        return (int)$countRes['COUNT'];
+    }
+    function buildQueryCond($cond){
+        $whereStr='';
+        foreach($cond as $key=>$val){
+            
+            if( $key!='page' && $key!='limit' && $val[1]!=''){
+               
+                if($val[0]=='like'){
+                    if($whereStr==''){
+                        $whereStr .='WHERE '.$key.' '.$val[0].' \'%'.$val[1].'%\'';
+                    }else{
+                        $whereStr .=' AND '.$key.' '.$val[0].' \'%'.$val[1].'%\'';
+                    }
+                }else{
+                    if($whereStr==''){
+                        $whereStr .='WHERE '.$key.' '.$val[0].' \''.$val[1].'\'';
+                    }else{
+                        $whereStr .=' AND '.$key.' '.$val[0].' \''.$val[1].'\'';
+                    }
+                }
+            }
         }
+        return $whereStr;
+    }
 
-        return $str;
-        return mb_convert_encoding($str, 'UTF-8', 'GBK');
 
-    }

+ 37 - 19
catch/device/controller/Station.php

@@ -32,27 +32,45 @@ class Station extends CatchController
         // header('Content-Type: text/html; charset=utf-8');
         // header('Content-Type: text/html; charset=gb2312');
             $param=$request->param();
-            $rows=queryOracleSelect('ADM_DEV',$param);
-            foreach($rows['data'] as &$val){
-                $val['UPDATE_DATE']=date("Y-m-d",strtotime($val['UPDATE_DATE']));
-                // echo mb_detect_encoding($val['DEVICE_NAME'],array('ASCII','GB2312','GBK','UTF-8'));
-                // echo mb_convert_encoding($val['DEVICE_NAME'], 'ASCII', 'GBK');
-                // echo ascii_decode($val['DEVICE_NAME']);
-                // $current_encode = mb_detect_encoding($val['DEVICE_NAME'], array("GBK","GB2312",'BIG5','UTF-8',"ASCII")); 
-                // echo $current_encode;
-                // $encoded_str = mb_convert_encoding($val['DEVICE_NAME'], 'UTF-8', $current_encode);
+            // var_dump($param);
+            $cond=[];
+            if($param['shortcode']){
+                $cond['DEVICE_CODE']=['like',$param['shortcode']];
+            }
+            if($param['name']){
+                $param['name'] = mb_convert_encoding($param['name'],  'GBK','UTF-8');
+                $cond['DEVICE_NAME']=['like',$param['name']];
+            }
+            $count=queryOracleCount('DSSC2.ADM_DEV',$cond);
 
-                echo mb_convert_encoding($val['DEVICE_NAME'], "UTF-8", "auto");
-                echo mb_convert_encoding($val['DEVICE_NAME'], "GBK", "auto");
-                echo mb_convert_encoding($val['DEVICE_NAME'], "GB2312", "auto");
-                echo mb_convert_encoding($val['DEVICE_NAME'], "BIG5", "auto");
-                echo mb_convert_encoding($val['DEVICE_NAME'], "ASCII", "auto");
-                // echo $encoded_str;
-                // echo ascii_decode($val['DEVICE_NAME']);
+            $cond['page']=isset($param['page'])?$param['page']:1;
+            $cond['limit']=isset($param['limit'])?$param['limit']:10;
+            $rows=queryOracleSelect('DSSC2.ADM_DEV',$cond);
+            
+            
+            foreach($rows as &$val){
+                $val['DEVICE_NAME'] = mb_convert_encoding($val['DEVICE_NAME'], 'UTF-8', 'GBK');
+                $val['UPDATE_DATE'] = mb_convert_encoding($val['UPDATE_DATE'], 'UTF-8', 'GBK');
+                $val['CREATE_DATE'] = mb_convert_encoding($val['CREATE_DATE'], 'UTF-8', 'GBK');
+                $findCond=[
+                    'DEVICE_CODE'=>['=',$val['DEVICE_CODE']]
+                ];
+                $info=queryOracleFind('DSSC2.ADM_DEV_RFID_CHN',$findCond);
+                $val['longitude']=$info['GPS_X'];
+                $val['latitude']=$info['GPS_Y'];
+               
             }
-            $rows['code']=10000;
-            $rows['message']='查询成功';
-            return $rows;
+            
+            $response=[
+                'count'=>$count,
+                'data'=>$rows,
+                'current'=>isset($param['page'])?(int)$param['page']:1,
+                'limit'=>isset($param['limit'])?(int)$param['limit']:10,
+            ];
+           
+            $response['code']=10000;
+            $response['message']='查询成功';
+            return $response;
         // $field = $request->get('field')?:'id';
         // $order = $request->get('order')?:'desc';
         // return CatchResponse::paginate($this->stationModel->getStationList($field,$order));

+ 2 - 2
catch/device/model/Station.php

@@ -9,9 +9,9 @@ class Station extends Model
 {
     use DataRangScopeTrait;
     use StationGet;
-    protected $connection = 'oracle';
+    // protected $connection = 'oracle';
     // 表名
-    public $name = 'ADM_DEV';
+    public $name = 'stations';
     // 数据库字段映射
     public $field = array(
         'id',

+ 54 - 0
catch/map/controller/RouteMap.php

@@ -11,6 +11,7 @@ use catchAdmin\device\model\Device as deviceModel;
 use catchAdmin\fences\model\Fences as fencesModel;
 use think\facade\Db;
 use think\facade\Env;
+use PDO;
 class RouteMap extends CatchController
 {
     protected $deviceModel;
@@ -533,4 +534,57 @@ class RouteMap extends CatchController
         }
         return $response_data;
     }
+    /**
+     * 查询设备轨迹
+     * @time 2022年09月18日 10:15
+     * 
+     */
+    public function queryDeviceRouteOracle(Request $request) : \think\Response
+    {
+      
+        $params=$request->param();
+
+        $device_number = $params['device_number'];
+       
+        if (!$device_number) {
+            return CatchResponse::fail("获取设备号失败");
+        }
+        $start_time = date('Y-m-d 00:00:00',time());
+        $end_time = date('Y-m-d 23:59:59',time());
+
+        if(isset($params['time_range']) && $params['time_range'] != ''){
+            $start_time=date('Y-m-d H:i:s',strtotime($params['time_range'][0]));
+            $end_time=date('Y-m-d H:i:s',strtotime($params['time_range'][1]));
+        }
+
+
+        $host=    Env::get('oracle.hostname',  '127.0.0.1');
+        $port=    Env::get('oracle.hostport',  '1521');
+        $instance_name=    Env::get('oracle.instance',  'ORCL');
+        $username=    Env::get('oracle.username',  'root');
+        $password=    Env::get('oracle.password',  'root');
+        
+        $conn = new PDO("oci:dbname=//".$host.":".$port."/".$instance_name,$username,$password);// PDO方式
+        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
+        // $sql='SELECT * FROM (SELECT a.*, ROWNUM rn FROM DSS2.W_DW_RF_RECORD a WHERE RF_FLAGID=\''.$device_number.'\' AND RF_DATE >= to_date(\''. $start_time.'\', \'yyyy-mm-dd hh24:mi:ss\') AND RF_DATE <= to_date(\''.$end_time.'\', \'yyyy-mm-dd hh24:mi:ss\')   ORDER BY RF_DATE DESC)   WHERE  ROWNUM <= 5000';
+        $sql='SELECT * FROM (SELECT a.*,ROWNUM rn,b.DEVICE_NAME,b.DEVICE_CODE,b.LOGIN_NAME,c.GPS_X,c.GPS_Y FROM DSSC2.W_DW_RF_RECORD a join DSSC2.ADM_DEV b ON a.RF_ID=b.LOGIN_NAME join DSSC2.ADM_DEV_RFID_CHN c ON b.DEVICE_CODE=c.DEVICE_CODE WHERE  RF_FLAGID=\''.$device_number.'\' AND RF_DATE >= to_date(\''. $start_time.'\', \'yyyy-mm-dd hh24:mi:ss\') AND RF_DATE <= to_date(\''.$end_time.'\', \'yyyy-mm-dd hh24:mi:ss\')   ORDER BY RF_DATE DESC)   WHERE  ROWNUM <= 5000';
+        $res = $conn -> query($sql);
+       
+        $rows = $res -> fetchAll(PDO::FETCH_ASSOC);
+        foreach($rows as &$val){
+            $val['DEVICE_NAME'] = mb_convert_encoding($val['DEVICE_NAME'], 'UTF-8', 'GBK');
+            $val['RF_DATE'] = mb_convert_encoding($val['RF_DATE'], 'UTF-8', 'GBK');
+            $wgsLoc = \algorithm\Geometry::wgsTOgcj($val['GPS_Y'],$val['GPS_X']);
+            $lngLat = \algorithm\Geometry::convertGcj02ToBd09($wgsLoc['lat'],$wgsLoc['lng']);
+            $val['GPS_X']=$lngLat['lng'];
+            $val['GPS_Y']=$lngLat['lat'];
+            // $val['timeInt']=strtotime($val['RF_DATE']);
+        }
+        if ($conn){
+            $conn = null;
+        }
+        return CatchResponse::success($rows);
+        
+    }
 }

+ 2 - 1
catch/map/route.php

@@ -23,6 +23,7 @@ $router->group(function () use ($router){
 	$router->get('map/queryAlarmLocationList', '\catchAdmin\map\controller\RouteMap@queryAlarmLocationList');
 	$router->get('map/queryFenceList', '\catchAdmin\map\controller\RouteMap@queryFenceList');
 	$router->get('map/queryDeviceRoute', '\catchAdmin\map\controller\RouteMap@queryDeviceRoute');
+	$router->get('map/queryDeviceRouteOracle', '\catchAdmin\map\controller\RouteMap@queryDeviceRouteOracle');
 	
 
 
@@ -30,4 +31,4 @@ $router->group(function () use ($router){
 	
 	
 })->middleware('auth');
-$router->post('map/queryAlarmFenceList', '\catchAdmin\map\controller\RouteMap@queryAlarmFenceList');
+$router->post('map/queryAlarmFenceList', '\catchAdmin\map\controller\RouteMap@queryAlarmFenceList');

+ 76 - 0
extend/algorithm/Geometry.php

@@ -52,6 +52,82 @@ class Geometry
         return array('lng'=>$lng,'lat'=>$lat);
     }
 
+    /**
+     * wgs84坐标转国测局坐标
+     * @param double $lat 纬度
+     * @param double $lng 经度
+     */
+    public static function wgsTOgcj($lat, $lng)
+    {
+        $pi = 3.14159265358979324;
+        $a = 6378245.0;
+        $ee = 0.00669342162296594323;
+        $wgLat = $lat;
+        $wgLon = $lng;
+        if (self::outOfChina($wgLat, $wgLon)){
+            return array('lat'=>$wgLat, 'lng'=>$wgLon);
+        }
+        $dLat = self::wgsTOgcjTransformLat($wgLon - 105.0, $wgLat - 35.0);
+        $dLon = self::wgsTOgcjTransformLon($wgLon - 105.0, $wgLat - 35.0);
+        $radLat = $wgLat / 180.0 * $pi;
+        $magic = sin($radLat);
+        $magic = 1 - $ee * $magic * $magic;
+        $sqrtMagic = sqrt($magic);
+        $dLat = ($dLat * 180.0) / (($a * (1 - $ee)) / ($magic * $sqrtMagic) * $pi);
+        $dLon = ($dLon * 180.0) / ($a / $sqrtMagic * cos($radLat) * $pi);
+
+        $mgLat = $wgLat + $dLat;
+        $mgLon = $wgLon + $dLon;
+
+        return array('lat'=>$mgLat, 'lng'=>$mgLon);
+    }
+
+    /**
+     * 经纬度是否超出中国范围
+     * @param double $lat 纬度
+     * @param double $lng 经度
+     */
+    public static function outOfChina($lat, $lng)
+    {
+        if ($lng < 72.004 || $lng > 137.8347)
+            return true;
+        if ($lat < 0.8293 || $lat > 55.8271)
+            return true;
+
+        return false;
+    }
+    
+     
+  
+    
+    /**
+     * wgsTOgcj转换纬度
+     * @param double $lat 纬度
+     * @param double $lng 经度
+     */
+    private static function wgsTOgcjTransformLat( $x, $y ){
+        $pi = 3.14159265358979324;
+        $ret = -100.0 + 2.0 * $x + 3.0 * $y + 0.2 * $y * $y + 0.1 * $x * $y + 0.2 * sqrt(abs($x));
+        $ret += (20.0 * sin(6.0 * $x * $pi) + 20.0 * sin(2.0 * $x * $pi)) * 2.0 / 3.0;
+        $ret += (20.0 * sin($y * $pi) + 40.0 * sin($y / 3.0 * $pi)) * 2.0 / 3.0;
+        $ret += (160.0 * sin($y / 12.0 * $pi) + 320 * sin($y * $pi / 30.0)) * 2.0 / 3.0;
+        return $ret;
+    }
+
+    /**
+     * wgsTOgcj转换经度
+     * @param double $lat 纬度
+     * @param double $lng 经度
+     */
+    private static function wgsTOgcjTransformLon( $x, $y ){
+        $pi = 3.14159265358979324;
+        $ret = 300.0 + $x + 2.0 * $y + 0.1 * $x * $x + 0.1 * $x * $y + 0.1 * sqrt(abs($x));
+        $ret += (20.0 * sin(6.0 * $x * $pi) + 20.0 * sin(2.0 * $x * $pi)) * 2.0 / 3.0;
+        $ret += (20.0 * sin($x * $pi) + 40.0 * sin($x / 3.0 * $pi)) * 2.0 / 3.0;
+        $ret += (150.0 * sin($x / 12.0 * $pi) + 300.0 * sin($x / 30.0 * $pi)) * 2.0 / 3.0;
+        return $ret;
+    }
+
      /**
      * 获取百度2点间距离(单位:km)
      * @param  $point1 坐标1