TestsController.php 43 KB

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