TestsController.php 41 KB

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