
package nc.bs.pub.action;

import nc.bs.framework.common.NCLocator;
import nccloud.bs.hrkq.hrkq.aggbusi.plugin.bpplugin.MonthOtTimeVOPluginPoint;
import nc.bs.pubapp.pf.action.AbstractPfAction;
import nc.impl.pubapp.pattern.rule.IRule;
import nc.impl.pubapp.pattern.rule.processer.CompareAroundProcesser;
import nc.vo.jcom.lang.StringUtil;
import nccloud.itf.hrkq.hrkq.IMonthottimevoMaintain;
import nc.vo.hrkq.monthottime.AggMonthOtTimeVO;
import nc.vo.pub.BusinessException;
import nc.vo.pubapp.AppContext;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;

public class N_6QOT_SAVEBASE extends AbstractPfAction<AggMonthOtTimeVO> {

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

                return processor;
        }

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

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