package nc.bs.pub.action;

import java.util.Hashtable;
import nc.bs.framework.common.NCLocator;
import nc.bs.logging.Logger;
import nc.bs.pub.compiler.AbstractCompiler2;
import nc.itf.fa.prv.IReduce;
import nc.pubitf.para.ISysInitDAO;
import nc.vo.am.common.util.StringUtils;
import nc.vo.am.proxy.AMProxy;
import nc.vo.fa.reduce.ReduceVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.compiler.PfParameterVO;
import nc.vo.uif2.LoginContext;
import nccloud.pub.ampub.permission.IPermission4Nccloud;
import nccloud.pubitf.fa.maintain.reduce.IReduce4Cloud;

public class N_HF_DELETE extends AbstractCompiler2 {
	private Hashtable m_methodReturnHash = new Hashtable();
	private Hashtable m_keyHash = null;

	public Object runComClass(PfParameterVO vo) throws BusinessException {
		try {
			super.m_tmpVo = vo;
			this.setParameter("context", this.getUserObj());
			ReduceVO billVO = (ReduceVO) this.getVo();
			//add by djy 20220104对于碧优资同步过来的单不能直接删除
			ISysInitDAO InitDAO = NCLocator.getInstance().lookup(ISysInitDAO.class);
			String src_byz = InitDAO.getSysInitTempVO("src_byz").getDefaultvalue();
			if(src_byz.equals(billVO.getParentVO().getAttributeValue("def10")))
				throw new BusinessException("ARC同步过来的单据不能删除！");
			this.setParameter("vo", billVO);
			if (vo.isCloudEntry) {
				this.validatePermission(vo, (ReduceVO) vo.m_billEntity);
			}

			Object retVal = null;
			if (vo.isCloudEntry) {
				((IReduce4Cloud) NCLocator.getInstance().lookup(IReduce4Cloud.class)).delete(new ReduceVO[]{billVO});
			} else {
				((IReduce) NCLocator.getInstance().lookup(IReduce.class)).delete((LoginContext) this.getUserObj(),
						(ReduceVO) this.getVo());
			}

			return retVal;
		} catch (Exception var4) {
			Logger.error(var4.getMessage(), var4);
			throw new BusinessException(var4);
		}
	}

	private void setParameter(String key, Object val) {
		if (this.m_keyHash == null) {
			this.m_keyHash = new Hashtable();
		}

		if (val != null) {
			this.m_keyHash.put(key, val);
		}

	}

	private void validatePermission(PfParameterVO vo, ReduceVO aggVO) throws BusinessException {
		IPermission4Nccloud permissionService = (IPermission4Nccloud) AMProxy.lookup(IPermission4Nccloud.class);
		String node_code = "2012056010";
		String resourceCode = "2012056010";
		String meta_code = "Delete";
		String faliure = permissionService.busiOprPermission(node_code, meta_code, resourceCode, aggVO);
		if (!StringUtils.isEmpty(faliure)) {
			throw new BusinessException(faliure);
		}
	}
}