新增device日志

This commit is contained in:
huangzj
2023-08-08 10:09:13 +08:00
parent 4f954e9469
commit 1a4e894695
18 changed files with 494 additions and 6 deletions

View File

@@ -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);
}
}