feat:() 优化

dev.processing.admire
晨哀 2024-10-10 15:05:16 +08:00
parent cdd18d947d
commit cefbc152f7
9 changed files with 99 additions and 27 deletions

View File

@ -37,6 +37,8 @@ public class KafkaConsumerService implements InitializingBean {
*/ */
private static final String TIPSY = "tipsy"; private static final String TIPSY = "tipsy";
private static final String LYRIC = "lyric";
@Resource @Resource
private KafkaConsumer kafkaConsumer; private KafkaConsumer kafkaConsumer;

View File

@ -46,7 +46,7 @@ public class OfflineMonitoringConsumer {
log.info("清除缓存中的数据,车辆vin: {}", vin); log.info("清除缓存中的数据,车辆vin: {}", vin);
// 清除缓存 // 清除缓存
cacheUtil.remove(vin); cacheUtil.remove(vin);
log.info("vin码为: {}de本地缓存清除成功",vin); log.info("vin码为: {}本地缓存清除成功",vin);
} }
} }

View File

@ -32,7 +32,7 @@ public class OnLineMonitoringConsumer {
/** /**
* 线 * 线
*/ */
private static final String ON_LINE_MONITORING = "MQ_ON_LINE_MONITORING"; private static final String ON_LINE_MONITORING = "queue_inform_email";
/** /**
* 线 * 线
*/ */

View File

@ -25,12 +25,14 @@ import javax.annotation.Resource;
public class TestKafka { public class TestKafka {
private static final String TIPSY = "tipsy"; private static final String TIPSY = "tipsy";
private static final String LYRIC = "lyric";
private static final String VIN = "63YCZDY6336C8H4CA"; private static final String VIN = "63YCZDY6336C8H4CA";
/** /**
* 线 * 线
*/ */
private static final String ON_LINE_MONITORING = "MQ_ON_LINE_MONITORING"; private static final String ON_LINE_MONITORING = "queue_inform_email";
/** /**
* 线 * 线
*/ */
@ -49,6 +51,7 @@ public class TestKafka {
JSONObject entries = new JSONObject(); JSONObject entries = new JSONObject();
entries.set("VIN码",VIN); entries.set("VIN码",VIN);
entries.set("name","宝马"); entries.set("name","宝马");
entries.set("Numerical_value",6);
String entriesString = entries.toString(); String entriesString = entries.toString();
ProducerRecord<String, String> producerRecord = new ProducerRecord<>(TIPSY, entriesString); ProducerRecord<String, String> producerRecord = new ProducerRecord<>(TIPSY, entriesString);
kafkaProducer.send(producerRecord); kafkaProducer.send(producerRecord);

View File

@ -6,6 +6,7 @@ import com.muyu.processing.basic.EventListener;
import com.muyu.processing.utils.CacheUtil; import com.muyu.processing.utils.CacheUtil;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.apache.kafka.common.protocol.types.Field; import org.apache.kafka.common.protocol.types.Field;
import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
@ -20,6 +21,7 @@ import java.util.Map;
* @Date2024/9/29 22:25 * @Date2024/9/29 22:25
*/ */
@Log4j2 @Log4j2
@Component
public class AddDatabaseListener implements EventListener { public class AddDatabaseListener implements EventListener {
@Resource @Resource
@ -32,7 +34,6 @@ public class AddDatabaseListener implements EventListener {
String vin = (String) jsonObject.get("VIN码"); String vin = (String) jsonObject.get("VIN码");
Map<String, Object> map = (Map<String, Object>) cacheUtil.get(vin); Map<String, Object> map = (Map<String, Object>) cacheUtil.get(vin);
if (map != null){ if (map != null){
log.info("本地缓存数据为: {}",map);
ArrayList<Object> keys = new ArrayList<>(); ArrayList<Object> keys = new ArrayList<>();
ArrayList<Object> values = new ArrayList<>(); ArrayList<Object> values = new ArrayList<>();
jsonObject.forEach((key, value) ->{ jsonObject.forEach((key, value) ->{

View File

@ -7,6 +7,7 @@ import com.muyu.processing.basic.EventListener;
import com.muyu.processing.utils.CacheUtil; import com.muyu.processing.utils.CacheUtil;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.awt.*; import java.awt.*;
import java.util.ArrayList; import java.util.ArrayList;
@ -21,6 +22,7 @@ import java.util.HashMap;
* @Date2024/10/9 11:17 * @Date2024/10/9 11:17
*/ */
@Log4j2 @Log4j2
@Component
public class FenceListener implements EventListener { public class FenceListener implements EventListener {
@Autowired @Autowired

View File

@ -7,6 +7,7 @@ import com.muyu.processing.basic.EventListener;
import com.muyu.processing.utils.CacheUtil; import com.muyu.processing.utils.CacheUtil;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.HashMap; import java.util.HashMap;
@ -20,6 +21,7 @@ import java.util.HashMap;
* @Date2024/10/9 11:20 * @Date2024/10/9 11:20
*/ */
@Log4j2 @Log4j2
@Component
public class IdentifyingFailuresListener implements EventListener { public class IdentifyingFailuresListener implements EventListener {
@Autowired @Autowired

View File

@ -0,0 +1,56 @@
package com.muyu.processing.listener;
import com.alibaba.fastjson.JSONObject;
import com.muyu.domain.WarnRule;
import com.muyu.processing.basic.EventCustom;
import com.muyu.processing.basic.EventListener;
import com.muyu.processing.utils.CacheUtil;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Date;
import java.util.Map;
/**
*
* @Author
* @Packagecom.muyu.processing.listener
* @Projectcloud-vehicle
* @nameWarnRuleListener
* @Date2024/10/10 13:57
*/
@Log4j2
public class WarnRuleListener implements EventListener {
@Resource
private CacheUtil cacheUtil;
@Override
public void onEvent(EventCustom event) {
String vin = null;
try {
log.info("预警规则");
JSONObject jsonObject = event.getData();
vin = (String) jsonObject.get("VIN码");
Map<String, Object> map = (Map<String, Object>) cacheUtil.get(vin);
if (map != null){
WarnRule warnRule = (WarnRule) map.get("warnRule");
String ruleName = warnRule.getRuleName();
Integer minValue = warnRule.getMinValue();
Integer maxValue = warnRule.getMaxValue();
Date slideTime = warnRule.getSlideTime();
Integer slideFrequency = warnRule.getSlideFrequency();
log.info("滑窗时间: {}",slideTime);
log.info("滑窗频率: {}",slideFrequency);
}
} catch (Exception e) {
log.info(">>报错<<预警规则: VIN码为: {},事件发送错误",vin,e.getMessage());
}
}
@Override
public void onApplicationEvent(EventCustom event) {
onEvent(event);
}
}

View File

@ -43,14 +43,17 @@ public class WarnRuleRespListener implements EventListener {
*/ */
@Override @Override
public void onEvent(EventCustom event) { public void onEvent(EventCustom event) {
String vin = null;
try {
// 获得数据 // 获得数据
JSONObject jsonObject = event.getData(); JSONObject jsonObject = event.getData();
// 获得VIN码 // 获得VIN码
String vin = (String) jsonObject.get("VIN码"); vin = (String) jsonObject.get("VIN码");
// 获得本地缓存数据 Integer Numerical_value = (Integer) jsonObject.get("Numerical_value");
// 获得本地缓存数
log.info("警告事件: VIN码为: {}",vin);
Map<String, Object> map = (Map<String, Object>) cacheUtil.get(vin); Map<String, Object> map = (Map<String, Object>) cacheUtil.get(vin);
if (map != null){ if (map != null){
log.info("本地缓存数据为: {}",map);
// 获得警告规矩集合 // 获得警告规矩集合
WarnRuleResp warnRuleResp = (WarnRuleResp) map.get("warnRuleResp"); WarnRuleResp warnRuleResp = (WarnRuleResp) map.get("warnRuleResp");
// 获得预警规则 // 获得预警规则
@ -60,15 +63,18 @@ public class WarnRuleRespListener implements EventListener {
String ruleName = warnRule.getRuleName(); String ruleName = warnRule.getRuleName();
Integer maxValue = warnRule.getMaxValue(); Integer maxValue = warnRule.getMaxValue();
Integer minValue = warnRule.getMinValue(); Integer minValue = warnRule.getMinValue();
if (maxValue >= MAX_VALUE || minValue <= MIN_VALUE){ if (maxValue <= Numerical_value || minValue >= Numerical_value){
log.info("数据值的大小有出入, 规则名称: {}, 数据值为: {}",ruleName,Numerical_value);
} }
} }
} }
} catch (Exception e) {
log.info(">>报错<<警告事件: VIN码为: {}, 事件发送错误:",vin,e.getMessage());
}
} }
@Override @Override
public void onApplicationEvent(EventCustom event) { public void onApplicationEvent(EventCustom event) {
onEvent(event);
} }
} }