package yem.wm.cm.sys.utils;


import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import yem.base.common.utils.DynamicObjectUtil;
import yem.base.common.utils.YEM;
import yem.wm.cm.csrm.enums.PageIdEnum;

import java.math.BigDecimal;
import java.util.Map;

/**
 * 客商帮助类
 * @author xwudd
 *
 */
public class RatingUtil {
	
	//得出评分等级 下拉列表	
	public static String setLevel(DynamicObject dynamicObject,BigDecimal totalscore,String level) {
		return setLevel(dynamicObject, totalscore, level, true);
	}
	
	public static String setLevel(DynamicObject dynamicObject,BigDecimal totalscore,String level,boolean returnKey) {
		String value = "";
		String selectfields = DynamicObjectUtil.getSelectfields(PageIdEnum.BD_GRADINGSCALE.getPageId(), false);
		DynamicObject[] gradingScales = BusinessDataServiceHelper.load(PageIdEnum.BD_GRADINGSCALE.getPageId(), selectfields,null);
		for(DynamicObject gradingScale : gradingScales) {
			String name = gradingScale.getString("name");
			BigDecimal upperLimit = gradingScale.getBigDecimal("yem_upperlimit");//上限
			BigDecimal lowerLimit = gradingScale.getBigDecimal("yem_lowerlimit");//下限
			if(totalscore.compareTo(upperLimit) <= 0 && totalscore.compareTo(lowerLimit) > 0) {
				if(returnKey) {
					value = name;
				}
				break;
			}
		}
		return value;
	}
}
