123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353 |
- <?php
- namespace catchAdmin\map\controller;
- use catcher\base\CatchRequest as Request;
- use catcher\CatchResponse;
- use catcher\base\CatchController;
- use Aliyun\OTS\OTSClient;
- use catchAdmin\hydraulic\model\HydEquipment as deviceModel;
- use catchAdmin\fences\model\Fences as fencesModel;
- use catchAdmin\hydraulic\model\HydEquipment;
- use think\facade\Db;
- use think\facade\Env;
- class RouteMap extends CatchController
- {
- protected $deviceModel;
- protected $fencesModel;
- protected $filterTrack=false;
- public function __construct(deviceModel $deviceModel,fencesModel $fencesModel)
- {
- $this->deviceModel = $deviceModel;
- $this->fencesModel = $fencesModel;
- }
-
- /**
- * 列表
- * @time 2021年05月18日 10:15
- * @param Request $request
- */
- public function queryDeviceList(Request $request) : \think\Response
- {
- $list =$this->deviceModel->getList();
- return CatchResponse::paginate($list);
- }
- /**
- * 列表
- * @time 2021年05月18日 10:15
- * @param Request $request
- */
- public function queryDeviceRealTimeInfo(Request $request) : \think\Response
- {
- $params=$request->param();
- if(!isset($params['imeis'])){
- return CatchResponse::success([]);
- }
- // var_dump($params);
- $imeis=$params['imeis'];
-
- $list=$this->deviceModel->whereIn('imei',$imeis)->select();
- foreach ($list as &$value) {
- $value['status_icon']='run';
- $value['status']='在线';
- }
- // var_dump($list);
- return CatchResponse::success($list);
- }
- /**
- * @Descripttion: 工具柜列表
- * @name: likang
- * @param {Request} $request
- * @return {*}
- */
- public function queryWorkBoxMap(Request $request)
- {
- $hy = new HydEquipment();
- return CatchResponse::paginate($hy->getList());
- }
- /**
- *
- * @time 2021年05月24日
- * @return \think\response\Json
- */
- public function queryLocationList(Request $request): \think\Response
- {
- return CatchResponse::success($this->deviceModel->queryLocationList());
- }
-
-
-
-
- /**
- *
- * @time 2021年05月24日
- * @return \think\response\Json
- */
- public function queryFenceList(Request $request): \think\Response
- {
- $list=DB::table('fences')->where('fence_type',0)->select()->toArray();
- foreach($list as &$val){
- $user_depart=Db::table('users')->where('id',$val['creator_id'])->value('department_id');
- $creator_level=Db::table('departments')->where('id',$user_depart)->value('level');
- if(!$creator_level){
- $val['level']=1;
- }else{
- $level_arr=explode('-',$creator_level);
- $val['level']=count($level_arr)+1;
- }
- }
- return CatchResponse::success($list);
- }
- /**
- * 查询当前定位
- * @time 2021年05月18日 10:15
- *
- */
- public function queryDeviceCurLocation(Request $request) : \think\Response
- {
- $params=$request->param();
- $device_number=$params['device_number'];
- if (!$device_number) {
- return CatchResponse::fail("获取设备号失败");
- }
- $device_info=$this->deviceModel->where('imei',$device_number)->find()->toArray();
- // var_dump($device_info);
- if($device_info['online_time']<$device_info['wifi_online_time']){
- $device_info['online_time']=$device_info['wifi_online_time'];
- $device_info['longitude']=$device_info['wifi_longitude'];
- $device_info['latitude']=$device_info['wifi_latitude'];
- }
- return CatchResponse::success($device_info);
- }
- /**
- * 查询学生轨迹RFid
- * @time 2021年05月18日 10:15
- *
- */
- public function queryStudentRouteRfid(Request $request) : \think\Response
- {
-
- $params=$request->param();
- $active_rfid=$params['active_rfid'];
- if (!$active_rfid) {
- return CatchResponse::fail("获取设备号失败");
- }
- $start_time = strtotime(date('Y-m-d 00:00:00'));
- $end_time = strtotime(date('Y-m-d 23:59:59'));
- if(isset($params['time_range']) && $params['time_range'] != ''){
- $start_time=strtotime($params['time_range'][0]);
- $end_time=strtotime($params['time_range'][1]);
- }
- // 非第三方设备从表格存储获取
- // $otsClient = new OTSClient (array (
- // 'EndPoint' => 'https://rlfd.cn-hangzhou.ots.aliyuncs.com',
- // 'AccessKeyID' => 'LTAI4FecTAyMPdhAdkUwhAGA',
- // 'AccessKeySecret' => 'Ih0knSSfcje3OUi1YrdjeXQZYIfmTK',
- // 'InstanceName' => 'rlfd',
- // ));
- $table_config=Db::table('sys_config')->where('type','table_store')->column('fieldValue','field');
- if(!isset($table_config['EndPoint']) || !isset($table_config['AccessKeyID']) || !isset($table_config['AccessKeySecret']) || !isset($table_config['InstanceName'])){
- return CatchResponse::fail("请先配置表格存储");
- }
- $otsClient = new OTSClient (array (
- 'EndPoint' => $table_config['EndPoint'],
- 'AccessKeyID' => $table_config['AccessKeyID'],
- 'AccessKeySecret' => $table_config['AccessKeySecret'],
- 'InstanceName' => $table_config['InstanceName'],
- ));
- $otsClient->getClientConfig()->debugLogHandler = null;
- $otsClient->getClientConfig()->errorLogHandler = null;
- // var_dump($otsClient);
- ini_set('memory_limit', '512M');
- $startPK = array (
- array('DeviceNumber',$active_rfid),
- array('Timestamp', $start_time)
- // array('Timestamp', 1620885120)
- );
- $endPK = array (
- array('DeviceNumber', $active_rfid),
- array('Timestamp', $end_time)
- // array('Timestamp', 1620885441)
- );
- $limit = 5500;
-
- $rows=[];
- while (! empty ($startPK) && $limit > 0) {
- $request = array (
- 'table_name' => 'wxt_route_rfid',
- 'max_versions' => 1,
- 'direction' => 'BACKWARD', // 方向可以为 FORWARD 或者 BACKWARD
- 'inclusive_start_primary_key' => $endPK, // 开始主键
- 'exclusive_end_primary_key' => $startPK, // 结束主键
- 'limit' => $limit
- );
-
-
- $response = [];
- try {
- $response = $otsClient->getRange($request);
- } catch (\Exception $e) {
- // var_dump($e);
- }
-
- if (!isset($response['rows'])){
- return CatchResponse::success([]);
- }
-
- foreach ($response['rows'] as $rowData) {
- // $str=($limit-4000)/2000;
- $item=[];
- foreach($rowData['primary_key'] as $keyItem){
- $item[$keyItem[0]]=$keyItem[1];
- }
- foreach($rowData['attribute_columns'] as $colItem){
- $item[$colItem[0]]=$colItem[1];
- }
- $station_info=Db::table('station')->where('station_code',$item['StationCode'])->find();
- if($station_info['station_type']==3){
- $school_name=Db::table('departments')->where('id',$station_info['school_id'])->cache(60)->value('department_name');
- $build_name=Db::table('kq_building')->where('id',$station_info['building_id'])->cache(60)->value('name');
- $floor_name=Db::table('kq_floor')->where('id',$station_info['floor_id'])->cache(60)->value('name');
- $station_address=$school_name.' '.$build_name.' '.$floor_name.' '.$station_info['room_no'].'房间';
- $item['Address']=$station_address;
- }else{
- $item['Address']=$station_info['address'];
- }
-
- $item['PassTime']=date('Y-m-d H:i:s',$item['Timestamp']);
- // $item['Longitude']+=$str;
- // $item['Latitude']+=$str;
- $rows[]=$item;
- $limit --;
- // 处理每一行数据
- }
-
- $startPK = $response['next_start_primary_key'];
- // 如果 next_start_primary_key 不为空并且 limit > 0 则循环继续
- }
- // var_dump($rows);
- return CatchResponse::success($rows);
-
- }
- /**
- * 查询学生轨迹GPS
- * @time 2021年05月18日 10:15
- *
- */
- public function queryDeviceRouteGps(Request $request) : \think\Response
- {
-
- $params=$request->param();
- // var_dump($params);
- // var_dump(strtotime($params['aData']));
- $device_number = $params['imei'];
- if (!$device_number) {
- return CatchResponse::fail("获取设备号失败");
- }
- if($params['time']==0 && isset($params['time_range']) && $params['time_range'] != ''){
- $start_time=strtotime($params['time_range'][0]);
- $end_time=strtotime($params['time_range'][1]);
-
- }else{
- $start_time = time()-$params['time'];
- $end_time=time();
- }
-
- $options=array(
- 'device_number'=>$device_number,
- 'start_time'=>$start_time,
- 'end_time'=>$end_time,
- 'table_name'=>'wxt_route_gps'
- );
- $res = queryTableStoreGpsRoute($options);
- if($res['success']){
- $data=$res['data'];
- $battery_level=Db::table('devices')->where('imei',$device_number)->value('battery_level');
- foreach($data as &$val){
- $val['Longitude']=round($val['Longitude'],6);
- $val['Latitude']=round($val['Latitude'],6);
- $val['SignalType']='GPS';
- $val['BatteryLevel']=$battery_level;
-
- }
- return CatchResponse::success($data);
- }else{
- return CatchResponse::fail($res['message']);
- }
-
-
-
-
- }
-
- /**
- * 查询相关建筑信息
- * @time 2021年05月18日 10:15
- * @param Request $request
- */
- public function queryBuildingInfo(Request $request) : \think\Response
- {
- $params=$request->param();
-
- $building_id=Db::table('station')->where('station_mac',$params['station_mac'])->value('building_id');
- $build_info=Db::table('kq_building')->where('id',$building_id)->find();
- $student_info=Db::table('users')->where('active_rfid',$params['active_rfid'])->find();
- $res=array('build_info'=>$build_info,'student_info'=>$student_info);
- return CatchResponse::success($res);
- }
- /**
- * 查询告警相关围栏信息
- * @time 2021年05月18日 10:15
- * @param Request $request
- */
- public function queryAlarmFenceList(Request $request) : \think\Response
- {
- $params=$request->param();
- $record=$params['record'];
- $fence_list=array();
- $alarm_list=$record['alarm_reason_list'];
- foreach($alarm_list as $val){
- $fence_id=Db::table('alarm_report')
- ->where('device_number',$record['imei'])
- ->where('alarm_type',$val['value'])
- ->order('id', 'desc')
- ->value('fence_id');
- if($fence_id){
- $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();
- if($fence_info){
- //$fence_info['department_name']=Db::table('departments')->where('id',$fence_info['departments'])->value('department_name');
- $fence_list[]=$fence_info;
- }
-
- }
- }
- return CatchResponse::success($fence_list);
- }
-
-
- }
|