package org.sky.resource.rule.sms;

import org.sky.core.literule.annotation.LiteRuleComponent;
import org.sky.core.literule.core.RuleComponent;
import org.sky.core.log.exception.ServiceException;
import org.sky.core.sms.SmsTemplate;
import org.sky.core.tool.utils.Func;
import org.sky.resource.pojo.entity.Sms;
import org.sky.resource.rule.constant.SmsRuleConstant;
import org.sky.resource.rule.context.SmsContext;

import java.util.Map;

/**
 * 缓存短信构建类
 *
 */
@LiteRuleComponent(id = SmsRuleConstant.CACHE_SMS_RULE, name = "缓存SMS构建")
public class CacheSmsRule extends RuleComponent {

	@Override
	public void process() {
		// 获取上下文
		String tenantId = this.getRequestData();
		SmsContext contextBean = this.getContextBean(SmsContext.class);

		Map<String, Sms> smsPool = contextBean.getSmsPool();
		Map<String, SmsTemplate> templatePool = contextBean.getTemplatePool();
		Sms smsCached = smsPool.get(tenantId);
		SmsTemplate template = templatePool.get(tenantId);
		if (Func.hasEmpty(template, smsCached)) {
			throw new ServiceException("SMS缓存读取失败!");
		}

	}
}
