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.IAlter;
import nc.pubitf.para.ISysInitDAO;
import nc.vo.am.common.util.StringUtils;
import nc.vo.am.proxy.AMProxy;
import nc.vo.fa.alter.AlterVO;
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.alter.originvalue.IAlterOriginValue4Cloud;

public class N_HG_DELETE extends AbstractCompiler2 {
	private Hashtable m_keyHash = null;

	public Object runComClass(PfParameterVO vo) throws BusinessException {
		try {
			super.m_tmpVo = vo;
			this.setParameter("context", this.getUserObj());
			AlterVO billVO = (AlterVO) 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("def1")))
				throw new BusinessException("ARC同步过来的单据不能删除！");
			if("Y".equals(billVO.getParentVO().getAttributeValue("def10")))
				throw new BusinessException("已经同步ARC单据不能删除！");
			this.setParameter("vo", billVO);
			Object retVal = null;
			if (vo.isCloudEntry) {
				this.validatePermission(vo, billVO);
				((IAlterOriginValue4Cloud) NCLocator.getInstance().lookup(IAlterOriginValue4Cloud.class))
						.delete((LoginContext) this.getUserObj(), billVO);
			} else {
				((IAlter) NCLocator.getInstance().lookup(IAlter.class)).delete((LoginContext) this.getUserObj(),
						(AlterVO) 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, AlterVO aggVO) throws BusinessException {
		IPermission4Nccloud permissionService = (IPermission4Nccloud) AMProxy.lookup(IPermission4Nccloud.class);
		String transType = (String) aggVO.getParent().getAttributeValue("transi_type");
		String node_code = null;
		String resourceCode = null;
		if ("HG-01".equals(transType)) {
			node_code = "2012028015";
			resourceCode = "2012028015";
		} else if ("HG-02".equals(transType)) {
			node_code = "2012028020";
			resourceCode = "2012028020";
		} else if ("HG-04".equals(transType)) {
			node_code = "2012028030";
			resourceCode = "2012028030";
		} else if ("HG-06".equals(transType)) {
			node_code = "2012028040";
			resourceCode = "2012028040";
		} else if ("HG-13".equals(transType)) {
			node_code = "2012028075";
			resourceCode = "2012028075";
		} else if ("HG-14".equals(transType)) {
			node_code = "2012028080";
			resourceCode = "2012028080";
		} else if ("HG-16".equals(transType)) {
			node_code = "2012028090";
			resourceCode = "2012028090";
		} else if ("HG-05".equals(transType)) {
			node_code = "2012028035";
			resourceCode = "2012028035";
		} else {
			node_code = "2012028120";
			resourceCode = "2012028120";
		}

		String meta_code = "Delete";
		String faliure = permissionService.busiOprPermission(node_code, meta_code, resourceCode, aggVO);
		if (!StringUtils.isEmpty(faliure)) {
			throw new BusinessException(faliure);
		}
	}
}