package org.jeecg.modules.adweb.enquiry.service;

import org.jeecg.modules.adweb.common.util.JedisUtil;
import org.jeecg.modules.adweb.listener.EnquiryEmailSenderListener;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public class EnquiryRedisService {

    @Value(value = "${spring.data.redis.host}")
    private String JEDIS_IP;

    @Value(value = "${spring.data.redis.port}")
    private int JEDIS_PORT;

    @Value(value = "${spring.data.redis.password:#{null}}")
    private String JEDIS_PASSWORD;

    public void init() {
        JedisUtil.initJedisPool(JEDIS_IP, JEDIS_PORT, JEDIS_PASSWORD);
    }

    @Async
    public void startEnquiryEmailMessageListener(
            String channel, IEnquiryEmailMessageService enquiryEmailMessageService) {
        EnquiryEmailSenderListener listener = new EnquiryEmailSenderListener();
        listener.setEnquiryEmailMessageService(enquiryEmailMessageService);
        JedisUtil.subscribeMsg(listener, channel);
    }
}
