package nc.impl.fa.deployout.rule;

import nc.bs.am.framework.action.ActionContext;
import nc.bs.am.framework.action.IRule;
import nc.bs.framework.common.NCLocator;
import nc.impl.am.db.VOPersistUtil;
import nc.pubitf.para.ISysInitDAO;
import nc.vo.am.common.AbstractAggBill;
import nc.vo.am.common.util.AssertUtils;
import nc.vo.fa.deployout.DeployOutHeadVO;
import nc.vo.fa.deployout.DeployOutVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.SuperVO;
import nc.vo.pub.VOStatus;
import nc.vo.util.AuditInfoUtil;
/**
 * <p>
 * <b>调出单取消审批更新调出单信息</b>
 * </p>
 * 
 * @author kongfy
 * @version 6.0 2011-11-01
 */
public class UpdateBillInfoWhenUnapproveAfterRule <E extends AbstractAggBill>  implements IRule<E> {

	@Override
	public void process(ActionContext<E> context, E... aggVos) throws BusinessException {
		// TODO Auto-generated method stub
		for (E aggVO : aggVos) {
			DeployOutVO billVO = (DeployOutVO) aggVO;
			//碧优资同步生成的调出单，不走标准的删除调入单。 -- ccy 2022年1月10日
			ISysInitDAO InitDAO = NCLocator.getInstance().lookup(ISysInitDAO.class);
			String src_byz = InitDAO.getSysInitTempVO("src_byz").getDefaultvalue();
			if(!src_byz.equals(((DeployOutHeadVO) billVO.getParentVO()).getDef10())) {

				DeployOutHeadVO hvo = (DeployOutHeadVO) billVO.getParentVO();
				// 情况调入单据PK
				hvo.setPk_deployin(null);
				// 清空调入单编码和状态
				hvo.setAttributeValue(DeployOutHeadVO.BILL_CODE_IN, null);
				hvo.setAttributeValue(DeployOutHeadVO.BILL_STATUS_IN, null);
	
				updateSuperVO(hvo);
			}
		}
	}

	public <T extends SuperVO> T[] updateSuperVO(T... superVO) throws BusinessException {
		AssertUtils.isTrue(superVO != null && superVO.length > 0, nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("deploy_0","02012020-0032")/*@res "更新的数据不能为空"*/);
		// 业务锁
		// 审计信息
		AuditInfoUtil.updateData(superVO);
		// 修改操作
		for (SuperVO bodyVO : superVO) {
			bodyVO.setStatus(VOStatus.UPDATED);
		}

		VOPersistUtil.update(superVO);

		return superVO;
	}
}