Merge branch 'feature' of https://gitee.com/liuyingfang/cashier-admin into feature
# Conflicts: # eladmin-common/src/main/java/cn/ysk/cashier/config/RedisConfig.java # eladmin-system/src/main/java/cn/ysk/cashier/controller/order/TbOrderInfoController.java # eladmin-system/src/main/java/cn/ysk/cashier/dto/order/TbOrderInfoDto.java
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
package cn.ysk.cashier.config;
|
||||
|
||||
import cn.ysk.cashier.service.shop.TbShopInfoService;
|
||||
import cn.ysk.cashier.system.service.UserService;
|
||||
import cn.ysk.cashier.utils.CacheKey;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.redis.connection.Message;
|
||||
import org.springframework.data.redis.connection.MessageListener;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.listener.PatternTopic;
|
||||
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Slf4j
|
||||
@Configuration
|
||||
public class RedisKeyExpirationListener implements MessageListener {
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
private TbShopInfoService shopInfoService;
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
private UserService userServiceu;
|
||||
|
||||
//redis key失效监听
|
||||
@Bean
|
||||
public RedisMessageListenerContainer redisMessageListenerContainer(RedisConnectionFactory connectionFactory) {
|
||||
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
|
||||
container.setConnectionFactory(connectionFactory);
|
||||
// 监听特定键的过期事件
|
||||
container.addMessageListener(this, new PatternTopic("__keyevent@0__:expired"));
|
||||
return container;
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
|
||||
public void onMessage(Message message, byte[] pattern) {
|
||||
String expiredKey = new String(message.getBody());
|
||||
|
||||
// 检查过期的键是否以特定前缀开头
|
||||
if(expiredKey.startsWith(CacheKey.ACT_CODE)) {
|
||||
String account = expiredKey.substring("act_code:".length());
|
||||
log.info("商户到期 账户名为:{}",account);
|
||||
shopInfoService.update(account);
|
||||
userServiceu.upEnableByusername(account);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user