package nccloud.impl.hrcm.ctrtmng.impl;

import nc.bs.framework.common.NCLocator;
import nc.ui.pub.print.IDataSource;
import nc.vo.pub.BusinessException;
import nccloud.base.exception.ExceptionUtils;
import nccloud.commons.lang.ArrayUtils;
import nccloud.dto.hrcm.ctrtmng.CtrtMngVO;
import nccloud.itf.hrcm.ctrtmng.ICtrtMngService;
import nccloud.pubitf.platform.print.AbstractPrintService;
import nccloud.pubitf.platform.print.IPrintInfo;
import nccloud.pubitf.platform.print.vo.PrintInfo;
import nccloud.web.hr.print.HRNccMetaDataDataSource;

public class CtrtMngPrintService extends AbstractPrintService {

	@Override
	public IDataSource[] getDataSources(IPrintInfo info) {
		PrintInfo printInfo = (PrintInfo)info;
		String[] pks = printInfo.getIds();
		if (ArrayUtils.isEmpty(pks)) {
			return new IDataSource[] { new HRNccMetaDataDataSource(new Object[0]) };
		}
		try {
			 CtrtMngVO agg = ((ICtrtMngService)NCLocator.getInstance().lookup(ICtrtMngService.class)).queryCtrtMngVOBypk(pks[0]);
			 if (agg == null) {
				 return new IDataSource[] { new HRNccMetaDataDataSource(new Object[0]) };
			 }
			 CtrtMngPrintDataSource watchEvalPrintDataSource = new CtrtMngPrintDataSource(new CtrtMngVO[] { agg });
			 return new IDataSource[] { watchEvalPrintDataSource };
		} catch (BusinessException e) {
			 ExceptionUtils.wrapException(e);
		}
		return null;
	}

}
