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.IDeployIn;
import nc.pub.fa.common.util.StringUtils;
import nc.pubitf.para.ISysInitDAO;
import nc.vo.am.proxy.AMProxy;
import nc.vo.fa.deployin.DeployInVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.compiler.PfParameterVO;
import nccloud.pub.ampub.permission.IPermission4Nccloud;
import nccloud.pubitf.fa.deploy.deployin.IDeployIn4Cloud;

public class N_HD_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());
			DeployInVO billVO = (DeployInVO) 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, (DeployInVO) vo.m_billEntity);
			}

			Object retVal = null;
			if (vo.isCloudEntry) {
				((IDeployIn4Cloud) NCLocator.getInstance().lookup(IDeployIn4Cloud.class))
						.delete(new DeployInVO[]{(DeployInVO) this.getVo()});
			} else {
				((IDeployIn) NCLocator.getInstance().lookup(IDeployIn.class)).delete((DeployInVO) this.getVo());
			}

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

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

	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);
		}

	}
}