package com.dev.swms.server.utils;

import java.math.BigDecimal;

import com.dev.swms.server.service.GlobalParamUtils;

public class CheckUtils{

	/**
	 * 判断字符串是否为空
	 */
	public static Boolean isEmpty(String str) {
		if(str==null||str.equals("")){
			return true;
		}else{
			return false;
		}
	}
	
	/**
	 * 判断字符串是否为空
	 */
	public static Boolean isTrimEmpty(String str) {
		if(str==null||str.equals("")||str.trim().equals("")){
			return true;
		}else{
			return false;
		}
	}
	/**去除字符串前后字符-*/
	public static String extractChar(String str) {
		if(str==null||str.equals("")||str.trim().equals("")||str.trim().equals("-")){
			return "";
		}else{
			if(str.substring(0,1).equals("-")){
				str=str.substring(1,str.length());
			}
			if(str.substring(str.length()-1,str.length()).equals("-")){
				str=str.substring(0,str.length()-1);
			}
			return str;
		}
	}
	
	/**校验是否为正确格式数字*/
	public static double format3Fraction(Object a) {
		return formatByPrecision(a,3);
	}
	
	/**检验是否为时间格式*/
	public static double format2Fraction(Object a){
		return formatByPrecision(a,2);
	}
	
	public static double format1Fraction(Object a){
		return formatByPrecision(a,1);
	}
	
	public static double formatByPrecision(Object o,int precision){
		double pDouble = Double.parseDouble(o.toString());
		BigDecimal  bd = new  BigDecimal(pDouble);
		BigDecimal  bdWithPrecision = bd.setScale(precision,BigDecimal.ROUND_HALF_UP);
		pDouble = bdWithPrecision.doubleValue();
		return pDouble;
	}
	
	public static double formateByDefaultPrecesion(Object o){
		int pre = Integer.valueOf(GlobalParamUtils.getGloableStringValue("maintainTableDecimal")).intValue();
		return formatByPrecision(o,pre);
	}


}
