//gDoB4S+UYfafwH1tyLzQ2JMlrpfXk744O+43pNreBurVi/GUJSKcXuemOWQZ03e5
package nc.bs.ic.m45.cancelsign;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import nc.bs.ic.general.cancelsign.CancelSignBPTemplate;
import nc.bs.ic.general.cancelsign.ICancelSignBP;
import nc.bs.ic.general.cancelsign.ICancelSignRuleProvider;
import nc.bs.ic.general.cancelsign.rule.CancelSignCheckAssetFlag;
import nc.bs.ic.m45.base.BPPlugInPoint;
import nc.bs.ic.m45.cancelsign.rule.AfterCancelSignRuleForLiabilityProcess;
import nc.bs.ic.m45.cancelsign.rule.AfterRuleForCancelRewritePUSettle;
import nc.bs.ic.m45.cancelsign.rule.AfterUnsignRuleForFinanceProcess;
import nc.bs.ic.m45.cancelsign.rule.BeforeRuleForDelete5X;
import nc.bs.ic.m45.cancelsign.rule.CancelSignCheckEtpickup;
import nc.bs.ic.m45.cancelsign.rule.CancelSignCheckFeeSettle;
import nc.bs.ic.m45.cancelsign.rule.CheckCancelSignRule;
import nc.bs.ic.m45.cancelsign.rule.EtdetlpickRule;
import nc.bs.ic.m45.wgpt.rule.WuYeWgptCancelSignRule;
import nc.bs.ic.pub.util.SagasUtils;
import nc.bs.scmpub.rule.VOSagaFrozenValidateRule;
import nc.impl.pubapp.pattern.rule.processer.AroundProcesser;
import nc.itf.ic.m45.compensate.IPurchaseInSagasCompensate;
import nc.vo.ic.general.define.SagasConst;
import nc.vo.ic.m45.entity.PurchaseInVO;
import nc.vo.scmpub.res.billtype.ICBillType;
import nccloud.bs.ic.mobile.inbound.operation.rewrite.MobAfterPurchaseInUnsign;
import nccloud.pubimpl.ic.inbound.purchasein.cancelsign.rule.CheckCancelSignIsBCompareRule;

/**
 * @author songhy
 *
 * 2010-1-21 下午02:14:48
 */
public class CancelSignBP 
  implements ICancelSignBP<PurchaseInVO>, 
  ICancelSignRuleProvider<PurchaseInVO> {

  @Override
  public PurchaseInVO[] cancelSign(PurchaseInVO[] bills) {
    CancelSignBPTemplate<PurchaseInVO> cancelSignBP 
      = new CancelSignBPTemplate<PurchaseInVO>(BPPlugInPoint.CancelSignAction, this);
    SagasUtils.frozenAndAddSaga(bills, ICBillType.PurchaseIn.getCode(),SagasConst.COMPENSABLE, null);
    Map<String, Serializable> paramMap = new HashMap<String, Serializable>();
   	// 动作标识
   	paramMap.put(SagasConst.KEY_ACTIONNAME, SagasConst.CANCELSIGN_45);
   	// 表头主键
   	paramMap.put(SagasConst.KEY_HID, bills[0].getPrimaryKey());
   	SagasUtils.compensate(paramMap, IPurchaseInSagasCompensate.class);
    PurchaseInVO[] resultVOs = cancelSignBP.cancelSign(bills);
    return resultVOs;
  }

  @Override
  public void addAfterRule(PurchaseInVO[] vos,
      AroundProcesser<PurchaseInVO> processor) {
    processor.addAfterRule( new AfterRuleForCancelRewritePUSettle() );
    processor.addAfterRule( new AfterUnsignRuleForFinanceProcess() );
    processor.addAfterRule( new AfterCancelSignRuleForLiabilityProcess() );
    // 移动协同消息
    processor.addAfterRule( new MobAfterPurchaseInUnsign() );
  }

  @Override
  public void addBeforeRule(PurchaseInVO[] vos,
      AroundProcesser<PurchaseInVO> processor) {
	// sagas冻结校验
	processor.addBeforeRule(new VOSagaFrozenValidateRule<PurchaseInVO>(true));
    processor.addBeforeRule(new CheckCancelSignRule());
    processor.addBeforeRule(new CheckCancelSignIsBCompareRule());// 校验是否生成业务对账单 NCC添加，add by yinl 20190509
    processor.addBeforeRule(new BeforeRuleForDelete5X());
    processor.addBeforeRule(new CancelSignCheckAssetFlag<PurchaseInVO>());
    processor.addBeforeRule(new CancelSignCheckEtpickup());
    processor.addBeforeRule(new EtdetlpickRule());
    // add by chaiwx ncc1909 内部费用结算后不能取消签字
    processor.addBeforeRule(new CancelSignCheckFeeSettle());
    //add by 周蓝萍 来源网购平台的订单生成的采购入库单不允许取消签字 2020-10-21 begin
  	processor.addBeforeRule(new WuYeWgptCancelSignRule());
    //add by 周蓝萍 来源网购平台的订单生成的采购入库单不允许取消签字 2020-10-21 end
  }

}

//gDoB4S+UYfafwH1tyLzQ2JMlrpfXk744O+43pNreBurVi/GUJSKcXuemOWQZ03e5