package com.cloudcross.ssp.listener;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 初始化一些数据，让项目一启动就加载进内存
 * @author chenyou
 *
 */
public class InitData {
	private static InitData instance;
	
	//用来存储地域的location,cn,cn_city进内存,这里以location为key,value是"cn,cn_city"
	public static Map<String, String> locationMap = new HashMap<String, String>();
	//这里存储数聚子场景
	public static Map<Integer, String> placeMap = new HashMap<Integer, String>();
	//这里存储数聚场景
	public static Map<Integer, String> placeClassInfoMap = new HashMap<Integer, String>();
	//这里存储数聚子场景和数聚场景的对应关系
	public static Map<Integer, List<Long>> placeClassMap = new HashMap<Integer, List<Long>>();
	
	private InitData() {
		
	}
	
	public InitData getInitDataInstance() {
		if(null == instance) {
			instance = new InitData();
		}
		
		return instance;
	}
	
	/**
	 * 根据省得到location,没有则返回空值
	 * @param cn
	 * @return
	 */
	public static String getLocation(String cn) {
		for(Map.Entry<String, String> map : locationMap.entrySet()) {
			if(map.getValue().equals(cn)) {
				return map.getKey();
			}
		}
		
		return null;
	}
	
	
	/**
	 * 根据省和市得到location,没有则返回空值
	 * @param cn
	 * @return
	 */
	public static String getLocation(String cn, String cnCity) {
		for(Map.Entry<String, String> map : locationMap.entrySet()) {
			if(map.getValue().equals(cn + "," + cnCity)) {
				return map.getKey();
			}
		}
		
		return null;
	}
	
	/**
	 * 根据数聚子场景id得到它的数聚场景的名称
	 * @param placeId
	 * @return
	 */
	public static String getPlaceClassName(Long placeId) {
		for(Map.Entry<Integer, List<Long>> map : placeClassMap.entrySet()) {
			if(map.getValue().contains(placeId)) {
				return InitData.placeClassInfoMap.get(map.getKey());
			}
		}
		
		return null;
	}
}
