package nc.bs.arap.busireg;

import nc.bs.arap.initclose.InitCloseCtrlBO;
import nc.bs.businessevent.BdUpdateEvent;
import nc.bs.businessevent.BusinessEvent;
import nc.bs.businessevent.IBusinessEvent;
import nc.bs.businessevent.IBusinessListener;
import nc.bs.framework.common.NCLocator;
import nc.itf.uap.IUAPQueryBS;
import nc.jdbc.framework.processor.ColumnProcessor;
import nc.jdbc.framework.processor.MapProcessor;
import nc.vo.arap.payable.PayableBillItemVO;
import nc.vo.pub.AggregatedValueObject;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFDouble;

import java.util.Map;

import org.apache.commons.lang.ArrayUtils;

public class InitCloseCtrlListener implements IBusinessListener {
	
	public void doAction(IBusinessEvent event) throws BusinessException {
		if ("1001".equals(event.getEventType()) || "1003".equals(event.getEventType())
				|| "1005".equals(event.getEventType())) {
			AggregatedValueObject[] obills = this.getBills(event);
			if (!ArrayUtils.isEmpty(obills)) {
				(new InitCloseCtrlBO()).checkIsInitClose(obills[0]);
			}
		}
	}

	protected 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[]) ((AggregatedValueObject[]) object);
			} else {
				bills = new AggregatedValueObject[]{(AggregatedValueObject) object};
			}
		}

		return bills;
	}
}