package nc.impl.fa.assetsplit;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import nc.bs.am.framework.action.IActionTemplate;
import nc.bs.am.framework.action.IRule;
import nc.bs.am.framework.action.approve.ApproveActionTemplate;
import nc.bs.am.framework.action.approve.UnApproveActionTemplate;
import nc.bs.am.framework.common.rule.ValidateServiceRule;
import nc.bs.framework.common.InvocationInfoProxy;
import nc.bs.uif2.validation.Validator;
import nc.impl.am.bill.BillBaseDAO;
import nc.impl.am.bill.rule.BillCodeDeleteRule;
import nc.impl.am.bill.rule.BillCodeInsertAfterRule;
import nc.impl.am.bill.rule.BillCodeInsertBeforeRule;
import nc.impl.am.bill.rule.BillCodeUpdateRule;
import nc.impl.am.bill.rule.VOSagasStatusCheckBeforeRule;
import nc.impl.am.common.InSqlManager;
import nc.impl.am.db.DBAccessUtil;
import nc.impl.am.db.QueryUtil;
import nc.impl.fa.asset.AssetServiceImpl;
import nc.impl.fa.assetcombin.rule.ARMSplitAssetsApproveAfterRule;
import nc.impl.fa.assetsplit.rule.AddNewAssetRule;
import nc.impl.fa.assetsplit.rule.AssetSplitUpdateCardLogAfterRule;
import nc.impl.fa.assetsplit.rule.CancelAssetReduceRule;
import nc.impl.fa.assetsplit.rule.ClearBodyAssetCardInfoRule;
import nc.impl.fa.assetsplit.rule.LockAssetCardRule;
import nc.impl.fa.assetsplit.rule.ReduceSplitedAssetRule;
import nc.impl.fa.assetsplit.rule.SplitAssetInMultiAccbookRule;
import nc.impl.fa.assetsplit.rule.UpdateRelatedEquipInfoForUnapprovingRule;
import nc.impl.fa.assetsplit.rule.UpdateRelatedEquipsInfoForApprovingRule;
import nc.impl.fa.assetsplit.validator.CheckBodyDepStartDateValidator;
import nc.impl.fa.assetsplit.validator.CheckBodysAssetCategoryLegalValidator;
import nc.impl.fa.assetsplit.validator.CheckBodysAssetCodeLegalValidator;
import nc.impl.fa.assetsplit.validator.CheckCreatedCardMinUnClosedBookPeriodValidator;
import nc.impl.fa.assetsplit.validator.CheckHeadMinUnClosedBookPeriodValidator;
import nc.impl.fa.assetsplit.validator.CheckSameAccbookValidator;
import nc.impl.fa.assetsplit.validator.CheckWorkloanInfosValidator;
import nc.impl.fa.closebook.CloseBookImpl;
import nc.impl.fa.common.rule.CreateBillLogAfterRule;
import nc.impl.fa.common.rule.DeleteBillLogAfterRule;
import nc.impl.fa.common.validator.CheckCardLegalValidator;
import nc.impl.fa.common.validator.CheckHasFipMakeVoucherForAccbooks;
import nc.impl.fa.common.validator.CheckMinUnClosedBookPeriodValidator;
import nc.impl.fa.rule.FAAccbookCheckSealRule;
import nc.impl.fa.rule.PKAccbookBeforeRule;
import nc.impl.fa.rule.ReceiptScanBeforeRule;
import nc.itf.fa.prv.IAssetSplit;
import nc.itf.fa.service.IAccbookInfoService;
import nc.itf.fa.service.IAssetService;
import nc.itf.fa.service.IUseDeptScaleService;
import nc.itf.org.IDeptQryService;
import nc.md.model.MetaDataException;
import nc.md.persist.framework.MDPersistenceService;
import nc.pub.fa.common.consts.LogTypeConst;
import nc.pub.fa.common.manager.DeptScaleManager;
import nc.pub.fa.common.manager.VOManager;
import nc.pub.fa.common.util.FAUseDeptKeyGenerator;
import nc.pub.fa.common.util.StringUtils;
import nc.pub.fa.common.util.UseDeptScaleUtils;
import nc.pubitf.org.IDeptPubService;
import nc.vo.am.common.AbstractAggBill;
import nc.vo.am.common.BaseLockData;
import nc.vo.am.common.TransportBillVO;
import nc.vo.am.common.util.ArrayUtils;
import nc.vo.am.common.util.BillTransportTool;
import nc.vo.am.common.util.CollectionUtils;
import nc.vo.am.common.util.MapUtils;
import nc.vo.am.manager.AccperiodVO;
import nc.vo.am.manager.LockManager;
import nc.vo.am.proxy.AMProxy;
import nc.vo.fa.assetsplit.AssetSplitBodyVO;
import nc.vo.fa.assetsplit.AssetSplitHeadVO;
import nc.vo.fa.assetsplit.AssetSplitVO;
import nc.vo.fa.deptscale.DeptScaleVO;
import nc.vo.org.OrgVO;
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.uif2.LoginContext;

public class AssetSplitImpl extends BillBaseDAO<AssetSplitVO> implements IAssetSplit {
	public void delete(AssetSplitVO vo) throws BusinessException {
		vo = this.reQueryBillByPK(vo.getParent().getPrimaryKey());
		this.deleteBillVO(new AssetSplitVO[]{vo});
	}

	public TransportBillVO insert(LoginContext context, AssetSplitVO vo) throws BusinessException {
		this.dealWithUseDept(vo);
		vo = ((AssetSplitVO[]) this.insertBillVO(new AssetSplitVO[]{vo}))[0];
		this.releasePKCardLock(vo, context);
		TransportBillVO pkBillVO = BillTransportTool.createTransportBill(vo, 1);
		return pkBillVO;
	}

	protected void initCommitActionRules(IActionTemplate<AssetSplitVO> template) {
		super.initCommitActionRules(template);
		template.addBeforeRule(new VOSagasStatusCheckBeforeRule());
		template.addBeforeRule(new ReceiptScanBeforeRule());
	}
	
	private void setMultiDeptForVO(AssetSplitVO vo) throws BusinessException {
		if (vo != null) {
			AssetSplitHeadVO headVO = (AssetSplitHeadVO) vo.getParentVO();
			if (headVO != null) {
				vo.setParentVO(this.setHeadMultiDeptscaleVOs(headVO));
			}

			AssetSplitBodyVO[] bodyVOs = (AssetSplitBodyVO[]) ((AssetSplitBodyVO[]) vo.getChildrenVO());
			if (ArrayUtils.isNotEmpty(bodyVOs)) {
				vo.setChildrenVO(this.setBodyMultiDeptscaleVOs(bodyVOs));
			}
		}

	}

	protected void dealWithUseDept(AssetSplitVO vo) throws BusinessException {
		AssetSplitBodyVO[] bodyVOs = (AssetSplitBodyVO[]) ((AssetSplitBodyVO[]) vo.getChildrenVO());
		int var7;
		if (ArrayUtils.isNotEmpty(bodyVOs)) {
			Set<String> oids = new HashSet();
			Map<String, OrgVO> orgVOCache = new HashMap();
			OrgVO orgVO = null;
			AssetSplitBodyVO[] var6 = bodyVOs;
			var7 = bodyVOs.length;

			int var8;
			for (var8 = 0; var8 < var7; ++var8) {
				AssetSplitBodyVO bodyVO = var6[var8];
				if (bodyVO.getStatus() != 3 && bodyVO.getStatus() != 0) {
					DeptScaleVO[] deptScaleVOs = bodyVO.getDeptscaleVOs();
					Set<String> pk_depts = VOManager.getAttributeValueSet(deptScaleVOs, "pk_dept");
					oids.addAll(pk_depts);
					String pk_dept = ((String[]) pk_depts.toArray(new String[0]))[0];
					if (orgVOCache.containsKey(pk_dept)) {
						orgVO = (OrgVO) orgVOCache.get(pk_dept);
					} else {
						orgVO = ((IDeptQryService) AMProxy.lookup(IDeptQryService.class)).queryOrgVOByDeptID(pk_dept);
						orgVOCache.put(pk_dept, orgVO);
					}
				}
			}

			if (null != oids && !oids.isEmpty()) {
				Map<String, String> deptVersionMap = ((IDeptPubService) AMProxy.lookup(IDeptPubService.class))
						.getLastVIDSByDeptIDS((String[]) oids.toArray(new String[0]));
				if (null != deptVersionMap && !deptVersionMap.isEmpty()) {
					AssetSplitBodyVO[] var20 = bodyVOs;
					var8 = bodyVOs.length;

					for (int var22 = 0; var22 < var8; ++var22) {
						AssetSplitBodyVO bodyVO = var20[var22];
						if (bodyVO.getStatus() != 0 && ArrayUtils.isNotEmpty(bodyVO.getDeptscaleVOs())) {
							DeptScaleVO[] var24 = bodyVO.getDeptscaleVOs();
							int var26 = var24.length;

							for (int var13 = 0; var13 < var26; ++var13) {
								DeptScaleVO dept = var24[var13];
								dept.setLink_key((String) null);
								dept.setPk_deptscale((String) null);
							}

							bodyVO.setUsedept((String) null);
							List<DeptScaleVO> vos = ((IUseDeptScaleService) AMProxy.lookup(IUseDeptScaleService.class))
									.insertForSplit(bodyVO, deptVersionMap, orgVO);
							MDPersistenceService.lookupPersistenceService().saveBillWithRealDelete(
									(CircularlyAccessibleValueObject[]) vos.toArray(new DeptScaleVO[0]));
						}
					}
				}
			}
		}

		AssetSplitHeadVO headVO = (AssetSplitHeadVO) vo.getParentVO();
		DeptScaleVO[] deptScaleVOs = ((IAssetService) AMProxy.lookup(IAssetService.class))
				.queryUseDept(headVO.getPk_card());
		if (ArrayUtils.isNotEmpty(deptScaleVOs)) {
			DeptScaleVO[] depts = deptScaleVOs;
			int var19 = deptScaleVOs.length;

			for (var7 = 0; var7 < var19; ++var7) {
				DeptScaleVO dept = depts[var7];
				dept.setLink_key((String) null);
				dept.setPk_deptscale((String) null);
			}

			headVO.setUsedept((String) null);
			depts = UseDeptScaleUtils.insert(deptScaleVOs);
			headVO.setUsedept(depts[0].getLink_key());
		}

		if (StringUtils.isEmpty(headVO.getTransi_type())) {
			headVO.setTransi_type("HM-01");
		}

	}

	public TransportBillVO update(LoginContext context, AssetSplitVO vo) throws BusinessException {
		LockManager.lock(new BaseLockData(vo));
		this.dealWithUseDept(vo);
		AssetSplitVO[] returnVOs = (AssetSplitVO[]) this.updateBillVO(new AssetSplitVO[]{vo},null);
		this.releasePKCardLock(vo, context);
		TransportBillVO transportBillVO = null;
		if (ArrayUtils.isNotEmpty(returnVOs)) {
			AssetSplitVO returnVO = returnVOs[0];
			this.setMultiDeptForVO(returnVO);
			transportBillVO = BillTransportTool.createTransportBill(returnVO, new String[]{"usedept"},
					new String[]{"usedept"}, 2);
		}

		return transportBillVO;
	}

	public AssetSplitVO commit(LoginContext context, AssetSplitVO[] billVOs) throws BusinessException {
		AssetSplitVO[] returnVOs = (AssetSplitVO[]) this.commitBillVO(billVOs);
		AssetSplitVO billVO = ArrayUtils.isEmpty(returnVOs) ? null : returnVOs[0];
		return billVO;
	}

	public AssetSplitVO unSave(AssetSplitVO[] billVOs) throws BusinessException {
		AssetSplitVO[] returnVOs = (AssetSplitVO[]) this.unSaveBillVOs(billVOs);
		AssetSplitVO billVO = ArrayUtils.isEmpty(returnVOs) ? null : returnVOs[0];
		return billVO;
	}

	protected void initInsertActionRules(IActionTemplate<AssetSplitVO> insertAction) {
		super.initInsertActionRules(insertAction);
		List<Validator> validators = new ArrayList();
		validators.add(new FAAccbookCheckSealRule());
		validators.add(new CheckCardLegalValidator(true, false));
		validators.add(new CheckHeadMinUnClosedBookPeriodValidator());
		validators.add(new CheckCreatedCardMinUnClosedBookPeriodValidator());
		validators.add(new CheckBodysAssetCodeLegalValidator());
		validators.add(new CheckBodysAssetCategoryLegalValidator());
		validators.add(new CheckSameAccbookValidator());
		validators.add(new CheckWorkloanInfosValidator());
		validators.add(new CheckHasFipMakeVoucherForAccbooks());
		validators.add(new CheckBodyDepStartDateValidator());
		insertAction.addBeforeRule(new ValidateServiceRule(validators));
		insertAction.addBeforeRule(new PKAccbookBeforeRule());
		insertAction.addBeforeRule(new BillCodeInsertBeforeRule());
		insertAction.addAfterRule(new BillCodeInsertAfterRule());
		insertAction.addAfterRule(new AssetSplitUpdateCardLogAfterRule(false));
	}

	protected void initUpdateActionRules(IActionTemplate<AssetSplitVO> updateAction) {
		super.initUpdateActionRules(updateAction);
		List<Validator> validators = new ArrayList();
		validators.add(new CheckCardLegalValidator(true, false));
		validators.add(new CheckHeadMinUnClosedBookPeriodValidator());
		validators.add(new CheckCreatedCardMinUnClosedBookPeriodValidator());
		validators.add(new CheckBodysAssetCodeLegalValidator());
		validators.add(new CheckSameAccbookValidator());
		validators.add(new CheckWorkloanInfosValidator());
		validators.add(new CheckBodyDepStartDateValidator());
		updateAction.addBeforeRule(new ValidateServiceRule(validators));
		updateAction.addBeforeRule(new LockAssetCardRule());
		updateAction.addBeforeRule(new BillCodeUpdateRule());
		updateAction.addAfterRule(new AssetSplitUpdateCardLogAfterRule(false, false, true));
	}

	protected void initDeleteActionRules(IActionTemplate<AssetSplitVO> deleteAction) {
		super.initDeleteActionRules(deleteAction);
		deleteAction.addBeforeRule(new VOSagasStatusCheckBeforeRule());
		deleteAction.addAfterRule(new BillCodeDeleteRule());
		deleteAction.addAfterRule(new AssetSplitUpdateCardLogAfterRule(false, true));
	}

	protected void initApproveRule(ApproveActionTemplate<AssetSplitVO> template) {
		List<Validator> validators = new ArrayList();
		validators.add(new FAAccbookCheckSealRule());
		validators.add(new CheckHasFipMakeVoucherForAccbooks());
		template.addApprovedBeforeRule(new IRule[]{new VOSagasStatusCheckBeforeRule()});
		template.addApprovedBeforeRule(new IRule[]{new ValidateServiceRule(validators)});
		List<IRule<AssetSplitVO>> approvePassAfterRules = new ArrayList();
		approvePassAfterRules.add(new SplitAssetInMultiAccbookRule());
		approvePassAfterRules.add(new AssetSplitUpdateCardLogAfterRule(true));
		approvePassAfterRules.add(new ReduceSplitedAssetRule());
		approvePassAfterRules.add(new AddNewAssetRule());

		approvePassAfterRules.add(new UpdateRelatedEquipsInfoForApprovingRule());
		approvePassAfterRules.add(new CreateBillLogAfterRule(LogTypeConst.split));
		approvePassAfterRules.add(new ARMSplitAssetsApproveAfterRule()); 
		template.addApprovePassAfterRule(approvePassAfterRules);
	}

	protected void initUnApproveRule(UnApproveActionTemplate<AssetSplitVO> template) {
		List<Validator> validators = new ArrayList();
		validators.add(new FAAccbookCheckSealRule());
		validators.add(new CheckCardLegalValidator(true, false));
		validators.add(new CheckBodysAssetCategoryLegalValidator());
		validators.add(new CheckMinUnClosedBookPeriodValidator());
		validators.add(new CheckHasFipMakeVoucherForAccbooks());
		List<IRule<AssetSplitVO>> unApprovBeforeRules = new ArrayList();
		unApprovBeforeRules.add(new VOSagasStatusCheckBeforeRule());
		unApprovBeforeRules.add(new ValidateServiceRule(validators));
		template.addUnApprovedBeforeRules(unApprovBeforeRules);
		List<IRule<AssetSplitVO>> lastUnApprovedAfterRules = new ArrayList();
		lastUnApprovedAfterRules.add(new CancelAssetReduceRule());
		lastUnApprovedAfterRules.add(new DeleteBillLogAfterRule());
		lastUnApprovedAfterRules.add(new AssetSplitUpdateCardLogAfterRule(false));
		lastUnApprovedAfterRules.add(new UpdateRelatedEquipInfoForUnapprovingRule());
		lastUnApprovedAfterRules.add(new ClearBodyAssetCardInfoRule());
		
		template.addLastUnApprovedAfterRules(lastUnApprovedAfterRules);
	}

	protected void initUnSaveActionRules(IActionTemplate<AssetSplitVO> template) {
		super.initUnSaveActionRules(template);
		template.addBeforeRule(new VOSagasStatusCheckBeforeRule());
	}

	protected void releasePKCardLock(AssetSplitVO billVO, LoginContext context) throws BusinessException {
		if (billVO != null) {
			String pk_card = ((AssetSplitHeadVO) billVO.getParent()).getPk_card();
			if (context != null) {
				LockManager.releasePKLocks(new String[]{pk_card}, context.getPk_loginUser());
			} else {
				LockManager.releasePKLocks(new String[]{pk_card}, InvocationInfoProxy.getInstance().getUserId());
			}

		}
	}

	private AssetSplitVO reQueryBillByPK(String... pks) {
		AssetSplitVO[] aggVO = (AssetSplitVO[]) QueryUtil.queryBillVOByPks(AssetSplitVO.class, pks, true);
		return aggVO != null && aggVO.length != 0 ? aggVO[0] : null;
	}

	public SuperVO[] setBodyMultiDeptscaleVOs(SuperVO[] superVOs) throws BusinessException {
		AssetSplitBodyVO[] bodyVOs = (AssetSplitBodyVO[]) ((AssetSplitBodyVO[]) superVOs);
		String[] usedeptPks = (String[]) VOManager.getAttributeValueArray(bodyVOs, "usedept");
		Map<String, List<DeptScaleVO>> deptListMap = null;
		if (ArrayUtils.isNotEmpty(usedeptPks)) {
			deptListMap = UseDeptScaleUtils.queryDeptScaleBatch(usedeptPks);
		}

		if (MapUtils.isNotEmpty(deptListMap)) {
			AssetSplitBodyVO[] var5 = bodyVOs;
			int var6 = bodyVOs.length;

			for (int var7 = 0; var7 < var6; ++var7) {
				AssetSplitBodyVO bodyVO = var5[var7];
				DeptScaleVO[] deptVOs = (DeptScaleVO[]) CollectionUtils
						.toArray((Collection) deptListMap.get(bodyVO.getUsedept()));
				String bodyPk_dept_key = FAUseDeptKeyGenerator.generatorKeyForAssetSplit(deptVOs);
				bodyVO.setDeptscaleVOs(deptVOs);
				bodyVO.setAttributeValue("usedept", DeptScaleManager.getShowName(deptVOs));
				bodyVO.setAttributeValue("bodypk_dept_key", bodyPk_dept_key);
			}
		}

		return bodyVOs;
	}

	public AssetSplitHeadVO setHeadMultiDeptscaleVOs(AssetSplitHeadVO headVO) throws BusinessException {
		String usedeptPk = headVO.getUsedept();
		Map<String, List<DeptScaleVO>> deptListMap = null;
		if (StringUtils.isNotEmpty(usedeptPk)) {
			deptListMap = UseDeptScaleUtils.queryDeptScaleBatch(new String[]{usedeptPk});
			DeptScaleVO[] deptScaleVOs = (DeptScaleVO[]) CollectionUtils
					.toArray((Collection) deptListMap.get(usedeptPk));
			List<String> pk_deptList = new ArrayList();
			StringBuilder pk_dept_key = new StringBuilder();
			if (ArrayUtils.isNotEmpty(deptScaleVOs)) {
				DeptScaleVO[] var7 = deptScaleVOs;
				int var8 = deptScaleVOs.length;

				for (int var9 = 0; var9 < var8; ++var9) {
					DeptScaleVO deptVO = var7[var9];
					pk_deptList.add(deptVO.getPk_dept());
				}

				Arrays.sort(pk_deptList.toArray(new String[0]));

				for (int i = 0; i < pk_deptList.size(); ++i) {
					String pkDept = (String) pk_deptList.get(i);
					pk_dept_key.append(pkDept);
				}
			}

			headVO.setDeptscaleVOs(deptScaleVOs);
			headVO.setAttributeValue("usedept", DeptScaleManager.getShowName(deptScaleVOs));
			headVO.setAttributeValue("pk_dept_key", pk_dept_key);
		}

		return headVO;
	}

	public List<String> queryCategoryCodeBySql(String sql, String pk_org, List<String> setOfBook)
			throws BusinessException {
		DBAccessUtil dbUtil = new DBAccessUtil();
		List<String> pk_categorys = dbUtil.querySingleColumn(sql.toString());
		if (setOfBook.size() > 1) {
			Map<String, List<String>> cate2setOfBook = ((IAccbookInfoService) AMProxy.lookup(IAccbookInfoService.class))
					.querySetAccbookByCategorys(pk_org, pk_categorys);
			Iterator var7 = cate2setOfBook.keySet().iterator();

			while (var7.hasNext()) {
				String pk_category = (String) var7.next();
				if (null != cate2setOfBook.get(pk_category)
						&& !((List) cate2setOfBook.get(pk_category)).containsAll(setOfBook)) {
					pk_categorys.remove(pk_category);
				}
			}
		}

		String querySQL = "select innercode from fa_category where pk_category in "
				+ InSqlManager.getInSQLValue(pk_categorys);
		List<String> innercodes = dbUtil.querySingleColumn(querySQL);
		return innercodes;
	}

	public UFDate isMinUnCloseMonth(String pk_org, String pk_card, UFDate busi_date) throws BusinessException {
		CloseBookImpl closebookService = new CloseBookImpl();
		Map<String, List<String>> pk_card2pk_accbook = (new AssetServiceImpl())
				.queryCardAssociateAccbooks(new String[]{pk_card});
		String[] pk_accbooks = (String[]) ((List) pk_card2pk_accbook.get(pk_card)).toArray(new String[0]);
		Map<String, UFBoolean> pk_accbook2isMinCloseMonth = closebookService.queryIsMinUnClosePeriod(pk_org,
				busi_date.toString(), pk_accbooks);
		if (pk_accbook2isMinCloseMonth.values().contains(UFBoolean.valueOf(false))) {
			AccperiodVO minUnCloseBookPeriod = closebookService.queryMinUnClosebookPeriod(pk_org, pk_accbooks[0]);
			UFDate endDate = minUnCloseBookPeriod.getEnddate();
			return endDate;
		} else {
			return busi_date;
		}
	}

	public Object[] queryObjectByBillVOs(AbstractAggBill[] billVOs) throws BusinessException {
		List<AssetSplitHeadVO> headVOs = new ArrayList();
		new ArrayList();
		AssetSplitVO[] AssetSplitVOs = (AssetSplitVO[]) ((AssetSplitVO[]) billVOs);
		if (ArrayUtils.isNotEmpty(billVOs)) {
			AbstractAggBill[] var5 = billVOs;
			int var6 = billVOs.length;

			for (int var7 = 0; var7 < var6; ++var7) {
				AbstractAggBill billVO = var5[var7];
				SuperVO[] bodyVOs = billVO.getChildrenVO();
				if (ArrayUtils.isNotEmpty(bodyVOs)) {
					try {
						bodyVOs = ((IAssetSplit) AMProxy.lookup(IAssetSplit.class)).setBodyMultiDeptscaleVOs(bodyVOs);
					} catch (BusinessException var12) {
						throw new MetaDataException(var12.getMessage());
					}
				}

				billVO.setChildren(AssetSplitBodyVO.class, bodyVOs);
				AssetSplitHeadVO headVO = (AssetSplitHeadVO) billVO.getParentVO();
				headVOs.add(headVO);
			}

			List newHeadVOs;
			try {
				newHeadVOs = this.setHeadMultiDeptscaleVO(headVOs);
			} catch (BusinessException var11) {
				throw new MetaDataException(var11.getMessage());
			}

			for (int i = 0; i < AssetSplitVOs.length; ++i) {
				AssetSplitVOs[i].setParentVO((CircularlyAccessibleValueObject) newHeadVOs.get(i));
			}
		}

		return billVOs;
	}

	public List<AssetSplitHeadVO> setHeadMultiDeptscaleVO(List<AssetSplitHeadVO> headVOs) throws BusinessException {
		List<AssetSplitHeadVO> VOs = new ArrayList();
		Object[] usedeptPks = VOManager.getAttributeValueArray(
				(CircularlyAccessibleValueObject[]) headVOs.toArray(new AssetSplitHeadVO[0]), "usedept");
		Map<String, List<DeptScaleVO>> deptListMaps = null;
		if (ArrayUtils.isNotEmpty(usedeptPks)) {
			deptListMaps = UseDeptScaleUtils.queryDeptScaleBatch((String[]) ((String[]) usedeptPks));
			if (MapUtils.isNotEmpty(deptListMaps)) {
				Iterator var5 = headVOs.iterator();

				while (var5.hasNext()) {
					AssetSplitHeadVO headVO = (AssetSplitHeadVO) var5.next();
					DeptScaleVO[] deptScaleVOs = (DeptScaleVO[]) CollectionUtils
							.toArray((Collection) deptListMaps.get(headVO.getUsedept()));
					List<String> pk_deptList = new ArrayList();
					StringBuilder pk_dept_key = new StringBuilder();
					if (ArrayUtils.isNotEmpty(deptScaleVOs)) {
						DeptScaleVO[] var10 = deptScaleVOs;
						int var11 = deptScaleVOs.length;

						for (int var12 = 0; var12 < var11; ++var12) {
							DeptScaleVO deptVO = var10[var12];
							pk_deptList.add(deptVO.getPk_dept());
						}

						Arrays.sort(pk_deptList.toArray(new String[0]));

						for (int i = 0; i < pk_deptList.size(); ++i) {
							String pkDept = (String) pk_deptList.get(i);
							pk_dept_key.append(pkDept);
						}
					}

					headVO.setDeptscaleVOs(deptScaleVOs);
					headVO.setAttributeValue("usedept", DeptScaleManager.getShowName(deptScaleVOs));
					headVO.setAttributeValue("pk_dept_key", pk_dept_key);
					VOs.add(headVO);
				}
			}
		}

		return VOs;
	}

	public AssetSplitVO[] queryVOByPK(String... pk) throws BusinessException {
		AssetSplitVO[] aggVO = (AssetSplitVO[]) QueryUtil.queryBillVOByPks(AssetSplitVO.class, pk, true);
		return aggVO;
	}
}