tongshanglei 2 vuotta sitten
vanhempi
commit
dcde639794

+ 40 - 10
app/common.php

@@ -1281,22 +1281,20 @@ use PDO;
         }
         $start=($cond['page']-1)*$cond['limit'];
         $end=$cond['page']*$cond['limit'];
-        $whereStr=buildQueryCond($cond);
-        $sql = 'SELECT * FROM ( SELECT '.$field.',ROWNUM RN FROM (SELECT * FROM '.$tableName.' '.$whereStr.' ORDER BY ID DESC) a WHERE ROWNUM <='.$end.' ) WHERE RN >='. $start;
-         // var_dump($sql);
+        $whereStr=buildQueryCond2($cond);
+        // $sql = 'SELECT * FROM ( SELECT '.$field.',ROWNUM RN FROM (SELECT * FROM '.$tableName.' '.$whereStr.' ORDER BY ID DESC) a WHERE ROWNUM <='.$end.' ) WHERE RN >='. $start;
+        $sql='SELECT * FROM ( SELECT '.$field.',ROWNUM RN FROM '.$tableName.' WHERE ROWNUM <='.$end.' '.$whereStr.'  ) WHERE RN >='. $start;
+        // var_dump($sql);
         // 查询并渲染
         $stid = oci_parse($conn, $sql);
-         // var_dump($stid);
         $r = oci_execute($stid);
-        // var_dump($r);
-        // $rows=[];
+        $rows=[];
         while($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
 
             $rows[]=$row;
         }
-        // var_dump($rows);
         oci_free_statement($stid);
-
+        return $rows;
         // $conn = new PDO("oci:dbname=//".$host.":".$port."/".$instance_name,$username,$password);// PDO方式
         // $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        
@@ -1314,7 +1312,7 @@ use PDO;
         //     $conn = null;
         // }
         // $rows=[];
-        return $rows;
+        
     }
     /**
      * 查询oracle数据库 count
@@ -1368,6 +1366,7 @@ use PDO;
         $whereStr=buildQueryCond($cond);
         $countQuery='SELECT count(*) as count FROM  '.$tableName.' '.$whereStr;
         // var_dump($countQuery);
+        // return 1111;
         $countRes= $conn -> query($countQuery)->fetch(PDO::FETCH_ASSOC);
 
         if ($conn){
@@ -1375,12 +1374,21 @@ use PDO;
         }
         return (int)$countRes['COUNT'];
     }
+    
     function buildQueryCond($cond){
         $whereStr='';
         foreach($cond as $key=>$val){
             
             if( $key!='page' && $key!='limit' && $val[1]!=''){
-               
+                if($key=='_string'){
+                    if($whereStr==''){
+                        $whereStr .='WHERE '.$val;
+                    }else{
+                        $whereStr .=' AND '.$val;
+                    }
+                   
+                    continue;
+                }
                 if($val[0]=='like'){
                     if($whereStr==''){
                         $whereStr .='WHERE '.$key.' '.$val[0].' \'%'.$val[1].'%\'';
@@ -1405,4 +1413,26 @@ use PDO;
         return $whereStr;
     }
 
+    function buildQueryCond2($cond){
+        $whereStr='';
+        foreach($cond as $key=>$val){
+            
+            if( $key!='page' && $key!='limit' && $val[1]!=''){
+                if($key=='_string'){
+                    $whereStr .=' AND '.$val;
+                    continue;
+                }
+                if($val[0]=='like'){
+                    $whereStr .=' AND '.$key.' '.$val[0].' \'%'.$val[1].'%\'';
+                }else if($val[0]=='timeRange'){
+                    $whereStr .=' AND '.$key.' >= to_date(\''.$val[1].'\', \'yyyy-mm-dd hh24:mi:ss\') AND '.$key.' <= to_date(\''.$val[2].'\', \'yyyy-mm-dd hh24:mi:ss\')';
+                }else{
+                    $whereStr .=' AND '.$key.' '.$val[0].' \''.$val[1].'\'';
+   
+                }
+            }
+        }
+        return $whereStr;
+    }
+
 

+ 5 - 4
catch/device/controller/Station.php

@@ -48,17 +48,17 @@ class Station extends CatchController
             // var_dump($param);
             $cond=[];
             if($param['shortcode']){
-                $cond['DEVICE_CODE']=['like',$param['shortcode']];
+                $cond['a.DEVICE_CODE']=['like',$param['shortcode']];
             }
             if($param['name']){
                 // $param['name'] = mb_convert_encoding($param['name'],  'GBK','UTF-8');
-                $cond['DEVICE_NAME']=['like',$param['name']];
+                $cond['a.DEVICE_NAME']=['like',$param['name']];
             }
             $count=queryOracleCount('DSSC2.ADM_DEV',$cond);
 
             $cond['page']=isset($param['page'])?$param['page']:1;
             $cond['limit']=isset($param['limit'])?$param['limit']:10;
-            $rows=queryOracleSelect('DSSC2.ADM_DEV',$cond,'a.ID,a.IS_ONLINE,a.LOGIN_NAME,a.DEVICE_CODE,a.DEVICE_NAME,a.OWNER_CODE,a.DEVICE_IP,a.DEVICE_PORT,to_char(a.UPDATE_DATE,\'yyyy-mm-dd hh24:mi:ss\') UPDATE_DATE');
+            $rows=queryOracleSelect('(SELECT * FROM DSSC2.ADM_DEV  ORDER BY ID DESC) a',$cond,'a.ID,a.IS_ONLINE,a.LOGIN_NAME,a.DEVICE_CODE,a.DEVICE_NAME,a.OWNER_CODE,a.DEVICE_IP,a.DEVICE_PORT,to_char(a.UPDATE_DATE,\'yyyy-mm-dd hh24:mi:ss\') UPDATE_DATE');
             
             
             foreach($rows as &$val){
@@ -111,7 +111,8 @@ class Station extends CatchController
 
         $cond['page']=isset($param['page'])?$param['page']:1;
         $cond['limit']=isset($param['limit'])?$param['limit']:10;
-        $rows=queryOracleSelect('DSSC2.W_DW_RF_RECORD',$cond,'a.RF_FLAGID,a.RF_STAT,to_char(a.RF_DATE,\'yyyy-mm-dd hh24:mi:ss\') RF_DATE');
+        
+        $rows=queryOracleSelect('(SELECT * FROM DSSC2.W_DW_RF_RECORD  ORDER BY ID DESC) a',$cond,'a.RF_FLAGID,a.RF_STAT,to_char(a.RF_DATE,\'yyyy-mm-dd hh24:mi:ss\') RF_DATE');
         foreach($rows as &$val){
             //状态: 0- 未知,1 - 进入,2 - 离开
             if($val['RF_STAT']==1){

+ 51 - 0
catch/yunying/controller/Vehicle.php

@@ -32,6 +32,57 @@ class Vehicle extends CatchController
         return CatchResponse::paginate($this->vehicleModel->getVehicleList($field,$order));
     }
     
+    public function getVehicleListOracle(Request $request) 
+    {
+
+        $param=$request->param();
+        //联表条件o.rfid_id = s.id and o.owner_id = r.id 
+        $cond=[
+            '_string'=>'o.rfid_id = s.id and o.owner_id = r.id ',
+        ];
+        if($param['PLATE_NO']){
+            $cond['o.PLATE_NO']=['like',$param['PLATE_NO']];
+        }
+        if($param['ID_CARD_NUMBER']){
+            $cond['r.ID_CARD_NUMBER']=['like',$param['ID_CARD_NUMBER']];
+        }
+        if($param['MOBILE_NUMBER']){
+            $cond['r.MOBILE_NUMBER']=['like',$param['MOBILE_NUMBER']];
+        }
+        if($param['RFID_SN']){
+            $cond['s.RFID_SN']=['like',$param['RFID_SN']];
+        }
+
+        $count=queryOracleCount('DSSC3.W_DW_NON_MOTOR o,DSSC3.W_DW_NON_MOTOR_OWNER r,DSSC3.W_DW_RFID_TAGS s',$cond);
+
+        $cond['page']=isset($param['page'])?$param['page']:1;
+        $cond['limit']=isset($param['limit'])?$param['limit']:10;
+        $rows=queryOracleSelect('DSSC3.W_DW_NON_MOTOR o,DSSC3.W_DW_NON_MOTOR_OWNER r,DSSC3.W_DW_RFID_TAGS s',$cond,'o.PLATE_NO,s.RFID_SN,r. NAME,r.ID_CARD_NUMBER,r.MOBILE_NUMBER,r.HOME_ADDRESS');
+        
+        // foreach($rows as &$val){
+        //     // $val['DEVICE_NAME'] = mb_convert_encoding($val['DEVICE_NAME'], 'UTF-8', 'GBK');
+        //     $val['IS_ONLINE_TEXT']=$val['IS_ONLINE']?'在线':'离线';
+        //     // $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'];
+           
+        // }
+        
+        $response=[
+            'code'=>10000,
+            'message'=>'查询成功',
+            'count'=>$count,
+            'data'=>$rows,
+            'current'=>isset($param['page'])?(int)$param['page']:1,
+            'limit'=>isset($param['limit'])?(int)$param['limit']:10,
+        ];
+        return $response;
+    }
     /**
      * 保存信息
      * @time 2022年01月20日 10:42

+ 2 - 0
catch/yunying/route.php

@@ -12,7 +12,9 @@
 // you should use `$router`
 $router->group(function () use ($router){
 	// vehicle路由
+	$router->get('vehicle/getVehicleList','\catchAdmin\yunying\controller\Vehicle@getVehicleListOracle');
 	$router->resource('vehicle', '\catchAdmin\yunying\controller\Vehicle');
+	
 	// 导出车辆
 	$router->post('export_vehicle', '\catchAdmin\yunying\controller\Vehicle@export_vehicle');
 	// vehicle_photo路由