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

import com.alicp.jetcache.anno.CacheInvalidate;
import com.xunhong.erp.turbo.api.infra.dto.cmd.DictionaryCreateCmd;
import com.xunhong.erp.turbo.api.infra.dto.vo.DictionaryVO;
import com.xunhong.erp.turbo.infra.app.assembler.DictionaryAssembler;
import com.xunhong.erp.turbo.infra.domain.entity.Dictionary;
import com.xunhong.erp.turbo.infra.domain.gateway.DictionaryGateway;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

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

	private final DictionaryAssembler dictionaryAssembler;
	private final DictionaryGateway dictionaryGateway;

	@CacheInvalidate(name = ":dictionary:cache:type:", key = "#dictionaryCreateCmd.type")
	public DictionaryVO execute(DictionaryCreateCmd dictionaryCreateCmd) {
		Dictionary dictionary = dictionaryGateway.save(dictionaryCreateCmd);

		return dictionaryAssembler.toDictionaryVO(dictionary);
	}
}

