package com.unis.crk.utils;

import cn.hutool.core.io.resource.ClassPathResource;
import org.apache.commons.io.IOUtils;
import org.springframework.util.ResourceUtils;

import java.io.FileInputStream;
import java.net.URL;
import java.util.LinkedHashMap;
import java.util.Map;

public class SqpMapUtil {
	private final static Map<String, String> SQL_MAP =new LinkedHashMap<>();
	static {
		try {
		    //此种写法在打包jar情况下能正常使用
            URL url1 = ResourceUtils.getURL("classpath:SqlMap/sql.xml");
			String mapping = IOUtils.toString(url1);
			Xml xml = new Xml(mapping);
			Map<String, String> sqls_ = xml.getText();
			for (Map.Entry<String, String> entry : sqls_.entrySet()) {
				SQL_MAP.put(entry.getKey(), entry.getValue());
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
//	static {
//		try {
//			URL url1 = ResourceUtils.getURL("classpath:SqlMap/sql.xml");
//			UrlResource resource1 = new UrlResource(url1);
//			Xml xml = new Xml(new FileInputStream(resource1.getFile()));
//			Map<String, String> sqls_ = xml.getText();
//			for (Map.Entry<String, String> entry : sqls_.entrySet()) {
//				SQL_MAP.put(entry.getKey(), entry.getValue());
//			}
//
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//
//	}
	public static String getSql(String key) {
	    return SQL_MAP.get(key);

	  }

}
