Forráskód Böngészése

化工人员定位接口同步

任敬轩 5 hónapja
szülő
commit
b82627f199

+ 427 - 0
app/Console/Commands/UpdateHgrydw.php

@@ -0,0 +1,427 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Support\Facades\Config;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Input;
+use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Redis;
+use Modules\Camera\Entities\CameraList;
+use Modules\Camera\Enum\CameraEnum;
+use Modules\Camera\Http\Controllers\Api\HaiKangController;
+use Modules\Camera\Http\Controllers\Api\TdwyController;
+use Modules\Camera\Jobs\CameraDownload;
+use Modules\Camera\Services\CameraServices;
+use Modules\Mine\Entities\MineList;
+use Modules\Mine\Entities\MineListExt;
+use Modules\Mine\Services\MineServices;
+use Modules\Mine\Enum\MineEnum;
+
+use GuzzleHttp\Client;
+
+class UpdateHkList extends Command
+{
+    /**
+     * The name and signature of the console command.
+     *
+     * @var string
+     */
+    protected $signature = 'hgrydw:update';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = '同步化工人员定位接口数据';
+
+    /**
+     * Create a new command instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Execute the console command.
+     *
+     * @return mixed
+     */
+    public function handle()
+    {
+        $start_time = time();
+        echo '开始时间:'.date('Y-m-d H:i:s');
+        $this->mzyQyxxInsert();
+        $this->jlQyxxInsert();
+        echo '时长:'.number_format(((time()-$start_time)/60),2).'分钟';
+    }
+
+    //化工人员定位煤制油区域信息录入
+    public function mzyQyxxInsert(){
+        //获取token
+        $url = 'http://10.186.64.30:8091/chem/api/getToken?username=super&password=meizhiyou';
+
+        $result = $this->httpRequest($url,'post');
+
+        if($result['data']){
+            //获取部门列表
+            $url = 'http://10.186.64.30:8091/chem/api/getAreaInfo?token='.$result['data'];
+
+            $result2 = $this->httpRequest($url);
+            // dd($result2);
+            if($result2['data'] && count($result2['data']) > 0){
+                DB::connection('mysql_fwe10')->table('uf_mzy_total')->delete();
+                DB::connection('mysql_fwe10')->table('uf_mzy_parent_counts')->delete();
+                DB::connection('mysql_fwe10')->table('uf_mzy_counts')->delete();
+                DB::connection('mysql_fwe10')->table('uf_mzy_type')->delete();
+                //uf_mzy_total
+                $total['total'] = $result2['data']['total'];
+                $total['staffNumb'] = $result2['data']['staffNumb'];
+                $total['callerNumb'] = $result2['data']['callerNumb'];
+                $total['carNumb'] = $result2['data']['carNumb'];
+                $total['contractorNumb'] = $result2['data']['contractorNumb'];
+                $total['toolcarNumb'] = $result2['data']['toolcarNumb'];
+                DB::connection('mysql_fwe10')->table('uf_mzy_total')->insert($total);
+
+                $counts_list = $result2['data']['counts'];
+                if(count($counts_list) > 0){
+                    for($i=0;$i<count($counts_list);$i++){
+                        //uf_mzy_parent_counts
+                        $pcounts['organName'] = $counts_list[$i]['organName'];
+                        $pcounts['staffNumb'] = $counts_list[$i]['staffNumb'];
+                        $pcounts['contractorNumb'] = $counts_list[$i]['contractorNumb'];
+                        $pcounts['callerNumb'] = $counts_list[$i]['callerNumb'];
+                        $pcounts['carNumb'] = $counts_list[$i]['carNumb'];
+                        $id = DB::connection('mysql_fwe10')->table('uf_mzy_parent_counts')->insertGetId($pcounts);
+                        if(count($counts_list[$i]['counts']) > 0){
+                            for($j=0;$j<count($counts_list[$i]['counts']);$j++){
+                                //uf_mzy_counts
+                                $counts['parent_id'] = $id;
+                                $counts['fid'] = $counts_list[$i]['counts'][$j]['fid'];
+                                $counts['areaName'] = $counts_list[$i]['counts'][$j]['areaName'];
+                                $counts['staffNumb'] = $counts_list[$i]['counts'][$j]['staffNumb'];
+                                $counts['contractorNumb'] = $counts_list[$i]['counts'][$j]['contractorNumb'];
+                                $counts['callerNumb'] = $counts_list[$i]['counts'][$j]['callerNumb'];
+                                $counts['carNumb'] = $counts_list[$i]['counts'][$j]['carNumb'];
+                                $counts['isSafe'] = $counts_list[$i]['counts'][$j]['isSafe'];
+                                DB::connection('mysql_fwe10')->table('uf_mzy_counts')->insert($counts);
+                                $persons = $counts_list[$i]['counts'][$j]['persons'];
+                                $personContractor = $counts_list[$i]['counts'][$j]['personContractor'];
+                                $personCaller = $counts_list[$i]['counts'][$j]['personCaller'];
+                                $car = $counts_list[$i]['counts'][$j]['car'];
+                                if(count($persons) > 0){
+                                    for($x=0;$x<count($persons);$x++){
+                                        //uf_mzy_type
+                                        $type['deviceId'] = $persons[$x]['deviceId'];
+                                        $type['timestamp'] = $persons[$x]['timestamp'];
+                                        $type['lon'] = $persons[$x]['lon'];
+                                        $type['lat'] = $persons[$x]['lat'];
+                                        $type['fid'] = $persons[$x]['fid'];
+                                        $type['name'] = $persons[$x]['name'];
+                                        $type['weekSel'] = $persons[$x]['weekSel'];
+                                        $type['stime1'] = $persons[$x]['stime1'];
+                                        $type['etime1'] = $persons[$x]['etime1'];
+                                        $type['stime2'] = $persons[$x]['stime2'];
+                                        $type['etime2'] = $persons[$x]['etime2'];
+                                        $type['stime3'] = $persons[$x]['stime3'];
+                                        $type['etime3'] = $persons[$x]['etime3'];
+                                        $type['organId'] = $persons[$x]['organId'];
+                                        $type['work'] = $persons[$x]['work'];
+                                        $type['minMaxCount'] = $persons[$x]['minMaxCount'];
+                                        $type['personOrganId'] = $persons[$x]['personOrganId'];
+                                        $type['inRegion'] = $persons[$x]['inRegion'];
+                                        $type['mode'] = $persons[$x]['mode'];
+                                        $type['type'] = 'persons';
+                                        DB::connection('mysql_fwe10')->table('uf_mzy_type')->insert($type);
+                                    }
+                                }
+                                if(count($personContractor) > 0){
+                                    for($x=0;$x<count($personContractor);$x++){
+                                        //uf_mzy_type
+                                        $type['deviceId'] = $personContractor[$x]['deviceId'];
+                                        $type['timestamp'] = $personContractor[$x]['timestamp'];
+                                        $type['lon'] = $personContractor[$x]['lon'];
+                                        $type['lat'] = $personContractor[$x]['lat'];
+                                        $type['fid'] = $personContractor[$x]['fid'];
+                                        $type['name'] = $personContractor[$x]['name'];
+                                        $type['weekSel'] = $personContractor[$x]['weekSel'];
+                                        $type['stime1'] = $personContractor[$x]['stime1'];
+                                        $type['etime1'] = $personContractor[$x]['etime1'];
+                                        $type['stime2'] = $personContractor[$x]['stime2'];
+                                        $type['etime2'] = $personContractor[$x]['etime2'];
+                                        $type['stime3'] = $personContractor[$x]['stime3'];
+                                        $type['etime3'] = $personContractor[$x]['etime3'];
+                                        $type['organId'] = $personContractor[$x]['organId'];
+                                        $type['work'] = $personContractor[$x]['work'];
+                                        $type['minMaxCount'] = $personContractor[$x]['minMaxCount'];
+                                        $type['personOrganId'] = $personContractor[$x]['personOrganId'];
+                                        $type['inRegion'] = $personContractor[$x]['inRegion'];
+                                        $type['mode'] = $personContractor[$x]['mode'];
+                                        $type['type'] = 'personContractor';
+                                        DB::connection('mysql_fwe10')->table('uf_mzy_type')->insert($type);
+                                    }
+                                }
+                                if(count($personCaller) > 0){
+                                    for($x=0;$x<count($personCaller);$x++){
+                                        //uf_mzy_type
+                                        $type['deviceId'] = $personCaller[$x]['deviceId'];
+                                        $type['timestamp'] = $personCaller[$x]['timestamp'];
+                                        $type['lon'] = $personCaller[$x]['lon'];
+                                        $type['lat'] = $personCaller[$x]['lat'];
+                                        $type['fid'] = $personCaller[$x]['fid'];
+                                        $type['name'] = $personCaller[$x]['name'];
+                                        $type['weekSel'] = $personCaller[$x]['weekSel'];
+                                        $type['stime1'] = $personCaller[$x]['stime1'];
+                                        $type['etime1'] = $personCaller[$x]['etime1'];
+                                        $type['stime2'] = $personCaller[$x]['stime2'];
+                                        $type['etime2'] = $personCaller[$x]['etime2'];
+                                        $type['stime3'] = $personCaller[$x]['stime3'];
+                                        $type['etime3'] = $personCaller[$x]['etime3'];
+                                        $type['organId'] = $personCaller[$x]['organId'];
+                                        $type['work'] = $personCaller[$x]['work'];
+                                        $type['minMaxCount'] = $personCaller[$x]['minMaxCount'];
+                                        $type['personOrganId'] = $personCaller[$x]['personOrganId'];
+                                        $type['inRegion'] = $personCaller[$x]['inRegion'];
+                                        $type['mode'] = $personCaller[$x]['mode'];
+                                        $type['type'] = 'personCaller';
+                                        DB::connection('mysql_fwe10')->table('uf_mzy_type')->insert($type);
+                                    }
+                                }
+                                if(count($car) > 0){
+                                    for($x=0;$x<count($car);$x++){
+                                        //uf_mzy_type
+                                        $type['deviceId'] = $car[$x]['deviceId'];
+                                        $type['timestamp'] = $car[$x]['timestamp'];
+                                        $type['lon'] = $car[$x]['lon'];
+                                        $type['lat'] = $car[$x]['lat'];
+                                        $type['fid'] = $car[$x]['fid'];
+                                        $type['name'] = $car[$x]['name'];
+                                        $type['weekSel'] = $car[$x]['weekSel'];
+                                        $type['stime1'] = $car[$x]['stime1'];
+                                        $type['etime1'] = $car[$x]['etime1'];
+                                        $type['stime2'] = $car[$x]['stime2'];
+                                        $type['etime2'] = $car[$x]['etime2'];
+                                        $type['stime3'] = $car[$x]['stime3'];
+                                        $type['etime3'] = $car[$x]['etime3'];
+                                        $type['organId'] = $car[$x]['organId'];
+                                        $type['work'] = $car[$x]['work'];
+                                        $type['minMaxCount'] = $car[$x]['minMaxCount'];
+                                        $type['personOrganId'] = $car[$x]['personOrganId'];
+                                        $type['inRegion'] = $car[$x]['inRegion'];
+                                        $type['mode'] = $car[$x]['mode'];
+                                        $type['type'] = 'persons';
+                                        DB::connection('mysql_fwe10')->table('uf_mzy_type')->insert($type);
+                                    }
+                                }
+                            }
+                        }
+                        // dd($id);
+                    }
+                }
+
+                // dd(123);
+            }
+        }
+    }
+
+    //化工人员定位精蜡区域信息录入
+    public function jlQyxxInsert(){
+        //获取token
+        $url = 'http://10.186.64.31:8091/chem/api/getToken?username=test&password=123456';
+
+        $result = $this->httpRequest($url,'post');
+
+        if($result['data']){
+            //获取部门列表
+            $url = 'http://10.186.64.31:8091/chem/api/getAreaInfo?token='.$result['data'];
+
+            $result2 = $this->httpRequest($url);
+            // dd($result2);
+            if($result2['data'] && count($result2['data']) > 0){
+                DB::connection('mysql_fwe10')->table('uf_jl_total')->delete();
+                DB::connection('mysql_fwe10')->table('uf_jl_parent_counts')->delete();
+                DB::connection('mysql_fwe10')->table('uf_jl_counts')->delete();
+                DB::connection('mysql_fwe10')->table('uf_jl_type')->delete();
+                //uf_mzy_total
+                $total['total'] = $result2['data']['total'];
+                $total['staffNumb'] = $result2['data']['staffNumb'];
+                $total['callerNumb'] = $result2['data']['callerNumb'];
+                $total['carNumb'] = $result2['data']['carNumb'];
+                $total['contractorNumb'] = $result2['data']['contractorNumb'];
+                $total['toolcarNumb'] = $result2['data']['toolcarNumb'];
+                DB::connection('mysql_fwe10')->table('uf_jl_total')->insert($total);
+
+                $counts_list = $result2['data']['counts'];
+                if(count($counts_list) > 0){
+                    for($i=0;$i<count($counts_list);$i++){
+                        //uf_mzy_parent_counts
+                        $pcounts['organName'] = $counts_list[$i]['organName'];
+                        $pcounts['staffNumb'] = $counts_list[$i]['staffNumb'];
+                        $pcounts['contractorNumb'] = $counts_list[$i]['contractorNumb'];
+                        $pcounts['callerNumb'] = $counts_list[$i]['callerNumb'];
+                        $pcounts['carNumb'] = $counts_list[$i]['carNumb'];
+                        $id = DB::connection('mysql_fwe10')->table('uf_jl_parent_counts')->insertGetId($pcounts);
+                        if(count($counts_list[$i]['counts']) > 0){
+                            for($j=0;$j<count($counts_list[$i]['counts']);$j++){
+                                //uf_mzy_counts
+                                $counts['parent_id'] = $id;
+                                $counts['fid'] = $counts_list[$i]['counts'][$j]['fid'];
+                                $counts['areaName'] = $counts_list[$i]['counts'][$j]['areaName'];
+                                $counts['staffNumb'] = $counts_list[$i]['counts'][$j]['staffNumb'];
+                                $counts['contractorNumb'] = $counts_list[$i]['counts'][$j]['contractorNumb'];
+                                $counts['callerNumb'] = $counts_list[$i]['counts'][$j]['callerNumb'];
+                                $counts['carNumb'] = $counts_list[$i]['counts'][$j]['carNumb'];
+                                $counts['isSafe'] = $counts_list[$i]['counts'][$j]['isSafe'];
+                                DB::connection('mysql_fwe10')->table('uf_jl_counts')->insert($counts);
+                                $persons = $counts_list[$i]['counts'][$j]['persons'];
+                                $personContractor = $counts_list[$i]['counts'][$j]['personContractor'];
+                                $personCaller = $counts_list[$i]['counts'][$j]['personCaller'];
+                                $car = $counts_list[$i]['counts'][$j]['car'];
+                                if(count($persons) > 0){
+                                    for($x=0;$x<count($persons);$x++){
+                                        //uf_mzy_type
+                                        $type['deviceId'] = $persons[$x]['deviceId'];
+                                        $type['timestamp'] = $persons[$x]['timestamp'];
+                                        $type['lon'] = $persons[$x]['lon'];
+                                        $type['lat'] = $persons[$x]['lat'];
+                                        $type['fid'] = $persons[$x]['fid'];
+                                        $type['name'] = $persons[$x]['name'];
+                                        $type['weekSel'] = $persons[$x]['weekSel'];
+                                        $type['stime1'] = $persons[$x]['stime1'];
+                                        $type['etime1'] = $persons[$x]['etime1'];
+                                        $type['stime2'] = $persons[$x]['stime2'];
+                                        $type['etime2'] = $persons[$x]['etime2'];
+                                        $type['stime3'] = $persons[$x]['stime3'];
+                                        $type['etime3'] = $persons[$x]['etime3'];
+                                        $type['organId'] = $persons[$x]['organId'];
+                                        $type['work'] = $persons[$x]['work'];
+                                        $type['minMaxCount'] = $persons[$x]['minMaxCount'];
+                                        $type['personOrganId'] = $persons[$x]['personOrganId'];
+                                        $type['inRegion'] = $persons[$x]['inRegion'];
+                                        $type['mode'] = $persons[$x]['mode'];
+                                        $type['type'] = 'persons';
+                                        DB::connection('mysql_fwe10')->table('uf_jl_type')->insert($type);
+                                    }
+                                }
+                                if(count($personContractor) > 0){
+                                    for($x=0;$x<count($personContractor);$x++){
+                                        //uf_mzy_type
+                                        $type['deviceId'] = $personContractor[$x]['deviceId'];
+                                        $type['timestamp'] = $personContractor[$x]['timestamp'];
+                                        $type['lon'] = $personContractor[$x]['lon'];
+                                        $type['lat'] = $personContractor[$x]['lat'];
+                                        $type['fid'] = $personContractor[$x]['fid'];
+                                        $type['name'] = $personContractor[$x]['name'];
+                                        $type['weekSel'] = $personContractor[$x]['weekSel'];
+                                        $type['stime1'] = $personContractor[$x]['stime1'];
+                                        $type['etime1'] = $personContractor[$x]['etime1'];
+                                        $type['stime2'] = $personContractor[$x]['stime2'];
+                                        $type['etime2'] = $personContractor[$x]['etime2'];
+                                        $type['stime3'] = $personContractor[$x]['stime3'];
+                                        $type['etime3'] = $personContractor[$x]['etime3'];
+                                        $type['organId'] = $personContractor[$x]['organId'];
+                                        $type['work'] = $personContractor[$x]['work'];
+                                        $type['minMaxCount'] = $personContractor[$x]['minMaxCount'];
+                                        $type['personOrganId'] = $personContractor[$x]['personOrganId'];
+                                        $type['inRegion'] = $personContractor[$x]['inRegion'];
+                                        $type['mode'] = $personContractor[$x]['mode'];
+                                        $type['type'] = 'personContractor';
+                                        DB::connection('mysql_fwe10')->table('uf_jl_type')->insert($type);
+                                    }
+                                }
+                                if(count($personCaller) > 0){
+                                    for($x=0;$x<count($personCaller);$x++){
+                                        //uf_mzy_type
+                                        $type['deviceId'] = $personCaller[$x]['deviceId'];
+                                        $type['timestamp'] = $personCaller[$x]['timestamp'];
+                                        $type['lon'] = $personCaller[$x]['lon'];
+                                        $type['lat'] = $personCaller[$x]['lat'];
+                                        $type['fid'] = $personCaller[$x]['fid'];
+                                        $type['name'] = $personCaller[$x]['name'];
+                                        $type['weekSel'] = $personCaller[$x]['weekSel'];
+                                        $type['stime1'] = $personCaller[$x]['stime1'];
+                                        $type['etime1'] = $personCaller[$x]['etime1'];
+                                        $type['stime2'] = $personCaller[$x]['stime2'];
+                                        $type['etime2'] = $personCaller[$x]['etime2'];
+                                        $type['stime3'] = $personCaller[$x]['stime3'];
+                                        $type['etime3'] = $personCaller[$x]['etime3'];
+                                        $type['organId'] = $personCaller[$x]['organId'];
+                                        $type['work'] = $personCaller[$x]['work'];
+                                        $type['minMaxCount'] = $personCaller[$x]['minMaxCount'];
+                                        $type['personOrganId'] = $personCaller[$x]['personOrganId'];
+                                        $type['inRegion'] = $personCaller[$x]['inRegion'];
+                                        $type['mode'] = $personCaller[$x]['mode'];
+                                        $type['type'] = 'personCaller';
+                                        DB::connection('mysql_fwe10')->table('uf_jl_type')->insert($type);
+                                    }
+                                }
+                                if(count($car) > 0){
+                                    for($x=0;$x<count($car);$x++){
+                                        //uf_mzy_type
+                                        $type['deviceId'] = $car[$x]['deviceId'];
+                                        $type['timestamp'] = $car[$x]['timestamp'];
+                                        $type['lon'] = $car[$x]['lon'];
+                                        $type['lat'] = $car[$x]['lat'];
+                                        $type['fid'] = $car[$x]['fid'];
+                                        $type['name'] = $car[$x]['name'];
+                                        $type['weekSel'] = $car[$x]['weekSel'];
+                                        $type['stime1'] = $car[$x]['stime1'];
+                                        $type['etime1'] = $car[$x]['etime1'];
+                                        $type['stime2'] = $car[$x]['stime2'];
+                                        $type['etime2'] = $car[$x]['etime2'];
+                                        $type['stime3'] = $car[$x]['stime3'];
+                                        $type['etime3'] = $car[$x]['etime3'];
+                                        $type['organId'] = $car[$x]['organId'];
+                                        $type['work'] = $car[$x]['work'];
+                                        $type['minMaxCount'] = $car[$x]['minMaxCount'];
+                                        $type['personOrganId'] = $car[$x]['personOrganId'];
+                                        $type['inRegion'] = $car[$x]['inRegion'];
+                                        $type['mode'] = $car[$x]['mode'];
+                                        $type['type'] = 'persons';
+                                        DB::connection('mysql_fwe10')->table('uf_jl_type')->insert($type);
+                                    }
+                                }
+                            }
+                        }
+                        // dd($id);
+                    }
+                }
+
+                // dd(123);
+            }
+        }
+    }
+
+    //接口第三方调用
+    public function httpRequest($url, $format = 'get', $data = null, $token = null){
+        //设置头信息
+        $headerArray =array("Content-type:application/json;","Accept:application/json");
+
+        if ($token) {
+            $headerArray[] = "Authorization:bearer " . $token;
+        }
+
+        $curl=curl_init();
+        curl_setopt($curl, CURLOPT_URL, $url);
+        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
+        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
+        if ($format == 'post') {
+            //post传值设置post传参
+            curl_setopt($curl, CURLOPT_POST, 1);
+            if ($data) {
+                $data = json_encode($data);
+                curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
+            }
+        }
+        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+        curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray);
+        $data=json_decode(curl_exec($curl), true);
+        curl_close($curl);
+        //返回接口返回数据
+        return $data;
+    }
+}

+ 8 - 0
app/Http/Controllers/TestsController.php

@@ -419,6 +419,10 @@ class TestsController {
             $result2 = $this->httpRequest($url);
             // dd($result2);
             if($result2['data'] && count($result2['data']) > 0){
+                DB::connection('mysql_fwe10')->table('uf_mzy_total')->delete();
+                DB::connection('mysql_fwe10')->table('uf_mzy_parent_counts')->delete();
+                DB::connection('mysql_fwe10')->table('uf_mzy_counts')->delete();
+                DB::connection('mysql_fwe10')->table('uf_mzy_type')->delete();
                 //uf_mzy_total
                 $total['total'] = $result2['data']['total'];
                 $total['staffNumb'] = $result2['data']['staffNumb'];
@@ -585,6 +589,10 @@ class TestsController {
             $result2 = $this->httpRequest($url);
             // dd($result2);
             if($result2['data'] && count($result2['data']) > 0){
+                DB::connection('mysql_fwe10')->table('uf_jl_total')->delete();
+                DB::connection('mysql_fwe10')->table('uf_jl_parent_counts')->delete();
+                DB::connection('mysql_fwe10')->table('uf_jl_counts')->delete();
+                DB::connection('mysql_fwe10')->table('uf_jl_type')->delete();
                 //uf_mzy_total
                 $total['total'] = $result2['data']['total'];
                 $total['staffNumb'] = $result2['data']['staffNumb'];