package com.lantone.qc.dbanaly.util;

import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.lantone.qc.pub.util.SpringContextUtil;
import org.apache.commons.collections.MapUtils;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @Description: 页面模板映射工具类
 * @author: rengb
 * @time: 2020/4/30 10:03
 */
public class ModuleMappingUtil {

    public static final Map<String, Map<Set<String>, String>> xmlDataTypeModuleInfo = Maps.newHashMap();

    public static String getXmlDataTypeModuleId(Map<String, String> sourceMap) {
        SpecialStorageUtil specialStorageUtil = SpringContextUtil.getBean("specialStorageUtil");
        if (MapUtils.isEmpty(sourceMap)
                || MapUtils.isEmpty(xmlDataTypeModuleInfo.get(specialStorageUtil.getHospitalIdThreadLocal().get()))) {
            return null;
        }
        Set<String> set = sourceMap.keySet();
        List list = new ArrayList(set);
        list.sort(new Comparator<String>() {
            @Override
            public int compare(String arg0, String arg1) {
                return arg0.compareTo(arg1);//这是顺序
            }
        });
        set = Sets.newLinkedHashSet(list);
        return xmlDataTypeModuleInfo.get(specialStorageUtil.getHospitalIdThreadLocal().get()).get(set);
    }

}