|
|
@@ -212,7 +212,7 @@ class ScreenService extends Service
|
|
|
$message = SystemlService::getLastData(array_column($data['data'],'code'));
|
|
|
foreach ($data['data'] as $key => $value){
|
|
|
$is_online = $is_exception = 0;
|
|
|
- if(isset($message[$value['code']])){
|
|
|
+ if(! empty($message[$value['code']])){
|
|
|
$is_online = 1;
|
|
|
$tmp = $message[$value['code']];
|
|
|
if(in_array($value['device_type_id'],DeviceType::$node_two)){
|
|
|
@@ -437,11 +437,13 @@ class ScreenService extends Service
|
|
|
'province' => '',
|
|
|
'city' => '',
|
|
|
'district' => '',
|
|
|
- 'location' => '',
|
|
|
+ 'location' => [],
|
|
|
'temperature' => [],
|
|
|
- 'humidity' => []
|
|
|
+ 'humidity' => [],
|
|
|
+ 'screen_num' => 1,
|
|
|
];
|
|
|
|
|
|
+ //选中仓的 传感器设备和定位设备信息
|
|
|
$device = ScreenDevice::from('screen_device as a')
|
|
|
->leftJoin('device as b','b.id','a.device_id')
|
|
|
->whereIn('b.device_type_id',[DeviceType::type_one,DeviceType::type_four])
|
|
|
@@ -460,33 +462,28 @@ class ScreenService extends Service
|
|
|
}
|
|
|
|
|
|
//gps定位
|
|
|
- $return_gps = SystemlService::getLastData($gps);
|
|
|
+ $time = strtotime('-60 min',time());
|
|
|
+ $time = $time * 1000;
|
|
|
+ $model = SystemL::whereIn('device_no', $gps)
|
|
|
+ ->select('value','time','device_no','data_point_name')
|
|
|
+ ->orderBy('id','desc');
|
|
|
+ $model->where('time','>=',$time);
|
|
|
+ $return_gps = $model->get()->toArray();
|
|
|
if(! empty($return_gps)){
|
|
|
- $first_position = "";
|
|
|
+ $first_postition = "";
|
|
|
+ $location = [];
|
|
|
foreach ($return_gps as $value){
|
|
|
- if(! empty ($first_postition)) continue;
|
|
|
- $first_position = $value['value'];
|
|
|
- }
|
|
|
- $url = 'https://restapi.amap.com/v3/geocode/regeo?location='.$first_position.'&key='.SystemL::GaoDeMapKey;
|
|
|
- try{
|
|
|
- $return = $this->curlOpen($url);
|
|
|
- $return = json_decode($return,true);
|
|
|
- if(! empty($return['status'])){
|
|
|
- $position = $return['regeocode']['addressComponent'] ?? [];
|
|
|
- $result = [
|
|
|
- 'province' => $position['province'] ?? '',
|
|
|
- 'city' => $position['city'] ?? '',
|
|
|
- 'district' => $position['district'] ?? '',
|
|
|
- 'location' => $first_position
|
|
|
- ];
|
|
|
+ if(empty($first_postition)) {
|
|
|
+ $first_postition = $value['value'];
|
|
|
}
|
|
|
- }catch (\Exception $exception){
|
|
|
-// return [false,$exception->getMessage()];
|
|
|
+ $location[] = $value['value'];
|
|
|
}
|
|
|
+ $result['location'] = $location;
|
|
|
+ $this->getLocation($first_postition,$result);
|
|
|
}
|
|
|
|
|
|
//温度湿度
|
|
|
- $time = strtotime('-2 min',time());
|
|
|
+ $time = strtotime('-1440 min',time());
|
|
|
$time = $time * 1000;
|
|
|
$model = SystemL::whereIn('device_no', $other)
|
|
|
->select('value','time','device_no','data_point_name')
|
|
|
@@ -497,6 +494,34 @@ class ScreenService extends Service
|
|
|
$result['temperature'] = $chart['temperature'];
|
|
|
$result['humidity'] = $chart['humidity'];
|
|
|
|
|
|
+ //同一区域有几个仓
|
|
|
+ $counts = ScreenDevice::from('screen_device as a')
|
|
|
+ ->leftJoin('device as b','b.id','a.device_id')
|
|
|
+ ->where('b.device_type_id',DeviceType::type_four)
|
|
|
+ ->where('a.del_time',0)
|
|
|
+ ->where('b.del_time',0)
|
|
|
+ ->where('a.screen_id','<>',$data['screen_id'])
|
|
|
+ ->select('b.code')
|
|
|
+ ->get()->toArray();
|
|
|
+ if(! empty($counts)){
|
|
|
+ $time = strtotime('-10 min',time());
|
|
|
+ $time = $time * 1000;
|
|
|
+ $model = SystemL::whereIn('device_no', $gps)
|
|
|
+ ->select('value','device_no')
|
|
|
+ ->orderBy('id','desc');
|
|
|
+ $model->where('time','>=',$time);
|
|
|
+ $return_other_gps = $model->get()->toArray();
|
|
|
+ if(! empty($return_other_gps)){
|
|
|
+ $code_p = [];
|
|
|
+ foreach ($return_other_gps as $value){
|
|
|
+ if(! isset($code_p[$value['device_no']]) && $value['value']) $code_p[$value['device_no']] = $value['value'];
|
|
|
+ }
|
|
|
+ if(! empty($code_p)){
|
|
|
+ $this->isSameLocation($code_p,$result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return [true, $result];
|
|
|
}
|
|
|
|
|
|
@@ -507,12 +532,12 @@ class ScreenService extends Service
|
|
|
foreach ($data as $value){
|
|
|
if (strstr($value['data_point_name'],'温度')){
|
|
|
$return1[$value['device_no']][] = [
|
|
|
- 'time' => date('Y-m-d H:i:s',$value['time'] / 1000),
|
|
|
+ 'time' => date('H:i:s',$value['time'] / 1000),
|
|
|
'value' => $value['value']
|
|
|
];
|
|
|
}elseif (strstr($value['data_point_name'],'湿度')){
|
|
|
$return2[$value['device_no']][] = [
|
|
|
- 'time' => date('Y-m-d H:i:s',$value['time'] / 1000),
|
|
|
+ 'time' => date('H:i:s',$value['time'] / 1000),
|
|
|
'value' => $value['value']
|
|
|
];
|
|
|
}
|
|
|
@@ -587,6 +612,7 @@ class ScreenService extends Service
|
|
|
foreach ($data as $key => $value){
|
|
|
if(isset($map[$value['id']])){
|
|
|
foreach ($return as $code => $val){
|
|
|
+ if(empty($val)) continue;
|
|
|
if(in_array($code,$map[$value['id']]) && isset($map2[$code])){
|
|
|
if(empty($data[$key]['temperature']) && $map2[$code] == DeviceType::type_one && strstr($val['data_point_name'],'温度')){
|
|
|
$data[$key]['temperature'] = $val['value'] . ($map3[$code] ?? '');
|
|
|
@@ -598,6 +624,16 @@ class ScreenService extends Service
|
|
|
$data[$key]['warning'] = $val['value'] ? '是' : '否';
|
|
|
}elseif(empty($data[$key]['gps']) && $map2[$code] == DeviceType::type_four){
|
|
|
$data[$key]['gps'] = $val['value'];
|
|
|
+ $tmp = [
|
|
|
+ 'province' => '',
|
|
|
+ 'city' => '',
|
|
|
+ 'district' => '',
|
|
|
+ ];
|
|
|
+ $this->getLocation($val['value'],$tmp);
|
|
|
+ $data[$key]['province'] = $tmp['province'];
|
|
|
+ $data[$key]['city'] = $tmp['city'];
|
|
|
+ $data[$key]['district'] = $tmp['district'];
|
|
|
+ $data[$key]['township'] = $tmp['township'];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -606,4 +642,36 @@ class ScreenService extends Service
|
|
|
|
|
|
return $data;
|
|
|
}
|
|
|
+
|
|
|
+ public function getLocation($position,&$result){
|
|
|
+ $url = 'https://restapi.amap.com/v3/geocode/regeo?location='.$position.'&key='.SystemL::GaoDeMapKey;
|
|
|
+ try{
|
|
|
+ $return = $this->curlOpen($url);
|
|
|
+ $return = json_decode($return,true);
|
|
|
+ if(! empty($return['status'])){
|
|
|
+ $position = $return['regeocode']['addressComponent'] ?? [];
|
|
|
+ $result['province'] = $position['province'] ?? '';
|
|
|
+ $result['city'] = $position['city'] ?? '';
|
|
|
+ $result['district'] = $position['district'] ?? '';
|
|
|
+ $result['township'] = $position['township'] ?? '';
|
|
|
+ }
|
|
|
+ }catch (\Exception $exception){
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function isSameLocation($position,&$result){
|
|
|
+ foreach ($position as $position_tmp){
|
|
|
+ $url = 'https://restapi.amap.com/v3/geocode/regeo?location='.$position_tmp.'&key='.SystemL::GaoDeMapKey;
|
|
|
+ try{
|
|
|
+ $return = $this->curlOpen($url);
|
|
|
+ $return = json_decode($return,true);
|
|
|
+ if(! empty($return['status'])){
|
|
|
+ $position_arr = $return['regeocode']['addressComponent'] ?? [];
|
|
|
+ $province = $position_arr['province'] ?? '';
|
|
|
+ if($province == $result['province']) $result['screen_num'] += 1;
|
|
|
+ }
|
|
|
+ }catch (\Exception $exception){
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|