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

import com.alicp.jetcache.anno.CacheInvalidate;
import com.xunhong.erp.turbo.api.infra.dto.cmd.SettingUpdateCmd;
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;

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

	private final SettingAssembler settingAssembler;
	private final SettingGateway settingGateway;

	@CacheInvalidate(name = ":setting:cache:type:", key = "#settingUpdateCmd.settingKey")
	public SettingVO execute(SettingUpdateCmd settingUpdateCmd) {
		Setting setting = settingGateway.update(settingUpdateCmd);
		return settingAssembler.toSettingVO(setting);
	}
}
