快码表类库DataDictionary

 代码没什么难度,主要是学习这种基础数据使用思想。

 

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

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;

public class DataDictionary {
	
	private static final Logger logger = LoggerFactory.getLogger(DataDictionary.class);
	
	private static Map<String, Map<String, String>> dictionary = new HashMap<String, Map<String, String>>();
	
	static{
		loadDictionary();
	}
	
	private static void loadDictionary(){
		logger.debug("loadDictionary begin...");
		
		// 获取spring bean容器
		WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
		ISysLookupTypeDao typedao = (ISysLookupTypeDao) wac.getBean("iSysLookupTypeDao");
		ISysLookupValueDao valuedao = (ISysLookupValueDao) wac.getBean("iSysLookupValueDao");
		List<SysLookupType> types = typedao.getAll();
		for(SysLookupType type : types){
			logger.debug(type.getLookupName() + "[" + type.getLookupCode() + "]:");
			
			Map<String, String> valuemap = new HashMap<String, String>();
			List<SysLookupValue> values = valuedao.getSysLookupValueByCode(type.getLookupCode());
			for(SysLookupValue value : values){
				logger.debug(value.getLookupValue() + " - " + value.getMeaning());
				
				valuemap.put(value.getLookupValue(), value.getMeaning());
			}
			dictionary.put(type.getLookupCode(), valuemap);
		}
		
		logger.debug("loadDictionary end...");
	}

	/**
	 * 通过lookupcode 与 lookupvalue 检索 meaning
	 * 
	 * @param code
	 * @param value
	 * @return
	 */
	public static String search(String code, String value){
		return dictionary.get(code).get(value);
	}
	
	public static void addOrUpdateToDictionary(String code, String value, String meaning){
		dictionary.get(code).put(value, meaning);
	}
	
	public static void removeFromDictionary(String code, String value){
		dictionary.get(code).remove(value);
	}
}

 

SYS_LOOKUP_TYPE:
快码表类库DataDictionary
 

 

SYS_LOOKUP_VALUE:
快码表类库DataDictionary
 

 

 

 

你可能感兴趣的:(Data)