package com.xunhong.erp.turbo.infra.app.executor.query;

import com.alicp.jetcache.anno.CacheRefresh;
import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.Cached;
import com.xunhong.erp.turbo.api.infra.dto.qry.SettingShowQry;
import com.xunhong.erp.turbo.api.infra.dto.vo.SettingVO;
import com.xunhong.erp.turbo.infra.app.assembler.SettingAssembler;
import com.xunhong.erp.turbo.infra.domain.entity.Setting;
import com.xunhong.erp.turbo.infra.domain.gateway.SettingGateway;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @author shenyifei
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class SettingShowQryExe {

	private final SettingAssembler settingAssembler;
	private final SettingGateway settingGateway;

	@Cached(name = ":setting:cache:type:", expire = 60, localExpire = 10, timeUnit = TimeUnit.MINUTES, cacheType = CacheType.REMOTE, key = "#settingShowQry.settingKey", cacheNullValue = true)
	@CacheRefresh(refresh = 50, timeUnit = TimeUnit.MINUTES)
	public SettingVO execute(SettingShowQry settingShowQry) {
		Setting setting = settingGateway.show(settingShowQry);

		return settingAssembler.toSettingVO(setting);
	}
}

