TestsController.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  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. DB::connection('mysql_fwe10')->table('uf_mzy_total')->delete();
  366. DB::connection('mysql_fwe10')->table('uf_mzy_parent_counts')->delete();
  367. DB::connection('mysql_fwe10')->table('uf_mzy_counts')->delete();
  368. DB::connection('mysql_fwe10')->table('uf_mzy_type')->delete();
  369. //uf_mzy_total
  370. $total['total'] = $result2['data']['total'];
  371. $total['staffNumb'] = $result2['data']['staffNumb'];
  372. $total['callerNumb'] = $result2['data']['callerNumb'];
  373. $total['carNumb'] = $result2['data']['carNumb'];
  374. $total['contractorNumb'] = $result2['data']['contractorNumb'];
  375. $total['toolcarNumb'] = $result2['data']['toolcarNumb'];
  376. DB::connection('mysql_fwe10')->table('uf_mzy_total')->insert($total);
  377. $counts_list = $result2['data']['counts'];
  378. if(count($counts_list) > 0){
  379. for($i=0;$i<count($counts_list);$i++){
  380. //uf_mzy_parent_counts
  381. $pcounts['organName'] = $counts_list[$i]['organName'];
  382. $pcounts['staffNumb'] = $counts_list[$i]['staffNumb'];
  383. $pcounts['contractorNumb'] = $counts_list[$i]['contractorNumb'];
  384. $pcounts['callerNumb'] = $counts_list[$i]['callerNumb'];
  385. $pcounts['carNumb'] = $counts_list[$i]['carNumb'];
  386. $id = DB::connection('mysql_fwe10')->table('uf_mzy_parent_counts')->insertGetId($pcounts);
  387. if(count($counts_list[$i]['counts']) > 0){
  388. for($j=0;$j<count($counts_list[$i]['counts']);$j++){
  389. //uf_mzy_counts
  390. $counts['parent_id'] = $id;
  391. $counts['fid'] = $counts_list[$i]['counts'][$j]['fid'];
  392. $counts['areaName'] = $counts_list[$i]['counts'][$j]['areaName'];
  393. $counts['staffNumb'] = $counts_list[$i]['counts'][$j]['staffNumb'];
  394. $counts['contractorNumb'] = $counts_list[$i]['counts'][$j]['contractorNumb'];
  395. $counts['callerNumb'] = $counts_list[$i]['counts'][$j]['callerNumb'];
  396. $counts['carNumb'] = $counts_list[$i]['counts'][$j]['carNumb'];
  397. $counts['isSafe'] = $counts_list[$i]['counts'][$j]['isSafe'];
  398. DB::connection('mysql_fwe10')->table('uf_mzy_counts')->insert($counts);
  399. $persons = $counts_list[$i]['counts'][$j]['persons'];
  400. $personContractor = $counts_list[$i]['counts'][$j]['personContractor'];
  401. $personCaller = $counts_list[$i]['counts'][$j]['personCaller'];
  402. $car = $counts_list[$i]['counts'][$j]['car'];
  403. if(count($persons) > 0){
  404. for($x=0;$x<count($persons);$x++){
  405. //uf_mzy_type
  406. $type['deviceId'] = $persons[$x]['deviceId'];
  407. $type['timestamp'] = $persons[$x]['timestamp'];
  408. $type['lon'] = $persons[$x]['lon'];
  409. $type['lat'] = $persons[$x]['lat'];
  410. $type['fid'] = $persons[$x]['fid'];
  411. $type['name'] = $persons[$x]['name'];
  412. $type['weekSel'] = $persons[$x]['weekSel'];
  413. $type['stime1'] = $persons[$x]['stime1'];
  414. $type['etime1'] = $persons[$x]['etime1'];
  415. $type['stime2'] = $persons[$x]['stime2'];
  416. $type['etime2'] = $persons[$x]['etime2'];
  417. $type['stime3'] = $persons[$x]['stime3'];
  418. $type['etime3'] = $persons[$x]['etime3'];
  419. $type['organId'] = $persons[$x]['organId'];
  420. $type['work'] = $persons[$x]['work'];
  421. $type['minMaxCount'] = $persons[$x]['minMaxCount'];
  422. $type['personOrganId'] = $persons[$x]['personOrganId'];
  423. $type['inRegion'] = $persons[$x]['inRegion'];
  424. $type['mode'] = $persons[$x]['mode'];
  425. $type['type'] = 'persons';
  426. DB::connection('mysql_fwe10')->table('uf_mzy_type')->insert($type);
  427. }
  428. }
  429. if(count($personContractor) > 0){
  430. for($x=0;$x<count($personContractor);$x++){
  431. //uf_mzy_type
  432. $type['deviceId'] = $personContractor[$x]['deviceId'];
  433. $type['timestamp'] = $personContractor[$x]['timestamp'];
  434. $type['lon'] = $personContractor[$x]['lon'];
  435. $type['lat'] = $personContractor[$x]['lat'];
  436. $type['fid'] = $personContractor[$x]['fid'];
  437. $type['name'] = $personContractor[$x]['name'];
  438. $type['weekSel'] = $personContractor[$x]['weekSel'];
  439. $type['stime1'] = $personContractor[$x]['stime1'];
  440. $type['etime1'] = $personContractor[$x]['etime1'];
  441. $type['stime2'] = $personContractor[$x]['stime2'];
  442. $type['etime2'] = $personContractor[$x]['etime2'];
  443. $type['stime3'] = $personContractor[$x]['stime3'];
  444. $type['etime3'] = $personContractor[$x]['etime3'];
  445. $type['organId'] = $personContractor[$x]['organId'];
  446. $type['work'] = $personContractor[$x]['work'];
  447. $type['minMaxCount'] = $personContractor[$x]['minMaxCount'];
  448. $type['personOrganId'] = $personContractor[$x]['personOrganId'];
  449. $type['inRegion'] = $personContractor[$x]['inRegion'];
  450. $type['mode'] = $personContractor[$x]['mode'];
  451. $type['type'] = 'personContractor';
  452. DB::connection('mysql_fwe10')->table('uf_mzy_type')->insert($type);
  453. }
  454. }
  455. if(count($personCaller) > 0){
  456. for($x=0;$x<count($personCaller);$x++){
  457. //uf_mzy_type
  458. $type['deviceId'] = $personCaller[$x]['deviceId'];
  459. $type['timestamp'] = $personCaller[$x]['timestamp'];
  460. $type['lon'] = $personCaller[$x]['lon'];
  461. $type['lat'] = $personCaller[$x]['lat'];
  462. $type['fid'] = $personCaller[$x]['fid'];
  463. $type['name'] = $personCaller[$x]['name'];
  464. $type['weekSel'] = $personCaller[$x]['weekSel'];
  465. $type['stime1'] = $personCaller[$x]['stime1'];
  466. $type['etime1'] = $personCaller[$x]['etime1'];
  467. $type['stime2'] = $personCaller[$x]['stime2'];
  468. $type['etime2'] = $personCaller[$x]['etime2'];
  469. $type['stime3'] = $personCaller[$x]['stime3'];
  470. $type['etime3'] = $personCaller[$x]['etime3'];
  471. $type['organId'] = $personCaller[$x]['organId'];
  472. $type['work'] = $personCaller[$x]['work'];
  473. $type['minMaxCount'] = $personCaller[$x]['minMaxCount'];
  474. $type['personOrganId'] = $personCaller[$x]['personOrganId'];
  475. $type['inRegion'] = $personCaller[$x]['inRegion'];
  476. $type['mode'] = $personCaller[$x]['mode'];
  477. $type['type'] = 'personCaller';
  478. DB::connection('mysql_fwe10')->table('uf_mzy_type')->insert($type);
  479. }
  480. }
  481. if(count($car) > 0){
  482. for($x=0;$x<count($car);$x++){
  483. //uf_mzy_type
  484. $type['deviceId'] = $car[$x]['deviceId'];
  485. $type['timestamp'] = $car[$x]['timestamp'];
  486. $type['lon'] = $car[$x]['lon'];
  487. $type['lat'] = $car[$x]['lat'];
  488. $type['fid'] = $car[$x]['fid'];
  489. $type['name'] = $car[$x]['name'];
  490. $type['weekSel'] = $car[$x]['weekSel'];
  491. $type['stime1'] = $car[$x]['stime1'];
  492. $type['etime1'] = $car[$x]['etime1'];
  493. $type['stime2'] = $car[$x]['stime2'];
  494. $type['etime2'] = $car[$x]['etime2'];
  495. $type['stime3'] = $car[$x]['stime3'];
  496. $type['etime3'] = $car[$x]['etime3'];
  497. $type['organId'] = $car[$x]['organId'];
  498. $type['work'] = $car[$x]['work'];
  499. $type['minMaxCount'] = $car[$x]['minMaxCount'];
  500. $type['personOrganId'] = $car[$x]['personOrganId'];
  501. $type['inRegion'] = $car[$x]['inRegion'];
  502. $type['mode'] = $car[$x]['mode'];
  503. $type['type'] = 'persons';
  504. DB::connection('mysql_fwe10')->table('uf_mzy_type')->insert($type);
  505. }
  506. }
  507. }
  508. }
  509. // dd($id);
  510. }
  511. }
  512. // dd(123);
  513. }
  514. }
  515. dd('success');
  516. }
  517. //化工人员定位精蜡区域信息录入
  518. public function jlQyxxInsert(){
  519. //获取token
  520. $url = 'http://10.186.64.31:8091/chem/api/getToken?username=test&password=123456';
  521. $result = $this->httpRequest($url,'post');
  522. if($result['data']){
  523. //获取部门列表
  524. $url = 'http://10.186.64.31:8091/chem/api/getAreaInfo?token='.$result['data'];
  525. $result2 = $this->httpRequest($url);
  526. // dd($result2);
  527. if($result2['data'] && count($result2['data']) > 0){
  528. DB::connection('mysql_fwe10')->table('uf_jl_total')->delete();
  529. DB::connection('mysql_fwe10')->table('uf_jl_parent_counts')->delete();
  530. DB::connection('mysql_fwe10')->table('uf_jl_counts')->delete();
  531. DB::connection('mysql_fwe10')->table('uf_jl_type')->delete();
  532. //uf_mzy_total
  533. $total['total'] = $result2['data']['total'];
  534. $total['staffNumb'] = $result2['data']['staffNumb'];
  535. $total['callerNumb'] = $result2['data']['callerNumb'];
  536. $total['carNumb'] = $result2['data']['carNumb'];
  537. $total['contractorNumb'] = $result2['data']['contractorNumb'];
  538. $total['toolcarNumb'] = $result2['data']['toolcarNumb'];
  539. DB::connection('mysql_fwe10')->table('uf_jl_total')->insert($total);
  540. $counts_list = $result2['data']['counts'];
  541. if(count($counts_list) > 0){
  542. for($i=0;$i<count($counts_list);$i++){
  543. //uf_mzy_parent_counts
  544. $pcounts['organName'] = $counts_list[$i]['organName'];
  545. $pcounts['staffNumb'] = $counts_list[$i]['staffNumb'];
  546. $pcounts['contractorNumb'] = $counts_list[$i]['contractorNumb'];
  547. $pcounts['callerNumb'] = $counts_list[$i]['callerNumb'];
  548. $pcounts['carNumb'] = $counts_list[$i]['carNumb'];
  549. $id = DB::connection('mysql_fwe10')->table('uf_jl_parent_counts')->insertGetId($pcounts);
  550. if(count($counts_list[$i]['counts']) > 0){
  551. for($j=0;$j<count($counts_list[$i]['counts']);$j++){
  552. //uf_mzy_counts
  553. $counts['parent_id'] = $id;
  554. $counts['fid'] = $counts_list[$i]['counts'][$j]['fid'];
  555. $counts['areaName'] = $counts_list[$i]['counts'][$j]['areaName'];
  556. $counts['staffNumb'] = $counts_list[$i]['counts'][$j]['staffNumb'];
  557. $counts['contractorNumb'] = $counts_list[$i]['counts'][$j]['contractorNumb'];
  558. $counts['callerNumb'] = $counts_list[$i]['counts'][$j]['callerNumb'];
  559. $counts['carNumb'] = $counts_list[$i]['counts'][$j]['carNumb'];
  560. $counts['isSafe'] = $counts_list[$i]['counts'][$j]['isSafe'];
  561. DB::connection('mysql_fwe10')->table('uf_jl_counts')->insert($counts);
  562. $persons = $counts_list[$i]['counts'][$j]['persons'];
  563. $personContractor = $counts_list[$i]['counts'][$j]['personContractor'];
  564. $personCaller = $counts_list[$i]['counts'][$j]['personCaller'];
  565. $car = $counts_list[$i]['counts'][$j]['car'];
  566. if(count($persons) > 0){
  567. for($x=0;$x<count($persons);$x++){
  568. //uf_mzy_type
  569. $type['deviceId'] = $persons[$x]['deviceId'];
  570. $type['timestamp'] = $persons[$x]['timestamp'];
  571. $type['lon'] = $persons[$x]['lon'];
  572. $type['lat'] = $persons[$x]['lat'];
  573. $type['fid'] = $persons[$x]['fid'];
  574. $type['name'] = $persons[$x]['name'];
  575. $type['weekSel'] = $persons[$x]['weekSel'];
  576. $type['stime1'] = $persons[$x]['stime1'];
  577. $type['etime1'] = $persons[$x]['etime1'];
  578. $type['stime2'] = $persons[$x]['stime2'];
  579. $type['etime2'] = $persons[$x]['etime2'];
  580. $type['stime3'] = $persons[$x]['stime3'];
  581. $type['etime3'] = $persons[$x]['etime3'];
  582. $type['organId'] = $persons[$x]['organId'];
  583. $type['work'] = $persons[$x]['work'];
  584. $type['minMaxCount'] = $persons[$x]['minMaxCount'];
  585. $type['personOrganId'] = $persons[$x]['personOrganId'];
  586. $type['inRegion'] = $persons[$x]['inRegion'];
  587. $type['mode'] = $persons[$x]['mode'];
  588. $type['type'] = 'persons';
  589. DB::connection('mysql_fwe10')->table('uf_jl_type')->insert($type);
  590. }
  591. }
  592. if(count($personContractor) > 0){
  593. for($x=0;$x<count($personContractor);$x++){
  594. //uf_mzy_type
  595. $type['deviceId'] = $personContractor[$x]['deviceId'];
  596. $type['timestamp'] = $personContractor[$x]['timestamp'];
  597. $type['lon'] = $personContractor[$x]['lon'];
  598. $type['lat'] = $personContractor[$x]['lat'];
  599. $type['fid'] = $personContractor[$x]['fid'];
  600. $type['name'] = $personContractor[$x]['name'];
  601. $type['weekSel'] = $personContractor[$x]['weekSel'];
  602. $type['stime1'] = $personContractor[$x]['stime1'];
  603. $type['etime1'] = $personContractor[$x]['etime1'];
  604. $type['stime2'] = $personContractor[$x]['stime2'];
  605. $type['etime2'] = $personContractor[$x]['etime2'];
  606. $type['stime3'] = $personContractor[$x]['stime3'];
  607. $type['etime3'] = $personContractor[$x]['etime3'];
  608. $type['organId'] = $personContractor[$x]['organId'];
  609. $type['work'] = $personContractor[$x]['work'];
  610. $type['minMaxCount'] = $personContractor[$x]['minMaxCount'];
  611. $type['personOrganId'] = $personContractor[$x]['personOrganId'];
  612. $type['inRegion'] = $personContractor[$x]['inRegion'];
  613. $type['mode'] = $personContractor[$x]['mode'];
  614. $type['type'] = 'personContractor';
  615. DB::connection('mysql_fwe10')->table('uf_jl_type')->insert($type);
  616. }
  617. }
  618. if(count($personCaller) > 0){
  619. for($x=0;$x<count($personCaller);$x++){
  620. //uf_mzy_type
  621. $type['deviceId'] = $personCaller[$x]['deviceId'];
  622. $type['timestamp'] = $personCaller[$x]['timestamp'];
  623. $type['lon'] = $personCaller[$x]['lon'];
  624. $type['lat'] = $personCaller[$x]['lat'];
  625. $type['fid'] = $personCaller[$x]['fid'];
  626. $type['name'] = $personCaller[$x]['name'];
  627. $type['weekSel'] = $personCaller[$x]['weekSel'];
  628. $type['stime1'] = $personCaller[$x]['stime1'];
  629. $type['etime1'] = $personCaller[$x]['etime1'];
  630. $type['stime2'] = $personCaller[$x]['stime2'];
  631. $type['etime2'] = $personCaller[$x]['etime2'];
  632. $type['stime3'] = $personCaller[$x]['stime3'];
  633. $type['etime3'] = $personCaller[$x]['etime3'];
  634. $type['organId'] = $personCaller[$x]['organId'];
  635. $type['work'] = $personCaller[$x]['work'];
  636. $type['minMaxCount'] = $personCaller[$x]['minMaxCount'];
  637. $type['personOrganId'] = $personCaller[$x]['personOrganId'];
  638. $type['inRegion'] = $personCaller[$x]['inRegion'];
  639. $type['mode'] = $personCaller[$x]['mode'];
  640. $type['type'] = 'personCaller';
  641. DB::connection('mysql_fwe10')->table('uf_jl_type')->insert($type);
  642. }
  643. }
  644. if(count($car) > 0){
  645. for($x=0;$x<count($car);$x++){
  646. //uf_mzy_type
  647. $type['deviceId'] = $car[$x]['deviceId'];
  648. $type['timestamp'] = $car[$x]['timestamp'];
  649. $type['lon'] = $car[$x]['lon'];
  650. $type['lat'] = $car[$x]['lat'];
  651. $type['fid'] = $car[$x]['fid'];
  652. $type['name'] = $car[$x]['name'];
  653. $type['weekSel'] = $car[$x]['weekSel'];
  654. $type['stime1'] = $car[$x]['stime1'];
  655. $type['etime1'] = $car[$x]['etime1'];
  656. $type['stime2'] = $car[$x]['stime2'];
  657. $type['etime2'] = $car[$x]['etime2'];
  658. $type['stime3'] = $car[$x]['stime3'];
  659. $type['etime3'] = $car[$x]['etime3'];
  660. $type['organId'] = $car[$x]['organId'];
  661. $type['work'] = $car[$x]['work'];
  662. $type['minMaxCount'] = $car[$x]['minMaxCount'];
  663. $type['personOrganId'] = $car[$x]['personOrganId'];
  664. $type['inRegion'] = $car[$x]['inRegion'];
  665. $type['mode'] = $car[$x]['mode'];
  666. $type['type'] = 'persons';
  667. DB::connection('mysql_fwe10')->table('uf_jl_type')->insert($type);
  668. }
  669. }
  670. }
  671. }
  672. // dd($id);
  673. }
  674. }
  675. // dd(123);
  676. }
  677. }
  678. dd('success');
  679. }
  680. public function getDcsApiData() {
  681. $apiUrl = "http://7.250.4.3:4300/v1/common/GetPointRealDataByPageV3";
  682. $client = new Client();
  683. $r = request()->all();
  684. if(isset($r['p'])) {
  685. $p = $r['p'];
  686. $k = $r['k'];
  687. } else {
  688. $p = $r;
  689. }
  690. $body = [
  691. 'headers' => [
  692. 'Authorization' => 'Bearer appkey_100100',
  693. 'Content-Type'=>'application/json; charset=utf-8',
  694. // 其他头部信息
  695. ],
  696. 'json' =>[
  697. 'PageNum'=>"-1",
  698. "PointIds"=>$p
  699. ]
  700. ];
  701. // 发送 HTTP POST 请求
  702. $response = $client->post($apiUrl, $body);
  703. // 获取 API 响应的 JSON 数据
  704. $res = json_decode($response->getBody(), true);
  705. if($res['IsSuccessful'] == 0) {
  706. return $res;
  707. }
  708. $data = isset($res['Data'])? $res['Data']: null;
  709. $transformedData['data']=[];
  710. for ($i = 0; $i < count($data); $i++) {
  711. $dic = $data[$i];
  712. $trans['v'][] = $dic['V'];
  713. $trans['list'][$i] = [
  714. 'id'=>$dic['ID'],
  715. 'nm'=>$dic['PointName'],
  716. 'v'=>$dic['V'],
  717. ];
  718. $trans['kv'][$dic['ID']] = $dic['V'];
  719. }
  720. if (!empty($k) && isset($trans[$k])) {
  721. return $trans[$k];
  722. }
  723. return $trans;
  724. }
  725. public function getDcsOpcData() {
  726. // $shell = "echo 'success' ";
  727. // $shellExec = shell_exec($shell);
  728. // // var_dump($shellExec);
  729. // if($shellExec){echo 'ok';} else {echo 'error'}
  730. $pids = [
  731. "ns=12380;s=九八零变电所80Z004照明回路_Ia",
  732. "ns=12380;s=九八零变电所5105_IA",
  733. "ns=12380;s=九八零变电所5101_UB",
  734. # 添加其他节点地址...
  735. ];
  736. $pyPath = "/home/python_proj/python_custom_script/zaoquan/dcs/";
  737. $pyFName = "test1.py";
  738. $pyKeyWord = "/usr/bin/python311";
  739. $pidsJson = json_encode($pids);
  740. $command = "$pyKeyWord {$pyPath}{$pyFName}". ' ' . escapeshellarg("{$pidsJson}");
  741. // $output = shell_exec($command);
  742. // return shell_exec($command);
  743. try {
  744. // 调用Python脚本
  745. $output = shell_exec($command);
  746. // 解析Python脚本返回的JSON数据
  747. $data = json_decode($output, true);
  748. // $data['a'] = 'aaa';
  749. // 返回JSON格式的数据给前端
  750. header('Content-Type: application/json');
  751. echo json_encode($data);
  752. } catch (Exception $e) {
  753. // 返回错误消息给前端
  754. header('Content-Type: application/json');
  755. echo json_encode(array("error" => $e->getMessage()));
  756. }
  757. }
  758. //接口第三方调用
  759. public function httpRequest($url, $format = 'get', $data = null, $token = null){
  760. //设置头信息
  761. $headerArray =array("Content-type:application/json;","Accept:application/json");
  762. if ($token) {
  763. $headerArray[] = "Authorization:bearer " . $token;
  764. }
  765. $curl=curl_init();
  766. curl_setopt($curl, CURLOPT_URL, $url);
  767. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  768. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
  769. if ($format == 'post') {
  770. //post传值设置post传参
  771. curl_setopt($curl, CURLOPT_POST, 1);
  772. if ($data) {
  773. $data = json_encode($data);
  774. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  775. }
  776. }
  777. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  778. curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray);
  779. $data=json_decode(curl_exec($curl), true);
  780. curl_close($curl);
  781. //返回接口返回数据
  782. return $data;
  783. }
  784. }