package nccloud.web.hr.rpt.action;

import nc.vo.hr.tools.pub.GeneralVO;
import nc.vo.pub.BusinessRuntimeException;
import nc.vo.uif2.LoginContext;
import nc.wa.smartmodel.provider.util.WaProviderConst;
import nccloud.framework.web.container.IRequest;
import nccloud.web.hr.pub.HRCommonAction;
import nccloud.web.hr.pub.HRNccTemplateUtils;
import nccloud.web.hr.pub.HRNccUtils;
import nccloud.web.hrhi.pub.PsndocTempUtils;
import nccloud.web.uapbd.commons.web.ParamUtils;
import nccloud.commons.lang.StringUtils;

import java.util.HashMap;

/**
 * 编辑前事件
 */
public class WaRptQryBeforeEditAction extends HRCommonAction {

	@Override
	public <T> Object execute(IRequest iRequest, T t) throws Exception {
		ParamUtils param = new ParamUtils(iRequest);
		LoginContext loginContext = HRNccUtils.getLoginContext(param);

		String areaCode = param.getString("area_code", null);
		if (StringUtils.isBlank(areaCode)) {
			throw new BusinessRuntimeException("Parameter Error!");
		}

		String itemKey = param.getString("key", null);
		if (StringUtils.isBlank(itemKey)) {
			throw new BusinessRuntimeException("Parameter Error!");
		}
		HashMap result = new HashMap();
		result.put("editable", true);
		// model参数
		GeneralVO vo = HRNccTemplateUtils.getVOFromForm(GeneralVO.class, PsndocTempUtils.getModelStr(param, null));
		if ("WaAccountByYearQueryConditionPanel".equals(areaCode)) {
			// 单位年度工资台账
			if (WaProviderConst.BASE_CYEAR.equals(itemKey)) {
				HashMap refParam = new HashMap();
				// ) 子表的部门不限制是否撤销,保存时交验
				refParam.put("pk_wa_class", vo.getAttributeValue(WaProviderConst.WA_CLASS_PK));
				result.put("refParam", refParam);
				return result;
			} else if (WaProviderConst.WA_CLASS_PK.equals(itemKey)) {
				HashMap refParam = new HashMap();
				// ) 子表的部门不限制是否撤销,保存时交验
				refParam.put("pk_org", loginContext.getPk_org());
				refParam.put("pk_group", loginContext.getPk_group());
				result.put("refParam", refParam);
				return result;
			}
		} else if ("WaItemQueryConditionPanelForGroup".equals(areaCode) || "WaBaseQueryConditionPanel".equals(areaCode) || "WaSumByPsnclQueryConditionPanel".equals(areaCode)
				|| "WaSumByDeptQueryConditionPanel".equals(areaCode) || "WaItemQueryConditionPanel".equals(areaCode)) {
			// 集团级薪资明细表&薪资变动***表&人员类别汇总表&部门汇总表&薪资明细表
			if (WaProviderConst.BASE_CPERIOD.equals(itemKey) || WaProviderConst.COMPARE_CPERIOD.equals(itemKey)) {
				HashMap refParam = new HashMap();
				// ) 子表的部门不限制是否撤销,保存时交验
				refParam.put("pk_wa_class", vo.getAttributeValue(WaProviderConst.WA_CLASS_PK));
				result.put("refParam", refParam);
				return result;
			} else if (WaProviderConst.WA_CLASS_PK.equals(itemKey)) {
				HashMap refParam = new HashMap();
				// ) 子表的部门不限制是否撤销,保存时交验
				refParam.put("pk_org", loginContext.getPk_org());
				refParam.put("pk_group", loginContext.getPk_group());
				result.put("refParam", refParam);
				return result;
			}
		} else if ("WaAccountByMonthQueryConditionPanel".equals(areaCode)) {
			// 年度对比分析
			if (WaProviderConst.BASE_CYEAR.equals(itemKey) || WaProviderConst.COMPARE_CYEAR.equals(itemKey)) {
				HashMap refParam = new HashMap();
				// ) 子表的部门不限制是否撤销,保存时交验
				refParam.put("pk_wa_class", vo.getAttributeValue(WaProviderConst.WA_CLASS_PK));
				result.put("refParam", refParam);
				return result;
			} else if (WaProviderConst.WA_CLASS_PK.equals(itemKey)) {
				HashMap refParam = new HashMap();
				// ) 子表的部门不限制是否撤销,保存时交验
				refParam.put("pk_org", loginContext.getPk_org());
				refParam.put("pk_group", loginContext.getPk_group());
				result.put("refParam", refParam);
				return result;
			}
		} else if ("WaMultiRptQueryConditionPanel".equals(areaCode)) {
			if (WaProviderConst.WA_CLASS_PK.equals(itemKey)) {
				HashMap refParam = new HashMap();
				// ) 子表的部门不限制是否撤销,保存时交验
				refParam.put("waYear", vo.getAttributeValue(WaProviderConst.CAC_CYEAR));
				String cacCperiod = (String) vo.getAttributeValue(WaProviderConst.CAC_CPERIOD);
				if (cacCperiod != null && cacCperiod.trim().length() == 1) {
					cacCperiod = "0" + cacCperiod.trim();
				}
				refParam.put("waPeriod", cacCperiod);
				refParam.put("pk_org", loginContext.getPk_org());
				result.put("refParam", refParam);
				return result;
			}
		}
		
		if("WaSumByDeptQueryConditionPanel".equals(areaCode) || "DeptWaAccountQueryConditionPanel".equals(areaCode)){
			if (WaProviderConst.SUM_DEPT.equals(itemKey)) {
				HashMap refParam = new HashMap();
				// ) 子表的部门不限制是否撤销,保存时交验
				refParam.put("pk_org", loginContext.getPk_org());
				refParam.put("pk_group", loginContext.getPk_group());
				result.put("refParam", refParam);
				return result;
			}
		}

		return result;
	}
}
