package com.benyun.core.init;

import com.benyun.core.dao.AddrCategoryDao;
import com.benyun.core.entity.AddrCategory;
import com.benyun.core.utils.HashUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

@Configuration
public class BenyunCoreInit {
    @Autowired
    AddrCategoryDao addrCategoryDao;

    @Bean("cityTierMap")
    public HashMap getCityTierMap(){
        HashMap<String, String> hashMap = new HashMap<>();
        for (AddrCategory addrCategory : addrCategoryDao.selectList(null)) {
            if(addrCategory.getCityTier() != null && !addrCategory.getCityTier().equals("")){
                if(addrCategory.getDistrict()!=null && !addrCategory.getDistrict().equals("")){
                    hashMap.put(addrCategory.getAddrCode(), addrCategory.getCityTier());
                }else if(addrCategory.getCity()!=null && !addrCategory.getCity().equals("")){
                    hashMap.put(addrCategory.getAddrCode().substring(0,4), addrCategory.getCityTier());
                }else
                    hashMap.put(addrCategory.getAddrCode().substring(0,2), addrCategory.getCityTier());
            }
        }
//        for (String s : hashMap.keySet()) {
//            System.out.println(s + " " +hashMap.get(s));
//        }

        return hashMap;
    }
}
