tongshanglei 2 lat temu
rodzic
commit
408918c3e6

+ 15 - 1
app/common.php

@@ -1273,7 +1273,7 @@ use PDO;
         $username=    Env::get('oracle.username',  'root');
         $password=    Env::get('oracle.password',  'root');
         // $conn = oci_connect('用户名', '密码', '远程数据库名(eg.//192.168.1.133/orcl)');
-        $conn = oci_connect('dssc3', 'dssc3', '61.175.203.188:6521/DSSC','AL32UTF8');
+        $conn = oci_connect($username, $password, $host.':'.$port.'/'. $instance_name,'AL32UTF8');
 
         if (!$conn) {
             $e = oci_error();
@@ -1435,4 +1435,18 @@ use PDO;
         return $whereStr;
     }
 
+    function getOracleConnect(){
+        $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 = oci_connect($username, $password, $host.':'.$port.'/'. $instance_name,'AL32UTF8');
+        if (!$conn) {
+            $e = oci_error();
+            trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
+        }
+        return $conn;
+    }
+
 

+ 163 - 8
catch/device/controller/Station.php

@@ -7,22 +7,25 @@ use catcher\CatchResponse;
 use catcher\base\CatchController;
 
 // use catchAdmin\device\model\RfRecord as rfRecordModel;
+// use catchAdmin\device\model\Station as stationModel;
 // use catchAdmin\device\model\StationPhoto;
-// use catcher\Utils;
-// use catcher\library\excel\Excel;
-// use PhpOffice\PhpSpreadsheet\IOFactory;
-
+use catcher\Utils;
+use catcher\library\excel\Excel;
+use PhpOffice\PhpSpreadsheet\IOFactory;
+use think\facade\Env;
 use think\facade\Db;
 use PDO;
+
 class Station extends CatchController
 {
     // protected $stationModel;
     // protected $rfRecordModel;
     
-    // public function __construct(rfRecordModel $rfRecordModel)
+    // public function __construct(rfRecordModel $rfRecordModel,stationModel $stationModel)
     // {
 
     //     $this->rfRecordModel = $rfRecordModel;
+    //     $this->stationModel = $stationModel;
     // }
     
     /**
@@ -58,7 +61,7 @@ class Station extends CatchController
 
             $cond['page']=isset($param['page'])?$param['page']:1;
             $cond['limit']=isset($param['limit'])?$param['limit']:10;
-            $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');
+            $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.CREATE_DATE,\'yyyy-mm-dd hh24:mi:ss\') CREATE_DATE');
             
             
             foreach($rows as &$val){
@@ -86,10 +89,93 @@ class Station extends CatchController
             return $response;
        
     }
+     /**
+     * 保存信息
+     * @time 2022年01月20日 10:55
+     * @param Request $request 
+     */
+    public function save(Request $request) 
+    {
+        $params=$request->param();
+        $params['LOGIN_NAME']=strtoupper($params['LOGIN_NAME']);
+        $r=$this->execSaveStation($params);
+        return CatchResponse::success($r);
+    }
     
-    public function getdeviceListByStation(Request $request){
-       
+
+    private function execSaveStation($data){
+        $conn=getOracleConnect();
+        $sql='select DEVICE_CODE from "DSSC2"."ADM_DEV" where DEVICE_CODE in (select max(DEVICE_CODE) from "DSSC2"."ADM_DEV")';
+        $stid = oci_parse($conn, $sql);
+        $r = oci_execute($stid);
+        $result = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS);
+
+        $deivce_code=$result['DEVICE_CODE']+1;
+        
+        $time=date('Y-m-d H:i:s');
+        //插入基站信息表
+        $sql='INSERT INTO "DSSC2"."ADM_DEV"("ID", "DEVICE_CODE","DEVICE_NAME", "DEVICE_CATEGORY", "DEVICE_TYPE","OWNER_CODE","LOGIN_TYPE","LOGIN_NAME","IS_ONLINE","CREATE_DATE","UPDATE_DATE") 
+                VALUES(DSSC2.SEQ_ADM_DEV.nextval,\''.$deivce_code.'\',\''.$data['DEVICE_NAME'].'\',32,\'13\',\'001\',\'6\',\''.$data['LOGIN_NAME'].'\',0,TO_DATE(\''.$time.'\', \'SYYYY-MM-DD HH24:MI:SS\'),TO_DATE(\''.$time.'\', \'SYYYY-MM-DD HH24:MI:SS\'))';
+        $stid = oci_parse($conn, $sql);
+        $r = oci_execute($stid);
+        
+         //插入基站信息表
+        $sql='INSERT INTO "DSSC2"."ADM_DEV_RFID_CHN"("ID", "DEVICE_CODE","CHANNEL_NAME", "STAT" ,"GPS_X","GPS_Y","TYPE") 
+        VALUES(DSSC2.SEQ_ADM_DEV_RFID_CHN.nextval,\''.$deivce_code.'\',\''.$data['DEVICE_NAME'].'\',1,\''.$data['longitude'].'\',\''.$data['latitude'].'\',1)';
+        $stid = oci_parse($conn, $sql);
+        $r = oci_execute($stid);
+        oci_free_statement($stid);
+        return $r;
+    }
+    /**
+     * 更新
+     * @time 2022年01月20日 10:55
+     * @param Request $request 
+     * @param $id
+     */
+    public function update(Request $request, $id) 
+    {
+        $params=$request->param();
+        $params['LOGIN_NAME']=strtoupper($params['LOGIN_NAME']);
+
+        //UPDATE DSSC2.ADM_DEV A SET A.DEVICE_NAME = '1014测试插入4' WHERE A.DEVICE_CODE = '79933';
+        //UPDATE DSSC2.ADM_DEV_RFID_CHN A SET  A.CHANNEL_NAME = '1014测试插入4' WHERE A.DEVICE_CODE ='79933';
+        $conn=getOracleConnect();
+        //更新
+        $sql='UPDATE DSSC2.ADM_DEV  SET DEVICE_NAME = \''.$params['DEVICE_NAME'].'\',LOGIN_NAME=\''.$params['LOGIN_NAME'].'\' WHERE DEVICE_CODE = \''.$id.'\' ';
+        $stid = oci_parse($conn, $sql);
+        $r = oci_execute($stid);
+        
+        $sql='UPDATE DSSC2.ADM_DEV_RFID_CHN  SET CHANNEL_NAME = \''.$params['DEVICE_NAME'].'\',GPS_X='.$params['longitude'].',GPS_Y='.$params['latitude'].' WHERE DEVICE_CODE = \''.$id.'\' ';
+        $stid2 = oci_parse($conn, $sql);
+        $r2 = oci_execute($stid2);
+        
+        return CatchResponse::success('修改成功');
+    }
+    
+    /**
+     * 删除
+     * @time 2022年01月20日 10:55
+     * @param $id
+     */
+    public function delete($id) : \think\Response
+    {
+
+        // $ids=Utils::stringToArrayBy($id);
+
+        $conn=getOracleConnect();
+        $sql='DELETE FROM DSSC2.ADM_DEV WHERE DEVICE_CODE in ('.$id.')';
       
+        $stid = oci_parse($conn, $sql);
+        $r = oci_execute($stid);
+
+        $sql='DELETE FROM DSSC2.ADM_DEV_RFID_CHN WHERE DEVICE_CODE in ('.$id.')';
+        $stid = oci_parse($conn, $sql);
+        $r = oci_execute($stid);
+        return CatchResponse::success($r);
+    }
+
+    public function getdeviceListByStation(Request $request){
 
         $params=$request->param();
         if(!$params['station_code']){
@@ -155,5 +241,74 @@ class Station extends CatchController
         // return CatchResponse::paginate($list);
    
     }
+
    
+    
+    /**
+     * 导入设备
+     *
+     * @time 2022年02月15日
+     * @param Excel $excel
+     * @param DeviceExport $deviceExport
+     * @throws \PhpOffice\PhpSpreadsheet\Exception
+     * @return \think\response\Json
+     */
+    public function importStation(Request $request)
+    {
+        $url = $request->post('url');
+        if (!$url) {
+            return CatchResponse::fail('请上传文件');
+        }
+        
+        $creator_id = $request->post('creator_id');
+        //解析地址
+        $parse_url = parse_url($url)['path'];
+        //载入excel表格 
+        $objPHPExcel = IOFactory::load(public_path() . $parse_url);
+        //获取表名,一维数组,值是表名。如:array('sheet1', 'sheet2', 'sheet3')
+        // $nameArr = $objPHPExcel->getSheetNames();
+        //获取表的数量
+        $sheetCount = $objPHPExcel->getSheetCount();
+        $fail = 0; //失败条数
+        $success = 0; //成功条数
+        $total = 0; //总共设备数
+        $data = []; //设备数据
+        //循环读取每一张表
+        for ($index = 0; $index < $sheetCount; $index++) {
+            //设置当前要读取的表
+            $sheet = $objPHPExcel->getSheet($index);   //excel中的第一张sheet
+            // var_dump($sheet);exit;
+            $highestRow  = $sheet->getHighestRow();       // 取得总行数
+            // var_dump($highestRow);
+            if ($highestRow <= 1) {
+                continue;
+            }
+            $total += $highestRow - 1;
+            for ($j = 2; $j <= $highestRow; $j++) {
+                $arr = array(); //每条设备信息
+                $arr['LOGIN_NAME'] = strtoupper(trim($sheet->getCell("A" . $j)->getFormattedValue())); 
+                $arr['longitude'] = trim($sheet->getCell("B" . $j)->getFormattedValue());  
+                $arr['latitude'] = trim($sheet->getCell("C" . $j)->getFormattedValue());  
+                $arr['DEVICE_NAME'] = trim($sheet->getCell("D" . $j)->getFormattedValue());  
+                
+                $r=$this->execSaveStation($arr);
+                if($r){
+                    $success++;
+                }else{
+                    $fail++;
+                }
+                // var_dump($arr);
+            //    array_push($data,$arr);
+            }
+        }
+        // array_unique($data, SORT_REGULAR);
+        // // var_dump($data);return CatchResponse::success();
+        // $count = $this->deviceModel->limit(100)->insertAll($data);
+        // if ($success = $count) {
+
+            return CatchResponse::success('共' . $total . '条数据,成功' . $success . '条,失败' . $fail . '条');
+
+        // }
+        // return CatchResponse::success(['error' => true, 'msg' => '导入失败']);
+    }
 }

+ 3 - 3
catch/device/route.php

@@ -15,7 +15,8 @@ $router->group(function () use ($router) {
 	$router->resource('device', '\catchAdmin\device\controller\Device');
 	// station路由
 	$router->get('station/getdeviceListByStation','\catchAdmin\device\controller\Station@getdeviceListByStation');
-
+	//导入基站
+	$router->post('station/importStation', '\catchAdmin\device\controller\Station@importStation');
 	$router->resource('station', '\catchAdmin\device\controller\Station');
 	// station_photo路由
 	$router->resource('station_photo', '\catchAdmin\device\controller\StationPhoto');
@@ -34,7 +35,6 @@ $router->group(function () use ($router) {
 	$router->post('station/export_station','\catchAdmin\device\controller\Station@export_station');
 	//导入设备
 	$router->post('import_device', '\catchAdmin\device\controller\Device@import_device');
-	//导入基站
-	$router->post('import_station', '\catchAdmin\device\controller\Station@import_station');
+	
 	
 })->middleware('auth');

+ 75 - 1
catch/report/controller/Report.php

@@ -6,7 +6,7 @@ use catcher\base\CatchRequest as Request;
 use catcher\CatchResponse;
 use catcher\base\CatchController;
 use catchAdmin\report\model\Report as ReportModel;
-
+use think\facade\Env;
 class Report extends CatchController
 {
 
@@ -56,4 +56,78 @@ class Report extends CatchController
         
         return CatchResponse::success($data);
     }
+
+    /**
+     * 过车总量统计
+     * @param Request $request 
+     */
+    public function vehiclePassingCount(Request $request){
+        $params=$request->param();
+        $start_time=strtotime($params['timeRange'][0]);
+        $end_time=strtotime($params['timeRange'][1]);
+        $xAxisData=[];
+        $yAxisData=[];
+        for($i=$start_time;$i<$end_time+24*3600;$i+=24*3600){
+            $time1=date('Y-m-d 00:00:00',$i);
+            $time2=date('Y-m-d 23:59:59',$i);
+            $xAxisData[]=date('Y-m-d',$i);
+            $cond['RF_DATE']=['timeRange',$time1,$time2];
+            // $count=queryOracleCount('DSSC2.W_DW_RF_RECORD',$cond);
+            $count=mt_rand(0,99999);
+            $yAxisData[]=$count;
+     
+        }   
+        
+        // var_dump($end_time);
+        return CatchResponse::success(['xAxisData'=>$xAxisData,'yAxisData'=>$yAxisData]);
+    }
+    
+    /**
+     * 区域过车统计
+     * @param Request $request 
+     */
+    public function areaDeviceCollect(Request $request){
+
+        $params=$request->param();
+        $start_time=date('Y-m-d 00:00:00',strtotime($params['timeRange'][0]));
+        $end_time=date('Y-m-d 00:00:00',strtotime($params['timeRange'][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 = oci_connect('dssc3', 'dssc3', '61.175.203.188:6521/DSSC','AL32UTF8');
+
+    //     if (!$conn) {
+    //         $e = oci_error();
+    //         trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
+    //     }
+
+    //    $sql='SELECT a.RF_ID,count(a.RF_FLAGID) num,b.DEVICE_NAME FROM DSSC2.W_DW_RF_RECORD a join DSSC2.ADM_DEV b ON a.RF_ID=b.LOGIN_NAME  WHERE  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\')  GROUP BY a.RF_ID,b.DEVICE_NAME ORDER BY num desc';
+    //     // var_dump($sql);
+    //     // 查询并渲染
+    //     $stid = oci_parse($conn, $sql);
+    //     $r = oci_execute($stid);
+    //     $rows=[];
+    //     while($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
+    //         $rows[]=$row;
+    //     }
+    //     oci_free_statement($stid);
+        $xAxisData=[];
+        $yAxisData=[];
+    //     foreach($rows as $val){
+    //         $xAxisData[]=$val['DEVICE_NAME'];
+    //         $yAxisData[]=$val['NUM'];
+    //     }
+        for($i=0;$i<800;$i++){
+            $xAxisData[]='测试基站'.$i;
+            $yAxisData[]=mt_rand(0,99999);
+        }
+      
+        // return $rows;
+        return CatchResponse::success(['xAxisData'=>$xAxisData,'yAxisData'=>$yAxisData]);
+    }
 }

+ 2 - 0
catch/report/route.php

@@ -15,4 +15,6 @@ $router->group('total', function () use ($router){
     $router->get('getStationGrowthTrendData','\catchAdmin\report\controller\Report@stationGrowthTrendData'); // 获取设备增长趋势数据
     $router->get('getDeviceGrowthTrendData','\catchAdmin\report\controller\Report@deviceGrowthTrendData'); // 获取设备增长趋势数据
 })->middleware('auth');
+$router->get('report/areaDeviceCollect','\catchAdmin\report\controller\Report@areaDeviceCollect'); // 获取区域过车统计
+$router->get('report/vehiclePassingCount','\catchAdmin\report\controller\Report@vehiclePassingCount'); // 过车总量统计