All Downloads are FREE. Search and download functionalities are using the official Maven repository.

yui.comn.hub.data.parser.HubDataToSearchMapParser Maven / Gradle / Ivy

The newest version!
package yui.comn.hub.data.parser;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.springframework.util.CollectionUtils;

import yui.comn.hub.data.handler.HubDataHandlerProcess;
import yui.comn.hub.model.HubConstant;
import yui.comn.hub.model.HubXmlColumn;
import yui.comn.hub.model.HubXmlData;
import yui.comn.hub.xml.parser.HubXmlCache;

/**
 * 把query查询语句翻译出来
 * @author yuyi ([email protected])
 */
public class HubDataToSearchMapParser {
    private static HubDataToSearchMapParser parser = new HubDataToSearchMapParser();
    
    public static HubDataToSearchMapParser getInstance() {
        return parser;
    }
    
    /**
     * 列表转Map列表
     */
    public Map toMapBySearchMap(Class clazz, String name, Map map) {
    	Map colMap = HubXmlCache.getInstance().toSearchMap(clazz, name);
        return toMapBySearchMap(colMap, map);
    }
    
    
    /**
     * 对象转Map
     */
    private Map toMapBySearchMap(Map colMap, Map map) {
        List columnHandlers = new ArrayList<>();
        for (Entry entry : map.entrySet()) {
        	HubXmlColumn column = colMap.get(entry.getKey());
        	if (!CollectionUtils.isEmpty(column.getHandlerConfigs())) {
        		columnHandlers.add(column);
        	}
        }
        
        //数据处理器
        for (HubXmlColumn hubXmlColumn : columnHandlers) {
            HubDataHandlerProcess.getInstance().handle(hubXmlColumn, map);
        }
        
        Map resultMap = new LinkedHashMap<>(); 
        for (Entry entry : map.entrySet()) {
        	HubXmlColumn column = colMap.get(entry.getKey());
        	
        	HubXmlData hxd = new HubXmlData();
        	hxd.setName(column.getName());
        	hxd.setDescr(column.getDescr());
        	hxd.setValue(entry.getValue());
        	hxd.setToValue(entry.getValue());
        	hxd.setMapper(column.getMapper());
        	
        	Object dsrObj = map.get(entry.getKey() + HubConstant.KEY_SUFFIX_CD);
			if (null != dsrObj) {
				hxd.setToValue(dsrObj);
				resultMap.put(entry.getKey(), hxd);
			} else {
				if (!entry.getKey().endsWith(HubConstant.KEY_SUFFIX_CD)) {
					resultMap.put(entry.getKey(), hxd);
				}
			}
		}
        
        return resultMap;
        
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy