RouteMap.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. <?php
  2. namespace catchAdmin\map\controller;
  3. use catcher\base\CatchRequest as Request;
  4. use catcher\CatchResponse;
  5. use catcher\base\CatchController;
  6. use Aliyun\OTS\OTSClient;
  7. use catchAdmin\device\model\Device as deviceModel;
  8. use catchAdmin\fences\model\Fences as fencesModel;
  9. use think\facade\Db;
  10. use think\facade\Env;
  11. use PDO;
  12. class RouteMap extends CatchController
  13. {
  14. protected $deviceModel;
  15. protected $fencesModel;
  16. protected $filterTrack=false;
  17. public function __construct(deviceModel $deviceModel,fencesModel $fencesModel)
  18. {
  19. $this->deviceModel = $deviceModel;
  20. $this->fencesModel = $fencesModel;
  21. }
  22. /**
  23. * 列表
  24. * @time 2021年05月18日 10:15
  25. * @param Request $request
  26. */
  27. public function queryDeviceList(Request $request) : \think\Response
  28. {
  29. $list =$this->deviceModel->getList();
  30. foreach($list as &$item){
  31. if($item['online_time']<$item['wifi_online_time']){
  32. $item['longitude']=$item['wifi_longitude'];
  33. $item['latitude']=$item['wifi_latitude'];
  34. }
  35. }
  36. return CatchResponse::paginate($list);
  37. }
  38. /**
  39. * 列表
  40. * @time 2021年05月18日 10:15
  41. * @param Request $request
  42. */
  43. public function queryDeviceRealTimeInfo(Request $request) : \think\Response
  44. {
  45. $params=$request->param();
  46. if(!isset($params['imeis'])){
  47. return CatchResponse::success([]);
  48. }
  49. // var_dump($params);
  50. $imeis=$params['imeis'];
  51. $list=$this->deviceModel->whereIn('imei',$imeis)->select();
  52. foreach ($list as &$value) {
  53. $value['status_icon']='run';
  54. $value['status']='在线';
  55. }
  56. // var_dump($list);
  57. return CatchResponse::success($list);
  58. }
  59. /**
  60. * 查询告警列表
  61. * @time 2021年05月24日
  62. * @return \think\response\Json
  63. */
  64. public function queryAlarmList(Request $request): \think\Response
  65. {
  66. $list=$this->deviceModel->queryAlarmList();
  67. foreach($list as &$item){
  68. if($item['online_time']<$item['wifi_online_time']){
  69. $item['longitude']=$item['wifi_longitude'];
  70. $item['latitude']=$item['wifi_latitude'];
  71. }
  72. }
  73. return CatchResponse::paginate($list);
  74. }
  75. /**
  76. *
  77. * @time 2021年05月24日
  78. * @return \think\response\Json
  79. */
  80. public function queryLocationList(Request $request): \think\Response
  81. {
  82. return CatchResponse::success($this->deviceModel->queryLocationList());
  83. }
  84. /**
  85. *
  86. * @time 2021年05月24日
  87. * @return \think\response\Json
  88. */
  89. public function queryAlarmLocationList(Request $request): \think\Response
  90. {
  91. return CatchResponse::success($this->deviceModel->queryAlarmLocationList());
  92. }
  93. /**
  94. *
  95. * @time 2021年05月24日
  96. * @return \think\response\Json
  97. */
  98. public function queryFenceList(Request $request): \think\Response
  99. {
  100. $list=DB::table('fences')->where('fence_type',0)->select()->toArray();
  101. foreach($list as &$val){
  102. $user_depart=Db::table('users')->where('id',$val['creator_id'])->value('department_id');
  103. $creator_level=Db::table('departments')->where('id',$user_depart)->value('level');
  104. if(!$creator_level){
  105. $val['level']=1;
  106. }else{
  107. $level_arr=explode('-',$creator_level);
  108. $val['level']=count($level_arr)+1;
  109. }
  110. }
  111. return CatchResponse::success($list);
  112. }
  113. /**
  114. * 查询当前定位
  115. * @time 2021年05月18日 10:15
  116. *
  117. */
  118. public function queryDeviceCurLocation(Request $request) : \think\Response
  119. {
  120. $params=$request->param();
  121. $device_number=$params['device_number'];
  122. if (!$device_number) {
  123. return CatchResponse::fail("获取设备号失败");
  124. }
  125. $device_info=$this->deviceModel->where('imei',$device_number)->find()->toArray();
  126. // var_dump($device_info);
  127. if($device_info['online_time']<$device_info['wifi_online_time']){
  128. $device_info['online_time']=$device_info['wifi_online_time'];
  129. $device_info['longitude']=$device_info['wifi_longitude'];
  130. $device_info['latitude']=$device_info['wifi_latitude'];
  131. }
  132. return CatchResponse::success($device_info);
  133. }
  134. /**
  135. * 查询学生轨迹GPS
  136. * @time 2021年05月18日 10:15
  137. *
  138. */
  139. public function queryDeviceRouteGps(Request $request) : \think\Response
  140. {
  141. $params=$request->param();
  142. // var_dump($params);
  143. // var_dump(strtotime($params['aData']));
  144. $device_number = $params['imei'];
  145. if (!$device_number) {
  146. return CatchResponse::fail("获取设备号失败");
  147. }
  148. if($params['time']==0 && isset($params['time_range']) && $params['time_range'] != ''){
  149. $start_time=strtotime($params['time_range'][0]);
  150. $end_time=strtotime($params['time_range'][1]);
  151. }else{
  152. $start_time = time()-$params['time'];
  153. $end_time=time();
  154. }
  155. $options=array(
  156. 'device_number'=>$device_number,
  157. 'start_time'=>$start_time,
  158. 'end_time'=>$end_time,
  159. 'table_name'=>'wxt_route_gps'
  160. );
  161. $res = queryTableStoreGpsRoute($options);
  162. if($res['success']){
  163. $data=$res['data'];
  164. $battery_level=Db::table('devices')->where('imei',$device_number)->value('battery_level');
  165. foreach($data as &$val){
  166. $val['Longitude']=round($val['Longitude'],6);
  167. $val['Latitude']=round($val['Latitude'],6);
  168. $val['SignalType']='GPS';
  169. $val['BatteryLevel']=$battery_level;
  170. }
  171. return CatchResponse::success($data);
  172. }else{
  173. return CatchResponse::fail($res['message']);
  174. }
  175. }
  176. /**
  177. * 查询告警相关围栏信息
  178. * @time 2021年05月18日 10:15
  179. * @param Request $request
  180. */
  181. public function queryAlarmFenceList(Request $request) : \think\Response
  182. {
  183. $params=$request->param();
  184. $record=$params['record'];
  185. $fence_list=array();
  186. $alarm_list=$record['alarm_reason_list'];
  187. foreach($alarm_list as $val){
  188. $fence_id=Db::table('alarm_report')
  189. ->where('device_number',$record['imei'])
  190. ->where('alarm_type',$val['value'])
  191. ->order('id', 'desc')
  192. ->value('fence_id');
  193. if($fence_id){
  194. $fence_info=$this->fencesModel->where('id',$fence_id)->append(['type_name','in_fence_time_area_text','out_fence_time_area_text','department_name','level'])->find();
  195. if($fence_info){
  196. //$fence_info['department_name']=Db::table('departments')->where('id',$fence_info['departments'])->value('department_name');
  197. $fence_list[]=$fence_info;
  198. }
  199. }
  200. }
  201. return CatchResponse::success($fence_list);
  202. }
  203. /**
  204. * 查询设备轨迹
  205. * @time 2022年09月18日 10:15
  206. *
  207. */
  208. public function queryDeviceRoute(Request $request) : \think\Response
  209. {
  210. $params=$request->param();
  211. $device_number = $params['device_number'];
  212. $route_type = $params['route_type'];
  213. if(isset($params['filter_track']) && $params['filter_track']=='true'){
  214. $this->filterTrack = true;
  215. }else{
  216. $this->filterTrack = false;
  217. }
  218. if (!$device_number) {
  219. return CatchResponse::fail("获取设备号失败");
  220. }
  221. $start_time = strtotime(date('Y-m-d').'00:00:00');
  222. $end_time = strtotime(date('Y-m-d').'23:59:59');
  223. if(isset($params['time_range']) && $params['time_range'] != ''){
  224. $start_time=strtotime($params['time_range'][0]);
  225. $end_time=strtotime($params['time_range'][1]);
  226. }
  227. $options=array(
  228. 'device_number'=>$device_number,
  229. 'start_time'=>$start_time,
  230. 'end_time'=>$end_time,
  231. 'table_name'=>'wxt_route_gps'
  232. );
  233. $res = queryTableStoreGpsRoute($options);
  234. $rows=$res['data'];
  235. if(Env::get('map.wifiwayz')){
  236. $rows = $this->analyzeRouteInfoWayzBatch($rows,$route_type);
  237. $rows=bmapFilterOutliers($rows);
  238. }else{
  239. $rows = $this->analyzeRouteInfoGaodeBatch($rows,$route_type);
  240. }
  241. return CatchResponse::success($rows);
  242. }
  243. /**
  244. * 批量解析含wifi信号Gps wayz
  245. */
  246. public function analyzeRouteInfoWayzBatch($list,$route_type='All'){
  247. if(!$list){
  248. return array();
  249. }
  250. $macLength=0;
  251. foreach($list as $item){
  252. if(isset($item['WifiMacs']) && $item['WifiMacs'] !=''){
  253. $macLength++;
  254. }
  255. }
  256. $arr= [];
  257. $preTime=0;
  258. $filter=0;//默认不过滤
  259. $wifiPreTime=0;
  260. $wifiFilter=0;//默认不过滤
  261. $count=count($list);
  262. if(!$this->filterTrack){
  263. if($count>1000){
  264. $filter=60;
  265. }elseif($count>500){
  266. $filter=30;
  267. }
  268. if($macLength>2000){
  269. $wifiFilter=600;
  270. }elseif($macLength>1000){
  271. $wifiFilter=300;
  272. }elseif($macLength>500){
  273. $wifiFilter=120;
  274. }else{
  275. $wifiFilter=30;
  276. }
  277. }
  278. $batch_wifi=array();
  279. foreach($list as $k=> $v){
  280. if($filter>0){//gps点过多时间也过滤部分
  281. $interval=abs($v['Timestamp']-$preTime);
  282. if( $interval < $filter){
  283. continue;
  284. }
  285. }
  286. if(isset($v['WifiMacs']) && $v['WifiMacs'] !=''){
  287. $wifiInterval=abs($v['Timestamp']-$wifiPreTime);
  288. if( $wifiInterval < $wifiFilter){
  289. continue;
  290. }
  291. if($route_type=='GPS'){
  292. continue;
  293. }
  294. $batch_wifi[$k]=$v;
  295. if(count($batch_wifi)==20 || $k==($count-1)){
  296. $wifiRes =requestWifiLBS_wayz_batch($batch_wifi);
  297. foreach($wifiRes as $key=>$value){
  298. if($value['success']){
  299. if($value['data']['lon'] == '' || is_null($value['data']['lat'])){
  300. continue;
  301. }
  302. $list[$key]['Latitude'] = $value['data']['lat'];
  303. $list[$key]['Longitude'] = $value['data']['lon'];
  304. $list[$key]['SignalType'] = 'WiFi';
  305. // $list[$key]['WifiAddress'] = $value['data']['address'];
  306. if(isset($value['data']['address'])){
  307. $list[$key]['WifiAddress'] = $value['data']['address'];
  308. }
  309. $arr[$key]=$list[$key];
  310. //array_push($arr, $list[$k]);
  311. }else{
  312. continue;
  313. }
  314. }
  315. $batch_wifi=array();
  316. }
  317. $wifiPreTime=$v['Timestamp'];
  318. }else{
  319. if($route_type=='WiFi'){
  320. continue;
  321. }
  322. if($v['Altitude']=='0.003' || $v['Altitude']=='3'){
  323. continue;
  324. }
  325. if( !isset($v['Latitude']) || !isset($v['Longitude']) || $v['Latitude']<0.065 || $v['Longitude']<0.065){
  326. continue;
  327. }
  328. $list[$k]['SignalType'] = 'GPS';
  329. $arr[$k]=$list[$k];
  330. //array_push($arr, $list[$k]);
  331. }
  332. $preTime=$v['Timestamp'];
  333. }
  334. //防止最后剩余wifi点未更新
  335. if($batch_wifi){
  336. $wifiRes =requestWifiLBS_wayz_batch($batch_wifi);
  337. foreach($wifiRes as $key=>$value){
  338. if($value['success']){
  339. if($value['data']['lon'] == '' || is_null($value['data']['lat'])){
  340. continue;
  341. }
  342. $list[$key]['Latitude'] = $value['data']['lat'];
  343. $list[$key]['Longitude'] = $value['data']['lon'];
  344. $list[$key]['SignalType'] = 'WiFi';
  345. // $list[$key]['WifiAddress'] = $value['data']['address'];
  346. if(isset($value['data']['address'])){
  347. $list[$key]['WifiAddress'] = $value['data']['address'];
  348. }
  349. $arr[$key]=$list[$key];
  350. //array_push($arr, $list[$k]);
  351. }else{
  352. continue;
  353. }
  354. }
  355. $batch_wifi=array();
  356. }
  357. ksort($arr);
  358. $response_data=[];
  359. foreach($arr as $item){
  360. array_push($response_data, $item);
  361. }
  362. return $response_data;
  363. }
  364. /**
  365. * 批量解析含wifi信号Gps 高德
  366. */
  367. public function analyzeRouteInfoGaodeBatch($list,$route_type='All'){
  368. if(!$list){
  369. return array();
  370. }
  371. $macLength=0;
  372. foreach($list as $item){
  373. if(isset($item['WifiMacs']) && $item['WifiMacs'] !=''){
  374. $macLength++;
  375. }
  376. }
  377. $arr= [];
  378. $preTime=0;
  379. $filter=0;//默认不过滤
  380. $wifiPreTime=0;
  381. $wifiFilter=0;//默认不过滤
  382. $count=count($list);
  383. if(!$this->filterTrack){
  384. if($count>1000){
  385. $filter=60;
  386. }elseif($count>500){
  387. $filter=30;
  388. }
  389. if($macLength>2000){
  390. $wifiFilter=600;
  391. }elseif($macLength>1000){
  392. $wifiFilter=300;
  393. }elseif($macLength>500){
  394. $wifiFilter=120;
  395. }else{
  396. $wifiFilter=30;
  397. }
  398. }
  399. $batch_wifi=array();
  400. foreach($list as $k=> $v){
  401. if($filter>0){//gps点过多时间也过滤部分
  402. $interval=abs($v['Timestamp']-$preTime);
  403. if( $interval < $filter){
  404. continue;
  405. }
  406. }
  407. if(isset($v['WifiMacs']) && $v['WifiMacs'] !=''){
  408. $wifiInterval=abs($v['Timestamp']-$wifiPreTime);
  409. if( $wifiInterval < $wifiFilter){
  410. continue;
  411. }
  412. if($route_type=='GPS'){
  413. continue;
  414. }
  415. $batch_wifi[$k]=$v;
  416. if(count($batch_wifi)==8|| $k==($count-1)){
  417. $wifiRes =requestWifiLBS_gaode_batch($batch_wifi);
  418. foreach($wifiRes as $key=>$value){
  419. if($value['success']){
  420. if($value['data']['lon'] == '' || is_null($value['data']['lat'])){
  421. continue;
  422. }
  423. $list[$key]['Latitude'] = $value['data']['lat'];
  424. $list[$key]['Longitude'] = $value['data']['lon'];
  425. $list[$key]['SignalType'] = 'WiFi';
  426. $list[$key]['WifiAddress'] = $value['data']['address'];
  427. $arr[$key]=$list[$key];
  428. //array_push($arr, $list[$k]);
  429. }else{
  430. continue;
  431. }
  432. }
  433. $batch_wifi=array();
  434. }
  435. $wifiPreTime=$v['Timestamp'];
  436. }else{
  437. if($route_type=='WiFi'){
  438. continue;
  439. }
  440. if($v['Altitude']=='0.003' || $v['Altitude']=='3'){
  441. continue;
  442. }
  443. if( !isset($v['Latitude']) || !isset($v['Longitude']) || $v['Latitude']<0.065 || $v['Longitude']<0.065){
  444. continue;
  445. }
  446. $list[$k]['SignalType'] = 'GPS';
  447. $arr[$k]=$list[$k];
  448. //array_push($arr, $list[$k]);
  449. }
  450. $preTime=$v['Timestamp'];
  451. }
  452. if($batch_wifi){
  453. $wifiRes =requestWifiLBS_gaode_batch($batch_wifi);
  454. foreach($wifiRes as $key=>$value){
  455. if($value['success']){
  456. if($value['data']['lon'] == '' || is_null($value['data']['lat'])){
  457. continue;
  458. }
  459. $list[$key]['Latitude'] = $value['data']['lat'];
  460. $list[$key]['Longitude'] = $value['data']['lon'];
  461. $list[$key]['SignalType'] = 'WiFi';
  462. $list[$key]['WifiAddress'] = $value['data']['address'];
  463. $arr[$key]=$list[$key];
  464. //array_push($arr, $list[$k]);
  465. }else{
  466. continue;
  467. }
  468. }
  469. $batch_wifi=array();
  470. }
  471. $response_data=[];
  472. ksort($arr);
  473. foreach($arr as $key=>$item){
  474. array_push($response_data, $item);
  475. }
  476. return $response_data;
  477. }
  478. /**
  479. * 查询设备轨迹
  480. * @time 2022年09月18日 10:15
  481. *
  482. */
  483. public function queryDeviceRouteOracle(Request $request) : \think\Response
  484. {
  485. $params=$request->param();
  486. $device_number = trim($params['device_number']);
  487. if (!$device_number) {
  488. return CatchResponse::fail("获取设备号失败");
  489. }
  490. $start_time = date('Y-m-d 00:00:00',time());
  491. $end_time = date('Y-m-d 23:59:59',time());
  492. if(isset($params['time_range']) && $params['time_range'] != ''){
  493. $start_time=date('Y-m-d H:i:s',strtotime($params['time_range'][0]));
  494. $end_time=date('Y-m-d H:i:s',strtotime($params['time_range'][1]));
  495. }
  496. $host= Env::get('oracle.hostname', '127.0.0.1');
  497. $port= Env::get('oracle.hostport', '1521');
  498. $instance_name= Env::get('oracle.instance', 'ORCL');
  499. $username= Env::get('oracle.username', 'root');
  500. $password= Env::get('oracle.password', 'root');
  501. $conn = oci_connect($username, $password, $host.':'.$port.'/'.$instance_name,'AL32UTF8');
  502. if (!$conn) {
  503. $e = oci_error();
  504. trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
  505. }
  506. $sql='SELECT * FROM (SELECT a.RF_ID,a.RF_FLAGID,to_char(a.RF_DATE,\'yyyy-mm-dd hh24:mi:ss\') RF_DATE,ROWNUM rn,b.DEVICE_NAME,b.DEVICE_CODE,b.LOGIN_NAME,c.GPS_X,c.GPS_Y FROM DSSC2.W_DW_RF_RECORD a join DSSC2.ADM_DEV b ON a.RF_ID=b.LOGIN_NAME join DSSC2.ADM_DEV_RFID_CHN c ON b.DEVICE_CODE=c.DEVICE_CODE WHERE RF_FLAGID=\''.$device_number.'\' AND RF_DATE >= to_date(\''. $start_time.'\', \'yyyy-mm-dd hh24:mi:ss\') AND RF_DATE <= to_date(\''.$end_time.'\', \'yyyy-mm-dd hh24:mi:ss\') ORDER BY RF_DATE DESC) WHERE ROWNUM <= 5000';
  507. // // 查询并渲染
  508. $stid = oci_parse($conn, $sql);
  509. // var_dump($stid);
  510. $r = oci_execute($stid);
  511. // var_dump($r);
  512. $rows=[];
  513. while($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
  514. // $wgsLoc = \algorithm\Geometry::wgsTOgcj($row['GPS_Y'],$row['GPS_X']);
  515. $wgsLoc = \algorithm\Geometry::gcj02ToWgs84((float)$row['GPS_Y'],(float)$row['GPS_X']);
  516. // $lngLat = \algorithm\Geometry::convertGcj02ToBd09($wgsLoc['lat'],$wgsLoc['lng']);
  517. $row['GPS_X']=$wgsLoc['lng'];
  518. $row['GPS_Y']=$wgsLoc['lat'];
  519. $rows[]=$row;
  520. }
  521. // var_dump($rows);
  522. oci_free_statement($stid);
  523. oci_close($conn);
  524. // $conn = new PDO("oci:dbname=//".$host.":".$port."/".$instance_name,$username,$password);// PDO方式
  525. // $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  526. // // $sql='SELECT * FROM (SELECT a.*, ROWNUM rn FROM DSS2.W_DW_RF_RECORD a WHERE RF_FLAGID=\''.$device_number.'\' AND RF_DATE >= to_date(\''. $start_time.'\', \'yyyy-mm-dd hh24:mi:ss\') AND RF_DATE <= to_date(\''.$end_time.'\', \'yyyy-mm-dd hh24:mi:ss\') ORDER BY RF_DATE DESC) WHERE ROWNUM <= 5000';
  527. // $sql='SELECT * FROM (SELECT a.RF_ID,a.RF_FLAGID,to_char(a.RF_DATE,\'yyyy-mm-dd hh24:mi:ss\') RF_DATE,ROWNUM rn,b.DEVICE_NAME,b.DEVICE_CODE,b.LOGIN_NAME,c.GPS_X,c.GPS_Y FROM DSSC2.W_DW_RF_RECORD a join DSSC2.ADM_DEV b ON a.RF_ID=b.LOGIN_NAME join DSSC2.ADM_DEV_RFID_CHN c ON b.DEVICE_CODE=c.DEVICE_CODE WHERE RF_FLAGID=\''.$device_number.'\' AND RF_DATE >= to_date(\''. $start_time.'\', \'yyyy-mm-dd hh24:mi:ss\') AND RF_DATE <= to_date(\''.$end_time.'\', \'yyyy-mm-dd hh24:mi:ss\') ORDER BY RF_DATE DESC) WHERE ROWNUM <= 5000';
  528. // // var_dump($sql);
  529. // $res = $conn -> query($sql);
  530. // $rows = $res -> fetchAll(PDO::FETCH_ASSOC);
  531. // foreach($rows as &$val){
  532. // $val['DEVICE_NAME'] = mb_convert_encoding($val['DEVICE_NAME'], 'UTF-8', 'GBK');
  533. // // $val['RF_DATE'] = mb_convert_encoding($val['RF_DATE'], 'UTF-8', 'GBK');
  534. // $wgsLoc = \algorithm\Geometry::wgsTOgcj($val['GPS_Y'],$val['GPS_X']);
  535. // $lngLat = \algorithm\Geometry::convertGcj02ToBd09($wgsLoc['lat'],$wgsLoc['lng']);
  536. // $val['GPS_X']=$lngLat['lng'];
  537. // $val['GPS_Y']=$lngLat['lat'];
  538. // // $val['timeInt']=strtotime($val['RF_DATE']);
  539. // }
  540. // if ($conn){
  541. // $conn = null;
  542. // }
  543. // $rows=[];
  544. return CatchResponse::success($rows);
  545. }
  546. /**
  547. * 查询设备轨迹
  548. * @time 2022年09月18日 10:15
  549. *
  550. */
  551. public function queryDeviceRouteList(Request $request)
  552. {
  553. $params=$request->param();
  554. if($params['route_type']!='1'){
  555. $response=[
  556. 'code'=>10000,
  557. 'message'=>'查询成功',
  558. 'count'=>0,
  559. 'data'=>[],
  560. 'current'=>isset($params['page'])?(int)$params['page']:1,
  561. 'limit'=>isset($params['limit'])?(int)$params['limit']:10,
  562. ];
  563. return $response;
  564. }
  565. $cond=[];
  566. // $cond=[
  567. // '_string'=>'a.RF_FLAGID = s.RFID_SN AND o.rfid_id = s.id',
  568. // ];
  569. if($params['name']){
  570. $mac=Db::table('stations')->whereLike('name',$params['name'])->value('mac');
  571. $cond['RF_ID']=['=',$mac];
  572. }
  573. if($params['rfid_sn']){
  574. $cond['RF_FLAGID']=['=',$params['rfid_sn']];
  575. }
  576. $conn=getOracleConnect();
  577. if($params['plate_no']){
  578. $rfid_sn='';
  579. $vehicle_sql='SELECT s.RFID_SN FROM DSSC3.W_DW_NON_MOTOR o,DSSC3.W_DW_RFID_TAGS s WHERE o.PLATE_NO =\''.$params['plate_no'].'\' AND o.rfid_id = s.id ';
  580. $vtid = oci_parse($conn, $vehicle_sql);
  581. oci_define_by_name($vtid, 'RFID_SN', $rfid_sn);
  582. oci_execute($vtid);
  583. oci_fetch($vtid);
  584. $cond['RF_FLAGID']=['=',$rfid_sn];
  585. }
  586. $start_time = date('Y-m-d 00:00:00',time());
  587. $end_time = date('Y-m-d 23:59:59',time());
  588. if(isset($params['timeRange']) && $params['timeRange'] != ''){
  589. $start_time=date('Y-m-d H:i:s',strtotime($params['timeRange'][0]));
  590. $end_time=date('Y-m-d H:i:s',strtotime($params['timeRange'][1]));
  591. $cond['a.RF_DATE']=['timeRange',$start_time,$end_time];
  592. }
  593. // $count=queryOracleCount('DSSC2.W_DW_RF_RECORD a',$cond);
  594. $cond['page']=isset($params['page'])?$params['page']:1;
  595. $cond['limit']=isset($params['limit'])?$params['limit']:10;
  596. $rows=[];
  597. $rows=queryOracleSelect('(SELECT * FROM DSSC2.W_DW_RF_RECORD ORDER BY ID DESC) a',$cond,'a.RF_FLAGID,a.RF_STAT,a.RF_ID,to_char(a.RF_DATE,\'yyyy-mm-dd hh24:mi:ss\') RF_DATE');
  598. foreach($rows as &$val){
  599. $vehicle_sql='SELECT o.PLATE_NO FROM DSSC3.W_DW_NON_MOTOR o,DSSC3.W_DW_RFID_TAGS s WHERE s.RFID_SN =\''.$val['RF_FLAGID'].'\' AND o.rfid_id = s.id ';
  600. $plate_no='';
  601. $stid = oci_parse($conn, $vehicle_sql);
  602. oci_define_by_name($stid, 'PLATE_NO', $plate_no);
  603. oci_execute($stid);
  604. oci_fetch($stid);
  605. oci_free_statement($stid);
  606. $val['PLATE_NO']=$plate_no;
  607. $val['ADDRESS']=Db::table('stations')->where('mac',$val['RF_ID'])->cache(120)->value('name');
  608. //状态: 0- 未知,1 - 进入,2 - 离开
  609. if($val['RF_STAT']==1){
  610. $val['RF_STAT_TEXT']='进入';
  611. }elseif($val['RF_STAT']==2){
  612. $val['RF_STAT_TEXT']='离开';
  613. }else{
  614. $val['RF_STAT_TEXT']='未知';
  615. }
  616. }
  617. oci_close($conn);
  618. $response=[
  619. 'code'=>10000,
  620. 'message'=>'查询成功',
  621. // 'count'=>$count,
  622. 'data'=>$rows,
  623. 'current'=>isset($params['page'])?(int)$params['page']:1,
  624. 'limit'=>isset($params['limit'])?(int)$params['limit']:10,
  625. ];
  626. return $response;
  627. }
  628. /**
  629. * 统计条数
  630. * @time 2022年09月18日 10:15
  631. *
  632. */
  633. public function queryDeviceRouteCount(Request $request)
  634. {
  635. $params=$request->param();
  636. if($params['route_type']!='1'){
  637. $response=[
  638. 'code'=>10000,
  639. 'message'=>'查询成功',
  640. 'count'=>0,
  641. ];
  642. return $response;
  643. }
  644. $cond=[];
  645. // $cond=[
  646. // '_string'=>'a.RF_FLAGID = s.RFID_SN AND o.rfid_id = s.id',
  647. // ];
  648. if($params['name']){
  649. $mac=Db::table('stations')->whereLike('name',$params['name'])->value('mac');
  650. $cond['RF_ID']=['=',$mac];
  651. }
  652. if($params['rfid_sn']){
  653. $cond['RF_FLAGID']=['=',$params['rfid_sn']];
  654. }
  655. if($params['plate_no']){
  656. $conn=getOracleConnect();
  657. $rfid_sn='';
  658. $vehicle_sql='SELECT s.RFID_SN FROM DSSC3.W_DW_NON_MOTOR o,DSSC3.W_DW_RFID_TAGS s WHERE o.PLATE_NO =\''.$params['plate_no'].'\' AND o.rfid_id = s.id ';
  659. $vtid = oci_parse($conn, $vehicle_sql);
  660. oci_define_by_name($vtid, 'RFID_SN', $rfid_sn);
  661. oci_execute($vtid);
  662. oci_fetch($vtid);
  663. $cond['RF_FLAGID']=['=',$rfid_sn];
  664. }
  665. $start_time = date('Y-m-d 00:00:00',time());
  666. $end_time = date('Y-m-d 23:59:59',time());
  667. if(isset($params['timeRange']) && $params['timeRange'] != ''){
  668. $start_time=date('Y-m-d H:i:s',strtotime($params['timeRange'][0]));
  669. $end_time=date('Y-m-d H:i:s',strtotime($params['timeRange'][1]));
  670. $cond['a.RF_DATE']=['timeRange',$start_time,$end_time];
  671. }
  672. $count=queryOracleCount('DSSC2.W_DW_RF_RECORD a',$cond);
  673. $response=[
  674. 'code'=>10000,
  675. 'message'=>'查询成功',
  676. 'count'=>$count,
  677. ];
  678. return $response;
  679. }
  680. /**
  681. * 统计条数
  682. * @time 2022年09月18日 10:15
  683. *
  684. */
  685. public function queryCountSearchDevice(Request $request)
  686. {
  687. $params=$request->param();
  688. $cond=[];
  689. $keywords=$params['keywords'];
  690. if(!$keywords){
  691. return [
  692. 'code'=>10000,
  693. 'message'=>'查询成功',
  694. 'station'=>0,
  695. 'vehicle'=>0,
  696. ];
  697. }
  698. $station_count=Db::table('stations')->where('name|mac', 'like', '%'.$keywords.'%')->count();
  699. $conn=getOracleConnect();
  700. $COUNT=0;
  701. $vehicle_sql='SELECT count(*) as COUNT FROM DSSC3.W_DW_NON_MOTOR o,DSSC3.W_DW_RFID_TAGS s WHERE (s.RFID_SN like \'%'.$keywords.'%\' OR o.PLATE_NO like \'%'.$keywords.'%\') AND o.rfid_id = s.id';
  702. $vtid = oci_parse($conn, $vehicle_sql);
  703. oci_define_by_name($vtid, 'COUNT', $COUNT);
  704. oci_execute($vtid);
  705. oci_fetch($vtid);
  706. oci_free_statement($vtid);
  707. oci_close($conn);
  708. $response=[
  709. 'code'=>10000,
  710. 'message'=>'查询成功',
  711. 'station'=>$station_count,
  712. 'vehicle'=>$COUNT,
  713. ];
  714. return $response;
  715. }
  716. }