From 6605c86abfcf40af76f5e54d625ea120b775d4b5 Mon Sep 17 00:00:00 2001 From: bin Date: Wed, 20 Jan 2021 17:12:25 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E4=B8=8D=E5=9C=A8=E7=BA=BF?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E4=B8=8D=E5=8F=91=E5=BF=83=E8=B7=B3=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../guizhou/quartz/job/GZHeartJob.java | 33 ++++++----- .../guizhou/quartz/job/GZLocationSend.java | 58 ++++++++++++------- .../guizhou/quartz/job/GZSyncSetting.java | 30 ++++++---- .../resources/application-pro3.properties | 2 +- 4 files changed, 75 insertions(+), 48 deletions(-) diff --git a/src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZHeartJob.java b/src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZHeartJob.java index d3f9b9c..691a725 100644 --- a/src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZHeartJob.java +++ b/src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZHeartJob.java @@ -42,28 +42,31 @@ public class GZHeartJob extends QuartzJobBean { String phone = device.getPhone(); GpsDeviceStatus gpsDeviceStatus = statusMapper.selectByImei(imei); int pow = 50; + int online = 0; if(gpsDeviceStatus != null){ String statusStr = gpsDeviceStatus.getDeviceStatus(); IOTDeviceStatus status = IOTDeviceStatus.build(statusStr); pow = status.getBattery(); + online = status.getOnline(); + } + if(online == 1){ + DianxinGzDeviceConfig config = configMapper.selectByImei(imei); + GZHeart heart = new GZHeart(); + GZDevicePower power = new GZDevicePower(); + power.setPower(pow); + power.setCharge(false); + heart.setPower(power); + GZDeviceStatus gzStatus = new GZDeviceStatus(); + heart.setStatus(gzStatus); + heart.setSignalIntensity(70); + try { + byte[] res = httpUtil.send(imei, phone, heart); + } catch (IOException e) { + e.printStackTrace(); + } } - DianxinGzDeviceConfig config = configMapper.selectByImei(imei); - GZHeart heart = new GZHeart(); - GZDevicePower power = new GZDevicePower(); - power.setPower(pow); - power.setCharge(false); - heart.setPower(power); - GZDeviceStatus gzStatus = new GZDeviceStatus(); - heart.setStatus(gzStatus); - heart.setSignalIntensity(70); - try { - byte[] res = httpUtil.send(imei, phone, heart); -// System.out.println(ByteUtil.bytesToHexString(res)); - } catch (IOException e) { - e.printStackTrace(); - } } } } diff --git a/src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZLocationSend.java b/src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZLocationSend.java index 97dac04..4adc149 100644 --- a/src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZLocationSend.java +++ b/src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZLocationSend.java @@ -4,9 +4,12 @@ package com.ssjl.zhaobiao.guizhou.quartz.job; import com.alibaba.fastjson.JSON; import com.ssjl.zhaobiao.guizhou.entity.DianxinGzDeviceConfig; import com.ssjl.zhaobiao.guizhou.entity.GZMessage.GZLocationInterval; +import com.ssjl.zhaobiao.guizhou.entity.GpsDeviceStatus; import com.ssjl.zhaobiao.guizhou.entity.IOT.Api.IotApiResponse; +import com.ssjl.zhaobiao.guizhou.entity.IOT.IOTDeviceStatus; import com.ssjl.zhaobiao.guizhou.entity.IOTDevice; import com.ssjl.zhaobiao.guizhou.repository.DianxinGzDeviceConfigMapper; +import com.ssjl.zhaobiao.guizhou.repository.GpsDeviceStatusMapper; import com.ssjl.zhaobiao.guizhou.utils.IOTApiUtil; import com.ssjl.zhaobiao.guizhou.utils.LocationUtil; import lombok.extern.slf4j.Slf4j; @@ -31,6 +34,8 @@ public class GZLocationSend extends QuartzJobBean { LocationUtil locationUtil; @Autowired IOTApiUtil iotApiUtil; + @Autowired + GpsDeviceStatusMapper gpsDeviceStatusMapper; @Value("${guizhou.device.testList}") String testList; @@ -40,31 +45,40 @@ public class GZLocationSend extends QuartzJobBean { List deviceList = JSON.parseArray(testList, IOTDevice.class); LocalDateTime time = LocalDateTime.now(); for (int i = 0; i < deviceList.size(); i++) { + int online = 0; IOTDevice device = deviceList.get(i); - try{ - // 找到上次发送的时间 - LocalDateTime lastTime = locationUtil.getTime(device.getImei()); - if(lastTime == null){ - lastTime = LocalDateTime.of(2020, 1 ,1,1,1); - } - DianxinGzDeviceConfig dianxinGzDeviceConfig = dianxinGzDeviceConfigMapper.selectByImei(device.getImei()); - List intervalList = GZLocationInterval.build(dianxinGzDeviceConfig.getLocationInterval()); - int interval = GZLocationInterval.timeInterval(time, intervalList); - if(interval == 0){ - // 不发送 - continue; - } - // 按时间段设计,下次发送的时间 - if(lastTime.plusMinutes(interval).isAfter(time)){ - continue; + GpsDeviceStatus deviceStatus = gpsDeviceStatusMapper.selectByImei(device.getImei()); + if(deviceStatus != null){ + IOTDeviceStatus status = IOTDeviceStatus.build(deviceStatus.getDeviceStatus()); + online = status.getOnline(); + } + if(online == 1){ + try{ + // 找到上次发送的时间 + LocalDateTime lastTime = locationUtil.getTime(device.getImei()); + if(lastTime == null){ + lastTime = LocalDateTime.of(2020, 1 ,1,1,1); + } + DianxinGzDeviceConfig dianxinGzDeviceConfig = dianxinGzDeviceConfigMapper.selectByImei(device.getImei()); + List intervalList = GZLocationInterval.build(dianxinGzDeviceConfig.getLocationInterval()); + int interval = GZLocationInterval.timeInterval(time, intervalList); + if(interval == 0){ + // 不发送 + continue; + } + // 按时间段设计,下次发送的时间 + if(lastTime.plusMinutes(interval).isAfter(time)){ + continue; + } + // 当前时间已达到,则发起即时定位,由于即时定位平台要等待定时数据,耗时很长,因而要开一条线程 + getLocation(device.getImei()); + // 更新发送时间 + locationUtil.saveTime(device.getImei(), time); + }catch (Exception e){ + e.printStackTrace(); } - // 当前时间已达到,则发起即时定位,由于即时定位平台要等待定时数据,耗时很长,因而要开一条线程 - getLocation(device.getImei()); - // 更新发送时间 - locationUtil.saveTime(device.getImei(), time); - }catch (Exception e){ - e.printStackTrace(); } + } } diff --git a/src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZSyncSetting.java b/src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZSyncSetting.java index b0ad448..10e449f 100644 --- a/src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZSyncSetting.java +++ b/src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZSyncSetting.java @@ -2,8 +2,11 @@ package com.ssjl.zhaobiao.guizhou.quartz.job; import com.alibaba.fastjson.JSON; import com.ssjl.zhaobiao.guizhou.entity.GZMessage.GZAskSetting; +import com.ssjl.zhaobiao.guizhou.entity.GpsDeviceStatus; +import com.ssjl.zhaobiao.guizhou.entity.IOT.IOTDeviceStatus; import com.ssjl.zhaobiao.guizhou.entity.IOTDevice; import com.ssjl.zhaobiao.guizhou.handle.GZResponseHandle; +import com.ssjl.zhaobiao.guizhou.repository.GpsDeviceStatusMapper; import com.ssjl.zhaobiao.guizhou.utils.ByteUtil; import com.ssjl.zhaobiao.guizhou.utils.GZHttpUtil; import lombok.extern.slf4j.Slf4j; @@ -28,6 +31,8 @@ public class GZSyncSetting extends QuartzJobBean { String testList; @Autowired GZResponseHandle responseHandle; + @Autowired + GpsDeviceStatusMapper statusMapper; @Override protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException { @@ -35,17 +40,22 @@ public class GZSyncSetting extends QuartzJobBean { List devices = JSON.parseArray(testList, IOTDevice.class); for (int i = 0; i < devices.size(); i++) { IOTDevice device = devices.get(i); - GZAskSetting askSetting = new GZAskSetting(); - try { - byte[] res = httpUtil.send(device.getImei(), device.getPhone(), askSetting); -// System.out.println(ByteUtil.bytesToHexString(res)); - res = (byte[]) responseHandle.process(device.getImei(), res); -// System.out.println(ByteUtil.bytesToHexString(res)); - } catch (IOException e) { - e.printStackTrace(); + GpsDeviceStatus gpsDeviceStatus = statusMapper.selectByImei(device.getImei()); + int online = 0; + if(gpsDeviceStatus != null){ + String statusStr = gpsDeviceStatus.getDeviceStatus(); + IOTDeviceStatus status = IOTDeviceStatus.build(statusStr); + online = status.getOnline(); + } + if(online == 1){ + GZAskSetting askSetting = new GZAskSetting(); + try { + byte[] res = httpUtil.send(device.getImei(), device.getPhone(), askSetting); + res = (byte[]) responseHandle.process(device.getImei(), res); + } catch (IOException e) { + e.printStackTrace(); + } } } - - } } diff --git a/src/main/resources/application-pro3.properties b/src/main/resources/application-pro3.properties index 0a35ce3..5be5f74 100644 --- a/src/main/resources/application-pro3.properties +++ b/src/main/resources/application-pro3.properties @@ -48,7 +48,7 @@ guizhou.device.version=RZL_2021 #guizhou.factory=zhanneng #guizhou.device.model=TPE390 #guizhou.device.version=TPE_0056 -guizhou.http.url=http://120.24.195.54:24183 +guizhou.http.url=http://139.9.239.216:7735 guizhou.device.testList= [{ "imei": "862622050654340","phone": "" },{ "imei": "862622050317740","phone": "" }] guizhou.device.zhizhong=862622050654340,862622050317740 guizhou.device.zhanneng=862622050925104,862622050927027