| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880 |
- <?php
- /**
- * Created by PhpStorm.
- * User: qiuzijian
- * Date: 2021-05-18
- * Time: 15:09
- */
- namespace App\Http\Controllers;
- 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 TestsController {
- public function test()
- {
- //宁煤洗选重复摄像头
- //$this->xixuan_repeat();
- //新接入摄像头接口测试
- //$this->new_joggle();
- //乐橙token
- // $this->token();
- //乐橙直播列表
- // $this->list();
- //根据序列号获取直播地址和直播状态
- // $this->address();
- //区域下摄像头接口测试
- // $this->camera_list();
- //区域列表接口测试
- // $this->mine_list();
- //区域下(包含子区域)摄像头接口测试
- // $this->camera_all_list();
- //检查摄像头质量
- // $this->checkCameraQuality();
- //化工人员定位煤制油部门信息录入
- // $this->mzyBmxxInsert();
- //化工人员定位煤制油区域信息录入
- // $this->mzyQyxxInsert();
- //化工人员定位精蜡区域信息录入
- // $this->jlQyxxInsert();
- }
- //区域列表接口测试
- public function mine_list(){
- $result = MineServices::getHaiKangArea(968, CameraEnum::REQUEST_TYPE_LOCAL);
- dd($result);
- }
- //区域下摄像头接口测试
- public function camera_list(){
- $camera = DB::table('mine_list')->where('id',4840)->get();
- $result = CameraServices::getHaiKangCamera(968, $camera[0]->index_code, CameraEnum::CAMERA_TYPE_ALL);
- dd($result);
- //同步区域下摄像头
- if ($result['status']) {
- $trans_arr = [];
- $index_code_arr = [];
- foreach ($result['data'] as $k => $v) {
- $ip = '';
- $port = '';
- $com_number = '';
- //当前摄像头index_code数组
- $index_code_arr[$k] = $v['camera_id'];
- $params = [
- 'mine_id' => $camera[0]->id,
- 'camera_name' => $this->transformCameraName($v['camera_name']),
- 'index_code' => $v['camera_id'],
- 'revert_id' => CameraEnum::CAMERA_DEFAULT_REVERT_ID,
- 'camera_source' => CameraEnum::CAMERA_SOURCE_2,
- 'ip' => $ip,
- 'port' => $port,
- 'com_number' => $com_number,
- ];
- CameraList::updateOrCreate(['index_code' => $v['camera_id']], $params);
- }
- //删除不存在的摄像头
- CameraList::where('mine_id', $camera[0]->id)->where('index_code', '!=', NULL)->whereNotIn('index_code', $index_code_arr)->delete();
- }
- dd('success');
- }
- //检查摄像头质量
- public function checkCameraQuality(){
- $mine_list = DB::table('mine_list')->where('degree','like','968|2308%')->where('deleted_at',null)->pluck('id');
- $camera_list = DB::table('camera_list')->whereIn('mine_id',$mine_list)->where('deleted_at',null)->get();
- $res = [];
- if(count($camera_list) > 0){
- for($i=0;$i<count($camera_list);$i++){
- $result = CameraServices::checkCameraQuality(968, $camera_list[$i]->index_code);
- $res[] = $result;
- }
- }
- dd($res);
- dd('success');
- }
- //区域下摄像头接口测试
- public function camera_all_list(){
- $parent_id = 7004;
- $mine_id = 7004;
- $mine_list = DB::table('mine_list')->where('degree','like',$mine_id.'|%')->get();
- dd($mine_list);
- if(count($mine_list) > 0){
- for($i=0;$i<count($mine_list);$i++){
- $camera = DB::table('mine_list')->where('id',$mine_list[$i]->id)->get();
- $result = CameraServices::getHaiKangCamera($parent_id, $camera[0]->index_code, CameraEnum::CAMERA_TYPE_ALL);
- dd($result);
- //同步区域下摄像头
- if ($result['status']) {
- $trans_arr = [];
- $index_code_arr = [];
- foreach ($result['data'] as $k => $v) {
- $ip = '';
- $port = '';
- $com_number = '';
- //当前摄像头index_code数组
- $index_code_arr[$k] = $v['camera_id'];
- $params = [
- 'mine_id' => $camera[0]->id,
- 'camera_name' => $this->transformCameraName($v['camera_name']),
- 'index_code' => $v['camera_id'],
- 'revert_id' => CameraEnum::CAMERA_DEFAULT_REVERT_ID,
- 'camera_source' => CameraEnum::CAMERA_SOURCE_2,
- 'ip' => $ip,
- 'port' => $port,
- 'com_number' => $com_number,
- ];
- CameraList::updateOrCreate(['index_code' => $v['camera_id']], $params);
- }
- //删除不存在的摄像头
- CameraList::where('mine_id', $camera[0]->id)->where('index_code', '!=', NULL)->whereNotIn('index_code', $index_code_arr)->delete();
- }
- }
- }
- dd('success');
- }
- //转义摄像头名称中的特殊字符
- public function transformCameraName($camera_name)
- {
- $camera_name = trim($camera_name);
- $camera_name = str_replace('#', '号', $camera_name);
- $camera_name = str_replace(' ', '-', $camera_name);
- $camera_name = str_replace('+', '', $camera_name);
- return $camera_name;
- }
- //直播列表
- public function list(){
- // At_0000bd7f06fa796842778d92b50d4d2d
- $url = 'https://openapi.lechange.cn/openapi/liveList';
- //当前的UTC时间戳
- $time= strtotime(date('Y-m-d H:i:s',time()));
- //随机字符串
- $nonce = md5(time());
- //授权信息之appid
- $appId='lc753b03152e3b4f1e';
- //授权信息之appSecret
- $appSecret='cc9b1224acd24571a5daf18e8c7f94';
- //拼接计算“签名原始串”
- $signStr="time:$time,nonce:$nonce,appSecret:$appSecret";
- //计算摘要 sign
- $sign=md5($signStr);
- //业务参数
- $params = [
- 'token'=>'At_0000bd7f06fa796842778d92b50d4d2d',
- 'queryRange'=>"1-99"
- ];
- //组装调用接口的body体内容
- $data = json_encode([
- 'system'=>
- [
- 'ver'=>'1.0',
- 'sign'=>$sign,
- 'appId'=>$appId,
- 'time'=>$time,
- 'nonce'=>$nonce
- ],
- 'params'=>empty($params)? new \stdClass():$params,
- 'id'=>'88'
- ]);
- //http调用
- $ret = $this->curl_post($data, $url);
- $utf8 = iconv('utf-8', 'UTF-8', $ret);
- //调用后返回输出
- // dd(nl2br($utf8));
- $aa = json_decode(nl2br($utf8), true);
- dd($aa['result']['data']);
- }
- //根据序列号获取直播地址和直播状态
- public function address(){
- // At_0000bd7f06fa796842778d92b50d4d2d
- $url = 'https://openapi.lechange.cn/openapi/getLiveStreamInfo';
- //当前的UTC时间戳
- $time= strtotime(date('Y-m-d H:i:s',time()));
- //随机字符串
- $nonce = md5(time());
- //授权信息之appid
- $appId='lc753b03152e3b4f1e';
- //授权信息之appSecret
- $appSecret='cc9b1224acd24571a5daf18e8c7f94';
- //拼接计算“签名原始串”
- $signStr="time:$time,nonce:$nonce,appSecret:$appSecret";
- //计算摘要 sign
- $sign=md5($signStr);
- //业务参数
- $params = [
- 'token'=>'At_0000bd7f06fa796842778d92b50d4d2d',
- 'deviceId'=>'6J0C716PAZ6CF87',
- 'channelId'=>22
- ];
- //组装调用接口的body体内容
- $data = json_encode([
- 'system'=>
- [
- 'ver'=>'1.0',
- 'sign'=>$sign,
- 'appId'=>$appId,
- 'time'=>$time,
- 'nonce'=>$nonce
- ],
- 'params'=>empty($params)? new \stdClass():$params,
- 'id'=>'88'
- ]);
- //http调用
- $ret = $this->curl_post($data, $url);
- $utf8 = iconv('utf-8', 'UTF-8', $ret);
- //调用后返回输出
- dd(nl2br($utf8 ));
- }
- public function token(){
- // At_0000bd7f06fa796842778d92b50d4d2d
- $url = 'https://openapi.lechange.cn:443/openapi/accessToken';
- //当前的UTC时间戳
- $time= strtotime(date('Y-m-d H:i:s',time()));
- //随机字符串
- $nonce = md5(time());
- //授权信息之appid
- $appId='lc753b03152e3b4f1e';
- //授权信息之appSecret
- $appSecret='cc9b1224acd24571a5daf18e8c7f94';
- //拼接计算“签名原始串”
- $signStr="time:$time,nonce:$nonce,appSecret:$appSecret";
- //计算摘要 sign
- $sign=md5($signStr);
- //业务参数
- $params = [];
- //组装调用接口的body体内容
- $data = json_encode([
- 'system'=>
- [
- 'ver'=>'1.0',
- 'sign'=>$sign,
- 'appId'=>$appId,
- 'time'=>$time,
- 'nonce'=>$nonce
- ],
- 'params'=>empty($params)? new \stdClass():$params,
- 'id'=>'88'
- ]);
- //http调用
- $ret = $this->curl_post($data, $url);
- $utf8 = iconv('utf-8', 'UTF-8', $ret);
- //调用后返回输出
- echo 'result:<br>'.nl2br($utf8 ).'<br>';
- }
- function curl_post($data,$url)
- {
- $ch = curl_init();
- $res= curl_setopt ($ch, CURLOPT_URL,$url);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt ($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
- $result = curl_exec ($ch);
- curl_close($ch);
- if ($result == NULL) {
- return 0;
- }
- return $result;
- }
- //新接入摄像头接口测试
- public function new_joggle(){
- $mine_id_list = MineListExt::where('is_hak', 1)->pluck('mine_id')->all();
- // dd($mine_id_list);
- $result = MineServices::getHaiKangArea(4569, CameraEnum::REQUEST_TYPE_LOCAL);//配合修改mineext和haikangcontroller里打印
- dd($result);
- }
- //宁煤洗选重复摄像头
- public function xixuan_repeat(){
- $mine_all = DB::table('mine_list')->where('deleted_at',null)->get();//所有区域
- //宁煤下各矿在离线数量
- $mine_list = DB::table('mine_list')->where('parent_id',968)->where('deleted_at',null)->get();
- $mine_use = [];//宁煤下每个矿所有区域
- foreach($mine_all as $key=>$value){
- if(count(explode('|',$value->degree)) > 1){
- if(explode('|',$value->degree)[0] == 968 && explode('|',$value->degree)[1] == 2429){
- $mine_use[] = $value->id;
- }
- }
- }
- $total = DB::table('camera_list')
- ->select('camera_list.camera_name','camera_list.camera_status','mine_list.title')
- ->leftJoin('mine_list','mine_list.id','=','camera_list.mine_id')
- ->whereIn('camera_list.mine_id',$mine_use)
- ->where('camera_list.deleted_at',null)
- ->where('mine_list.deleted_at',null)
- ->orderBy('mine_list.title')
- ->get();
- // dd($total);
- $aa = [];
- foreach($total as $k=>$v){
- $aa[] = $v->camera_name;
- }
- $unique_arr = array_unique ( $aa );
- // dd($unique_arr);
- $repeat_arr = array_diff_assoc ( $aa, $unique_arr );
- return $repeat_arr;
- }
- //化工人员定位煤制油部门信息录入
- public function mzyBmxxInsert(){
- //获取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/getOrgans?token='.$result['data'];
- $result2 = $this->httpRequest($url);
- if($result2['data'] && count($result2['data']) > 0){
- $list = $result2['data'];
- DB::connection('mysql_fwe10')->table('uf_mzy_bmxx')->where('id','!=',null)->delete();
- // dd($list);
- for($i=0;$i<count($list);$i++){
- $data['id'] = $list[$i]['id'];
- $data['token'] = $list[$i]['token'];
- $data['organName'] = $list[$i]['organName'];
- $data['parentId'] = $list[$i]['parentId'];
- $data['manager'] = $list[$i]['manager'];
- $data['phone'] = $list[$i]['phone'];
- $data['address'] = $list[$i]['address'];
- DB::connection('mysql_fwe10')->table('uf_mzy_bmxx')->insert($data);
- }
- }
- }
- dd('success');
- }
- //化工人员定位煤制油区域信息录入
- 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);
- }
- }
- dd('success');
- }
- //化工人员定位精蜡区域信息录入
- 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);
- }
- }
- dd('success');
- }
-
- public function getDcsApiData() {
- $apiUrl = "http://7.250.4.3:4300/v1/common/GetPointRealDataByPageV3";
-
- $client = new Client();
-
- $r = request()->all();
-
- if(isset($r['p'])) {
- $p = $r['p'];
- $k = $r['k'];
- } else {
- $p = $r;
- }
-
-
- $body = [
- 'headers' => [
- 'Authorization' => 'Bearer appkey_100100',
- 'Content-Type'=>'application/json; charset=utf-8',
- // 其他头部信息
- ],
- 'json' =>[
- 'PageNum'=>"-1",
- "PointIds"=>$p
- ]
- ];
- // 发送 HTTP POST 请求
- $response = $client->post($apiUrl, $body);
-
- // 获取 API 响应的 JSON 数据
- $res = json_decode($response->getBody(), true);
-
- if($res['IsSuccessful'] == 0) {
- return $res;
- }
- $data = isset($res['Data'])? $res['Data']: null;
-
- $transformedData['data']=[];
- for ($i = 0; $i < count($data); $i++) {
- $dic = $data[$i];
- $trans['v'][] = $dic['V'];
- $trans['list'][$i] = [
- 'id'=>$dic['ID'],
- 'nm'=>$dic['PointName'],
- 'v'=>$dic['V'],
- ];
- $trans['kv'][$dic['ID']] = $dic['V'];
- }
-
- if (!empty($k) && isset($trans[$k])) {
- return $trans[$k];
- }
-
- return $trans;
-
- }
-
-
- public function getDcsOpcData() {
-
- // $shell = "echo 'success' ";
- // $shellExec = shell_exec($shell);
- // // var_dump($shellExec);
- // if($shellExec){echo 'ok';} else {echo 'error'}
-
- $pids = [
- "ns=12380;s=九八零变电所80Z004照明回路_Ia",
- "ns=12380;s=九八零变电所5105_IA",
- "ns=12380;s=九八零变电所5101_UB",
- # 添加其他节点地址...
- ];
-
- $pyPath = "/home/python_proj/python_custom_script/zaoquan/dcs/";
- $pyFName = "test1.py";
- $pyKeyWord = "/usr/bin/python311";
-
- $pidsJson = json_encode($pids);
- $command = "$pyKeyWord {$pyPath}{$pyFName}". ' ' . escapeshellarg("{$pidsJson}");
- // $output = shell_exec($command);
- // return shell_exec($command);
-
- try {
- // 调用Python脚本
- $output = shell_exec($command);
-
- // 解析Python脚本返回的JSON数据
- $data = json_decode($output, true);
- // $data['a'] = 'aaa';
- // 返回JSON格式的数据给前端
- header('Content-Type: application/json');
- echo json_encode($data);
- } catch (Exception $e) {
- // 返回错误消息给前端
- header('Content-Type: application/json');
- echo json_encode(array("error" => $e->getMessage()));
- }
- }
- //接口第三方调用
- 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;
- }
- }
|