//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package nc.bs.so.m30.maintain;

import nc.bs.scmpub.rule.CrossRuleValidateRule;
import nc.bs.so.m30.maintain.rule.insert.RewriteBillInsertRule;
import nc.bs.so.m30.maintain.rule.insert.RewritePromotePriceInsertRule;
import nc.bs.so.m30.maintain.rule.insert.WritebackMaterialPriceRule;
import nc.bs.so.m30.plugin.BP30PlugInPoint;
import nc.bs.so.m30.rule.atp.SaleOrderVOATPAfterRule;
import nc.bs.so.m30.rule.atp.SaleOrderVOATPBeforeRule;
import nc.bs.so.m30.rule.billcode.AddNewBillCodeRule;
import nc.bs.so.m30.rule.billcode.CheckUniqueBillCodeRule;
import nc.bs.so.m30.rule.businessinfo.SaveTransferMsgRule;
import nc.bs.so.m30.rule.credit.RenovateARByHidsBeginRule;
import nc.bs.so.m30.rule.credit.RenovateARByHidsEndRule;
import nc.bs.so.m30.rule.feature.CfgMatchCheckRule;
import nc.bs.so.m30.rule.feature.CfgMatchSaveRule;
import nc.bs.so.m30.rule.m35.ArsubOffsetBeforeSaveRule;
import nc.bs.so.m30.rule.m35.LrgCashMarCheckRule;
import nc.bs.so.m30.rule.maintaincheck.*;
import nc.bs.so.m30.rule.maintainprocess.*;
import nc.bs.so.m30.rule.pm.CheckBusiForPMRule;
import nc.bs.so.m30.rule.pm.CheckProjectMFGRule;
import nc.bs.so.m30.rule.pm.CheckProjectValueRule;
import nc.bs.so.m30.rule.reserve.AutoReserveRule;
import nc.bs.so.m30.rule.rewrite.price.RewritePriceFormRule;
import nc.bs.so.pub.rule.FillBillTailInfoRuleForIns;
import nc.impl.pubapp.bd.userdef.UserDefSaveRule;
import nc.impl.pubapp.pattern.data.bill.BillInsert;
import nc.impl.pubapp.pattern.rule.IRule;
import nc.impl.pubapp.pattern.rule.processer.AroundProcesser;
import nc.itf.scmpub.reference.uap.group.SysInitGroupQuery;
import nc.vo.credit.engrossmaintain.pub.action.M30EngrossAction;
import nc.vo.ml.NCLangRes4VoTransl;
import nc.vo.pubapp.pattern.log.TimeLog;
import nc.vo.pubapp.util.SetAddAuditInfoRule;
import nc.vo.scmpub.rule.AutoMaterialAssignRule;
import nc.vo.scmpub.rule.SaleOrgEnableCheckRule;
import nc.vo.so.m30.entity.SaleOrderBVO;
import nc.vo.so.m30.entity.SaleOrderHVO;
import nc.vo.so.m30.entity.SaleOrderVO;
import nccloud.bs.so.mobile.saleorder.operation.rule.MobAfterSaveMessageRule;

public class InsertSaleOrderBP {
    public InsertSaleOrderBP() {
    }

    public SaleOrderVO[] insert(SaleOrderVO[] bills) {
        AroundProcesser<SaleOrderVO> processer = new AroundProcesser(BP30PlugInPoint.InsertBP);
        TimeLog.logStart();
        this.addBeforeRule(processer);
        processer.before(bills);
        TimeLog.info(NCLangRes4VoTransl.getNCLangRes().getStrByID("4006011_0", "04006011-0066"));
        TimeLog.logStart();
        BillInsert<SaleOrderVO> bo = new BillInsert();
        SaleOrderVO[] vos = (SaleOrderVO[])bo.insert(bills);
        TimeLog.info(NCLangRes4VoTransl.getNCLangRes().getStrByID("4006011_0", "04006011-0067"));
        TimeLog.logStart();
        this.addAfterRule(processer);
        processer.after(vos);
        TimeLog.info(NCLangRes4VoTransl.getNCLangRes().getStrByID("4006011_0", "04006011-0068"));
        return vos;
    }

    private void addAfterRule(AroundProcesser<SaleOrderVO> processer) {
        IRule<SaleOrderVO> rule = null;
        IRule<SaleOrderVO> var4 = new InsertSoBalanceWhenAddNewRule();
        processer.addAfterRule(var4);
        IRule<SaleOrderVO> var5 = new RenovateARByHidsEndRule(M30EngrossAction.M30Insert);
        processer.addAfterRule(var5);
        IRule<SaleOrderVO> var6 = new ThisGatheringRule();
        processer.addAfterRule(var6);
        IRule<SaleOrderVO> var7 = new CheckUniqueBillCodeRule();
        processer.addAfterRule(var7);
        IRule<SaleOrderVO> var8 = new RewriteBillInsertRule();
        processer.addAfterRule(var8);
        IRule<SaleOrderVO> var9 = new SaveTransferMsgRule();
        processer.addAfterRule(var9);
        IRule<SaleOrderVO> var10 = new RewritePriceFormRule();
        processer.addAfterRule(var10);
        IRule<SaleOrderVO> var11 = new SourceToSaleOrderMsgRule();
        processer.addAfterRule(var11);
        boolean icEnable = SysInitGroupQuery.isICEnabled();
        if (icEnable) {
            IRule<SaleOrderVO> var12 = new SaleOrderVOATPAfterRule();
            processer.addAfterRule(var12);
            IRule<SaleOrderVO> var13 = new AutoReserveRule();
            processer.addAfterRule(var13);
        }

        if (SysInitGroupQuery.isPRICEEnabled()) {
            IRule<SaleOrderVO> var14 = new RewritePromotePriceInsertRule();
            processer.addAfterRule(var14);
        }
        /**
         * 销售订单新增回写参考物料售价规则
         */
        IRule<SaleOrderVO> var15 = new WritebackMaterialPriceRule();
        processer.addAfterRule(var15);

        processer.addAfterRule(new MobAfterSaveMessageRule());
    }

    private void addBeforeRule(AroundProcesser<SaleOrderVO> processer) {
        IRule<SaleOrderVO> rule = new SaleOrgEnableCheckRule();
        processer.addBeforeRule(rule);
        IRule<SaleOrderVO> var4 = new FillupRedundanceDataRule();
        processer.addBeforeRule(var4);
        IRule<SaleOrderVO> var5 = new FillupFretexchangeRule();
        processer.addBeforeRule(var5);
        IRule<SaleOrderVO> var6 = new AddNewBillCodeRule();
        processer.addBeforeRule(var6);
        IRule<SaleOrderVO> var7 = new CheckNumPriceMnyRule();
        processer.addBeforeRule(var7);
        IRule<SaleOrderVO> var8 = new SaleOrderCheckNumAndMnyRule();
        processer.addBeforeRule(var8);
        IRule<SaleOrderVO> var9 = new CheckMaterilaOVidRule();
        processer.addBeforeRule(var9);
        IRule<SaleOrderVO> var10 = new CheckSettleOrgRepeat();
        processer.addBeforeRule(var10);
        IRule<SaleOrderVO> var11 = new CheckDateRule();
        processer.addBeforeRule(var11);
        processer.addBeforeRule(new AutoMaterialAssignRule("cmaterialid", new String[]{"pk_org"}, new String[]{"pk_org", "csendstockorgid", "csettleorgid", "carorgid", "cprofitcenterid", "csprofitcenterid"}));
        IRule<SaleOrderVO> var12 = new CfgMatchSaveRule();
        processer.addBeforeRule(var12);
        IRule<SaleOrderVO> var13 = new CfgMatchCheckRule();
        processer.addBeforeRule(var13);
        IRule<SaleOrderVO> var14 = new CheckSaveBillRule();
        processer.addBeforeRule(var14);
        IRule<SaleOrderVO> var15 = new FillBillTailInfoRuleForIns();
        processer.addBeforeRule(var15);
        IRule<SaleOrderVO> var16 = new SetAddAuditInfoRule();
        processer.addBeforeRule(var16);
        IRule<SaleOrderVO> var17 = new RenovateARByHidsBeginRule(M30EngrossAction.M30Insert);
        processer.addBeforeRule(var17);
        boolean icEnable = SysInitGroupQuery.isICEnabled();
        if (icEnable) {
            IRule<SaleOrderVO> var18 = new SaleOrderVOATPBeforeRule();
            processer.addBeforeRule(var18);
        }

        IRule<SaleOrderVO> var19 = new LrgCashMarCheckRule();
        processer.addBeforeRule(var19);
        IRule<SaleOrderVO> var20 = new ArsubOffsetBeforeSaveRule();
        processer.addBeforeRule(var20);
        IRule<SaleOrderVO> var21 = new CheckLrgTotalMoney();
        processer.addBeforeRule(var21);
        IRule<SaleOrderVO> var22 = new UserDefSaveRule(new Class[]{SaleOrderHVO.class, SaleOrderBVO.class});
        processer.addBeforeRule(var22);
        IRule<SaleOrderVO> var23 = new CrossRuleValidateRule();
        processer.addBeforeRule(var23);
        IRule<SaleOrderVO> var24 = new CheckProjectValueRule();
        processer.addBeforeRule(var24);
        IRule<SaleOrderVO> var25 = new CheckBusiForPMRule();
        processer.addBeforeRule(var25);
        IRule<SaleOrderVO> var26 = new CheckValueWhenIsdeliveryRule();
        processer.addBeforeRule(var26);
        IRule<SaleOrderVO> var27 = new CheckProjectMFGRule();
        processer.addBeforeRule(var27);
    }
}
