UpdateHgrydw.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Support\Facades\Config;
  4. use Illuminate\Support\Facades\DB;
  5. use Illuminate\Support\Facades\Input;
  6. use Illuminate\Support\Facades\Log;
  7. use Illuminate\Support\Facades\Redis;
  8. use Modules\Camera\Entities\CameraList;
  9. use Modules\Camera\Enum\CameraEnum;
  10. use Modules\Camera\Http\Controllers\Api\HaiKangController;
  11. use Modules\Camera\Http\Controllers\Api\TdwyController;
  12. use Modules\Camera\Jobs\CameraDownload;
  13. use Modules\Camera\Services\CameraServices;
  14. use Modules\Mine\Entities\MineList;
  15. use Modules\Mine\Entities\MineListExt;
  16. use Modules\Mine\Services\MineServices;
  17. use Modules\Mine\Enum\MineEnum;
  18. use GuzzleHttp\Client;
  19. class UpdateHkList extends Command
  20. {
  21. /**
  22. * The name and signature of the console command.
  23. *
  24. * @var string
  25. */
  26. protected $signature = 'hgrydw:update';
  27. /**
  28. * The console command description.
  29. *
  30. * @var string
  31. */
  32. protected $description = '同步化工人员定位接口数据';
  33. /**
  34. * Create a new command instance.
  35. *
  36. * @return void
  37. */
  38. public function __construct()
  39. {
  40. parent::__construct();
  41. }
  42. /**
  43. * Execute the console command.
  44. *
  45. * @return mixed
  46. */
  47. public function handle()
  48. {
  49. $start_time = time();
  50. echo '开始时间:'.date('Y-m-d H:i:s');
  51. $this->mzyQyxxInsert();
  52. $this->jlQyxxInsert();
  53. echo '时长:'.number_format(((time()-$start_time)/60),2).'分钟';
  54. }
  55. //化工人员定位煤制油区域信息录入
  56. public function mzyQyxxInsert(){
  57. //获取token
  58. $url = 'http://10.186.64.30:8091/chem/api/getToken?username=super&password=meizhiyou';
  59. $result = $this->httpRequest($url,'post');
  60. if($result['data']){
  61. //获取部门列表
  62. $url = 'http://10.186.64.30:8091/chem/api/getAreaInfo?token='.$result['data'];
  63. $result2 = $this->httpRequest($url);
  64. // dd($result2);
  65. if($result2['data'] && count($result2['data']) > 0){
  66. DB::connection('mysql_fwe10')->table('uf_mzy_total')->delete();
  67. DB::connection('mysql_fwe10')->table('uf_mzy_parent_counts')->delete();
  68. DB::connection('mysql_fwe10')->table('uf_mzy_counts')->delete();
  69. DB::connection('mysql_fwe10')->table('uf_mzy_type')->delete();
  70. //uf_mzy_total
  71. $total['total'] = $result2['data']['total'];
  72. $total['staffNumb'] = $result2['data']['staffNumb'];
  73. $total['callerNumb'] = $result2['data']['callerNumb'];
  74. $total['carNumb'] = $result2['data']['carNumb'];
  75. $total['contractorNumb'] = $result2['data']['contractorNumb'];
  76. $total['toolcarNumb'] = $result2['data']['toolcarNumb'];
  77. DB::connection('mysql_fwe10')->table('uf_mzy_total')->insert($total);
  78. $counts_list = $result2['data']['counts'];
  79. if(count($counts_list) > 0){
  80. for($i=0;$i<count($counts_list);$i++){
  81. //uf_mzy_parent_counts
  82. $pcounts['organName'] = $counts_list[$i]['organName'];
  83. $pcounts['staffNumb'] = $counts_list[$i]['staffNumb'];
  84. $pcounts['contractorNumb'] = $counts_list[$i]['contractorNumb'];
  85. $pcounts['callerNumb'] = $counts_list[$i]['callerNumb'];
  86. $pcounts['carNumb'] = $counts_list[$i]['carNumb'];
  87. $id = DB::connection('mysql_fwe10')->table('uf_mzy_parent_counts')->insertGetId($pcounts);
  88. if(count($counts_list[$i]['counts']) > 0){
  89. for($j=0;$j<count($counts_list[$i]['counts']);$j++){
  90. //uf_mzy_counts
  91. $counts['parent_id'] = $id;
  92. $counts['fid'] = $counts_list[$i]['counts'][$j]['fid'];
  93. $counts['areaName'] = $counts_list[$i]['counts'][$j]['areaName'];
  94. $counts['staffNumb'] = $counts_list[$i]['counts'][$j]['staffNumb'];
  95. $counts['contractorNumb'] = $counts_list[$i]['counts'][$j]['contractorNumb'];
  96. $counts['callerNumb'] = $counts_list[$i]['counts'][$j]['callerNumb'];
  97. $counts['carNumb'] = $counts_list[$i]['counts'][$j]['carNumb'];
  98. $counts['isSafe'] = $counts_list[$i]['counts'][$j]['isSafe'];
  99. DB::connection('mysql_fwe10')->table('uf_mzy_counts')->insert($counts);
  100. $persons = $counts_list[$i]['counts'][$j]['persons'];
  101. $personContractor = $counts_list[$i]['counts'][$j]['personContractor'];
  102. $personCaller = $counts_list[$i]['counts'][$j]['personCaller'];
  103. $car = $counts_list[$i]['counts'][$j]['car'];
  104. if(count($persons) > 0){
  105. for($x=0;$x<count($persons);$x++){
  106. //uf_mzy_type
  107. $type['deviceId'] = $persons[$x]['deviceId'];
  108. $type['timestamp'] = $persons[$x]['timestamp'];
  109. $type['lon'] = $persons[$x]['lon'];
  110. $type['lat'] = $persons[$x]['lat'];
  111. $type['fid'] = $persons[$x]['fid'];
  112. $type['name'] = $persons[$x]['name'];
  113. $type['weekSel'] = $persons[$x]['weekSel'];
  114. $type['stime1'] = $persons[$x]['stime1'];
  115. $type['etime1'] = $persons[$x]['etime1'];
  116. $type['stime2'] = $persons[$x]['stime2'];
  117. $type['etime2'] = $persons[$x]['etime2'];
  118. $type['stime3'] = $persons[$x]['stime3'];
  119. $type['etime3'] = $persons[$x]['etime3'];
  120. $type['organId'] = $persons[$x]['organId'];
  121. $type['work'] = $persons[$x]['work'];
  122. $type['minMaxCount'] = $persons[$x]['minMaxCount'];
  123. $type['personOrganId'] = $persons[$x]['personOrganId'];
  124. $type['inRegion'] = $persons[$x]['inRegion'];
  125. $type['mode'] = $persons[$x]['mode'];
  126. $type['type'] = 'persons';
  127. DB::connection('mysql_fwe10')->table('uf_mzy_type')->insert($type);
  128. }
  129. }
  130. if(count($personContractor) > 0){
  131. for($x=0;$x<count($personContractor);$x++){
  132. //uf_mzy_type
  133. $type['deviceId'] = $personContractor[$x]['deviceId'];
  134. $type['timestamp'] = $personContractor[$x]['timestamp'];
  135. $type['lon'] = $personContractor[$x]['lon'];
  136. $type['lat'] = $personContractor[$x]['lat'];
  137. $type['fid'] = $personContractor[$x]['fid'];
  138. $type['name'] = $personContractor[$x]['name'];
  139. $type['weekSel'] = $personContractor[$x]['weekSel'];
  140. $type['stime1'] = $personContractor[$x]['stime1'];
  141. $type['etime1'] = $personContractor[$x]['etime1'];
  142. $type['stime2'] = $personContractor[$x]['stime2'];
  143. $type['etime2'] = $personContractor[$x]['etime2'];
  144. $type['stime3'] = $personContractor[$x]['stime3'];
  145. $type['etime3'] = $personContractor[$x]['etime3'];
  146. $type['organId'] = $personContractor[$x]['organId'];
  147. $type['work'] = $personContractor[$x]['work'];
  148. $type['minMaxCount'] = $personContractor[$x]['minMaxCount'];
  149. $type['personOrganId'] = $personContractor[$x]['personOrganId'];
  150. $type['inRegion'] = $personContractor[$x]['inRegion'];
  151. $type['mode'] = $personContractor[$x]['mode'];
  152. $type['type'] = 'personContractor';
  153. DB::connection('mysql_fwe10')->table('uf_mzy_type')->insert($type);
  154. }
  155. }
  156. if(count($personCaller) > 0){
  157. for($x=0;$x<count($personCaller);$x++){
  158. //uf_mzy_type
  159. $type['deviceId'] = $personCaller[$x]['deviceId'];
  160. $type['timestamp'] = $personCaller[$x]['timestamp'];
  161. $type['lon'] = $personCaller[$x]['lon'];
  162. $type['lat'] = $personCaller[$x]['lat'];
  163. $type['fid'] = $personCaller[$x]['fid'];
  164. $type['name'] = $personCaller[$x]['name'];
  165. $type['weekSel'] = $personCaller[$x]['weekSel'];
  166. $type['stime1'] = $personCaller[$x]['stime1'];
  167. $type['etime1'] = $personCaller[$x]['etime1'];
  168. $type['stime2'] = $personCaller[$x]['stime2'];
  169. $type['etime2'] = $personCaller[$x]['etime2'];
  170. $type['stime3'] = $personCaller[$x]['stime3'];
  171. $type['etime3'] = $personCaller[$x]['etime3'];
  172. $type['organId'] = $personCaller[$x]['organId'];
  173. $type['work'] = $personCaller[$x]['work'];
  174. $type['minMaxCount'] = $personCaller[$x]['minMaxCount'];
  175. $type['personOrganId'] = $personCaller[$x]['personOrganId'];
  176. $type['inRegion'] = $personCaller[$x]['inRegion'];
  177. $type['mode'] = $personCaller[$x]['mode'];
  178. $type['type'] = 'personCaller';
  179. DB::connection('mysql_fwe10')->table('uf_mzy_type')->insert($type);
  180. }
  181. }
  182. if(count($car) > 0){
  183. for($x=0;$x<count($car);$x++){
  184. //uf_mzy_type
  185. $type['deviceId'] = $car[$x]['deviceId'];
  186. $type['timestamp'] = $car[$x]['timestamp'];
  187. $type['lon'] = $car[$x]['lon'];
  188. $type['lat'] = $car[$x]['lat'];
  189. $type['fid'] = $car[$x]['fid'];
  190. $type['name'] = $car[$x]['name'];
  191. $type['weekSel'] = $car[$x]['weekSel'];
  192. $type['stime1'] = $car[$x]['stime1'];
  193. $type['etime1'] = $car[$x]['etime1'];
  194. $type['stime2'] = $car[$x]['stime2'];
  195. $type['etime2'] = $car[$x]['etime2'];
  196. $type['stime3'] = $car[$x]['stime3'];
  197. $type['etime3'] = $car[$x]['etime3'];
  198. $type['organId'] = $car[$x]['organId'];
  199. $type['work'] = $car[$x]['work'];
  200. $type['minMaxCount'] = $car[$x]['minMaxCount'];
  201. $type['personOrganId'] = $car[$x]['personOrganId'];
  202. $type['inRegion'] = $car[$x]['inRegion'];
  203. $type['mode'] = $car[$x]['mode'];
  204. $type['type'] = 'persons';
  205. DB::connection('mysql_fwe10')->table('uf_mzy_type')->insert($type);
  206. }
  207. }
  208. }
  209. }
  210. // dd($id);
  211. }
  212. }
  213. // dd(123);
  214. }
  215. }
  216. }
  217. //化工人员定位精蜡区域信息录入
  218. public function jlQyxxInsert(){
  219. //获取token
  220. $url = 'http://10.186.64.31:8091/chem/api/getToken?username=test&password=123456';
  221. $result = $this->httpRequest($url,'post');
  222. if($result['data']){
  223. //获取部门列表
  224. $url = 'http://10.186.64.31:8091/chem/api/getAreaInfo?token='.$result['data'];
  225. $result2 = $this->httpRequest($url);
  226. // dd($result2);
  227. if($result2['data'] && count($result2['data']) > 0){
  228. DB::connection('mysql_fwe10')->table('uf_jl_total')->delete();
  229. DB::connection('mysql_fwe10')->table('uf_jl_parent_counts')->delete();
  230. DB::connection('mysql_fwe10')->table('uf_jl_counts')->delete();
  231. DB::connection('mysql_fwe10')->table('uf_jl_type')->delete();
  232. //uf_mzy_total
  233. $total['total'] = $result2['data']['total'];
  234. $total['staffNumb'] = $result2['data']['staffNumb'];
  235. $total['callerNumb'] = $result2['data']['callerNumb'];
  236. $total['carNumb'] = $result2['data']['carNumb'];
  237. $total['contractorNumb'] = $result2['data']['contractorNumb'];
  238. $total['toolcarNumb'] = $result2['data']['toolcarNumb'];
  239. DB::connection('mysql_fwe10')->table('uf_jl_total')->insert($total);
  240. $counts_list = $result2['data']['counts'];
  241. if(count($counts_list) > 0){
  242. for($i=0;$i<count($counts_list);$i++){
  243. //uf_mzy_parent_counts
  244. $pcounts['organName'] = $counts_list[$i]['organName'];
  245. $pcounts['staffNumb'] = $counts_list[$i]['staffNumb'];
  246. $pcounts['contractorNumb'] = $counts_list[$i]['contractorNumb'];
  247. $pcounts['callerNumb'] = $counts_list[$i]['callerNumb'];
  248. $pcounts['carNumb'] = $counts_list[$i]['carNumb'];
  249. $id = DB::connection('mysql_fwe10')->table('uf_jl_parent_counts')->insertGetId($pcounts);
  250. if(count($counts_list[$i]['counts']) > 0){
  251. for($j=0;$j<count($counts_list[$i]['counts']);$j++){
  252. //uf_mzy_counts
  253. $counts['parent_id'] = $id;
  254. $counts['fid'] = $counts_list[$i]['counts'][$j]['fid'];
  255. $counts['areaName'] = $counts_list[$i]['counts'][$j]['areaName'];
  256. $counts['staffNumb'] = $counts_list[$i]['counts'][$j]['staffNumb'];
  257. $counts['contractorNumb'] = $counts_list[$i]['counts'][$j]['contractorNumb'];
  258. $counts['callerNumb'] = $counts_list[$i]['counts'][$j]['callerNumb'];
  259. $counts['carNumb'] = $counts_list[$i]['counts'][$j]['carNumb'];
  260. $counts['isSafe'] = $counts_list[$i]['counts'][$j]['isSafe'];
  261. DB::connection('mysql_fwe10')->table('uf_jl_counts')->insert($counts);
  262. $persons = $counts_list[$i]['counts'][$j]['persons'];
  263. $personContractor = $counts_list[$i]['counts'][$j]['personContractor'];
  264. $personCaller = $counts_list[$i]['counts'][$j]['personCaller'];
  265. $car = $counts_list[$i]['counts'][$j]['car'];
  266. if(count($persons) > 0){
  267. for($x=0;$x<count($persons);$x++){
  268. //uf_mzy_type
  269. $type['deviceId'] = $persons[$x]['deviceId'];
  270. $type['timestamp'] = $persons[$x]['timestamp'];
  271. $type['lon'] = $persons[$x]['lon'];
  272. $type['lat'] = $persons[$x]['lat'];
  273. $type['fid'] = $persons[$x]['fid'];
  274. $type['name'] = $persons[$x]['name'];
  275. $type['weekSel'] = $persons[$x]['weekSel'];
  276. $type['stime1'] = $persons[$x]['stime1'];
  277. $type['etime1'] = $persons[$x]['etime1'];
  278. $type['stime2'] = $persons[$x]['stime2'];
  279. $type['etime2'] = $persons[$x]['etime2'];
  280. $type['stime3'] = $persons[$x]['stime3'];
  281. $type['etime3'] = $persons[$x]['etime3'];
  282. $type['organId'] = $persons[$x]['organId'];
  283. $type['work'] = $persons[$x]['work'];
  284. $type['minMaxCount'] = $persons[$x]['minMaxCount'];
  285. $type['personOrganId'] = $persons[$x]['personOrganId'];
  286. $type['inRegion'] = $persons[$x]['inRegion'];
  287. $type['mode'] = $persons[$x]['mode'];
  288. $type['type'] = 'persons';
  289. DB::connection('mysql_fwe10')->table('uf_jl_type')->insert($type);
  290. }
  291. }
  292. if(count($personContractor) > 0){
  293. for($x=0;$x<count($personContractor);$x++){
  294. //uf_mzy_type
  295. $type['deviceId'] = $personContractor[$x]['deviceId'];
  296. $type['timestamp'] = $personContractor[$x]['timestamp'];
  297. $type['lon'] = $personContractor[$x]['lon'];
  298. $type['lat'] = $personContractor[$x]['lat'];
  299. $type['fid'] = $personContractor[$x]['fid'];
  300. $type['name'] = $personContractor[$x]['name'];
  301. $type['weekSel'] = $personContractor[$x]['weekSel'];
  302. $type['stime1'] = $personContractor[$x]['stime1'];
  303. $type['etime1'] = $personContractor[$x]['etime1'];
  304. $type['stime2'] = $personContractor[$x]['stime2'];
  305. $type['etime2'] = $personContractor[$x]['etime2'];
  306. $type['stime3'] = $personContractor[$x]['stime3'];
  307. $type['etime3'] = $personContractor[$x]['etime3'];
  308. $type['organId'] = $personContractor[$x]['organId'];
  309. $type['work'] = $personContractor[$x]['work'];
  310. $type['minMaxCount'] = $personContractor[$x]['minMaxCount'];
  311. $type['personOrganId'] = $personContractor[$x]['personOrganId'];
  312. $type['inRegion'] = $personContractor[$x]['inRegion'];
  313. $type['mode'] = $personContractor[$x]['mode'];
  314. $type['type'] = 'personContractor';
  315. DB::connection('mysql_fwe10')->table('uf_jl_type')->insert($type);
  316. }
  317. }
  318. if(count($personCaller) > 0){
  319. for($x=0;$x<count($personCaller);$x++){
  320. //uf_mzy_type
  321. $type['deviceId'] = $personCaller[$x]['deviceId'];
  322. $type['timestamp'] = $personCaller[$x]['timestamp'];
  323. $type['lon'] = $personCaller[$x]['lon'];
  324. $type['lat'] = $personCaller[$x]['lat'];
  325. $type['fid'] = $personCaller[$x]['fid'];
  326. $type['name'] = $personCaller[$x]['name'];
  327. $type['weekSel'] = $personCaller[$x]['weekSel'];
  328. $type['stime1'] = $personCaller[$x]['stime1'];
  329. $type['etime1'] = $personCaller[$x]['etime1'];
  330. $type['stime2'] = $personCaller[$x]['stime2'];
  331. $type['etime2'] = $personCaller[$x]['etime2'];
  332. $type['stime3'] = $personCaller[$x]['stime3'];
  333. $type['etime3'] = $personCaller[$x]['etime3'];
  334. $type['organId'] = $personCaller[$x]['organId'];
  335. $type['work'] = $personCaller[$x]['work'];
  336. $type['minMaxCount'] = $personCaller[$x]['minMaxCount'];
  337. $type['personOrganId'] = $personCaller[$x]['personOrganId'];
  338. $type['inRegion'] = $personCaller[$x]['inRegion'];
  339. $type['mode'] = $personCaller[$x]['mode'];
  340. $type['type'] = 'personCaller';
  341. DB::connection('mysql_fwe10')->table('uf_jl_type')->insert($type);
  342. }
  343. }
  344. if(count($car) > 0){
  345. for($x=0;$x<count($car);$x++){
  346. //uf_mzy_type
  347. $type['deviceId'] = $car[$x]['deviceId'];
  348. $type['timestamp'] = $car[$x]['timestamp'];
  349. $type['lon'] = $car[$x]['lon'];
  350. $type['lat'] = $car[$x]['lat'];
  351. $type['fid'] = $car[$x]['fid'];
  352. $type['name'] = $car[$x]['name'];
  353. $type['weekSel'] = $car[$x]['weekSel'];
  354. $type['stime1'] = $car[$x]['stime1'];
  355. $type['etime1'] = $car[$x]['etime1'];
  356. $type['stime2'] = $car[$x]['stime2'];
  357. $type['etime2'] = $car[$x]['etime2'];
  358. $type['stime3'] = $car[$x]['stime3'];
  359. $type['etime3'] = $car[$x]['etime3'];
  360. $type['organId'] = $car[$x]['organId'];
  361. $type['work'] = $car[$x]['work'];
  362. $type['minMaxCount'] = $car[$x]['minMaxCount'];
  363. $type['personOrganId'] = $car[$x]['personOrganId'];
  364. $type['inRegion'] = $car[$x]['inRegion'];
  365. $type['mode'] = $car[$x]['mode'];
  366. $type['type'] = 'persons';
  367. DB::connection('mysql_fwe10')->table('uf_jl_type')->insert($type);
  368. }
  369. }
  370. }
  371. }
  372. // dd($id);
  373. }
  374. }
  375. // dd(123);
  376. }
  377. }
  378. }
  379. //接口第三方调用
  380. public function httpRequest($url, $format = 'get', $data = null, $token = null){
  381. //设置头信息
  382. $headerArray =array("Content-type:application/json;","Accept:application/json");
  383. if ($token) {
  384. $headerArray[] = "Authorization:bearer " . $token;
  385. }
  386. $curl=curl_init();
  387. curl_setopt($curl, CURLOPT_URL, $url);
  388. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  389. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
  390. if ($format == 'post') {
  391. //post传值设置post传参
  392. curl_setopt($curl, CURLOPT_POST, 1);
  393. if ($data) {
  394. $data = json_encode($data);
  395. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  396. }
  397. }
  398. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  399. curl_setopt($curl,CURLOPT_HTTPHEADER,$headerArray);
  400. $data=json_decode(curl_exec($curl), true);
  401. curl_close($curl);
  402. //返回接口返回数据
  403. return $data;
  404. }
  405. }