package com.ruoyi.web.work.redis;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.work.domain.ResumeDeliver;
import com.ruoyi.web.work.service.IResumeDeliverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.stereotype.Service;

@Service
public class RedisKeyExpirationListener implements MessageListener {

    @Autowired
    private IResumeDeliverService resumeDeliverService;

    @Override
    public void onMessage(Message message, byte[] pattern) {
        String expiredKey = message.toString();
        // 处理过期事件，更新数据库
        System.out.println("Key expired: " + expiredKey);
        if (expiredKey.contains("app_deliver")) {
            ResumeDeliver deliver = resumeDeliverService.getById(StringUtils.getId(expiredKey));
            if (deliver != null) {
                deliver.setIsExpire(1);
                resumeDeliverService.updateById(deliver);
            }
        }
    }
}