package nc.impl.so.m30.action.main;

import nc.bs.so.m30.maintain.UpdateSaleOrderBP;
import nc.bs.so.m30.plugin.Action30PlugInPoint;
import nc.bs.so.m30.rule.approve.AfterSoSyncRuleGyMes;
import nc.bs.so.m30.rule.maintainprocess.CompareDimensionModifyRule;
import nc.bs.so.m30.rule.maintainprocess.FillupDataWhenUpdateRule;
import nc.bs.so.m30.rule.maintainprocess.NullRule;
import nc.impl.pubapp.pattern.rule.IRule;
import nc.impl.pubapp.pattern.rule.processer.CompareAroundProcesser;
import nc.vo.pubapp.pattern.log.TimeLog;
import nc.vo.so.m30.entity.SaleOrderVO;

public class UpdateSaleOrderAction {
    public SaleOrderVO[] update(SaleOrderVO[] bills, SaleOrderVO[] originBills) {
        CompareAroundProcesser<SaleOrderVO> processer = new CompareAroundProcesser<SaleOrderVO>(Action30PlugInPoint.UpdateAction);


        addBeforeRule(processer);
        addAfterRule(processer);

        TimeLog.logStart();
        processer.before(bills, originBills);

        TimeLog.info("调用修改保存前操作插入点");

        TimeLog.logStart();
        UpdateSaleOrderBP action = new UpdateSaleOrderBP();
        SaleOrderVO[] vos = action.update(bills, originBills);

        TimeLog.info("调用修改保存BP，进行保存");

        TimeLog.logStart();
        processer.after(vos, originBills);

        TimeLog.info("调用修改保存后操作插入点");
        return vos;
    }


    private void addAfterRule(CompareAroundProcesser<SaleOrderVO> processer) {
        processer.addAfterRule(new NullRule());
        processer.addAfterRule(new CompareDimensionModifyRule());
        // 在变更后推送到高压MES
        processer.addAfterRule(new AfterSoSyncRuleGyMes());
    }


    private void addBeforeRule(CompareAroundProcesser<SaleOrderVO> processer) {
        IRule<SaleOrderVO> rule = null;

        rule = new FillupDataWhenUpdateRule();
        processer.addBeforeRule(rule);
    }
}