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

package nc.bs.mmpac.pmo.pac0002.bp;

import nc.bs.mmpac.pmo.pac0002.pluginpoint.PMOPluginPoint;
import nc.bs.mmpac.pmo.pac0002.rule.PMOFilterBillStatusRule;
import nc.bs.mmpac.pmo.pac0002.rule.PMOFinishAutoFinishPutPlanRule;
import nc.bs.mmpac.pmo.pac0002.rule.fill.PMOFillFinishValueRule;
import nc.bs.mmpub.rule.MMVOSagaFrozenValidateRule;
import nc.impl.pubapp.pattern.rule.IFilterRule;
import nc.impl.pubapp.pattern.rule.IRule;
import nc.impl.pubapp.pattern.rule.processer.CompareAroundProcesser;
import nc.util.mmf.framework.gc.GCUpdateBPTemplate;
import nc.vo.mmpac.pmo.pac0002.constant.PMOConstLang;
import nc.vo.mmpac.pmo.pac0002.entity.PMOAggVO;
import nc.vo.mmpac.pmo.pac0002.enumeration.PMOFBillstatusEnum;

public class PMOFinishBP {
    public PMOFinishBP() {
    }

    public PMOAggVO[] finish(PMOAggVO[] fullBills, PMOAggVO[] originBills) {
        GCUpdateBPTemplate<PMOAggVO> bp = new GCUpdateBPTemplate(PMOPluginPoint.FINISH);
        this.addFinishBeforeRule(bp.getAroundProcesser());
        this.addFinishAfterRule(bp.getAroundProcesser());
        PMOAggVO[] retBills = (PMOAggVO[])bp.update(fullBills, originBills);
        return retBills;
    }

    private void addFinishBeforeRule(CompareAroundProcesser<PMOAggVO> processer) {
        IRule<PMOAggVO> checkFrozenRule = new MMVOSagaFrozenValidateRule(true);
        processer.addBeforeRule(checkFrozenRule);
        IFilterRule<PMOAggVO> filterStatusRule = new PMOFilterBillStatusRule(PMOConstLang.getMSG_ACTION_NO_AUDIT(), PMOFBillstatusEnum.AUDIT);
        processer.addBeforeRule(filterStatusRule);
        IRule<PMOAggVO> fillFinishRule = new PMOFillFinishValueRule(false);
        processer.addBeforeRule(fillFinishRule);
    }

    private void addFinishAfterRule(CompareAroundProcesser<PMOAggVO> processer) {
        IRule<PMOAggVO> finishPutPlanRule = new PMOFinishAutoFinishPutPlanRule();
        processer.addAfterRule(finishPutPlanRule);
//        /** 同步修改备料计划完成(生产订单强制完工时) */
//        IRule<PMOAggVO> pMOToFinishPickMRule = new PMOToFinishPickMRule();
//        processer.addAfterRule(pMOToFinishPickMRule);
    }

    public PMOAggVO[] finishCancel(PMOAggVO[] fullBills, PMOAggVO[] originBills) {
        GCUpdateBPTemplate<PMOAggVO> bp = new GCUpdateBPTemplate(PMOPluginPoint.UNFINISH);
        this.addFinishCancelBeforeRule(bp.getAroundProcesser());
        this.addFinishCancelAfterRule(bp.getAroundProcesser());
        PMOAggVO[] retBills = (PMOAggVO[])bp.update(fullBills, originBills);
        return retBills;
    }

    private void addFinishCancelBeforeRule(CompareAroundProcesser<PMOAggVO> processer) {
        IFilterRule<PMOAggVO> filterStatusRule = new PMOFilterBillStatusRule(PMOConstLang.getMSG_ACTION_NO_AUDIT(), PMOFBillstatusEnum.AUDIT);
        processer.addBeforeRule(filterStatusRule);
        IRule<PMOAggVO> fillFinishRule = new PMOFillFinishValueRule(true);
        processer.addBeforeRule(fillFinishRule);
    }

    private void addFinishCancelAfterRule(CompareAroundProcesser<PMOAggVO> processer) {
    }
}
