package nc.bs.arap.twxt.listener;

import java.util.HashMap;
import java.util.Map;

import nc.bs.businessevent.BusinessEvent;
import nc.bs.businessevent.BusinessEvent.BusinessUserObj;
import nc.bs.businessevent.IBusinessEvent;
import nc.bs.businessevent.IBusinessListener;
import nc.util.uap.twxt.WYTwxtUtil;
import nc.vo.arap.basebill.BaseAggVO;
import nc.vo.arap.payable.AggPayableBillVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.VOStatus;
/**
 * @author 符耀铭
 * @time 2019-10-24
 * @description 新加的类，用于物业应付单删除后回写物业天问系统
 */
public class PayablebillDelWriteTWListener implements IBusinessListener {

	@Override
	public void doAction(IBusinessEvent event) throws BusinessException {
		BusinessEvent erEvent = (BusinessEvent) event;
		BusinessUserObj obj = (BusinessUserObj) (erEvent).getUserObject();
		
		if (obj.getUserObj() instanceof AggPayableBillVO[]) {
			AggPayableBillVO[] vos =(AggPayableBillVO[]) obj.getUserObj();

			if(null!=vos){
				Map paraMap=new HashMap();
				for(int i=0;i<vos.length;i++){
					if("F1-Cxx-D70".equals(vos[i].getHeadVO().getPk_tradetype()) && vos[i].getHeadVO().getStatus()==VOStatus.DELETED){
						paraMap.put("ORDERID", vos[i].getHeadVO().getDef2()==null?vos[i].getHeadVO().getDef1():vos[i].getHeadVO().getDef2());
						paraMap.put("TYPE", "4");
						paraMap.put("REMARK", "应付单删除回写");
						WYTwxtUtil.callWyTwService(paraMap, "NCBILL_REVOKE", "应付单删除回写");
					}
				}
			}
		}
		else if(obj.getUserObj() instanceof BaseAggVO[]){
			BaseAggVO[] baseAggVOs=(BaseAggVO[]) obj.getUserObj();
			
			if(null!=baseAggVOs){
				Map paraMap=new HashMap();
				for(int i=0;i<baseAggVOs.length;i++){
					if("F1-Cxx-D70".equals(baseAggVOs[i].getHeadVO().getPk_tradetype())&& baseAggVOs[i].getHeadVO().getStatus()==VOStatus.DELETED){
						paraMap.put("ORDERID", baseAggVOs[i].getHeadVO().getAttributeValue("def2")==null?baseAggVOs[i].getHeadVO().getDef1():baseAggVOs[i].getHeadVO().getAttributeValue("def2"));
						paraMap.put("TYPE", "4");
						paraMap.put("REMARK", "应付单删除回写");
						WYTwxtUtil.callWyTwService(paraMap, "NCBILL_REVOKE", "应付单删除回写");
					}
				}
			}
			
		}
	}

}
