package nc.bs.sf.listener;

import nc.bs.businessevent.BdUpdateEvent;
import nc.bs.businessevent.BusinessEvent;
import nc.bs.businessevent.IBusinessEvent;
import nc.bs.businessevent.IBusinessListener;
import nc.vo.pub.AggregatedValueObject;
import nc.vo.pub.BusinessException;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
/**
 * 上收下拨校验
 * @author xug
 * @date 2021年11月23日
 */
public class GXCSSXBListener implements IBusinessListener {

	@Override
	public void doAction(IBusinessEvent event) throws BusinessException {
		
		String souid = event.getSourceID();
		String type = event.getEventType();
		AggregatedValueObject[] vos=getBills(event);

		String pk_org = "";
		Object bill_date = "";
//		Object billType = vos[0].getParentVO().getAttributeValue("pk_tradetype");
		if("74d29f86-4334-4fc9-a7d3-085cf5dd7845".equals(souid)){//资金上收
			if(vos[0].getChildrenVO() != null && vos[0].getChildrenVO().length > 1) {
				ExceptionUtils.wrappBusinessException("[资金下拨],不能录入多行表体!");
			}
		}else if("aa76ec14-f065-4394-885c-43f34f0c83c6".equals(souid)){//资金下拨
			if(vos[0].getChildrenVO() != null && vos[0].getChildrenVO().length > 1) {
				ExceptionUtils.wrappBusinessException("[资金上收],不能录入多行表体!");
			}
		}
	}
	
	private AggregatedValueObject[] getBills(IBusinessEvent event) {
		Object object = null;
		if ((event instanceof BusinessEvent)) {
			BusinessEvent e = (BusinessEvent) event;
			object = e.getObject();
		} else if ((event instanceof BdUpdateEvent)) {
			BdUpdateEvent e = (BdUpdateEvent) event;
			object = e.getNewObject();
		}

		AggregatedValueObject[] bills = null;
		if (null != object) {
			if (object.getClass().isArray()) {
				bills = (AggregatedValueObject[]) object;
			} else {
				bills = new AggregatedValueObject[1];
				bills[0] = ((AggregatedValueObject) object);
			}
		}
		return bills;
	}

}
