feat: 事件系统

server_five_liuyunhu
lijiayao 2024-04-04 15:04:25 +08:00
parent 9e8106ab46
commit 041aaa4654
7 changed files with 202 additions and 12 deletions

View File

@ -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);
}
}

View File

@ -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>

View File

@ -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 {

View File

@ -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();
}
}

View File

@ -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;
} }

View File

@ -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("故障事件检测结束.....");
} }
/** /**

View File

@ -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("实时数据事件结束.....");
} }