package nccloud.web.hrwa.waruleex.action;

import nc.hr.utils.CommonUtils;
import nc.hr.utils.ResHelper;
import nc.vo.bd.pub.NODE_TYPE;
import nc.vo.hrwa.waruleex.AggWageformExVO;
import nc.vo.pub.BusinessException;
import nc.vo.uif2.LoginContext;
import nc.vo.util.ManageModeUtil;
import nccloud.framework.web.container.IRequest;
import nccloud.web.hr.pub.HRCommonAction;
import nccloud.web.hr.pub.HRNccUtils;
import nccloud.web.uapbd.commons.web.ParamUtils;
/**
 * 
 * 下午4:20:50
 * msw：
 * 薪资规则点增加按钮时进行校验,若校验通过，返回true,不通过，直接抛错
 *
 */
public class WaRuleExBeforeDoAction extends HRCommonAction {

	@Override
	public <T> Object execute(IRequest request, T para) throws Exception {
		ParamUtils param = new ParamUtils(request);
		LoginContext context = HRNccUtils.getLoginContext(param);
		String opType = param.getString("op_type", null);// 前端必须传入操作运算符，例如add,copy,edit
		if (opType == null) {
			return null;
		}
		if ("add".equals(opType) || "copy".equals(opType)) {
			beforeDoAction(context, opType, null);
		} else if ("edit".equals(opType) || "delete".equals(opType)) {
			String pkWaWageform = param.getString("pk_wa_wageformex", null);
			WaRuleExCommon common = new WaRuleExCommon();
			AggWageformExVO aggWageformVO = common.listHandleData(context, pkWaWageform);
			beforeDoAction(context, opType, aggWageformVO);
		}
		return true;
	}
/**
 * 
 * 2019年6月27日下午4:47:35
 * msw
 * @param context
 * @param opType
 * @param ob
 * @throws BusinessException：
 *
 */
	private void beforeDoAction(LoginContext context, String opType, Object ob) throws BusinessException {
		// 检查是否已经选择了人力资源组织人力资源组织
		try {
			if (context.getNodeType() != NODE_TYPE.GROUP_NODE && context.getNodeType() != NODE_TYPE.GLOBE_NODE) {
				CommonUtils.checkOrg(context);
			}
		} catch (BusinessException ex) {
			throw new BusinessException(ResHelper.getString("60130payrule",
					"060130payrule0005")/* @res "请选择人力资源组织！" */);
		}
		// 增加的场合,没有选中数据的场合不进行管控模式的校验
		if ("add".equals(opType) || "copy".equals(opType) || ob == null) {
			return;
		}
		// 管控模式的校验
		boolean blnIsCanOperator = ManageModeUtil.manageable(ob, context);
		if (!blnIsCanOperator) {
			throw new BusinessException(ManageModeUtil.getDisManageableMsg(context.getNodeType()));
		}
	}
}
