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

package nc.bs.qc.c003.maintain;

import nc.bs.qc.c003.maintain.rule.ChkBillCodeUniqueRule;
import nc.bs.qc.c003.maintain.rule.InsertAndDelBatchCodeBeforeRule;
import nc.bs.qc.c003.maintain.rule.ReportChkChkBatUnique;
import nc.bs.qc.c003.maintain.rule.SyncQcQmsRule;
import nc.bs.qc.c003.maintain.rule.insert.CreatChkBatchRule;
import nc.bs.qc.c003.maintain.rule.insert.FillUpDataRule;
import nc.bs.qc.c003.maintain.rule.insert.InsertBatchCodeAfterRule;
import nc.bs.qc.c003.maintain.rule.insert.InsertBillCodeRule;
import nc.bs.qc.c003.maintain.rule.insert.MatchReportTypeRule;
import nc.bs.qc.c003.maintain.rule.insert.RowNoFillUpRule;
import nc.bs.qc.c003.maintain.rule.insert.WriteC001WhenInsertRule;
import nc.bs.qc.c003.maintain.rule.insert.WriteC002WhenInsertRule;
import nc.bs.qc.c003.plugin.ReportBPPlugInPoint;
import nc.bs.qc.pub.rule.QCRowNoCheckRule;
import nc.bs.qc.pub.rule.QCWriteOperateLogRule;
import nc.impl.pubapp.bd.material.assistant.MarAssistantSaveRule;
import nc.impl.pubapp.bd.userdef.UserDefSaveRule;
import nc.impl.pubapp.pattern.data.bill.BillInsert;
import nc.impl.pubapp.pattern.rule.processer.AroundProcesser;
import nc.vo.pubapp.util.SetAddAuditInfoRule;
import nc.vo.qc.c003.entity.ReportHeaderVO;
import nc.vo.qc.c003.entity.ReportItemVO;
import nc.vo.qc.c003.entity.ReportVO;
import nc.vo.qc.c003.rule.FillupFacceptjudgeRule;
import nc.vo.qc.c003.rule.MaterialInStorckOrgRule;
import nc.vo.qc.c003.rule.ReportCheckFlowRule;
import nc.vo.qc.c003.rule.ReportItemsCheckRule;
import nc.vo.qc.c003.rule.ReportNumCheckRule;
import nc.vo.qc.c003.util.ReportAddStockStateRule;
import nc.vo.qc.pub.rule.CheckBillNumRule;
import nc.vo.scmpub.rule.QcCenterEnableCheckRule;
import nccloud.dto.qc.c003.constance.QCReportOprLogConst;

public class ReportInsertBP {
    public ReportInsertBP() {
    }

    public ReportVO[] insertReport(ReportVO[] aggVO) {
        AroundProcesser<ReportVO> processer = new AroundProcesser(ReportBPPlugInPoint.ReportInsertBP);
        this.addBeforeRule(processer);
        this.addAfterFinalRule(processer);
        processer.before(aggVO);
        BillInsert<ReportVO> bo = new BillInsert();
        ReportVO[] vos = (ReportVO[])bo.insert(aggVO);
        processer.after(aggVO);
        return vos;
    }

    private void addAfterFinalRule(AroundProcesser<ReportVO> processer) {
        processer.addAfterFinalRule(new ChkBillCodeUniqueRule());
        processer.addAfterFinalRule(new WriteC001WhenInsertRule());
        processer.addAfterFinalRule(new WriteC002WhenInsertRule());
        processer.addAfterFinalRule(new InsertBatchCodeAfterRule());
        processer.addAfterRule(new QCWriteOperateLogRule(QCReportOprLogConst.maintainService.getCode(), QCReportOprLogConst.addAction.getCode()));
        processer.addAfterFinalRule(new SyncQcQmsRule());
    }

    private void addBeforeRule(AroundProcesser<ReportVO> processer) {
        processer.addBeforeRule(new FillUpDataRule());
        processer.addBeforeRule(new SetAddAuditInfoRule());
        String[] hKeys = new String[2];
        hKeys[0] = "nchecknum";
        hKeys[1] = "ncheckastnum";
        String[] bKeys = new String[2];
        bKeys[0] = "nnum";
        bKeys[1] = "nastnum";
        processer.addBeforeRule(new CheckBillNumRule(hKeys, bKeys));
        processer.addBeforeRule(new InsertBillCodeRule());
        processer.addBeforeRule(new CreatChkBatchRule());
        processer.addBeforeRule(new ReportChkChkBatUnique());
        processer.addBeforeRule(new FillupFacceptjudgeRule());
        processer.addBeforeRule(new RowNoFillUpRule());
        processer.addBeforeRule(new QCRowNoCheckRule(ReportItemVO.class, "crowno"));
        processer.addBeforeRule(new MatchReportTypeRule());
        processer.addBeforeRule(new ReportItemsCheckRule());
        processer.addBeforeRule(new ReportNumCheckRule());
        processer.addBeforeRule(new InsertAndDelBatchCodeBeforeRule(true));
        MarAssistantSaveRule<ReportVO> mar = new MarAssistantSaveRule();
        processer.addBeforeRule(mar);
        processer.addBeforeRule(new QcCenterEnableCheckRule());
        processer.addBeforeRule(new UserDefSaveRule(new Class[]{ReportHeaderVO.class, ReportItemVO.class}));
        processer.addBeforeRule(new ReportAddStockStateRule());
        processer.addBeforeRule(new ReportCheckFlowRule());
        processer.addBeforeRule(new MaterialInStorckOrgRule());
    }
}
