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

package nc.bs.mmpac.pickm.bp;

import nc.bs.mmpac.pickm.bp.rule.PickmFillInfoFormMORule;
import nc.bs.mmpac.pickm.plugin.PickmPluginPoint;
import nc.bs.mmpac.pickm.rule.PickmCheckItemMaterialPermissionRule;
import nc.bs.mmpac.pickm.rule.PickmCheckMaterialPermissionRule;
import nc.bs.mmpac.pickm.rule.PickmCheckSameStockRule;
import nc.bs.mmpac.pickm.rule.PickmCreateSubItemRule;
import nc.bs.mmpac.pickm.rule.PickmCreateSubMoForInsertRule;
import nc.bs.mmpac.pickm.rule.PickmItemSortByRtForInsertRule;
import nc.bs.mmpac.pickm.rule.PickmMakeDateRule;
import nc.bs.mmpac.pickm.rule.PickmSaveRule;
import nc.bs.mmpac.pickm.rule.SNMaterialNotBackFlushRule;
import nc.bs.mmpac.pickm.rule.ic.PickmATPCheckRule;
import nc.bs.mmpac.pickm.rule.ic.PickmAutoReserveRule;
import nc.bs.mmpac.pickm.rule.ic.PickmSetReplaceSrcAndRowNoAfterInsertRule;
import nc.bs.mmpac.pickm.rule.realsub.PickmRewritePLOWhenInsertRule;
import nc.bs.pubapp.pub.rule.FieldLengthCheckRule;
import nc.bs.pubapp.pub.rule.FillInsertDataRule;
import nc.bs.pubapp.pub.rule.OrgDisabledCheckRule;
import nc.impl.pubapp.bd.userdef.UserDefSaveRule;
import nc.impl.pubapp.pattern.data.bill.template.InsertBPTemplate;
import nc.impl.pubapp.pattern.data.bill.tool.BillTransferTool;
import nc.impl.pubapp.pattern.rule.IRule;
import nc.impl.pubapp.pattern.rule.processer.AroundProcesser;
import nc.util.mmf.busi.rule.MMBillCodeCheckAndTrantypeRule;
import nc.util.mmf.busi.rule.MMCreateBillcodeAndTrantypecodeRule;
import nc.util.mmf.framework.base.MMValueCheck;
import nc.vo.mmpac.pickm.entity.AggPickmVO;
import nc.vo.mmpac.pickm.entity.PickmHeadVO;
import nc.vo.mmpac.pickm.entity.PickmItemVO;

public class PickmInsertForMoBP {

    public PickmInsertForMoBP() {
    }

    public AggPickmVO[] insertForMo(AggPickmVO[] vos) {
        if (MMValueCheck.isEmpty(vos)) {
            return null;
        } else {
            BillTransferTool<AggPickmVO> transferTool = new BillTransferTool(vos);
            AggPickmVO[] mergedVOs = (AggPickmVO[]) transferTool.getClientFullInfoBill();
            InsertBPTemplate<AggPickmVO> bp = new InsertBPTemplate(PickmPluginPoint.SAVE);
            this.addBeforeRule(bp.getAroundProcesser());
            this.addAfterRule(bp.getAroundProcesser());
            AggPickmVO[] retvos = (AggPickmVO[]) bp.insert(mergedVOs);
            return retvos;
        }
    }

    /**
     * @deprecated
     */
    @Deprecated
    protected PickmCreateSubItemRule getPickmCreateSubItemRule(boolean isBg) {
        return null;
    }

    private void addAfterRule(AroundProcesser<AggPickmVO> processor) {
        IRule<AggPickmVO> setReplaceSrcRule = new PickmSetReplaceSrcAndRowNoAfterInsertRule(true);
        processor.addAfterRule(setReplaceSrcRule);
        IRule<AggPickmVO> billCodeRule = new MMBillCodeCheckAndTrantypeRule("55A3", "vbillcode", "pk_group", "pk_org",
                "vbusitype");
        processor.addAfterRule(billCodeRule);
        IRule<AggPickmVO> atpCheckRule = new PickmATPCheckRule(false, (AggPickmVO[]) null);
        processor.addAfterRule(atpCheckRule);
        IRule<AggPickmVO> pickmAutoReserveRule = new PickmAutoReserveRule();
        processor.addAfterRule(pickmAutoReserveRule);
        IRule<AggPickmVO> pickmRewritePLOWhenInsertRule = new PickmRewritePLOWhenInsertRule();
        processor.addAfterRule(pickmRewritePLOWhenInsertRule);
        IRule<AggPickmVO> pickmCreateSubMoRule = new PickmCreateSubMoForInsertRule();
        processor.addAfterRule(pickmCreateSubMoRule);
    }

    private void addBeforeRule(AroundProcesser<AggPickmVO> processor) {
        IRule<AggPickmVO> orgRule = new OrgDisabledCheckRule("pk_org", "FACTORYTYPE000000000");
        processor.addBeforeRule(orgRule);
        IRule<AggPickmVO> fillDataRule = new FillInsertDataRule();
        processor.addBeforeRule(fillDataRule);
        IRule<AggPickmVO> getMakeDateRule = new PickmMakeDateRule();
        processor.addBeforeRule(getMakeDateRule);
        IRule<AggPickmVO> billcodeRule = new MMCreateBillcodeAndTrantypecodeRule("55A3", "vbillcode", "pk_group",
                "pk_org", "vbusitype");
        processor.addBeforeRule(billcodeRule);
        IRule<AggPickmVO> createSubItemRule = new PickmCreateSubItemRule(true);
        processor.addBeforeRule(createSubItemRule);
        IRule<AggPickmVO> sortItemRule = new PickmItemSortByRtForInsertRule();
        processor.addBeforeRule(sortItemRule);
        IRule<AggPickmVO> lengthCheckRule = new FieldLengthCheckRule();
        processor.addBeforeRule(lengthCheckRule);
        IRule<AggPickmVO> sameRule = new PickmCheckSameStockRule();
        processor.addBeforeRule(sameRule);
        IRule<AggPickmVO> marperRule = new PickmCheckMaterialPermissionRule();
        processor.addBeforeRule(marperRule);
        IRule<AggPickmVO> bmarperRule = new PickmCheckItemMaterialPermissionRule();
        processor.addBeforeRule(bmarperRule);
        IRule<AggPickmVO> pickmSaveRule = new PickmSaveRule();
        processor.addBeforeRule(pickmSaveRule);
        IRule<AggPickmVO> snMaterialCheckRule = new SNMaterialNotBackFlushRule();
        processor.addBeforeRule(snMaterialCheckRule);
        IRule<AggPickmVO> atpCheckRule = new PickmATPCheckRule(true, (AggPickmVO[]) null);
        processor.addBeforeRule(atpCheckRule);
        IRule<AggPickmVO> userDefSaveRule = new UserDefSaveRule(new String[]{"vdef", "vbdef"},
                new Class[]{PickmHeadVO.class, PickmItemVO.class});
        processor.addBeforeRule(userDefSaveRule);
        processor.addBeforeRule(new PickmFillInfoFormMORule());
    }
}
