UpdateHgrydw.php 26 KB

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