package nc.bs.pub.action;

import nc.bs.pubapp.pf.action.AbstractPfAction;
import nc.bs.hr.baod_orders.ace.bp.AceBaod_ordersInsertBP;
import nc.bs.hr.baod_orders.ace.bp.AceBaod_ordersUpdateBP;
import nc.bs.hr.baod_orders.plugin.bpplugin.Baod_ordersPluginPoint;
import nc.impl.pubapp.pattern.rule.processer.CompareAroundProcesser;
import nc.impl.pubapp.pattern.data.bill.tool.BillTransferTool;
import nc.vo.jcom.lang.StringUtil;
import nc.impl.pubapp.pattern.rule.IRule;
import nc.vo.th.baod.entity.AggBaodVO;
import nc.vo.pub.BusinessException;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nc.bs.framework.common.NCLocator;

public class N_YGBD_SAVEBASE extends AbstractPfAction<AggBaodVO> {

  @Override
  protected CompareAroundProcesser<AggBaodVO> getCompareAroundProcesserWithRules(
      Object userObj) {
      CompareAroundProcesser<AggBaodVO> processor = null;
		AggBaodVO[] clientFullVOs = (AggBaodVO[]) this.getVos();
		/*BillTransferTool<AggBaodVO> tool = new BillTransferTool<AggBaodVO>(
				clientFullVOs);
		clientFullVOs = tool.getClientFullInfoBill();*/
		if (!StringUtil.isEmptyWithTrim(clientFullVOs[0].getParentVO()
				.getPrimaryKey())) {
			processor = new CompareAroundProcesser<AggBaodVO>(
					Baod_ordersPluginPoint.SCRIPT_UPDATE);
		} else {
			processor = new CompareAroundProcesser<AggBaodVO>(
					Baod_ordersPluginPoint.SCRIPT_INSERT);
		}
		   // TODO 在此处添加前后规则
		   IRule<AggBaodVO> rule=null;
					  
				  		
    return processor;
  }

  @Override
  protected AggBaodVO[] processBP(Object userObj,
      AggBaodVO[] clientFullVOs,AggBaodVO[] originBills) {
      
      AggBaodVO[] bills = null;
      try {
            nc.itf.hr.IBaod_ordersMaintain operator = NCLocator.getInstance().lookup(nc.itf.hr.IBaod_ordersMaintain.class);
            if (!StringUtil.isEmptyWithTrim(clientFullVOs[0].getParentVO().getPrimaryKey())) {
              bills = operator.update(clientFullVOs,originBills);
		            } else {
              bills = operator.insert(clientFullVOs,originBills);
		            }
      } catch (BusinessException e) {
				          ExceptionUtils.wrappBusinessException(e.getMessage());
			      }
		      return bills;
  }
}
