package nccloud.web.hrwa.ref.basic;

import java.util.Map;

import nc.bs.logging.Logger;
import nc.hr.utils.SQLHelper;
import nc.vo.pub.BusinessException;
import nc.vo.util.VisibleUtil;
import nc.vo.wa.grade.WaGradeVO;
import nccloud.framework.web.processor.refgrid.RefQueryInfo;
import nccloud.framework.web.ui.meta.RefMeta;
import nccloud.framework.web.ui.meta.TreeRefMeta;
import nccloud.web.refer.DefaultGridRefAction;

/**
 * 薪资类别标准列表参照
 * 
 * @author YuCheng
 *
 */
public class WaGradeExGridRef extends DefaultGridRefAction {

	@Override
	public RefMeta getRefMeta(RefQueryInfo refQueryInfo) {
		TreeRefMeta meta = new TreeRefMeta();
		meta.setTableName("wa_grade");
		meta.setExtraFields(new String[] { "code", SQLHelper.getMultiLangNameColumn("name"), "vmemo", "pk_wa_grd", "pk_group", "pk_org", "ismultsec",
				WaGradeVO.ISRANGE, WaGradeVO.PRMLV_MONEY_SORT, WaGradeVO.SECLV_MONEY_SORT });
		meta.setPkField("pk_wa_grd");
		meta.setCodeField("code");
		meta.setNameField(SQLHelper.getMultiLangNameColumn("name"));
		return meta;
	}

	@Override
	public String getExtraSql(RefQueryInfo refQueryInfo, RefMeta refMeta) {
		Map<String, String> param = refQueryInfo.getQueryCondition();
		if (param == null)
			return null;
		StringBuffer sbWhere = new StringBuffer(
				" and wa_grade.pk_wa_grd in (select pk_wa_grd from wa_grade_ver where effect_flag = 'Y') and wa_grade.standard_type = '1'");
		if (param.get("pk_wa_item") != null) {
			sbWhere.append(" and wa_grade.pk_wa_item = '" + param.get("pk_wa_item") + "'");
		}
		if (param.get("pk_group") != null && param.get("pk_org") != null) {
			sbWhere.append(" and wa_grade.pk_org ='"+param.get("pk_org")+"' and wa_grade.pk_group ='"+param.get("pk_group")+"'");
		}
//		try {
//			if (param.get("pk_group") != null && param.get("pk_org") != null) {
//				sbWhere.append(" and " + VisibleUtil.getRefVisibleCondition(param.get("pk_group"), param.get("pk_org"),
//						"92054d71-866d-4d82-9085-75ad2f63d4c1"));
//			}
//		} catch (BusinessException e) {
//			Logger.error(e.getMessage());
//		}
		return sbWhere.toString();
	}
}
