package nc.bs.pub.action;

import java.util.Hashtable;
import nc.bs.pub.compiler.AbstractCompiler2;
import nc.impl.fa.deployout.DeployOutImpl;
import nc.vo.am.common.util.StringUtils;
import nc.vo.am.common.util.sagas.AMSagasUtils;
import nc.vo.am.proxy.AMProxy;
import nc.vo.fa.deployout.DeployOutBodyVO;
import nc.vo.fa.deployout.DeployOutHeadVO;
import nc.vo.fa.deployout.DeployOutVO;
import nc.vo.pub.AggregatedValueObject;
import nc.vo.pub.BusinessException;
import nc.vo.pub.compiler.PfParameterVO;
import nccloud.pub.ampub.permission.IPermission4Nccloud;
import nccloud.web.byz.action.ARCApproveAction;

public class N_HC_APPROVE extends AMApproveAbstractCompiler2 {
	private Hashtable m_methodReturnHash = new Hashtable<>();

	private Hashtable m_keyHash = null;

	public Object runComClass(PfParameterVO vo) throws BusinessException {
		super.runComClass(vo);
		if (vo.isCloudEntry) {
			validatePermission(vo, (DeployOutVO) vo.m_billEntity);
			AMSagasUtils.frozenAndAddSaga(new AggregatedValueObject[] { (AggregatedValueObject) vo.m_billEntity });
		}
		Object object = (new DeployOutImpl()).approveBillVOs((AbstractCompiler2) this, vo);

		// modefy by djy 20220319因为审批驳回都会走这个动作，只有审批有回调ARC
//		String approveresult = vo.m_workFlow==null?null:vo.m_workFlow.approveresult;
//		if ("Y".equals(approveresult)) {
			// add by djy 20220216 增加对ARC系统的对接
			DeployOutVO aggvo = (DeployOutVO) vo.m_billEntity;
			DeployOutHeadVO head = (DeployOutHeadVO) aggvo.getParentVO();
			DeployOutBodyVO[] body = (DeployOutBodyVO[]) aggvo.getChildrenVO();
			if(head.getBill_status()==3) {
			if ("碧优资".equals(head.getDef10())) {
				// 推送给ARC
				new ARCApproveAction().sendApprove(body[0].getAttributeValue("pk_card") + "", head.getDef11(), 5);
				}
			}
//		}
		return object;
	}

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