事件处理:完成存储事件
parent
db8d363e99
commit
7034a24507
|
@ -1,13 +1,18 @@
|
|||
package com.muyu.analyze.consumer;
|
||||
|
||||
import com.muyu.analyze.domian.VehicleData;
|
||||
import com.muyu.analyze.service.VehicleService;
|
||||
import com.muyu.analyze.utils.AnalyzeUtils;
|
||||
import com.muyu.common.core.utils.SpringUtils;
|
||||
import net.bytebuddy.agent.builder.AgentBuilder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.kafka.annotation.KafkaListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 类说明
|
||||
|
@ -17,14 +22,31 @@ import java.util.regex.Pattern;
|
|||
*/
|
||||
@Component
|
||||
public class Consumer {
|
||||
@KafkaListener(topics="test", groupId = "group",properties = {"bootstrap.servers=10.10.26.5:9092"})
|
||||
public void getMessage(String message) {
|
||||
|
||||
VehicleData analyze = AnalyzeUtils.analyze(message);
|
||||
|
||||
|
||||
System.out.println("kafka 消费者监听,接收到消息:" + analyze);
|
||||
}
|
||||
List<String> list = new ArrayList<>();
|
||||
|
||||
{
|
||||
list.add("storedEvent");
|
||||
list.add("realTimeDataEvent");
|
||||
list.add("breakdown");
|
||||
list.add("fenceAlarm");
|
||||
}
|
||||
|
||||
|
||||
@KafkaListener(topics = "test", groupId = "group", properties = {"bootstrap.servers = 10.10.26.5:9092"})
|
||||
@PostMapping("/msg")
|
||||
public void getMessage(String msg) {
|
||||
VehicleData analyze = AnalyzeUtils.analyze(msg);
|
||||
for (String s : list) {
|
||||
VehicleService vehicleService = SpringUtils.getBean(s);
|
||||
vehicleService.eventResolution(analyze);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -2,6 +2,10 @@ package com.muyu.analyze.domian;
|
|||
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.muyu.common.core.web.domain.BaseEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
@ -20,7 +24,11 @@ import java.math.BigDecimal;
|
|||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class VehicleData {
|
||||
public class VehicleData{
|
||||
|
||||
|
||||
|
||||
private Long id;
|
||||
/**
|
||||
* VIN
|
||||
*/
|
||||
|
@ -123,7 +131,7 @@ public class VehicleData {
|
|||
/**
|
||||
* 动力电池剩余电量SOC
|
||||
*/
|
||||
private BigDecimal remainingBattery;
|
||||
private String remainingBattery;
|
||||
|
||||
/**
|
||||
* 电池总容量
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package com.muyu.analyze.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.muyu.analyze.domian.VehicleData;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ProjectName: cloud-vehicles
|
||||
* @PackageName: com.muyu.analyze.mapper
|
||||
* @Description TODO
|
||||
* @Author HuangDaJu
|
||||
* @Date 2024/4/4 09:48
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Mapper
|
||||
public interface VehicleMapper{
|
||||
Boolean addVehicleStoredEvent(ArrayList<VehicleData> list);
|
||||
|
||||
|
||||
|
||||
|
||||
// void addVehicleStoredEvent(VehicleData analyze);
|
||||
|
||||
|
||||
// void addVehicleStoredEvent1(ArrayList<VehicleData> list);
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.muyu.analyze.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.analyze.domian.VehicleData;
|
||||
|
||||
/**
|
||||
* @ProjectName: cloud-vehicles
|
||||
* @PackageName: com.muyu.analyze.service
|
||||
* @Description TODO
|
||||
* @Author HuangDaJu
|
||||
* @Date 2024/4/4 09:30
|
||||
* @Version 1.0
|
||||
*/
|
||||
public interface VehicleService {
|
||||
|
||||
void eventResolution(VehicleData analyze);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.muyu.analyze.service.impl;
|
||||
|
||||
import com.muyu.analyze.domian.VehicleData;
|
||||
import com.muyu.analyze.service.VehicleService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @ProjectName: cloud-vehicles
|
||||
* @PackageName: com.muyu.analyze.service.impl.historicalTrack
|
||||
* @Description TODO
|
||||
* @Author HuangDaJu
|
||||
* @Date 2024/4/4 09:36
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Service("breakdown")
|
||||
public class BreakdownImpl implements VehicleService{
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void eventResolution(VehicleData analyze) {
|
||||
System.out.println("我是故障报警");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.muyu.analyze.service.impl;
|
||||
|
||||
import com.muyu.analyze.domian.VehicleData;
|
||||
import com.muyu.analyze.service.VehicleService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @ProjectName: cloud-vehicles
|
||||
* @PackageName: com.muyu.analyze.service.impl
|
||||
* @Description TODO
|
||||
* @Author HuangDaJu
|
||||
* @Date 2024/4/4 16:02
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Service("fenceAlarm")
|
||||
public class FenceAlarmImpl implements VehicleService {
|
||||
|
||||
@Override
|
||||
public void eventResolution(VehicleData analyze) {
|
||||
|
||||
System.out.println("电子围栏报警事件开启");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.muyu.analyze.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.analyze.domian.VehicleData;
|
||||
import com.muyu.analyze.mapper.VehicleMapper;
|
||||
import com.muyu.analyze.service.VehicleService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @ProjectName: cloud-vehicles
|
||||
* @PackageName: com.muyu.analyze.service.impl.realTimeDataEvent
|
||||
* @Description TODO
|
||||
* @Author HuangDaJu
|
||||
* @Date 2024/4/4 09:35
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Service("realTimeDataEvent")
|
||||
public class RealTimeDataEventImpl implements VehicleService {
|
||||
|
||||
@Override
|
||||
public void eventResolution(VehicleData analyze) {
|
||||
System.out.println("我是实时数据");
|
||||
System.out.println(analyze);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package com.muyu.analyze.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.muyu.analyze.domian.VehicleData;
|
||||
import com.muyu.analyze.mapper.VehicleMapper;
|
||||
import com.muyu.analyze.service.VehicleService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ProjectName: cloud-vehicles 事件存储
|
||||
* @PackageName: com.muyu.analyze.service
|
||||
* @Description TODO
|
||||
* @Author HuangDaJu
|
||||
* @Date 2024/4/4 09:30
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Service("storedEvent")
|
||||
@Slf4j
|
||||
public class StoredEventImpl implements VehicleService {
|
||||
|
||||
private final ArrayList<VehicleData> list = new ArrayList<>();
|
||||
|
||||
@Autowired
|
||||
private VehicleMapper vehicleMapper;
|
||||
@Override
|
||||
public void eventResolution(VehicleData analyze) {
|
||||
|
||||
|
||||
list.add(analyze);
|
||||
if (list.size() >= 50) {
|
||||
log.info("集合满50,存储事件开始");
|
||||
Boolean i= vehicleMapper.addVehicleStoredEvent(list);
|
||||
|
||||
if (i) {
|
||||
list.clear();
|
||||
log.info("存储事件结束");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -165,7 +165,7 @@ public class AnalyzeUtils {
|
|||
*/
|
||||
|
||||
String remainingBattery = aa.substring(132, 138);
|
||||
vehicleData.setRemainingBattery(new BigDecimal(remainingBattery));
|
||||
vehicleData.setRemainingBattery(remainingBattery);
|
||||
|
||||
|
||||
// 当前状态允许的最大反馈功率: 400000
|
||||
|
@ -312,7 +312,7 @@ public class AnalyzeUtils {
|
|||
// CHG: 1
|
||||
String chgStatus = aa.substring(205, 206);
|
||||
vehicleData.setChgStatus(Integer.parseInt(chgStatus));
|
||||
System.out.println(vehicleData);
|
||||
|
||||
return vehicleData;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue