package com.wgb.system.service.config;

import com.wgb.system.service.domain.mapper.RegionMapper;
import com.wgb.system.service.domain.mapper.SysMapMapper;
import com.wgb.system.service.domain.model.Region;
import com.wgb.system.service.domain.model.SysMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.List;

@Configuration
@Order(2)
public class InitRegionConfig {

    @Value("${redis.map.layer.val}")
    private String regionLayer;

    @Autowired
    private SysMapMapper sysMapMapper;

    @Autowired
    private RedisTemplate redisTemplate;

    @Bean
    public String  initWathatSecret() {
       List<SysMap> sysMapList= sysMapMapper.selectList(null);
        sysMapList.stream().forEach(i->{
           redisTemplate.opsForValue().set(regionLayer+i.getName(),i);
           redisTemplate.opsForValue().set(regionLayer+i.getId(),i);
            redisTemplate.opsForValue().set(regionLayer+i.getAdcode(),i);
           redisTemplate.opsForValue().set(regionLayer+i.getParentCode(),i);
       });
        return "";
    }
}
