package nccloud.web.hrwa.waruleex.action.formula;

import java.util.List;
import java.util.Map;

import nc.itf.org.IOrgConst;
import nc.vo.bd.pub.NODE_TYPE;
import nc.vo.wa.pub.WaLoginContext;
import nccloud.commons.lang.StringUtils;
import nccloud.framework.web.container.IRequest;
import nccloud.framework.web.container.SessionContext;
import nccloud.framework.web.json.JsonFactory;
import nccloud.web.hr.formula.HRFormulaType4Web;
import nccloud.web.hr.pub.HRCommonAction;
import nccloud.web.hrwa.waruleex.action.formula.factory.WaRuleExFormulaTypeFactory;
import nccloud.web.uapbd.commons.web.ParamUtils;

/**
 * 查询公式项
 * 
 * @author Administrator
 *
 */
public class WaRuleExQueryFormulaTypeAction extends HRCommonAction {

	@Override
	public <T> Object execute(IRequest request, T para) throws Exception {
		ParamUtils param = new ParamUtils(request);
		String pk_group = SessionContext.getInstance().getClientInfo().getPk_group();
		String pk_user = SessionContext.getInstance().getClientInfo().getUserid();
		String pk_org = param.getString("pk_org", pk_group);
		WaLoginContext context = new WaLoginContext();
		context.setPk_org(param.getString("pk_org", null));
		context.setPk_group(pk_group);
		context.setPk_loginUser(pk_user);
		// 设置组织类型
		NODE_TYPE nodeType = NODE_TYPE.ORG_NODE;
		if (StringUtils.isBlank(pk_org)) {
			throw new RuntimeException("Error Only4Dev:pk_org一定要传！！！！！！！！！！");
		} else if (IOrgConst.GLOBEORG.equals(pk_org)) {
			nodeType = NODE_TYPE.GLOBE_NODE;
		} else if (pk_org.equals(pk_group)) {
			nodeType = NODE_TYPE.GROUP_NODE;
		} else {
			nodeType = NODE_TYPE.ORG_NODE;
		}
		context.setNodeType(nodeType);
		WaRuleExFormulaTypeFactory factory = new WaRuleExFormulaTypeFactory(context);
		Map<String, List<HRFormulaType4Web>> result = factory.getFormulaTypes();
		if (result.get("dsList").size() == 4) {
			result.get("dsList").remove(3);// 删除薪资函数
		}
		return JsonFactory.create().toJson(result);
	}

}
