事件处理:完成存储事件
parent
db8d363e99
commit
7034a24507
|
@ -1,13 +1,18 @@
|
||||||
package com.muyu.analyze.consumer;
|
package com.muyu.analyze.consumer;
|
||||||
|
|
||||||
import com.muyu.analyze.domian.VehicleData;
|
import com.muyu.analyze.domian.VehicleData;
|
||||||
|
import com.muyu.analyze.service.VehicleService;
|
||||||
import com.muyu.analyze.utils.AnalyzeUtils;
|
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.kafka.annotation.KafkaListener;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import javax.annotation.Resource;
|
||||||
import java.util.regex.Matcher;
|
import java.util.ArrayList;
|
||||||
import java.util.regex.Pattern;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 类说明
|
* 类说明
|
||||||
|
@ -17,15 +22,32 @@ import java.util.regex.Pattern;
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class Consumer {
|
public class Consumer {
|
||||||
|
|
||||||
|
|
||||||
|
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"})
|
@KafkaListener(topics = "test", groupId = "group", properties = {"bootstrap.servers = 10.10.26.5:9092"})
|
||||||
public void getMessage(String message) {
|
@PostMapping("/msg")
|
||||||
|
public void getMessage(String msg) {
|
||||||
VehicleData analyze = AnalyzeUtils.analyze(message);
|
VehicleData analyze = AnalyzeUtils.analyze(msg);
|
||||||
|
for (String s : list) {
|
||||||
|
VehicleService vehicleService = SpringUtils.getBean(s);
|
||||||
System.out.println("kafka 消费者监听,接收到消息:" + analyze);
|
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.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
@ -21,6 +25,10 @@ import java.math.BigDecimal;
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class VehicleData{
|
public class VehicleData{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private Long id;
|
||||||
/**
|
/**
|
||||||
* VIN
|
* VIN
|
||||||
*/
|
*/
|
||||||
|
@ -123,7 +131,7 @@ public class VehicleData {
|
||||||
/**
|
/**
|
||||||
* 动力电池剩余电量SOC
|
* 动力电池剩余电量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);
|
String remainingBattery = aa.substring(132, 138);
|
||||||
vehicleData.setRemainingBattery(new BigDecimal(remainingBattery));
|
vehicleData.setRemainingBattery(remainingBattery);
|
||||||
|
|
||||||
|
|
||||||
// 当前状态允许的最大反馈功率: 400000
|
// 当前状态允许的最大反馈功率: 400000
|
||||||
|
@ -312,7 +312,7 @@ public class AnalyzeUtils {
|
||||||
// CHG: 1
|
// CHG: 1
|
||||||
String chgStatus = aa.substring(205, 206);
|
String chgStatus = aa.substring(205, 206);
|
||||||
vehicleData.setChgStatus(Integer.parseInt(chgStatus));
|
vehicleData.setChgStatus(Integer.parseInt(chgStatus));
|
||||||
System.out.println(vehicleData);
|
|
||||||
return vehicleData;
|
return vehicleData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue