feat: 事件系统
parent
9e8106ab46
commit
041aaa4654
|
@ -0,0 +1,33 @@
|
||||||
|
package com.couplet.common.redis.configure;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||||
|
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
|
||||||
|
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: LiJiaYao
|
||||||
|
* @Date: 2024/4/4
|
||||||
|
* @Description: redis监听配置
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class RedisListenerConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
RedisMessageListenerContainer listenerContainer(RedisConnectionFactory redisConnectionFactory) {
|
||||||
|
|
||||||
|
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
|
||||||
|
container.setConnectionFactory(redisConnectionFactory);
|
||||||
|
return container;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
KeyExpirationEventMessageListener redisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
|
||||||
|
return new KeyExpirationEventMessageListener(listenerContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -86,6 +86,14 @@
|
||||||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||||
<version>1.2.5</version>
|
<version>1.2.5</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.couplet</groupId>
|
||||||
|
<artifactId>couplet-modules-mq</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.couplet</groupId>
|
||||||
|
<artifactId>couplet-common-business</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -11,7 +11,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
* @date 2024/4/2 8:39
|
* @date 2024/4/2 8:39
|
||||||
* @description
|
* @description
|
||||||
*/
|
*/
|
||||||
@SpringBootApplication
|
@SpringBootApplication(scanBasePackages = "com.couplet")
|
||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
@EnableFeignClients(basePackages = "com.couplet.**")
|
@EnableFeignClients(basePackages = "com.couplet.**")
|
||||||
public class CoupletMsgApplication {
|
public class CoupletMsgApplication {
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
package com.couplet.analyze.msg.consumer;
|
||||||
|
|
||||||
|
import com.rabbitmq.client.Channel;
|
||||||
|
|
||||||
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.amqp.core.Message;
|
||||||
|
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
|
||||||
|
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: LiJiaYao
|
||||||
|
* @Date: 2024/4/4
|
||||||
|
* @Description:
|
||||||
|
*/
|
||||||
|
@Log4j2
|
||||||
|
@Component
|
||||||
|
@RabbitListener(queues = "")
|
||||||
|
public class MsgConsumer {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private StringRedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
@RabbitHandler
|
||||||
|
public void realTimeDataConsumer(Channel channel, Message message){
|
||||||
|
|
||||||
|
// log.info();
|
||||||
|
|
||||||
|
String messageId = message.getMessageProperties().getMessageId();
|
||||||
|
long deliveryTag = message.getMessageProperties().getDeliveryTag();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package com.couplet.analyze.msg.contents;
|
package com.couplet.analyze.msg.contents;
|
||||||
|
|
||||||
|
import io.swagger.models.auth.In;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,27 +14,76 @@ public class StateConstant {
|
||||||
/**
|
/**
|
||||||
* 车辆状态
|
* 车辆状态
|
||||||
*/
|
*/
|
||||||
public static final Integer VEHICLE_STATUS = 0;
|
public static final Integer VEHICLE_STATUS = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 充电状态
|
* 充电状态
|
||||||
*/
|
*/
|
||||||
public static final Integer CHARGING_STATUS = 0;
|
public static final Integer CHARGING_STATUS = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 运行状态
|
* 运行状态
|
||||||
*/
|
*/
|
||||||
public static final Integer OPERATING_STATUS = 0;
|
public static final Integer OPERATING_STATUS = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* soc状态
|
* soc状态
|
||||||
*/
|
*/
|
||||||
public static final Integer SOC_STATUS = 0;
|
public static final Integer SOC_STATUS = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 可充电储能装置工作状态
|
* 可充电储能装置工作状态
|
||||||
*/
|
*/
|
||||||
public static final Integer CHARGING_ENERGY_STORAGE_STATUS = 0 ;
|
public static final Integer CHARGING_ENERGY_STORAGE_STATUS = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 驱动电机状态
|
||||||
|
*/
|
||||||
|
public static final Integer DRIVE_MOTOR_STATUS = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定位是否有效
|
||||||
|
*/
|
||||||
|
public static final Integer POSITION_STATUS = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EAS(汽车防盗系统)状态
|
||||||
|
*/
|
||||||
|
public static final Integer EAS_STATUS = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PTC(电动加热器)状态
|
||||||
|
*/
|
||||||
|
public static final Integer PTC_STATUS = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ABS(防抱死)状态
|
||||||
|
*/
|
||||||
|
public static final Integer ABS_STATUS = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MCU(电机/逆变器)状态
|
||||||
|
*/
|
||||||
|
public static final Integer MCU_STATUS = 1;
|
||||||
|
/**
|
||||||
|
* 动力电池加热状态
|
||||||
|
*/
|
||||||
|
public static final Integer HEATING_STATUS = 1;
|
||||||
|
/**
|
||||||
|
* 动力电池当前状态
|
||||||
|
*/
|
||||||
|
public static final Integer BATTERY_STATUS = 1;
|
||||||
|
/**
|
||||||
|
* 动力电池保温状态
|
||||||
|
*/
|
||||||
|
public static final Integer BATTERY_INSULATION_STATUS = 1;
|
||||||
|
/**
|
||||||
|
* DCDC(电力交换系统) 状态
|
||||||
|
*/
|
||||||
|
public static final Integer DCDC_STATUS = 1;
|
||||||
|
/**
|
||||||
|
* CHG(充电机)状态
|
||||||
|
*/
|
||||||
|
public static final Integer CHG_STATUS = 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,43 @@
|
||||||
package com.couplet.analyze.msg.service.impl;
|
package com.couplet.analyze.msg.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.couplet.analyze.msg.contents.StateConstant;
|
||||||
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||||
import com.couplet.analyze.msg.service.IncidentService;
|
import com.couplet.analyze.msg.service.IncidentService;
|
||||||
import com.couplet.common.log.annotation.Log;
|
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.aspectj.bridge.Message;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
|
||||||
|
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: LiJiaYao
|
* @Author: LiJiaYao
|
||||||
* @Date: 2024/4/2
|
* @Date: 2024/4/2
|
||||||
* @Description: 故障事件
|
* @Description: 故障事件
|
||||||
*/
|
*/
|
||||||
@Service("breakdown")
|
@Service("breakdown")
|
||||||
@Log4j2
|
public class BreakdownServiceImpl extends KeyExpirationEventMessageListener implements IncidentService {
|
||||||
public class BreakdownServiceImpl implements IncidentService {
|
|
||||||
|
/**
|
||||||
|
* 设置redis存储
|
||||||
|
*/
|
||||||
|
@Autowired
|
||||||
|
private StringRedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
private static Logger log = LoggerFactory.getLogger(BreakdownServiceImpl.class);
|
||||||
|
|
||||||
|
public BreakdownServiceImpl(RedisMessageListenerContainer listenerContainer) {
|
||||||
|
super(listenerContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 故障事件
|
* 故障事件
|
||||||
*
|
*
|
||||||
|
@ -23,10 +47,35 @@ public class BreakdownServiceImpl implements IncidentService {
|
||||||
public void incident(CoupletMsgData coupletMsgData) {
|
public void incident(CoupletMsgData coupletMsgData) {
|
||||||
|
|
||||||
log.info("故障事件开始.....");
|
log.info("故障事件开始.....");
|
||||||
|
long l = System.currentTimeMillis();
|
||||||
|
log.info("开始时间是:"+l);
|
||||||
|
if (StateConstant.VEHICLE_STATUS != coupletMsgData.getVehicleStatus()
|
||||||
|
|| StateConstant.CHARGING_STATUS!=coupletMsgData.getChgStatus()
|
||||||
|
|| StateConstant.OPERATING_STATUS!=coupletMsgData.getOperatingStatus()
|
||||||
|
|| StateConstant.SOC_STATUS!=coupletMsgData.getSocStatus()
|
||||||
|
|| StateConstant.CHARGING_ENERGY_STORAGE_STATUS != coupletMsgData.getChargingEnergyStorageStatus()
|
||||||
|
|| StateConstant.DRIVE_MOTOR_STATUS != coupletMsgData.getDriveMotorStatus()
|
||||||
|
|| StateConstant.POSITION_STATUS != coupletMsgData.getPositionStatus()
|
||||||
|
|| StateConstant.EAS_STATUS != coupletMsgData.getEasStatus()
|
||||||
|
|| StateConstant.PTC_STATUS != coupletMsgData.getPtcStatus()
|
||||||
|
|| StateConstant.ABS_STATUS != coupletMsgData.getAbsStatus()
|
||||||
|
|| StateConstant.MCU_STATUS != coupletMsgData.getMcuStatus()
|
||||||
|
|| StateConstant.HEATING_STATUS != coupletMsgData.getHeatingStatus()
|
||||||
|
|| StateConstant.BATTERY_STATUS != coupletMsgData.getBatteryStatus()
|
||||||
|
|| StateConstant.BATTERY_INSULATION_STATUS != coupletMsgData.getBatteryInsulationStatus()
|
||||||
|
|| StateConstant.DCDC_STATUS != coupletMsgData.getDcdcStatus()
|
||||||
|
|| StateConstant.CHG_STATUS != coupletMsgData.getChgStatus()){
|
||||||
|
//获取过期的key
|
||||||
|
String expireKey = coupletMsgData.toString();
|
||||||
|
redisTemplate.opsForValue().set(String.valueOf(coupletMsgData),JSON.toJSONString(coupletMsgData),10, TimeUnit.MINUTES);
|
||||||
|
|
||||||
log.info("故障事件结束.....");
|
long timeMillis = System.currentTimeMillis();
|
||||||
|
log.debug("失效+key is:"+ "coupletMsgData");
|
||||||
|
log.info("故障事件结束时间:"+timeMillis);
|
||||||
|
log.info("故障事件检测结束.....");
|
||||||
|
|
||||||
|
}
|
||||||
|
log.info("故障事件检测结束.....");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package com.couplet.analyze.msg.service.impl;
|
package com.couplet.analyze.msg.service.impl;
|
||||||
|
|
||||||
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
import com.couplet.analyze.msg.domain.CoupletMsgData;
|
||||||
|
import com.couplet.analyze.msg.mapper.IncidentMapper;
|
||||||
import com.couplet.analyze.msg.service.IncidentService;
|
import com.couplet.analyze.msg.service.IncidentService;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,6 +16,12 @@ import org.springframework.stereotype.Service;
|
||||||
@Log4j2
|
@Log4j2
|
||||||
public class RealTimeDataServiceImpl implements IncidentService {
|
public class RealTimeDataServiceImpl implements IncidentService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询传入的数据是否存在
|
||||||
|
*/
|
||||||
|
@Autowired
|
||||||
|
private IncidentMapper incidentMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 实时数据事件
|
* 实时数据事件
|
||||||
*
|
*
|
||||||
|
@ -26,6 +34,9 @@ public class RealTimeDataServiceImpl implements IncidentService {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
log.info("实时数据事件结束.....");
|
log.info("实时数据事件结束.....");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue