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

package nc.bs.mmpac.wr.bp;

import java.util.HashMap;
import java.util.Map;
import nc.bs.mmpac.wr.plugin.WrPluginPoint;
import nc.bs.mmpac.wr.rule.WrAuditAndApplyCheckRule;
import nc.bs.mmpac.wr.rule.WrAuditAndProdInRule;
import nc.bs.mmpac.wr.rule.WrCheckMaterialPermissionRule;
import nc.bs.mmpac.wr.rule.WrCheckMoIsCloseRule;
import nc.bs.mmpac.wr.rule.WrCheckTranstypeCodeRule;
import nc.bs.mmpac.wr.rule.WrClearNullBodyRule;
import nc.bs.mmpac.wr.rule.WrFillInsertDataRule;
import nc.bs.mmpac.wr.rule.WrHeadNotNullRule;
import nc.bs.mmpac.wr.rule.WrIsSaveAndApproveRule;
import nc.bs.mmpac.wr.rule.WrNoneMainProductBomCheckRule;
import nc.bs.mmpac.wr.rule.WrPickFilterRule;
import nc.bs.mmpac.wr.rule.WrQualityFilterRule;
import nc.bs.mmpac.wr.rule.WrRowNoRule;
import nc.bs.mmpac.wr.rule.WrSetDefaultValueWhenInsertRule;
import nc.bs.mmpac.wr.rule.WrSetItemDefaultValueRule;
import nc.bs.mmpac.wr.rule.WrSetQualityVODefaultValueRule;
import nc.bs.mmpac.wr.rule.batch.WrCreateBatProdRule;
import nc.bs.mmpac.wr.rule.batch.WrCreateBatchCodeRule;
import nc.bs.mmpac.wr.rule.check.WrNullRule;
import nc.bs.mmpac.wr.rule.instockbatch.WrInsertAndDelInStockBatchCodeBeforeRule;
import nc.bs.mmpac.wr.rule.instockbatch.WrInsertInStockBatchCodeAfterRule;
import nc.bs.mmpac.wr.rule.mo.MoDiscadNumRewriteRule;
import nc.bs.mmpac.wr.rule.mo.WrMORewriteRule;
import nc.bs.mmpac.wr.rule.output.WrOutputNotNullRule;
import nc.bs.mmpac.wr.rule.pick.WrPickNotNullRule;
import nc.bs.mmpac.wr.rule.putplan.WrInsertRewriteWrNumForPutPlanRule;
import nc.bs.mmpac.wr.rule.serialno.WrMoSerialNoMarkIRule;
import nc.bs.mmpac.wr.rule.serialno.WrSerialNoAutoCreateBeforeRule;
import nc.bs.mmpac.wr.rule.serialno.WrSerialNoCheckCodeRepeat;
import nc.bs.mmpac.wr.rule.serialno.WrSerialNoCheckRule;
import nc.bs.mmpac.wr.rule.serialno.WrSerialNoSaveRule;
import nc.bs.mmpac.wr.rule.serialno.WrSnSynToQualtiyRule;
import nc.bs.mmpub.rule.MMATOMaterialCheckRule;
import nc.bs.mmpub.rule.MMAutoMaterialAssignRule;
import nc.bs.pubapp.pub.rule.FieldLengthCheckRule;
import nc.bs.pubapp.pub.rule.OrgDisabledCheckRule;
import nc.impl.pubapp.bd.material.assistant.MarAssistantSaveRule;
import nc.impl.pubapp.bd.userdef.UserDefSaveRule;
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.MMCheckMaterialVirtualRule;
import nc.util.mmf.busi.rule.MMCreateBillcodeAndTrantypecodeRule;
import nc.util.mmf.framework.gc.GCInsertBPTemplate;
import nc.vo.mmpac.wr.entity.AggWrVO;
import nc.vo.mmpac.wr.entity.WrItemVO;
import nc.vo.mmpac.wr.entity.WrPickVO;
import nc.vo.mmpac.wr.entity.WrQualityVO;
import nc.vo.mmpac.wr.entity.WrVO;

public class WrInsertBP {
	private boolean isOnlyInsert = false;

	public WrInsertBP() {
	}

	public AggWrVO[] insert(AggWrVO[] vos) {
		GCInsertBPTemplate<AggWrVO> bp = new GCInsertBPTemplate(WrPluginPoint.INSERT);
		AroundProcesser<AggWrVO> processor = bp.getAroundProcesser();
		Map<String, String> vbatchsMap = new HashMap();
		this.addBeforeRule(processor, vos, vbatchsMap);
		this.addAfterRule(processor, vbatchsMap);
		return (AggWrVO[]) bp.insert(vos);
	}

	private void addBeforeRule(AroundProcesser<AggWrVO> processer, AggWrVO[] vos, Map<String, String> vbatchsMap) {
		IRule<AggWrVO> wrNullRule = new WrNullRule();
		processer.addBeforeRule(wrNullRule);
		IRule<AggWrVO> mmatoMaterialCheckRule = new MMATOMaterialCheckRule((String) null, "cbmaterialvid", "cbffileid");
		processer.addBeforeRule(mmatoMaterialCheckRule);
		IRule<AggWrVO> orgRule = new OrgDisabledCheckRule("pk_org", "FACTORYTYPE000000000");
		processer.addBeforeRule(orgRule);
		IRule<AggWrVO> checkDefRule = new UserDefSaveRule(new String[] { "vdef", "vbdef", "vgdef", "vpdef" },
				new Class[] { WrVO.class, WrItemVO.class, WrQualityVO.class, WrPickVO.class });
		processer.addBeforeRule(checkDefRule);
		MarAssistantSaveRule<AggWrVO> marRule = new MarAssistantSaveRule();
		processer.addBeforeRule(marRule);
		IRule<AggWrVO> fillInsertDataRule = new WrFillInsertDataRule();
		processer.addBeforeRule(fillInsertDataRule);
		IRule<AggWrVO> autoMaterialAssignRule = new MMAutoMaterialAssignRule((String) null, "cbmaterialvid",
				new String[] { "pk_org" }, (String[]) null);
		processer.addBeforeFinalRule(autoMaterialAssignRule);
		IRule<AggWrVO> orgPermissionRule = new WrCheckMaterialPermissionRule();
		processer.addBeforeRule(orgPermissionRule);
		IRule<AggWrVO> moCloseRule = new WrCheckMoIsCloseRule();
		processer.addBeforeRule(moCloseRule);
		processer.addBeforeRule(new MMCheckMaterialVirtualRule(WrItemVO.class));
		IRule<AggWrVO> wrSetDefaultValueWhenInsertRule = new WrSetDefaultValueWhenInsertRule();
		processer.addBeforeRule(wrSetDefaultValueWhenInsertRule);
		IRule<AggWrVO> wrSetItemDefaultValueRule = new WrSetItemDefaultValueRule();
		processer.addBeforeRule(wrSetItemDefaultValueRule);
		IRule<AggWrVO> billcodeRule = new MMCreateBillcodeAndTrantypecodeRule("55A4", "vbillcode", "pk_group", "pk_org",
				"vtrantypecode");
		processer.addBeforeRule(billcodeRule);
		IRule<AggWrVO> wrHeadNotNullRule = new WrHeadNotNullRule();
		processer.addBeforeRule(wrHeadNotNullRule);
		IRule<AggWrVO> wrBatchCodeRule = new WrCreateBatchCodeRule();
		processer.addBeforeRule(wrBatchCodeRule);
		IRule<AggWrVO> wrClearNullProductBodyRule = new WrClearNullBodyRule();
		processer.addBeforeRule(wrClearNullProductBodyRule);
		processer.addBeforeRule(new WrRowNoRule());
		IRule<AggWrVO> wrQualityFilterRule = new WrQualityFilterRule();
		processer.addBeforeRule(wrQualityFilterRule);
		IRule<AggWrVO> wrPickFilterRule = new WrPickFilterRule();
		processer.addBeforeRule(wrPickFilterRule);
		IRule<AggWrVO> wrOutputNotNullRule = new WrOutputNotNullRule();
		processer.addBeforeRule(wrOutputNotNullRule);
		IRule<AggWrVO> wrNoneMainProductBomCheckRule = new WrNoneMainProductBomCheckRule();
		processer.addBeforeRule(wrNoneMainProductBomCheckRule);
		IRule<AggWrVO> wrConsumeNotNullRule = new WrPickNotNullRule();
		processer.addBeforeRule(wrConsumeNotNullRule);
		IRule<AggWrVO> lengthCheckRule = new FieldLengthCheckRule();
		processer.addBeforeRule(lengthCheckRule);
		IRule<AggWrVO> wrInsertAndDelInStockBatchCodeBeforeRule = new WrInsertAndDelInStockBatchCodeBeforeRule(
				vbatchsMap);
		processer.addBeforeRule(wrInsertAndDelInStockBatchCodeBeforeRule);
		WrSetQualityVODefaultValueRule wrSetQualityVODefaultValueRule = new WrSetQualityVODefaultValueRule();
		processer.addBeforeRule(wrSetQualityVODefaultValueRule);
		processer.addBeforeRule(new WrSerialNoCheckCodeRepeat());
		WrSerialNoAutoCreateBeforeRule wrAutoCreateSnBeforeRule = new WrSerialNoAutoCreateBeforeRule();
		processer.addBeforeRule(wrAutoCreateSnBeforeRule);
		WrSerialNoCheckRule wrSnCheckRule = new WrSerialNoCheckRule();
		processer.addBeforeRule(wrSnCheckRule);
		WrSnSynToQualtiyRule synToQRule = new WrSnSynToQualtiyRule();
		processer.addBeforeRule(synToQRule);
		WrMoSerialNoMarkIRule mosnMarkRule = new WrMoSerialNoMarkIRule();
		processer.addBeforeRule(mosnMarkRule);
		IRule<AggWrVO> wrCreateBatProdRule = new WrCreateBatProdRule();
		processer.addBeforeRule(wrCreateBatProdRule);
		processer.addBeforeRule(new WrCheckTranstypeCodeRule());
	}

	private void addAfterRule(AroundProcesser<AggWrVO> processor, Map<String, String> vbatchsMap) {
		IRule<AggWrVO> rule = new MMBillCodeCheckAndTrantypeRule("55A4", "vbillcode", "pk_group", "pk_org",
				"vtrantypecode");
		processor.addAfterRule(rule);
		IRule<AggWrVO> wrCreateInStockBatchCodeAfterRule = new WrInsertInStockBatchCodeAfterRule(vbatchsMap);
		processor.addAfterRule(wrCreateInStockBatchCodeAfterRule);
		processor.addAfterRule(new WrInsertRewriteWrNumForPutPlanRule());
		IRule<AggWrVO> wrMORewriteRule = new WrMORewriteRule(2);
		processor.addAfterRule(wrMORewriteRule);
		IRule<AggWrVO> moDiscadNumRewriteRule = new MoDiscadNumRewriteRule(2);
		processor.addAfterRule(moDiscadNumRewriteRule);
		IRule<AggWrVO> snSaveRule = new WrSerialNoSaveRule();
		processor.addAfterRule(snSaveRule);
//		/** 同步修改备料计划完成 */
//		IRule<AggWrVO> pickMFinishRule = new PickMFinishRule();
//		processor.addAfterRule(pickMFinishRule);
//		/** ******************** */

		if (!this.isOnlyInsert) {
			processor.addAfterRule(new WrIsSaveAndApproveRule());
		}

		processor.addAfterRule(new WrAuditAndApplyCheckRule());
		processor.addAfterRule(new WrAuditAndProdInRule());
	}

	/** @deprecated */
	@Deprecated
	protected IRule<AggWrVO> getMoRewriteRule() {
		return null;
	}

	/** @deprecated */
	@Deprecated
	protected IRule<AggWrVO> getMoDiscadNumRewriteRule() {
		return null;
	}

	/** @deprecated */
	@Deprecated
	protected IRule<AggWrVO> getAuditRule() {
		return null;
	}

	public boolean isOnlyInsert() {
		return this.isOnlyInsert;
	}

	public void setOnlyInsert(boolean isOnlyInsert) {
		this.isOnlyInsert = isOnlyInsert;
	}
}
