TestsController.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: qiuzijian
  5. * Date: 2021-05-18
  6. * Time: 15:09
  7. */
  8. namespace App\Http\Controllers;
  9. use Illuminate\Support\Facades\Config;
  10. use Illuminate\Support\Facades\DB;
  11. use Illuminate\Support\Facades\Input;
  12. use Illuminate\Support\Facades\Log;
  13. use Illuminate\Support\Facades\Redis;
  14. use Modules\Camera\Entities\CameraList;
  15. use Modules\Camera\Enum\CameraEnum;
  16. use Modules\Camera\Http\Controllers\Api\HaiKangController;
  17. use Modules\Camera\Http\Controllers\Api\TdwyController;
  18. use Modules\Camera\Jobs\CameraDownload;
  19. use Modules\Camera\Services\CameraServices;
  20. use Modules\Mine\Entities\MineList;
  21. use Modules\Mine\Entities\MineListExt;
  22. use Modules\Mine\Services\MineServices;
  23. use Modules\Mine\Enum\MineEnum;
  24. use GuzzleHttp\Client;
  25. class TestsController {
  26. public function test()
  27. {
  28. //宁煤洗选重复摄像头
  29. //$this->xixuan_repeat();
  30. //新接入摄像头接口测试
  31. //$this->new_joggle();
  32. //乐橙token
  33. // $this->token();
  34. //乐橙直播列表
  35. // $this->list();
  36. //根据序列号获取直播地址和直播状态
  37. // $this->address();
  38. //区域下摄像头接口测试
  39. // $this->camera_list();
  40. //区域列表接口测试
  41. // $this->mine_list();
  42. //区域下(包含子区域)摄像头接口测试
  43. // $this->camera_all_list();
  44. //检查摄像头质量
  45. // $this->checkCameraQuality();
  46. //化工人员定位煤制油部门信息录入
  47. // $this->mzyBmxxInsert();
  48. //化工人员定位煤制油区域信息录入
  49. // $this->mzyQyxxInsert();
  50. //化工人员定位精蜡区域信息录入
  51. // $this->jlQyxxInsert();
  52. }
  53. //区域列表接口测试
  54. public function mine_list(){
  55. $result = MineServices::getHaiKangArea(968, CameraEnum::REQUEST_TYPE_LOCAL);
  56. dd($result);
  57. }
  58. //区域下摄像头接口测试
  59. public function camera_list(){
  60. $camera = DB::table('mine_list')->where('id',4840)->get();
  61. $result = CameraServices::getHaiKangCamera(968, $camera[0]->index_code, CameraEnum::CAMERA_TYPE_ALL);
  62. dd($result);
  63. //同步区域下摄像头
  64. if ($result['status']) {
  65. $trans_arr = [];
  66. $index_code_arr = [];
  67. foreach ($result['data'] as $k => $v) {
  68. $ip = '';
  69. $port = '';
  70. $com_number = '';
  71. //当前摄像头index_code数组
  72. $index_code_arr[$k] = $v['camera_id'];
  73. $params = [
  74. 'mine_id' => $camera[0]->id,
  75. 'camera_name' => $this->transformCameraName($v['camera_name']),
  76. 'index_code' => $v['camera_id'],
  77. 'revert_id' => CameraEnum::CAMERA_DEFAULT_REVERT_ID,
  78. 'camera_source' => CameraEnum::CAMERA_SOURCE_2,
  79. 'ip' => $ip,
  80. 'port' => $port,
  81. 'com_number' => $com_number,
  82. ];
  83. CameraList::updateOrCreate(['index_code' => $v['camera_id']], $params);
  84. }
  85. //删除不存在的摄像头
  86. CameraList::where('mine_id', $camera[0]->id)->where('index_code', '!=', NULL)->whereNotIn('index_code', $index_code_arr)->delete();
  87. }
  88. dd('success');
  89. }
  90. //检查摄像头质量
  91. public function checkCameraQuality(){
  92. $mine_list = DB::table('mine_list')->where('degree','like','968|2308%')->where('deleted_at',null)->pluck('id');
  93. $camera_list = DB::table('camera_list')->whereIn('mine_id',$mine_list)->where('deleted_at',null)->get();
  94. $res = [];
  95. if(count($camera_list) > 0){
  96. for($i=0;$i<count($camera_list);$i++){
  97. $result = CameraServices::checkCameraQuality(968, $camera_list[$i]->index_code);
  98. $res[] = $result;
  99. }
  100. }
  101. dd($res);
  102. dd('success');
  103. }
  104. //区域下摄像头接口测试
  105. public function camera_all_list(){
  106. $parent_id = 7004;
  107. $mine_id = 7004;
  108. $mine_list = DB::table('mine_list')->where('degree','like',$mine_id.'|%')->get();
  109. dd($mine_list);
  110. if(count($mine_list) > 0){
  111. for($i=0;$i<count($mine_list);$i++){
  112. $camera = DB::table('mine_list')->where('id',$mine_list[$i]->id)->get();
  113. $result = CameraServices::getHaiKangCamera($parent_id, $camera[0]->index_code, CameraEnum::CAMERA_TYPE_ALL);
  114. dd($result);
  115. //同步区域下摄像头
  116. if ($result['status']) {
  117. $trans_arr = [];
  118. $index_code_arr = [];
  119. foreach ($result['data'] as $k => $v) {
  120. $ip = '';
  121. $port = '';
  122. $com_number = '';
  123. //当前摄像头index_code数组
  124. $index_code_arr[$k] = $v['camera_id'];
  125. $params = [
  126. 'mine_id' => $camera[0]->id,
  127. 'camera_name' => $this->transformCameraName($v['camera_name']),
  128. 'index_code' => $v['camera_id'],
  129. 'revert_id' => CameraEnum::CAMERA_DEFAULT_REVERT_ID,
  130. 'camera_source' => CameraEnum::CAMERA_SOURCE_2,
  131. 'ip' => $ip,
  132. 'port' => $port,
  133. 'com_number' => $com_number,
  134. ];
  135. CameraList::updateOrCreate(['index_code' => $v['camera_id']], $params);
  136. }
  137. //删除不存在的摄像头
  138. CameraList::where('mine_id', $camera[0]->id)->where('index_code', '!=', NULL)->whereNotIn('index_code', $index_code_arr)->delete();
  139. }
  140. }
  141. }
  142. dd('success');
  143. }
  144. //转义摄像头名称中的特殊字符
  145. public function transformCameraName($camera_name)
  146. {
  147. $camera_name = trim($camera_name);
  148. $camera_name = str_replace('#', '号', $camera_name);
  149. $camera_name = str_replace(' ', '-', $camera_name);
  150. $camera_name = str_replace('+', '', $camera_name);
  151. return $camera_name;
  152. }
  153. //直播列表
  154. public function list(){
  155. // At_0000bd7f06fa796842778d92b50d4d2d
  156. $url = 'https://openapi.lechange.cn/openapi/liveList';
  157. //当前的UTC时间戳
  158. $time= strtotime(date('Y-m-d H:i:s',time()));
  159. //随机字符串
  160. $nonce = md5(time());
  161. //授权信息之appid
  162. $appId='lc753b03152e3b4f1e';
  163. //授权信息之appSecret
  164. $appSecret='cc9b1224acd24571a5daf18e8c7f94';
  165. //拼接计算“签名原始串”
  166. $signStr="time:$time,nonce:$nonce,appSecret:$appSecret";
  167. //计算摘要 sign
  168. $sign=md5($signStr);
  169. //业务参数
  170. $params = [
  171. 'token'=>'At_0000bd7f06fa796842778d92b50d4d2d',
  172. 'queryRange'=>"1-99"
  173. ];
  174. //组装调用接口的body体内容
  175. $data = json_encode([
  176. 'system'=>
  177. [
  178. 'ver'=>'1.0',
  179. 'sign'=>$sign,
  180. 'appId'=>$appId,
  181. 'time'=>$time,
  182. 'nonce'=>$nonce
  183. ],
  184. 'params'=>empty($params)? new \stdClass():$params,
  185. 'id'=>'88'
  186. ]);
  187. //http调用
  188. $ret = $this->curl_post($data, $url);
  189. $utf8 = iconv('utf-8', 'UTF-8', $ret);
  190. //调用后返回输出
  191. // dd(nl2br($utf8));
  192. $aa = json_decode(nl2br($utf8), true);
  193. dd($aa['result']['data']);
  194. }
  195. //根据序列号获取直播地址和直播状态
  196. public function address(){
  197. // At_0000bd7f06fa796842778d92b50d4d2d
  198. $url = 'https://openapi.lechange.cn/openapi/getLiveStreamInfo';
  199. //当前的UTC时间戳
  200. $time= strtotime(date('Y-m-d H:i:s',time()));
  201. //随机字符串
  202. $nonce = md5(time());
  203. //授权信息之appid
  204. $appId='lc753b03152e3b4f1e';
  205. //授权信息之appSecret
  206. $appSecret='cc9b1224acd24571a5daf18e8c7f94';
  207. //拼接计算“签名原始串”
  208. $signStr="time:$time,nonce:$nonce,appSecret:$appSecret";
  209. //计算摘要 sign
  210. $sign=md5($signStr);
  211. //业务参数
  212. $params = [
  213. 'token'=>'At_0000bd7f06fa796842778d92b50d4d2d',
  214. 'deviceId'=>'6J0C716PAZ6CF87',
  215. 'channelId'=>22
  216. ];
  217. //组装调用接口的body体内容
  218. $data = json_encode([
  219. 'system'=>
  220. [
  221. 'ver'=>'1.0',
  222. 'sign'=>$sign,
  223. 'appId'=>$appId,
  224. 'time'=>$time,
  225. 'nonce'=>$nonce
  226. ],
  227. 'params'=>empty($params)? new \stdClass():$params,
  228. 'id'=>'88'
  229. ]);
  230. //http调用
  231. $ret = $this->curl_post($data, $url);
  232. $utf8 = iconv('utf-8', 'UTF-8', $ret);
  233. //调用后返回输出
  234. dd(nl2br($utf8 ));
  235. }
  236. public function token(){
  237. // At_0000bd7f06fa796842778d92b50d4d2d
  238. $url = 'https://openapi.lechange.cn:443/openapi/accessToken';
  239. //当前的UTC时间戳
  240. $time= strtotime(date('Y-m-d H:i:s',time()));
  241. //随机字符串
  242. $nonce = md5(time());
  243. //授权信息之appid
  244. $appId='lc753b03152e3b4f1e';
  245. //授权信息之appSecret
  246. $appSecret='cc9b1224acd24571a5daf18e8c7f94';
  247. //拼接计算“签名原始串”
  248. $signStr="time:$time,nonce:$nonce,appSecret:$appSecret";
  249. //计算摘要 sign
  250. $sign=md5($signStr);
  251. //业务参数
  252. $params = [];
  253. //组装调用接口的body体内容
  254. $data = json_encode([
  255. 'system'=>
  256. [
  257. 'ver'=>'1.0',
  258. 'sign'=>$sign,
  259. 'appId'=>$appId,
  260. 'time'=>$time,
  261. 'nonce'=>$nonce
  262. ],
  263. 'params'=>empty($params)? new \stdClass():$params,
  264. 'id'=>'88'
  265. ]);
  266. //http调用
  267. $ret = $this->curl_post($data, $url);
  268. $utf8 = iconv('utf-8', 'UTF-8', $ret);
  269. //调用后返回输出
  270. echo 'result:<br>'.nl2br($utf8 ).'<br>';
  271. }
  272. function curl_post($data,$url)
  273. {
  274. $ch = curl_init();
  275. $res= curl_setopt ($ch, CURLOPT_URL,$url);
  276. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  277. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  278. curl_setopt ($ch, CURLOPT_HEADER, 0);
  279. curl_setopt($ch, CURLOPT_POST, 1);
  280. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  281. curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  282. $result = curl_exec ($ch);
  283. curl_close($ch);
  284. if ($result == NULL) {
  285. return 0;
  286. }
  287. return $result;
  288. }
  289. //新接入摄像头接口测试
  290. public function new_joggle(){
  291. $mine_id_list = MineListExt::where('is_hak', 1)->pluck('mine_id')->all();
  292. // dd($mine_id_list);
  293. $result = MineServices::getHaiKangArea(4569, CameraEnum::REQUEST_TYPE_LOCAL);//配合修改mineext和haikangcontroller里打印
  294. dd($result);
  295. }
  296. //宁煤洗选重复摄像头
  297. public function xixuan_repeat(){
  298. $mine_all = DB::table('mine_list')->where('deleted_at',null)->get();//所有区域
  299. //宁煤下各矿在离线数量
  300. $mine_list = DB::table('mine_list')->where('parent_id',968)->where('deleted_at',null)->get();
  301. $mine_use = [];//宁煤下每个矿所有区域
  302. foreach($mine_all as $key=>$value){
  303. if(count(explode('|',$value->degree)) > 1){
  304. if(explode('|',$value->degree)[0] == 968 && explode('|',$value->degree)[1] == 2429){
  305. $mine_use[] = $value->id;
  306. }
  307. }
  308. }
  309. $total = DB::table('camera_list')
  310. ->select('camera_list.camera_name','camera_list.camera_status','mine_list.title')
  311. ->leftJoin('mine_list','mine_list.id','=','camera_list.mine_id')
  312. ->whereIn('camera_list.mine_id',$mine_use)
  313. ->where('camera_list.deleted_at',null)
  314. ->where('mine_list.deleted_at',null)
  315. ->orderBy('mine_list.title')
  316. ->get();
  317. // dd($total);
  318. $aa = [];
  319. foreach($total as $k=>$v){
  320. $aa[] = $v->camera_name;
  321. }
  322. $unique_arr = array_unique ( $aa );
  323. // dd($unique_arr);
  324. $repeat_arr = array_diff_assoc ( $aa, $unique_arr );
  325. return $repeat_arr;
  326. }
  327. //化工人员定位煤制油部门信息录入
  328. public function mzyBmxxInsert(){
  329. //获取token
  330. $url = 'http://10.186.64.30:8091/chem/api/getToken?username=super&password=meizhiyou';
  331. $result = $this->httpRequest($url,'post');
  332. if($result['data']){
  333. //获取部门列表
  334. $url = 'http://10.186.64.30:8091/chem/api/getOrgans?token='.$result['data'];
  335. $result2 = $this->httpRequest($url);
  336. if($result2['data'] && count($result2['data']) > 0){
  337. $list = $result2['data'];
  338. DB::connection('mysql_fwe10')->table('uf_mzy_bmxx')->where('id','!=',null)->delete();
  339. // dd($list);
  340. for($i=0;$i<count($list);$i++){
  341. $data['id'] = $list[$i]['id'];
  342. $data['token'] = $list[$i]['token'];
  343. $data['organName'] = $list[$i]['organName'];
  344. $data['parentId'] = $list[$i]['parentId'];
  345. $data['manager'] = $list[$i]['manager'];
  346. $data['phone'] = $list[$i]['phone'];
  347. $data['address'] = $list[$i]['address'];
  348. DB::connection('mysql_fwe10')->table('uf_mzy_bmxx')->insert($data);
  349. }
  350. }
  351. }
  352. dd('success');
  353. }
  354. //化工人员定位煤制油区域信息录入
  355. public function mzyQyxxInsert(){
  356. //获取token
  357. $url = 'http://10.186.64.30:8091/chem/api/getToken?username=super&password=meizhiyou';
  358. $result = $this->httpRequest($url,'post');
  359. if($result['data']){
  360. //获取部门列表
  361. $url = 'http://10.186.64.30:8091/chem/api/getAreaInfo?token='.$result['data'];
  362. $result2 = $this->httpRequest($url);
  363. // dd($result2);
  364. if($result2['data'] && count($result2['data']) > 0){
  365. //uf_mzy_total
  366. $total['total'] = $result2['data']['total'];
  367. $total['staffNumb'] = $result2['data']['staffNumb'];
  368. $total['callerNumb'] = $result2['data']['callerNumb'];
  369. $total['carNumb'] = $result2['data']['carNumb'];
  370. $total['contractorNumb'] = $result2['data']['contractorNumb'];
  371. $total['toolcarNumb'] = $result2['data']['toolcarNumb'];
  372. DB::connection('mysql_fwe10')->table('uf_mzy_total')->insert($total);
  373. $counts_list = $result2['data']['counts'];
  374. if(count($counts_list) > 0){
  375. for($i=0;$i<count($counts_list);$i++){
  376. //uf_mzy_parent_counts
  377. $pcounts['organName'] = $counts_list[$i]['organName'];
  378. $pcounts['staffNumb'] = $counts_list[$i]['staffNumb'];
  379. $pcounts['contractorNumb'] = $counts_list[$i]['contractorNumb'];
  380. $pcounts['callerNumb'] = $counts_list[$i]['callerNumb'];
  381. $pcounts['carNumb'] = $counts_list[$i]['carNumb'];
  382. $id = DB::connection('mysql_fwe10')->table('uf_mzy_parent_counts')->insertGetId($pcounts);
  383. if(count($counts_list[$i]['counts']) > 0){
  384. for($j=0;$j<count($counts_list[$i]['counts']);$j++){
  385. //uf_mzy_counts
  386. $counts['parent_id'] = $id;
  387. $counts['fid'] = $counts_list[$i]['counts'][$j]['fid'];
  388. $counts['areaName'] = $counts_list[$i]['counts'][$j]['areaName'];
  389. $counts['staffNumb'] = $counts_list[$i]['counts'][$j]['staffNumb'];
  390. $counts['contractorNumb'] = $counts_list[$i]['counts'][$j]['contractorNumb'];
  391. $counts['callerNumb'] = $counts_list[$i]['counts'][$j]['callerNumb'];
  392. $counts['carNumb'] = $counts_list[$i]['counts'][$j]['carNumb'];
  393. $counts['isSafe'] = $counts_list[$i]['counts'][$j]['isSafe'];
  394. DB::connection('mysql_fwe10')->table('uf_mzy_counts')->insert($counts);
  395. $persons = $counts_list[$i]['counts'][$j]['persons'];
  396. $personContractor = $counts_list[$i]['counts'][$j]['personContractor'];
  397. $personCaller = $counts_list[$i]['counts'][$j]['personCaller'];
  398. $car = $counts_list[$i]['counts'][$j]['car'];
  399. if(count($persons) > 0){
  400. for($x=0;$x<count($persons);$x++){
  401. //uf_mzy_type
  402. $type['deviceId'] = $persons[$x]['deviceId'];
  403. $type['timestamp'] = $persons[$x]['timestamp'];
  404. $type['lon'] = $persons[$x]['lon'];
  405. $type['lat'] = $persons[$x]['lat'];
  406. $type['fid'] = $persons[$x]['fid'];
  407. $type['name'] = $persons[$x]['name'];
  408. $type['weekSel'] = $persons[$x]['weekSel'];
  409. $type['stime1'] = $persons[$x]['stime1'];
  410. $type['etime1'] = $persons[$x]['etime1'];
  411. $type['stime2'] = $persons[$x]['stime2'];
  412. $type['etime2'] = $persons[$x]['etime2'];
  413. $type['stime3'] = $persons[$x]['stime3'];
  414. $type['etime3'] = $persons[$x]['etime3'];
  415. $type['organId'] = $persons[$x]['organId'];
  416. $type['work'] = $persons[$x]['work'];
  417. $type['minMaxCount'] = $persons[$x]['minMaxCount'];
  418. $type['personOrganId'] = $persons[$x]['personOrganId'];
  419. $type['inRegion'] = $persons[$x]['inRegion'];
  420. $type['mode'] = $persons[$x]['mode'];
  421. $type['type'] = 'persons';
  422. DB::connection('mysql_fwe10')->table('uf_mzy_type')->insert($type);
  423. }
  424. }
  425. if(count($personContractor) > 0){
  426. for($x=0;$x<count($personContractor);$x++){
  427. //uf_mzy_type
  428. $type['deviceId'] = $personContractor[$x]['deviceId'];
  429. $type['timestamp'] = $personContractor[$x]['timestamp'];
  430. $type['lon'] = $personContractor[$x]['lon'];
  431. $type['lat'] = $personContractor[$x]['lat'];
  432. $type['fid'] = $personContractor[$x]['fid'];
  433. $type['name'] = $personContractor[$x]['name'];
  434. $type['weekSel'] = $personContractor[$x]['weekSel'];
  435. $type['stime1'] = $personContractor[$x]['stime1'];
  436. $type['etime1'] = $personContractor[$x]['etime1'];
  437. $type['stime2'] = $personContractor[$x]['stime2'];
  438. $type['etime2'] = $personContractor[$x]['etime2'];
  439. $type['stime3'] = $personContractor[$x]['stime3'];
  440. $type['etime3'] = $personContractor[$x]['etime3'];
  441. $type['organId'] = $personContractor[$x]['organId'];
  442. $type['work'] = $personContractor[$x]['work'];
  443. $type['minMaxCount'] = $personContractor[$x]['minMaxCount'];
  444. $type['personOrganId'] = $personContractor[$x]['personOrganId'];
  445. $type['inRegion'] = $personContractor[$x]['inRegion'];
  446. $type['mode'] = $personContractor[$x]['mode'];
  447. $type['type'] = 'personContractor';
  448. DB::connection('mysql_fwe10')->table('uf_mzy_type')->insert($type);
  449. }
  450. }
  451. if(count($personCaller) > 0){
  452. for($x=0;$x<count($personCaller);$x++){
  453. //uf_mzy_type
  454. $type['deviceId'] = $personCaller[$x]['deviceId'];
  455. $type['timestamp'] = $personCaller[$x]['timestamp'];
  456. $type['lon'] = $personCaller[$x]['lon'];
  457. $type['lat'] = $personCaller[$x]['lat'];
  458. $type['fid'] = $personCaller[$x]['fid'];
  459. $type['name'] = $personCaller[$x]['name'];
  460. $type['weekSel'] = $personCaller[$x]['weekSel'];
  461. $type['stime1'] = $personCaller[$x]['stime1'];
  462. $type['etime1'] = $personCaller[$x]['etime1'];
  463. $type['stime2'] = $personCaller[$x]['stime2'];
  464. $type['etime2'] = $personCaller[$x]['etime2'];
  465. $type['stime3'] = $personCaller[$x]['stime3'];
  466. $type['etime3'] = $personCaller[$x]['etime3'];
  467. $type['organId'] = $personCaller[$x]['organId'];
  468. $type['work'] = $personCaller[$x]['work'];
  469. $type['minMaxCount'] = $personCaller[$x]['minMaxCount'];
  470. $type['personOrganId'] = $personCaller[$x]['personOrganId'];
  471. $type['inRegion'] = $personCaller[$x]['inRegion'];
  472. $type['mode'] = $personCaller[$x]['mode'];
  473. $type['type'] = 'personCaller';
  474. DB::connection('mysql_fwe10')->table('uf_mzy_type')->insert($type);
  475. }
  476. }
  477. if(count($car) > 0){
  478. for($x=0;$x<count($car);$x++){
  479. //uf_mzy_type
  480. $type['deviceId'] = $car[$x]['deviceId'];
  481. $type['timestamp'] = $car[$x]['timestamp'];
  482. $type['lon'] = $car[$x]['lon'];
  483. $type['lat'] = $car[$x]['lat'];
  484. $type['fid'] = $car[$x]['fid'];
  485. $type['name'] = $car[$x]['name'];
  486. $type['weekSel'] = $car[$x]['weekSel'];
  487. $type['stime1'] = $car[$x]['stime1'];
  488. $type['etime1'] = $car[$x]['etime1'];
  489. $type['stime2'] = $car[$x]['stime2'];
  490. $type['etime2'] = $car[$x]['etime2'];
  491. $type['stime3'] = $car[$x]['stime3'];
  492. $type['etime3'] = $car[$x]['etime3'];
  493. $type['organId'] = $car[$x]['organId'];
  494. $type['work'] = $car[$x]['work'];
  495. $type['minMaxCount'] = $car[$x]['minMaxCount'];
  496. $type['personOrganId'] = $car[$x]['personOrganId'];
  497. $type['inRegion'] = $car[$x]['inRegion'];
  498. $type['mode'] = $car[$x]['mode'];
  499. $type['type'] = 'persons';
  500. DB::connection('mysql_fwe10')->table('uf_mzy_type')->insert($type);
  501. }
  502. }
  503. }
  504. }
  505. // dd($id);
  506. }
  507. }
  508. // dd(123);
  509. }
  510. }
  511. dd('success');
  512. }
  513. //化工人员定位精蜡区域信息录入
  514. public function jlQyxxInsert(){
  515. //获取token
  516. $url = 'http://10.186.64.31:8091/chem/api/getToken?username=test&password=123456';
  517. $result = $this->httpRequest($url,'post');
  518. if($result['data']){
  519. //获取部门列表
  520. $url = 'http://10.186.64.31:8091/chem/api/getAreaInfo?token='.$result['data'];
  521. $result2 = $this->httpRequest($url);
  522. // dd($result2);
  523. if($result2['data'] && count($result2['data']) > 0){
  524. //uf_mzy_total
  525. $total['total'] = $result2['data']['total'];
  526. $total['staffNumb'] = $result2['data']['staffNumb'];
  527. $total['callerNumb'] = $result2['data']['callerNumb'];
  528. $total['carNumb'] = $result2['data']['carNumb'];
  529. $total['contractorNumb'] = $result2['data']['contractorNumb'];
  530. $total['toolcarNumb'] = $result2['data']['toolcarNumb'];
  531. DB::connection('mysql_fwe10')->table('uf_jl_total')->insert($total);
  532. $counts_list = $result2['data']['counts'];
  533. if(count($counts_list) > 0){
  534. for($i=0;$i<count($counts_list);$i++){
  535. //uf_mzy_parent_counts
  536. $pcounts['organName'] = $counts_list[$i]['organName'];
  537. $pcounts['staffNumb'] = $counts_list[$i]['staffNumb'];
  538. $pcounts['contractorNumb'] = $counts_list[$i]['contractorNumb'];
  539. $pcounts['callerNumb'] = $counts_list[$i]['callerNumb'];
  540. $pcounts['carNumb'] = $counts_list[$i]['carNumb'];
  541. $id = DB::connection('mysql_fwe10')->table('uf_jl_parent_counts')->insertGetId($pcounts);
  542. if(count($counts_list[$i]['counts']) > 0){
  543. for($j=0;$j<count($counts_list[$i]['counts']);$j++){
  544. //uf_mzy_counts
  545. $counts['parent_id'] = $id;
  546. $counts['fid'] = $counts_list[$i]['counts'][$j]['fid'];
  547. $counts['areaName'] = $counts_list[$i]['counts'][$j]['areaName'];
  548. $counts['staffNumb'] = $counts_list[$i]['counts'][$j]['staffNumb'];
  549. $counts['contractorNumb'] = $counts_list[$i]['counts'][$j]['contractorNumb'];
  550. $counts['callerNumb'] = $counts_list[$i]['counts'][$j]['callerNumb'];
  551. $counts['carNumb'] = $counts_list[$i]['counts'][$j]['carNumb'];
  552. $counts['isSafe'] = $counts_list[$i]['counts'][$j]['isSafe'];
  553. DB::connection('mysql_fwe10')->table('uf_jl_counts')->insert($counts);
  554. $persons = $counts_list[$i]['counts'][$j]['persons'];
  555. $personContractor = $counts_list[$i]['counts'][$j]['personContractor'];
  556. $personCaller = $counts_list[$i]['counts'][$j]['personCaller'];
  557. $car = $counts_list[$i]['counts'][$j]['car'];
  558. if(count($persons) > 0){
  559. for($x=0;$x<count($persons);$x++){
  560. //uf_mzy_type
  561. $type['deviceId'] = $persons[$x]['deviceId'];
  562. $type['timestamp'] = $persons[$x]['timestamp'];
  563. $type['lon'] = $persons[$x]['lon'];
  564. $type['lat'] = $persons[$x]['lat'];
  565. $type['fid'] = $persons[$x]['fid'];
  566. $type['name'] = $persons[$x]['name'];
  567. $type['weekSel'] = $persons[$x]['weekSel'];
  568. $type['stime1'] = $persons[$x]['stime1'];
  569. $type['etime1'] = $persons[$x]['etime1'];
  570. $type['stime2'] = $persons[$x]['stime2'];
  571. $type['etime2'] = $persons[$x]['etime2'];
  572. $type['stime3'] = $persons[$x]['stime3'];
  573. $type['etime3'] = $persons[$x]['etime3'];
  574. $type['organId'] = $persons[$x]['organId'];
  575. $type['work'] = $persons[$x]['work'];
  576. $type['minMaxCount'] = $persons[$x]['minMaxCount'];
  577. $type['personOrganId'] = $persons[$x]['personOrganId'];
  578. $type['inRegion'] = $persons[$x]['inRegion'];
  579. $type['mode'] = $persons[$x]['mode'];
  580. $type['type'] = 'persons';
  581. DB::connection('mysql_fwe10')->table('uf_jl_type')->insert($type);
  582. }
  583. }
  584. if(count($personContractor) > 0){
  585. for($x=0;$x<count($personContractor);$x++){
  586. //uf_mzy_type
  587. $type['deviceId'] = $personContractor[$x]['deviceId'];
  588. $type['timestamp'] = $personContractor[$x]['timestamp'];
  589. $type['lon'] = $personContractor[$x]['lon'];
  590. $type['lat'] = $personContractor[$x]['lat'];
  591. $type['fid'] = $personContractor[$x]['fid'];
  592. $type['name'] = $personContractor[$x]['name'];
  593. $type['weekSel'] = $personContractor[$x]['weekSel'];
  594. $type['stime1'] = $personContractor[$x]['stime1'];
  595. $type['etime1'] = $personContractor[$x]['etime1'];
  596. $type['stime2'] = $personContractor[$x]['stime2'];
  597. $type['etime2'] = $personContractor[$x]['etime2'];
  598. $type['stime3'] = $personContractor[$x]['stime3'];
  599. $type['etime3'] = $personContractor[$x]['etime3'];
  600. $type['organId'] = $personContractor[$x]['organId'];
  601. $type['work'] = $personContractor[$x]['work'];
  602. $type['minMaxCount'] = $personContractor[$x]['minMaxCount'];
  603. $type['personOrganId'] = $personContractor[$x]['personOrganId'];
  604. $type['inRegion'] = $personContractor[$x]['inRegion'];
  605. $type['mode'] = $personContractor[$x]['mode'];
  606. $type['type'] = 'personContractor';
  607. DB::connection('mysql_fwe10')->table('uf_jl_type')->insert($type);
  608. }
  609. }
  610. if(count($personCaller) > 0){
  611. for($x=0;$x<count($personCaller);$x++){
  612. //uf_mzy_type
  613. $type['deviceId'] = $personCaller[$x]['deviceId'];
  614. $type['timestamp'] = $personCaller[$x]['timestamp'];
  615. $type['lon'] = $personCaller[$x]['lon'];
  616. $type['lat'] = $personCaller[$x]['lat'];
  617. $type['fid'] = $personCaller[$x]['fid'];
  618. $type['name'] = $personCaller[$x]['name'];
  619. $type['weekSel'] = $personCaller[$x]['weekSel'];
  620. $type['stime1'] = $personCaller[$x]['stime1'];
  621. $type['etime1'] = $personCaller[$x]['etime1'];
  622. $type['stime2'] = $personCaller[$x]['stime2'];
  623. $type['etime2'] = $personCaller[$x]['etime2'];
  624. $type['stime3'] = $personCaller[$x]['stime3'];
  625. $type['etime3'] = $personCaller[$x]['etime3'];
  626. $type['organId'] = $personCaller[$x]['organId'];
  627. $type['work'] = $personCaller[$x]['work'];
  628. $type['minMaxCount'] = $personCaller[$x]['minMaxCount'];
  629. $type['personOrganId'] = $personCaller[$x]['personOrganId'];
  630. $type['inRegion'] = $personCaller[$x]['inRegion'];
  631. $type['mode'] = $personCaller[$x]['mode'];
  632. $type['type'] = 'personCaller';
  633. DB::connection('mysql_fwe10')->table('uf_jl_type')->insert($type);
  634. }
  635. }
  636. if(count($car) > 0){
  637. for($x=0;$x<count($car);$x++){
  638. //uf_mzy_type
  639. $type['deviceId'] = $car[$x]['deviceId'];
  640. $type['timestamp'] = $car[$x]['timestamp'];
  641. $type['lon'] = $car[$x]['lon'];
  642. $type['lat'] = $car[$x]['lat'];
  643. $type['fid'] = $car[$x]['fid'];
  644. $type['name'] = $car[$x]['name'];
  645. $type['weekSel'] = $car[$x]['weekSel'];
  646. $type['stime1'] = $car[$x]['stime1'];
  647. $type['etime1'] = $car[$x]['etime1'];
  648. $type['stime2'] = $car[$x]['stime2'];
  649. $type['etime2'] = $car[$x]['etime2'];
  650. $type['stime3'] = $car[$x]['stime3'];
  651. $type['etime3'] = $car[$x]['etime3'];
  652. $type['organId'] = $car[$x]['organId'];
  653. $type['work'] = $car[$x]['work'];
  654. $type['minMaxCount'] = $car[$x]['minMaxCount'];
  655. $type['personOrganId'] = $car[$x]['personOrganId'];
  656. $type['inRegion'] = $car[$x]['inRegion'];
  657. $type['mode'] = $car[$x]['mode'];
  658. $type['type'] = 'persons';
  659. DB::connection('mysql_fwe10')->table('uf_jl_type')->insert($type);
  660. }
  661. }
  662. }
  663. }
  664. // dd($id);
  665. }
  666. }
  667. // dd(123);
  668. }
  669. }
  670. dd('success');
  671. }
  672. public function getDcsApiData() {
  673. $apiUrl = "http://7.250.4.3:4300/v1/common/GetPointRealDataByPageV3";
  674. $client = new Client();
  675. $r = request()->all();
  676. if(isset($r['p'])) {
  677. $p = $r['p'];
  678. $k = $r['k'];
  679. } else {
  680. $p = $r;
  681. }
  682. $body = [
  683. 'headers' => [
  684. 'Authorization' => 'Bearer appkey_100100',
  685. 'Content-Type'=>'application/json; charset=utf-8',
  686. // 其他头部信息
  687. ],
  688. 'json' =>[
  689. 'PageNum'=>"-1",
  690. "PointIds"=>$p
  691. ]
  692. ];
  693. // 发送 HTTP POST 请求
  694. $response = $client->post($apiUrl, $body);
  695. // 获取 API 响应的 JSON 数据
  696. $res = json_decode($response->getBody(), true);
  697. if($res['IsSuccessful'] == 0) {
  698. return $res;
  699. }
  700. $data = isset($res['Data'])? $res['Data']: null;
  701. $transformedData['data']=[];
  702. for ($i = 0; $i < count($data); $i++) {
  703. $dic = $data[$i];
  704. $trans['v'][] = $dic['V'];
  705. $trans['list'][$i] = [
  706. 'id'=>$dic['ID'],
  707. 'nm'=>$dic['PointName'],
  708. 'v'=>$dic['V'],
  709. ];
  710. $trans['kv'][$dic['ID']] = $dic['V'];
  711. }
  712. if (!empty($k) && isset($trans[$k])) {
  713. return $trans[$k];
  714. }
  715. return $trans;
  716. }
  717. public function getDcsOpcData() {
  718. // $shell = "echo 'success' ";
  719. // $shellExec = shell_exec($shell);
  720. // // var_dump($shellExec);
  721. // if($shellExec){echo 'ok';} else {echo 'error'}
  722. $pids = [
  723. "ns=12380;s=九八零变电所80Z004照明回路_Ia",
  724. "ns=12380;s=九八零变电所5105_IA",
  725. "ns=12380;s=九八零变电所5101_UB",
  726. # 添加其他节点地址...
  727. ];
  728. $pyPath = "/home/python_proj/python_custom_script/zaoquan/dcs/";
  729. $pyFName = "test1.py";
  730. $pyKeyWord = "/usr/bin/python311";
  731. $pidsJson = json_encode($pids);
  732. $command = "$pyKeyWord {$pyPath}{$pyFName}". ' ' . escapeshellarg("{$pidsJson}");
  733. // $output = shell_exec($command);
  734. // return shell_exec($command);
  735. try {
  736. // 调用Python脚本
  737. $output = shell_exec($command);
  738. // 解析Python脚本返回的JSON数据
  739. $data = json_decode($output, true);
  740. // $data['a'] = 'aaa';
  741. // 返回JSON格式的数据给前端
  742. header('Content-Type: application/json');
  743. echo json_encode($data);
  744. } catch (Exception $e) {
  745. // 返回错误消息给前端
  746. header('Content-Type: application/json');
  747. echo json_encode(array("error" => $e->getMessage()));
  748. }
  749. }
  750. //接口第三方调用
  751. public function httpRequest($url, $format = 'get', $data = null, $token = null){
  752. //设置头信息
  753. $headerArray =array("Content-type:application/json;","Accept:application/json");
  754. if ($token) {
  755. $headerArray[] = "Authorization:bearer " . $token;
  756. }
  757. $curl=curl_init();
  758. curl_setopt($curl, CURLOPT_URL, $url);
  759. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  760. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
  761. if ($format == 'post') {
  762. //post传值设置post传参
  763. curl_setopt($curl, CURLOPT_POST, 1);
  764. if ($data) {
  765. $data = json_encode($data);
  766. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  767. }
  768. }
  769. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  770. curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray);
  771. $data=json_decode(curl_exec($curl), true);
  772. curl_close($curl);
  773. //返回接口返回数据
  774. return $data;
  775. }
  776. }