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

package nc.bs.qc.c003.maintain;

import java.util.Map;

import nc.bs.qc.c003.maintain.rule.ChkBillCodeUniqueRule;
import nc.bs.qc.c003.maintain.rule.ReportChkChkBatUnique;
import nc.bs.qc.c003.maintain.rule.SyncQcQmsRule;
import nc.bs.qc.c003.maintain.rule.update.FillUpDataUpdateRule;
import nc.bs.qc.c003.maintain.rule.update.UpdChkBatCode;
import nc.bs.qc.c003.maintain.rule.update.UpdateBatchCodeAfterRule;
import nc.bs.qc.c003.maintain.rule.update.UpdateBatchCodeBeforeRule;
import nc.bs.qc.c003.maintain.rule.update.UpdateBillCodeRule;
import nc.bs.qc.c003.maintain.rule.update.WriteC001WhenUpdateRule;
import nc.bs.qc.c003.plugin.ReportBPPlugInPoint;
import nc.bs.qc.pub.rule.QCRowNoCheckRule;
import nc.bs.qc.pub.rule.QCWriteOperateLogRule;
import nc.bs.scmpub.rule.VOSagaFrozenValidateRule;
import nc.impl.pubapp.bd.material.assistant.MarAssistantSaveRule;
import nc.impl.pubapp.pattern.data.bill.BillUpdate;
import nc.impl.pubapp.pattern.rule.processer.CompareAroundProcesser;
import nc.vo.pubapp.util.SetUpdateAuditInfoRule;
import nc.vo.qc.c003.entity.ReportItemVO;
import nc.vo.qc.c003.entity.ReportVO;
import nc.vo.qc.c003.rule.MaterialInStorckOrgRule;
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.c003.util.ReportVOInfoUtils;
import nc.vo.qc.pub.rule.CheckBillNumRule;
import nc.vo.qc.pub.rule.NoPassUpdateRule;
import nccloud.dto.qc.c003.constance.QCReportOprLogConst;

public class ReportUpdateBP {
    public ReportUpdateBP() {
    }

    public ReportVO[] updateReport(ReportVO[] voArray, ReportVO[] originBills) {
        CompareAroundProcesser<ReportVO> processer = new CompareAroundProcesser(ReportBPPlugInPoint.ReportUpdateBP);
        this.addBeforeRule(processer);
        this.addAfterRule(processer);
        ReportVOInfoUtils.handlerIndate((Map) null, voArray);
        processer.before(voArray, originBills);
        BillUpdate<ReportVO> bo = new BillUpdate();
        ReportVO[] vos = (ReportVO[]) bo.update(voArray, originBills);
        processer.after(voArray, originBills);
        (new QCWriteOperateLogRule(QCReportOprLogConst.maintainService.getCode(), QCReportOprLogConst.updateAction.getCode())).process(originBills, voArray);
        return vos;
    }

    private void addAfterRule(CompareAroundProcesser<ReportVO> processer) {
        processer.addAfterRule(new ChkBillCodeUniqueRule());
        processer.addAfterRule(new UpdChkBatCode());
        processer.addAfterRule(new ReportChkChkBatUnique());
        processer.addAfterRule(new WriteC001WhenUpdateRule());
        processer.addAfterRule(new UpdateBatchCodeAfterRule());
        processer.addAfterRule(new SyncQcQmsRule());
    }

    private void addBeforeRule(CompareAroundProcesser<ReportVO> processer) {
        processer.addBeforeRule(new VOSagaFrozenValidateRule(true));
        processer.addBeforeRule(new UpdateBillCodeRule());
        processer.addBeforeRule(new FillUpDataUpdateRule());
        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 SetUpdateAuditInfoRule());
        processer.addBeforeRule(new ReportItemsCheckRule());
        processer.addBeforeRule(new QCRowNoCheckRule(ReportItemVO.class, "crowno"));
        processer.addBeforeRule(new ReportNumCheckRule());
        processer.addBeforeRule(new UpdateBatchCodeBeforeRule());
        MarAssistantSaveRule<ReportVO> mar = new MarAssistantSaveRule();
        processer.addBeforeRule(mar);
        processer.addBeforeRule(new NoPassUpdateRule());
        processer.addBeforeRule(new ReportAddStockStateRule());
        processer.addBeforeRule(new MaterialInStorckOrgRule());
    }
}
