package nc.ui.wa.ref;

import nc.bs.logging.Logger;
import nc.hr.utils.ResHelper;
import nc.ui.bd.ref.AbstractRefModel;
import nc.vo.pub.BusinessException;
import nc.vo.util.VisibleUtil;
import nc.vo.wa.grade.WaGradeVO;

import nccloud.commons.lang.StringUtils;
/**
 * 薪资类别标准(版本)参照模型
 *
 * @author: xuhw
 * @date: 2009-11-17 下午12:56:56
 * @since: eHR V6.0
 * @走查人:
 * @走查日期:
 * @修改人:
 * @修改日期:
 */
public class WaGradeVerExRefModel extends AbstractRefModel
{
	/**
	 * 薪资标准类别
	 */
	public final static String WA_GRADE_BEAN_ID = "92054d71-866d-4d82-9085-75ad2f63d4c1";
	/**
	 * 薪资项目
	 */
	private String strPkItem;

	public WaGradeVerExRefModel(String pk_item, String strPKOrg)
	{
		super();
		this.setTableName(" (select wa_grade_ver.pk_wa_gradever, \r\n" + 
				"               wa_grade.code gradever_num, \r\n" + 
				"               wa_grade.name gradever_name, \r\n" + 
				"               wa_grade.pk_org, \r\n" + 
				"               wa_grade.pk_group,  \r\n" + 
				"               wa_grade_ver.gradever_name name, \r\n" + 
				"               wa_grade_ver.gradever_num code, \r\n" + 
				"               wa_grade_ver.effect_flag \r\n" + 
				"               from wa_grade_ver   \r\n" + 
				"               left join wa_grade \r\n" + 
				"                    on wa_grade.pk_wa_grd = wa_grade_ver.pk_wa_grd\r\n" + 
				"               inner join (select distinct ver.pk_wa_gradever,wg.code,wg.name from wa_gradeorg org \r\n" + 
				"                   left join wa_grade wg\r\n" + 
				"                        on org.pk_wa_grade = wg.pk_wa_grd\r\n" + 
				"                   left join wa_grade_ver ver\r\n" + 
				"                        on wg.pk_wa_grd = ver.pk_wa_grd\r\n" + 
				"                 where ver.effect_flag = 'Y') orgtemp\r\n" + 
				"                    on orgtemp.pk_wa_gradever = wa_grade_ver.pk_wa_gradever and wa_grade.code = orgtemp.code \r\n" + 
				"                    and orgtemp.name = wa_grade.name\r\n" + 
				"               where nvl(wa_grade_ver.dr,0) = 0 and nvl(wa_grade.dr,0) = 0) temp ");
		this.setFieldCode(new String[]
				{ "code", "name", "gradever_name","gradever_num" });
		this.setFieldName(new String[]
		{ ResHelper.getString("6013commonbasic","06013commonbasic0043")/*@res "薪资标准类别编码"*/, ResHelper.getString("6013commonbasic","06013commonbasic0044")/*@res "薪资标准类别名称"*/, ResHelper.getString("common","UC000-0003660")/*@res "说明"*/ });
		this.setPkFieldCode("pk_wa_gradever");
		this.setHiddenFieldCode(new String[]
				{ "pk_wa_gradever", "pk_group", "pk_org","effect_flag"});
		this.setDefaultFieldCount(4);
		this.setRefTitle("薪资类别标准(版本)");
		this.setStrPkItem(pk_item);
		setRefCodeField("name");
		setRefNameField("name");
//		begin 20150723 xiejie3 参照的缓存键值是用bd_refinfo表的name字段值，目前很多参照的refModel中没有设置RefNodeName的值
		setRefNodeName("薪资标准(版本)"); /*-=notranslate=-*/
//		end
	}

	public WaGradeVerExRefModel()
	{
		super();
		this.setTableName(" (select wa_grade_ver.pk_wa_gradever, \r\n" + 
				"               wa_grade.code gradever_num, \r\n" + 
				"               wa_grade.name gradever_name, \r\n" + 
				"               wa_grade.pk_org, \r\n" + 
				"               wa_grade.pk_group,  \r\n" + 
				"               wa_grade_ver.gradever_name name, \r\n" + 
				"               wa_grade_ver.gradever_num code, \r\n" + 
				"               wa_grade_ver.effect_flag \r\n" + 
				"               from wa_grade_ver   \r\n" + 
				"               left join wa_grade \r\n" + 
				"                    on wa_grade.pk_wa_grd = wa_grade_ver.pk_wa_grd\r\n" + 
				"               inner join (select distinct ver.pk_wa_gradever,wg.code,wg.name from wa_gradeorg org \r\n" + 
				"                   left join wa_grade wg\r\n" + 
				"                        on org.pk_wa_grade = wg.pk_wa_grd\r\n" + 
				"                   left join wa_grade_ver ver\r\n" + 
				"                        on wg.pk_wa_grd = ver.pk_wa_grd\r\n" + 
				"                 where ver.effect_flag = 'Y') orgtemp\r\n" + 
				"                    on orgtemp.pk_wa_gradever = wa_grade_ver.pk_wa_gradever and wa_grade.code = orgtemp.code \r\n" + 
				"                    and orgtemp.name = wa_grade.name\r\n" + 
				"               where nvl(wa_grade_ver.dr,0) = 0 and nvl(wa_grade.dr,0) = 0) temp");
		this.setFieldCode(new String[]
		{ "code", "name", "gradever_name","gradever_num" });
		this.setFieldName(new String[]
	    // 2015-09-06 zhousze 解决公共薪资项目、薪资发放项目参照薪资标准表时，表头显示主键问题，主要是多语路径错误，
	    // 不能有空格 begin
		{ ResHelper.getString("6013commonbasic","06013commonbasic0043")/*@res "薪资标准类别编码"*/, ResHelper.getString("6013commonbasic","06013commonbasic0044")/*@res "薪资标准类别名称"*/, ResHelper.getString("common","UC000-0003660")/*@res "说明"*/ });
		// 2015-09-06 zhousze 解决公共薪资项目、薪资发放项目参照薪资标准表时，表头显示主键问题，主要是多语路径错误，
		// 不能有空格 end
		this.setPkFieldCode("pk_wa_gradever");
		this.setHiddenFieldCode(new String[]
		{ "pk_wa_gradever", "pk_group", "pk_org","effect_flag"});
		this.setDefaultFieldCount(3);
		this.setRefTitle("薪资类别标准(版本)");
		setRefCodeField("name");
		setRefNameField("name");
//		begin 20150723 xiejie3 参照的缓存键值是用bd_refinfo表的name字段值，目前很多参照的refModel中没有设置RefNodeName的值
		setRefNodeName("薪资标准(版本)"); /*-=notranslate=-*/
//		end
		
	}

	/**
	 * 拼写sql<BR>
	 * 和5系列相比去掉了<BR>
	 * 和币种相关的过滤<BR>
	 * bd_currtype.dr=0 and wa_grade.pk_currtype = bd_currtype.pk_currtype
	 *
	 * @author xuhw on 2009-11-20
	 * @see nc.ui.bd.ref.AbstractRefModel#getEnvWherePart()
	 */
	@Override
	protected String getEnvWherePart()
	{
		StringBuffer sbWhere = new StringBuffer();

		sbWhere.append(" effect_flag = 'Y' and pk_group = '" + getPk_group() + "' and pk_org = '" + getPk_group() + "'");
		
//		if (!StringUtils.isBlank(getStrPkItem()))
//		{
//			sbWhere.append(" wa_grade.pk_wa_item = '" + getStrPkItem() + "' and ");
//		}
		
		

//		try
//		{
//			return sbWhere.toString() + " " + VisibleUtil.getRefVisibleCondition(getPk_group(), getPk_org(), WA_GRADE_BEAN_ID) + "";
//		}
//		catch (BusinessException e)
//		{
//			Logger.error(e.getMessage(), e);
//		}

		if (StringUtils.isBlank(sbWhere.toString()))
		{
			return null;
		}
		else
		{
			return sbWhere.toString();
		}

	}

	public String getStrPkItem()
	{
		return strPkItem;
	}

	public void setStrPkItem(String strPkItem)
	{
		this.strPkItem = strPkItem;
	}
}