package nc.impl.fbm.gather;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.ArrayUtils;

import nc.bs.dao.BaseDAO;
import nc.bs.dao.DAOException;
import nc.bs.fbm.base.validator.FbmBaseDeleteValidator;
import nc.bs.fbm.gather.GatherBillAccAdapter;
import nc.bs.fbm.gather.action.AuditGather;
import nc.bs.fbm.gather.action.CancelAuditGather;
import nc.bs.fbm.gather.action.CancelDisableGather;
import nc.bs.fbm.gather.action.CancelReliefGather;
import nc.bs.fbm.gather.action.DeleteGather;
import nc.bs.fbm.gather.action.DestroyGatherAction;
import nc.bs.fbm.gather.action.DisableGather;
import nc.bs.fbm.gather.action.ReliefKeepGather;
import nc.bs.fbm.gather.action.SaveGather;
import nc.bs.fbm.gather.validator.GatherCanoperateValidator;
import nc.bs.fbm.gather.validator.GatherOuterValidator;
import nc.bs.fbm.gather.validator.GatherRecieveCancelValidator;
import nc.bs.fbm.gather.validator.GatherRecieveCompleteValidator;
import nc.bs.fbm.gather.validator.GatherSaveAndApproveValidator;
import nc.bs.fbm.gather.validator.GatherSaveValidator;
import nc.bs.fbm.gather.validator.SaveIllegalGatherValidator;
import nc.bs.fbm.proxy.FBMPrivateServiceProxy;
import nc.bs.fbm.pub.validator.FbmCheckIntegratedValidator;
import nc.bs.framework.common.InvocationInfoProxy;
import nc.bs.framework.common.NCLocator;
import nc.bs.logging.Logger;
import nc.bs.pf.pub.PfDataCache;
import nc.bs.pfbm.proxy.PFBMPrivateServiceProxy;
import nc.bs.pub.tools.CheckInitDateTool;
import nc.bs.pub.tools.FbmHideFieldUtil;
import nc.bs.fbm.pub.tools.FbmPrivateUtil;
import nc.bs.sec.esapi.NCESAPI;
import nc.bs.uif2.validation.DefaultValidationService;
import nc.bs.uif2.validation.IValidationService;
import nc.bs.uif2.validation.ValidationFrameworkUtil;
import nc.bs.uif2.validation.Validator;
import nc.impl.fbm.pub.action.ActionQueryServiceImpl;
import nc.itf.bd.bankdoc.IBankdocQueryService;
import nc.itf.bd.currtype.ICurrtypeQuery;
import nc.itf.bd.notetype.INotetypeQueryService;
import nc.itf.cm.prv.CmpConst;
import nc.itf.fbm.beforeregister.IBeforeRegisterManageService;
import nc.itf.fbm.gather.IGatherManageService;
import nc.itf.fbm.gather.IGatherQueryService;
import nc.itf.fbm.outer.IOuterQueryService;
import nc.itf.fbm.pub.FBMPublicServiceProxy;
import nc.itf.fbm.pub.proxy.FbmPubPublicServiceProxy;
import nc.itf.org.IOrgConstBasic;
import nc.itf.pfbm.centeroccupyct.ICenteroccupyctManageService;
import nc.itf.uap.pf.IplatFormEntry;
import nc.pubitf.bd.accessor.GeneralAccessorFactory;
import nc.pubitf.bd.accessor.IGeneralAccessor;
import nc.pubitf.cmp.originalBalance.IOriBalanceService;
import nc.pubitf.fbm.api.ecds.pub.IFbmPubQueryService;
import nc.pubitf.org.IDeptPubService;
import nc.pubitf.org.IFundOrgPubService;
import nc.pubitf.org.cache.IBasicOrgUnitPubService_C;
import nc.pubitf.org.cache.IOrgUnitPubService_C;
import nc.pubitf.uapbd.ICustsupPubService;
import nc.vo.arap.gathering.AggGatheringBillVO;
import nc.vo.arap.gathering.GatheringBillItemVO;
import nc.vo.arap.gathering.GatheringBillVO;
import nc.vo.bd.accessor.IBDData;
import nc.vo.bd.bankaccount.IBankAccConstant;
import nc.vo.bd.bankdoc.BankdocVO;
import nc.vo.bd.currtype.CurrtypeVO;
import nc.vo.bd.cust.CustSupplierVO;
import nc.vo.bd.notetype.NotetypeVO;
import nc.vo.cmp.bill.RecBillAggVO;
import nc.vo.cmp.bill.RecBillDetailVO;
import nc.vo.cmp.bill.RecBillVO;
import nc.vo.cmp.originalbalance.OriginalBalanceVO;
import nc.vo.fbm.FBMSysParamConst;
import nc.vo.fbm.endore.EndoreVO;
import nc.vo.fbm.outer.OuterVO;
import nc.vo.fbm.pub.action.ActionVO;
import nc.vo.fbm.pub.adapter.GatherSagaInfoAdapter;
import nc.vo.fbm.pub.adapter.SagasFrozenProcessor;
import nc.vo.fbm.pub.constant.FbmBusConstant;
import nc.vo.fbm.pub.constant.FbmFieldConstant;
import nc.vo.fbm.pub.constant.RegisterStatusConstant;
import nc.vo.fbm.pub.statuscontrol.IStatusControlStrategy;
import nc.vo.fbm.pub.statuscontrol.StatusControlProcess;
import nc.vo.fbm.pub.util.FbmCommonTools;
import nc.vo.fbm.pub.util.FbmPublicUtil;
import nc.vo.fbm.pub.util.FbmSqlUtils;
import nc.vo.fbm.pub.voucherutil.BaseVoucherUtil;
import nc.vo.fbm.register.AggRegisterVO;
import nc.vo.fbm.register.PaymentStatusEnum;
import nc.vo.fbm.register.RegisterVO;
import nc.vo.fbm.storage.AggStorageVO;
import nc.vo.fbm.util.FbmSignPubSecurityUtil;
import nc.vo.fts.commissiongathering.AggGatheringVO;
import nc.vo.fts.commissiongathering.GatherFinanceVO;
import nc.vo.fts.commissiongathering.GatherFundVO;
import nc.vo.fts.commissiongathering.GatheringVO;
import nc.vo.org.OrgVO;
import nc.vo.org.util.OrgPubUtil;
import nc.vo.pf.pub.util.ArrayUtil;
import nc.vo.pfbm.centeroccupyct.AggCenteroccupyctVO;
import nc.vo.pfbm.pub.constant.EFbmBusConstant;
import nc.vo.pub.AggregatedValueObject;
import nc.vo.pub.BusinessException;
import nc.vo.pub.SuperVO;
import nc.vo.pub.VOStatus;
import nc.vo.pub.lang.UFBoolean;
import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDateTime;
import nc.vo.pub.lang.UFDouble;
import nc.vo.pub.lang.UFLiteralDate;
import nc.vo.pubapp.AppContext;
import nc.vo.tmpub.util.StringUtil;
import nc.vo.tmpub.util.TMCurrencyUtil;
import nc.vo.tmpub.validator.FinOrgUnUseValidator;
import nc.vo.tmpub.validator.VOFieldDesc;
import nc.vo.uap.pf.PfProcessBatchRetObject;
import nccloud.pubitf.platform.saga.CheckInfo;

/**
 * @author Administrator
 *
 */
public class GatherManageServiceImpl implements IGatherManageService {

	/**
	 * 没有状态控制更新
	 *
	 * @param aggvo
	 * @return AggRegisterVO
	 * @throws BusinessException
	 */
	@Override
	public AggRegisterVO updateGatherWithoutStatusControl(AggRegisterVO aggvo) throws BusinessException {
		aggvo.getParentVO().setStatus(VOStatus.UPDATED);
		// 更新数据库
		FBMPrivateServiceProxy.getMDService().saveBillWithRealDelete(aggvo);
		// 返回更新的VO
		return (AggRegisterVO) FbmPrivateUtil.queryAggvoByPK(aggvo);
	}

	/**
	 * 没有状态控制更新
	 *
	 * @param aggvo
	 * @return AggRegisterVO
	 * @throws BusinessException
	 */
	@Override
	public AggRegisterVO[] updateGathersWithoutStatusControl(AggRegisterVO[] aggvos) throws BusinessException {
		if (aggvos != null && aggvos.length > 0) {
			ArrayList<RegisterVO> regarr = new ArrayList<RegisterVO>();
			for (int i = 0; i < aggvos.length; i++) {
				aggvos[i].getParentVO().setStatus(VOStatus.UPDATED);
				regarr.add((RegisterVO) aggvos[i].getParentVO());
			}
			// 更新数据库
			FBMPrivateServiceProxy.getMDService().saveBillWithRealDelete(regarr.toArray(new RegisterVO[0]));
			// 返回更新的VO
			return FbmPrivateUtil.queryAggvosByPKsNCC(aggvos);
		}
		return null;
	}

	/**
	 * 新增
	 *
	 * @param aggvo
	 * @return aggvo
	 * @throws BusinessException
	 */
	@Override
	public AggRegisterVO insertGather(AggRegisterVO aggvo) throws BusinessException {
		RegisterVO registervo = (RegisterVO) aggvo.getParentVO();
		// 轻量级票据保存校验
		Validator gatherSaveValidator = new GatherSaveValidator();
		IValidationService vEcdService = ValidationFrameworkUtil.createValidationService(gatherSaveValidator);
		vEcdService.validate(registervo);

		// 组织停用校验 modify by aishm 2013-03-26
		DefaultValidationService validateService = new DefaultValidationService();
		validateService.addValidator(new FinOrgUnUseValidator(new VOFieldDesc(RegisterVO.PK_ORG)));
		validateService.validate(aggvo);

		/**
		 * 20200618 xuhrc 产品优化 需求6.6.2
		 * 收票登记保存/保存提交时校验，该票据目前在系统中的状态，如果背书或者付票的指令还是交易失败则不可保存
		 */
		Validator gatherSaveAndApproveValidator = new GatherSaveAndApproveValidator();
		IValidationService vgatherSaveAndApprovevice = ValidationFrameworkUtil
				.createValidationService(gatherSaveAndApproveValidator);
		vgatherSaveAndApprovevice.validate(aggvo.getParentVO());
		// 非法票据的校验
		Validator saveIllegalGatherValidator = new SaveIllegalGatherValidator();
		IValidationService vService = ValidationFrameworkUtil.createValidationService(saveIllegalGatherValidator);
		vService.validate(aggvo.getParentVO());
		
		// 对前台用户输入的数据进行验签  下方的signDataAggVO方法自带验签功能，故不需要在此重复验签
//		if (FbmBusConstant.GATHER_TYPE_INPUT.equals(registervo.getGathertype())
//				&& StringUtil.isNull(registervo.getCode())) {
//			FbmSignPubSecurityUtil.verifySign(aggvo,FbmSignPubSecurityUtil.CONST_ACTIONCODE_SAVE,false,null);
//		}
		
		// 持票单位为空时，取组织对应的内部客商 modify by aishm 2011-09-29
		if (StringUtil.isNull(registervo.getHoldunit())) {
			// V6.1持票单位改为组织 2011-12-20 modify by aishm
			registervo.setHoldunit(registervo.getPk_org());
		}
		// 查询付票单位对应的财务组织，如果收票登记单的所属财务组织与付票单位对应的财务组织相同，认定为同名背书
		ICustsupPubService cusService = NCLocator.getInstance().lookup(ICustsupPubService.class);
		String paybillunit = registervo.getPaybillunit();
		String entrustedpaybillunit = registervo.getEntrustedpaybillunit();
//		NCC-93126在新增时付票单位和被委托付票方都为空抛错		在提交时付票单位必须有值（提交时有校验）
		if (StringUtil.isNull(paybillunit) && StringUtil.isNull(entrustedpaybillunit)) {
			throw new BusinessException(
					nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618ncc1_0", "03618ncc1-0000")
							/* @res "票据" */ + registervo.getFbmbillno() + nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
									.getStrByID("3618ncc1_0", "03618ncc1-0006")/* @res "缺少付票单位信息！" */);
		}
		Map<String, String> cusOrgMap = cusService.queryOrgPkByCustsupPk(new String[] { paybillunit });
		String pk_cus_org = null;
		if (cusOrgMap != null && StringUtil.isNotNull(cusOrgMap.get(paybillunit))) {
			pk_cus_org = cusOrgMap.get(paybillunit);
		}
		EndoreVO ownedr = FBMPrivateServiceProxy.getEndoreQueryService().queryOwnEndore4Register(registervo.getPk_org(),
				registervo.getFbmbillno());
		if (StringUtil.isNotNull(pk_cus_org) && pk_cus_org.equals(registervo.getPk_org()) && ownedr != null
				&& ownedr.getOwnendore() != null && ownedr.getOwnendore().booleanValue()) {
			// 有同名背书的背书单记录，且付票单位与财务组织相同，认为是同名背书
			registervo.setSelfendore(UFBoolean.TRUE);
		} else {
			registervo.setSelfendore(UFBoolean.FALSE);
			//判断是否为上收下拨收票
			Map<String, String> pkMaps = FBMPrivateServiceProxy.getBillDeliveryQueryService()
					.queryBillDeliveryPksByFbmbillno(registervo.getPk_org(), new String[] { registervo.getFbmbillno() }, true);
			if(null == pkMaps || pkMaps.isEmpty()) {
				pkMaps = FBMPrivateServiceProxy.getBillAllocateQueryService()
						.queryBillAllocatePksByFbmbillno(registervo.getPk_org(), new String[] { registervo.getFbmbillno() }, true);
				if(null != pkMaps && !pkMaps.isEmpty()) {
					registervo.setGathertype(FbmBusConstant.GATHER_TYPE_ALLOCATE);
				}
			}else {
				registervo.setGathertype(FbmBusConstant.GATHER_TYPE_DELIVERY);
			}
		}
		
		// 检验票据池登记银行承兑银行信息
		checkBankDoc(registervo);

		if (registervo.getSignagrbank() != null && !registervo.getSignagrbank().trim().equals("")) {
			BankdocVO bankdocVOByPk = NCLocator.getInstance().lookup(IBankdocQueryService.class)
					.getBankdocVOByPk(registervo.getSignagrbank());
			if (bankdocVOByPk != null) {
				if (bankdocVOByPk.getPcombinenum() != null && !bankdocVOByPk.getPcombinenum().trim().equals("")) {
					registervo.setSignagrbanknum(bankdocVOByPk.getPcombinenum());
				} else {
					// 2018-12-11 朱三鹏让注释掉，待签收批量生成收票登记的时候，校验直接抛错，为了继续走业务，只是显示，没有业务含义
//        			throw new BusinessException("所选择的承兑银行没有设置人行联行行号");
				}
				if (bankdocVOByPk.getPcombinename() != null && !bankdocVOByPk.getPcombinename().trim().equals("")) {
					registervo.setSignagrbankname(bankdocVOByPk.getPcombinename());
				} else {
					// 2018-12-11 朱三鹏让注释掉，待签收批量生成收票登记的时候，校验直接抛错，为了继续走业务，只是显示，没有业务含义
//        			throw new BusinessException("所选择的承兑银行没有设置人行联行名称");
				}

			} else {
				throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
						"03618fbm_add02-0323")/* @res "根据所选择的承兑银行找不到相关银行档案" */);
			}
		}
		// end_luxiong7_20180921_山西正华票据池票据签发部分补丁FBM
		//可用余额赋值
		aggvo.getparentVO().setAvailablemoney(aggvo.getparentVO().getMoney());
		aggvo.getparentVO().setTotalavailablemoney(aggvo.getparentVO().getOlcmoney());

		// 取单据编号并设置
		String vbillno = FBMPrivateServiceProxy.getBillcodeManage().getBillCode_RequiresNew(
				registervo.getPk_billtypecode(), registervo.getPk_group(), registervo.getPk_org(), aggvo);
		registervo.setAttributeValue(FbmFieldConstant.VBILLNO, vbillno);
		// 更新数据库
		FbmPrivateUtil.updateAggVO(aggvo, VOStatus.NEW);
		/**
		 * 数字签名
		 */
		FbmSignPubSecurityUtil.signDataAggVO(aggvo);
		// 设置票据状态
		IStatusControlStrategy strategy = new SaveGather((RegisterVO) aggvo.getParentVO(), SaveGather.ADD_ACTION);
		StatusControlProcess.getInstance().process(strategy);

		return FBMPrivateServiceProxy.getGatherQueryService()
				.queryGatherVOByPK(((RegisterVO) aggvo.getParentVO()).getPk_register());
	}

	/**
	 * 检验票据池登记银行承兑银行信息
	 *
	 * @param registervo
	 * @throws BusinessException
	 */
	private void checkBankDoc(RegisterVO registervo) throws BusinessException {
		if (registervo.getSignagrbank() != null && !registervo.getSignagrbank().trim().equals("")) {
			BankdocVO bankdocVOByPk = NCLocator.getInstance().lookup(IBankdocQueryService.class)
					.getBankdocVOByPk(registervo.getSignagrbank());
			if (bankdocVOByPk != null) {
				if (!StringUtil.isNull(bankdocVOByPk.getPcombinenum())) {
					registervo.setSignagrbanknum(bankdocVOByPk.getPcombinenum());
				} else {
					// 2018-12-11 朱三鹏让注释掉，待签收批量生成收票登记的时候，校验直接抛错，为了继续走业务，只是显示，没有业务含义
//        			throw new BusinessException("所选择的承兑银行没有设置人行联行行号");
				}
				if (!StringUtil.isNull(bankdocVOByPk.getPcombinename())) {
					registervo.setSignagrbankname(bankdocVOByPk.getPcombinename());
				} else {
					// 2018-12-11 朱三鹏让注释掉，待签收批量生成收票登记的时候，校验直接抛错，为了继续走业务，只是显示，没有业务含义
//        			throw new BusinessException("所选择的承兑银行没有设置人行联行名称");
				}
			} else {
				throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
						"03618fbm_add02-0323")/* @res "根据所选择的承兑银行找不到相关银行档案" */);
			}
		}
	}

	/**
	 * 删除
	 *
	 * @param aggvo
	 * @throws BusinessException
	 */
	@Override
	public AggRegisterVO deleteGather(AggRegisterVO aggvo) throws BusinessException {
		// xuhrc 20191126 云原生后端saga异常校验
		checkSagaStatus(aggvo);
		RegisterVO registervo = (RegisterVO) aggvo.getParentVO();

		// 删除校验（非自由态单据不能删除）
		Validator deleteValidator = new FbmBaseDeleteValidator();
		IValidationService vService = ValidationFrameworkUtil.createValidationService(deleteValidator);
		vService.validate(aggvo.getParentVO());

		// 有关联关系的单据不能删除
		Validator outerValidator = new GatherOuterValidator();
		IValidationService outerService = ValidationFrameworkUtil.createValidationService(outerValidator);
		outerService.validate(aggvo.getParentVO());

		// 非收票录入或者期初票据的单据不能删除
//		Validator delValidator = new GatherCanoperateValidator();
//		IValidationService delService = ValidationFrameworkUtil.createValidationService(delValidator);
//		delService.validate(aggvo.getParentVO());

		// 设置票据状态
		IStatusControlStrategy strategy = new DeleteGather((RegisterVO) aggvo.getParentVO());
		StatusControlProcess.getInstance().process(strategy);

		// 如果是待签收生成的，需要将状态回退为未生成
		if(FbmBusConstant.GATHER_TYPE_SIGNINPUT.equals(registervo.getGathertype())) {
			NCLocator.getInstance().lookup(IBeforeRegisterManageService.class).undoWhenDeleteGather(registervo);
		}

		// 退单据号
		FBMPrivateServiceProxy.getBillcodeManage().returnBillCodeOnDelete(registervo.getPk_billtypecode(),
				registervo.getPk_group(), registervo.getPk_org(), registervo.getVbillno(), aggvo);
		FBMPrivateServiceProxy.getMDService().deleteBillFromDB(aggvo);

		return aggvo;
	}

	/**
	 * 删除
	 *
	 * @param aggvo
	 * @throws BusinessException
	 */
	@Override
	public AggRegisterVO deleteAutoGatherFromEndore(AggRegisterVO aggvo) throws BusinessException {
		// xuhrc 20191126 云原生后端saga异常校验
		checkSagaStatus(aggvo);
		RegisterVO registervo = (RegisterVO) aggvo.getParentVO();

		// 删除校验（非自由态单据不能删除）
		Validator deleteValidator = new FbmBaseDeleteValidator();
		IValidationService vService = ValidationFrameworkUtil.createValidationService(deleteValidator);
		vService.validate(aggvo.getParentVO());

		// 有关联关系的单据不能删除
		Validator outerValidator = new GatherOuterValidator();
		IValidationService outerService = ValidationFrameworkUtil.createValidationService(outerValidator);
		outerService.validate(aggvo.getParentVO());

//		// 非收票录入或者期初票据的单据不能删除
//		Validator delValidator = new GatherCanoperateValidator();
//		IValidationService delService = ValidationFrameworkUtil.createValidationService(delValidator);
//		delService.validate(aggvo.getParentVO());

		// 设置票据状态
		IStatusControlStrategy strategy = new DeleteGather((RegisterVO) aggvo.getParentVO());
		StatusControlProcess.getInstance().process(strategy);
		// 退单据号
		FBMPrivateServiceProxy.getBillcodeManage().returnBillCodeOnDelete(registervo.getPk_billtypecode(),
				registervo.getPk_group(), registervo.getPk_org(), registervo.getVbillno(), aggvo);
		FBMPrivateServiceProxy.getMDService().deleteBillFromDB(aggvo);

		return aggvo;
	}

	/**
	 * 更新
	 *
	 * @param aggvo
	 * @return AggRegisterVO
	 * @throws BusinessException
	 */
	@Override
	public AggRegisterVO updateGather(AggRegisterVO aggvo) throws BusinessException {
		// xuhrc 20191126 云原生后端saga异常校验
		checkSagaStatus(aggvo);
		RegisterVO registervo = (RegisterVO) aggvo.getParentVO();
		// 轻量级票据保存校验
		Validator gatherSaveValidator = new GatherSaveValidator();
		IValidationService vEcdService = ValidationFrameworkUtil.createValidationService(gatherSaveValidator);
		vEcdService.validate(registervo);

		// 非法票据的校验
		Validator saveIllegalGatherValidator = new SaveIllegalGatherValidator();
		IValidationService vService = ValidationFrameworkUtil.createValidationService(saveIllegalGatherValidator);
		vService.validate(aggvo.getParentVO());

		// begin_luxiong7_20180921_山西正华票据池票据签发部分补丁FBM
		if (registervo.getSignagrbank() != null && !registervo.getSignagrbank().trim().equals("")) {
			BankdocVO bankdocVOByPk = NCLocator.getInstance().lookup(IBankdocQueryService.class)
					.getBankdocVOByPk(registervo.getSignagrbank());
			if (bankdocVOByPk != null) {
				if (bankdocVOByPk.getPcombinenum() != null && !bankdocVOByPk.getPcombinenum().trim().equals("")) {
					registervo.setSignagrbanknum(bankdocVOByPk.getPcombinenum());
				} else {
//        			throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0","03618fbm_add02-0324")/*@res "所选择的承兑银行没有设置人行联行行号"*/);
				}
				if (bankdocVOByPk.getPcombinename() != null && !bankdocVOByPk.getPcombinename().trim().equals("")) {
					registervo.setSignagrbankname(bankdocVOByPk.getPcombinename());
				} else {
//        			throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0","03618fbm_add02-0325")/*@res "所选择的承兑银行没有设置人行联行名称"*/);
				}

			} else {
				throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
						"03618fbm_add02-0323")/* @res "根据所选择的承兑银行找不到相关银行档案" */);
			}
		}
		// end_luxiong7_20180921_山西正华票据池票据签发部分补丁FBM

		AggRegisterVO oldAggVO = (AggRegisterVO) FbmPrivateUtil.queryAggvoByPK(aggvo);
		// 数字验签，验签数据库是否被修改
		if (oldAggVO != null) {
			/**
			 * 对数据库老数据进行数字验签
			 */
			FbmSignPubSecurityUtil.verifySign(oldAggVO, FbmSignPubSecurityUtil.CONST_ACTIONCODE_SAVEUPDATE, false,
					aggvo);
		}

		// 检验票据池登记银行承兑银行信息
		checkBankDoc(registervo);

		// 设置票据状态
		AggRegisterVO oldaggvo = FBMPrivateServiceProxy.getGatherQueryService()
				.queryGatherVOByPK(((RegisterVO) aggvo.getParentVO()).getPk_register());
		IStatusControlStrategy deletestrategy = new DeleteGather((RegisterVO) oldaggvo.getParentVO());// 先删旧数据
		StatusControlProcess.getInstance().process(deletestrategy);
		// 更新数据库
		//可用余额赋值
		aggvo.getparentVO().setAvailablemoney(aggvo.getparentVO().getMoney());
		aggvo.getparentVO().setTotalavailablemoney(aggvo.getparentVO().getOlcmoney());

		AggRegisterVO retvo = (AggRegisterVO) FbmPrivateUtil.updateAggVO(aggvo, VOStatus.UPDATED);
		IStatusControlStrategy strategy = new SaveGather((RegisterVO) retvo.getParentVO(), SaveGather.UPDATE_ACTION);// 再增
		StatusControlProcess.getInstance().process(strategy);

		return FBMPrivateServiceProxy.getGatherQueryService()
				.queryGatherVOByPK(((RegisterVO) aggvo.getParentVO()).getPk_register());
	}

	/**
	 * 弃审
	 *
	 * @param aggvo
	 * @return AggRegisterVO
	 * @throws BusinessException
	 */
	@Override
	public AggRegisterVO unApproveGather(AggRegisterVO aggvo, boolean isEndStep, UFDate tallydate)
			throws BusinessException {
		// xuhrc 20191126 云原生后端saga异常校验
		checkSagaStatus(aggvo);
		// 推式生成单据如果已经审批不能取消审批 shigy 20110301
//		Validator unApproveValidator = new GatherCancelApproveValidator();
//		IValidationService vService = ValidationFrameworkUtil.createValidationService(unApproveValidator);
//		vService.validate(aggvo.getParentVO());

		// 有关联关系的单据不能取消审批
		Validator outerValidator = new GatherOuterValidator();
		IValidationService outerService = ValidationFrameworkUtil.createValidationService(outerValidator);
		outerService.validate(aggvo.getParentVO());

		// 已签收的票据不能取消审批
		RegisterVO parentVO = aggvo.getparentVO();
		if (parentVO != null && parentVO.getSfflag() == UFBoolean.TRUE) {
			throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0",
					"03618fbm-1042")/* @res "已签收的票据不能取消审批！" */);
		}
		// 已发送指令的不能取消审批
		if(parentVO.getElcpaymentstatus() != null) {			
			throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
					.getStrByID("3618fbm_add02_0", "03618fbm_add02-0220")/* @res "已向银行发送指令，不允许取消审批！" */);
		}

		// 更新数据库
		FbmPrivateUtil.updateAggVO(aggvo, VOStatus.UPDATED);

		RegisterVO revo = (RegisterVO) aggvo.getParent();

		// 单据状态为自由态时才能维护堆栈
		if (isEndStep) {
			// 设置票据状态
			IStatusControlStrategy strategy = new CancelAuditGather((RegisterVO) aggvo.getParentVO());
			StatusControlProcess.getInstance().process(strategy);

			// 期初登记票据期初
			if (revo.getSfflag() != null && revo.getSfflag().booleanValue()
					&& (revo.getInitflag() == null || !revo.getInitflag().booleanValue())) {
				// 删掉票据帐
				GatherBillAccAdapter billAdapter = new GatherBillAccAdapter();
				billAdapter.deleteBillAcc(aggvo, tallydate);
			}

			// 期初登记票据期初
			if (revo.getInitflag() != null && revo.getInitflag().booleanValue()) {
				if (FbmPublicUtil.isCMPInitDateEnable(revo.getPk_group(),revo.getPk_org())) {
					IOriBalanceService balser = FBMPublicServiceProxy.getOriBalanceService();
					balser.insertNote(init2OriginalBalanceVO(aggvo, "DEL"));
				}
			}
		}
		return FBMPrivateServiceProxy.getGatherQueryService()
				.queryGatherVOByPK(((RegisterVO) aggvo.getParentVO()).getPk_register());
	}

	/**
	 * 审批
	 *
	 * @param aggvo
	 * @return AggRegisterVO
	 * @throws BusinessException
	 */
	@Override
	public AggRegisterVO approveGather(AggRegisterVO aggvo, boolean isEndStep) throws BusinessException {
		// xuhrc 20191126 云原生后端saga异常校验
		checkSagaStatus(aggvo);
		// 如果是保存及审批，vo没有审批日期
		if (((RegisterVO) aggvo.getParentVO()).getDapprovedate() == null) {
			((RegisterVO) aggvo.getParentVO()).setDapprovedate(((RegisterVO) aggvo.getParentVO()).getDoperatedate());
		}
		// 审批日期必须晚于等于制单日期 modify by aishm 2013-03-27
		if (aggvo.getparentVO().getDapprovedate() != null
				&& aggvo.getparentVO().getDapprovedate().beforeDate(aggvo.getparentVO().getDoperatedate()) ) {
			throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0",
					"03618fbm-1025")/* @res "审批日期必须晚于等于制单日期！" */);
		}

//		// 推式生成单据不能审批
//		Validator approveValidator = new GatherCanoperateValidator();
//		IValidationService approveService = ValidationFrameworkUtil.createValidationService(approveValidator);
//		approveService.validate(aggvo.getParentVO());
//
		// 有关联关系的单据不能审批
		Validator outerValidator = new GatherOuterValidator();
		IValidationService vService = ValidationFrameworkUtil.createValidationService(outerValidator);
		vService.validate(aggvo.getParentVO());

		// 更新数据库
		FbmPrivateUtil.updateAggVO(aggvo, VOStatus.UPDATED);

		RegisterVO revo = (RegisterVO) aggvo.getParent();
		String pk_org = revo.getPk_org();

		// 只有审批通过才处理堆栈
		if (isEndStep) {
			// 设置票据状态
			IStatusControlStrategy strategy = new AuditGather((RegisterVO) aggvo.getParentVO());
			StatusControlProcess.getInstance().process(strategy);

//			if(revo.getCyberbankflag() != null && revo.getCyberbankflag().booleanValue()){
			// 单位票据池需要进行验签
			FbmSignPubSecurityUtil.verifySign(aggvo, FbmSignPubSecurityUtil.CONST_ACTIONCODE_APPROVE, false, null);
//			}

			// 如果已收票，登记票据帐,期初不登记票据帐
			if ((revo.getSfflag() != null && revo.getSfflag().booleanValue())
					&& (revo.getInitflag() == null || !revo.getInitflag().booleanValue())) {
				GatherBillAccAdapter billAdapter = new GatherBillAccAdapter();
				billAdapter.writeBillAcc(aggvo);
				// ydx自动制证
				if (FbmPublicUtil.isAutoVoucher(pk_org)) {
					FBMPrivateServiceProxy.getGatherManageService().voucherGatherVO(aggvo);
				}
			}

			// 期初登记票据期初
			if (revo.getInitflag() != null && revo.getInitflag().booleanValue()) {
				if (FbmPublicUtil.isCMPInitDateEnable(revo.getPk_group(),revo.getPk_org())) {
					IOriBalanceService balser = FBMPublicServiceProxy.getOriBalanceService();
					balser.insertNote(init2OriginalBalanceVO(aggvo, "ADD"));
				}
			}
		}
		return FBMPrivateServiceProxy.getGatherQueryService()
				.queryGatherVOByPK(((RegisterVO) aggvo.getParentVO()).getPk_register());
	}

	private OriginalBalanceVO[] init2OriginalBalanceVO(AggRegisterVO aggvo, String operate) {
		RegisterVO resvo = (RegisterVO) aggvo.getParentVO();
		OriginalBalanceVO vo = new OriginalBalanceVO();
		vo.setAcctype(IBankAccConstant.ACCTYPE_BILL);
		// NCdp204576522 写期初余额的复核日期修改为收票日期 modify by aishm 2013-06-06
		vo.setApprovedate(resvo.getGatherdate() == null ? new UFLiteralDate((new UFDate()).toString())
				: new UFLiteralDate(resvo.getGatherdate().toString()));
		vo.setApprovetime(
				resvo.getGatherdate() == null ? new UFDateTime() : new UFDateTime(resvo.getGatherdate().toString()));
		vo.setApprover(resvo.getApprover());
		vo.setCreationtime(resvo.getApprovetime());
		vo.setCreator(resvo.getApprover());

		vo.setFormcode(CmpConst.BILL_RECDEPOSIT);

		vo.setModifiedtime(resvo.getApprovetime());
		vo.setModifier(resvo.getApprover());
		vo.setPk_account(CmpConst.BILL_RECDEPOSIT + "");
		vo.setPk_currtype(resvo.getPk_curr());
		vo.setPk_group(resvo.getPk_group());
		vo.setPk_notetype(resvo.getFbmbilltype());
		vo.setPk_org(resvo.getPk_org());
		vo.setPk_org_v(resvo.getPk_org_v());

		if ("DEL".equalsIgnoreCase(operate)) {
			vo.setGlobalinit_local(
					resvo.getGllcmoney() == null ? UFDouble.ZERO_DBL : UFDouble.ZERO_DBL.sub(resvo.getGllcmoney()));
			vo.setGroupinit_local(
					resvo.getGlcmoney() == null ? UFDouble.ZERO_DBL : UFDouble.ZERO_DBL.sub(resvo.getGlcmoney()));
			vo.setInit_local(
					resvo.getOlcmoney() == null ? UFDouble.ZERO_DBL : UFDouble.ZERO_DBL.sub(resvo.getOlcmoney()));
			vo.setInit_primal(UFDouble.ZERO_DBL.sub(resvo.getMoney()));
			vo.setCurrent_local(
					resvo.getOlcmoney() == null ? UFDouble.ZERO_DBL : UFDouble.ZERO_DBL.sub(resvo.getOlcmoney()));
			vo.setCurrent_primal(UFDouble.ZERO_DBL.sub(resvo.getMoney()));
			vo.setGlobalcurrent_local(
					resvo.getGllcmoney() == null ? UFDouble.ZERO_DBL : UFDouble.ZERO_DBL.sub(resvo.getGllcmoney()));
			vo.setGlobalrealtime_local(
					resvo.getGllcmoney() == null ? UFDouble.ZERO_DBL : UFDouble.ZERO_DBL.sub(resvo.getGllcmoney()));
			vo.setGrouprealtime_local(
					resvo.getGlcmoney() == null ? UFDouble.ZERO_DBL : UFDouble.ZERO_DBL.sub(resvo.getGlcmoney()));
			vo.setGroupcurrent_local(
					resvo.getGlcmoney() == null ? UFDouble.ZERO_DBL : UFDouble.ZERO_DBL.sub(resvo.getGlcmoney()));
			vo.setRealtime_local(
					resvo.getOlcmoney() == null ? UFDouble.ZERO_DBL : UFDouble.ZERO_DBL.sub(resvo.getOlcmoney()));
			vo.setRealtime_primal(UFDouble.ZERO_DBL.sub(resvo.getMoney()));
		} else {
			vo.setGlobalinit_local(resvo.getGllcmoney() == null ? UFDouble.ZERO_DBL : resvo.getGllcmoney());
			vo.setGroupinit_local(resvo.getGlcmoney() == null ? UFDouble.ZERO_DBL : resvo.getGlcmoney());
			vo.setInit_local(resvo.getOlcmoney() == null ? UFDouble.ZERO_DBL : resvo.getOlcmoney());
			vo.setInit_primal(resvo.getMoney());
			vo.setCurrent_local(resvo.getOlcmoney() == null ? UFDouble.ZERO_DBL : resvo.getOlcmoney());
			vo.setCurrent_primal(resvo.getMoney());
			vo.setGlobalcurrent_local(resvo.getGllcmoney() == null ? UFDouble.ZERO_DBL : resvo.getGllcmoney());
			vo.setGlobalrealtime_local(resvo.getGllcmoney() == null ? UFDouble.ZERO_DBL : resvo.getGllcmoney());
			vo.setGrouprealtime_local(resvo.getGlcmoney() == null ? UFDouble.ZERO_DBL : resvo.getGlcmoney());
			vo.setGroupcurrent_local(resvo.getGlcmoney() == null ? UFDouble.ZERO_DBL : resvo.getGlcmoney());
			vo.setRealtime_local(resvo.getOlcmoney() == null ? UFDouble.ZERO_DBL : resvo.getOlcmoney());
			vo.setRealtime_primal(resvo.getMoney());
		}
		return new OriginalBalanceVO[] { vo };
	}

	/**
	 * 收票登记批量银行托收
	 *
	 * @param registerList
	 * @throws BusinessException
	 */
	@Override
	public void batchConsignBank(List<AggRegisterVO> registerList) throws BusinessException {
		return;
	}

	/**
	 * 收票登记批量贴现
	 *
	 * @param registerList
	 * @throws BusinessException
	 */
	@Override
	public void batchDiscount(List<AggRegisterVO> registerList) throws BusinessException {
		return;
	}

	/**
	 * 收票登记批量质押
	 *
	 * @param registerList
	 * @throws BusinessException
	 */
	@Override
	public void batchImpawn(List<AggRegisterVO> registerList) throws BusinessException {
		return;
	}

	/**
	 * 收票登记取消收票
	 *
	 * @param registervo
	 * @throws BusinessException
	 */
	@Override
	public AggRegisterVO cancleGather(AggRegisterVO aggvo) throws BusinessException {
		// xuhrc 20191126 云原生后端saga异常校验
		checkSagaStatus(aggvo);
		RegisterVO regvo = (RegisterVO) aggvo.getParentVO();
		// 加票据号锁
		FbmPublicUtil.lockFbmbillno(new String[] { regvo.getFbmbillno() });

		// 集成应用校验
		//Validator integratedValidator = new FbmCheckIntegratedValidator();
		// 调用校验
//		Validator dateValidator = new GatherRecieveCancelValidator();
//		IValidationService integratedValidatorService = ValidationFrameworkUtil.createValidationService(integratedValidator);
//		IValidationService dateValidatorService = ValidationFrameworkUtil.createValidationService(dateValidator);

		// begin-wangsh7-20191129-签收集成校验问题
		/**
		 * 收款单参照sql部分截取 ((isnull(sfflag, 'N') = 'Y' and isnull(onlinebankflag, 'N') =
		 * 'Y') or (isnull(sfflag, 'N') = 'N' and isnull(onlinebankflag, 'N') = 'N')))))
		 *
		 * 由此可见如果是网银指令的，才会参照已经签收完成，即已经指令成功的，如果不发指令，参照的是还未签收的，因此电票类型也要被校验住，
		 * 而且以前的校验是不对的，判断电票是要查询票据所属的大类才行
		 */
		// begin_luxiong7_20181214_电票收票完成后才能关联功能，不需要此校验
//				String fbmbilltype = regvo.getFbmbilltype();
//				if (fbmbilltype.equals(FbmBusConstant.PKNOTETYPE_BANK) || fbmbilltype.equals(FbmBusConstant.PKNOTETYPE_BUSI)) {
//					vService.validate(regvo);
//				}
		// 为同名背书的收票登记做处理
		if (regvo.getSelfendore() != null && regvo.getSelfendore().booleanValue()) {
			// 同名背书不需要集成校验
		} else {
			// 非同名背书,正常校验
//			if (regvo.getOnlinebankflag() == null || !regvo.getOnlinebankflag().booleanValue()) {
//				integratedValidatorService.validate(regvo);
//				dateValidatorService.validate(regvo);
//			}
			// 有关联关系校验
			Validator outerValidator = new GatherOuterValidator();
			IValidationService outerService = ValidationFrameworkUtil.createValidationService(outerValidator);
			outerService.validate(aggvo.getParentVO());
		}
		// end_luxiong7_20181214_电票收票完成后才能关联功能，不需要此校验
		// end-wangsh7-20191129-签收集成校验问题

		// ydx:付款排程已经预订的票据不能取消审批 付款排程已经执行占用的票据不能取消审批
		if (regvo.getBookflag() != null && regvo.getBookflag().booleanValue()) {
			throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0",
					"03618fbm-0717")/* @res "付款排程已经预订的票据不能取消收票" */);
		}
		if (regvo.getPlanflag() != null && regvo.getPlanflag().booleanValue()) {
			throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0",
					"03618fbm-0718")/* @res "付款排程已经执行占用的票据不能取消收票" */);
		}

		// 如果最新票据动作栈记录不是已收票 一定有其他后续处理
		ActionQueryServiceImpl actionQueryService = new ActionQueryServiceImpl();
		ActionVO actionVo = actionQueryService.queryNewestActionByPKRegister(regvo.getPk_register());
		if (null != actionVo && !RegisterStatusConstant.REGISTER.equals(actionVo.getEndstatus())) {
			throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0",
					"03618fbm-1060", null, new String[] { regvo.getFbmbillno() }/* @res "票据{0}的前一操作必须是已登記的數據。" */));
		}

		// 已收票标志位置为false
		regvo.setSfflag(UFBoolean.FALSE);
		//收票登记取消签收,def1设置为空
		regvo.setDef1(null);
		//清空签收人、签收日期
		aggvo.getparentVO().setSigner(null);
		aggvo.getparentVO().setSigndate(null);
		// 删除票据帐
		GatherBillAccAdapter billAdapter = new GatherBillAccAdapter();
		billAdapter.deleteBillAcc(aggvo, regvo.getGatherdate());

		// 更新数据库并返回VO
		aggvo = (AggRegisterVO) FbmPrivateUtil.updateAggVO(aggvo, VOStatus.UPDATED);

		// begin_luxiong7_20181213_取消收票后自动删除占用费计算单据(centeroccupyct_config)
		deleteCenterVO(aggvo);
		// end_luxiong7_20181213_取消收票后自动删除占用费计算单据(centeroccupyct_config)

		// 调用票据上收进行取消收票
		// 202206版本 20211109 校验是否票据上收 如果是的话就做票据上收取消签收操作
		processBillDeliveryAllocate(regvo, false);
		return aggvo;
	}

	/**
	 * 收票登记收票完成
	 *
	 * @param registervo
	 * @return RegisterVO
	 * @throws BusinessException
	 */
	@Override
	public AggRegisterVO completeGather_RequiresNew(AggRegisterVO aggvo) throws BusinessException {
		// xuhrc 20191126 云原生后端saga异常校验
		checkSagaStatus(aggvo);
		RegisterVO regvo = (RegisterVO) aggvo.getParentVO();
		// 加票据号锁
		FbmPublicUtil.lockFbmbillno(new String[] { regvo.getFbmbillno() });

		String pk_org = regvo.getPk_org();
		// 状态校验
		Validator dateValidator = new GatherRecieveCompleteValidator();
		IValidationService dService = ValidationFrameworkUtil.createValidationService(dateValidator);
		dService.validate(regvo);
		// 集成应用校验
//		Validator integratedValidator = new FbmCheckIntegratedValidator();
//		IValidationService vService = ValidationFrameworkUtil.createValidationService(integratedValidator);
		// begin-wangsh7-20191129-签收集成校验问题-NCdp206226432
		/**
		 * 收款单参照sql部分截取 ((isnull(sfflag, 'N') = 'Y' and isnull(onlinebankflag, 'N') =
		 * 'Y') or (isnull(sfflag, 'N') = 'N' and isnull(onlinebankflag, 'N') = 'N')))))
		 *
		 * 由此可见如果是网银指令的，才会参照已经签收完成，即已经指令成功的，如果不发指令，参照的是还未签收的，因此电票类型也要被校验住，
		 * 而且以前的校验是不对的，判断电票是要查询票据所属的大类才行
		 */
		// begin_luxiong7_20181214_电票收票完成后才能关联功能，不需要此校验
//		String fbmbilltype = regvo.getFbmbilltype();
//		if (fbmbilltype.equals(FbmBusConstant.PKNOTETYPE_BANK) || fbmbilltype.equals(FbmBusConstant.PKNOTETYPE_BUSI)) {
//			vService.validate(regvo);
//		}
		// 为同名背书的收票登记做处理
		if (regvo.getSelfendore() != null && regvo.getSelfendore().booleanValue()) {
			// 同名背书不需要集成校验
		} else {
			// 非同名背书,正常校验
//			if (regvo.getOnlinebankflag() == null || !regvo.getOnlinebankflag().booleanValue()) {
//				vService.validate(regvo);
//			}
			// 有关联关系校验
			Validator outerValidator = new GatherOuterValidator();
			IValidationService outerService = ValidationFrameworkUtil.createValidationService(outerValidator);
			outerService.validate(aggvo.getParentVO());
		}
		// end_luxiong7_20181214_电票收票完成后才能关联功能，不需要此校验
		// end-wangsh7-20191129-签收集成校验问题-NCdp206226432

		// 已收票标志位置为false
		regvo.setSfflag(UFBoolean.TRUE);
		//代表是在收票登记签收的
		regvo.setDef1("Y");
		//回写签收人、签收日期
		aggvo.getparentVO().setSigner(AppContext.getInstance().getPkUser());
		aggvo.getparentVO().setSigndate(AppContext.getInstance().getBusiDate());

//		if(regvo.getCyberbankflag() != null && regvo.getCyberbankflag().booleanValue()){
		// 单位票据池需要进行验签
		FbmSignPubSecurityUtil.verifySign(aggvo, FbmSignPubSecurityUtil.CONST_ACTIONCODE_RECIEVECOMPLETE, false, null);
//		}

		// 登记票据帐
		if (!regvo.getInitflag().booleanValue()) {
			GatherBillAccAdapter billAdapter = new GatherBillAccAdapter();
			billAdapter.writeBillAcc(aggvo);
			// ydx自动制证
			if (FbmPublicUtil.isAutoVoucher(pk_org)) {
				FBMPrivateServiceProxy.getGatherManageService().voucherGatherVO(aggvo);
			}
		}
		((RegisterVO) aggvo.getParentVO()).setSfflag(UFBoolean.TRUE);
		aggvo = (AggRegisterVO) FbmPrivateUtil.updateAggVO(aggvo, VOStatus.UPDATED);

		// begin_wusib_20190726_原有逻辑入池后才计费，不知道当时是什么原因加这个逻辑，与需求赵伟刚确认先注释。
		// begin_luxiong7_20181115_收票完成后自动生成占用费计算单据(centeroccupyct_config)
//		insertCenterVO(aggvo);
		// end_luxiong7_20181115_收票完成后自动生成占用费计算单据
		// end_wusib_20190726_原有逻辑入池后才计费，不知道当时是什么原因加这个逻辑，与需求赵伟刚确认先注释。
		// 更新数据库并返回VO

		// 202206版本 20211109 校验是否票据上收 如果是的话就做票据上收成功和下拨操作
		processBillDeliveryAllocate(regvo, true);
		return aggvo;
	}

	/**
	 * 收票登记收票完成，不进行状态控制以及集成判断等
	 *
	 * @param registervo
	 * @return RegisterVO
	 * @throws BusinessException
	 */
	@Override
	public AggRegisterVO completeGatherWithOutControl(AggRegisterVO aggvo) throws BusinessException {
		// modified by wangsh7 集成时已将票据的saga校验前移，回退时不需要saga校验 begin
		// xuhrc 20191126 云原生后端saga异常校验
//		checkSagaStatus(aggvo);
		// modified by wangsh7 集成时已将票据的saga校验前移，回退时不需要saga校验 end
		// 登记票据帐
		GatherBillAccAdapter billAdapter = new GatherBillAccAdapter();
		billAdapter.writeBillAcc(aggvo);
		//回写签收人、签收日期
		RegisterVO registerVO = aggvo.getparentVO();
		registerVO.setSigner(AppContext.getInstance().getPkUser());
		registerVO.setSigndate(AppContext.getInstance().getBusiDate());
		// 更新数据库并返回VO
		aggvo = (AggRegisterVO) FbmPrivateUtil.updateAggVO(aggvo, VOStatus.UPDATED);
		// 202206版本 20211109 校验是否票据上收 如果是的话就做票据上收成功和下拨操作
		processBillDeliveryAllocate(registerVO, true);
		return aggvo;
	}

	/**
	 * 收票登记取消收票，不进行状态控制以及集成判断等
	 *
	 * @param registervo
	 * @throws BusinessException
	 */
	@Override
	public AggRegisterVO cancleGatherWithOutControl(AggRegisterVO aggvo) throws BusinessException {
		// modified by wangsh7 集成时已将票据的saga校验前移，回退时不需要saga校验 begin
		// xuhrc 20191126 云原生后端saga异常校验
//		checkSagaStatus(aggvo);
		// modified by wangsh7 集成时已将票据的saga校验前移，回退时不需要saga校验 end
		// 删除票据帐
		GatherBillAccAdapter billAdapter = new GatherBillAccAdapter();
		RegisterVO registerVO = aggvo.getparentVO();
		billAdapter.deleteBillAcc(aggvo, registerVO.getGatherdate());
		//清空签收人、签收日期
		registerVO.setSigner(null);
		registerVO.setSigndate(null);
		// 更新数据库并返回VO
		aggvo = (AggRegisterVO) FbmPrivateUtil.updateAggVO(aggvo, VOStatus.UPDATED);
		// 202206版本 20211109 校验是否票据上收 如果是的话就做票据上收成功和下拨操作
		processBillDeliveryAllocate(registerVO, false);
		return aggvo;
	}

	/**
	 * 收票登记取消制证
	 *
	 * @param registervo
	 * @return AggRegisterVO
	 * @throws BusinessException
	 */
	@Override
	public AggRegisterVO cancelVoucherGatherVO(AggRegisterVO aggvo) throws BusinessException {
		// xuhrc 20191126 云原生后端saga异常校验
		checkSagaStatus(aggvo);
		RegisterVO regvo = aggvo.getparentVO();
		if (regvo.getSelfendore() != null && regvo.getSelfendore().booleanValue()) {
			// 同名背书不需要校验，可以直接制证
		} else {
			IOuterQueryService outerqryservice = NCLocator.getInstance().lookup(IOuterQueryService.class);
			OuterVO[] vos = outerqryservice.queryOuterVOsByPk_busibill(regvo.getPk_register());
			if (ArrayUtils.isNotEmpty(vos)) {
				//该单据已被集成收款业务引用，不能取消制证
				throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0", "03618fbm-1131"));
			}
		}
		// begin 云原生取消凭证冻结业务单据修改人wangdengk
		GatherSagaInfoAdapter sagaAdapter = new GatherSagaInfoAdapter();
		SagasFrozenProcessor.process(sagaAdapter, aggvo);
		// end
		// 更新数据库并返回VO
		BaseVoucherUtil.sendDAPMessge_del(aggvo);
		return (AggRegisterVO) FbmPrivateUtil.queryAggvoByPK(aggvo);
	}

	/**
	 * 收票登记制证
	 *
	 * @param registervo
	 * @return AggRegisterVO
	 * @throws BusinessException
	 */
	@Override
	public AggRegisterVO voucherGatherVO(AggRegisterVO aggvo) throws BusinessException {
		// xuhrc 20191126 云原生后端saga异常校验
		checkSagaStatus(aggvo);
		RegisterVO regvo = aggvo.getparentVO();
		if (regvo.getSelfendore() != null && regvo.getSelfendore().booleanValue()) {
			// 同名背书不需要校验，可以直接制证
		} else if (null == regvo.getDef7() || !FbmBusConstant.SYSTEM_API.equals(regvo.getDef7())) {//api过来的数据不需要校验集成
			// 是否集成应用
			String msg = FbmPublicUtil.isTogatherWithCmpArApFts(regvo.getPk_org());
			if (StringUtil.isNotNull(msg)) {
				// 集成使用时，收票登记不能独立制证，可在使用票据收款的业务制证
				throw new BusinessException(
						nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0", "03618fbm-1124"));
			}
			IOuterQueryService outerqryservice = NCLocator.getInstance().lookup(IOuterQueryService.class);
			OuterVO[] vos = outerqryservice.queryOuterVOsByPk_busibill(regvo.getPk_register());
			if (ArrayUtils.isNotEmpty(vos)) {
				// 该单据已被集成收款业务引用，不能制证
				throw new BusinessException(
						nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0", "03618fbm-1125"));
			}
		}
		// begin 云原生取消凭证冻结业务单据修改人wangdengk
		GatherSagaInfoAdapter sagaAdapter = new GatherSagaInfoAdapter();
		SagasFrozenProcessor.process(sagaAdapter, aggvo);
		// end
		// 制证日期取右上角业务日期
		regvo.setDvoucherdate(AppContext.getInstance().getBusiDate());
		// 更新数据库并返回VO
		BaseVoucherUtil.sendDAPMessge(aggvo);
		return (AggRegisterVO) FbmPrivateUtil.queryAggvoByPK(aggvo);
	}

	/**
	 * 新增并审批收票登记单
	 */
	@Override
	public void insertAndApproveGather(AggRegisterVO[] aggvos) throws BusinessException {
		if (aggvos != null && aggvos.length != 0) {
			IOrgUnitPubService_C oups = NCLocator.getInstance().lookup(IOrgUnitPubService_C.class);
			String initDateNY = null;
			RegisterVO registervo = null;
			String vbillno = null;
			for (AggRegisterVO aggvo : aggvos) {
				registervo = (RegisterVO) aggvo.getParentVO();
				initDateNY = oups.getOrgModulePeriodByOrgIDAndModuleID(registervo.getPk_org(),
						FbmBusConstant.PRODUCT_FBM_FUNCODE);
				if (StringUtil.isNull(initDateNY)) {
					throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0",
							"03618fbm-0719")/* @res "收票单位的期初期间没有启用，请通知收票单位启用期初期间。" */);
				}
				// 期初日期格式有两种：2010-01-01和2010-01
				if (initDateNY.length() == 7) {
					initDateNY = initDateNY + "-01";
				}
				if (registervo.getGatherdate().before(new UFDate(initDateNY))) {
					throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0",
							"03618fbm-0720")/* @res "收票日期应晚于收票单位的期初期间" */);
				}

				// 将隐藏项值设置到对应字段 modify by aishm 2012-07-24
				FbmHideFieldUtil.setHideField(registervo,
						new String[][] { { RegisterVO.HIDEPAYUNIT, RegisterVO.PAYUNIT, FbmHideFieldUtil.CUST },
								{ RegisterVO.HIDEPAYBANK, RegisterVO.PAYBANK, FbmHideFieldUtil.BANKDOC },
								{ RegisterVO.HIDEPAYBANKACC, RegisterVO.PAYBANKACC, FbmHideFieldUtil.BANKACC },
								{ RegisterVO.HIDERECEIVEUNIT, RegisterVO.RECEIVEUNIT, FbmHideFieldUtil.CUST },
								{ RegisterVO.HIDERECEIVEBANK, RegisterVO.RECEIVEBANK, FbmHideFieldUtil.BANKDOC },
								{ RegisterVO.HIDERECEIVEBANKACC, RegisterVO.RECEIVEBANKACC, FbmHideFieldUtil.BANKACC },
								{ RegisterVO.INVOICEUNIT, RegisterVO.INVOICEUNITNAME, FbmHideFieldUtil.CUST } });

				// 取单据编号并设置
				vbillno = FBMPrivateServiceProxy.getBillcodeManage().getBillCode_RequiresNew(
						registervo.getPk_billtypecode(), registervo.getPk_group(), registervo.getPk_org(), aggvo);
				registervo.setAttributeValue(FbmFieldConstant.VBILLNO, vbillno);
				// 更新数据库
				FbmPrivateUtil.updateAggVO(aggvo, VOStatus.NEW);
				/**
				 * 数字签名
				 */
				FbmSignPubSecurityUtil.signDataAggVO(aggvo);
				// 新增时设置票据状态
				IStatusControlStrategy insertgather = new SaveGather((RegisterVO) aggvo.getParentVO(), false);
				StatusControlProcess.getInstance().process(insertgather);
				// 审批时设置票据状态
				IStatusControlStrategy approvegather = new AuditGather((RegisterVO) aggvo.getParentVO(), false);
				StatusControlProcess.getInstance().process(approvegather);

				// 如果生成的是废票，则设置废票票据状态 for V6.1 modify by aishm 2012-02-22
				if (aggvo.getparentVO().getDisableflag() != null
						&& aggvo.getparentVO().getDisableflag().booleanValue()) {
					AggRegisterVO aggregvo = FBMPrivateServiceProxy.getGatherQueryService()
							.queryGatherVOByPK(aggvo.getparentVO().getPk_register());
					IStatusControlStrategy disablegather = new DisableGather(aggregvo.getparentVO(), false);
					StatusControlProcess.getInstance().process(disablegather);
				}

				// 如果已收票，登记票据帐
				if (registervo.getSfflag() != null && registervo.getSfflag().booleanValue()) {
					GatherBillAccAdapter billAdapter = new GatherBillAccAdapter();
					billAdapter.writeBillAcc(aggvo);
					// ydx自动制证
					if (FbmPublicUtil.isAutoVoucher(registervo.getPk_org())) {
						FBMPrivateServiceProxy.getGatherManageService().voucherGatherVO(aggvo);
					}
					/**
					 * V6.1不再预算控制 modify by aishm 2012-04-11
					 */
//					(aggvo).getParentVO().setAttributeValue("haspassedntbcheck", UFBoolean.TRUE);
//					(aggvo).getParentVO().setAttributeValue("tbbmessage", FbmTbbCommonUtil.controlNtb(aggvo, false,new UFDate(), FbmTbbCommonUtil.UFIND));
				}
			}
		}
	}

	/**
	 * 弃审并删除收票登记单
	 */
	@Override
	public void unapproveAndDeleteGather(AggRegisterVO[] aggvos) throws BusinessException {
		// xuhrc 20191126 云原生后端saga异常校验
		checkSagaStatus(aggvos);
		if (aggvos != null && aggvos.length != 0) {
			for (AggRegisterVO aggvo : aggvos) {
				RegisterVO registervo = aggvo.getparentVO();
				// 删除票据帐
				if (aggvo.getparentVO().getSfflag() != null && aggvo.getparentVO().getSfflag().booleanValue()) {
					GatherBillAccAdapter billAdapter = new GatherBillAccAdapter();
					billAdapter.deleteBillAcc(aggvo, registervo.getGatherdate());
				}

				// 如果生成的是废票，则删除废票票据状态 for V6.1 modify by aishm 2012-02-22
				if (aggvo.getparentVO().getDisableflag() != null
						&& aggvo.getparentVO().getDisableflag().booleanValue()) {
					IStatusControlStrategy disablegather = new CancelDisableGather(aggvo.getparentVO(), false);
					StatusControlProcess.getInstance().process(disablegather);
				}

				// 弃审状态控制
				IStatusControlStrategy cancelaudit = new CancelAuditGather((RegisterVO) aggvo.getParentVO(), false);
				StatusControlProcess.getInstance().process(cancelaudit);
				// 删除状态控制
				IStatusControlStrategy deletegather = new DeleteGather((RegisterVO) aggvo.getParentVO(), false);
				StatusControlProcess.getInstance().process(deletegather);

				// 删除校验
				if (registervo.getVoucher() != null && registervo.getVoucher().equals(UFBoolean.TRUE)) {
					throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0",
							"03618fbm-1002")/* @res "生成的收票登记单已制证，不能反操作" */);
				}

				// 退单据号
				FBMPrivateServiceProxy.getBillcodeManage().returnBillCodeOnDelete(registervo.getPk_billtypecode(),
						registervo.getPk_group(), registervo.getPk_org(), registervo.getVbillno(), aggvo);

				// 删除收票登记单
				FBMPrivateServiceProxy.getMDService().deleteBill(aggvo);
			}
		}
	}

	/**
	 * 资金组织端确认内部托管单或者内部领用单时，如果是调剂托管，则生成资金组织端的收票登记单
	 *
	 * @param aggvos
	 * @throws BusinessException
	 */
	@Override
	public void insertGatherFromFund(AggRegisterVO[] aggvos) throws BusinessException {
		// xuhrc 20191126 云原生后端saga异常校验
		checkSagaStatus(aggvos);
		if (aggvos != null && aggvos.length != 0) {
			insertAndApproveGather(aggvos);
		}
	}

	/**
	 * 资金组织端取消确认内部托管单或者内部领用单时，如果是调剂托管，则删除资金组织端的收票登记单
	 *
	 * @param pk_parent
	 * @throws BusinessException
	 */
	@Override
	public void deleteGatherFromFund(String pk_parent) throws BusinessException {
		if (!StringUtil.isNull(pk_parent)) {
			try {
				AggRegisterVO[] aggvos = FBMPrivateServiceProxy.getGatherQueryService()
						.queryGatherVOByWhereSql("pk_parent = '" + NCESAPI.sqlEncode(pk_parent) + "'");
				if (aggvos != null && aggvos.length != 0) {
					unapproveAndDeleteGather(aggvos);
				}
			} catch (Exception e) {
				Logger.error(e.getMessage(), e);
				throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0",
						"03618fbm-0721")/* @res "删除资金组织端的收票登记单时异常！" */);
			}
		} else {
			return;
		}
	}

	@Override
	public void cancelDisableGather(String pk_register) throws BusinessException {
		updateDisableFlag(pk_register, "N");
	}

	@Override
	public void disableGather(String pk_register) throws BusinessException {
		updateDisableFlag(pk_register, "Y");
	}

	private void updateDisableFlag(String pk_register, String flag) throws DAOException {
		BaseDAO dao = new BaseDAO();
		String sql = "update fbm_register set disableflag='" + NCESAPI.sqlEncode(flag) + "' where pk_register='"
				+ NCESAPI.sqlEncode(pk_register) + "'";
		dao.executeUpdate(sql);
	}

	/**
	 * 更新收票登记单的托管组织
	 *
	 * @param pk_registers
	 * @param pk_keeporg
	 * @throws BusinessException
	 */
	@Override
	public void updateGatherKeepOrg(String[] pk_registers, String pk_keeporg) throws BusinessException {
		if (pk_registers != null && pk_registers.length != 0) {
			BaseDAO basedao = new BaseDAO();
			String wheresql = FbmSqlUtils.getInStr("pk_register", pk_registers, true);
			String sql = "update fbm_register set pk_keeporg = '" + NCESAPI.sqlEncode(pk_keeporg) + "' where "
					+ wheresql;
			basedao.executeUpdate(sql);
		}
	}

	@Override
	public void updateReturnRecord(String[] pk_registers, String returnrecord) throws BusinessException {
		if (pk_registers != null && pk_registers.length != 0) {
			BaseDAO dao = new BaseDAO();
			String wheresql = FbmSqlUtils.getInStr("pk_register", pk_registers, true);
			String sql = "update fbm_register set returnrecord = '" + NCESAPI.sqlEncode(returnrecord) + "' where "
					+ wheresql;
			dao.executeUpdate(sql);
		}
	}

	@Override
	public AggRegisterVO DestroyGather(String pk_register, UFDate desDate, String pk_desman) throws BusinessException {
		IGatherQueryService que = FBMPrivateServiceProxy.getGatherQueryService();
		AggRegisterVO aggvo = que.queryGatherVOByPK(pk_register);
		RegisterVO revo = (RegisterVO) aggvo.getParent();
		// 更新核销信息
		revo.setVerifydate(desDate);
		revo.setVerifyman(pk_desman);
		revo.setIsverify(UFBoolean.TRUE);
		revo.setDisableflag(UFBoolean.TRUE);
		aggvo.setParent(revo);
		FbmPrivateUtil.updateAggVO(aggvo, VOStatus.UPDATED);

		// 设置收票票据状态
		IStatusControlStrategy strategy = new DestroyGatherAction(revo);
		StatusControlProcess.getInstance().process(strategy);

		return FBMPrivateServiceProxy.getGatherQueryService().queryGatherVOByPK(pk_register);
	}

	@Override
	public void updateFundorg(SuperVO[] bvos, String pk_fundorg, String pk_fundorg_v) throws BusinessException {
		if (bvos != null && bvos.length != 0) {
			String[] pk_registers = new String[bvos.length];
			for (int i = 0; i < bvos.length; i++) {
				pk_registers[i] = (String) bvos[i].getAttributeValue(FbmFieldConstant.PK_REGISTER);
			}
			StringBuilder exeSql = new StringBuilder();
			exeSql.append("update fbm_register set ");
			exeSql.append(FbmFieldConstant.PK_FUNDORG);
			if (StringUtil.isNull(pk_fundorg)) {
				exeSql.append("='~',");
			} else {
				exeSql.append("='").append(NCESAPI.sqlEncode(pk_fundorg)).append("',");
			}

			exeSql.append(FbmFieldConstant.PK_FUNDORG_V);
			if (StringUtil.isNull(pk_fundorg_v)) {
				exeSql.append("='~'");
			} else {
				exeSql.append("='").append(NCESAPI.sqlEncode(pk_fundorg_v)).append("'");
			}

			exeSql.append("where ");
			exeSql.append(FbmSqlUtils.getInStr(FbmFieldConstant.PK_REGISTER, pk_registers, true));
			BaseDAO dao = new BaseDAO();
			try {
				dao.executeUpdate(exeSql.toString());
			} catch (DAOException e) {
				Logger.error(e.getMessage(), e);
				throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0",
						"03618fbm-0722")/* @res "更新受托资金组织时异常" */);
			}
		}
	}

	@Override
	public void insertGatherWithReliefKeep(AggRegisterVO[] aggvos) throws BusinessException {
		// xuhrc 20191126 云原生后端saga异常校验
		checkSagaStatus(aggvos);
		if (aggvos != null && aggvos.length != 0) {
			for (AggRegisterVO aggvo : aggvos) {
				RegisterVO registervo = (RegisterVO) aggvo.getParentVO();
				// 取单据编号并设置
				String vbillno = FBMPrivateServiceProxy.getBillcodeManage().getBillCode_RequiresNew(
						registervo.getPk_billtypecode(), registervo.getPk_group(), registervo.getPk_org(), aggvo);
				registervo.setAttributeValue(FbmFieldConstant.VBILLNO, vbillno);

				// 组织停用校验
				DefaultValidationService validateService = new DefaultValidationService();
				validateService.addValidator(new FinOrgUnUseValidator(new VOFieldDesc(RegisterVO.PK_ORG)));
				validateService.validate(aggvo);
				if (aggvo.getparentVO().getOlcrate() == null) {
					throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0",
							"03618fbm-1122")/* @res "调入组织本币汇率为空，请设置调入组织汇率！" */);
				}
				// 更新数据库
				FbmPrivateUtil.updateAggVO(aggvo, VOStatus.NEW);
				// 设置票据状态为调剂托管态
				IStatusControlStrategy reliefgather = new ReliefKeepGather((RegisterVO) aggvo.getParentVO(), false);
				StatusControlProcess.getInstance().process(reliefgather);

				// 如果生成的是废票，则设置废票票据状态 for V6.1 modify by aishm 2012-02-22
				if (aggvo.getparentVO().getDisableflag() != null
						&& aggvo.getparentVO().getDisableflag().booleanValue()) {
					AggRegisterVO aggreg = FBMPrivateServiceProxy.getGatherQueryService()
							.queryGatherVOByPK(aggvo.getparentVO().getPk_register());
					IStatusControlStrategy disablegather = new DisableGather(aggreg.getparentVO(), false);
					StatusControlProcess.getInstance().process(disablegather);
				}

				// 登记票据账 2012-7-5 票据日记账余额统计关联改动
				GatherBillAccAdapter billAdapter = new GatherBillAccAdapter();
				billAdapter.writeBillAcc(aggvo);
			}
		}
	}

	@Override
	public void deleteGatherWithReliefKeep(AggRegisterVO[] aggvos) throws BusinessException {
		// xuhrc 20191126 云原生后端saga异常校验
		checkSagaStatus(aggvos);
		if (aggvos != null && aggvos.length != 0) {
			for (AggRegisterVO aggvo : aggvos) {
				RegisterVO registervo = (RegisterVO) aggvo.getParentVO();

				// 删除票据帐 2012-7-5 票据日记账余额统计关联改动
				GatherBillAccAdapter billAdapter = new GatherBillAccAdapter();
				billAdapter.deleteBillAcc(aggvo, registervo.getGatherdate());

				// 如果生成的是废票，则删除废票票据状态 for V6.1 modify by aishm 2012-02-22
				if (aggvo.getparentVO().getDisableflag() != null
						&& aggvo.getparentVO().getDisableflag().booleanValue()) {
					IStatusControlStrategy disablegather = new CancelDisableGather(aggvo.getparentVO(), false);
					StatusControlProcess.getInstance().process(disablegather);
				}

				// 取消调剂状态控制
				IStatusControlStrategy cancelreliefgather = new CancelReliefGather(registervo, false);
				StatusControlProcess.getInstance().process(cancelreliefgather);

				// 删除校验
				if (registervo.getVoucher() != null && registervo.getVoucher().equals(UFBoolean.TRUE)) {
					throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0",
							"03618fbm-1002")/* @res "生成的收票登记单已制证，不能反操作" */);
				}

				// 退单据号
				FBMPrivateServiceProxy.getBillcodeManage().returnBillCodeOnDelete(registervo.getPk_billtypecode(),
						registervo.getPk_group(), registervo.getPk_org(), registervo.getVbillno(), aggvo);

				// 删除收票登记单
				FBMPrivateServiceProxy.getMDService().deleteBill(aggvo);
			}
		}
	}

	/**
	 * 快速导入收票登记后台接口
	 *
	 * @param evos
	 * @throws BusinessException
	 */
	@Override
	public void quickImportGather(List<RegisterVO> origvos) throws BusinessException {
		List<AggRegisterVO> voList = new ArrayList<AggRegisterVO>();
		IBasicOrgUnitPubService_C orgSrv = NCLocator.getInstance().lookup(IBasicOrgUnitPubService_C.class);
		String pk_group = AppContext.getInstance().getPkGroup();
		String pk_user = AppContext.getInstance().getPkUser();
		String[] pk_orgs = orgSrv.getOrgPKsByTypeIDsAndGroupID(pk_group, IOrgConstBasic.BUSINESSUNITORGTYPE);
		Map<String, String> mapOrg = new HashMap<String, String>();
		Map<String, String> mapCustSup = new HashMap<String, String>();
		Map<String, String> notetypeMap = getNoteTypeMap();
		Map<String, String> currtypeMap = getCurrtypeMap();
		Map<String, String> currtypeCodeMap = getCurrtypeCodeMap();
		Map<String, String> fundPlanMap = new HashMap<String, String>();
		Map<String, String> bankaccsubMap = new HashMap<String, String>();
		Map<String, String> bankdocMap = new HashMap<String, String>();

		IGeneralAccessor cussupAccessor = GeneralAccessorFactory
				.getAccessor(nc.itf.bd.pub.IBDMetaDataIDConst.CUSTSUPPLIER);
		IGeneralAccessor fundPlanAccessor = GeneralAccessorFactory
				.getAccessor(nc.itf.bd.pub.IBDMetaDataIDConst.FUNDPLAN);
		IGeneralAccessor bankaccsubAccessor = GeneralAccessorFactory
				.getAccessor(nc.itf.bd.pub.IBDMetaDataIDConst.BANKACCSUB);
		IGeneralAccessor bankdocAccessor = GeneralAccessorFactory.getAccessor(nc.itf.bd.pub.IBDMetaDataIDConst.BANKDOC);
		String pk_billtypecode = origvos.get(0).getPk_billtypecode();

		for (RegisterVO origvo : origvos) {

			RegisterVO regVO = new RegisterVO();

			// 处理主组织
			String pk_org_name = origvo.getPk_org();

			String pk_org = null;
			if (mapOrg.get(pk_org_name) != null) {
				pk_org = mapOrg.get(pk_org_name);
			} else {// pk_org_name为组织名称时
				List<OrgVO> orgList = OrgPubUtil.getVOListByClause(OrgVO.class, OrgVO.PK_ORG, Arrays.asList(pk_orgs),
						"name='" + pk_org_name + "'");
				if (!ArrayUtil.isNull(orgList)) {
					pk_org = orgList.get(0).getPk_org();
					mapOrg.put(pk_org_name, pk_org);
				} else {// pk_org_name是组织编码时
					List<OrgVO> orgCodeList = OrgPubUtil.getVOListByClause(OrgVO.class, OrgVO.PK_ORG,
							Arrays.asList(pk_orgs), "code='" + pk_org_name + "'");
					if (orgCodeList.size() > 0) {
						pk_org = orgCodeList.get(0).getPk_org();
						mapOrg.put(pk_org_name, pk_org);
					}

				}
			}
			checkOrgIsExist(pk_org);// 判断财务组织为空，表示导入的财务组织不存在
			regVO.setPk_org(pk_org);

			// 期初
			regVO.setInitflag(origvo.getInitflag());

			// 处理收票日期
			UFDate gatherdate = origvo.getGatherdate();
			regVO.setGatherdate(gatherdate);

			// 处理付票单位
			String paybillunit_name = origvo.getPaybillunit();
			String paybillunit = null;
			if (mapCustSup.get(pk_org + paybillunit_name) != null) {
				paybillunit = mapCustSup.get(pk_org + paybillunit_name);
			} else {
				IBDData custBDData = cussupAccessor.getDocByNameWithMainLang(pk_org, paybillunit_name);
				if (custBDData != null) {
					paybillunit = custBDData.getPk();
				}
				mapCustSup.put(pk_org + paybillunit_name, paybillunit);
			}
			regVO.setPaybillunit(paybillunit);

			// 处理票据编号
			String fbmbillno = origvo.getFbmbillno();
			regVO.setFbmbillno(fbmbillno);

			// 处理票据类型
			String fbmbilltypename = origvo.getFbmbilltype();
			;
			regVO.setFbmbilltype(notetypeMap.get(fbmbilltypename));
			// 处理币种
			String pk_curr_name = origvo.getPk_curr();
			if (!StringUtil.isNull(currtypeMap.get(pk_curr_name))) {
				regVO.setPk_curr(currtypeMap.get(pk_curr_name));
			} else {
				regVO.setPk_curr(currtypeCodeMap.get(pk_curr_name));
			}

			// 处理票据金额
			UFDouble money = origvo.getMoney();
			regVO.setMoney(money);
			regVO.setOlcrate(new UFDouble(1.0000000));
			regVO.setGlcrate(new UFDouble(1.0000000));
			regVO.setGllcrate(new UFDouble(1.0000000));
			regVO.setOlcmoney(money);
			regVO.setGlcmoney(money);
			regVO.setGllcmoney(money);

			// 处理出票日期
			UFDate invoicedate = origvo.getInvoicedate();
			regVO.setInvoicedate(invoicedate);

			// 处理到期日期
			UFDate enddate = origvo.getEnddate();
			regVO.setEnddate(enddate);

			// 收票计划项目
			if (origvo.getGatherplanitem() != null) {
				String gatherplanitem = null;
				String gahterplanitem_name = origvo.getGatherplanitem();
				if (fundPlanMap.get(pk_org + gahterplanitem_name) != null) {
					gatherplanitem = fundPlanMap.get(pk_org + gahterplanitem_name);
				} else {
					IBDData bdData = fundPlanAccessor.getDocByNameWithMainLang(pk_org, gahterplanitem_name);
					if (bdData != null) {
						gatherplanitem = bdData.getPk();
					}
					fundPlanMap.put(pk_org + gahterplanitem_name, gatherplanitem);
				}
				regVO.setGatherplanitem(gatherplanitem);
			}
			// 备注
			regVO.setNote(origvo.getNote());

			// 业务组织
			String pk_entrusorg_name = origvo.getPk_entrustorg();
			if (pk_entrusorg_name != null) {
				String pk_entrusorg = null;
				if (mapOrg.get(pk_entrusorg_name) != null) {
					pk_entrusorg = mapOrg.get(pk_entrusorg_name);
				} else {
					List<OrgVO> orgList = OrgPubUtil.getVOListByClause(OrgVO.class, OrgVO.PK_ORG,
							Arrays.asList(pk_orgs), "name='" + NCESAPI.sqlEncode(pk_entrusorg_name) + "'");
					if (orgList.size() > 0) {
						pk_entrusorg = orgList.get(0).getPk_org();
						mapOrg.put(pk_entrusorg_name, pk_entrusorg);
					}

				}
				regVO.setPk_entrustorg(pk_entrusorg);
			}
			//
			regVO.setContractno(origvo.getContractno());

			regVO.setAcceptanceno(origvo.getAcceptanceno());

			// 出票单位
			if (origvo.getInvoiceunit() != null) {
				String invoiceunitname = origvo.getInvoiceunit();
				String invoiceunit = null;
				if (mapCustSup.get(pk_org + invoiceunitname) != null) {
					invoiceunit = mapCustSup.get(pk_org + invoiceunitname);
				} else {
					IBDData custBDData = cussupAccessor.getDocByNameWithMainLang(pk_org, invoiceunitname);
					if (custBDData != null) {
						invoiceunit = custBDData.getPk();
					}
					mapCustSup.put(pk_org + invoiceunitname, invoiceunit);
				}
				regVO.setInvoiceunit(invoiceunit);
				regVO.setInvoiceunitname(invoiceunitname);
			}

			// 付款单位
			if (origvo.getHidepayunit() != null) {
				String hidepayunit = origvo.getHidepayunit();
				String payunit = null;
				if (mapCustSup.containsKey(pk_org + hidepayunit)) {
					payunit = mapCustSup.get(pk_org + hidepayunit);
				} else {
					IBDData custBDData = cussupAccessor.getDocByNameWithMainLang(pk_org, hidepayunit);
					if (custBDData != null) {
						payunit = custBDData.getPk();
					}
					mapCustSup.put(pk_org + hidepayunit, payunit);
				}
				regVO.setPayunit(hidepayunit);
				regVO.setHidepayunit(payunit);
			}

			// 收款单位
			if (origvo.getHidereceiveunit() != null) {
				String hidereceiveunit = origvo.getHidereceiveunit();
				String receiveunit = null;
				if (mapCustSup.containsKey(pk_org + hidereceiveunit)) {
					receiveunit = mapCustSup.get(pk_org + hidereceiveunit);
				} else {
					IBDData custBDData = cussupAccessor.getDocByNameWithMainLang(pk_org, hidereceiveunit);
					if (custBDData != null) {
						receiveunit = custBDData.getPk();
					}
					mapCustSup.put(pk_org + hidereceiveunit, receiveunit);
				}
				regVO.setReceiveunit(hidereceiveunit);
				regVO.setHidereceiveunit(receiveunit);
			}
			// 付款银行帐号
			if (origvo.getHidepaybankacc() != null) {
				String hidepaybankacc = origvo.getHidepaybankacc();
				String paybankacc = null;
				if (bankaccsubMap.containsKey(pk_org + hidepaybankacc)) {
					paybankacc = bankaccsubMap.get(pk_org + hidepaybankacc);
				} else {
					IBDData bankaccData = bankaccsubAccessor.getDocByCode(pk_org, hidepaybankacc);
					if (bankaccData != null) {
						paybankacc = bankaccData.getPk();
					}
					bankaccsubMap.put(pk_org + hidepaybankacc, hidepaybankacc);
				}
				regVO.setHidepaybankacc(paybankacc);
				regVO.setPaybankacc(hidepaybankacc);
			}
			// 已收票
			regVO.setSfflag(origvo.getSfflag() == null ? UFBoolean.FALSE : origvo.getSfflag());
			// 收款银行帐号
			if (origvo.getHidereceivebankacc() != null) {
				String hidereceivebankacc = origvo.getHidereceivebankacc();
				String receivebankacc = null;
				if (bankaccsubMap.containsKey(pk_org + hidereceivebankacc)) {
					receivebankacc = bankaccsubMap.get(pk_org + hidereceivebankacc);
				} else {
					IBDData bankaccData = bankaccsubAccessor.getDocByCode(pk_org, hidereceivebankacc);
					if (bankaccData != null) {
						receivebankacc = bankaccData.getPk();
					}
					bankaccsubMap.put(pk_org + hidereceivebankacc, hidereceivebankacc);
				}
				regVO.setHidereceivebankacc(receivebankacc);
				regVO.setReceivebankacc(hidereceivebankacc);
			}

			// 付款银行
			if (origvo.getHidepaybank() != null) {
				String hidepaybank = origvo.getHidepaybank();
				String paybank = null;
				if (bankdocMap.containsKey(pk_org + hidepaybank)) {
					paybank = bankdocMap.get(pk_org + hidepaybank);
				} else {
					IBDData bankdocData = bankdocAccessor.getDocByNameWithMainLang(pk_org, hidepaybank);
					if (bankdocData != null) {
						paybank = bankdocData.getPk();
					}
					bankdocMap.put(pk_org + hidepaybank, paybank);
				}
				regVO.setHidepaybank(paybank);
				regVO.setPaybank(hidepaybank);
			}

			// 收款银行
			if (origvo.getHidereceivebank() != null) {
				String hidereceivebank = origvo.getHidereceivebank();
				String receivebank = null;
				if (bankdocMap.containsKey(pk_org + hidereceivebank)) {
					receivebank = bankdocMap.get(pk_org + hidereceivebank);
				} else {
					IBDData bankdocData = bankdocAccessor.getDocByNameWithMainLang(pk_org, hidereceivebank);
					if (bankdocData != null) {
						receivebank = bankdocData.getPk();
					}
					bankdocMap.put(pk_org + hidereceivebank, receivebank);
				}
				regVO.setHidereceivebank(receivebank);
				regVO.setReceivebank(hidereceivebank);
			}

			regVO.setCyberbankflag(origvo.getCyberbankflag());
			if (origvo.getCyberbankflag() != null && origvo.getCyberbankflag().booleanValue()) {
				// 登记银行
				if (StringUtil.isNull(origvo.getPk_bankdoc())) {
					throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
							"03618fbm_add02-0326")/* @res "导入时网银为Y，登记银行不能为空！" */);
				}
				// 承兑银行
				if (StringUtil.isNull(origvo.getSignagrbank())) {
					throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
							"03618fbm_add02-0327")/* @res "导入时网银为Y，承兑银行不能为空！" */);
				}

				// 登记银行
				if (StringUtil.isNull(origvo.getPk_bankdoc())) {
					String pk_bankdoc = origvo.getPk_bankdoc();
					String bankdoc = null;
					if (bankdocMap.containsKey(pk_org + pk_bankdoc)) {
						bankdoc = bankdocMap.get(pk_org + pk_bankdoc);
					} else {
						IBDData bankdocData = bankdocAccessor.getDocByNameWithMainLang(pk_org, pk_bankdoc);
						if (bankdocData != null) {
							bankdoc = bankdocData.getPk();
						} else {
							throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
									.getStrByID("3618fbm_add02_0", "03618fbm_add02-0328")/* @res "导入的登记银行错误！" */);
						}
						bankdocMap.put(pk_org + pk_bankdoc, bankdoc);
					}
					regVO.setPk_bankdoc(bankdoc);
				}

				// 承兑银行
				if (StringUtil.isNull(origvo.getSignagrbank())) {
					String signagrbank = origvo.getSignagrbank();
					String pksignagrbank = null;
					if (bankdocMap.containsKey(pk_org + signagrbank)) {
						pksignagrbank = bankdocMap.get(pk_org + signagrbank);
					} else {
						IBDData bankdocData = bankdocAccessor.getDocByNameWithMainLang(pk_org, signagrbank);
						if (bankdocData != null) {
							pksignagrbank = bankdocData.getPk();
						} else {
							throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes()
									.getStrByID("3618fbm_add02_0", "03618fbm_add02-0329")/* @res "导入的承兑银行错误！" */);
						}
						bankdocMap.put(pk_org + signagrbank, pksignagrbank);
					}
					regVO.setSignagrbank(pksignagrbank);
					if (!StringUtil.isNull(origvo.getAcceptorname())) {
						regVO.setAcceptorname(origvo.getAcceptorname());
					} else {
						regVO.setAcceptorname(signagrbank);
					}
				}

				// 检验票据池登记银行承兑银行信息
				checkBankDoc(regVO);
			}

			// pk_group
			regVO.setPk_group(pk_group);

			// billtype
			regVO.setPk_billtypecode(origvo.getPk_billtypecode());
			regVO.setPk_billtypeid(origvo.getPk_billtypeid());
			// gathertype
			regVO.setGathertype(FbmBusConstant.GATHER_TYPE_INPUT);

			// Billmaker
			regVO.setBillmaker(pk_user);
			// bookflag
			regVO.setBookflag(UFBoolean.FALSE);
			// buyerinterest
			regVO.setBuyerinterest(origvo.getBuyerinterest() == null ? UFBoolean.FALSE : origvo.getBuyerinterest());
			// disableflag
			regVO.setDisableflag(UFBoolean.FALSE);

			regVO.setPlanflag(UFBoolean.FALSE);
			// 单据状态
			regVO.setVbillstatus(nc.vo.trade.pub.IBillStatus.FREE);

			// 制证
			if (origvo.getVoucher() != null) {
				regVO.setVoucher(origvo.getVoucher());
			} else {
				regVO.setVoucher(UFBoolean.FALSE);
			}

			regVO.setDoperatedate(new UFDate());

			AggRegisterVO aggRegVO = new AggRegisterVO();
			aggRegVO.setParentVO(regVO);

			voList.add(aggRegVO);
		}

		AggRegisterVO[] vos = voList.toArray(new AggRegisterVO[0]);
		PfProcessBatchRetObject obj = (PfProcessBatchRetObject) NCLocator.getInstance().lookup(IplatFormEntry.class)
				.processBatch("SAVEBASE", pk_billtypecode, null, vos, null, null);
		if (!StringUtil.isNull(obj.getExceptionMsg())) {
			throw new BusinessException(obj.getExceptionMsg());
		}

		Logger.debug("快速导入已完成");
	}

	private void checkOrgIsExist(String pk_org) throws BusinessException {
		if (StringUtil.isNull(pk_org)) {
			throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
					"03618fbm_add02-0330")/* @res "财务组织不存在，请填写正确的财务组织" */);
		}
	}

	private Map<String, String> getNoteTypeMap() throws BusinessException {
		INotetypeQueryService notetypeSrv = NCLocator.getInstance().lookup(INotetypeQueryService.class);
		NotetypeVO[] notetypevos = notetypeSrv.queryAllNotetypeVOs();
		Map<String, String> notetypemap = new HashMap<String, String>();
		for (NotetypeVO vo : notetypevos) {
			notetypemap.put(vo.getCode(), vo.getPk_notetype());
			notetypemap.put(vo.getName(), vo.getPk_notetype());
		}
		return notetypemap;
	}

	private Map<String, String> getCurrtypeMap() throws BusinessException {
		ICurrtypeQuery srv = NCLocator.getInstance().lookup(ICurrtypeQuery.class);
		CurrtypeVO[] vos = srv.queryAllCurrtypeVO();
		Map<String, String> currtypeMap = new HashMap<String, String>();
		for (CurrtypeVO vo : vos) {
			currtypeMap.put(vo.getName(), vo.getPk_currtype());
		}
		return currtypeMap;
	}

	private Map<String, String> getCurrtypeCodeMap() throws BusinessException {
		ICurrtypeQuery srv = NCLocator.getInstance().lookup(ICurrtypeQuery.class);
		CurrtypeVO[] vos = srv.queryAllCurrtypeVO();
		Map<String, String> currtypeMap = new HashMap<String, String>();
		for (CurrtypeVO vo : vos) {
			currtypeMap.put(vo.getCode(), vo.getPk_currtype());
		}
		return currtypeMap;
	}

	@Override
	public void updateGatherByBillpool(AggRegisterVO[] aggvos) throws BusinessException {
		// xuhrc 20191126 云原生后端saga异常校验
		checkSagaStatus(aggvos);
		RegisterVO[] registerVOs = new RegisterVO[aggvos.length];
		for (int i = 0; i < aggvos.length; i++) {
			aggvos[i].getParentVO().setStatus(VOStatus.UPDATED);
			registerVOs[i] = (RegisterVO) aggvos[i].getParentVO();
		}
		// 更新数据库
		FBMPrivateServiceProxy.getMDService().saveBillWithRealDelete(registerVOs);

	}

	@Override
	public void updateGatherByBillpoolWithoutSagaCheck(AggRegisterVO[] aggvos) throws BusinessException {
		RegisterVO[] registerVOs = new RegisterVO[aggvos.length];
		for (int i = 0; i < aggvos.length; i++) {
			aggvos[i].getParentVO().setStatus(VOStatus.UPDATED);
			registerVOs[i] = (RegisterVO) aggvos[i].getParentVO();
		}
		// 更新数据库
		FBMPrivateServiceProxy.getMDService().saveBillWithRealDelete(registerVOs);
	}

	/**
	 * 网银办理前业务校验
	 *
	 * @param aggVOs
	 * @param pks
	 * @param cacheMap
	 * @return
	 * @throws BusinessException
	 */
	private AggRegisterVO[] doNetBankBeforeValidate(AggRegisterVO[] aggVOs, List<String> pks,
			Map<String, AggRegisterVO> cacheMap) throws BusinessException {
		if (aggVOs != null && aggVOs.length > 0) {
			boolean passFlag = false;
			List<AggRegisterVO> result = new ArrayList<AggRegisterVO>();// 用于存储业务校验通过得数据

			Map<String, Boolean> noteClassMap = new HashMap<String, Boolean>();
			Map<String, Boolean> bankMap = new HashMap<String, Boolean>();

			for (AggRegisterVO aggVO : aggVOs) {
				if (aggVO != null && aggVO.getParentVO() != null) {
					/**
					 * 判断票据状态，只有已登记得可以进行银行登记
					 */
					if (RegisterStatusConstant.REGISTER.equals(aggVO.getparentVO().getRegisterstatus())) {
						/**
						 * 判断当前票据是否已完成收票
						 */
						if (aggVO.getparentVO().getSfflag() != null && aggVO.getparentVO().getSfflag().booleanValue()) {
							/**
							 * 判断当前票据是否勾选网银
							 */
							if (aggVO.getparentVO().getCyberbankflag() != null
									&& aggVO.getparentVO().getCyberbankflag().booleanValue()) {
								// begin-wangsh7-20190731-建行电票不能银行登记
								/**
								 * 山西正华建行电票登记问题：建行的电票不允许银行登记，经需求确认合并到1909
								 */
//								passFlag = true;
								if (isJSYH(aggVO.getparentVO().getPk_bankdoc(), bankMap)
										&& isEcdNoteClass(aggVO.getparentVO().getPk_register(), noteClassMap)) {
									passFlag = false;
									setNetBankError(aggVO,
											nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
													"03618fbm_add02-0034")
													/* @res "单据[" */ + ((RegisterVO) aggVO.getParentVO()).getVbillno()
													+ nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID(
															"3618fbm_add02_0",
															"03618fbm_add02-0381")/* "]，建设银行电票不能进行银行登记！" */);
								} else {
									passFlag = true;
								}
								// end-wangsh7-20190731
							} else {
								passFlag = false;
								setNetBankError(aggVO,
										nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
												"03618fbm_add02-0034")
												/* @res "单据[" */ + ((RegisterVO) aggVO.getParentVO()).getVbillno()
												+ nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID(
														"3618fbm_add02_0",
														"03618fbm_add02-0331")/* @res "]未勾选网银，不能进行网银办理！" */);
							}
						} else {
							passFlag = false;
							setNetBankError(aggVO,
									nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
											"03618fbm_add02-0034")
											/* @res "单据[" */ + ((RegisterVO) aggVO.getParentVO()).getVbillno()
											+ nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
													"03618fbm_add02-0332")/* @res "]未完成收票登记，不能进行网银办理！" */);
						}
					} else {
						passFlag = false;
						setNetBankError(aggVO,
								nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
										"03618fbm_add02-0034")
										/* @res "单据[" */ + ((RegisterVO) aggVO.getParentVO()).getVbillno()
										+ nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
												"03618fbm_add02-0333")/* @res "]已被使用，不能进行银行登记！" */);
					}

					pks.add(aggVO.getParentVO().getPrimaryKey());// 记录单据主键，后续根据主键序列重现排序
				} else {
					throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
							"03618fbm_add02-0033")/* @res "数据为空！" */);
				}
				if (!passFlag) {
					cacheMap.put(aggVO.getparentVO().getPrimaryKey(), aggVO);// 未通过业务校验得数据存入缓存
				} else {
					result.add(aggVO);// 存储通过业务校验得数据
				}

				passFlag = false;
			}

			/**
			 * 校验不通过的数据条数
			 */
			if (cacheMap.size() == aggVOs.length) {
				if (aggVOs.length == 1) {
					throw new BusinessException(((RegisterVO) aggVOs[0].getParentVO()).getBankreturninfo());
				}
				throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
						"03618fbm_add02-0334")/* @res "所有数据都不符合业务需求，不能进行网银办理！" */);
			}

			return result.toArray(new AggRegisterVO[result.size()]);
		} else {
			throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
					"03618fbm_add02-0033")/* @res "数据为空！" */);
		}
	}

	/**
	 * 网银办理
	 *
	 * @param aggVOs
	 * @return
	 * @throws BusinessException
	 */
	private AggRegisterVO[] doNetBank(AggRegisterVO[] aggVOs) throws BusinessException {
		// xuhrc 20191126 云原生后端saga异常校验
		checkSagaStatus(aggVOs);
		return PFBMPrivateServiceProxy.getIEbankBillManageService().receiptRegis(aggVOs, FbmBusConstant.MODEL_NAME_OBM);
	}

	/**
	 * 网银办理后业务校验
	 *
	 * @param aggVOs
	 * @param pks
	 * @param cacheMap
	 * @throws BusinssException
	 */
	private AggRegisterVO[] doNetBankAfterValidate(AggRegisterVO[] aggVOs, List<String> pks,
			Map<String, AggRegisterVO> cacheMap) throws BusinessException {
		if (aggVOs != null && aggVOs.length > 0) {
			int reqNum = pks.size();// 后台总共需要处理的数据条数
			int ebankRetNum = aggVOs.length;// 网银返回的数据条数
			int noPassNum = cacheMap.size();// 网银办理前业务校验不通过的数据条数

			/**
			 * 校验网银办理返回的数据条数
			 */
			if (reqNum > ebankRetNum + noPassNum) {
				throw new BusinessException(
						nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0266")
								/* @res "网银丢失数据[" */ + (reqNum - (ebankRetNum + noPassNum))
								+ nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
										"03618fbm_add02-0267")/* @res "]条！" */);
			}

			/**
			 * 校验网银办理后的数据是否为空
			 */
			for (AggRegisterVO aggVO : aggVOs) {
				if (aggVO == null || aggVO.getParentVO() == null) {
					throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
							"03618fbm_add02-0268")/* @res "网银返回数据为空！" */);
				}
				if (aggVO.getparentVO().getPaymentstatus() == null) {
					throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
							"03618fbm_add02-0269")/* @res "网银返回数据 指令状态为空！" */);
				}
				cacheMap.put(aggVO.getParentVO().getPrimaryKey(), aggVO);// 将网银处理后的数据也放入缓存
			}

			AggRegisterVO[] result = new AggRegisterVO[reqNum];
			for (int i = 0; i < reqNum; i++) {
				result[i] = cacheMap.get(pks.get(i));
			}
			return result;
		} else {
			throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
					"03618fbm_add02-0268")/* @res "网银返回数据为空！" */);
		}
	}

	/**
	 * 更新数据库
	 *
	 * @param aggVOs
	 * @throws BusinssException
	 */
	private void doUpdate2DB(AggRegisterVO[] aggVOs) throws BusinessException {
		if (aggVOs != null && aggVOs.length > 0) {
			for (AggRegisterVO aggVO : aggVOs) {
				if (aggVO != null && aggVO.getparentVO() != null) {
					RegisterVO registerVO = aggVO.getparentVO();
					/**
					 * 未勾选网银，发送银行登记指令情况 指令状态成功，则网银复选框赋值true
					 *
					 */
					if (!(registerVO.getCyberbankflag() != null && registerVO.getCyberbankflag().booleanValue())) {
						if (PaymentStatusEnum.TRADESUCCESS.value().equals(registerVO.getPaymentstatus())) {
							registerVO.setCyberbankflag(UFBoolean.TRUE);
						} else {
							registerVO.setCyberbankflag(UFBoolean.FALSE);
						}
					}
					// 更新票据信息
					aggVO = (AggRegisterVO) FbmPrivateUtil.updateAggVO(aggVO, VOStatus.UPDATED);
				} else {
					throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
							"03618fbm_add02-0268")/* @res "网银返回数据为空！" */);
				}
			}
		} else {
			throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
					"03618fbm_add02-0268")/* @res "网银返回数据为空！" */);
		}
	}

	@Override
	public AggRegisterVO[] bankRegister(AggRegisterVO[] aggVOs) throws BusinessException {
		// xuhrc 20191126 云原生后端saga异常校验
		checkSagaStatus(aggVOs);
		// start_190722_wusib_NCC1909版本废弃票据池启用日期参数
//		String initdate = SysinitAccessor.getInstance().getParaString(InvocationInfoProxy.getInstance().getGroupId(),
//				"PFBM0001");
//		if (initdate == null) {
//			throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
//					"03618fbm_add02-0335")/* @res "登记银行失败，请先设置票据池启用日期参数！" */);
//		}
		// end_190722_wusib_NCC1909版本废弃票据池启用日期参数

		// 未勾选网银，补全银行信息，如：登记银行，承兑银行等
		BankRegisterUtil.bankRegisterHelp(aggVOs);
		// 判断银企直联是否启用
		if (!FbmPublicUtil.isOBMEnable((String) aggVOs[0].getParentVO().getAttributeValue(FbmFieldConstant.PK_GROUP))) {
			throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
					"03618fbm_add02-0223")/* @res "未安装银企直联模块，请先安装后使用" */);
		}

		/**
		 * 强制ca验签
		 */
//		PFBMcaVerityVO pfbmcavo = new PFBMcaVerityVO();
//		PfbmCASignatureVO pfbmca = pfbmcavo.getGatherCa(aggVOs[0]);
////		pfbmca.setCryptograph(discountvo.getCacode());
//		PfbmCAVerfier caVerifier = new PfbmCAVerfier();
//		caVerifier.verifyPayInfo(new PfbmCASignatureVO[]{pfbmca}, new ConsignCAInfoAccessor(), AppContext.getInstance().getPkUser(),aggVOs[0].getparentVO().getPk_billtypecode());

		List<String> pks = new ArrayList<String>();// 主键序列
		Map<String, AggRegisterVO> cacheMap = new HashMap<String, AggRegisterVO>();// 缓存，用于存储业务校验不通过得数据

		try {
			aggVOs = doNetBankBeforeValidate(aggVOs, pks, cacheMap);
		} catch (BusinessException e) {
			throw new BusinessException(
					nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0336")
							/* @res "银行登记 网银办理前业务校验不通过。" */ + (e.getMessage() == null ? "" : e.getMessage()));
		}

		try {
			aggVOs = doNetBank(aggVOs);
		} catch (BusinessException e) {
			throw new BusinessException(
					nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0337")
							/* @res "银行登记 网银办理过程中出现异常。" */ + (e.getMessage() == null ? "" : e.getMessage()));
		}

		try {
			aggVOs = doNetBankAfterValidate(aggVOs, pks, cacheMap);
		} catch (BusinessException e) {
			throw new BusinessException(
					nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0338")
							/* @res "银行登记 网银办理后业务校验不通过。" */ + (e.getMessage() == null ? "" : e.getMessage()));
		}

		try {
			doUpdate2DB(aggVOs);
		} catch (BusinessException e) {
			throw new BusinessException(
					nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0339")
							/* @res "银行登记 更新数据库出现异常。" */ + (e.getMessage() == null ? "" : e.getMessage()));
		}
		return aggVOs;
	}

	@Override
	public void bankRegisterWriteBackRegister(AggRegisterVO[] aggVOs) throws BusinessException {
		// xuhrc 20191126 云原生后端saga异常校验
		checkSagaStatus(aggVOs);
		if (aggVOs != null && aggVOs.length > 0) {
			List<AggRegisterVO> result = new ArrayList<AggRegisterVO>();
			/**
			 * 过滤，去除指令状态为空得数据
			 */
			for (AggRegisterVO aggVO : aggVOs) {
				if (aggVO != null && aggVO.getparentVO() != null) {
					if (aggVO.getparentVO().getPaymentstatus() != null) {
						result.add(aggVO);
					}
				} else {
					throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
							"03618fbm_add02-0033")/* @res "数据为空！" */);
				}
			}

			doUpdate2DB(result.toArray(new AggRegisterVO[result.size()]));// 更新数据库
		} else {
			throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
					"03618fbm_add02-0033")/* @res "数据为空！" */);
		}
	}

	/**
	 * 将指令状态置为失败
	 *
	 * @param aggVO
	 * @param errMess
	 */
	private void setNetBankError(AggRegisterVO aggVO, String errMess) {
		((RegisterVO) aggVO.getParentVO()).setPaymentstatus(PaymentStatusEnum.TRADEFAIL.toIntValue());
		((RegisterVO) aggVO.getParentVO()).setBankreturninfo(errMess);
	}

	/**
	 * 生成审批态银行托管单
	 *
	 * @param aggVOs
	 * @throws BusinessException
	 */
	@Override
	public void insertStorageVO(AggRegisterVO aggVO) throws BusinessException {
		// 创建要传递的数据
		AggStorageVO aggstovo = RegisterToChangeVO.registerToChangeStorageVO(aggVO);// 收票登记转化为银行托管VO
		// 生成保存态的银行托管单
		aggstovo = FBMPrivateServiceProxy.getBankKeepManageService().insertBankKeep(aggstovo);

		aggstovo.getParentVO().setAttributeValue("vbillstatus", 1);// 单据状态=审批通过
		aggstovo.getParentVO().setAttributeValue("approver", aggstovo.getParentVO().getAttributeValue("billmaker"));// 审批人=制单人
		aggstovo.getParentVO().setAttributeValue("approvetime",
				aggstovo.getParentVO().getAttributeValue("creationtime"));// 审批时间=创建时间
		aggstovo.getParentVO().setAttributeValue("dapprovedate",
				aggstovo.getParentVO().getAttributeValue("doperatedate"));// 审批日期=制单日期

		// 调用审批流
		boolean isEndStep2 = FbmPrivateUtil.isEndStep4Audit(aggstovo);
		// 生成审批态的银行托管单
		aggstovo = FBMPrivateServiceProxy.getBankKeepManageService().approveBankKeep(aggstovo, isEndStep2);
	}

	/**
	 * 生成审批态银行托管单
	 *
	 * @param aggVOs
	 * @throws BusinessException
	 */
	@Override
	public void insertStorageVOAndCenterVO(AggRegisterVO[] aggregisterVO) throws BusinessException {
		// xuhrc 20191126 云原生后端saga异常校验
		checkSagaStatus(aggregisterVO);
		for (int i = 0; i < aggregisterVO.length; i++) {
			// 生成银行托款单
			if (aggregisterVO[i].getparentVO().getNote().equals("92")) {
				insertStorageVO(aggregisterVO[i]);
			}

			// 生成占用费计算
			insertCenterVO(aggregisterVO[i]);
		}
	}

	/**
	 * 生成占用费计算
	 *
	 * @param aggVOs
	 * @throws BusinessException
	 */
	@Override
	public void insertCenterVO(AggRegisterVO aggVO) throws BusinessException {
		RegisterVO regvo = (RegisterVO) aggVO.getParentVO();
//		if(StringUtil.isNotNull(regvo.getPk_occupyctmangage()) ){//占用费率不为空
//			// 组装占用费聚合VO
//			AggCenteroccupyctVO[] aggCenteroccupyctVO = new AggCenteroccupyctVO[1];
//			aggCenteroccupyctVO[0]=RegisterToChangeVO.registerToChangeCenterVO(aggVO);//收票登记转化为占用费VO
//			// 勾选计算费用，新增占用费计算记录
//			if( aggCenteroccupyctVO!=null ){
//				NCLocator.getInstance().lookup(ICenteroccupyctManageService.class).insert(aggCenteroccupyctVO);
//			}
//		}
		if ((StringUtil.isNotNull(regvo.getPk_org())) && StringUtil.isNotNull(regvo.getPaybillunit())) {
			Map<String, String> orgmap = FBMPrivateServiceProxy.getCustsupPubService()
					.queryOrgPkByCustsupPk(new String[] { regvo.getPaybillunit() });
			// 如果是外部客商，直接返回null
			if (null == orgmap) {
				return;
			}
			String paybillunit = orgmap.get(regvo.getPaybillunit());

			// 根据资金组织ID与财务组织ID查询是否存在委托关系
			boolean isFundOrgIDSByOrgID = NCLocator.getInstance().lookup(IFundOrgPubService.class)
					.isExistRelationByFundOrgIDAndFinanceOrgID(regvo.getPk_org(), paybillunit);
			if (isFundOrgIDSByOrgID) {// 财务组织为中心，付票单位为成员单位
				// 组装占用费聚合VO
				AggCenteroccupyctVO[] aggCenteroccupyctVO = new AggCenteroccupyctVO[1];
				aggCenteroccupyctVO[0] = RegisterToChangeVO.registerToChangeCenterVO(aggVO);// 收票登记转化为占用费VO
				// 勾选计算费用，新增占用费计算记录
				if (aggCenteroccupyctVO != null) {
					NCLocator.getInstance().lookup(ICenteroccupyctManageService.class).insert(aggCenteroccupyctVO);
				}
			}
		}
	}

	/**
	 * 删除占用费计算
	 *
	 * @param aggVOs
	 * @throws BusinessException
	 */
	@Override
	public void deleteCenterVO(AggRegisterVO aggVO) throws BusinessException {
		RegisterVO regvo = (RegisterVO) aggVO.getParentVO();
		// 根据来源单据主键查出占用费聚合VO
		AggCenteroccupyctVO[] aggCenteroccupyctVO = NCLocator.getInstance().lookup(ICenteroccupyctManageService.class)
				.queryCenteroccupyctVOByPk_Srcbill(regvo.getPk_register());
		// 勾选计算费用，新增占用费计算记录
		if (aggCenteroccupyctVO != null) {
			NCLocator.getInstance().lookup(ICenteroccupyctManageService.class).delete(aggCenteroccupyctVO);
		}
	}

	/**
	 * 作废
	 *
	 * @param aggvo
	 * @throws BusinessException
	 */
	@Override
	public AggRegisterVO disableGatherbill(AggRegisterVO aggvo) throws BusinessException {
		// xuhrc 20191126 云原生后端saga异常校验
		checkSagaStatus(aggvo);
		// 如果是待签收生成的，需要将状态回退为未生成
		if(FbmBusConstant.GATHER_TYPE_SIGNINPUT.equals(aggvo.getparentVO().getGathertype())) {
			NCLocator.getInstance().lookup(IBeforeRegisterManageService.class).undoWhenDeleteGather(aggvo.getparentVO());
		}
		// 作废前校验
		this.doBeforeDisableValidator(aggvo);
		RegisterVO registerVO = aggvo.getparentVO();
		// 更新作废标识及作废信息
		registerVO.setDisuseflag(UFBoolean.TRUE);
		FbmPrivateUtil.updateAggVO(aggvo, VOStatus.UPDATED);
		// 设置票据状态 作废后单据不可用，票据返回到已开票状态
		IStatusControlStrategy strategy = new DisableGather(registerVO);
		StatusControlProcess.getInstance().process(strategy);
		return (AggRegisterVO) FbmPrivateUtil.queryAggvoByPK(aggvo);
	}

	/**
	 * 作废前校验
	 *
	 * @param aggvo
	 * @throws BusinessException
	 */
	private void doBeforeDisableValidator(AggRegisterVO aggVO) throws BusinessException {
		if (aggVO == null) {
			throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
					"03618fbm_add02-0232")/* @res "当前操作单据不能为空！" */);
		} else {
			RegisterVO payvo = (RegisterVO) aggVO.getParentVO();
			if (payvo == null) {
				throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
						"03618fbm_add02-0232")/* @res "当前操作单据不能为空！" */);
			} else {
				if (payvo.getElcpaymentstatus() == null
						|| !(payvo.getElcpaymentstatus().equals(PaymentStatusEnum.TRADEFAIL.toIntValue()))) {
					throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
							"03618fbm_add02-0259")/*
													 * @res "不能确认该单据交易失败，不能作废！"
													 */);
				} else if (payvo.getOnlinebankflag() == null || !(payvo.getOnlinebankflag().booleanValue())) {
					throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
							"03618fbm_add02-0347")/*
													 * @res "该单据没有勾选网银，不能作废！"
													 */);
				}
				// 该单据已经被作废，不能重复作废！
				else if (payvo.getDisuseflag() != null && payvo.getDisuseflag().booleanValue()) {
					throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
							"03618fbm_add02-0239")/*
													 * @res "该单据已经被作废，不能重复作废！"
													 */);
				}
			}
		}
	}

	/**
	 * 取消作废
	 *
	 * @param aggvo
	 * @throws BusinessException
	 */
	@Override
	public AggRegisterVO cancelDisableGatherbill(AggRegisterVO aggvo) throws BusinessException {
		// xuhrc 20191126 云原生后端saga异常校验
		checkSagaStatus(aggvo);
		// 取消作废前校验
		this.doBeforeCancelDisableValidator(aggvo);
		// 如果是待签收生成的，需要将状态恢复为已生成
		if(FbmBusConstant.GATHER_TYPE_SIGNINPUT.equals(aggvo.getparentVO().getGathertype())) {
			NCLocator.getInstance().lookup(IBeforeRegisterManageService.class).doWhenUnDisableGather(aggvo.getparentVO());
		}
		RegisterVO registerVO = (RegisterVO) aggvo.getParentVO();
		// 更新作废标识及作废信息
//		registerVO.setDisableflag(UFBoolean.FALSE);
		// 作废
		registerVO.setDisuseflag(UFBoolean.FALSE);
		// 清空作废原因
		registerVO.setDisablenote(null);
		// 删除作废人
		registerVO.setDisableuser(null);
		// 删除作废时间
		registerVO.setDisabledate(null);
		FbmPrivateUtil.updateAggVO(aggvo, VOStatus.UPDATED);
		// 设置票据状态 票据已开票状态到在付票状态（添加票据台账记录信息）
		IStatusControlStrategy strategy = new CancelDisableGather(registerVO);
		StatusControlProcess.getInstance().process(strategy);

		return (AggRegisterVO) FbmPrivateUtil.queryAggvoByPK(aggvo);
	}

	/**
	 * 取消作废前校验
	 *
	 * @param aggvo
	 * @throws BusinessException
	 */
	private void doBeforeCancelDisableValidator(AggRegisterVO aggVO) throws BusinessException {
		if (aggVO == null) {
			throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
					"03618fbm_add02-0232")/* @res "当前操作单据不能为空！" */);
		} else {
			RegisterVO payvo = (RegisterVO) aggVO.getParentVO();
			if (payvo == null) {
				throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
						"03618fbm_add02-0232")/* @res "当前操作单据不能为空！" */);
			} else {
				// 该单据没有被作废，不能取消作废！
				if (payvo.getDisuseflag() != null && !(payvo.getDisuseflag().booleanValue())) {
					throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618ncc_0",
							"03618ncc-0027")/* @res "该单据未被作废，不能取消作废！" */);
				}
			}
		}
	}

	/**
	 * 判断是否是电票
	 *
	 * @param pk_register
	 * @param noteClass
	 * @return
	 */
	private boolean isEcdNoteClass(String pk_register, Map<String, Boolean> noteClassMap) {
		if (noteClassMap.containsKey(pk_register)) {
			return noteClassMap.get(pk_register);
		} else {
			Boolean isEcd = FbmPublicUtil.isEcdNoteClass(pk_register);
			noteClassMap.put(pk_register, isEcd);
			return isEcd;
		}
	}

	/**
	 * 判断是否是建设银行
	 *
	 * @param pk_bankdoc
	 * @param bankMap
	 * @return
	 * @throws BusinessException
	 */
	private boolean isJSYH(String pk_bankdoc, Map<String, Boolean> bankMap) throws BusinessException {
		if (bankMap.containsKey(pk_bankdoc)) {
			return bankMap.get(pk_bankdoc);
		} else {
			Boolean isJSYH = EFbmBusConstant.JSYH.equals(
					NCLocator.getInstance().lookup(IBankdocQueryService.class).queryBanktypePkByBankdocPk(pk_bankdoc));
			bankMap.put(pk_bankdoc, isJSYH);
			return isJSYH;
		}
	}

	private void checkSagaStatus(AggRegisterVO aggvo) throws BusinessException {
		if (aggvo != null && aggvo.getParentVO() != null) {
			CheckInfo info = new CheckInfo();
			info.setPkfieldName(RegisterVO.PK_REGISTER);
			info.setTableName(RegisterVO.getDefaultTableName());
			info.setPks(new String[] { aggvo.getPrimaryKey() });
			FbmPubPublicServiceProxy.getSagaStatusCheckService().checkSagaStatus(new CheckInfo[] { info });
		}
	}

	private void checkSagaStatus(AggRegisterVO[] aggVOs) throws BusinessException {
		if (aggVOs != null && aggVOs.length > 0) {
			CheckInfo info = new CheckInfo();
			info.setPkfieldName(RegisterVO.PK_REGISTER);
			info.setTableName(RegisterVO.getDefaultTableName());
			List<String> pkList = new ArrayList<String>();
			for (AggRegisterVO aggvo : aggVOs) {
				RegisterVO parentvo = (RegisterVO) aggvo.getParentVO();
				String pk_register = parentvo.getPk_register();
				pkList.add(pk_register);
			}
			info.setPks(pkList.toArray(new String[pkList.size()]));
			FbmPubPublicServiceProxy.getSagaStatusCheckService().checkSagaStatus(new CheckInfo[] { info });
		}
	}

	@Override
	public AggregatedValueObject combinGatherbill(String[] pk_registers, String pk_billtypecode)
			throws BusinessException {
		// 根据主键查询相关VO
		IGatherQueryService gatherService = NCLocator.getInstance().lookup(IGatherQueryService.class);
		AggRegisterVO[] aggVOs = gatherService.getAggVOsByPKs(pk_registers);
		// 检验相关数据
		if (ArrayUtils.isEmpty(aggVOs)) {
			throw new BusinessException("传入AggRegisterVO数组为空，请检查");
		}
		GatherCheckUtil.checkSameOrgCurr(aggVOs);
		GatherCheckUtil.checkSamePaybillunit(aggVOs);
		GatherCheckUtil.checkIsBookOrPlan(aggVOs);
		GatherCheckUtil.checkRegisterStatus(aggVOs);

		AggregatedValueObject aggVO = null;
		if ("36J7".equals(pk_billtypecode)) {
			// 组合委托收款单
			aggVO = commissionBill(aggVOs, pk_billtypecode);
		} else if ("F2".equals(pk_billtypecode)) {
			// 组合收款单
			aggVO = gatheringbill(aggVOs, pk_billtypecode);
		} else if ("F4".equals(pk_billtypecode)) {
			// 组合收款结算单
			aggVO = recbill(aggVOs, pk_billtypecode);
		}
		return aggVO;
	}

	/**
	 *  收票登记关联资金收款单，组装资金收款单VO
	 * @param aggVOs
	 * @param pk_billtypecode
	 * @return 收款结算单
	 * @throws BusinessException
	 */
	private AggregatedValueObject recbill(AggRegisterVO[] aggVOs, String pk_billtypecode) throws BusinessException {
//		String funcode = "36070RBR";// 功能编码
		String pk_desbilltype = "F4";
//		String tradetype = "D4";
		String billclass = "sj";// 单据大类
		
		RegisterVO pvo = aggVOs[0].getparentVO();
		String pk_org = pvo.getPk_org();
		String pk_org_v = pvo.getPk_org_v();
		String pk_group = pvo.getPk_group();
		String pk_curr = pvo.getPk_curr();
		String paybillunit = pvo.getPaybillunit();
		String paybillunit_v = pvo.getPaybillunit_v();
		// begin_luxiong7_20181205_电票签收后才能关联，不需要此校验
		// NCC-178601 前端已经进行控制，这里不需要校验，另外这个校验不对
//		String fbmbilltype = pvo.getFbmbilltype();
//		if (fbmbilltype.equals(FbmBusConstant.PKNOTETYPE_BANK) || fbmbilltype.equals(FbmBusConstant.PKNOTETYPE_BUSI)) {// 非电票需要此校验
//			GatherCheckUtil.checkHasReceiveComplete(aggVOs);
//		}
		// bend_luxiong7_20181205_电票签收后才能关联，不需要此校验

		if (!FbmPublicUtil.isCMPInitDateEnable(pk_group, pk_org)) {
			throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
					"03618fbm_add02-0107")/* @res "现金管理模块未启用" *//* @res "现金管理模块未启用！" */);
		}

		if (!FbmPublicUtil.isTogatherWithOther(pk_org, FBMSysParamConst.INTEGRATED_APPLY)) {// luxiong7
			throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3637fbm_add_0",
					"03637fbm_add-0004")/* @res "票据管理与现金管理或应收应付没有集成应用，不能执行此操作！" */);
		}

//			UFDate busidate = TMBusiDateManager.getTMBusiDate();
		UFDate busidate = AppContext.getInstance().getBusiDate();

		// 取得组织本币汇率
		UFDouble orgcurrrate = TMCurrencyUtil.getOrgCurrRate(pk_org, pk_curr, busidate);
		// 取得集团本币汇率
		UFDouble glcurrrate = TMCurrencyUtil.getGroupCurrRate(pk_group, pk_org, pk_curr, busidate);
		// 取得全局本币汇率
		UFDouble gllcurrrate = TMCurrencyUtil.getGlobalCurrRate(pk_org, pk_curr, busidate);
		// 原币金额合计
		UFDouble summoney_cr = new UFDouble();
		// 组织本币金额合计
		UFDouble sumolcmoney_cr = new UFDouble();
		// 集团本币金额合计
		UFDouble sumglcmoney_cr = new UFDouble();
		// 全局本币金额合计
		UFDouble sumgllcmoney_cr = new UFDouble();

		CustSupplierVO custSupplierVO = FBMPrivateServiceProxy.getCustSupQueryService().queryCustSupVOByPk(pvo.getPaybillunit());
		RecBillAggVO recbillaggvo = new RecBillAggVO();
		RecBillDetailVO[] childrenvos = new RecBillDetailVO[aggVOs.length];
		AggRegisterVO aggvo = null;
		for (int i = 0; i < childrenvos.length; i++) {
			aggvo = aggVOs[i];
			childrenvos[i] = new RecBillDetailVO();
			childrenvos[i].setPk_org(pk_org);// 主组织
			childrenvos[i].setPk_org_v(pk_org_v);
			childrenvos[i].setPk_fiorg(pk_org);// 财务组织pk_fiorg为票据主组织
			childrenvos[i].setPk_fiorg_v(pk_org_v);
			childrenvos[i].setPk_group(pk_group);// 集团
//				childrenvos[i].setPrepay(0);// 收款性质为应收款
			childrenvos[i].setNote_type(aggvo.getparentVO().getFbmbilltype());// 票据类型note_type
			childrenvos[i].setNote_no(aggvo.getparentVO().getPk_register());// 票据主键
			childrenvos[i].setPk_currtype(pk_curr);// 币种
			childrenvos[i].setDirection(1);// 方向 1=收，-1=付
			childrenvos[i].setRec_primal(aggvo.getparentVO().getMoney());// 收款原币金额 rec_primal
			childrenvos[i].setLocal_rate(orgcurrrate);// 组织本币汇率local_rate
			childrenvos[i].setGroup_rate(glcurrrate);// 集团本币汇率group_rate
			childrenvos[i].setGlobal_rate(gllcurrrate);// 全局本币汇率global_rate
			childrenvos[i].setBill_date(busidate);// 单据日期bill_date为业务日期
			childrenvos[i].setCreator(getUser());// 创建人为当前登录用户
			childrenvos[i].setCreationtime(AppContext.getInstance().getServerTime());// 创建时间为系统时间
//				childrenvos[i].setBusidate(busidate);// 起算日期为业务日期
			childrenvos[i].setBill_type(pk_desbilltype);// 单据类型bill_type
			childrenvos[i].setBillclass(billclass);// 单据大类为收款结算单
			//设置供应商和客户
			if (custSupplierVO != null && custSupplierVO.getCustsuptype() != null) {
				if (custSupplierVO.getCustsuptype().intValue() == 2) {
					childrenvos[i].setPk_supplier(paybillunit);
					childrenvos[i].setPkSupplierV(paybillunit_v);					
					childrenvos[i].setObjecttype(1);// 往来对象为供应商
				} else if (custSupplierVO.getCustsuptype().intValue() == 1) {
					childrenvos[i].setPk_customer(paybillunit);
					childrenvos[i].setPkCustomerV(paybillunit_v);
					childrenvos[i].setObjecttype(0);// 往来对象为客户
				}else{
					childrenvos[i].setPk_customer(paybillunit);
					childrenvos[i].setPkCustomerV(paybillunit_v);
					//childrenvos[i].setPk_supplier(paybillunit);
					//childrenvos[i].setPkSupplierV(paybillunit_v);
					childrenvos[i].setObjecttype(0);// 往来对象为客户
				}
			}
			
			// 汇率三个字段传表体
			childrenvos[i].setOlcratetype(pvo.getOlcratetype());
			childrenvos[i].setOlcratecategory(pvo.getOlcratecategory());
			childrenvos[i].setOlcratedate(pvo.getOlcratedate());

			summoney_cr = summoney_cr.add(aggvo.getparentVO().getMoney());

			// 取得组织本币金额
			UFDouble orgmoney = TMCurrencyUtil.getOrgLocalMoney(pk_org, pk_curr, aggvo.getparentVO().getMoney(),
					orgcurrrate, busidate, pvo.getOlcratetype());
			// 设置组织本币金额精度
			if (orgmoney != null) {
				orgmoney = FbmPublicUtil.getOrgDigitmoney(pk_org, pk_curr, orgmoney);
				sumolcmoney_cr = sumolcmoney_cr.add(orgmoney);
			}
			childrenvos[i].setRec_local(orgmoney);// 收款组织本币金额 rec_local

			// 取得集团本币金额
			UFDouble glmoney = TMCurrencyUtil.getGroupLocalMoney(pk_group, pk_org, pk_curr,
					aggvo.getparentVO().getMoney(), glcurrrate, orgcurrrate, busidate);
			// 设置集团本币金额精度
			if (glmoney != null) {
				glmoney = FbmPublicUtil.getGroupDigitmoney(pk_group, pk_org, pk_curr, glmoney);
				sumglcmoney_cr = sumglcmoney_cr.add(glmoney);
			}
			childrenvos[i].setGroup_local_rec(glmoney);// 收款集团本币金额 group_local_rec

			// 取得全局本币金额
			UFDouble gllmoney = TMCurrencyUtil.getGlobalLocalMoney(pk_org, pk_curr, aggvo.getparentVO().getMoney(),
					gllcurrrate, orgcurrrate, busidate);
			// 设置全局本币金额精度
			if (gllmoney != null) {
				gllmoney = FbmPublicUtil.getGlobalDigitmoney(pk_org, pk_curr, gllmoney);
				sumgllcmoney_cr = sumgllcmoney_cr.add(gllmoney);
			}
			childrenvos[i].setGlobal_local_rec(glmoney);// 收款全局本币金额
			// 2022.07需求：收票登记关联资金收款单带出业务员、业务组织(来自收票登记的业务组织字段)、部门
			childrenvos[i].setPk_busiman(aggvo.getparentVO().getPsn());
			childrenvos[i].setPk_busiorg(aggvo.getparentVO().getPk_entrustorg());
			childrenvos[i].setPk_busiorg_v(aggvo.getparentVO().getPk_entrustorg_v());
			childrenvos[i].setPk_dept(aggvo.getparentVO().getDept());
			//设置区间信息
			childrenvos[i].setBillrange(aggvo.getparentVO().getBillrange());
			childrenvos[i].setBillrangestart(aggvo.getparentVO().getBillrangestart());
			childrenvos[i].setBillrangeend(aggvo.getparentVO().getBillrangeend());
			childrenvos[i].setPk_billtypecode(aggvo.getparentVO().getPk_billtypecode());
			childrenvos[i].setSubcontractcirculation(aggvo.getparentVO().getSubcontractcirculation());

		}

		RecBillVO parentvo = new RecBillVO();
		parentvo.setPk_org(pk_org);// 主组织
		parentvo.setPk_org_v(pk_org_v);
		parentvo.setPk_fiorg(pk_org);// 财务组织为票据主组织
		parentvo.setPk_fiorg_v(pk_org_v);
		parentvo.setPk_group(pk_group);// 集团
		parentvo.setPk_currtype(pk_curr);// 币种
		parentvo.setBillmaker(getUser());// 制单人为当前登录用户
		parentvo.setBill_date(busidate);// 单据日期为业务日期billmaker_date
		parentvo.setBillmaker_date(busidate);// 制单日期为业务日期billmaker_date
//			parentvo.setBusidate(busidate);// 起算日期为业务日期
		parentvo.setCreator(getUser());// 创建人为当前登录用户
		parentvo.setCreationtime(AppContext.getInstance().getServerTime());// 创建时间为系统时间
		parentvo.setBill_type(pk_desbilltype);// 单据类型
		parentvo.setBillclass(billclass);// 单据大类为收款
//			parentvo.setTrade_type(tradetype);// 交易类型
//			parentvo.setPk_tradetypeid(PfDataCache.getBillType(tradetype) == null ? null
//					: PfDataCache.getBillType(tradetype).getPk_billtypeid());
//			parentvo.setSyscode(0);// 所属系统
		parentvo.setSource_flag("8");// 来源系统source_flag (来源于:票据管理)
		parentvo.setBill_status(-10);// 单据状态为自由态
		parentvo.setPrimal_money(summoney_cr);// 收款原币金额
		parentvo.setLocal_rate(orgcurrrate);// 组织本币汇率
		parentvo.setGroup_rate(glcurrrate);// 集团本币汇率
		parentvo.setGlobal_rate(gllcurrrate);// 全局本币汇率
		parentvo.setLocal_money(sumolcmoney_cr);// 收款组织本币金额
		parentvo.setGroup_local(sumglcmoney_cr);// 收款集团本币金额
		parentvo.setGlobal_local(sumgllcmoney_cr);// 收款全局本币金额
		// 票据号
		parentvo.setNote_no(aggvo.getparentVO().getPk_register());// 票据主键
		// 票据类型
		parentvo.setNote_type(aggvo.getparentVO().getFbmbilltype());
		//设置供应商和客户
		if (custSupplierVO != null && custSupplierVO.getCustsuptype() != null) {
			if (custSupplierVO.getCustsuptype().intValue() == 2) {
				parentvo.setPk_supplier(paybillunit);
				parentvo.setPkSupplierV(paybillunit_v);					
				parentvo.setObjecttype(1);// 往来对象为供应商
			} else if (custSupplierVO.getCustsuptype().intValue() == 1)  {
				parentvo.setPk_customer(paybillunit);
				parentvo.setPkCustomerV(paybillunit_v);
				parentvo.setObjecttype(0);// 往来对象为客户
			}else{
				parentvo.setPk_customer(paybillunit);
				parentvo.setPkCustomerV(paybillunit_v);
				//parentvo.setPk_supplier(paybillunit);
				//parentvo.setPkSupplierV(paybillunit_v);
				parentvo.setObjecttype(0);// 往来对象为客户
			}
		}
		recbillaggvo.setParent(parentvo);
		recbillaggvo.setChildrenVO(childrenvos);
		return recbillaggvo;

	}

	/**
	 *  收票登记关联收款单，组装收款单VO
	 * @param aggVOs
	 * @param pk_billtypecode
	 * @return 收款单的聚合VO
	 * @throws BusinessException
	 */
	private AggregatedValueObject gatheringbill(AggRegisterVO[] aggVOs, String pk_billtypecode)
			throws BusinessException {
//		String funcode = "20060GBR";
		String pk_desbilltype = "F2";
//		String tradetype = "D2";
		String billclass = "sk";
		IDeptPubService deptSrv = NCLocator.getInstance().lookup(IDeptPubService.class);

		RegisterVO pvo = aggVOs[0].getparentVO();
		String pk_org = pvo.getPk_org();
		String pk_org_v = pvo.getPk_org_v();
		String pk_group = pvo.getPk_group();
		String pk_curr = pvo.getPk_curr();
		String paybillunit = pvo.getPaybillunit();
		String gatherplanitem = pvo.getGatherplanitem();
		String paybillunit_v = pvo.getPaybillunit_v();
		
		CustSupplierVO custSupplierVO = FBMPrivateServiceProxy.getCustSupQueryService().queryCustSupVOByPk(pvo.getPaybillunit());

		// begin_luxiong7_20181205_电票签收后才能关联，不需要此校验
		String fbmbilltype = pvo.getFbmbilltype();
		if (fbmbilltype.equals(FbmBusConstant.PKNOTETYPE_BANK) || fbmbilltype.equals(FbmBusConstant.PKNOTETYPE_BUSI)) {// 非电票需要此校验
			GatherCheckUtil.checkHasReceiveComplete(aggVOs);
		}
		// bend_luxiong7_20181205_电票签收后才能关联，不需要此校验

		if (!FbmPublicUtil.isAREnable(pk_group)) {
			throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3637fbm_add_0",
					"03637fbm_add-0003")/* @res "应收模块未启用！" */);
		}

		if (!FbmPublicUtil.isTogatherWithOther(pk_org, FBMSysParamConst.INTEGRATED_APPLY)) {
			throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3637fbm_add_0",
					"03637fbm_add-0004")/* @res "票据管理与现金管理或应收应付没有集成应用，不能执行此操作！" */);
		}

//			UFDate busidate = TMBusiDateManager.getTMBusiDate();
		UFDate busidate = AppContext.getInstance().getBusiDate();

		// 取得组织本币汇率
		UFDouble orgcurrrate = TMCurrencyUtil.getOrgCurrRate(pk_org, pk_curr, busidate);
		// 取得集团本币汇率
		UFDouble glcurrrate = TMCurrencyUtil.getGroupCurrRate(pk_group, pk_org, pk_curr, busidate);
		// 取得全局本币汇率
		UFDouble gllcurrrate = TMCurrencyUtil.getGlobalCurrRate(pk_org, pk_curr, busidate);
		// 原币金额合计
		UFDouble summoney_cr = new UFDouble();
		// 组织本币金额合计
		UFDouble sumolcmoney_cr = new UFDouble();
		// 集团本币金额合计
		UFDouble sumglcmoney_cr = new UFDouble();
		// 全局本币金额合计
		UFDouble sumgllcmoney_cr = new UFDouble();

		AggGatheringBillVO araggvo = new AggGatheringBillVO();
		GatheringBillItemVO[] childrenvos = new GatheringBillItemVO[aggVOs.length];
		
		// 收款单表体部分赋值
		for (int i = 0; i < childrenvos.length; i++) {
			AggRegisterVO aggvo = aggVOs[i];
			childrenvos[i] = new GatheringBillItemVO();
			childrenvos[i].setPk_org(pk_org);// 主组织
			childrenvos[i].setPk_org_v(pk_org_v);
			childrenvos[i].setSett_org(pk_org);// 结算财务组织为票据主组织
			childrenvos[i].setSett_org_v(pk_org_v);
			childrenvos[i].setPk_group(pk_group);// 集团childrenvos[i].setPrepay(0);// 收款性质为应收款
			childrenvos[i].setChecktype(aggvo.getparentVO().getFbmbilltype());// 票据类型
			childrenvos[i].setCheckno(aggvo.getparentVO().getPk_register());// 票据主键
			childrenvos[i].setPk_currtype(pk_curr);// 币种
			childrenvos[i].setDirection(-1);
			childrenvos[i].setMoney_cr(aggvo.getparentVO().getMoney());// 原币金额
			childrenvos[i].setRate(orgcurrrate);// 组织本币汇率
			childrenvos[i].setGrouprate(glcurrrate);// 集团本币汇率
			childrenvos[i].setGlobalrate(gllcurrrate);// 全局本币汇率
			childrenvos[i].setBilldate(busidate);// 制单日期为业务日期
			childrenvos[i].setBusidate(busidate);// 起算日期为业务日期
			childrenvos[i].setPk_billtype(pk_desbilltype);// 单据类型
			childrenvos[i].setBillclass(billclass);// 单据大类为收款
			// 设置供应商和客户
			if (custSupplierVO != null && custSupplierVO.getCustsuptype() != null) {
				if (custSupplierVO.getCustsuptype().intValue() == 2) {
					childrenvos[i].setSupplier(paybillunit);
					childrenvos[i].setSupplier_v(paybillunit_v);
					childrenvos[i].setObjtype(1);// 往来对象为供应商
				} else if (custSupplierVO.getCustsuptype().intValue() == 1){
					childrenvos[i].setCustomer(paybillunit);
					childrenvos[i].setCustomer_v(paybillunit_v);
					childrenvos[i].setObjtype(0);// 往来对象为客户
				}else{
					childrenvos[i].setCustomer(paybillunit);
					childrenvos[i].setCustomer_v(paybillunit_v);
					//childrenvos[i].setSupplier(paybillunit);
					//childrenvos[i].setSupplier_v(paybillunit_v);
					childrenvos[i].setObjtype(0);// 往来对象为客户
				}
			}

			summoney_cr = summoney_cr.add(aggvo.getparentVO().getMoney());

			// 取得组织本币金额
			UFDouble orgmoney = TMCurrencyUtil.getOrgLocalMoney(pk_org, pk_curr, aggvo.getparentVO().getMoney(),
					orgcurrrate, busidate, pvo.getOlcratetype());
			// 设置组织本币金额精度
			if (orgmoney != null) {
				orgmoney = FbmPublicUtil.getOrgDigitmoney(pk_org, pk_curr, orgmoney);
				sumolcmoney_cr = sumolcmoney_cr.add(orgmoney);
			}
			childrenvos[i].setLocal_money_cr(orgmoney);

			// 取得集团本币金额
			UFDouble glmoney = TMCurrencyUtil.getGroupLocalMoney(pk_group, pk_org, pk_curr,
					aggvo.getparentVO().getMoney(), glcurrrate, orgcurrrate, busidate);
			// 设置集团本币金额精度
			if (glmoney != null) {
				glmoney = FbmPublicUtil.getGroupDigitmoney(pk_group, pk_org, pk_curr, glmoney);
				sumglcmoney_cr = sumglcmoney_cr.add(glmoney);
			}
			childrenvos[i].setGroupcrebit(glmoney);

			// 取得全局本币金额
			UFDouble gllmoney = TMCurrencyUtil.getGlobalLocalMoney(pk_org, pk_curr, aggvo.getparentVO().getMoney(),
					gllcurrrate, orgcurrrate, busidate);
			// 设置全局本币金额精度
			if (gllmoney != null) {
				gllmoney = FbmPublicUtil.getGlobalDigitmoney(pk_org, pk_curr, gllmoney);
				sumgllcmoney_cr = sumgllcmoney_cr.add(gllmoney);
			}
			childrenvos[i].setGlobalcrebit(gllmoney);

			// 2022.07需求：收票登记关联收款单时带出业务员、业务组织(来自收票登记的业务组织字段)及业务部门
			childrenvos[i].setPk_psndoc(aggvo.getparentVO().getPsn());
			childrenvos[i].setSo_org(aggvo.getparentVO().getPk_entrustorg());
			childrenvos[i].setSo_org_v(aggvo.getparentVO().getPk_entrustorg_v());
			childrenvos[i].setSo_deptid(aggvo.getparentVO().getDept());
			//设置区间信息
			//childrenvos[i].setBillrange(aggvo.getparentVO().getBillrange());
			childrenvos[i].setBillrangestart(aggvo.getparentVO().getBillrangestart());
			childrenvos[i].setBillrangeend(aggvo.getparentVO().getBillrangeend());
			String[] deptv = deptSrv.queryPkVidByIdAndDateArea(aggvo.getparentVO().getDept(), busidate.toString());
			if (ArrayUtils.isNotEmpty(deptv)) {
				childrenvos[i].setSo_deptid_v(deptv[0]);
			}
		}

		// 收款单表头部分赋值
		GatheringBillVO parentvo = new GatheringBillVO();
		parentvo.setPk_org(pk_org);// 主组织
		parentvo.setPk_org_v(pk_org_v);
		parentvo.setSett_org(pk_org);// 结算财务组织为票据主组织
		parentvo.setSett_org_v(pk_org_v);
		parentvo.setPk_group(pk_group);// 集团parentvo.setPk_currtype(pk_curr);// 币种
		parentvo.setBillmaker(getUser());// 制单人为当前登录用户
		parentvo.setBilldate(busidate);// 制单日期为业务日期
		parentvo.setBusidate(busidate);// 起算日期为业务日期
		parentvo.setCreator(getUser());// 创建人为当前登录用户
		parentvo.setCreationtime(AppContext.getInstance().getServerTime());// 创建时间为系统时间
		parentvo.setPk_billtype(pk_desbilltype);// 单据类型
		parentvo.setBillclass(billclass);// 单据大类为收款
		parentvo.setSyscode(0);// 所属系统
		parentvo.setSrc_syscode(0);// 来源系统
		parentvo.setBillstatus(-1);// 单据状态为自由态
		parentvo.setMoney(summoney_cr);// 原币金额合计
		parentvo.setRate(orgcurrrate);// 组织本币汇率
		parentvo.setGrouprate(glcurrrate);// 集团本币汇率
		parentvo.setGlobalrate(gllcurrrate);// 全局本币汇率
		parentvo.setLocal_money(sumolcmoney_cr);// 组织本币金额合计
		parentvo.setGrouplocal(sumglcmoney_cr);// 集团本币金额合计
		parentvo.setGloballocal(sumgllcmoney_cr);// 全局本币金额合计
		parentvo.setBankrollprojet(gatherplanitem);// 资金计划项目
		// 设置供应商和客户
		if (custSupplierVO != null && custSupplierVO.getCustsuptype() != null) {
			if (custSupplierVO.getCustsuptype().intValue() == 2) {
				//供应商
				parentvo.setSupplier(paybillunit);
				parentvo.setSupplier_v(paybillunit_v);
				parentvo.setObjtype(1);// 往来对象为供应商
			} else if (custSupplierVO.getCustsuptype().intValue() == 1){
				//客户
				parentvo.setCustomer(paybillunit);
				parentvo.setCustomer_v(paybillunit_v);
				parentvo.setObjtype(0);// 往来对象为客户
			}else{
				//客商
				parentvo.setCustomer(paybillunit);
				parentvo.setCustomer_v(paybillunit_v);
				//parentvo.setSupplier(paybillunit);
				//parentvo.setSupplier_v(paybillunit_v);
				parentvo.setObjtype(0);// 往来对象为客户
			}
		}
		araggvo.setParentVO(parentvo);
		araggvo.setChildrenVO(childrenvos);
		return araggvo;

	}

	/**
	 *  收票登记关联委托收款单，组装委托收款单VO
	 * @param aggVOs
	 * @param pk_billtypecode
	 * @return 委托收款单的聚合VO
	 * @throws BusinessException
	 */
	private AggregatedValueObject commissionBill(AggRegisterVO[] aggVOs, String pk_billtypecode)
			throws BusinessException {
//		String funcode = "36300TG"; // 功能编码
		String pk_vsourcebilltype = "36H1"; // 来源单据类型
		if (aggVOs != null && aggVOs.length > 0) {
			RegisterVO pvo = aggVOs[0].getparentVO();
			String pk_org = pvo.getPk_org();
			String pk_org_v = pvo.getPk_org_v();
			String pk_group = pvo.getPk_group();
			String pk_curr = pvo.getPk_curr();

			// begin_luxiong7_20181214_只有资金组织才能关联委托收款
			boolean isFundOrg = NCLocator.getInstance().lookup(IFundOrgPubService.class).isFundOrg(pk_org);
			if (!isFundOrg) {// 非资金组织不生成
				throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
						"03618fbm_add02-0089")/* @res "当前财务组织不是资金组织，无法关联生成委托收款单！" */);
			}
			// end_luxiong7_20181214_只有资金组织才能关联委托收款

			// begin_luxiong7_20181205_电票签收后才能关联，不需要此校验
			String fbmbilltype = pvo.getFbmbilltype();
			if (fbmbilltype.equals(FbmBusConstant.PKNOTETYPE_BANK)
					|| fbmbilltype.equals(FbmBusConstant.PKNOTETYPE_BUSI)) {// 非电票需要此校验
				GatherCheckUtil.checkHasReceiveComplete(aggVOs);
			}

			// bend_luxiong7_20181205_电票签收后才能关联，不需要此校验
			if (!FbmPublicUtil.isFTSEnable(pk_group)) {
				throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
						"03618fbm_add02-0090")/* @res "结算中心未启用" *//* @res "结算中心未启用！" */);
			}

			if (!FbmPublicUtil.isTogatherWithOther(pk_org, FBMSysParamConst.INTEGRATED_APPLY)) {// luxiong7
																								// 票据业务是否与结算中心集成应用
				throw new BusinessException(
						nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0091")
								/* @res "当前组织业务参数：" */ + FBMSysParamConst.INTEGRATED_APPLY
								+ nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
										"03618fbm_add02-0092")/* @res "没有启用,请检查" */);
			}

//			UFDate busidate = TMBusiDateManager.getTMBusiDate();
			UFDate busidate = AppContext.getInstance().getBusiDate();

			// 取得组织本币汇率
			UFDouble orgcurrrate = TMCurrencyUtil.getOrgCurrRate(pk_org, pk_curr, busidate);
			// 取得集团本币汇率
			UFDouble glcurrrate = TMCurrencyUtil.getGroupCurrRate(pk_group, pk_org, pk_curr, busidate);
			// 取得全局本币汇率
			UFDouble gllcurrrate = TMCurrencyUtil.getGlobalCurrRate(pk_org, pk_curr, busidate);
			// 原币金额合计
			UFDouble summoney_cr = new UFDouble();
			// 组织本币金额合计
			UFDouble sumolcmoney_cr = new UFDouble();
			// 集团本币金额合计
			UFDouble sumglcmoney_cr = new UFDouble();
			// 全局本币金额合计
			UFDouble sumgllcmoney_cr = new UFDouble();

			AggGatheringVO aggVO = new AggGatheringVO();
			GatherFinanceVO[] childrenvos = new GatherFinanceVO[aggVOs.length];// 委收财务信息实体 GatherFinanceVO
			GatherFundVO[] fund_childrenvos = new GatherFundVO[aggVOs.length];// 委收资金信息实体 GatherFundVO
			AggRegisterVO aggvo = null;

			// 委收财务信息实体 GatherFinanceVO
			for (int i = 0; i < childrenvos.length; i++) {
				aggvo = aggVOs[i];
				childrenvos[i] = new GatherFinanceVO();
				childrenvos[i].setPk_org(pk_org);// 主组织
				childrenvos[i].setPk_org_v(pk_org_v);
				childrenvos[i].setPk_group(pk_group);// 集团
//				childrenvos[i].setAmount(aggvo.getparentVO().getMoney());// 收款金额 amount
				childrenvos[i].setOlcrate(orgcurrrate);// 组织本币汇率local_rate
				childrenvos[i].setGlcrate(glcurrrate);// 集团本币汇率group_rate
				childrenvos[i].setGllcrate(gllcurrrate);// 全局本币汇率global_rate
				childrenvos[i].setFundtype(null);// 货币形态
				childrenvos[i].setPk_balatype(null);// 结算方式
				childrenvos[i].setVsourcecode(aggvo.getparentVO().getVbillno());// 来源单据号
				childrenvos[i].setRecmodule("FBM");// 来源模块
				childrenvos[i].setPk_srcbill(aggvo.getparentVO().getPk_register());// 来源单据标识
				childrenvos[i].setAddress_p(null);// 付款方单位地址
//				childrenvos[i].setBankaccount_p(aggvo.getparentVO().getPaybank());//付款方银行帐号
				childrenvos[i].setBankname_p(null);// 付款方开户银行名称
//				childrenvos[i].setCompany_p(aggvo.getparentVO().getPaybillunit());//付款方单位名称=付票单位
//				childrenvos[i].set+Pk_bankaccount_p(aggvo.getparentVO().getHidepaybankacc());//付款方银行帐号标识
				childrenvos[i].setPk_bankname_p(null);// 付款方开户银行标识
				childrenvos[i].setOrigetmode("note");// 约定收款方式 =票据收款
				childrenvos[i].setPk_company_p(pvo.getPaybillunit());// 付款客商标识
				childrenvos[i].setPk_company_p_v(pvo.getPaybillunit_v());// 付款客商标识
//				childrenvos[i].setPk_financeorg_r(pk_org);// 收款方财务组织
//				childrenvos[i].setPk_financeorg_v(pk_org_v);// 收款方财务组织版本
//				childrenvos[i].setPk_financeplan(aggvo.getparentVO().getGatherplanitem());// 单位收款计划项目
//				childrenvos[i].setPk_inneraccount_r(aggvo.getparentVO().getPk_inbalaacc());//收款方内部账户 pk_inbalaacc

				summoney_cr = summoney_cr.add(aggvo.getparentVO().getMoney());

				// 取得组织本币金额
				UFDouble orgmoney = TMCurrencyUtil.getOrgLocalMoney(pk_org, pk_curr, aggvo.getparentVO().getMoney(),
						orgcurrrate, busidate,pvo.getOlcratetype());
				// 设置组织本币金额精度
				if (orgmoney != null) {
					orgmoney = FbmPublicUtil.getOrgDigitmoney(pk_org, pk_curr, orgmoney);
					sumolcmoney_cr = sumolcmoney_cr.add(orgmoney);
				}
				childrenvos[i].setOlcamount(orgmoney);// 收款组织本币金额 rec_local

				// 取得集团本币金额
				UFDouble glmoney = TMCurrencyUtil.getGroupLocalMoney(pk_group, pk_org, pk_curr,
						aggvo.getparentVO().getMoney(), glcurrrate, orgcurrrate, busidate);
				// 设置集团本币金额精度
				if (glmoney != null) {
					glmoney = FbmPublicUtil.getGroupDigitmoney(pk_group, pk_org, pk_curr, glmoney);
					sumglcmoney_cr = sumglcmoney_cr.add(glmoney);
				}
				childrenvos[i].setGlcamount(glmoney);// 收款集团本币金额 group_local_rec

				// 取得全局本币金额
				UFDouble gllmoney = TMCurrencyUtil.getGlobalLocalMoney(pk_org, pk_curr, aggvo.getparentVO().getMoney(),
						gllcurrrate, orgcurrrate, busidate);
				// 设置全局本币金额精度
				if (gllmoney != null) {
					gllmoney = FbmPublicUtil.getGlobalDigitmoney(pk_org, pk_curr, gllmoney);
					sumgllcmoney_cr = sumgllcmoney_cr.add(gllmoney);
				}
				childrenvos[i].setGllcamount(glmoney);// 收款全局本币金额
			}

			// 委收资金信息实体 GatherFundVO
			for (int i = 0; i < fund_childrenvos.length; i++) {
				aggvo = aggVOs[i];
				fund_childrenvos[i] = new GatherFundVO();
				fund_childrenvos[i].setPk_org(pk_org);// 主组织
				fund_childrenvos[i].setPk_org_v(pk_org_v);
				fund_childrenvos[i].setPk_group(pk_group);// 集团
				fund_childrenvos[i].setBillno(aggvo.getparentVO().getFbmbillno());// 收款票据号
				fund_childrenvos[i].setAmount(aggvo.getparentVO().getMoney());// 收款金额 amount
				fund_childrenvos[i].setFeeamount(null);// 费用金额 feeamount
				fund_childrenvos[i].setFeedirection(null);// 费用方向
				fund_childrenvos[i].setFundtype(null);// 货币形态
				fund_childrenvos[i].setGetmode("note");// 收款方式 =票据收款
				fund_childrenvos[i].setOlcrate(orgcurrrate);// 组织本币汇率local_rate
				fund_childrenvos[i].setGlcrate(glcurrrate);// 集团本币汇率group_rate
				fund_childrenvos[i].setGllcrate(gllcurrrate);// 全局本币汇率global_rate
				fund_childrenvos[i].setGlcfeeamount(null);// 费用集团本币金额
				fund_childrenvos[i].setGllcfeeamount(null);// 费用全局本币金额
				fund_childrenvos[i].setOlcfeeamount(null);// 费用组织本币金额
				fund_childrenvos[i].setIsfees(null);// 是否费用
				fund_childrenvos[i].setMemo(null);// 备注
				fund_childrenvos[i].setPk_balatype(null);// 结算方式
				fund_childrenvos[i].setPk_bankaccount_r(null);// 收款银行账号
				fund_childrenvos[i].setPk_billno(aggvo.getparentVO().getPk_register());// 票据号标识=主键
				fund_childrenvos[i].setPk_cashaccount_r(null);// 收款现金账户
				fund_childrenvos[i].setPk_getplanitem(null);// 收款计划项目
				fund_childrenvos[i].setPk_notetype(aggvo.getparentVO().getFbmbilltype());// 收款票据类型
				fund_childrenvos[i].setPurpose(null);// 用途
				fund_childrenvos[i].setRelationindex(null);// 关联索引
				fund_childrenvos[i].setRowno(i);// 行号
				//设置区间信息
				//fund_childrenvos[i].setBillrange(aggvo.getparentVO().getBillrange());
				//fund_childrenvos[i].setBillrangestart(aggvo.getparentVO().getBillrangestart());
				//fund_childrenvos[i].setBillrangeend(aggvo.getparentVO().getBillrangeend());

//				summoney_cr = summoney_cr.add(aggvo.getparentVO().getMoney());

				// 取得组织本币金额
				UFDouble orgmoney = TMCurrencyUtil.getOrgLocalMoney(pk_org, pk_curr, aggvo.getparentVO().getMoney(),
						orgcurrrate, busidate,pvo.getOlcratetype());
				// 设置组织本币金额精度
				if (orgmoney != null) {
					orgmoney = FbmPublicUtil.getOrgDigitmoney(pk_org, pk_curr, orgmoney);
//					sumolcmoney_cr = sumolcmoney_cr.add(orgmoney);
				}
				fund_childrenvos[i].setOlcamount(orgmoney);// 组织本币金额

				// 取得集团本币金额
				UFDouble glmoney = TMCurrencyUtil.getGroupLocalMoney(pk_group, pk_org, pk_curr,
						aggvo.getparentVO().getMoney(), glcurrrate, orgcurrrate, busidate);
				// 设置集团本币金额精度
				if (glmoney != null) {
					glmoney = FbmPublicUtil.getGroupDigitmoney(pk_group, pk_org, pk_curr, glmoney);
//					sumglcmoney_cr = sumglcmoney_cr.add(glmoney);
				}
				fund_childrenvos[i].setGlcamount(glmoney);// 集团本币金额

				// 取得全局本币金额
				UFDouble gllmoney = TMCurrencyUtil.getGlobalLocalMoney(pk_org, pk_curr, aggvo.getparentVO().getMoney(),
						gllcurrrate, orgcurrrate, busidate);
				// 设置全局本币金额精度
				if (gllmoney != null) {
					gllmoney = FbmPublicUtil.getGlobalDigitmoney(pk_org, pk_curr, gllmoney);
//					sumgllcmoney_cr = sumgllcmoney_cr.add(gllmoney);
				}
				fund_childrenvos[i].setGllcamount(glmoney);// 全局本币金额
			}

			GatheringVO parentvo = new GatheringVO();
			parentvo.setPk_org(pk_org);// 主组织
			parentvo.setPk_org_v(pk_org_v);
			parentvo.setPk_transactorg(pk_org);// 办理资金组织
			parentvo.setPk_transactorg_v(pk_org_v);// 办理资金组织版本
			parentvo.setPk_fundgetorg(pk_org);// 收款资金组织 pk_fundgetorg
			parentvo.setPk_fundgetorg_v(pk_org_v);// 收款资金组织版本
			parentvo.setPk_group(pk_group);// 集团
			parentvo.setPk_currtype(pk_curr);// 委托币种
			parentvo.setPk_gathercurr(pk_curr);// 收款币种
			parentvo.setPk_billtype(pk_billtypecode);// 单据类型 委托收款
			parentvo.setPk_billtypeid(PfDataCache.getBillType(pk_billtypecode) == null ? null
					: PfDataCache.getBillType(pk_billtypecode).getPk_billtypeid());// 单据类型编码
			parentvo.setOlctotalamount(null);// 委托组织本币总金额
			parentvo.setGlctotalamount(null);// 委托集团本币总金额
			parentvo.setGllctotalamount(null);// 委托全局本币总金额
			parentvo.setRecmodul("FBM");// 来源模块
			parentvo.setVsourcebustype("billhand");// 来源业务类型
			parentvo.setVsourcecode(aggvo.getparentVO().getVbillno());// 来源单据号
			parentvo.setPk_vsourcebilltypeid(aggvo.getparentVO().getPk_billtypeid());// 来源单据类型
			parentvo.setPk_vsourcebilltype(pk_vsourcebilltype);// 来源单据类型编码
			// isautorelation

			parentvo.setAcceptdate(busidate);// 自动受理日期
			parentvo.setBillmaker(getUser());// 制单人为当前登录用户
			parentvo.setBilldate(busidate);// 制单日期为业务日期
			parentvo.setBillstatus(0);// 单据状态=待提交
			parentvo.setBilltime(AppContext.getInstance().getServerTime());// 制单时间系统时间
			parentvo.setBusidate(busidate);// 业务日期
			parentvo.setBusinessno(null);// 业务流水号
			parentvo.setCleardate(null);// 清算日期
			parentvo.setClearinacctype(null);// 清算传入账户类型
			parentvo.setClearinszdirection(null);// 清算传入收支类型
			parentvo.setClearoutacctype(null);// 清算传出账户类型
			parentvo.setClearoutszdirection(null);// 清算传出收支类型
			parentvo.setConsigndate(null);// 委托日期
			parentvo.setConsigner(null);// 委托人
			parentvo.setConsigntime(null);// 委托时间
			parentvo.setCreationtime(AppContext.getInstance().getServerTime());// 创建时间=系统时间
			parentvo.setCreator(getUser());// 创建人=当前登录用户
			parentvo.setCurroperator(null);// 当前处理人
			parentvo.setDecidedate(null);// 经办日期
			parentvo.setDecidetime(null);// 经办时间
			parentvo.setDecideuser(null);// 经办人
			parentvo.setDecidewfstatus(null);// 经办工作流状态
			parentvo.setDeliverdate(null);// 传递日期
			parentvo.setDelivertime(null);// 传递时间
			parentvo.setDelivertype(null);// 传递类型
			parentvo.setDeliveruser(null);// 传递人
			parentvo.setDeliverwfstatus(null);// 传递工作流状态
			parentvo.setDestdeliverdirection(null);// 去向传递方向
			parentvo.setEncryptkey(null);// 密文
			parentvo.setGatheringdate(null);// 收款日期
			parentvo.setGatheringtime(null);// 收款时间
			parentvo.setGatheringuser(null);// 收款人
			parentvo.setGatheringwfstatus(null);// 收款工作流状态
//			parentvo.setLocal_rate(orgcurrrate);// 组织本币汇率
//			parentvo.setGroup_rate(glcurrrate);// 集团本币汇率
//			parentvo.setGlobal_rate(gllcurrrate);// 全局本币汇率
//			//表头金额总和只需一个表体所有表体行金额之和
//			parentvo.setPrimal_money(summoney_cr);// 收款原币金额
//			parentvo.setLocal_money(sumolcmoney_cr);// 收款组织本币金额
//			parentvo.setGroup_local(sumglcmoney_cr);// 收款集团本币金额
//			parentvo.setGlobal_local(sumgllcmoney_cr);// 收款全局本币金额

			aggVO.setParent(parentvo);
			aggVO.setChildrenVO(childrenvos);
			aggVO.setChildrenVO(fund_childrenvos);

//			FuncletInitData initData = null;
//	        initData = new FuncletInitData();
//	        initData.setInitType(ILinkType.LINK_TYPE_ADD);
//	        initData.setInitData(aggVO );
//	        FuncRegisterVO funvo = WorkbenchEnvironment.getInstance().getFuncRegisterVO(funcode);
//	        FuncletWindowLauncher.openFuncNodeFrame((AbstractFunclet) getModel().getContext().getEntranceUI(),
//	        		funvo, initData, null, false, DialogTool.getWindowOfScreenCenter());
			return aggVO;
		}
		return null;
	}

	/**
	 * 获取当前操作人员
	 *
	 * @return
	 */
	private String getUser() {
		return InvocationInfoProxy.getInstance().getUserId();
	}

	/**
	 * 新增
	 *
	 * @param aggvo
	 * @return K
	 * @throws BusinessException
	 */
	@Override
	public AggRegisterVO pdfInsertGather(AggRegisterVO aggvo) throws BusinessException {

		RegisterVO registervo = (RegisterVO) aggvo.getParentVO();

		// 组织停用校验 modify by aishm 2013-03-26
		DefaultValidationService validateService = new DefaultValidationService();
		validateService.addValidator(new FinOrgUnUseValidator(new VOFieldDesc(RegisterVO.PK_ORG)));
		validateService.validate(aggvo);

		/**
		 * 数字签名
		 */
		FbmSignPubSecurityUtil.signDataAggVO(aggvo);

		// 取单据编号并设置
		String vbillno = FBMPrivateServiceProxy.getBillcodeManage().getBillCode_RequiresNew(
				registervo.getPk_billtypecode(), registervo.getPk_group(), registervo.getPk_org(), aggvo);
		registervo.setAttributeValue(FbmFieldConstant.VBILLNO, vbillno);

		// 更新数据库
		AggRegisterVO retvo = (AggRegisterVO) FbmPrivateUtil.updateAggVO(aggvo, VOStatus.NEW);

		return retvo;

	}

	/**
	 * 更新
	 *
	 * @param aggvo
	 * @return K
	 * @throws BusinessException
	 */
	@Override
	public AggRegisterVO pdfUpdateGather(AggRegisterVO aggvo) throws BusinessException {

		// xuhrc 20191126 云原生后端saga异常校验
		checkSagaStatus(aggvo);
		RegisterVO registervo = (RegisterVO) aggvo.getParentVO();
		// 将来源置为手工录入
		registervo.setGathertype(FbmBusConstant.GATHER_TYPE_INPUT);

		// begin_luxiong7_20180921_山西正华票据池票据签发部分补丁FBM
		UFBoolean initFlag = registervo.getInitflag();
		boolean isInitAccept = initFlag != null && initFlag.booleanValue()
				&& FbmBusConstant.BILLTYPE_INITACCEPT.equals(registervo.getPk_billtypecode());// 是期初应收
		boolean isEcd = false;// 是否电票
		String fbmBillType = registervo.getFbmbilltype();// 票据类别
		Integer billtypeclass = NCLocator.getInstance().lookup(IFbmPubQueryService.class)
				.queryNoteclassByPk(fbmBillType);// 票据大类
		if (billtypeclass != null && FbmBusConstant.ECD_FBMBILLTYPE.equals(billtypeclass)) {
			isEcd = true;
		}
		// 如果是电票,且非期初 ,收票日期不能早于电票启用日期
		if (!isInitAccept && isEcd) {
			// 轻量级票据保存校验
			Validator gatherSaveValidator = new GatherSaveValidator();
			IValidationService vEcdService = ValidationFrameworkUtil.createValidationService(gatherSaveValidator);
			vEcdService.validate(registervo);
		}
		// 校验业务单元期初期间 modify by aishm 2013-03-18
		CheckInitDateTool.checkInitData(RegisterVO.GATHERDATE,
				nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0", "03618fbm-0461")/* @res "收票日期" */,
				registervo.getGatherdate(), registervo.getPk_org(), registervo.getInitflag());

		// 非法票据的校验
		Validator saveIllegalGatherValidator = new SaveIllegalGatherValidator();
		IValidationService vService = ValidationFrameworkUtil.createValidationService(saveIllegalGatherValidator);
		vService.validate(aggvo.getParentVO());

		// begin_luxiong7_20180921_山西正华票据池票据签发部分补丁FBM
		if (registervo.getSignagrbank() != null && !registervo.getSignagrbank().trim().equals("")) {
			BankdocVO bankdocVOByPk = NCLocator.getInstance().lookup(IBankdocQueryService.class)
					.getBankdocVOByPk(registervo.getSignagrbank());
			if (bankdocVOByPk != null) {
				if (bankdocVOByPk.getPcombinenum() != null && !bankdocVOByPk.getPcombinenum().trim().equals("")) {
					registervo.setSignagrbanknum(bankdocVOByPk.getPcombinenum());
				} else {
//        			throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0","03618fbm_add02-0324")/*@res "所选择的承兑银行没有设置人行联行行号"*/);
				}
				if (bankdocVOByPk.getPcombinename() != null && !bankdocVOByPk.getPcombinename().trim().equals("")) {
					registervo.setSignagrbankname(bankdocVOByPk.getPcombinename());
				} else {
//        			throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0","03618fbm_add02-0325")/*@res "所选择的承兑银行没有设置人行联行名称"*/);
				}

			} else {
				throw new BusinessException(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
						"03618fbm_add02-0323")/* @res "根据所选择的承兑银行找不到相关银行档案" */);
			}
		}

		/**
		 * 数字签名
		 */
		FbmSignPubSecurityUtil.signDataAggVO(aggvo);

		if (billtypeclass != null && FbmBusConstant.ECD_FBMBILLTYPE.equals(billtypeclass)) {
			isEcd = true;
		}

		// 检验票据池登记银行承兑银行信息
		checkBankDoc(registervo);

		// 更新数据库
		AggRegisterVO retvo = (AggRegisterVO) FbmPrivateUtil.updateAggVO(aggvo, VOStatus.UPDATED);

		// 设置票据状态
		IStatusControlStrategy strategy = new SaveGather((RegisterVO) aggvo.getParentVO());
		StatusControlProcess.getInstance().process(strategy);

		return retvo;

	}

	/**
	 * 删除
	 *
	 * @param aggvo
	 * @return
	 * @throws BusinessException
	 */
	@Override
	public AggRegisterVO pdfDeleteGather(AggRegisterVO aggvo) throws BusinessException {

		// xuhrc 20191126 云原生后端saga异常校验
		checkSagaStatus(aggvo);
		RegisterVO registervo = (RegisterVO) aggvo.getParentVO();

		// 删除校验（非自由态单据不能删除）
		Validator deleteValidator = new FbmBaseDeleteValidator();
		IValidationService vService = ValidationFrameworkUtil.createValidationService(deleteValidator);
		vService.validate(aggvo.getParentVO());

		// 有关联关系的单据不能删除
		Validator outerValidator = new GatherOuterValidator();
		IValidationService outerService = ValidationFrameworkUtil.createValidationService(outerValidator);
		outerService.validate(aggvo.getParentVO());

		// 退单据号
		FBMPrivateServiceProxy.getBillcodeManage().returnBillCodeOnDelete(registervo.getPk_billtypecode(),
				registervo.getPk_group(), registervo.getPk_org(), registervo.getVbillno(), aggvo);

		FBMPrivateServiceProxy.getMDService().deleteBillFromDB(aggvo);

		return aggvo;

	}

	/**
	 * 处理票据上收和票据下拨 签收和取消签收
	 * 
	 * @param aggvo  收票登记
	 * @param isSign 是否签收 true 签收 false 取消签收
	 * @return void 返回类型
	 * @throws BusinessException
	 *
	 */
	private void processBillDeliveryAllocate(RegisterVO regvo, boolean isSign) throws BusinessException {
		// 真正实现逻辑需要修改 根据收票类型进行判断是否需要调用票据上收相关方法
		// 如果是电票才会调用票据上收和票据下拨
		if (FbmCommonTools.isEBill(regvo.getFbmbilltype())) {
			String fbmbillno = regvo.getFbmbillno();
			String pk_org = regvo.getPk_org();
			String pk_register = regvo.getPk_register();
			String gatherType = regvo.getGathertype();
			if (isSign) {
				if(FbmBusConstant.GATHER_TYPE_DELIVERY.equals(gatherType)) {
					// 真正实现逻辑需要修改 根据收票类型进行判断是否需要调用票据上收相关方法
					FBMPrivateServiceProxy.getBillDeliveryManageService().signBillByFbmbillno(
							pk_org,
							new String[] { fbmbillno }, pk_register);
				}else if(FbmBusConstant.GATHER_TYPE_ALLOCATE.equals(gatherType)) {
					FBMPrivateServiceProxy.getBillAllocateManageService().signBillByFbmbillno(pk_org,
							new String[] { fbmbillno }, pk_register);
				}
			} else {
				// 取消签收
				if(FbmBusConstant.GATHER_TYPE_DELIVERY.equals(gatherType)) {
					// 真正实现逻辑需要修改 根据收票类型进行判断是否需要调用票据上收相关方法
					FBMPrivateServiceProxy.getBillDeliveryManageService().unSignBillByFbmbillno(
							pk_org,
							new String[] { fbmbillno }, pk_register);
				} else if (FbmBusConstant.GATHER_TYPE_ALLOCATE.equals(gatherType)) {
					FBMPrivateServiceProxy.getBillAllocateManageService().unSignBillByFbmbillno(
							pk_org,
							new String[] { fbmbillno }, pk_register);
				}
			}
		}

	}


}
