Commit 4391254c by 向延琳

新e盾消费电量数据

1 parent 3cbdeaa5
......@@ -98,6 +98,15 @@ public class KafkaConsumerConfig {
}
@Bean(initMethod = "init", destroyMethod = "destroy")
KafkaBatteryConsumer kafkaBatteryConsumer(@Value("${mq.kafka.device.battery.topic}") String topic) {
KafkaBatteryConsumer kafkaBatteryConsumer = new KafkaBatteryConsumer();
kafkaBatteryConsumer.setnThreads(nThreads);
kafkaBatteryConsumer.setConsumerConfig(gpsConsumerConfig);
kafkaBatteryConsumer.setTopic(topic);
return kafkaBatteryConsumer;
}
@Bean(initMethod = "init", destroyMethod = "destroy")
FenceAlarmConsumer fenceAlarmConsumer(@Value("${mq.kafka.fence.alarm.topic}") String topic) {
FenceAlarmConsumer fenceAlarmConsumer = new FenceAlarmConsumer();
fenceAlarmConsumer.setnThreads(nThreads);
......
package cn.com.glsx.kafka.model;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.Date;
/**
* 电量
* @author xiangyanlin
* @date 2022/4/12
*/
@NoArgsConstructor
@AllArgsConstructor
@Data
public class BatteryDTO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* id
*/
private Integer id;
/**
* 设备号
*/
private String sn;
/**
* 电量
*/
private Integer SOC;
/**
* 电量上传时间
*/
private String alarmTime;
/**
* 创建时间
*/
private String createTime;
/**
* 更新时间
*/
private String updateTime;
}
package cn.com.glsx.kafka.queue.consumer;
import cn.com.glsx.kafka.model.BatteryDTO;
import cn.com.glsx.kafka.queue.base.MessageReceiver;
import cn.com.glsx.stdinterface.api.BatteryClient;
import cn.com.glsx.stdinterface.dto.DevicePowerDTO;
import com.alibaba.fastjson.JSONObject;
import com.glsx.plat.common.utils.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import java.nio.charset.Charset;
import java.util.Optional;
/**
* 消费电量数据
*
* @author xiangyanlin
* @date 2022/4/12
*/
@Slf4j
public class KafkaBatteryConsumer extends MessageReceiver {
@Autowired
private BatteryClient batteryClient;
@Override
public void processMessage(String topic, byte[] message) throws Exception {
String devicePowerJson = new String(message, Charset.defaultCharset());
log.info("{}", "电量消息:" + devicePowerJson);
if(StringUtils.isEmpty(devicePowerJson)) {
return;
}
BatteryDTO devicePower = JSONObject.parseObject(devicePowerJson, BatteryDTO.class);
//电量信息保存入库
DevicePowerDTO devicePowerDTO = convert(devicePower);
batteryClient.saveBatteryInfo(devicePowerDTO);
}
public DevicePowerDTO convert(BatteryDTO batteryDTO) {
DevicePowerDTO devicePowerDTO = new DevicePowerDTO();
Optional.ofNullable(batteryDTO.getId())
.map(Integer::longValue)
.ifPresent(devicePowerDTO::setId);
devicePowerDTO.setSn(batteryDTO.getSn());
devicePowerDTO.setAlarmTime(DateUtils.parse(batteryDTO.getAlarmTime()));
devicePowerDTO.setSoc(batteryDTO.getSOC());
devicePowerDTO.setCreatedDate(DateUtils.parse(batteryDTO.getCreateTime()));
devicePowerDTO.setUpdatedDate(DateUtils.parse(batteryDTO.getUpdateTime()));
return devicePowerDTO;
}
}
......@@ -9,7 +9,6 @@ import com.alibaba.fastjson.JSON;
import com.glsx.plat.common.utils.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
/**
* 行程数据消费
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!