package com.ruoyi.demo.init;

import com.ruoyi.demo.constant.RedisInitContant;
import com.ruoyi.demo.entity.AddrCategory;
import com.ruoyi.demo.mapper.AddrCategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;

import javax.annotation.PostConstruct;
@Configuration
public class BenyunCoreInit {
    @Autowired
    AddrCategoryMapper addrCategoryDao;

    @Autowired
    RedisTemplate redisTemplate;


    @PostConstruct
    public void initAddrCodeMap() {
        if(redisTemplate.hasKey(RedisInitContant.INIT_ADDR_CODE_MAP))
            return;
        System.out.println("正在加载AddrCodeMap");
        for (AddrCategory addrCode : addrCategoryDao.selectList(null)) {
            redisTemplate.boundHashOps(RedisInitContant.INIT_ADDR_CODE_MAP).put(addrCode.getAddrCode(), addrCode.getAddrInfo());
        }
        System.out.println("AddrCodeMap已完成");
    }

}
