
package nc.bs.pub.action;

import nc.bs.framework.common.NCLocator;
import nccloud.bs.ic.ic.aggbusi.plugin.bpplugin.NccsynergyPluginPoint;
import nc.bs.pubapp.pf.action.AbstractPfAction;
import nc.impl.pubapp.pattern.rule.IRule;
import nc.impl.pubapp.pattern.rule.processer.CompareAroundProcesser;
import nc.itf.ic.ic.INccsynergyMaintain;
import nc.vo.jcom.lang.StringUtil;
import nc.vo.sap.syproconfig.AggSyProConfigVO;
import nc.vo.pub.BusinessException;
import nc.vo.pubapp.AppContext;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;

public class N_4008_SAVEBASE extends AbstractPfAction<AggSyProConfigVO> {

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

                return processor;
        }

        @Override
        protected AggSyProConfigVO[] processBP(Object userObj,
                        AggSyProConfigVO[] clientFullVOs, AggSyProConfigVO[] originBills) {

                AggSyProConfigVO[] bills = null;
            try {
              INccsynergyMaintain operator =
                  NCLocator.getInstance().lookup(INccsynergyMaintain.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;
        }
}
