Procházet zdrojové kódy

设备不在线时,不发心跳包

develop
bin před 3 roky
rodič
revize
6605c86abf
4 změnil soubory, kde provedl 75 přidání a 48 odebrání
  1. +18
    -15
      src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZHeartJob.java
  2. +36
    -22
      src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZLocationSend.java
  3. +20
    -10
      src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZSyncSetting.java
  4. +1
    -1
      src/main/resources/application-pro3.properties

+ 18
- 15
src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZHeartJob.java Zobrazit soubor

@@ -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();
}
}
}
}

+ 36
- 22
src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZLocationSend.java Zobrazit soubor

@@ -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<IOTDevice> 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<GZLocationInterval> 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<GZLocationInterval> 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();
}

}
}



+ 20
- 10
src/main/java/com/ssjl/zhaobiao/guizhou/quartz/job/GZSyncSetting.java Zobrazit soubor

@@ -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<IOTDevice> 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();
}
}
}


}
}

+ 1
- 1
src/main/resources/application-pro3.properties Zobrazit soubor

@@ -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


Načítá se…
Zrušit
Uložit