添加水电双计设备在线状态维护,以及下发修改设备地址码指令接口等

This commit is contained in:
蒾酒
2024-12-24 01:53:17 +08:00
parent 16b2d0e242
commit 39dafad29c
6 changed files with 87 additions and 10 deletions

View File

@ -11,11 +11,13 @@ import com.fastbee.rechargecard.domain.NgWaterPumpUsageRecords;
import com.fastbee.rechargecard.mapper.NgWaterPumpUsageRecordsMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
* @author gsb
@ -34,6 +36,8 @@ public class DeviceOtherMsgConsumer {
@Autowired
private NgWaterPumpUsageRecordsMapper ngWaterPumpUsageRecordsMapper;
@Autowired
private StringRedisTemplate stringRedisTemplate;
@Autowired
private PubMqttClient pubMqttClient;
@ -44,7 +48,6 @@ public class DeviceOtherMsgConsumer {
//处理emq订阅的非 property/post 属性上报的消息 ,因为其他消息量小,放在一起处理
Long productId;//产品id
Long packetId;//包号
byte[] data = bo.getData();//数据
String topic=bo.getTopicName();//主题
@ -55,7 +58,7 @@ public class DeviceOtherMsgConsumer {
String serialNumber= split[2];//设备序列号
System.err.println("主题:"+topic+"--产品id:"+productId+"--设备序列号:"+serialNumber);
//设备上报数据消息
//设备上报数据消息---------------------------------------------------------------------------------
if(topic.endsWith("/info/up")){
deviceDataReportHandler(new String(data));
//保存使用记录
@ -66,25 +69,27 @@ public class DeviceOtherMsgConsumer {
if(jsonObject.getStr("type").equals("waterEleData")){
String data1 = jsonObject.getStr("data");
if(JSONUtil.parseObj(data1).get("action").equals("timeMsg")){
//更新设备在线状态
updateDeviceOnlineStatus( productId,serialNumber);
pumpUsageRecords.setMessageContent(JSONUtil.toJsonStr(jsonObject));
int i = ngWaterPumpUsageRecordsMapper.insertNgWaterPumpUsageRecords(pumpUsageRecords);
if(i<1){
System.err.println("--------------------------保存使用记录失败!---------------------------");
}
}
}
}
//构建回复消息
//构建回复消息-----------------------------------------------------------------------------
Map<String,Object> reportMsg=new HashMap<>();
reportMsg.put("code",0);
reportMsg.put("msg","ok");
issueInstructionsProducer.receiveDataReportResponse(productId.toString(),serialNumber,JSONUtil.toJsonStr(reportMsg));
} else if ( topic.endsWith("/info/reply")) {
}
//打印设备
else if ( topic.endsWith("/info/reply")) {
platformDataReportAckHandler(new String(data));
} else if (topic.endsWith("/cmd/down")) {
}
else if (topic.endsWith("/cmd/down")) {
platformCmdHandler(new String(data));
//回应
@ -97,6 +102,27 @@ public class DeviceOtherMsgConsumer {
}
}
/**
* 更新设备在线状态
*/
private void updateDeviceOnlineStatus(Long productId,String serialNumber){
try {
//判断
if(Boolean.TRUE.equals(stringRedisTemplate.hasKey("neixiang_device_online_status:" + productId + ":" + serialNumber))){
//重新设置过期时间
stringRedisTemplate.expire("neixiang_device_online_status:"+productId+":"+serialNumber,1200, TimeUnit.SECONDS);
return;
}
stringRedisTemplate.opsForValue().set("neixiang_device_online_status:"+productId+":"+serialNumber,"1",1200, TimeUnit.SECONDS);
}catch (Exception e){
log.error("=>更新设备在线状态出错",e);
}
}
/**
* 处理设备数据上报
* @param data 消息