package org.sky.resource.rule.oss;

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.oss.OssTemplate;
import org.sky.core.tool.utils.Func;
import org.sky.resource.pojo.entity.Oss;
import org.sky.resource.rule.constant.OssRuleConstant;
import org.sky.resource.rule.context.OssContext;

import java.util.Map;

/**
 * OSS缓存读取校验
 *
 */
@LiteRuleComponent(id = OssRuleConstant.OSS_READ_RULE, name = "OSS缓存读取校验")
public class OssReadRule extends RuleComponent {
	@Override
	public void process() {
		String tenantId = this.getRequestData();
		OssContext contextBean = this.getContextBean(OssContext.class);
		Map<String, Oss> ossPool = contextBean.getOssPool();
		Map<String, OssTemplate> templatePool = contextBean.getTemplatePool();
		Oss ossCached = ossPool.get(tenantId);
		OssTemplate template = templatePool.get(tenantId);
		if (Func.hasEmpty(template, ossCached)) {
			throw new ServiceException("OSS缓存读取失败!");
		}
	}
}
