新增device日志
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package com.njcn.csdevice.handler;
|
||||
|
||||
|
||||
import com.github.tocrhz.mqtt.annotation.MqttSubscribe;
|
||||
|
||||
import com.github.tocrhz.mqtt.annotation.Payload;
|
||||
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
||||
import com.njcn.common.utils.PubUtils;
|
||||
import com.njcn.csdevice.service.impl.CsLogsPOService;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @date 2023年06月10日 09:41
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class MqttMessageHandler {
|
||||
|
||||
|
||||
private final CsLogsPOService csLogsPOService;
|
||||
|
||||
/**
|
||||
* 插入devicelog
|
||||
*/
|
||||
@MqttSubscribe(value = "/deviceLog")
|
||||
public void responseRtData(String topic, MqttMessage message, @Payload String payload) {
|
||||
DeviceLogDTO deviceLogDTO = PubUtils.json2obj(new String(message.getPayload(), StandardCharsets.UTF_8),DeviceLogDTO.class);
|
||||
csLogsPOService.addLog(deviceLogDTO);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user