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 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.GatherCancelApproveValidator;
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.tools.FbmPrivateUtil;
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.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.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.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.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.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.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.ml.NCLangRes4VoTransl;
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.pub.AggregatedValueObject;
import nc.vo.pub.BusinessException;
import nc.vo.pub.CircularlyAccessibleValueObject;
import nc.vo.pub.SuperVO;
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;
import org.apache.commons.lang3.ArrayUtils;

public class GatherManageServiceImpl implements IGatherManageService {
	public AggRegisterVO updateGatherWithoutStatusControl(AggRegisterVO aggvo) throws BusinessException {
		aggvo.getParentVO().setStatus(1);

		FBMPrivateServiceProxy.getMDService().saveBillWithRealDelete(aggvo);

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

	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(1);
				regarr.add((RegisterVO) aggvos[i].getParentVO());
			}

			FBMPrivateServiceProxy.getMDService()
					.saveBillWithRealDelete((CircularlyAccessibleValueObject[]) regarr.toArray(new RegisterVO[0]));

			return FbmPrivateUtil.queryAggvosByPKsNCC(aggvos);
		}
		return null;
	}

	public AggRegisterVO insertGather(AggRegisterVO aggvo) throws BusinessException {
		RegisterVO registervo = (RegisterVO) aggvo.getParentVO();

		Validator gatherSaveValidator = new GatherSaveValidator();
		IValidationService vEcdService = ValidationFrameworkUtil
				.createValidationService(new Validator[] { gatherSaveValidator });
		vEcdService.validate(registervo);

		DefaultValidationService validateService = new DefaultValidationService();
		validateService.addValidator(new FinOrgUnUseValidator(new VOFieldDesc[] { new VOFieldDesc("pk_org") }));
		validateService.validate(aggvo);

		Validator gatherSaveAndApproveValidator = new GatherSaveAndApproveValidator();

		IValidationService vgatherSaveAndApprovevice = ValidationFrameworkUtil
				.createValidationService(new Validator[] { gatherSaveAndApproveValidator });
		vgatherSaveAndApprovevice.validate(aggvo.getParentVO());

		Validator saveIllegalGatherValidator = new SaveIllegalGatherValidator();
		IValidationService vService = ValidationFrameworkUtil
				.createValidationService(new Validator[] { saveIllegalGatherValidator });
		vService.validate(aggvo.getParentVO());

		if (StringUtil.isNull(registervo.getHoldunit())) {
			registervo.setHoldunit(registervo.getPk_org());
		}

		ICustsupPubService cusService = (ICustsupPubService) NCLocator.getInstance().lookup(ICustsupPubService.class);
		String paybillunit = registervo.getPaybillunit();
		String entrustedpaybillunit = registervo.getEntrustedpaybillunit();
		// zhangxinah 去掉收票单位校验
		if (StringUtil.isNull(paybillunit) && StringUtil.isNull(entrustedpaybillunit)) {
			throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("3618ncc1_0", "03618ncc1-0000")
					+ NCLangRes4VoTransl.getNCLangRes().getStrByID("3618ncc1_0", "03618ncc1-0000")
					+ registervo.getFbmbillno());
		}

		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 = (String) 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("billallocate");
				}
			} else {
				registervo.setGathertype("billdelivery");
			}
		}

		checkBankDoc(registervo);

		if (registervo.getSignagrbank() != null && !registervo.getSignagrbank().trim().equals("")) {

			BankdocVO bankdocVOByPk = ((IBankdocQueryService) NCLocator.getInstance()
					.lookup(IBankdocQueryService.class)).getBankdocVOByPk(registervo.getSignagrbank());
			if (bankdocVOByPk != null) {
				if (bankdocVOByPk.getPcombinenum() != null && !bankdocVOByPk.getPcombinenum().trim().equals("")) {
					registervo.setSignagrbanknum(bankdocVOByPk.getPcombinenum());
				}

				if (bankdocVOByPk.getPcombinename() != null && !bankdocVOByPk.getPcombinename().trim().equals("")) {
					registervo.setSignagrbankname(bankdocVOByPk.getPcombinename());

				}

			} else {

				throw new BusinessException(
						NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0323"));
			}
		}

		String vbillno = FBMPrivateServiceProxy.getBillcodeManage().getBillCode_RequiresNew(
				registervo.getPk_billtypecode(), registervo.getPk_group(), registervo.getPk_org(), aggvo);
		registervo.setAttributeValue("vbillno", vbillno);

		FbmPrivateUtil.updateAggVO(aggvo, 2);

		FbmSignPubSecurityUtil.signDataAggVO(new AggregatedValueObject[] { aggvo });

		IStatusControlStrategy strategy = new SaveGather((RegisterVO) aggvo.getParentVO(), "add");
		StatusControlProcess.getInstance().process(strategy);

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

	private void checkBankDoc(RegisterVO registervo) throws BusinessException {
		if (registervo.getSignagrbank() != null && !registervo.getSignagrbank().trim().equals("")) {

			BankdocVO bankdocVOByPk = ((IBankdocQueryService) NCLocator.getInstance()
					.lookup(IBankdocQueryService.class)).getBankdocVOByPk(registervo.getSignagrbank());
			if (bankdocVOByPk != null) {
				if (!StringUtil.isNull(bankdocVOByPk.getPcombinenum())) {
					registervo.setSignagrbanknum(bankdocVOByPk.getPcombinenum());
				}

				if (!StringUtil.isNull(bankdocVOByPk.getPcombinename())) {
					registervo.setSignagrbankname(bankdocVOByPk.getPcombinename());

				}
			} else {

				throw new BusinessException(
						NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0323"));
			}
		}
	}

	public AggRegisterVO deleteGather(AggRegisterVO aggvo) throws BusinessException {
		checkSagaStatus(aggvo);
		RegisterVO registervo = (RegisterVO) aggvo.getParentVO();

		Validator deleteValidator = new FbmBaseDeleteValidator();
		IValidationService vService = ValidationFrameworkUtil
				.createValidationService(new Validator[] { deleteValidator });
		vService.validate(aggvo.getParentVO());

		Validator outerValidator = new GatherOuterValidator();
		IValidationService outerService = ValidationFrameworkUtil
				.createValidationService(new Validator[] { outerValidator });
		outerService.validate(aggvo.getParentVO());

		Validator delValidator = new GatherCanoperateValidator();
		IValidationService delService = ValidationFrameworkUtil
				.createValidationService(new Validator[] { delValidator });
		delService.validate(aggvo.getParentVO());

		IStatusControlStrategy strategy = new DeleteGather((RegisterVO) aggvo.getParentVO());
		StatusControlProcess.getInstance().process(strategy);

		if ("signinput".equals(registervo.getGathertype())) {
			((IBeforeRegisterManageService) 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;
	}

	public AggRegisterVO deleteAutoGatherFromEndore(AggRegisterVO aggvo) throws BusinessException {
		checkSagaStatus(aggvo);
		RegisterVO registervo = (RegisterVO) aggvo.getParentVO();

		Validator deleteValidator = new FbmBaseDeleteValidator();
		IValidationService vService = ValidationFrameworkUtil
				.createValidationService(new Validator[] { deleteValidator });
		vService.validate(aggvo.getParentVO());

		Validator outerValidator = new GatherOuterValidator();
		IValidationService outerService = ValidationFrameworkUtil
				.createValidationService(new Validator[] { outerValidator });
		outerService.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;
	}

	public AggRegisterVO updateGather(AggRegisterVO aggvo) throws BusinessException {
		checkSagaStatus(aggvo);
		RegisterVO registervo = (RegisterVO) aggvo.getParentVO();

		Validator gatherSaveValidator = new GatherSaveValidator();
		IValidationService vEcdService = ValidationFrameworkUtil
				.createValidationService(new Validator[] { gatherSaveValidator });
		vEcdService.validate(registervo);

		Validator saveIllegalGatherValidator = new SaveIllegalGatherValidator();
		IValidationService vService = ValidationFrameworkUtil
				.createValidationService(new Validator[] { saveIllegalGatherValidator });
		vService.validate(aggvo.getParentVO());

		if (registervo.getSignagrbank() != null && !registervo.getSignagrbank().trim().equals("")) {

			BankdocVO bankdocVOByPk = ((IBankdocQueryService) NCLocator.getInstance()
					.lookup(IBankdocQueryService.class)).getBankdocVOByPk(registervo.getSignagrbank());
			if (bankdocVOByPk != null) {
				if (bankdocVOByPk.getPcombinenum() != null && !bankdocVOByPk.getPcombinenum().trim().equals("")) {
					registervo.setSignagrbanknum(bankdocVOByPk.getPcombinenum());
				}

				if (bankdocVOByPk.getPcombinename() != null && !bankdocVOByPk.getPcombinename().trim().equals("")) {
					registervo.setSignagrbankname(bankdocVOByPk.getPcombinename());

				}
			} else {

				throw new BusinessException(
						NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0323"));
			}
		}

		AggRegisterVO oldAggVO = (AggRegisterVO) FbmPrivateUtil.queryAggvoByPK(aggvo);

		if (oldAggVO != null) {

			FbmSignPubSecurityUtil.verifySign(oldAggVO, "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);

		AggRegisterVO retvo = (AggRegisterVO) FbmPrivateUtil.updateAggVO(aggvo, 1);
		IStatusControlStrategy strategy = new SaveGather((RegisterVO) retvo.getParentVO(), "update");
		StatusControlProcess.getInstance().process(strategy);

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

	public AggRegisterVO unApproveGather(AggRegisterVO aggvo, boolean isEndStep, UFDate tallydate)
			throws BusinessException {
		checkSagaStatus(aggvo);

		Validator unApproveValidator = new GatherCancelApproveValidator();
		IValidationService vService = ValidationFrameworkUtil
				.createValidationService(new Validator[] { unApproveValidator });
		vService.validate(aggvo.getParentVO());

		Validator outerValidator = new GatherOuterValidator();
		IValidationService outerService = ValidationFrameworkUtil
				.createValidationService(new Validator[] { outerValidator });
		outerService.validate(aggvo.getParentVO());

		RegisterVO parentVO = aggvo.getparentVO();
		if (parentVO != null && parentVO.getSfflag() == UFBoolean.TRUE) {
			throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0", "03618fbm-1042"));
		}

		if (parentVO.getElcpaymentstatus() != null) {
			throw new BusinessException(
					NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0220"));
		}

		FbmPrivateUtil.updateAggVO(aggvo, 1);

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

	public AggRegisterVO approveGather(AggRegisterVO aggvo, boolean isEndStep) throws BusinessException {
		checkSagaStatus(aggvo);

		if (((RegisterVO) aggvo.getParentVO()).getDapprovedate() == null) {
			((RegisterVO) aggvo.getParentVO()).setDapprovedate(((RegisterVO) aggvo.getParentVO()).getDoperatedate());
		}

		if (aggvo.getparentVO().getDapprovedate() != null
				&& aggvo.getparentVO().getDapprovedate().beforeDate(aggvo.getparentVO().getDoperatedate())) {
			throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0", "03618fbm-1025"));
		}

		Validator outerValidator = new GatherOuterValidator();
		IValidationService vService = ValidationFrameworkUtil
				.createValidationService(new Validator[] { outerValidator });
		vService.validate(aggvo.getParentVO());

		FbmPrivateUtil.updateAggVO(aggvo, 1);

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

		if (isEndStep) {

			IStatusControlStrategy strategy = new AuditGather((RegisterVO) aggvo.getParentVO());
			StatusControlProcess.getInstance().process(strategy);

			FbmSignPubSecurityUtil.verifySign(aggvo, "approve", false, null);

			if (revo.getSfflag() != null && revo.getSfflag().booleanValue()
					&& (revo.getInitflag() == null || !revo.getInitflag().booleanValue())) {
				GatherBillAccAdapter billAdapter = new GatherBillAccAdapter();
				billAdapter.writeBillAcc(aggvo);

				if (FbmPublicUtil.isAutoVoucher(pk_org)) {
					FBMPrivateServiceProxy.getGatherManageService().voucherGatherVO(aggvo);
				}
			}

			if (revo.getInitflag() != null && revo.getInitflag().booleanValue()
					&& 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(Integer.valueOf(3));

		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(Integer.valueOf(3));

		vo.setModifiedtime(resvo.getApprovetime());
		vo.setModifier(resvo.getApprover());
		vo.setPk_account("3");
		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 };
	}

	public void batchConsignBank(List<AggRegisterVO> registerList) throws BusinessException {
	}

	public void batchDiscount(List<AggRegisterVO> registerList) throws BusinessException {
	}

	public void batchImpawn(List<AggRegisterVO> registerList) throws BusinessException {
	}

	public AggRegisterVO cancleGather(AggRegisterVO aggvo) throws BusinessException {
		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(new Validator[] { integratedValidator });
		IValidationService dateValidatorService = ValidationFrameworkUtil
				.createValidationService(new Validator[] { dateValidator });

		if (regvo.getSelfendore() == null || !regvo.getSelfendore().booleanValue()) {

			if (regvo.getOnlinebankflag() == null || !regvo.getOnlinebankflag().booleanValue()) {
				integratedValidatorService.validate(regvo);
				dateValidatorService.validate(regvo);
			}

			Validator outerValidator = new GatherOuterValidator();
			IValidationService outerService = ValidationFrameworkUtil
					.createValidationService(new Validator[] { outerValidator });
			outerService.validate(aggvo.getParentVO());
		}

		if (regvo.getBookflag() != null && regvo.getBookflag().booleanValue()) {
			throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0", "03618fbm-0717"));
		}

		if (regvo.getPlanflag() != null && regvo.getPlanflag().booleanValue()) {
			throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0", "03618fbm-0718"));
		}

		ActionQueryServiceImpl actionQueryService = new ActionQueryServiceImpl();
		ActionVO actionVo = actionQueryService.queryNewestActionByPKRegister(regvo.getPk_register());
		if (null != actionVo && !"register".equals(actionVo.getEndstatus())) {
			throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0", "03618fbm-1060", null,
					new String[] { regvo.getFbmbillno() }));
		}

		regvo.setSfflag(UFBoolean.FALSE);

		aggvo.getparentVO().setSigner(null);
		aggvo.getparentVO().setSigndate(null);

		GatherBillAccAdapter billAdapter = new GatherBillAccAdapter();
		billAdapter.deleteBillAcc(aggvo, regvo.getGatherdate());

		aggvo = (AggRegisterVO) FbmPrivateUtil.updateAggVO(aggvo, 1);

		deleteCenterVO(aggvo);

		processBillDeliveryAllocate(regvo, false);
		return aggvo;
	}

	public AggRegisterVO completeGather_RequiresNew(AggRegisterVO aggvo) throws BusinessException {
		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(new Validator[] { dateValidator });
		dService.validate(regvo);

		Validator integratedValidator = new FbmCheckIntegratedValidator();
		IValidationService vService = ValidationFrameworkUtil
				.createValidationService(new Validator[] { integratedValidator });

		if (regvo.getSelfendore() == null || !regvo.getSelfendore().booleanValue()) {

			if (regvo.getOnlinebankflag() == null || !regvo.getOnlinebankflag().booleanValue()) {
				vService.validate(regvo);
			}

			Validator outerValidator = new GatherOuterValidator();
			IValidationService outerService = ValidationFrameworkUtil
					.createValidationService(new Validator[] { outerValidator });
			outerService.validate(aggvo.getParentVO());
		}

		regvo.setSfflag(UFBoolean.TRUE);

		aggvo.getparentVO().setSigner(AppContext.getInstance().getPkUser());
		aggvo.getparentVO().setSigndate(AppContext.getInstance().getBusiDate());

		FbmSignPubSecurityUtil.verifySign(aggvo, "recievecomplete", false, null);

		if (!regvo.getInitflag().booleanValue()) {
			GatherBillAccAdapter billAdapter = new GatherBillAccAdapter();
			billAdapter.writeBillAcc(aggvo);

			if (FbmPublicUtil.isAutoVoucher(pk_org)) {
				FBMPrivateServiceProxy.getGatherManageService().voucherGatherVO(aggvo);
			}
		}
		((RegisterVO) aggvo.getParentVO()).setSfflag(UFBoolean.TRUE);
		aggvo = (AggRegisterVO) FbmPrivateUtil.updateAggVO(aggvo, 1);

		processBillDeliveryAllocate(regvo, true);
		return aggvo;
	}

	public AggRegisterVO completeGatherWithOutControl(AggRegisterVO aggvo) throws BusinessException {
		GatherBillAccAdapter billAdapter = new GatherBillAccAdapter();
		billAdapter.writeBillAcc(aggvo);

		RegisterVO registerVO = aggvo.getparentVO();
		registerVO.setSigner(AppContext.getInstance().getPkUser());
		registerVO.setSigndate(AppContext.getInstance().getBusiDate());

		aggvo = (AggRegisterVO) FbmPrivateUtil.updateAggVO(aggvo, 1);

		processBillDeliveryAllocate(registerVO, true);
		return aggvo;
	}

	public AggRegisterVO cancleGatherWithOutControl(AggRegisterVO aggvo) throws BusinessException {
		GatherBillAccAdapter billAdapter = new GatherBillAccAdapter();
		RegisterVO registerVO = aggvo.getparentVO();
		billAdapter.deleteBillAcc(aggvo, registerVO.getGatherdate());

		registerVO.setSigner(null);
		registerVO.setSigndate(null);

		aggvo = (AggRegisterVO) FbmPrivateUtil.updateAggVO(aggvo, 1);

		processBillDeliveryAllocate(registerVO, false);
		return aggvo;
	}

	public AggRegisterVO cancelVoucherGatherVO(AggRegisterVO aggvo) throws BusinessException {
		checkSagaStatus(aggvo);
		RegisterVO regvo = aggvo.getparentVO();
		if (regvo.getSelfendore() == null || !regvo.getSelfendore().booleanValue()) {

			IOuterQueryService outerqryservice = (IOuterQueryService) NCLocator.getInstance()
					.lookup(IOuterQueryService.class);
			OuterVO[] vos = outerqryservice.queryOuterVOsByPk_busibill(regvo.getPk_register());
			if (ArrayUtils.isNotEmpty(vos)) {
				throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0", "03618fbm-1131"));
			}
		}

		GatherSagaInfoAdapter sagaAdapter = new GatherSagaInfoAdapter();
		SagasFrozenProcessor.process(sagaAdapter, aggvo);

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

	public AggRegisterVO voucherGatherVO(AggRegisterVO aggvo) throws BusinessException {
		checkSagaStatus(aggvo);
		RegisterVO regvo = aggvo.getparentVO();
		if (regvo.getSelfendore() == null || !regvo.getSelfendore().booleanValue()) {

			String msg = FbmPublicUtil.isTogatherWithCmpArApFts(regvo.getPk_org());
			if (StringUtil.isNotNull(msg)) {
				throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0", "03618fbm-1124"));
			}
			IOuterQueryService outerqryservice = (IOuterQueryService) NCLocator.getInstance()
					.lookup(IOuterQueryService.class);
			OuterVO[] vos = outerqryservice.queryOuterVOsByPk_busibill(regvo.getPk_register());
			if (ArrayUtils.isNotEmpty(vos)) {
				throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0", "03618fbm-1125"));
			}
		}

		GatherSagaInfoAdapter sagaAdapter = new GatherSagaInfoAdapter();
		SagasFrozenProcessor.process(sagaAdapter, aggvo);

		regvo.setDvoucherdate(AppContext.getInstance().getBusiDate());

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

	public void insertAndApproveGather(AggRegisterVO[] aggvos) throws BusinessException {
		if (aggvos != null && aggvos.length != 0) {
			IOrgUnitPubService_C oups = (IOrgUnitPubService_C) 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(), "3618");

				if (StringUtil.isNull(initDateNY)) {
					throw new BusinessException(
							NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0", "03618fbm-0719"));
				}

				if (initDateNY.length() == 7) {
					initDateNY = initDateNY + "-01";
				}
				if (registervo.getGatherdate().before(new UFDate(initDateNY))) {
					throw new BusinessException(
							NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0", "03618fbm-0720"));
				}

				FbmHideFieldUtil.setHideField(registervo, new String[][] { { "hidepayunit", "payunit", "1" },
						{ "hidepaybank", "paybank", "2" }, { "hidepaybankacc", "paybankacc", "3" },
						{ "hidereceiveunit", "receiveunit", "1" }, { "hidereceivebank", "receivebank", "2" },
						{ "hidereceivebankacc", "receivebankacc", "3" }, { "invoiceunit", "invoiceunitname", "1" } });

				vbillno = FBMPrivateServiceProxy.getBillcodeManage().getBillCode_RequiresNew(
						registervo.getPk_billtypecode(), registervo.getPk_group(), registervo.getPk_org(), aggvo);
				registervo.setAttributeValue("vbillno", vbillno);

				FbmPrivateUtil.updateAggVO(aggvo, 2);

				FbmSignPubSecurityUtil.signDataAggVO(new AggregatedValueObject[] { 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);

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

					if (FbmPublicUtil.isAutoVoucher(registervo.getPk_org())) {
						FBMPrivateServiceProxy.getGatherManageService().voucherGatherVO(aggvo);
					}
				}
			}
		}
	}

	public void unapproveAndDeleteGather(AggRegisterVO[] aggvos) throws BusinessException {
		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());
				}

				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(
							NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0", "03618fbm-1002"));
				}

				FBMPrivateServiceProxy.getBillcodeManage().returnBillCodeOnDelete(registervo.getPk_billtypecode(),
						registervo.getPk_group(), registervo.getPk_org(), registervo.getVbillno(), aggvo);

				FBMPrivateServiceProxy.getMDService().deleteBill(aggvo);
			}
		}
	}

	public void insertGatherFromFund(AggRegisterVO[] aggvos) throws BusinessException {
		checkSagaStatus(aggvos);
		if (aggvos != null && aggvos.length != 0) {
			insertAndApproveGather(aggvos);
		}
	}

	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(NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0", "03618fbm-0721"));
			}
		} else {
			return;
		}
	}

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

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

	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, new boolean[] { true });
			String sql = "update fbm_register set pk_keeporg = '" + NCESAPI.sqlEncode(pk_keeporg) + "' where "
					+ wheresql;

			basedao.executeUpdate(sql);
		}
	}

	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, new boolean[] { true });
			String sql = "update fbm_register set returnrecord = '" + NCESAPI.sqlEncode(returnrecord) + "' where "
					+ wheresql;

			dao.executeUpdate(sql);
		}
	}

	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, 1);

		IStatusControlStrategy strategy = new DestroyGatherAction(revo);
		StatusControlProcess.getInstance().process(strategy);

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

	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("pk_register");
			}
			StringBuilder exeSql = new StringBuilder();
			exeSql.append("update fbm_register set ");
			exeSql.append("pk_fundorg");
			if (StringUtil.isNull(pk_fundorg)) {
				exeSql.append("='~',");
			} else {
				exeSql.append("='").append(NCESAPI.sqlEncode(pk_fundorg)).append("',");
			}

			exeSql.append("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("pk_register", pk_registers, new boolean[] { true }));
			BaseDAO dao = new BaseDAO();
			try {
				dao.executeUpdate(exeSql.toString());
			} catch (DAOException e) {
				Logger.error(e.getMessage(), e);
				throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0", "03618fbm-0722"));
			}
		}
	}

	public void insertGatherWithReliefKeep(AggRegisterVO[] aggvos) throws BusinessException {
		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("vbillno", vbillno);

				DefaultValidationService validateService = new DefaultValidationService();
				validateService.addValidator(new FinOrgUnUseValidator(new VOFieldDesc[] { new VOFieldDesc("pk_org") }));
				validateService.validate(aggvo);
				if (aggvo.getparentVO().getOlcrate() == null) {
					throw new BusinessException(
							NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0", "03618fbm-1122"));
				}

				FbmPrivateUtil.updateAggVO(aggvo, 2);

				IStatusControlStrategy reliefgather = new ReliefKeepGather((RegisterVO) aggvo.getParentVO(), false);
				StatusControlProcess.getInstance().process(reliefgather);

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

				GatherBillAccAdapter billAdapter = new GatherBillAccAdapter();
				billAdapter.writeBillAcc(aggvo);
			}
		}
	}

	public void deleteGatherWithReliefKeep(AggRegisterVO[] aggvos) throws BusinessException {
		checkSagaStatus(aggvos);
		if (aggvos != null && aggvos.length != 0) {
			for (AggRegisterVO aggvo : aggvos) {
				RegisterVO registervo = (RegisterVO) aggvo.getParentVO();

				GatherBillAccAdapter billAdapter = new GatherBillAccAdapter();
				billAdapter.deleteBillAcc(aggvo, registervo.getGatherdate());

				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(
							NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0", "03618fbm-1002"));
				}

				FBMPrivateServiceProxy.getBillcodeManage().returnBillCodeOnDelete(registervo.getPk_billtypecode(),
						registervo.getPk_group(), registervo.getPk_org(), registervo.getVbillno(), aggvo);

				FBMPrivateServiceProxy.getMDService().deleteBill(aggvo);
			}
		}
	}

	public void quickImportGather(List<RegisterVO> origvos) throws BusinessException {
		List<AggRegisterVO> voList = new ArrayList<AggRegisterVO>();
		IBasicOrgUnitPubService_C orgSrv = (IBasicOrgUnitPubService_C) 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, "BUSINESSUNIT00000000");
		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("8c6510dd-3b8a-4cfc-a5c5-323d53c6006f");

		IGeneralAccessor fundPlanAccessor = GeneralAccessorFactory.getAccessor("edc7fbfe-4111-440e-93e0-a88664969dd4");

		IGeneralAccessor bankaccsubAccessor = GeneralAccessorFactory
				.getAccessor("cd1f9a1c-eb08-493f-88ff-bcd1c134dee1");
		IGeneralAccessor bankdocAccessor = GeneralAccessorFactory.getAccessor("bf5aeed4-6b35-4a2e-b750-b9aabce59e21");
		String pk_billtypecode = ((RegisterVO) 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 = (String) mapOrg.get(pk_org_name);
			} else {
				List<OrgVO> orgList = OrgPubUtil.getVOListByClause(OrgVO.class, "pk_org", Arrays.asList(pk_orgs),
						"name='" + pk_org_name + "'");

				if (!ArrayUtil.isNull(orgList)) {
					pk_org = ((OrgVO) orgList.get(0)).getPk_org();
					mapOrg.put(pk_org_name, pk_org);
				} else {
					List<OrgVO> orgCodeList = OrgPubUtil.getVOListByClause(OrgVO.class, "pk_org",
							Arrays.asList(pk_orgs), "code='" + pk_org_name + "'");
					if (orgCodeList.size() > 0) {
						pk_org = ((OrgVO) 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 + pk_org) != null) {
				paybillunit = (String) mapCustSup.get(pk_org + pk_org);
			} else {
				IBDData custBDData = cussupAccessor.getDocByNameWithMainLang(pk_org, paybillunit_name);
				if (custBDData != null) {
					paybillunit = custBDData.getPk();
				}
				mapCustSup.put(pk_org + pk_org, paybillunit);
			}
			regVO.setPaybillunit(paybillunit);

			String fbmbillno = origvo.getFbmbillno();
			regVO.setFbmbillno(fbmbillno);

			String fbmbilltypename = origvo.getFbmbilltype();

			regVO.setFbmbilltype((String) notetypeMap.get(fbmbilltypename));

			String pk_curr_name = origvo.getPk_curr();
			if (!StringUtil.isNull((String) currtypeMap.get(pk_curr_name))) {
				regVO.setPk_curr((String) currtypeMap.get(pk_curr_name));
			} else {
				regVO.setPk_curr((String) currtypeCodeMap.get(pk_curr_name));
			}

			UFDouble money = origvo.getMoney();
			regVO.setMoney(money);
			regVO.setOlcrate(new UFDouble(1.0D));
			regVO.setGlcrate(new UFDouble(1.0D));
			regVO.setGllcrate(new UFDouble(1.0D));
			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 + pk_org) != null) {
					gatherplanitem = (String) fundPlanMap.get(pk_org + pk_org);
				} else {
					IBDData bdData = fundPlanAccessor.getDocByNameWithMainLang(pk_org, gahterplanitem_name);
					if (bdData != null) {
						gatherplanitem = bdData.getPk();
					}
					fundPlanMap.put(pk_org + pk_org, 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 = (String) mapOrg.get(pk_entrusorg_name);
				} else {
					List<OrgVO> orgList = OrgPubUtil.getVOListByClause(OrgVO.class, "pk_org", Arrays.asList(pk_orgs),
							"name='" + NCESAPI.sqlEncode(pk_entrusorg_name) + "'");
					if (orgList.size() > 0) {
						pk_entrusorg = ((OrgVO) 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 + pk_org) != null) {
					invoiceunit = (String) mapCustSup.get(pk_org + pk_org);
				} else {
					IBDData custBDData = cussupAccessor.getDocByNameWithMainLang(pk_org, invoiceunitname);
					if (custBDData != null) {
						invoiceunit = custBDData.getPk();
					}
					mapCustSup.put(pk_org + pk_org, invoiceunit);
				}
				regVO.setInvoiceunit(invoiceunit);
				regVO.setInvoiceunitname(invoiceunitname);
			}

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

			if (origvo.getHidereceiveunit() != null) {
				String hidereceiveunit = origvo.getHidereceiveunit();
				String receiveunit = null;
				if (mapCustSup.containsKey(pk_org + pk_org)) {
					receiveunit = (String) mapCustSup.get(pk_org + pk_org);
				} else {
					IBDData custBDData = cussupAccessor.getDocByNameWithMainLang(pk_org, hidereceiveunit);
					if (custBDData != null) {
						receiveunit = custBDData.getPk();
					}
					mapCustSup.put(pk_org + pk_org, receiveunit);
				}
				regVO.setReceiveunit(hidereceiveunit);
				regVO.setHidereceiveunit(receiveunit);
			}

			if (origvo.getHidepaybankacc() != null) {
				String hidepaybankacc = origvo.getHidepaybankacc();
				String paybankacc = null;
				if (bankaccsubMap.containsKey(pk_org + pk_org)) {
					paybankacc = (String) bankaccsubMap.get(pk_org + pk_org);
				} else {
					IBDData bankaccData = bankaccsubAccessor.getDocByCode(pk_org, hidepaybankacc);
					if (bankaccData != null) {
						paybankacc = bankaccData.getPk();
					}
					bankaccsubMap.put(pk_org + pk_org, 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 + pk_org)) {
					receivebankacc = (String) bankaccsubMap.get(pk_org + pk_org);
				} else {
					IBDData bankaccData = bankaccsubAccessor.getDocByCode(pk_org, hidereceivebankacc);
					if (bankaccData != null) {
						receivebankacc = bankaccData.getPk();
					}
					bankaccsubMap.put(pk_org + pk_org, hidereceivebankacc);
				}
				regVO.setHidereceivebankacc(receivebankacc);
				regVO.setReceivebankacc(hidereceivebankacc);
			}

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

			if (origvo.getHidereceivebank() != null) {
				String hidereceivebank = origvo.getHidereceivebank();
				String receivebank = null;
				if (bankdocMap.containsKey(pk_org + pk_org)) {
					receivebank = (String) bankdocMap.get(pk_org + pk_org);
				} else {
					IBDData bankdocData = bankdocAccessor.getDocByNameWithMainLang(pk_org, hidereceivebank);
					if (bankdocData != null) {
						receivebank = bankdocData.getPk();
					}
					bankdocMap.put(pk_org + pk_org, 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(
							NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0326"));
				}

				if (StringUtil.isNull(origvo.getSignagrbank())) {
					throw new BusinessException(
							NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0327"));
				}

				if (StringUtil.isNull(origvo.getPk_bankdoc())) {
					String pk_bankdoc = origvo.getPk_bankdoc();
					String bankdoc = null;
					if (bankdocMap.containsKey(pk_org + pk_org)) {
						bankdoc = (String) bankdocMap.get(pk_org + pk_org);
					} else {
						IBDData bankdocData = bankdocAccessor.getDocByNameWithMainLang(pk_org, pk_bankdoc);
						if (bankdocData != null) {
							bankdoc = bankdocData.getPk();
						} else {
							throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
									"03618fbm_add02-0328"));
						}
						bankdocMap.put(pk_org + pk_org, bankdoc);
					}
					regVO.setPk_bankdoc(bankdoc);
				}

				if (StringUtil.isNull(origvo.getSignagrbank())) {
					String signagrbank = origvo.getSignagrbank();
					String pksignagrbank = null;
					if (bankdocMap.containsKey(pk_org + pk_org)) {
						pksignagrbank = (String) bankdocMap.get(pk_org + pk_org);
					} else {
						IBDData bankdocData = bankdocAccessor.getDocByNameWithMainLang(pk_org, signagrbank);
						if (bankdocData != null) {
							pksignagrbank = bankdocData.getPk();
						} else {
							throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
									"03618fbm_add02-0329"));
						}
						bankdocMap.put(pk_org + pk_org, pksignagrbank);
					}
					regVO.setSignagrbank(pksignagrbank);
					if (!StringUtil.isNull(origvo.getAcceptorname())) {
						regVO.setAcceptorname(origvo.getAcceptorname());
					} else {
						regVO.setAcceptorname(signagrbank);
					}
				}

				checkBankDoc(regVO);
			}

			regVO.setPk_group(pk_group);

			regVO.setPk_billtypecode(origvo.getPk_billtypecode());
			regVO.setPk_billtypeid(origvo.getPk_billtypeid());

			regVO.setGathertype("input");

			regVO.setBillmaker(pk_user);

			regVO.setBookflag(UFBoolean.FALSE);

			regVO.setBuyerinterest((origvo.getBuyerinterest() == null) ? UFBoolean.FALSE : origvo.getBuyerinterest());

			regVO.setDisableflag(UFBoolean.FALSE);

			regVO.setPlanflag(UFBoolean.FALSE);

			regVO.setVbillstatus(Integer.valueOf(-1));

			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 = (AggRegisterVO[]) voList.toArray(new AggRegisterVO[0]);

		PfProcessBatchRetObject obj = (PfProcessBatchRetObject) ((IplatFormEntry) 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(
					NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0330"));
		}
	}

	private Map<String, String> getNoteTypeMap() throws BusinessException {
		INotetypeQueryService notetypeSrv = (INotetypeQueryService) 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 = (ICurrtypeQuery) 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 = (ICurrtypeQuery) 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;
	}

	public void updateGatherByBillpool(AggRegisterVO[] aggvos) throws BusinessException {
		checkSagaStatus(aggvos);
		RegisterVO[] registerVOs = new RegisterVO[aggvos.length];
		for (int i = 0; i < aggvos.length; i++) {
			aggvos[i].getParentVO().setStatus(1);
			registerVOs[i] = (RegisterVO) aggvos[i].getParentVO();
		}

		FBMPrivateServiceProxy.getMDService().saveBillWithRealDelete(registerVOs);
	}

	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(1);
			registerVOs[i] = (RegisterVO) aggvos[i].getParentVO();
		}

		FBMPrivateServiceProxy.getMDService().saveBillWithRealDelete(registerVOs);
	}

	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 ("register".equals(aggVO.getparentVO().getRegisterstatus())) {

						if (aggVO.getparentVO().getSfflag() != null && aggVO.getparentVO().getSfflag().booleanValue()) {

							if (aggVO.getparentVO().getCyberbankflag() != null
									&& aggVO.getparentVO().getCyberbankflag().booleanValue()) {

								if (isJSYH(aggVO.getparentVO().getPk_bankdoc(), bankMap)
										&& isEcdNoteClass(aggVO.getparentVO().getPk_register(), noteClassMap)) {
									passFlag = false;
									setNetBankError(aggVO,
											NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
													"03618fbm_add02-0034")
													+ NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
															"03618fbm_add02-0034")
													+ ((RegisterVO) aggVO

															.getParentVO()).getVbillno());

								} else {

									passFlag = true;
								}
							} else {

								passFlag = false;
								setNetBankError(aggVO,
										NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
												"03618fbm_add02-0034")
												+ NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
														"03618fbm_add02-0034")
												+ ((RegisterVO) aggVO

														.getParentVO()).getVbillno());
							}

						} else {
							passFlag = false;
							setNetBankError(aggVO,
									NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
											"03618fbm_add02-0034")
											+ NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
													"03618fbm_add02-0034")
											+ ((RegisterVO) aggVO

													.getParentVO()).getVbillno());
						}

					} else {

						passFlag = false;
						setNetBankError(aggVO,
								NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0034")
										+ NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
												"03618fbm_add02-0034")
										+ ((RegisterVO) aggVO

												.getParentVO()).getVbillno());
					}

					pks.add(aggVO.getParentVO().getPrimaryKey());
				} else {
					throw new BusinessException(
							NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0033"));
				}

				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(
						NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0334"));
			}

			return (AggRegisterVO[]) result.toArray(new AggRegisterVO[result.size()]);
		}
		throw new BusinessException(
				NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0033"));
	}

	private AggRegisterVO[] doNetBank(AggRegisterVO[] aggVOs) throws BusinessException {
		checkSagaStatus(aggVOs);
		return PFBMPrivateServiceProxy.getIEbankBillManageService().receiptRegis(aggVOs, "OBM");
	}

	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(
						NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0266")
								+ NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0266")
								+ (reqNum - ebankRetNum + noPassNum));
			}

			for (AggRegisterVO aggVO : aggVOs) {
				if (aggVO == null || aggVO.getParentVO() == null) {
					throw new BusinessException(
							NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0268"));
				}

				if (aggVO.getparentVO().getPaymentstatus() == null) {
					throw new BusinessException(
							NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0269"));
				}

				cacheMap.put(aggVO.getParentVO().getPrimaryKey(), aggVO);
			}

			AggRegisterVO[] result = new AggRegisterVO[reqNum];
			for (int i = 0; i < reqNum; i++) {
				result[i] = (AggRegisterVO) cacheMap.get(pks.get(i));
			}
			return result;
		}
		throw new BusinessException(
				NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0268"));
	}

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

					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, 1);
				} else {
					throw new BusinessException(
							NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0268"));
				}
			}
		} else {

			throw new BusinessException(
					NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0268"));
		}
	}

	public AggRegisterVO[] bankRegister(AggRegisterVO[] aggVOs) throws BusinessException {
		checkSagaStatus(aggVOs);

		BankRegisterUtil.bankRegisterHelp(aggVOs);

		if (!FbmPublicUtil.isOBMEnable((String) aggVOs[0].getParentVO().getAttributeValue("pk_group"))) {
			throw new BusinessException(
					NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0223"));
		}

		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(
					NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0336")
							+ NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0336"));
		}

		try {
			aggVOs = doNetBank(aggVOs);
		} catch (BusinessException e) {
			throw new BusinessException(
					NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0337")
							+ NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0337"));
		}

		try {
			aggVOs = doNetBankAfterValidate(aggVOs, pks, cacheMap);
		} catch (BusinessException e) {
			throw new BusinessException(
					NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0338")
							+ NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0338"));
		}

		try {
			doUpdate2DB(aggVOs);
		} catch (BusinessException e) {
			throw new BusinessException(
					NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0339")
							+ NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0339"));
		}

		return aggVOs;
	}

	public void bankRegisterWriteBackRegister(AggRegisterVO[] aggVOs) throws BusinessException {
		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(
							NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0033"));
				}
			}

			doUpdate2DB((AggRegisterVO[]) result.toArray(new AggRegisterVO[result.size()]));
		} else {
			throw new BusinessException(
					NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0033"));
		}
	}

	private void setNetBankError(AggRegisterVO aggVO, String errMess) {
		((RegisterVO) aggVO.getParentVO()).setPaymentstatus(Integer.valueOf(PaymentStatusEnum.TRADEFAIL.toIntValue()));
		((RegisterVO) aggVO.getParentVO()).setBankreturninfo(errMess);
	}

	public void insertStorageVO(AggRegisterVO aggVO) throws BusinessException {
		AggStorageVO aggstovo = RegisterToChangeVO.registerToChangeStorageVO(aggVO);

		aggstovo = FBMPrivateServiceProxy.getBankKeepManageService().insertBankKeep(aggstovo);

		aggstovo.getParentVO().setAttributeValue("vbillstatus", Integer.valueOf(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);
	}

	public void insertStorageVOAndCenterVO(AggRegisterVO[] aggregisterVO) throws BusinessException {
		checkSagaStatus(aggregisterVO);
		for (int i = 0; i < aggregisterVO.length; i++) {

			if (aggregisterVO[i].getparentVO().getNote().equals("92")) {
				insertStorageVO(aggregisterVO[i]);
			}

			insertCenterVO(aggregisterVO[i]);
		}
	}

	public void insertCenterVO(AggRegisterVO aggVO) throws BusinessException {
		RegisterVO regvo = (RegisterVO) aggVO.getParentVO();

		if (StringUtil.isNotNull(regvo.getPk_org()) && StringUtil.isNotNull(regvo.getPaybillunit())) {

			Map<String, String> orgmap = FBMPrivateServiceProxy.getCustsupPubService()
					.queryOrgPkByCustsupPk(new String[] { regvo.getPaybillunit() });

			if (null == orgmap) {
				return;
			}
			String paybillunit = (String) orgmap.get(regvo.getPaybillunit());

			boolean isFundOrgIDSByOrgID = ((IFundOrgPubService) NCLocator.getInstance()
					.lookup(IFundOrgPubService.class))
					.isExistRelationByFundOrgIDAndFinanceOrgID(regvo.getPk_org(), paybillunit);
			if (isFundOrgIDSByOrgID) {

				AggCenteroccupyctVO[] aggCenteroccupyctVO = new AggCenteroccupyctVO[1];
				aggCenteroccupyctVO[0] = RegisterToChangeVO.registerToChangeCenterVO(aggVO);

				if (aggCenteroccupyctVO != null) {
					((ICenteroccupyctManageService) NCLocator.getInstance().lookup(ICenteroccupyctManageService.class))
							.insert(aggCenteroccupyctVO);
				}
			}
		}
	}

	public void deleteCenterVO(AggRegisterVO aggVO) throws BusinessException {
		RegisterVO regvo = (RegisterVO) aggVO.getParentVO();

		AggCenteroccupyctVO[] aggCenteroccupyctVO = ((ICenteroccupyctManageService) NCLocator.getInstance()
				.lookup(ICenteroccupyctManageService.class)).queryCenteroccupyctVOByPk_Srcbill(regvo.getPk_register());

		if (aggCenteroccupyctVO != null) {
			((ICenteroccupyctManageService) NCLocator.getInstance().lookup(ICenteroccupyctManageService.class))
					.delete(aggCenteroccupyctVO);
		}
	}

	public AggRegisterVO disableGatherbill(AggRegisterVO aggvo) throws BusinessException {
		checkSagaStatus(aggvo);

		if ("signinput".equals(aggvo.getparentVO().getGathertype())) {
			((IBeforeRegisterManageService) NCLocator.getInstance().lookup(IBeforeRegisterManageService.class))
					.undoWhenDeleteGather(aggvo.getparentVO());
		}

		doBeforeDisableValidator(aggvo);
		RegisterVO registerVO = aggvo.getparentVO();

		registerVO.setDisuseflag(UFBoolean.TRUE);
		FbmPrivateUtil.updateAggVO(aggvo, 1);

		IStatusControlStrategy strategy = new DisableGather(registerVO);
		StatusControlProcess.getInstance().process(strategy);
		return (AggRegisterVO) FbmPrivateUtil.queryAggvoByPK(aggvo);
	}

	private void doBeforeDisableValidator(AggRegisterVO aggVO) throws BusinessException {
		if (aggVO == null) {
			throw new BusinessException(
					NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0232"));
		}

		RegisterVO payvo = (RegisterVO) aggVO.getParentVO();
		if (payvo == null) {
			throw new BusinessException(
					NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0232"));
		}

		if (payvo.getElcpaymentstatus() == null
				|| !payvo.getElcpaymentstatus().equals(Integer.valueOf(PaymentStatusEnum.TRADEFAIL.toIntValue()))) {
			throw new BusinessException(
					NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0259"));
		}

		if (payvo.getOnlinebankflag() == null || !payvo.getOnlinebankflag().booleanValue()) {
			throw new BusinessException(
					NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0347"));
		}

		if (payvo.getDisuseflag() != null && payvo.getDisuseflag().booleanValue()) {
			throw new BusinessException(
					NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0239"));
		}
	}

	public AggRegisterVO cancelDisableGatherbill(AggRegisterVO aggvo) throws BusinessException {
		checkSagaStatus(aggvo);

		doBeforeCancelDisableValidator(aggvo);

		if ("signinput".equals(aggvo.getparentVO().getGathertype())) {
			((IBeforeRegisterManageService) NCLocator.getInstance().lookup(IBeforeRegisterManageService.class))
					.doWhenUnDisableGather(aggvo.getparentVO());
		}
		RegisterVO registerVO = (RegisterVO) aggvo.getParentVO();

		registerVO.setDisuseflag(UFBoolean.FALSE);

		registerVO.setDisablenote(null);

		registerVO.setDisableuser(null);

		registerVO.setDisabledate(null);
		FbmPrivateUtil.updateAggVO(aggvo, 1);

		IStatusControlStrategy strategy = new CancelDisableGather(registerVO);
		StatusControlProcess.getInstance().process(strategy);

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

	private void doBeforeCancelDisableValidator(AggRegisterVO aggVO) throws BusinessException {
		if (aggVO == null) {
			throw new BusinessException(
					NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0232"));
		}

		RegisterVO payvo = (RegisterVO) aggVO.getParentVO();
		if (payvo == null) {
			throw new BusinessException(
					NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0232"));
		}

		if (payvo.getDisuseflag() != null && !payvo.getDisuseflag().booleanValue()) {
			throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("3618ncc_0", "03618ncc-0027"));
		}
	}

	private boolean isEcdNoteClass(String pk_register, Map<String, Boolean> noteClassMap) {
		if (noteClassMap.containsKey(pk_register)) {
			return ((Boolean) noteClassMap.get(pk_register)).booleanValue();
		}
		Boolean isEcd = Boolean.valueOf(FbmPublicUtil.isEcdNoteClass(pk_register));
		noteClassMap.put(pk_register, isEcd);
		return isEcd.booleanValue();
	}

	private boolean isJSYH(String pk_bankdoc, Map<String, Boolean> bankMap) {
		if (bankMap.containsKey(pk_bankdoc)) {
			return ((Boolean) bankMap.get(pk_bankdoc)).booleanValue();
		}
		Boolean isJSYH = false;
		try {
			isJSYH = Boolean.valueOf("0001Z010000000000363"
					.equals(((IBankdocQueryService) NCLocator.getInstance().lookup(IBankdocQueryService.class))
							.queryBanktypePkByBankdocPk(pk_bankdoc)));
		} catch (BusinessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		bankMap.put(pk_bankdoc, isJSYH);
		return isJSYH.booleanValue();
	}

	private void checkSagaStatus(AggRegisterVO aggvo) throws BusinessException {
		if (aggvo != null && aggvo.getParentVO() != null) {
			CheckInfo info = new CheckInfo();
			info.setPkfieldName("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("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((String[]) pkList.toArray(new String[pkList.size()]));
			FbmPubPublicServiceProxy.getSagaStatusCheckService().checkSagaStatus(new CheckInfo[] { info });
		}
	}

	public AggregatedValueObject combinGatherbill(String[] pk_registers, String pk_billtypecode)
			throws BusinessException {
		IGatherQueryService gatherService = (IGatherQueryService) 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;
	}

	private AggregatedValueObject recbill(AggRegisterVO[] aggVOs, String pk_billtypecode) throws BusinessException {
		String pk_desbilltype = "F4";

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

		if (!FbmPublicUtil.isCMPInitDateEnable(pk_group, pk_org)) {
			throw new BusinessException(
					NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0107"));
		}

		if (!FbmPublicUtil.isTogatherWithOther(pk_org, "FBM2002")) {
			throw new BusinessException(
					NCLangRes4VoTransl.getNCLangRes().getStrByID("3637fbm_add_0", "03637fbm_add-0004"));
		}

		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);
			childrenvos[i].setPk_fiorg_v(pk_org_v);
			childrenvos[i].setPk_group(pk_group);

			childrenvos[i].setNote_type(aggvo.getparentVO().getFbmbilltype());
			childrenvos[i].setNote_no(aggvo.getparentVO().getPk_register());
			childrenvos[i].setPk_currtype(pk_curr);
			childrenvos[i].setDirection(Integer.valueOf(1));
			childrenvos[i].setRec_primal(aggvo.getparentVO().getMoney());
			childrenvos[i].setLocal_rate(orgcurrrate);
			childrenvos[i].setGroup_rate(glcurrrate);
			childrenvos[i].setGlobal_rate(gllcurrrate);
			childrenvos[i].setBill_date(busidate);
			childrenvos[i].setCreator(getUser());
			childrenvos[i].setCreationtime(AppContext.getInstance().getServerTime());

			childrenvos[i].setBill_type(pk_desbilltype);
			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(Integer.valueOf(1));
				} else {
					childrenvos[i].setPk_customer(paybillunit);
					childrenvos[i].setPkCustomerV(paybillunit_v);
					childrenvos[i].setObjecttype(Integer.valueOf(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);

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

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

			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);
		parentvo.setBillmaker_date(busidate);

		parentvo.setCreator(getUser());
		parentvo.setCreationtime(AppContext.getInstance().getServerTime());
		parentvo.setBill_type(pk_desbilltype);
		parentvo.setBillclass(billclass);

		parentvo.setSource_flag("8");
		parentvo.setBill_status(Integer.valueOf(-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(Integer.valueOf(1));
			} else {
				parentvo.setPk_customer(paybillunit);
				parentvo.setPkCustomerV(paybillunit_v);
				parentvo.setObjecttype(Integer.valueOf(0));
			}
		}
		recbillaggvo.setParent(parentvo);
		recbillaggvo.setChildrenVO(childrenvos);
		return recbillaggvo;
	}

	private AggregatedValueObject gatheringbill(AggRegisterVO[] aggVOs, String pk_billtypecode)
			throws BusinessException {
		String pk_desbilltype = "F2";

		String billclass = "sk";
		IDeptPubService deptSrv = (IDeptPubService) 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());

		String fbmbilltype = pvo.getFbmbilltype();
		if (fbmbilltype.equals("FBMTZ6E0000000000001") || fbmbilltype.equals("FBMTZ6E0000000000002")) {
			GatherCheckUtil.checkHasReceiveComplete(aggVOs);
		}

		if (!FbmPublicUtil.isAREnable(pk_group)) {
			throw new BusinessException(
					NCLangRes4VoTransl.getNCLangRes().getStrByID("3637fbm_add_0", "03637fbm_add-0003"));
		}

		if (!FbmPublicUtil.isTogatherWithOther(pk_org, "FBM2002")) {
			throw new BusinessException(
					NCLangRes4VoTransl.getNCLangRes().getStrByID("3637fbm_add_0", "03637fbm_add-0004"));
		}

		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].setChecktype(aggvo.getparentVO().getFbmbilltype());
			childrenvos[i].setCheckno(aggvo.getparentVO().getPk_register());
			childrenvos[i].setBillrangestart(aggvo.getparentVO().getBillrangestart());
			childrenvos[i].setBillrangeend(aggvo.getparentVO().getBillrangeend());
			childrenvos[i].setPk_currtype(pk_curr);
			childrenvos[i].setDirection(Integer.valueOf(-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);
					childrenvos[i].setObjtype(Integer.valueOf(1));
				} else {
					childrenvos[i].setCustomer(paybillunit);
					childrenvos[i].setCustomer_v(paybillunit_v);
					childrenvos[i].setObjtype(Integer.valueOf(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);

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

			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.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(Integer.valueOf(0));
		parentvo.setSrc_syscode(Integer.valueOf(0));
		parentvo.setBillstatus(Integer.valueOf(-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);
				parentvo.setObjtype(Integer.valueOf(1));
			} else {
				parentvo.setCustomer(paybillunit);
				parentvo.setCustomer_v(paybillunit_v);
				parentvo.setObjtype(Integer.valueOf(0));
			}
		}
		araggvo.setParentVO(parentvo);
		araggvo.setChildrenVO(childrenvos);
		return araggvo;
	}

	private AggregatedValueObject commissionBill(AggRegisterVO[] aggVOs, String pk_billtypecode)
			throws BusinessException {
		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();

			boolean isFundOrg = ((IFundOrgPubService) NCLocator.getInstance().lookup(IFundOrgPubService.class))
					.isFundOrg(pk_org);
			if (!isFundOrg) {
				throw new BusinessException(
						NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0089"));
			}

			String fbmbilltype = pvo.getFbmbilltype();
			if (fbmbilltype.equals("FBMTZ6E0000000000001") || fbmbilltype.equals("FBMTZ6E0000000000002")) {
				GatherCheckUtil.checkHasReceiveComplete(aggVOs);
			}

			if (!FbmPublicUtil.isFTSEnable(pk_group)) {
				throw new BusinessException(
						NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0090"));
			}

			if (!FbmPublicUtil.isTogatherWithOther(pk_org, "FBM2002")) {
				throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0",
						"03618fbm_add02-0091") + "FBM2002"
						+ NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0091"));
			}

			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];
			GatherFundVO[] fund_childrenvos = new GatherFundVO[aggVOs.length];
			AggRegisterVO aggvo = null;

			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].setOlcrate(orgcurrrate);
				childrenvos[i].setGlcrate(glcurrrate);
				childrenvos[i].setGllcrate(gllcurrrate);
				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].setBankname_p(null);

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

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

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

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

			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());
				fund_childrenvos[i].setFeeamount(null);
				fund_childrenvos[i].setFeedirection(null);
				fund_childrenvos[i].setFundtype(null);
				fund_childrenvos[i].setGetmode("note");
				fund_childrenvos[i].setOlcrate(orgcurrrate);
				fund_childrenvos[i].setGlcrate(glcurrrate);
				fund_childrenvos[i].setGllcrate(gllcurrrate);
				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(Integer.valueOf(i));

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

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

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

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

			parentvo.setAcceptdate(busidate);
			parentvo.setBillmaker(getUser());
			parentvo.setBilldate(busidate);
			parentvo.setBillstatus(Integer.valueOf(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);

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

			return aggVO;
		}
		return null;
	}

	private String getUser() {
		return InvocationInfoProxy.getInstance().getUserId();
	}

	public AggRegisterVO pdfInsertGather(AggRegisterVO aggvo) throws BusinessException {
		RegisterVO registervo = (RegisterVO) aggvo.getParentVO();

		DefaultValidationService validateService = new DefaultValidationService();
		validateService.addValidator(new FinOrgUnUseValidator(new VOFieldDesc[] { new VOFieldDesc("pk_org") }));
		validateService.validate(aggvo);

		FbmSignPubSecurityUtil.signDataAggVO(new AggregatedValueObject[] { aggvo });

		String vbillno = FBMPrivateServiceProxy.getBillcodeManage().getBillCode_RequiresNew(
				registervo.getPk_billtypecode(), registervo.getPk_group(), registervo.getPk_org(), aggvo);
		registervo.setAttributeValue("vbillno", vbillno);

		return (AggRegisterVO) FbmPrivateUtil.updateAggVO(aggvo, 2);
	}

	public AggRegisterVO pdfUpdateGather(AggRegisterVO aggvo) throws BusinessException {
		checkSagaStatus(aggvo);
		RegisterVO registervo = (RegisterVO) aggvo.getParentVO();

		registervo.setGathertype("input");

		UFBoolean initFlag = registervo.getInitflag();

		boolean isInitAccept = (initFlag != null && initFlag.booleanValue()
				&& "36HN".equals(registervo.getPk_billtypecode()));
		boolean isEcd = false;
		String fbmBillType = registervo.getFbmbilltype();

		Integer billtypeclass = ((IFbmPubQueryService) 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(new Validator[] { gatherSaveValidator });
			vEcdService.validate(registervo);
		}

		CheckInitDateTool.checkInitData("gatherdate",
				NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_0", "03618fbm-0461"), registervo.getGatherdate(),
				registervo.getPk_org(), registervo.getInitflag());

		Validator saveIllegalGatherValidator = new SaveIllegalGatherValidator();
		IValidationService vService = ValidationFrameworkUtil
				.createValidationService(new Validator[] { saveIllegalGatherValidator });
		vService.validate(aggvo.getParentVO());

		if (registervo.getSignagrbank() != null && !registervo.getSignagrbank().trim().equals("")) {

			BankdocVO bankdocVOByPk = ((IBankdocQueryService) NCLocator.getInstance()
					.lookup(IBankdocQueryService.class)).getBankdocVOByPk(registervo.getSignagrbank());
			if (bankdocVOByPk != null) {
				if (bankdocVOByPk.getPcombinenum() != null && !bankdocVOByPk.getPcombinenum().trim().equals("")) {
					registervo.setSignagrbanknum(bankdocVOByPk.getPcombinenum());
				}

				if (bankdocVOByPk.getPcombinename() != null && !bankdocVOByPk.getPcombinename().trim().equals("")) {
					registervo.setSignagrbankname(bankdocVOByPk.getPcombinename());

				}
			} else {

				throw new BusinessException(
						NCLangRes4VoTransl.getNCLangRes().getStrByID("3618fbm_add02_0", "03618fbm_add02-0323"));
			}
		}

		FbmSignPubSecurityUtil.signDataAggVO(new AggregatedValueObject[] { aggvo });

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

		checkBankDoc(registervo);

		AggRegisterVO retvo = (AggRegisterVO) FbmPrivateUtil.updateAggVO(aggvo, 1);

		IStatusControlStrategy strategy = new SaveGather((RegisterVO) aggvo.getParentVO());
		StatusControlProcess.getInstance().process(strategy);

		return retvo;
	}

	public AggRegisterVO pdfDeleteGather(AggRegisterVO aggvo) throws BusinessException {
		checkSagaStatus(aggvo);
		RegisterVO registervo = (RegisterVO) aggvo.getParentVO();

		Validator deleteValidator = new FbmBaseDeleteValidator();
		IValidationService vService = ValidationFrameworkUtil
				.createValidationService(new Validator[] { deleteValidator });
		vService.validate(aggvo.getParentVO());

		Validator outerValidator = new GatherOuterValidator();
		IValidationService outerService = ValidationFrameworkUtil
				.createValidationService(new Validator[] { 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;
	}

	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 ("billdelivery".equals(gatherType)) {

					FBMPrivateServiceProxy.getBillDeliveryManageService().signBillByFbmbillno(pk_org,
							new String[] { fbmbillno }, pk_register);

				} else if ("billallocate".equals(gatherType)) {
					FBMPrivateServiceProxy.getBillAllocateManageService().signBillByFbmbillno(pk_org,
							new String[] { fbmbillno }, pk_register);

				}

			} else if ("billdelivery".equals(gatherType)) {

				FBMPrivateServiceProxy.getBillDeliveryManageService().unSignBillByFbmbillno(pk_org,
						new String[] { fbmbillno }, pk_register);

			} else if ("billallocate".equals(gatherType)) {
				FBMPrivateServiceProxy.getBillAllocateManageService().unSignBillByFbmbillno(pk_org,
						new String[] { fbmbillno }, pk_register);
			}
		}
	}
}
