feat: 增加gps和状态消息的处理

dev
huangfeng 3 months ago
parent 7f04bad05d
commit 35b2b961e0

@ -42,4 +42,10 @@ public class CommonData {
Integer type;
Integer number;
PullAndAngleMonitoring dataList;
Integer positioningSystemInfo;
Double gwLongitude;
Double gwLatitude;
Float signal;
Float batteryVoltage;
Float remainingBatteryPower;
}

@ -0,0 +1,36 @@
package com.shxy.xymanager_framework.mqtt;
import com.shxy.xymanager_common.entity.TerminalPositions;
import com.shxy.xymanager_common.entity.Terminals;
import com.shxy.xymanager_common.model.mqtt.CommonData;
import com.shxy.xymanager_dao.dao.TerminalPositionsMapper;
import com.shxy.xymanager_service.service.TerminalExtService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
@Slf4j
public class GPSHandler {
@Resource
TerminalExtService terminalExtService;
@Resource
TerminalPositionsMapper terminalPositionsMapper;
public void handleUpload(CommonData data, String deviceId) throws Exception {
Terminals term = terminalExtService.getByCmdid(deviceId);
if (term == null) {
log.error("mqtt收到LongitudeAndLatitudeInfo但是该装置" + deviceId + "不存在");
return;
}
log.info("mqtt消息LongitudeAndLatitudeInfo " + deviceId + " " + data.getGwLatitude() + "," + data.getGwLongitude());
TerminalPositions record = terminalPositionsMapper.selectByPrimaryKey(term.getId());
if (record != null) {
record.setLatitude(data.getGwLatitude());
record.setLongitude(data.getGwLongitude());
terminalPositionsMapper.updateByPrimaryKey(record);
}
}
}

@ -20,6 +20,10 @@ public class MessageHandler {
WeatherHandler weatherHandler;
@Resource
PullHandler pullHandler;
@Resource
GPSHandler gpsHandler;
@Resource
StatusHandler statusHandler;
public void process(MessageUpload msg) throws Exception {
if (!CollectionUtils.isEmpty(msg.getDevices())) {
@ -57,6 +61,12 @@ public class MessageHandler {
case "PullAndAngleMonitoring":
pullHandler.handleUpload(data, deviceId);
break;
case "LongitudeAndLatitudeInfo":
gpsHandler.handleUpload(data, deviceId);
break;
case "StatusMonitoring":
statusHandler.handleUpload(data, deviceId);
break;
default:
throw new ApiException(service.getServiceId() + "暂时无法处理");
}

@ -29,7 +29,7 @@ public class PullHandler {
public void handleUpload(CommonData data, String deviceId) throws Exception {
Terminals term = terminalExtService.getByCmdid(deviceId);
if (term == null) {
log.error("mqtt收到拉力,但是该装置" + deviceId + "不存在");
log.error("mqtt收到PullAndAngleMonitoring,但是该装置" + deviceId + "不存在");
return;
}
PullAndAngleMonitoring dataList = data.getDataList();
@ -37,6 +37,7 @@ public class PullHandler {
throw new ApiException("拉力dataList内容是空的");
}
String time = dataList.getTime().replace("T", "").replace("Z", "");
log.info("mqtt消息PullAndAngleMonitoring " + deviceId + " " + time);
Date dTime = DateUtil.parse(time, "yyyyMMddHHmmss");
long updateTime = dTime.getTime() / 1000;

@ -0,0 +1,36 @@
package com.shxy.xymanager_framework.mqtt;
import com.shxy.xymanager_common.entity.TerminalStatus;
import com.shxy.xymanager_common.entity.Terminals;
import com.shxy.xymanager_common.model.mqtt.CommonData;
import com.shxy.xymanager_dao.dao.TerminalStatusDao;
import com.shxy.xymanager_service.service.TerminalExtService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
@Slf4j
public class StatusHandler {
@Resource
TerminalExtService terminalExtService;
@Resource
TerminalStatusDao terminalStatusDao;
public void handleUpload(CommonData data, String deviceId) throws Exception {
Terminals term = terminalExtService.getByCmdid(deviceId);
if (term == null) {
log.error("mqtt收到StatusMonitoring但是该装置" + deviceId + "不存在");
return;
}
log.info("mqtt消息StatusMonitoring " + deviceId + " " + data.getBatteryVoltage() + "," + data.getRemainingBatteryPower());
TerminalStatus record = terminalStatusDao.selectByPrimaryKey(term.getId());
if (record != null) {
record.setBatteryVoltage(data.getBatteryVoltage());
record.setBatteryCapacity(data.getRemainingBatteryPower());
terminalStatusDao.updateByPrimaryKey(record);
}
}
}

@ -27,10 +27,11 @@ public class WeatherHandler {
public void handleUpload(CommonData data, String deviceId) throws Exception {
Terminals term = terminalExtService.getByCmdid(deviceId);
if (term == null) {
log.error("mqtt收到天气,但是该装置" + deviceId + "不存在");
log.error("mqtt收到WeatherMonitoring,但是该装置" + deviceId + "不存在");
return;
}
String time = data.getTime().replace("T", "").replace("Z", "");
log.info("mqtt消息WeatherMonitoring " + deviceId + " " + time);
Date dTime = DateUtil.parse(time, "yyyyMMddHHmmss");
long updateTime = dTime.getTime() / 1000;

Loading…
Cancel
Save