package com.yifu.cloud.plus.v1.yifu.admin.init;

import com.yifu.cloud.plus.v1.yifu.admin.service.SysDictItemService;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.RedisUtil;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Map;

/**
 * @Author fxj
 * @Date 2022/6/23
 * @Description
 * @Version 1.0
 */
@Log4j2
@Component
public class DictItemRedisInit {
	@Autowired
	private SysDictItemService dictItemService;

	@Autowired
	private RedisUtil redisUtil;

	@PostConstruct
	public void init(){
		log.info("字典数据加入缓存初始化开始...");
		Map<String, Object> dictItem = dictItemService.getAllDictItemSub();
		if (Common.isNotNull(dictItem)){
			for (Map.Entry<String,Object> entry:dictItem.entrySet()){
				redisUtil.set(entry.getKey(),entry.getValue());
			}
		}
		log.info("字典数据加入缓存初始化结束...");
	}
}
