feat: 增加日志和自增mid

dev
huangfeng 3 months ago
parent 35b2b961e0
commit 5c9ede915b

@ -67,6 +67,9 @@ public class MessageHandler {
case "StatusMonitoring":
statusHandler.handleUpload(data, deviceId);
break;
case "SolarPowerProperties":
log.info("暂不处理SolarPowerProperties");
break;
default:
throw new ApiException(service.getServiceId() + "暂时无法处理");
}

@ -2,27 +2,40 @@ package com.shxy.xymanager_framework.mqtt;
import com.shxy.xymanager_common.model.mqtt.MessageSend;
import com.shxy.xymanager_common.util.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
@Slf4j
public class MqttPublisherService {
@Value("${mqtt.cmdtopic}")
private String cmdtopic;
int mid = 0;
@Resource
private MqttClient mqttClient;
private synchronized int getNextMid() {
mid++;
return mid;
}
@Async
public void publish(MessageSend msg) throws Exception {
msg.setMid(this.getNextMid());
String json = JSONUtil.object2Json(msg);
MqttMessage message = new MqttMessage(json.getBytes());
message.setQos(1);
message.setRetained(true);
log.info("mqtt发送消息:" + json);
mqttClient.publish(cmdtopic, message);
}
}

@ -37,6 +37,7 @@ public class MqttSubscriber implements IMqttMessageListener {
public void messageArrived(String topic, MqttMessage message) throws Exception {
String json = new String(message.getPayload());
try {
log.info("mqtt收到消息:" + json);
MessageUpload msg = JSONUtil.json2Object(json, MessageUpload.class);
messageHandler.process(msg);
} catch (ApiException aex) {

@ -75,6 +75,7 @@ public class PullHandler {
record.setMaxpullPull(dataList.getMaxPull());
record.setMaxpullWind(dataList.getMaxPullWind());
record.setMaxpullTilt(dataList.getMaxPullOblique());
record.setEqualIcethickness(dataList.getEqualIceThickness());
record.setCreateTime(new Date());
LeadPullsExample example = new LeadPullsExample();

Loading…
Cancel
Save