|
@@ -108,7 +108,7 @@ class ScreenService extends Service
|
|
|
public function orderList($data){
|
|
|
$model = Screen::where('del_time',0)
|
|
|
->select('*')
|
|
|
- ->orderBy('id','desc');
|
|
|
+ ->orderBy('id','asc');
|
|
|
|
|
|
if(! empty($data['type'])) $model->where('type',$data['type']);
|
|
|
if(! empty($data['area_id'])) $model->where('area_id', $data['area_id']);
|
|
@@ -134,18 +134,22 @@ class ScreenService extends Service
|
|
|
if(empty($data['data'])) return $data;
|
|
|
|
|
|
$screen_id = array_column($data['data'],'id');
|
|
|
- $gateway_id = ScreenGateway::whereIn('screen_id',$screen_id)
|
|
|
+ $gateway = ScreenGateway::whereIn('screen_id',$screen_id)
|
|
|
->where('del_time',0)
|
|
|
- ->pluck('screen_id','gateway_id')
|
|
|
+ ->select('screen_id','gateway_id')
|
|
|
+ ->get()
|
|
|
->toArray();
|
|
|
//获取仓是否在线离线状态
|
|
|
- $online = SystemlService::getIsOnlineStatus($gateway_id);
|
|
|
+ $online = SystemlService::getIsOnlineStatus($gateway);
|
|
|
//获取Gps信号判断状态
|
|
|
$gps = SystemlService::getGpsStatus($screen_id);
|
|
|
//获取是否异常状态判断
|
|
|
$exception = SystemlService::getExceptionStatus($screen_id);
|
|
|
|
|
|
- $g_map = array_flip($gateway_id);
|
|
|
+ $g_map = [];
|
|
|
+ foreach ($gateway as $value){
|
|
|
+ $g_map[$value['screen_id']] = $value['gateway_id'];
|
|
|
+ }
|
|
|
foreach ($data['data'] as $key => $value){
|
|
|
$data['data'][$key]['gateway_id'] = $g_map[$value['id']] ?? 0;
|
|
|
$tmp_online = $online[$value['id']] ?? 0;
|
|
@@ -192,7 +196,8 @@ class ScreenService extends Service
|
|
|
->leftJoin('device_type as c','c.id','b.device_type_id')
|
|
|
->where('a.screen_id',$data['screen_id'])
|
|
|
->where('a.del_time',0)
|
|
|
- ->select('a.id','b.id as device_id','b.title','b.code','b.gateway_id','b.device_type_id','b.remark','c.title as device_type_name','b.size');
|
|
|
+ ->where('b.del_time',0)
|
|
|
+ ->select('a.id','b.id as device_id','b.title','b.code','b.gateway_id','b.device_type_id','b.remark','c.title as device_type_name','b.size','b.unit');
|
|
|
|
|
|
if(! empty($data['gateway_id'])) $model->where('b.gateway_id',$data['gateway_id']);
|
|
|
$list = $this->limit($model,'',$data);
|
|
@@ -337,6 +342,44 @@ class ScreenService extends Service
|
|
|
return [true,['node_one' => $posts_a,'node_two'=>$posts_b,'node_three'=>$posts_c]];
|
|
|
}
|
|
|
|
|
|
+ public function screenTrendChart($data){
|
|
|
+ if(empty($data['device_no'])) return [false,'请选择设备'];
|
|
|
+ if(count($data['device_no']) > 4) return [false,'一次最多选择4个设备'];
|
|
|
+ if(empty($data['time'][0]) || empty($data['time'][1])) return [false,'时间不能为空'];
|
|
|
+
|
|
|
+ $time = $this->changeDateToTimeStampAboutRange($data['time']);
|
|
|
+ $model = SystemL::whereIn('device_no', $data['device_no'])
|
|
|
+ ->select('value','time','device_no')
|
|
|
+ ->orderBy('id','asc');
|
|
|
+ $model->where('time','>=',$time[0] * 1000);
|
|
|
+ $model->where('time','<',$time[1] * 1000);
|
|
|
+ $list = $model->get()->toArray();
|
|
|
+ $list = $this->fillScreenTrendChart($list);
|
|
|
+
|
|
|
+ return [true,$list];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function fillScreenTrendChart($data){
|
|
|
+ if(empty($data)) return $data;
|
|
|
+
|
|
|
+ $return = [];
|
|
|
+ foreach ($data as $value){
|
|
|
+ $return[$value['device_no']][] = [
|
|
|
+ 'time' => date('Y-m-d H:i:s',$value['time'] / 1000),
|
|
|
+ 'value' => $value['value']
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ $final = [];
|
|
|
+ foreach ($return as $key => $value){
|
|
|
+ $final[] = [
|
|
|
+ 'device_no' => $key,
|
|
|
+ 'detail' => $value
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ return $final;
|
|
|
+ }
|
|
|
+
|
|
|
public function screenHistoryList($data){
|
|
|
if(empty($data['screen_id'])) return [false,'请选择仓或台'];
|
|
|
if(empty($data['device_type_id'])) return [false,'设备类型不能为空'];
|
|
@@ -389,40 +432,102 @@ class ScreenService extends Service
|
|
|
public function screenGps($data){
|
|
|
if(empty($data['screen_id'])) return [false,'请选择仓'];
|
|
|
|
|
|
- //gps类
|
|
|
- $gps = ScreenDevice::from('screen_device as a')
|
|
|
+ //返回的参数
|
|
|
+ $result = [
|
|
|
+ 'province' => '',
|
|
|
+ 'city' => '',
|
|
|
+ 'district' => '',
|
|
|
+ 'location' => '',
|
|
|
+ 'temperature' => [],
|
|
|
+ 'humidity' => []
|
|
|
+ ];
|
|
|
+
|
|
|
+ $device = ScreenDevice::from('screen_device as a')
|
|
|
->leftJoin('device as b','b.id','a.device_id')
|
|
|
- ->where('b.device_type_id',4)
|
|
|
+ ->whereIn('b.device_type_id',[DeviceType::type_one,DeviceType::type_four])
|
|
|
->where('a.del_time',0)
|
|
|
->where('b.del_time',0)
|
|
|
- ->select('b.code')
|
|
|
- ->first();
|
|
|
- if(empty($gps)) return [true,''];
|
|
|
- $gps = $gps->toArray();
|
|
|
-
|
|
|
- $sys_data = SystemL::where('device_no',$gps['code'])
|
|
|
- ->orderBy('id','desc')
|
|
|
- ->select('value')
|
|
|
- ->first();
|
|
|
- if(empty($sys_data)) return [true,''];
|
|
|
- $location = $sys_data->value;//经纬度
|
|
|
- $url = 'https://restapi.amap.com/v3/geocode/regeo?location='.$location.'&key='.SystemL::GaoDeMapKey;
|
|
|
- try{
|
|
|
- $return = $this->curlOpen($url);
|
|
|
- $return = json_decode($return,true);
|
|
|
- if(empty($return['status'])) return [false,'定位失败'];
|
|
|
-
|
|
|
- $position = $return['regeocode']['addressComponent'] ?? [];
|
|
|
- $result = [
|
|
|
- 'province' => $position['province'] ?? '',
|
|
|
- 'city' => $position['city'] ?? '',
|
|
|
- 'district' => $position['district'] ?? '',
|
|
|
- 'location' => $location
|
|
|
- ];
|
|
|
- return [true, $result];
|
|
|
- }catch (\Exception $exception){
|
|
|
- return [false,$exception->getMessage()];
|
|
|
+ ->where('a.screen_id',$data['screen_id'])
|
|
|
+ ->select('b.code','b.device_type_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $gps = $other = [];
|
|
|
+ foreach ($device as $value){
|
|
|
+ if($value['device_type_id'] == DeviceType::type_four){
|
|
|
+ $gps[] = $value['code'];
|
|
|
+ }else{
|
|
|
+ $other[] = $value['code'];
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ //gps定位
|
|
|
+ $return_gps = SystemlService::getLastData($gps);
|
|
|
+ if(! empty($return_gps)){
|
|
|
+ $first_position = "";
|
|
|
+ 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
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }catch (\Exception $exception){
|
|
|
+// return [false,$exception->getMessage()];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //温度湿度
|
|
|
+ $time = strtotime('-2 min',time());
|
|
|
+ $time = $time * 1000;
|
|
|
+ $model = SystemL::whereIn('device_no', $other)
|
|
|
+ ->select('value','time','device_no','data_point_name')
|
|
|
+ ->orderBy('id','asc');
|
|
|
+ $model->where('time','>=',$time);
|
|
|
+ $list = $model->get()->toArray();
|
|
|
+ $chart = $this->fillScreenChart($list);
|
|
|
+ $result['temperature'] = $chart['temperature'];
|
|
|
+ $result['humidity'] = $chart['humidity'];
|
|
|
+
|
|
|
+ return [true, $result];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function fillScreenChart($data){
|
|
|
+ if(empty($data)) return ['temperature' => [], 'humidity'=> []];
|
|
|
+
|
|
|
+ $return1 = $return2 = [];
|
|
|
+ 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),
|
|
|
+ 'value' => $value['value']
|
|
|
+ ];
|
|
|
+ }elseif (strstr($value['data_point_name'],'湿度')){
|
|
|
+ $return2[$value['device_no']][] = [
|
|
|
+ 'time' => date('Y-m-d H:i:s',$value['time'] / 1000),
|
|
|
+ 'value' => $value['value']
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $final1 = $final2 = [];
|
|
|
+ foreach ($return1 as $key => $value){
|
|
|
+ if(! empty($final1)) continue;
|
|
|
+ $final1 = $value;
|
|
|
+ }
|
|
|
+ foreach ($return2 as $key => $value){
|
|
|
+ if(! empty($final2)) continue;
|
|
|
+ $final2 = $value;
|
|
|
+ }
|
|
|
+
|
|
|
+ return ['temperature' => $final1, 'humidity'=>$final2];
|
|
|
}
|
|
|
|
|
|
public function uploadScreenFile($file){
|
|
@@ -447,4 +552,58 @@ class ScreenService extends Service
|
|
|
|
|
|
return [true, '/api/screen/'.$file_name];
|
|
|
}
|
|
|
+
|
|
|
+ public function screenMessage($data){
|
|
|
+ $model = Screen::where('del_time',0)
|
|
|
+ ->select('id','code','title','img')
|
|
|
+ ->orderBy('id','asc');
|
|
|
+
|
|
|
+ $list = $model->get()->toArray();
|
|
|
+ $list = $this->fillScreenMessage($list);
|
|
|
+
|
|
|
+ return [200,$list];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function fillScreenMessage($data){
|
|
|
+ if(empty($data)) return $data;
|
|
|
+
|
|
|
+ $screen_id = array_column($data,'id');
|
|
|
+ //设备
|
|
|
+ $result = ScreenDevice::from('screen_device as a')
|
|
|
+ ->leftJoin('device as b','b.id','a.device_id')
|
|
|
+ ->whereIn('a.screen_id',$screen_id)
|
|
|
+ ->where('a.del_time',0)
|
|
|
+ ->select('a.screen_id','b.code','b.device_type_id','b.unit')
|
|
|
+ ->get()
|
|
|
+ ->toArray();
|
|
|
+ $map = $map2 = $map3 = [];
|
|
|
+ foreach ($result as $value){
|
|
|
+ $map[$value['screen_id']][] = $value['code'];
|
|
|
+ $map2[$value['code']] = $value['device_type_id'];
|
|
|
+ $map3[$value['code']] = $value['unit'];
|
|
|
+ }
|
|
|
+ $return = SystemlService::getLastData(array_column($result,'code'));
|
|
|
+
|
|
|
+ foreach ($data as $key => $value){
|
|
|
+ if(isset($map[$value['id']])){
|
|
|
+ foreach ($return as $code => $val){
|
|
|
+ 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] ?? '');
|
|
|
+ }elseif(empty($data[$key]['humidity']) && $map2[$code] == DeviceType::type_one && strstr($val['data_point_name'],'湿度')){
|
|
|
+ $data[$key]['humidity'] = $val['value']. ($map3[$code] ?? '');
|
|
|
+ }elseif(empty($data[$key]['open']) && $map2[$code] == DeviceType::type_two){
|
|
|
+ $data[$key]['open'] = $val['value'] ? '开' : '关';
|
|
|
+ }elseif(empty($data[$key]['warning']) && $map2[$code] == DeviceType::type_three){
|
|
|
+ $data[$key]['warning'] = $val['value'] ? '是' : '否';
|
|
|
+ }elseif(empty($data[$key]['gps']) && $map2[$code] == DeviceType::type_four){
|
|
|
+ $data[$key]['gps'] = $val['value'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
}
|