/****************************************************************************************
 * sunpenga
 * 2011-8-5
 ***************************************************************************************/
package nc.plugin.hi.entrymng;

import nc.bs.framework.common.NCLocator;
import nc.bs.logging.Logger;
import nc.itf.hi.IPsndocQryService;
import nc.itf.hi.entrymng.IEntrymngQueryService;
import nc.md.persist.framework.MDPersistenceService;
import nc.ui.pub.print.IMetaDataDataSource;
import nc.vo.hi.entrymng.AggEntryapplyVO;
import nc.vo.hi.entrymng.EntryapplyVO;
import nc.vo.hi.psndoc.EduVO;
import nc.vo.hi.psndoc.FamilyVO;
import nc.vo.hi.psndoc.LinkmanVO;
import nc.vo.hi.psndoc.PsndocAggVO;
import nc.vo.hi.psndoc.WorkVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.SuperVO;

/**
 * @author sunpenga
 * 
 */
public class EntryPrintDataSourceForMail implements IMetaDataDataSource {

	// 单据主表ID
	private String billId = null;

	// 单据类型
	private String billType = null;

	public EntryPrintDataSourceForMail(String billId, String billType) {
		super();
		this.billId = billId;
		this.billType = billType;
	}

	@Override
	public String[] getAllDataItemExpress() {
		return null;
	}

	@Override
	public String[] getAllDataItemNames() {
		return null;
	}

	@Override
	public String[] getDependentItemExpressByExpress(String arg0) {
		return null;
	}

	@Override
	public String[] getItemValuesByExpress(String arg0) {
		if("pk_entryapply".equals(arg0)) {
			return new String[] {billId};
		}
		return null;
	}

	@Override
	public String getModuleName() {
		return null;
	}

	@Override
	public boolean isNumber(String arg0) {
		return false;
	}

	@Override
	public Object[] getMDObjects() {

		try {
			AggEntryapplyVO vo = NCLocator.getInstance().lookup(IEntrymngQueryService.class).queryByPk(getBillId());
			
		   String pk_psndoc = ((EntryapplyVO)vo.getParentVO()).getPk_psndoc();
			 // 没有通过主键数组查询的接口，暂时先循环查询
           PsndocAggVO aggvo = MDPersistenceService.lookupPersistenceQueryService().queryBillOfVOByPK(PsndocAggVO.class, pk_psndoc, false);
           //此处只支持入职登记表打印的四个子集

           String order = " recordnum desc ";
           IPsndocQryService psndocQryService = NCLocator.getInstance().lookup(IPsndocQryService.class);
           String cond = " pk_psndoc = '" + pk_psndoc + "' ";
           SuperVO[] works = psndocQryService.querySubVO(WorkVO.class, cond, order);
           SuperVO[] edus = psndocQryService.querySubVO(EduVO.class, cond, order);
           SuperVO[] familys = psndocQryService.querySubVO(FamilyVO.class, cond, order);
           SuperVO[] linkmans = psndocQryService.querySubVO(LinkmanVO.class, cond, order);
           aggvo.setTableVO(WorkVO.getDefaultTableName(),works);
           aggvo.setTableVO(EduVO.getDefaultTableName(),edus);
           aggvo.setTableVO(FamilyVO.getDefaultTableName(),familys);
           aggvo.setTableVO(LinkmanVO.getDefaultTableName(),linkmans);
           if("6101-Cxx-01".equals(((EntryapplyVO)vo.getParentVO()).getTranstype())) {
        	   return new AggEntryapplyVO[] {vo};
           }
		   return new PsndocAggVO[] {aggvo};	
//		   return new AggEntryapplyVO[]{vo};
		} catch (BusinessException e) {
			Logger.error(e.getMessage(), e);
			return null;
		}
	}

	public void setBillId(String billId) {
		this.billId = billId;
	}

	public String getBillId() {
		return billId;
	}

	public void setBillType(String billType) {
		this.billType = billType;
	}

	public String getBillType() {
		return billType;
	}

}
