package nccloud.web.hrwa.waruleex.action;

import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import nc.hr.utils.ResHelper;
import nc.vo.bd.pub.NODE_TYPE;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFDateTime;
import nc.vo.uif2.LoginContext;
import nccloud.framework.web.container.SessionContext;
import nccloud.web.uapbd.commons.web.ParamUtils;

public class WaRuleExUtil {
	public Map<String, String> getMapRemovedNull(Map<String, String> map) {
		Iterator<Entry<String, String>> it = map.entrySet().iterator();
		while (it.hasNext()) {
			Entry<String, String> itEntry = it.next();
			Object itValue = itEntry.getValue();
			if (itValue == null || "".equals(itValue)) {
				it.remove();
			}
		}
		return map;
	}
/**
 * 
 * 上午9:55:55
 * msw
 * @param param
 * @return：
 * @throws BusinessException 
 *
 */
	public static LoginContext getLogincontext(ParamUtils param,Map<String,String> map) throws BusinessException {
		LoginContext context = new LoginContext();
		String pk_org=map.isEmpty() ? param.getString("pk_org", null) : map.get("pk_org");
		if (pk_org == null) {
			throw new BusinessException( ResHelper.getString("60130payrule",
					"060130payrule0005")/* @res "请选择人力资源组织！" */);
		}
		context.setPk_org(pk_org);
		context.setPkorgs(new String[] { pk_org });
		String nodeType =map.isEmpty() ? param.getString("node_type", null) : map.get("node_type");
		if ("GLOBE_NODE".equals(nodeType)) {
			context.setNodeType(NODE_TYPE.GLOBE_NODE);
		} else if ("GROUP_NODE".equals(nodeType)) {
			context.setNodeType(NODE_TYPE.GROUP_NODE);
		} else {
			context.setNodeType(NODE_TYPE.ORG_NODE);
		}
		context.setPk_group(SessionContext.getInstance().getClientInfo().getPk_group());
		return context;
	}
	/**
	 * 
	 * 上午9:21:34
	 * msw
	 * @param str
	 * @return：
	 * 去除前端传递空字符串的情况
	 *
	 */
	public static String getStrRemovedNull(String str) {
		if (str == null) {
			return null;
		}
		str = str.replaceAll("value=}", "value=null}");
		str = str.replaceAll("value=,", "value=null,");
		str = str.replaceAll("display=,", "display=null,");
		str = str.replaceAll("display=},", "display=null},");
		return str;
	}
	/**
	 * 
	 * 下午2:52:41
	 * msw
	 * @param value
	 * @return：
	 *
	 */
	public static UFDateTime getUFDateTime(Object value) {
		if (value == null || value.toString().trim().equals("")) {
			return new UFDateTime();
		} else if (value instanceof UFDateTime) {
			return (UFDateTime) value;
		} else {
			return new UFDateTime(value.toString().trim());
		}
	}
}
