TestsController.php 41 KB

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