package nccloud.web.hryf.regApply.action;

import java.util.Arrays;
import java.util.HashMap;

import nc.itf.hr.frame.IPersistenceRetrieve;
import nc.vo.pub.AggregatedValueObject;
import nc.vo.pub.SuperVO;
import nc.vo.trn.pub.TRNConst;
import nc.vo.trn.regitem.TrnRegItemVO;
import nc.vo.trn.regmng.Glbdef2VO;
import nc.vo.trn.regmng.RegapplyVO;
import nc.vo.uif2.LoginContext;
import nccloud.dto.hryf.tools.HRYFConst;
import nccloud.framework.service.ServiceLocator;
import nccloud.framework.web.container.IRequest;
import nccloud.framework.web.ui.meta.PageMeta;
import nccloud.framework.web.ui.pattern.billcard.ExtSpecilAggBill;
import nccloud.framework.web.ui.pattern.extbillcard.ExtBillCard;
import nccloud.framework.web.ui.pattern.form.Form;
import nccloud.web.hr.pub.HRNccTemplateUtils;
import nccloud.web.hr.pub.HRNccUtils;
import nccloud.web.hryf.regApply.utils.RegPageMetaUtil;
import nccloud.web.uapbd.commons.web.ParamUtils;

/**
 * 转正申请-按照billid查询
 * @author lbt 20190314
 *
 */
public class RegApplyQueryOneAction extends RegBaseAction {

	
	@Override
	public <T> Object execute(IRequest request, T para) throws Exception {
		//解析请求中得参数，放入map中，并根据参数获取用户的登录上下文信息。
		ParamUtils param = new ParamUtils(request);
		LoginContext context = HRNccUtils.getLoginContext(param);
	
		
		AggregatedValueObject agg = super.getSelectedData(param);
		RegapplyVO regapplyVO = (RegapplyVO) agg.getParentVO();
		context.setPk_org(regapplyVO.getPk_org());
		TrnRegItemVO[] regItemSet = super.getItemSet(context,param,regapplyVO.getProbation_type());
		
		//页面编辑数据
		HashMap result = new HashMap();
		
		ExtSpecilAggBill extagg = new ExtSpecilAggBill();
		extagg.setHead((SuperVO) agg.getParentVO());
		ExtBillCard card =  HRNccTemplateUtils.getExtBillCard(HRYFConst.APPCODE_REGAPPLY, HRYFConst.PAGECODE_REGAPPLY, extagg, Arrays.asList("list"));
		Form form = new Form();
		form.setPageid(card.getPageid());
		form.setTempletid(card.getTempletid());
		form.setModel(card.getHead().getModel());
		result.put("formData", form);	
		
		String pk_hi_regapply = regapplyVO.getPk_hi_regapply();
		Glbdef2VO[] glbdef1VOs = (Glbdef2VO[]) ServiceLocator.find(IPersistenceRetrieve.class).retrieveByClause(null, Glbdef2VO.class, "pk_hi_regapply ='"+pk_hi_regapply+"' and nvl(dr,0) = 0");
		agg.setChildrenVO(glbdef1VOs);
		result.put("formBodyData", HRNccTemplateUtils.getGridWithArea(HRYFConst.PAGECODE_REGAPPLY, "card_body", (Glbdef2VO[])agg.getChildrenVO()));
		
		// 返回前后项目模板
		PageMeta pm = super.showAllSetItems(context, HRYFConst.APPCODE_REGAPPLY, HRYFConst.PAGECODE_REGAPPLY, true, regItemSet,TRNConst.TRNS_OLDINFO_TAB,TRNConst.TRNS_NEWINFO_TAB);
		pm = RegPageMetaUtil.getPageMetaByEditType( context, pm,HRYFConst.APPCODE_REGAPPLY, "edit",regapplyVO);
		result.put(TRNConst.TRNS_OLDINFO_TAB, pm.getAreaMeta(TRNConst.TRNS_OLDINFO_TAB));
		result.put(TRNConst.TRNS_NEWINFO_TAB, pm.getAreaMeta(TRNConst.TRNS_NEWINFO_TAB));
		result.put(TRNConst.TRNS_PSNINFO_TAB, pm.getAreaMeta(TRNConst.TRNS_PSNINFO_TAB));
		result.put("card", pm.getAreaMeta("card"));
		return result;
	}
	
	
}
