mqtt消息添加心跳包处理,设备新增运行状态字段以及接口
This commit is contained in:
@ -76,18 +76,21 @@ public class DeviceOtherMsgConsumer {
|
||||
NgWaterPumpUsageRecords pumpUsageRecords=new NgWaterPumpUsageRecords();
|
||||
pumpUsageRecords.setDeviceNumber(serialNumber);
|
||||
JSONObject jsonObject = JSONUtil.parseObj(data);
|
||||
jsonObject.set("time", (LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))));//收到消息的当地时间
|
||||
// jsonObject.set("time", (LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))));//收到消息的当地时间
|
||||
if(jsonObject.getStr("type")!=null){
|
||||
//上报正常数据
|
||||
if(jsonObject.getStr("type").equals("waterEleData")){
|
||||
String data1 = jsonObject.getStr("data");
|
||||
//收到定时报文
|
||||
//收到开阀定时报文
|
||||
if(JSONUtil.parseObj(data1).get("action").equals("timeMsg")){
|
||||
pumpUsageRecords.setMessageContent(JSONUtil.toJsonStr(jsonObject));
|
||||
// int i = ngWaterPumpUsageRecordsMapper.insertNgWaterPumpUsageRecords(pumpUsageRecords);
|
||||
// if(i<1){
|
||||
// System.err.println("--------------------------保存使用记录失败!---------------------------");
|
||||
// }
|
||||
}else if(JSONUtil.parseObj(data1).get("action").equals("safeMsg")){
|
||||
}
|
||||
//收到关阀时定时报文
|
||||
else if(JSONUtil.parseObj(data1).get("action").equals("safeMsg")){
|
||||
//续费在线状态
|
||||
updateDeviceOnlineStatus( productId,serialNumber);
|
||||
//保存数据
|
||||
@ -97,14 +100,28 @@ public class DeviceOtherMsgConsumer {
|
||||
// System.err.println("--------------------------保存使用记录失败!---------------------------");
|
||||
// }
|
||||
|
||||
}//开阀门,关阀门
|
||||
}
|
||||
//开阀门,关阀门
|
||||
else if(JSONUtil.parseObj(data1).get("action").equals("startPump")||JSONUtil.parseObj(data1).get("action").equals("stopPump")){
|
||||
int i = ngWaterPumpUsageRecordsMapper.insertNgWaterPumpUsageRecords(pumpUsageRecords);
|
||||
if(i<1){
|
||||
System.err.println("--------------------------保存使用记录失败!---------------------------");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//收到心跳报文
|
||||
else if(jsonObject.getStr("type").equals("heartBeat")){
|
||||
//需要回应
|
||||
//构建回复消息-----------------------------------------------------------------------------
|
||||
// Map<String,Object> reportMsg=new HashMap<>();
|
||||
// reportMsg.put("code",100);
|
||||
// reportMsg.put("pakSn","ok");
|
||||
// reportMsg.put("data","heartBeat");
|
||||
jsonObject.set("code",100);
|
||||
issueInstructionsProducer.receiveDataReportResponse(productId.toString(),serialNumber,JSONUtil.toJsonStr(jsonObject));
|
||||
}
|
||||
|
||||
}
|
||||
//构建回复消息-----------------------------------------------------------------------------
|
||||
// Map<String,Object> reportMsg=new HashMap<>();
|
||||
|
Reference in New Issue
Block a user