package com.cim.idm.mwmsextend.generic.util;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.cim.idm.framework.IDMFrameServiceProxy;
import com.cim.idm.wmsextend.generic.errorHandler.CustomException;

public class PDAVersionCheckUtil {
	/** 
	 * 比较版本号的大小,前者大则返回一个正数,后者大返回一个负数,相等则返回0 
	 * @param version1 
	 * @param version2 
	 * @return 
	 */  
	public String compareVersion(String version1, String version2) throws Exception {  
	    if (version1 == null || version2 == null) {  
	        throw new CustomException("compareVersion error:illegal params.");  
	    }  
	    String[] versionArray1 = version1.split("\\.");//注意此处为正则匹配，不能用"."；  
	    String[] versionArray2 = version2.split("\\.");   
	    int minLength = Math.min(versionArray1.length, versionArray2.length);//取最小长度值  
	    String result = "="; 
        for (int i=0;i<minLength;i++)
        {
	     if(Integer.parseInt(versionArray1[i].toString())>Integer.parseInt(versionArray2[i].toString()))
	     {
	    	 result =">";
	    	 break;
	     }
	     if(Integer.parseInt(versionArray1[i].toString())<Integer.parseInt(versionArray2[i].toString()))
	     {
	    	 result ="<";
	    	 break;
	     }
	    }  
	    //如果已经分出大小，则直接返回，如果未分出大小，则再比较位数，有子版本的为大；  
        result = (!result.equalsIgnoreCase("=")) ? result : (versionArray1.length==versionArray2.length)? result : (versionArray1.length>versionArray2.length)?">":"<";  
	    return result;  
	}  
	
	public void accessFlag(String flag)throws Exception{
		if(flag.equalsIgnoreCase("Y"))
		{
			
		}
		else
		{
			throw new Exception("该版本不可用.");
		}
		
	} 
	public String PDADBVersion(String EnumName){
		Map<String, Object> bindMap = new HashMap<String, Object>();
		bindMap.put("ENUMNAME", EnumName);
		String SQL = "SELECT ENUMVALUE FROM ENUMDEFVALUE WHERE ENUMNAME =:ENUMNAME";
		List<Map<String, Object>> sqlResult = IDMFrameServiceProxy.getSqlTemplate().queryForList(SQL, bindMap);
		return sqlResult.get(0).get("ENUMVALUE").toString();
	}
	
}
