package nccloud.pubimpl.gl.assbalance;

import nc.bd.accperiod.InvalidAccperiodExcetion;
import nc.bs.framework.common.InvocationInfoProxy;
import nc.bs.framework.common.NCLocator;
import nc.bs.logging.Logger;
import nc.gl.account.glconst.CurrTypeConst;
import nc.gl.utils.DataFormatUtilGL;
import nc.gl.utils.GLMultiLangUtil;
import nc.itf.bd.pub.IBDMetaDataIDConst;
import nc.itf.gl.accbook.IRemoteBillModel;
import nc.itf.gl.accountingbook.IAccountingbookService;
import nc.itf.gl.pub.IGlPeriod;
import nc.itf.gl.pub.ILinkQueryParamTransfer;
import nc.itf.glcom.para.GLParaAccessor;
import nc.itf.org.IOrgMetaDataIDConst;
import nc.itf.pubbd.profitcenter.IProfitCenterPubService;
import nc.itf.uap.busibean.SysinitAccessor;
import nc.pub.gl.query.AssBlcResultGetter;
import nc.pub.gl.query.CBalanceAssTool;
import nc.pub.gl.query.GlQueryVOAssTool;
import nc.pub.gl.query.GlQueryVOContainer;
import nc.pubitf.accperiod.AccountCalendar;
import nc.pubitf.bd.accessor.GeneralAccessorFactory;
import nc.pubitf.bd.accessor.IGeneralAccessor;
import nc.ui.fi.uforeport.BSDataSourceControl;
import nc.vo.bd.accassitem.AccAssItemVO;
import nc.vo.bd.accessor.IBDData;
import nc.vo.bd.account.AccountVO;
import nc.vo.bd.account.pub.AccountGLSimpleVO;
import nc.vo.bd.currtype.CurrtypeVO;
import nc.vo.bd.material.MaterialVO;
import nc.vo.bd.pub.BDCacheQueryUtil;
import nc.vo.fipub.freevalue.account.proxy.AccAssGL;
import nc.vo.fipub.freevalue.util.FreeValueDefUtil;
import nc.vo.fipub.utils.StrTools;
import nc.vo.gateway60.accountbook.AccountBookUtil;
import nc.vo.gateway60.itfs.AccountByPkThreadCache;
import nc.vo.gateway60.itfs.AccountUtilGL;
import nc.vo.gateway60.itfs.CalendarUtilGL;
import nc.vo.gateway60.itfs.CurrtypeGL;
import nc.vo.gl.balancesubjass.BalanceSubjAssBSKey;
import nc.vo.gl.balancesubjass.BalanceSubjAssBSVO;
import nc.vo.glcom.account.Balanorient;
import nc.vo.glcom.ass.AssAccessorManager;
import nc.vo.glcom.ass.AssVO;
import nc.vo.glcom.balance.GLQueryObj;
import nc.vo.glcom.balance.GlQryFormatVO;
import nc.vo.glcom.balance.GlQueryVO;
import nc.vo.glcom.glperiod.GlPeriodVO;
import nc.vo.glcom.tools.BaseCorpChooser;
import nc.vo.glcom.tools.GLPubProxy;
import nc.vo.ml.NCLangRes4VoTransl;
import nc.vo.profitcenter.ProfitcenterVersionVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.lang.UFBoolean;
import nc.vo.pub.lang.UFDate;
import nc.vo.pub.lang.UFDouble;
import nccloud.dto.gl.lightgl.displayformattool.ShowContentCenter;
import nccloud.pub.gl.lightgl.ColumnInfo;
import nccloud.pub.gl.lightgl.IColumnInfo;
import nccloud.pubimpl.gl.account.AccountRepUtil;
import nccloud.pubimpl.gl.account.GLReportFormat;
import nccloud.pubimpl.gl.util.JsonUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

public class AssBalanceQueryBO {

    private String pk_localcurr;

    private GLReportFormat format = new GLReportFormat(BalanceSubjAssBSKey.K_PK_ACCOUNTINGBOOK, BalanceSubjAssBSKey.K_ACCSUBJCODE, BalanceSubjAssBSKey.K_PK_CURRTYPE);

    public Map<String, Object> queryAssBalance(Map<String, Object> params) throws BusinessException{
        BSDataSourceControl envInit = initEnvirment(params);
        try {
            GlQueryVO qryvo = null;
            // 处理联查
            if (params.get("link") != null) {
                try {
                    String classname = params.get("class").toString();
                    Class<?> clazz = Class.forName(classname);
                    ILinkQueryParamTransfer transfer = (ILinkQueryParamTransfer) clazz.newInstance();
                    qryvo = (GlQueryVO) transfer.transLinkQueryParam(params);
                } catch (Exception e) {
                    Logger.error(e.getMessage(), e);
                    throw new BusinessException(e.getMessage(), e);
                }
            } else {
                qryvo = getQueryVO(params);
                AccountRepUtil.checkQueryVO(qryvo);
                AccountRepUtil.checkPeriodSpan(qryvo);
                checkQryObjs(qryvo);
            }
            if (!GlQueryVOAssTool.isMultiPages(qryvo)) {
                Logger.info("*************************************************");
                Logger.info("进入辅助余额表单页处理");
                Logger.info("*************************************************");
                return queryOnePage(qryvo);
            } else {
                Logger.info("*************************************************");
                Logger.info("进入辅助余额表单翻页处理，预分为  " + GlQueryVOAssTool.getPages(qryvo) + " 页");
                Logger.info("*************************************************");
                return queryMultiPage(qryvo);
            }
        } catch (BusinessException e) {
            Logger.error(e.getMessage(), e);
            throw new BusinessException(e.getMessage(), e);
        } catch (Exception e) {
            Logger.error(e.getMessage(), e);
            throw new BusinessException(e.getMessage(), e);
        } finally {
            if (envInit != null) {
                envInit.afterPress("", null, null);
            }
        }
    }

    /**
     * 初始化数据源环境变量（报表联查跨数据源）
     *
     * @param params
     * @throws BusinessException
     */
    public BSDataSourceControl initEnvirment(Map<String, Object> params) throws BusinessException {
        if (params.containsKey("env")) {
            try {
                String env = (String) params.get("env");
                String[] envs = env.replace("[", "").replace("]", "").replaceAll("\"", "").split(",");
                BSDataSourceControl envInit = new BSDataSourceControl();
                envInit.beforePress(null, envs, null);
                return envInit;
            } catch (Exception e) {
                Logger.error(e.getMessage());
                throw new BusinessException(e.getMessage(), e);
            }
        }
        return null;
    }

    public GlQueryVO constructQueryVO(Map<String, Object> params) throws Exception {
        GlQueryVO qryvo = null;
        // 处理联查
        if (params.get("link") != null) {
            try {
                String classname = params.get("class").toString();
                Class<?> clazz = Class.forName(classname);
                ILinkQueryParamTransfer transfer = (ILinkQueryParamTransfer) clazz.newInstance();
                qryvo = (GlQueryVO) transfer.transLinkQueryParam(params);
            } catch (Exception e) {
                Logger.error(e.getMessage(), e);
                throw new BusinessException(e.getMessage(), e);
            }
        } else {
            qryvo = getQueryVO(params);
            AccountRepUtil.checkQueryVO(qryvo);
            AccountRepUtil.checkPeriodSpan(qryvo);
            checkQryObjs(qryvo);
        }
        return qryvo;
    }
    public Map<String, Object> queryAssBalance2(Map<String, Object> params) throws BusinessException{
        try {
            GlQueryVO qryvo = constructQueryVO(params);
            checkQryObjs(qryvo);
            return queryPageData(qryvo);
        } catch (BusinessException e) {
            Logger.error(e.getMessage(), e);
            throw new BusinessException(e.getMessage(), e);
        } catch (Exception e) {
            Logger.error(e.getMessage(), e);
            throw new BusinessException(e.getMessage(), e);
        }
    }

    public Map<String, Object> queryPageData(GlQueryVO qryvo) throws Exception {
        if (!GlQueryVOAssTool.isMultiPages(qryvo)) {
            Logger.info("*************************************************");
            Logger.info("进入辅助余额表单页处理");
            Logger.info("*************************************************");
            return queryOnePage2(qryvo);
        } else {
            Logger.info("*************************************************");
            Logger.info("进入辅助余额表单翻页处理，预分为  " + GlQueryVOAssTool.getPages(qryvo) + " 页");
            Logger.info("*************************************************");
            return queryMultiPage2(qryvo);
        }
    }
    private Map<String, Object> queryOnePage2(GlQueryVO qryvo) throws Exception {
        GlQueryVOAssTool.suplyCurrentGlQueryVO(qryvo);
        GlQueryVOAssTool.getSuplyedGLQueryObj(qryvo.getFormatVO().getQryObjs());
        IRemoteBillModel blnsbjAssMdl = GLPubProxy.getIRemoteBillModel();
        BalanceSubjAssBSVO[] bvos = (BalanceSubjAssBSVO[]) blnsbjAssMdl.dealQueryAssBalance(qryvo);
        Map<String, Object> res = getRes(qryvo);
        List<Map<String,Object>> pages = new ArrayList<Map<String,Object>>();
        Map<String, Object> page = new HashMap<String, Object>();
        page.put("pagedata", bvos);
        pages.add(page);
        res.put("data", pages);
        return res;
    }
    private Map<String, Object> queryMultiPage2(GlQueryVO qryvo) throws Exception {
        IRemoteBillModel blnsbjAssMdl = GLPubProxy.getIRemoteBillModel();
        GlQueryVOContainer glQryCtner = blnsbjAssMdl.getQueryVOContainer(qryvo);
        if(glQryCtner!=null){
            for(int i =0;i<glQryCtner.getSize();i++){
                if (glQryCtner.getQueryAt(i) != null) {
                    glQryCtner.getQueryAt(i).setGlChartConditionVO(qryvo.getGlChartConditionVO());
                }
            }
        }
        List<Map<String,Object>> pages = new ArrayList<Map<String,Object>>();
        if (glQryCtner.getSize() > 0) {
            BalanceSubjAssBSVO[] allBvos = (BalanceSubjAssBSVO[]) glQryCtner.getVos();
            if(allBvos != null) {
                BlnSbjAssMdlSttl blnSbjAssMdlSttl = new BlnSbjAssMdlSttl();
                for (Object key : glQryCtner.getVKeys()) {
                    String assCode = (String) key;
                    GlQueryVO copyStartQryvo = (GlQueryVO) qryvo.clone();
                    GlQueryVOAssTool.suplyCurrentGlQueryVO(copyStartQryvo);
                    GlQueryVO tempQryVO = GlQueryVOAssTool.getGlQueryVOMultiPage(copyStartQryvo, assCode);
                    BalanceSubjAssBSVO[] tempBvos = AssBlcResultGetter.getBlnVOsByQryVOs(assCode, allBvos);
                    tempBvos = blnSbjAssMdlSttl.getSettleedDatas(tempBvos, tempQryVO);
                    Map<String, Object> page = new HashMap<String, Object>();
//					List<Map<String, Object>> data = getData(copyStartQryvo, tempBvos);
                    page.put("pageinfo", getHeadKeyName(tempQryVO));
                    page.put("pagedata", tempBvos);
                    pages.add(page);
                }
            } else {
                for(int i =0 ;i<glQryCtner.getVKeys().size();i++) {
                    GlQueryVO tempQryVO = glQryCtner.getQueryAt(i);
                    BalanceSubjAssBSVO[] tempBvos = (BalanceSubjAssBSVO[]) glQryCtner.getBalaceVOsAt(i);
                    Map<String, Object> page = new HashMap<String, Object>();
//					List<Map<String, Object>> data = getData(tempQryVO, tempBvos);
                    page.put("pageinfo", getHeadKeyName(tempQryVO));
                    page.put("pagedata", tempBvos);
                    pages.add(page);
                }
            }
        }
        Map<String, Object> res = getRes(qryvo);
        res.put("data", pages);
        return res;
    }
    /**
     * 辅助余额表翻页处理
     * nc.ui.gl.assbalance.BalanceSubjAssView.query(GlQueryVO newQryVO)
     * @param qryvo
     * @return
     * @throws Exception
     */
    private Map<String, Object> queryMultiPage(GlQueryVO qryvo) throws Exception {
        IRemoteBillModel blnsbjAssMdl = GLPubProxy.getIRemoteBillModel();
        GlQueryVOContainer glQryCtner = blnsbjAssMdl.getQueryVOContainer(qryvo);
        if(glQryCtner!=null){
            for(int i =0;i<glQryCtner.getSize();i++){
                if (glQryCtner.getQueryAt(i) != null) {
                    glQryCtner.getQueryAt(i).setGlChartConditionVO(qryvo.getGlChartConditionVO());
                }
            }
        }
        boolean showPageLength = false;
        List<Map<String,Object>> pages = new ArrayList<Map<String,Object>>();
        if (glQryCtner != null && glQryCtner.getSize() > 0) {
            showPageLength = true;
            BalanceSubjAssBSVO[] allBvos = (BalanceSubjAssBSVO[]) glQryCtner.getVos();
            if(allBvos != null) {
                BlnSbjAssMdlSttl blnSbjAssMdlSttl = new BlnSbjAssMdlSttl();
                for (Object key : glQryCtner.getVKeys()) {
                    String assCode = (String) key;
                    GlQueryVO copyStartQryvo = (GlQueryVO) qryvo.clone();
                    GlQueryVOAssTool.suplyCurrentGlQueryVO(copyStartQryvo);
                    GlQueryVO tempQryVO = GlQueryVOAssTool.getGlQueryVOMultiPage(copyStartQryvo, assCode);
                    BalanceSubjAssBSVO[] tempBvos = AssBlcResultGetter.getBlnVOsByQryVOs(assCode, allBvos);
                    tempBvos = blnSbjAssMdlSttl.getSettleedDatas(tempBvos, tempQryVO);
                    Map<String, Object> page = new HashMap<String, Object>();
                    List<Map<String, Object>> data = getData(copyStartQryvo, tempBvos);
                    page.put("pageinfo", getHeadKeyName(tempQryVO));
                    page.put("pagedata", data);
                    pages.add(page);
                }
            } else {
                for(int i =0 ;i<glQryCtner.getVKeys().size();i++) {
                    GlQueryVO tempQryVO = glQryCtner.getQueryAt(i);
                    BalanceSubjAssBSVO[] tempBvos = (BalanceSubjAssBSVO[]) glQryCtner.getBalaceVOsAt(i);
                    Map<String, Object> page = new HashMap<String, Object>();
                    List<Map<String, Object>> data = getData(tempQryVO, tempBvos);
                    page.put("pageinfo", getHeadKeyName(tempQryVO));
                    page.put("pagedata", data);
                    pages.add(page);
                }
            }
        } else {
            Map<String, Object> page = new HashMap<String, Object>();
            page.put("pageinfo", "");
            page.put("pagedata", "");
            pages.add(page);
        }
        Map<String, Object> res = getRes(qryvo);
        res.put("data", pages);
        res.put("showpagelength", showPageLength);// 按表头查询时，若未查到数据，则不提示页码信息
        return res;
    }

    /**
     * 翻页表头
     * @param qryvo
     * @return
     */
    private String getHeadKeyName(GlQueryVO qryvo) {
        String headKeyName = "";
        GLQueryObj[] queryObjs = qryvo.getFormatVO().getQryObjs();
        for (int i = 0; i < queryObjs.length; i++) {
            GLQueryObj queryObj = queryObjs[i];
            if (queryObj.getHeadEle()) {
                if(queryObj.getTypeName().equals(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000031")/* @res "会计科目" */)) {
                    String subjName = ShowContentCenter.getShowAccsubj(qryvo.getBaseAccountingbook(), qryvo.getPk_account()[0], qryvo.getSubjVersion());
                    headKeyName = NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000135")/* @res "【科 目：" */+ subjName
                            + NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000136")/* @res "】" */ + headKeyName;
                } else {
                    String pk_checktype = "";
                    if(queryObj.getValueRange()!=null && queryObj.getValueRange()[0]!=null) {
                        pk_checktype = queryObj.getValueRange()[0].getPk_Checktype();
                    }
                    if(!StrTools.isEmptyStr(pk_checktype)) {
                        if (qryvo.getAssVos() != null || qryvo.getAssVos().length > 0) {
                            for (AssVO assvo : qryvo.getAssVos()) {
                                if (pk_checktype.equals(assvo.getPk_Checktype())) {
                                    headKeyName += ShowContentCenter.getShowAss(qryvo.getBaseAccountingbook(), new AssVO[] { assvo });
                                }
                            }
                        }
                    }
                }
            }
        }
        return headKeyName;
    }

    /**
     * 辅助余额表单页处理
     * nc.ui.gl.assbalance.BalanceSubjAssView.queryOnePage(GlQueryVO newQryVO)
     * @param qryvo
     * @return
     * @throws Exception
     */
    private Map<String, Object> queryOnePage(GlQueryVO qryvo) throws Exception {
        GlQueryVOAssTool.suplyCurrentGlQueryVO(qryvo);
        GlQueryVOAssTool.getSuplyedGLQueryObj(qryvo.getFormatVO().getQryObjs());
        IRemoteBillModel blnsbjAssMdl = GLPubProxy.getIRemoteBillModel();
        BalanceSubjAssBSVO[] bvos = (BalanceSubjAssBSVO[]) blnsbjAssMdl.dealQueryAssBalance(qryvo);
        Map<String, Object> res = getRes(qryvo);
        List<Map<String,Object>> pages = new ArrayList<Map<String,Object>>();
        Map<String, Object> page = new HashMap<String, Object>();
        page.put("pagedata", getData(qryvo, bvos));
        pages.add(page);
        res.put("data", pages);
        res.put("showpagelength", false);// 按表体查询，不需提示页码信息
        return res;
    }

    /**
     * 小友机器人智能查账，补充必要参数
     *
     * @param params
     * @throws BusinessException
     */
    private void fillParamMap(Map<String, Object> params) throws BusinessException {
        // 小友参数，期间yyyyMM-yyyyMM
        String companyPK = (String) ((Map<?, ?>) params.get("companychoose")).get("pk_org");
        String accountingPeriod = JsonUtils.getStrEmpty(params.get("accountingPeriod"));
        String auxiliaryFiles = JsonUtils.getStrEmpty(params.get("auxiliaryFiles"));
        String accountSubject = JsonUtils.getStrNULL(params.get("accountSubject"));
        // 处理账簿、期间、辅助项、科目等参数
        List<String> accountingbook_pks = new ArrayList<String>();
        String pk_accountingbook = AccountRepUtil.getAccountingbookPKByOrgPK(companyPK);
        accountingbook_pks.add(pk_accountingbook);
        UFDate bizDate = new UFDate(InvocationInfoProxy.getInstance().getBizDateTime());
        AccountCalendar calendar = CalendarUtilGL.getAccountCalendarByAccountBook(pk_accountingbook);
        calendar.setDate(bizDate);
        String periodyear = calendar.getYearVO().getPeriodyear();
        if (StrTools.isEmptyStr(accountingPeriod) ||accountingPeriod.length()>40|| !accountingPeriod.matches("\\d{6}-\\d{6}[^\\s]*")) {
            throw new BusinessException(
                    "会计期间格式不正确！请按照如下示例：" + periodyear + "01" + StrTools.PERIODSPLIT + periodyear + "03");
        }
        String[] splitPeriod = accountingPeriod.split(StrTools.PERIODSPLIT);
        String year_begin = splitPeriod[0].substring(0, 4);
        String year_end = splitPeriod[1].substring(0, 4);
        String period_begin = splitPeriod[0].substring(4);
        String period_end = splitPeriod[1].substring(4);
        if (StrTools.isEmptyStr(year_begin)) {
            year_begin = periodyear;
        }
        if (StrTools.isEmptyStr(year_end)) {
            year_end = year_begin;
        }
        if (StrTools.isEmptyStr(period_begin)) {
            period_begin = calendar.getMonthVO().getAccperiodmth();
        }
        if (StrTools.isEmptyStr(period_end)) {
            period_end = period_begin;
        }
        String commaEn = ",";
        String commaCh = "，";
        String[] itemname = auxiliaryFiles.contains(commaEn) ? auxiliaryFiles.split(commaEn)
                : auxiliaryFiles.split(commaCh);
        // 设置默认参数
        params.put("pk_glorgbooks", accountingbook_pks);
        params.put("selectionState", true);
        params.put("beginyear", year_begin);
        params.put("endyear", year_end);
        params.put("beginperiod", period_begin);
        params.put("endperiod", period_end);
        params.put("includeUnTallyed", true);
        params.put("includeError", true);
        params.put("includeTransfer", true);
        params.put("includeReClassify", false);
        params.put("currTypeName", CurrTypeConst.QUERY_LOC_CURRTYPE());
        params.put("return_currtype", CurrTypeConst.LOC_RETURN);
        params.put("balanceDirection", Balanorient.TWOWAY);
        // 查询对象：会计科目
        List<Map<String, Object>> qryObjs = new ArrayList<Map<String, Object>>();
        Map<String, Object> accountQryObj = new HashMap<String, Object>(6);
        String MultiLang_Account = NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000031");/** @res * "会计科目" */
        accountQryObj.put("name", MultiLang_Account);
        accountQryObj.put("pk_checktype", MultiLang_Account);
        if (!StrTools.isEmptyStr(accountSubject)) {
            StringBuilder pk_accasoa = new StringBuilder();
            // 1、科目范围 1001-1002
            if (accountSubject.contains(StrTools.PERIODSPLIT)) {
                String[] accountScope = accountSubject.split(StrTools.PERIODSPLIT);
                AccountGLSimpleVO[] accvos = AccountUtilGL.querySimpleAccountVOs(new String[] { pk_accountingbook },
                        accountScope[0], accountScope[1], "1", "1", true, false,
                        AccountRepUtil.getPowerCond(), bizDate.toString());
                if (accvos != null && accvos.length > 0) {
                    for (AccountGLSimpleVO accvo : accvos) {
                        pk_accasoa.append(accvo.getPk_accasoa()).append(commaEn);
                    }
                } else {
                    throw new BusinessException(
                            NCLangRes4VoTransl.getNCLangRes().getStrByID("20021101", "UPP20021101-000264")/* @res "科目编码" */
                                    + NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000230")/* @res "查询范围"*/
                                    + accountSubject
                                    + NCLangRes4VoTransl.getNCLangRes().getStrByID("20021201","UPP20021201-000322")/*@res "没有符合条件的数据！"*/);
                }
                // 2、指定一个或多个科目编码，分隔符是中英文的逗号：1001 1001,1002,1003
            } else {
                accountSubject = accountSubject.replaceAll(" ", "");
                String[] accountCodes = accountSubject.contains(commaCh) ? accountSubject.split(commaCh)
                        : accountSubject.split(commaEn);
                Map<String, String> accountCodesMap = new Hashtable<String, String>(accountCodes.length);// 错误的科目编码
                for (String code : accountCodes) {
                    accountCodesMap.put(code, "");
                }
                AccountVO[] accvos = AccountByPkThreadCache.getInstance().getAccountVOByCodes(pk_accountingbook,
                        accountCodes, bizDate.toString());
                if (accvos != null && accvos.length > 0) {
                    for (AccountVO accvo : accvos) {
                        if (accvo != null) {
                            pk_accasoa.append(accvo.getPk_accasoa()).append(commaEn);
                            accountCodesMap.remove(accvo.getCode());
                        }
                    }
                }
                if (!accountCodesMap.isEmpty()) {
                    StringBuilder errAccCode = new StringBuilder();
                    for (String code : accountCodesMap.keySet()) {
                        errAccCode.append(code).append(commaEn);
                    }
                    errAccCode.deleteCharAt(errAccCode.length() - 1);
                    throw new BusinessException(
                            NCLangRes4VoTransl.getNCLangRes().getStrByID("20021101", "UPP20021101-000264")/* @res "科目编码" */
                                    + errAccCode.toString()
                                    + NCLangRes4VoTransl.getNCLangRes().getStrByID("20021505", "UPP20021505-000146")/* @res "不存在" */);
                }
            }
            if (pk_accasoa.length() > 0) {
                pk_accasoa.deleteCharAt(pk_accasoa.length() - 1);
            }
            accountQryObj.put("pk_checkvalue", pk_accasoa.toString());
        }
        accountQryObj.put("headEle", false);
        accountQryObj.put("accEle", false);
        accountQryObj.put("includeSub", false);
        qryObjs.add(accountQryObj);
        // 查询对象：辅助项
        if (itemname != null && itemname.length > 0) {
            IGeneralAccessor accessor = GeneralAccessorFactory.getAccessor(IBDMetaDataIDConst.ACCASSITEM);
            String groupId = InvocationInfoProxy.getInstance().getGroupId();
            StringBuilder errChecktype = new StringBuilder();// 错误的辅助项名称
            for (String checktypename : itemname) {
                checktypename = checktypename.trim();
                if (StrTools.isEmptyStr(checktypename)) {
                    continue;
                }
                IBDData bdData = accessor.getDocByNameWithMainLang(groupId, checktypename);
                if (bdData == null) {
                    errChecktype.append(checktypename).append(commaEn);
                }
                // 如果存在错误数据，最终会抛错，就不必构造对象了
                if (errChecktype.length() == 0) {
                    Map<String, Object> qryObj = new HashMap<String, Object>(6);
                    qryObj.put("name", bdData.getName().toString());
                    qryObj.put("pk_checktype", bdData.getPk());
                    qryObj.put("pk_checkvalue", "");
                    qryObj.put("headEle", false);
                    qryObj.put("accEle", false);
                    qryObj.put("includeSub", false);
                    qryObjs.add(qryObj);
                }
            }
            if (errChecktype.length() > 0) {
                errChecktype.deleteCharAt(errChecktype.length() - 1);
                throw new BusinessException(
                        NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000058")/* @res*"辅助核算"*/
                                + errChecktype.toString()
                                + NCLangRes4VoTransl.getNCLangRes().getStrByID("20021505", "UPP20021505-000146")/* @res "不存在" */);
            }
        }
        params.put("qryObjs", qryObjs);
    }

    /**
     * 解析json参数，构造GlQueryVO<br>
     * nc.ui.gl.assbalance.QueryDialogPanel.getqryVO()
     * @param params
     * @return
     * @throws BusinessException
     */
    public GlQueryVO getQueryVO(Map<String, Object> params) throws BusinessException {
        // 小友机器人智能查账
        if (params.containsKey("companyName")) {
            fillParamMap(params);
        }

        GlQueryVO qryVO = new GlQueryVO();
        String[] pk_glorgbooks = JsonUtils.getStrArray(params.get("pk_glorgbooks"));
        if (pk_glorgbooks == null || pk_glorgbooks.length == 0) {
            throw new BusinessException(
                    NCLangRes4VoTransl.getNCLangRes().getStrByID("gl20111017public_v1_0", "02002001-0019")/* @res "请先选择核算账簿!!" */);
        }
        String pk_accountingbook = pk_glorgbooks[0];
        String newBase = BaseCorpChooser.getPk_BasCorp(pk_glorgbooks, pk_accountingbook);
        qryVO.setBaseAccountingbook(newBase);
        if (pk_glorgbooks == null || pk_glorgbooks.length == 0) {
            pk_glorgbooks = new String[] { pk_accountingbook };
        }
        qryVO.setpk_accountingbook(pk_glorgbooks);
        GlQryFormatVO qryFormatVo = qryVO.getFormatVO();

        qryVO.setQueryByPeriod(JsonUtils.getBoolean(params.get("selectionState")));

        if(params.get("isprint")!=null&&(boolean)params.get("isprint")) {
            qryVO.setPrint(Boolean.TRUE);
        }
        if(qryVO.isQueryByPeriod()) {
            qryVO.setYear(JsonUtils.getStrNULL(params.get("beginyear")));
            qryVO.setPeriod(JsonUtils.getStrNULL(params.get("beginperiod")));
            qryVO.setEndYear(JsonUtils.getStrNULL(params.get("endyear")));
            qryVO.setEndPeriod(JsonUtils.getStrNULL(params.get("endperiod")));
            if (!StrTools.isEmptyStr(qryVO.getYear()) && !StrTools.isEmptyStr(qryVO.getEndYear())
                    && !StrTools.isEmptyStr(qryVO.getPeriod()) && !StrTools.isEmptyStr(qryVO.getEndPeriod())) {
                AccountCalendar calendar = CalendarUtilGL.getAccountCalendarByAccountBook(qryVO.getBaseAccountingbook());
                calendar.set(qryVO.getYear(), qryVO.getPeriod());
                qryVO.setDate(calendar.getMonthVO().getBegindate());
                calendar.set(qryVO.getEndYear(), qryVO.getEndPeriod().substring(0, 2));
                qryVO.setEndDate(calendar.getMonthVO().getEnddate().asEnd());
            }
        } else {
            if (StrTools.isEmptyStr(JsonUtils.getStrNULL(params.get("begindate"))) || StrTools.isEmptyStr(JsonUtils.getStrNULL(params.get("enddate"))) ) {
                throw new BusinessException(
                        NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000521")/* @res "日期不支持选空，请重新选择！" */);
            }
//			if (qryvo.getDate().after(qryvo.getEndDate())) {
//				throw new BusinessException(
//						NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-001161")/* @res "查询开始期间不能大于结束期间，请重新选择！" */);
//			}
            UFDate startDate = AccountRepUtil.getStdStartDate(JsonUtils.getStrNULL(params.get("begindate")));
            UFDate endDate = AccountRepUtil.getStdEndDate(JsonUtils.getStrNULL(params.get("enddate")));
            AccountCalendar calendar = CalendarUtilGL.getAccountCalendarByAccountBook(newBase);
            String[] startPeiod = AccountBookUtil.getStartPeriod(newBase);
            try {
                calendar.set(startPeiod[0],startPeiod[1]);
            } catch (InvalidAccperiodExcetion e) {
                Logger.error(e.getMessage(), e);
            }
            UFDate accountBookstartDate = calendar.getMonthVO().getBegindate();
            UFDate accountBookEndDate = calendar.getMonthVO().getEnddate();
            if (startDate.before(accountBookstartDate)) {
                qryVO.setDate(accountBookstartDate);
            } else {
                qryVO.setDate(startDate);
            }
//			if(endDate.after(accountBookEndDate)) {
//				qryVO.setEndDate(accountBookEndDate);
//			} else {
            qryVO.setEndDate(endDate);
//			}
            if (qryVO.getDate() != null && qryVO.getEndDate() != null) {
                calendar.setDate(qryVO.getDate());
                qryVO.setYear(calendar.getYearVO().getPeriodyear());
                qryVO.setPeriod(calendar.getMonthVO().getAccperiodmth());

                calendar.setDate(qryVO.getEndDate());
                qryVO.setEndYear(calendar.getYearVO().getPeriodyear());
                qryVO.setEndPeriod(calendar.getMonthVO().getAccperiodmth());
            }
        }

        qryVO.setUserData(new String[] { qryVO.getYear(), qryVO.getPeriod() });

        qryVO.setIncludeUnTallyed(JsonUtils.getBoolean(params.get("includeUnTallyed")));
        qryVO.setIncludeError(JsonUtils.getBoolean(params.get("includeError")));
        qryVO.setIncludeTransfer(JsonUtils.getBoolean(params.get("includeTransfer")));
        qryVO.setIncludeReClassify(JsonUtils.getBoolean(params.get("includeReClassify")));

        qryVO.setCurrTypeName(JsonUtils.getStrNULL(params.get("currTypeName")));
        qryVO.setM_Return_CurrType(JsonUtils.getInteger(params.get("return_currtype")));
        qryVO.setLocalFrac(false);
        // ----------------------------------
        if (qryVO.getCurrTypeName().equals(CurrTypeConst.AUX_CURRTYPE())
                || qryVO.getCurrTypeName().equals(CurrTypeConst.QUERY_LOC_CURRTYPE())
                || qryVO.getCurrTypeName().equals(CurrTypeConst.ALL_CURRTYPE())) {
            qryVO.setPk_currtype(null);
            if (qryVO.getCurrTypeName().equals(CurrTypeConst.AUX_CURRTYPE())) {
                qryVO.setLocalFrac(true);
            }
        } else {
            qryVO.setPk_currtype(JsonUtils.getStrNULL(params.get("pk_currtype")));
        }
        if (qryVO.getCurrTypeName().equals(CurrTypeConst.ALL_CURRTYPE())) {
            qryVO.setLocalFrac(isLocalFrac(pk_accountingbook));
        }
        qryFormatVo.setMultiCorpCombine(JsonUtils.getBoolean(params.get("rbCorpJun")));

        qryFormatVo.setBalanceOrient(JsonUtils.getInteger(params.get("balanceDirection")));
        if(params.get("balanceRangeFrom")!=null){
            qryFormatVo.setBalanceRangeFrom(new UFDouble(params.get("balanceRangeFrom").toString()));
        }
        if(params.get("balanceRangeTo")!=null){
            qryFormatVo.setBalanceRangeTo(new UFDouble(params.get("balanceRangeTo").toString()));
        }
        // 0表示显示在查询对象之后,1为前
        qryFormatVo
                .setCorpDispLocation(JsonUtils.getBoolean(params.get("qryObjPlusCorp")) ? 0
                        : 1);
        qryFormatVo.setIsSubjSelectAll(true);
        qryFormatVo.setSortType(0);
        qryFormatVo.setIsCorpSubjDspBase(!JsonUtils.getBoolean(params.get("cbCorpSubjDspBase")));
        qryFormatVo.setIsQryByCorpAss(JsonUtils.getBoolean(params.get("cbQryByCorpAss")));
        // v31添加
        qryFormatVo.setShowDayAcc(false);
        qryFormatVo.setShowYearAcc(false);
        qryFormatVo.setCombineVoucher(false);
        qryFormatVo.setTwoWayBalance(JsonUtils.getBoolean(params.get("twowaybalance")));//借贷方显示余额
        qryFormatVo.setShowHasBalanceButZeroOccur(!JsonUtils.getBoolean(params.get("ckShowZeroAmount")));
//		qryFormatVo.setShowZeroBalance(false);
//		if (JsonUtils.getBoolean(params.get("ckShowZeroAmount"))) {
//			qryFormatVo.setShowZeroAmountRec(false);
//		} else {
//			qryFormatVo.setShowZeroAmountRec(!JsonUtils.getBoolean(params.get("ckNotShowZeroOccurZeroBalance")));
//		}
        //增加无余额不显示，且三选一
        qryFormatVo.setShowHasBalanceButZeroOccur(!UFBoolean.valueOf(params.get("ckShowZeroAmount").toString()).booleanValue());//无发生不显示
        qryFormatVo.setShowZeroAmountRec(!UFBoolean.valueOf(params.get("ckNotShowZeroOccurZeroBalance").toString()).booleanValue());  //无余额无发生不显示
        if(params.get("ckShowZeroBalance")!=null) {
            qryFormatVo.setShowZeroBalance(!UFBoolean.valueOf(params.get("ckShowZeroBalance").toString()).booleanValue());  //无余额不显示
        }

        // end v31添加
        qryVO.setFormatVO(qryFormatVo);
        // add by zhaoshya,参照得到的pk是vid,需要转换下
        Object[] pk_orgs = JsonUtils.getStrArray(params.get("pk_orgs"));
        String[] pk_units = null;
        if (pk_glorgbooks.length == 1) {
            if (pk_orgs != null && pk_orgs.length > 0) {
                pk_units = new String[pk_orgs.length];
                for (int i = 0; i < pk_orgs.length; i++) {
                    pk_units[i] = pk_orgs[i].toString();
                }
            } else {
                pk_units = AccountRepUtil.getPowerUnits(pk_glorgbooks[0]);
            }
        }
        // 处理利润中心zlp
        String[] pk_liabilitycenteros = params.get("pk_liabilitycenter")==null||params.get("pk_liabilitycenter").equals("")?null:((List<String>)params.get("pk_liabilitycenter")).toArray(new String[0]);
        String[] pk_liabilitycenters = null;
        if (pk_glorgbooks.length == 1) {
            if (pk_liabilitycenteros != null && pk_liabilitycenteros.length > 0) {
                pk_liabilitycenters = new String[pk_liabilitycenteros.length];
                for (int i = 0; i < pk_liabilitycenteros.length; i++) {
                    pk_liabilitycenters[i] = pk_liabilitycenteros[i].toString();
                }
            }else {
                // 查询有权限的利润中心
//				pk_liabilitycenters=AccountRepUtil.getPowerProfitCenters(new String[] {pk_accountingbook});
            }
        }
        qryVO.setPk_liabilitycenters(pk_liabilitycenters);//利润中心

        qryVO.setPk_unis(pk_units);
        //是否合并利润中心
        qryVO.setMultiLiabcenter(params.get("multliabcenter")==null?false:UFBoolean.valueOf(params.get("multliabcenter").toString()).booleanValue());
        qryVO.setMultiBusi(JsonUtils.getBoolean(params.get("multiBusi")));
        qryVO.setMultiYearMerge(JsonUtils.getBoolean(params.get("multiYearMerge")));
        UFDate busiDate = new UFDate(InvocationInfoProxy.getInstance().getBizDateTime());
        qryVO.setPk_user(InvocationInfoProxy.getInstance().getUserId());
        qryVO.setDefaultAdjust(false);
        qryVO.setDisLocalCurySum(false);
        qryVO.setUseSubjVersion(JsonUtils.getBoolean(params.get("useSubjVersion")));
        if (qryVO.isUseSubjVersion()) {
            qryVO.setSubjVersion(JsonUtils.getStrNULL(params.get("subjVersion")));
        } else {
            qryVO.setSubjVersionYear("" + busiDate.getYear());
            qryVO.setSubjVerisonPeriod(busiDate.getStrMonth());
            qryVO.setSubjVersion(busiDate.toStdString());
        }
        setQryObjs(qryVO, params.get("qryObjs"));
        qryVO.setShowBusinessDate(false);
        qryVO.setPk_fccurrtype(params.get("pk_fccurrtype") != null ? params.get("pk_fccurrtype").toString() : null );//	转换币种
        qryVO.setFcrate(params.get("fcrate") != null ? params.get("fcrate").toString() : null );//汇率
        // 查询对象检验
        // if (!checkQryObjs(qryFormatVo)){
        // return null;}
//			if (JsonUtils.getInteger(params.get("iUsedByBookStyle")) == JsonUtils.getInteger(params.get("iAssBalanceUse"))
//					&& getChartSettingPanel().isShowChart()) {
//				// --add by congjl 2010-09-21 设置图形化参数
//				GlChartConditionVO chartVO = new GlChartConditionVO();
//				IChartModel chartType = (IChartModel) getChartSettingPanel()
//						.getCmbType().getSelectedUserData();
//				int contentKey = Integer.parseInt(getChartSettingPanel()
//						.getCmbContent().getSelectedUserData().toString());
//				String idxX = getChartSettingPanel().getCmbX()
//						.getSelectedItem().toString();// x轴
//				String idxZ = getChartSettingPanel().getCmbLegend()
//						.getSelectedItem().toString();// 图例项
//				chartVO.setContentKey(contentKey);
//				chartVO.setIdxX(idxX);
//				chartVO.setIdxZ(idxZ);
//				chartVO.setChartType(chartType);
//				chartVO.setShowChart(getChartSettingPanel().isShowChart());
//
//				// 设置图形化界面条件
//				chartVO.setCmbTypeModel(getChartSettingPanel().getCmbType()
//						.getModel());
//				chartVO.setCmbXModel(getChartSettingPanel().getCmbX()
//						.getModel());
//				chartVO.setCmbYModel(getChartSettingPanel().getCmbY()
//						.getModel());
//				chartVO.setCmbContentModel(getChartSettingPanel()
//						.getCmbContent().getModel());
//				chartVO.setCmbLegendModel(getChartSettingPanel().getCmbLegend()
//						.getModel());
//				qryVO.setGlChartConditionVO(chartVO);
//				// --add end
//			}
        return qryVO;
    }

    /**
     * 确定BD302是否主辅币核算,如果是返回true,否则返回false
     * @param strPk_orgbook
     * @return
     */
    private Boolean isLocalFrac(String strPk_orgbook) {
        try {
            // BD302 是否主辅币核算 是true,否则false
            UFBoolean blnTemp;
            if (strPk_orgbook.equals("0001")){
                blnTemp = UFBoolean.valueOf(SysinitAccessor.getInstance().getParaString( strPk_orgbook, "BD212").toString());}
            else {
                if (AccountBookUtil.getSetOfBookVOByPk_accountingBook(strPk_orgbook).getPk_standardcurr() == null) {
                    return new Boolean(true);
                } else {
                    return new Boolean(false);
                }
            }
            return new Boolean(blnTemp.booleanValue());
        } catch (Exception e) {
            Logger.error(e.getMessage(),e);
        }
        return Boolean.FALSE;
    }

    /**
     * 设置GLQueryObj[]
     *
     * @param qryVO
     * @param json
     * @return
     * @throws BusinessException
     */
    @SuppressWarnings("unchecked")
    private void setQryObjs(GlQueryVO qryVO, Object json) throws BusinessException{
        if (json == null) {
            return;
        }
        Set<String> checktypeList = new HashSet<String>();
        List<GLQueryObj> glQueryObjs = new ArrayList<GLQueryObj>();
        List<Object> list = (List<Object>) json;
        for (int i = 0; i < list.size(); i++) {
            Map<String, Object> qryObjMap = (Map<String, Object>) (list.get(i));
            if (!StrTools.isEmptyStr(JsonUtils.getStrNULL(qryObjMap.get("name")))
                    && !NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000031")/** @res * "会计科目" */
                    .equals(JsonUtils.getStrNULL(qryObjMap.get("name")))) {
                checktypeList.add(JsonUtils.getStrNULL(qryObjMap.get("pk_checktype")));
            }
        }
        for (int i = 0; i < list.size(); i++) {
            Map<String, Object> qryObjMap = (Map<String, Object>) (list.get(i));
            if (StrTools.isEmptyStr(JsonUtils.getStrNULL(qryObjMap.get("name")))) {
                continue;
            }
            GLQueryObj glQueryObj = new GLQueryObj();
            glQueryObj.setAccEle(JsonUtils.getBoolean(qryObjMap.get("accEle")));
            glQueryObj.setAttrsValues(null);// 辅助属性余额表才用到
            glQueryObj.setHeadEle(JsonUtils.getBoolean(qryObjMap.get("headEle")));
            glQueryObj.setIncludeSub(JsonUtils.getBoolean(qryObjMap.get("includeSub")));
            glQueryObj.setLinkObj(null);
            glQueryObj.setDirty(false);
            glQueryObj.setType(JsonUtils.getStrNULL(qryObjMap.get("name")));
            glQueryObj.setTypeName(JsonUtils.getStrNULL(qryObjMap.get("name")));

            String pk_checkvalues = JsonUtils.getStrNULL(qryObjMap.get("pk_checkvalue"));
            if(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000031")/** @res * "会计科目"*/
                    .equals(JsonUtils.getStrNULL(qryObjMap.get("name")))){
                if (pk_checkvalues != null && pk_checkvalues.length() > 0) {
                    AccountVO[] accvos = AccountUtilGL.queryAccountVosByPks(pk_checkvalues.split(","), qryVO.getSubjVersion(), false);
                    if (accvos != null && accvos.length > 0) {
                        // 按code上下级排序
                        Arrays.sort(accvos, new Comparator<AccountVO>() {
                            @Override
                            public int compare(AccountVO o1, AccountVO o2) {
                                return o1.getCode().compareTo(o2.getCode());
                            }
                        });
                        AssVO[] accounts = new AssVO[accvos.length];
                        for (int j = 0; j < accvos.length; j++) {
                            accounts[j] = new AssVO();
                            accounts[j].setCheckvaluecode(accvos[j].getCode());
                            accounts[j].setCheckvaluename(accvos[j].getName());
                            accounts[j].setPk_Checkvalue(accvos[j].getPk_accasoa());
                        }
                        glQueryObj.setValueRange(accounts);
                    }
                } else {
                    AccountGLSimpleVO[] accvos = AccountUtilGL.queryAccByAss(
                            checktypeList.toArray(new String[0]),
                            qryVO.getBaseAccountingbook(),
                            qryVO.getSubjVersion());
                    if (accvos != null && accvos.length > 0) {
                        // 按code上下级排序
                        Arrays.sort(accvos, new Comparator<AccountGLSimpleVO>() {
                            @Override
                            public int compare(AccountGLSimpleVO o1, AccountGLSimpleVO o2) {
                                return o1.getCode().compareTo(o2.getCode());
                            }
                        });
                        AssVO[] accounts = new AssVO[accvos.length];
                        for (int j = 0; j < accvos.length; j++) {
                            accounts[j] = new AssVO();
                            accounts[j].setCheckvaluecode(accvos[j].getCode());
                            accounts[j].setCheckvaluename(accvos[j].getName());
                            accounts[j].setPk_Checkvalue(accvos[j].getPk_accasoa());
                        }
                        glQueryObj.setValueRange(accounts);
                    }
                }
                if (glQueryObj.getValueRange() == null) {
                    throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000198")/*@res "没有对应的科目！"*/);
                }
            } else {
                String pk_checktype = JsonUtils.getStrNULL(qryObjMap.get("pk_checktype"));
                AccAssItemVO accassItemVO = AccAssGL.getAccAssItemVOByPk(pk_checktype);
                if (accassItemVO == null) {
                    Logger.error("assbalance: invalid pk_checktype:" + pk_checktype);
                    continue;
                }
                String checktypename = GLMultiLangUtil.getMultiName(accassItemVO);
                String checktypecode = accassItemVO.getCode();
                String classid = AccAssGL.getClassidByCheckTypePk(pk_checktype);
                if (!StrTools.isEmptyStr(pk_checkvalues)) {
                    String[] arrCheckvalues= pk_checkvalues.split(",");
                    AssVO[] assvos = new AssVO[arrCheckvalues.length];
                    for (int j = 0; j < assvos.length; j++) {
                        assvos[j] = new AssVO();
                        assvos[j].setPk_Checktype(pk_checktype);
                        assvos[j].setChecktypename(checktypename);
                        assvos[j].setChecktypecode(checktypecode);
                        assvos[j].setM_classid(classid);
                    }
                    // 自定义档案类型
                    if (FreeValueDefUtil.getInstance().isDefDoc(classid)) {
                        for (int j = 0; j < assvos.length; j++) {
                            assvos[j].setPk_Checkvalue(arrCheckvalues[j]);
                            assvos[j].setCheckvaluecode(arrCheckvalues[j]);
                            assvos[j].setCheckvaluename(arrCheckvalues[j]);
                        }
                    } else {
                        IGeneralAccessor accessor = new AssAccessorManager().getDBAccess(classid);
                        IBDData[] datas = accessor.getDocbyPks(arrCheckvalues);
                        Map<String, IBDData> map = new HashMap<String, IBDData>();
                        for (IBDData data : datas) {
                            map.put(data.getPk(), data);
                        }
                        for (int j = 0; j < assvos.length; j++) {
                            assvos[j].setPk_Checkvalue(arrCheckvalues[j]);
                            assvos[j].setCheckvaluecode(map.get(arrCheckvalues[j]).getCode());
                            assvos[j].setCheckvaluename(map.get(arrCheckvalues[j]).getName().getText());
                        }
                    }
                    glQueryObj.setValueRange(assvos);
                } else {
                    AssVO[] assvos = new AssVO[1];
                    assvos[0] = new AssVO();
                    assvos[0].setPk_Checktype(pk_checktype);
                    assvos[0].setCheckvaluename("ALL");
                    assvos[0].setChecktypename(checktypename);
                    assvos[0].setChecktypecode(checktypecode);
                    glQueryObj.setValueRange(assvos);
                }
            }
            glQueryObjs.add(glQueryObj);
        }
        qryVO.getFormatVO().setQryObjs(glQueryObjs.toArray(new GLQueryObj[glQueryObjs.size()]));
    }

    /**
     * 获取返回信息json
     *
     * @param qryvo
     * @return
     * @throws Exception
     */
    private Map<String, Object> getRes(GlQueryVO qryvo) throws Exception {
        Map<String, Object> result = new HashMap<String, Object>();

        result.put("column", getColumn(qryvo));

        Map<String, String> headTitle = new HashMap<String, String>();
        headTitle.put("accbook"/* @res "核算账簿：" */, AccountRepUtil.getOrgNames(qryvo));
        headTitle.put("period"/* @res "期  间：" */,
                qryvo.isQueryByPeriod()
                        ? qryvo.getYear() + StrTools.PERIODSPLIT + qryvo.getPeriod() + StrTools.PERIODSCOPESPLIT + qryvo.getEndYear() + StrTools.PERIODSPLIT + qryvo.getEndPeriod()
                        : DataFormatUtilGL.formatDate(qryvo.getDate()).getValue() + StrTools.PERIODSCOPESPLIT + DataFormatUtilGL.formatDate(qryvo.getEndDate()).getValue());
        headTitle.put("currtype"/* @res "币  种：" */ , qryvo.getCurrTypeName());
        headTitle.put("loccurrtype"/* @res "本币类型" */, qryvo.getReturn_CurrtypeName());
        if(!StrTools.isEmptyStr(qryvo.getPk_fccurrtype())) {
            CurrtypeVO currtypeVO = CurrtypeGL.findByPrimaryKey(qryvo.getPk_fccurrtype().toString());
            if (currtypeVO != null) {
                headTitle.put("loccurrtype"/* @res "本币类型" */, GLMultiLangUtil.getMultiName(currtypeVO));

            }
        }
        result.put("headtitle", headTitle);
        return result;
    }

    /**
     * 表体数据json
     *
     * @param qryvo
     * @param subjAssembleVOs
     * @return
     * @throws Exception
     */
    public List<Map<String, Object>> getData(GlQueryVO qryvo, BalanceSubjAssBSVO[] vos) throws Exception {
        List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
        if (vos == null || vos.length == 0) {
            return data;
        }
        setPk_localcurr(AccountRepUtil.getLocalCurr(qryvo));
        // 是否多页
        boolean isMultiPages = GlQueryVOAssTool.isMultiPages(qryvo);
        // 处理业务单元名称
        processUnitName(qryvo, vos);
        // 处理利润中心名称
        adjustLiabilitycenterVersion(qryvo, vos);
        Map<String,String> assIndexMap= new HashMap<String,String>();
        GLQueryObj[] queryObjs = qryvo.getFormatVO().getQryObjs();
        for (int i = 0; i < queryObjs.length; i++) {
            GLQueryObj queryObj = queryObjs[i];
            AssVO[] assvos = queryObj.getValueRange();
            if (assvos != null && assvos.length > 0 && assvos[0] != null) {
                assIndexMap.put(assvos[0].getPk_Checktype(), i + "");
            }
        }
        boolean isExistsMaterial = isExistsMaterial(qryvo);
        Map<String, String> materialMeasdocMap = null;
        if (isExistsMaterial) {
            materialMeasdocMap = getMaterialMeasdoc(vos);
        }
        for (BalanceSubjAssBSVO vo : vos) {
            // 处理累计行、总计行的原币精度：如果查询指定币种，则取查询币种的精度；否则取返回币种的精度。start
            String pk_currtype = (String) vo.getValue(BalanceSubjAssBSKey.K_PK_CURRTYPE);
            String pk_currtype_amount =
                    (pk_currtype == null || pk_currtype.length() != 20
                            || "ZZZZZZZZZZZZZZZZZZZZ".equals(pk_currtype) || "99999999999999999999".equals(pk_currtype))
                            && qryvo.getPk_currtype() != null
                            && !CurrTypeConst.ALL_CURRTYPE().equals(qryvo.getPk_currtype())
                            && !CurrTypeConst.QUERY_LOC_CURRTYPE().equals(qryvo.getPk_currtype())
                            ? qryvo.getPk_currtype()
                            : pk_localcurr;
            // end
            Map<String, Object> row = new HashMap<String, Object>();
            row.put("pk_accountingbook", vo.getValue(BalanceSubjAssBSKey.K_PK_ACCOUNTINGBOOK));
            Object mark = vo.getValue(BalanceSubjAssBSKey.K_MARK);
            row.put("mark", mark);
            row.put("year", vo.getValue(BalanceSubjAssBSKey.K_YEAR)); // 会计年度
            String pk_accountingbook = (String)vo.getValue(BalanceSubjAssBSKey.K_PK_ACCOUNTINGBOOK);
            // nccloud.pubimpl.gl.assbalance.BlnSbjAssMdlSttl.addSumAllMark 设置了合计行的pk_accountingbook为9999，会导致多余的查询账簿sql。
            row.put("bookname", "9999".equals(pk_accountingbook) ? "" : AccountBookUtil.getAccountingBookNameByPk(pk_accountingbook));
            row.put("unitname", vo.getValue(BalanceSubjAssBSKey.K_USERDATA));
            row.put("liabilitycentername", vo.getValue(BalanceSubjAssBSKey.K_LIABILITYCENTERNAME));

            row.put("accsubjcode", vo.getValue(BalanceSubjAssBSKey.K_ACCSUBJCODE));
            row.put("accsubjname", vo.getValue(BalanceSubjAssBSKey.K_ACCSUBJNAME));

            row.put("measureunit", vo.getValue(BalanceSubjAssBSKey.K_UNIT));// 计量单位
            row.put("curtype", vo.getValue(BalanceSubjAssBSKey.K_CURTYPE)); // 币种名称

            row.put("initorients", vo.getValue(BalanceSubjAssBSKey.K_INITORIENTS)); // 期初方向
            //外币折算 zlp 20200515
            if(!StrTools.isEmptyStr(qryvo.getPk_fccurrtype()) &&  !StrTools.isEmptyStr(qryvo.getFcrate()) ){
                //原币不折算
                UFDouble fcrate = new UFDouble(qryvo.getFcrate());
//				row.put("initamount", format.getFormatAmountVlaue(multiplyCalculation(vo.getValue(BalanceSubjAssBSKey.K_INITAMOUNT),fcrate), vo, pk_currtype_amount)); // 期初余额(原币)
                row.put("initamount", format.getFormatAmountVlaue(vo.getValue(BalanceSubjAssBSKey.K_INITAMOUNT), vo, pk_currtype_amount)); // 期初余额(原币)
                row.put("initlocamount", format.getFormatLocalVlaue(multiplyCalculation(vo.getValue(BalanceSubjAssBSKey.K_INITLOCAMOUNT),fcrate), pk_localcurr)); // 期初余额(本币)
                row.put("initdebitamount", format.getFormatAmountVlaue(vo.getValue(BalanceSubjAssBSKey.K_INITDEBITAMOUNT), vo, pk_currtype_amount)); // 期初余额(原币)
                row.put("initdebitlocamount", format.getFormatLocalVlaue(multiplyCalculation(vo.getValue(BalanceSubjAssBSKey.K_INITDEBITLOCAMOUNT),fcrate), pk_localcurr)); // 期初余额(本币)
                row.put("initcreditamount", format.getFormatAmountVlaue(vo.getValue(BalanceSubjAssBSKey.K_INITCREDITAMOUNT), vo, pk_currtype_amount)); // 期初余额(原币)
                row.put("initcreditlocamount", format.getFormatLocalVlaue(multiplyCalculation(vo.getValue(BalanceSubjAssBSKey.K_INITCREDITLOCAMOUNT),fcrate), pk_localcurr)); // 期初余额(本币)

//				row.put("debitamount", format.getFormatAmountVlaue(multiplyCalculation(vo.getValue(BalanceSubjAssBSKey.K_DEBITAMOUNT),fcrate), vo, pk_currtype_amount));
                row.put("debitamount", format.getFormatAmountVlaue(vo.getValue(BalanceSubjAssBSKey.K_DEBITAMOUNT), vo, pk_currtype_amount));
                row.put("debitlocamount", format.getFormatLocalVlaue(multiplyCalculation(vo.getValue(BalanceSubjAssBSKey.K_DEBITLOCAMOUNT),fcrate), pk_localcurr));

//				row.put("creditamount", format.getFormatAmountVlaue(multiplyCalculation(vo.getValue(BalanceSubjAssBSKey.K_CREDITAMOUNT),fcrate), vo, pk_currtype_amount));
                row.put("creditamount", format.getFormatAmountVlaue(vo.getValue(BalanceSubjAssBSKey.K_CREDITAMOUNT), vo, pk_currtype_amount));
                row.put("creditlocamount", format.getFormatLocalVlaue(multiplyCalculation(vo.getValue(BalanceSubjAssBSKey.K_CREDITLOCAMOUNT),fcrate), pk_localcurr));

//				row.put("debitaccumamount", format.getFormatAmountVlaue(multiplyCalculation(vo.getValue(BalanceSubjAssBSKey.K_DEBITACCUMAMOUNT),fcrate), vo, pk_currtype_amount));
                row.put("debitaccumamount", format.getFormatAmountVlaue(vo.getValue(BalanceSubjAssBSKey.K_DEBITACCUMAMOUNT), vo, pk_currtype_amount));
                row.put("debitaccumlocamount", format.getFormatLocalVlaue(multiplyCalculation(vo.getValue(BalanceSubjAssBSKey.K_DEBITACCUMLOCAMOUNT),fcrate), pk_localcurr));

//				row.put("creditaccumamount", format.getFormatAmountVlaue(multiplyCalculation(vo.getValue(BalanceSubjAssBSKey.K_CREDITACCUMAMOUNT),fcrate), vo, pk_currtype_amount));
                row.put("creditaccumamount", format.getFormatAmountVlaue(vo.getValue(BalanceSubjAssBSKey.K_CREDITACCUMAMOUNT), vo, pk_currtype_amount));
                row.put("creditaccumlocamount", format.getFormatLocalVlaue(multiplyCalculation(vo.getValue(BalanceSubjAssBSKey.K_CREDITACCUMLOCAMOUNT),fcrate), pk_localcurr));

//				row.put("endamount", format.getFormatAmountVlaue(multiplyCalculation(vo.getValue(BalanceSubjAssBSKey.K_ENDAMOUNT),fcrate), vo, pk_currtype_amount)); // 期末余额(原币)
                row.put("endamount", format.getFormatAmountVlaue(vo.getValue(BalanceSubjAssBSKey.K_ENDAMOUNT), vo, pk_currtype_amount)); // 期末余额(原币)
                row.put("endlocamount", format.getFormatLocalVlaue(multiplyCalculation(vo.getValue(BalanceSubjAssBSKey.K_ENDLOCAMOUNT),fcrate), pk_localcurr)); // 期末余额(本币)
                row.put("enddebitamount", format.getFormatAmountVlaue(vo.getValue(BalanceSubjAssBSKey.K_ENDDEBITAMOUNT), vo, pk_currtype_amount)); // 期末余额(原币)
                row.put("enddebitlocamount", format.getFormatLocalVlaue(multiplyCalculation(vo.getValue(BalanceSubjAssBSKey.K_ENDDEBITLOCAMOUNT),fcrate), pk_localcurr)); // 期末余额(本币)
                row.put("endcreditamount", format.getFormatAmountVlaue(vo.getValue(BalanceSubjAssBSKey.K_ENDCREDITAMOUNT), vo, pk_currtype_amount)); // 期末余额(原币)
                row.put("endcreditlocamount", format.getFormatLocalVlaue(multiplyCalculation(vo.getValue(BalanceSubjAssBSKey.K_ENDCREDITLOCAMOUNT),fcrate), pk_localcurr)); // 期末余额(本币)

            }else {
                row.put("initamount", format.getFormatAmountVlaue(vo.getValue(BalanceSubjAssBSKey.K_INITAMOUNT), vo, pk_currtype_amount)); // 期初余额(原币)
                row.put("initlocamount", format.getFormatLocalVlaue(vo.getValue(BalanceSubjAssBSKey.K_INITLOCAMOUNT), pk_localcurr)); // 期初余额(本币)
                row.put("initdebitamount", format.getFormatAmountVlaue(vo.getValue(BalanceSubjAssBSKey.K_INITDEBITAMOUNT), vo, pk_currtype_amount)); // 期初余额(原币)
                row.put("initdebitlocamount", format.getFormatLocalVlaue(vo.getValue(BalanceSubjAssBSKey.K_INITDEBITLOCAMOUNT), pk_localcurr)); // 期初余额(本币)
                row.put("initcreditamount", format.getFormatAmountVlaue(vo.getValue(BalanceSubjAssBSKey.K_INITCREDITAMOUNT), vo, pk_currtype_amount)); // 期初余额(原币)
                row.put("initcreditlocamount", format.getFormatLocalVlaue(vo.getValue(BalanceSubjAssBSKey.K_INITCREDITLOCAMOUNT), pk_localcurr)); // 期初余额(本币)

                row.put("debitamount", format.getFormatAmountVlaue(vo.getValue(BalanceSubjAssBSKey.K_DEBITAMOUNT), vo, pk_currtype_amount));
                row.put("debitlocamount", format.getFormatLocalVlaue(vo.getValue(BalanceSubjAssBSKey.K_DEBITLOCAMOUNT), pk_localcurr));

                row.put("creditamount", format.getFormatAmountVlaue(vo.getValue(BalanceSubjAssBSKey.K_CREDITAMOUNT), vo, pk_currtype_amount));
                row.put("creditlocamount", format.getFormatLocalVlaue(vo.getValue(BalanceSubjAssBSKey.K_CREDITLOCAMOUNT), pk_localcurr));

                row.put("debitaccumamount", format.getFormatAmountVlaue(vo.getValue(BalanceSubjAssBSKey.K_DEBITACCUMAMOUNT), vo, pk_currtype_amount));
                row.put("debitaccumlocamount", format.getFormatLocalVlaue(vo.getValue(BalanceSubjAssBSKey.K_DEBITACCUMLOCAMOUNT), pk_localcurr));

                row.put("creditaccumamount", format.getFormatAmountVlaue(vo.getValue(BalanceSubjAssBSKey.K_CREDITACCUMAMOUNT), vo, pk_currtype_amount));
                row.put("creditaccumlocamount", format.getFormatLocalVlaue(vo.getValue(BalanceSubjAssBSKey.K_CREDITACCUMLOCAMOUNT), pk_localcurr));

                row.put("endamount", format.getFormatAmountVlaue(vo.getValue(BalanceSubjAssBSKey.K_ENDAMOUNT), vo, pk_currtype_amount)); // 期末余额(原币)
                row.put("endlocamount", format.getFormatLocalVlaue(vo.getValue(BalanceSubjAssBSKey.K_ENDLOCAMOUNT), pk_localcurr)); // 期末余额(本币)
                row.put("enddebitamount", format.getFormatAmountVlaue(vo.getValue(BalanceSubjAssBSKey.K_ENDDEBITAMOUNT), vo, pk_currtype_amount)); // 期末余额(原币)
                row.put("enddebitlocamount", format.getFormatLocalVlaue(vo.getValue(BalanceSubjAssBSKey.K_ENDDEBITLOCAMOUNT), pk_localcurr)); // 期末余额(本币)
                row.put("endcreditamount", format.getFormatAmountVlaue(vo.getValue(BalanceSubjAssBSKey.K_ENDCREDITAMOUNT), vo, pk_currtype_amount)); // 期末余额(原币)
                row.put("endcreditlocamount", format.getFormatLocalVlaue(vo.getValue(BalanceSubjAssBSKey.K_ENDCREDITLOCAMOUNT), pk_localcurr)); // 期末余额(本币)
            }

            row.put("endorients", vo.getValue(BalanceSubjAssBSKey.K_ENDORIENTS)); // 期末方向
            // 数量格式化
            if (isExistsMaterial) {
                String pk_measdoc ="";
                if(row.get("mark") == null ||
                        !nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("gl20111017public_v1_0","02002001-0012")/*@res "业务单元累计"*/.equals(row.get("mark").toString())){
                    String materialPK = getMaterialPK(vo);
                    pk_measdoc = materialMeasdocMap.get(materialPK);
                }
                row.put("initquant", format.getFormatQuanMaterial(vo.getValue(BalanceSubjAssBSKey.K_INITQUANT), pk_measdoc)); // 期初余额(数量)
                row.put("initdebitquant", format.getFormatQuanMaterial(vo.getValue(BalanceSubjAssBSKey.K_INITDEBITQUANT), pk_measdoc));
                row.put("initcreditquant", format.getFormatQuanMaterial(vo.getValue(BalanceSubjAssBSKey.K_INITCREDITQUANT), pk_measdoc));

                row.put("debitquant", format.getFormatQuanMaterial(vo.getValue(BalanceSubjAssBSKey.K_DEBITQUANT), pk_measdoc));
                row.put("creditquant", format.getFormatQuanMaterial(vo.getValue(BalanceSubjAssBSKey.K_CREDITQUANT), pk_measdoc));

                row.put("debitaccumquant", format.getFormatQuanMaterial(vo.getValue(BalanceSubjAssBSKey.K_DEBITACCUMQUANT), pk_measdoc));
                row.put("creditaccumquant", format.getFormatQuanMaterial(vo.getValue(BalanceSubjAssBSKey.K_CREDITACCUMQUANT), pk_measdoc));

                row.put("endquant", format.getFormatQuanMaterial(vo.getValue(BalanceSubjAssBSKey.K_ENDQUANT), pk_measdoc)); // 期末数量余额
                row.put("enddebitquant", format.getFormatQuanMaterial(vo.getValue(BalanceSubjAssBSKey.K_ENDDEBITQUANT), pk_measdoc));
                row.put("endcreditquant", format.getFormatQuanMaterial(vo.getValue(BalanceSubjAssBSKey.K_ENDCREDITQUANT), pk_measdoc));

            } else {
                row.put("initquant", format.getFormatQuan(vo.getValue(BalanceSubjAssBSKey.K_INITQUANT), vo, qryvo.getSubjVersion())); // 期初余额(数量)
                row.put("initdebitquant", format.getFormatQuan(vo.getValue(BalanceSubjAssBSKey.K_INITDEBITQUANT), vo, qryvo.getSubjVersion()));
                row.put("initcreditquant", format.getFormatQuan(vo.getValue(BalanceSubjAssBSKey.K_INITCREDITQUANT), vo, qryvo.getSubjVersion()));

                row.put("debitquant", format.getFormatQuan(vo.getValue(BalanceSubjAssBSKey.K_DEBITQUANT), vo, qryvo.getSubjVersion()));
                row.put("creditquant", format.getFormatQuan(vo.getValue(BalanceSubjAssBSKey.K_CREDITQUANT), vo, qryvo.getSubjVersion()));
                row.put("debitaccumquant", format.getFormatQuan(vo.getValue(BalanceSubjAssBSKey.K_DEBITACCUMQUANT), vo, qryvo.getSubjVersion()));
                row.put("creditaccumquant", format.getFormatQuan(vo.getValue(BalanceSubjAssBSKey.K_CREDITACCUMQUANT), vo, qryvo.getSubjVersion()));
                row.put("endquant", format.getFormatQuan(vo.getValue(BalanceSubjAssBSKey.K_ENDQUANT), vo, qryvo.getSubjVersion())); // 期末数量余额
                row.put("enddebitquant", format.getFormatQuan(vo.getValue(BalanceSubjAssBSKey.K_ENDDEBITQUANT), vo, qryvo.getSubjVersion()));
                row.put("endcreditquant", format.getFormatQuan(vo.getValue(BalanceSubjAssBSKey.K_ENDCREDITQUANT), vo, qryvo.getSubjVersion()));
            }
            // 辅助项的pk、编码和名称
            Object assvosObj = vo.getValue(BalanceSubjAssBSKey.K_ASSVOS);
            if (assvosObj != null && assvosObj.getClass().isArray()) {
                AssVO[] assvos = (AssVO[]) assvosObj;
                if(mark == null ||
                        !NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000115")/* @res "总计" */.equals(mark.toString())) {
                    for (int i = 0; i < assvos.length; i++) {
                        String showassname ="";
                        AssVO assvo = assvos[i];
                        //拆分名称
                        String[] split = assvo.getCheckvaluename().split(",");
                        if(split.length > 1){
                            assvo.setCheckvaluename(split[1]);
                        }
                        String index = assIndexMap.get(assvo.getPk_Checktype());
                        row.put("checktypecode" + index, assvo.getChecktypecode());
                        row.put("checktypename" + index, assvo.getChecktypename());
                        row.put("checkvaluecode" + index, assvo.getCheckvaluecode());
                        row.put("checkvaluename" + index, assvo.getCheckvaluename());
                        row.put("classid" + index, assvo.getM_classid());
                        row.put("pk_checktype" + index, assvo.getPk_Checktype());
                        row.put("pk_checkvalue" + index, assvo.getPk_Checkvalue());
                        if(qryvo.getFormatVO().isMultiCorpCombine()){
                            String accountingbook = !StrTools.isEmptyStr(vo.getPk_glorgbook()) ? vo.getPk_glorgbook():vo.getPk_glorgbook();
                            showassname = ShowContentCenter.getShowAss(accountingbook, new AssVO[] { assvo });
                        }else{
                            showassname = ShowContentCenter.getShowAss(vo.getPk_glorgbook(), new AssVO[] { assvo });
                        }
                        //辅助余额表辅助项去掉【】
                        if(showassname.indexOf("【")==0 && showassname.indexOf("】")==showassname.length()-1) {
                            showassname = showassname.substring(1,showassname.length()- 1);
                        }
//                        row.put("showname" + index, showassname);
                        row.put("showname" + index, assvo.getCheckvaluename());
//						row.put("showname" + index, assvo.getCheckvaluename());
                    }
                }
            }
            data.add(row);
            // nc.ui.gl.assbalance.BalanceSubjAssView.goForDetail() 设置联查信息
            if (mark != null) {
                if (mark.equals(NCLangRes4VoTransl.getNCLangRes().getStrByID("gl20111017public_v1_0", "02002001-0012")/* @res "业务单元累计" */)) {
                    row.put("linkmsg", NCLangRes4VoTransl.getNCLangRes().getStrByID("gl20111017public_v1_0", "02002001-0013")/*@res "业务单元累计不支持联查"*/);
                    continue;
                }
                if (qryvo.getpk_accountingbook().length >= 2 && !mark.equals(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000115")/*@res "总计"*/)) {
                    row.put("linkmsg", NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030", "UPP20023030-000169")/*@res "多单位小计、合计行不支持联查明细！"*/);
                    continue;
                }
                if (mark.equals(NCLangRes4VoTransl.getNCLangRes().getStrByID("gl20111017public_v1_0", "02002001-0014")/* @res "币种累计" */)) {
                    continue;
                }
                if(!isMultiPages && mark.toString().indexOf(nc.vo.ml.NCLangRes4VoTransl.getNCLangRes().getStrByID("gl20111017public_v1_0","02002001-0015")/*@res "小计"*/) >= 0) {
                    continue;
                }
            }
            Map<String, Object> link = new HashMap<>();
            if (assvosObj != null && assvosObj.getClass().isArray()) {
                AssVO[] assvos = (AssVO[]) assvosObj;
                List<Map<String, String>> list = new ArrayList<Map<String, String>>(assvos.length);
                for (AssVO assvo : assvos) {
                    Map<String, String> map = new HashMap<String, String>();
                    map.put("pk_checktype", assvo.getPk_Checktype());
                    map.put("pk_checkvalue", assvo.getPk_Checkvalue());
                    list.add(map);
                }
                link.put("ass", list);
            }
            link.put("mark", mark);
            link.put("pk_unit", vo.getValue(BalanceSubjAssBSKey.K_PK_UNIT));
            link.put("pk_liabilitycenter", vo.getValue(BalanceSubjAssBSKey.K_LIABILITYCENTER));
            link.put("year", vo.getValue(BalanceSubjAssBSKey.K_YEAR));
            link.put("accsubjcode", vo.getValue(BalanceSubjAssBSKey.K_ACCSUBJCODE));
            link.put("pk_accasoa", vo.getValue(BalanceSubjAssBSKey.K_PK_ACCASOA));
            link.put("pk_currtype", vo.getValue(BalanceSubjAssBSKey.K_PK_CURRTYPE));
            link.put("pk_accountingbook", vo.getValue(BalanceSubjAssBSKey.K_PK_ACCOUNTINGBOOK));
            row.put("link", link);
        }
        return data;
    }


    /**
     *   两数计算   金额乘以汇率
     * @param value  金额
     * @param fcrate 汇率
     * @return
     */
    private UFDouble multiplyCalculation(Object value,UFDouble fcrate) {
        if(null==value || null==fcrate) {
            return null;
        }

        UFDouble amount = new UFDouble(value.toString());
        amount=amount.multiply(fcrate);
        return amount;
    }

    /**
     * 处理业务单元名称
     * <br>将业务单元名称存到userdata字段
     * @param qryvo
     * @param balanceSubjAssVOs
     * @throws Exception
     */
    @SuppressWarnings("unchecked")
    private void processUnitName(GlQueryVO qryvo, BalanceSubjAssBSVO[] balanceSubjAssVOs) throws Exception {
        BalanceSubjAssBSVO[] vos = balanceSubjAssVOs;
        GlQueryVO qryVO = qryvo;
        if (vos == null || vos.length == 0 || qryVO == null || qryVO.getpk_accountingbook().length > 1){
            return;}
        try {
            if (!GLParaAccessor.isSecondBUStart(qryVO.getBaseAccountingbook()).booleanValue()){
                return;}
        } catch (BusinessException e) {
            Logger.error(e.getMessage(), e);
        }
        HashSet<String> pk_units = new HashSet<String>();
        try {
            for (int i = 0; i < vos.length; i++) {
                if (null != vos[i].getValue(BalanceSubjAssBSKey.K_PK_UNIT)) {
                    String pk_unit = vos[i].getValue(BalanceSubjAssBSKey.K_PK_UNIT).toString();
                    pk_units.add(pk_unit);
                }
            }
        } catch (Exception e) {
            Logger.error(e.getMessage(), e);
        }

        IAccountingbookService service = (IAccountingbookService)NCLocator.getInstance().lookup(IAccountingbookService.class.getName());
        HashMap<String, Object> obj = new HashMap<String, Object>();
        obj.put(IAccountingbookService.PK_UNIT, pk_units);
        String date = qryVO.getSubjVersion().equals("0000-00-00") ? "0001-01-01" : qryVO.getSubjVersion();
        obj.put(IAccountingbookService.DATE, qryVO.getDate() == null ? new UFDate(date) : qryVO.getDate());
        HashMap<String,Object> returnObj = service.getObjectOnce(obj);
        for (int i = 0; i < vos.length; i++) {
            vos[i].setValue(BalanceSubjAssBSKey.K_USERDATA, null);
        }
        if(returnObj.containsKey(IAccountingbookService.PK_UNIT_V)){
            HashMap<String,String> versionMap = (HashMap<String, String>) returnObj.get(IAccountingbookService.PK_UNIT_V);
            HashMap<String,String> unit_name = (HashMap<String, String>) returnObj.get(IAccountingbookService.UNIT_NAME);
            for (int i = 0; i < vos.length; i++) {
                if(null != vos[i].getValue(BalanceSubjAssBSKey.K_PK_UNIT)){
                    String pk_unit = vos[i].getValue(BalanceSubjAssBSKey.K_PK_UNIT).toString();
                    vos[i].setValue(BalanceSubjAssBSKey.K_USERDATA, unit_name.get(versionMap.get(pk_unit)));
                }
            }
        }
    }

    /** 利润中心赋值
     * 把利润中心赋值给 liabilitycentername字段
     * @param qryvo
     * @param balanceSubjAssVOs
     */
    protected void adjustLiabilitycenterVersion(GlQueryVO qryvo, BalanceSubjAssBSVO[] balanceSubjAssVOs) {
        BalanceSubjAssBSVO[] vos = balanceSubjAssVOs;
        GlQueryVO qryVO = qryvo;
        if (vos == null || vos.length == 0 || qryVO == null || qryVO.getpk_accountingbook().length > 1){
            return;
        }
        try {
            if (!GLParaAccessor.isLbtCenterStart(qryVO.getBaseAccountingbook()).booleanValue()){
                return;
            }
        } catch (BusinessException e) {
            Logger.error(e.getMessage(), e);
        }
        try {
            HashSet<String> pk_profits = new HashSet<String>();
            for (int i = 0; i < vos.length; i++) {
                //把利润中心为空的 赋值为~ 用于联查辅助明细
                if(vos[i].getValue(BalanceSubjAssBSKey.K_LIABILITYCENTER)!=null&&vos[i].getValue(BalanceSubjAssBSKey.K_LIABILITYCENTER).equals(BalanceSubjAssBSKey.K_LIABILITYCENTERCODE_NULL_POSITION)) {
                    vos[i].setValue(BalanceSubjAssBSKey.K_LIABILITYCENTER,BalanceSubjAssBSKey.DATA_SOURCE_EMPTY);
                }else {
                    pk_profits.add((String) vos[i].getValue(BalanceSubjAssBSKey.K_LIABILITYCENTER));
                }
            }
            if(pk_profits.size()>0) {
                IProfitCenterPubService service = (IProfitCenterPubService)NCLocator.getInstance().lookup(IProfitCenterPubService.class.getName());
                String date = qryVO.getSubjVersion().equals("0000-00-00")?"0001-01-01":qryVO.getSubjVersion();
                Map<String, ProfitcenterVersionVO> profitVoMap = service.queryVersion(pk_profits.toArray(new String[] { }), qryVO.getEndDate()==null?new UFDate(date):qryVO.getEndDate());
                if(profitVoMap.size()>0) {
                    for (int i = 0; i < vos.length; i++) {
                        if(null != vos[i].getValue(BalanceSubjAssBSKey.K_LIABILITYCENTER)){
                            ProfitcenterVersionVO profitcenterVersionVO = profitVoMap.get(vos[i].getValue(BalanceSubjAssBSKey.K_LIABILITYCENTER));
                            if(profitcenterVersionVO!=null) {
                                String lbname=profitcenterVersionVO.getName();
                                String code=profitcenterVersionVO.getCode();
                                vos[i].setValue(BalanceSubjAssBSKey.K_LIABILITYCENTERCODE,code);
                                vos[i].setValue(BalanceSubjAssBSKey.K_LIABILITYCENTERNAME, lbname);
                            }
                        }
                    }
                }
            }

        } catch (Exception e) {
            Logger.error(e.getMessage(), e);
        }

    }

    /** 利润中心赋值
     * 把利润中心赋值给 liabilitycentername字段
     * @param qryvo
     * @param balanceSubjAssVOs
     */
    protected void adjustLiabilitycenter(GlQueryVO qryvo, BalanceSubjAssBSVO[] balanceSubjAssVOs) {
        BalanceSubjAssBSVO[] vos = balanceSubjAssVOs;
        GlQueryVO qryVO = qryvo;
        if (vos == null || vos.length == 0 || qryVO == null || qryVO.getpk_accountingbook().length > 1){
            return;}
        try {
            if (!GLParaAccessor.isLbtCenterStart(qryVO.getBaseAccountingbook()).booleanValue()){
                return;}
        } catch (BusinessException e) {
            Logger.error(e.getMessage(), e);
        }
        try {
            HashSet<String> set = new HashSet<String>();
            for (int i = 0; i < vos.length; i++) {
                set.add((String) vos[i].getValue(BalanceSubjAssBSKey.K_LIABILITYCENTER));
            }
            set.remove(null);
            set.remove("N/A");
            String[] pk_orgs = set.toArray(new String[] { /*fill for sonar*/});
            IBDData[] datas = GeneralAccessorFactory.getAccessor(IOrgMetaDataIDConst.PROFITCENTER).getDocbyPks(pk_orgs);

            HashMap<String, IBDData> pkliabiliCenterMap=new HashMap<String, IBDData>();
            Arrays.stream(datas).forEach(data->{
                Optional.ofNullable(data).ifPresent(x->{
                    pkliabiliCenterMap.put(x.getPk(),x);
                });;
            });
            if (pk_orgs.length > 0) {
                for (int i = 0; i < vos.length; i++) {
                    IBDData data=pkliabiliCenterMap.get(vos[i].getValue(BalanceSubjAssBSKey.K_LIABILITYCENTER));
                    //vos[i].setValue(BalanceSubjAssBSKey.K_LIABILITYCENTER,data==null?"":data.getName().toString());
                    vos[i].setValue(BalanceSubjAssBSKey.K_LIABILITYCENTERCODE, data==null?"":data.getCode().toString());
                    vos[i].setValue(BalanceSubjAssBSKey.K_LIABILITYCENTERNAME,data==null?"":data.getName().toString());
                }
            }
        } catch (Exception e) {
            Logger.error(e.getMessage(), e);
        }

    }

    private List<IColumnInfo> getColumn(GlQueryVO qryvo){
        List<IColumnInfo> colList = new ArrayList<IColumnInfo>();
        colList.add(new ColumnInfo(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000009")/*@res "摘要"*/, "mark", ColumnInfo.LEFT));
        if(qryvo.isMultiYearList()){
            colList.add(new ColumnInfo(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000078")/*@res "年"*/, "year", ColumnInfo.LEFT));
        }
        if (qryvo.getFormatVO().getCorpDispLocation() == 1) { // 核算账簿+查询对象
            if(qryvo.getpk_accountingbook().length>1&&!qryvo.isMultiCorpCombine()){
                colList.add(new ColumnInfo(NCLangRes4VoTransl.getNCLangRes().getStrByID("gl20111017public_v1_0","1200230400004")/*@res "核算账簿名称"*/, "bookname", ColumnInfo.LEFT));
            }
        }
        if(AccountRepUtil.isBuSupport(qryvo)){
            colList.add(new ColumnInfo(NCLangRes4VoTransl.getNCLangRes().getStrByID("common","UCMD1-000396")/*@res "业务单元"*/, "unitname", ColumnInfo.LEFT));
        }
        //利润中心zlp
        if(AccountRepUtil.isliabilitycenterSupport(qryvo)){
            colList.add(new ColumnInfo(NCLangRes4VoTransl.getNCLangRes().getStrByID("common","UCMD1-000445")/*@res "利润中心多语"*/, "liabilitycentername", ColumnInfo.LEFT));
        }

        if (!GlQueryVOAssTool.isMultiPages(qryvo)) {
            GLQueryObj[] queryObjs = qryvo.getFormatVO().getQryObjs();
            for (int i = 0; i < queryObjs.length; i++) {
                GLQueryObj queryObj = queryObjs[i];
                if(queryObj.getTypeName().equals(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000031")/* @res "会计科目" */)) {
                    colList.add(new ColumnInfo(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000010")/*@res "科目编码"*/, "accsubjcode", ColumnInfo.LEFT));
                    colList.add(new ColumnInfo(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000011")/*@res "科目名称"*/, "accsubjname", ColumnInfo.LEFT));
                } else {
                    AssVO[] assvos = queryObj.getValueRange();
                    if (assvos != null && assvos[0] != null) {
                        AssVO assvo = assvos[0];
                        colList.add(new ColumnInfo(assvo.getChecktypename() + NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000033")/*@res "编码"*/,
                                "checkvaluecode" + i, ColumnInfo.LEFT));
                        colList.add(new ColumnInfo(assvo.getChecktypename() + NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000034")/*@res "名称"*/,
                                "showname" + i, ColumnInfo.LEFT));
                    }
                }
            }
        } else {
            GLQueryObj[] queryObjs = qryvo.getFormatVO().getQryObjs();
            for (int i = 0; i < queryObjs.length; i++) {
                GLQueryObj queryObj = queryObjs[i];
                if (!queryObj.getHeadEle()) {
                    if(queryObj.getTypeName().equals(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000031")/* @res "会计科目" */)) {
                        colList.add(new ColumnInfo(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000010")/*@res "科目编码"*/, "accsubjcode", ColumnInfo.LEFT));
                        colList.add(new ColumnInfo(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000011")/*@res "科目名称"*/, "accsubjname", ColumnInfo.LEFT));
                    } else {
                        AssVO[] assvos = queryObj.getValueRange();
                        if (assvos != null && assvos[0] != null) {
                            AssVO assvo = assvos[0];
                            colList.add(new ColumnInfo(assvo.getChecktypename() + NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000033")/*@res "编码"*/,
                                    "checkvaluecode" + i, ColumnInfo.LEFT));
                            colList.add(new ColumnInfo(assvo.getChecktypename() + NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000034")/*@res "名称"*/,
                                    "showname" + i, ColumnInfo.LEFT));
                        }
                    }
                }
            }
        }
        if (qryvo.getFormatVO().getCorpDispLocation() == 0) { // 查询对象+核算账簿
            if(qryvo.getpk_accountingbook().length>1&&!qryvo.isMultiCorpCombine()){
                colList.add(new ColumnInfo(NCLangRes4VoTransl.getNCLangRes().getStrByID("gl20111017public_v1_0","1200230400004")/*@res "核算账簿名称"*/, "bookname", ColumnInfo.LEFT));
            }
        }
        colList.add(new ColumnInfo(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000532")/*@res "计量单位"*/, "measureunit", ColumnInfo.LEFT));
        // 查询所有币种则显示币种列
        if (qryvo.getCurrTypeName().equals(CurrTypeConst.ALL_CURRTYPE())) {
            colList.add(new ColumnInfo(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000012")/*@res "币种"*/, "curtype", ColumnInfo.LEFT));
        }

        String[] childStr = null;
        String[] childAlign = null;
        if(qryvo.getCurrTypeName().equals(CurrTypeConst.QUERY_LOC_CURRTYPE())){
            childStr = new String[]{NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000050")/*@res "数量"*/
                    ,NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000053")/*@res "本币"*/};
            childAlign = new String[]{ColumnInfo.RIGTH,ColumnInfo.RIGTH};
        }else{
            childStr = new String[]{NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000050")/*@res "数量"*/
                    ,NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000051")/*@res "原币"*/
                    ,NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000053")/*@res "本币"*/};
            childAlign = new String[]{ColumnInfo.RIGTH,ColumnInfo.RIGTH,ColumnInfo.RIGTH};
        }
        String[] childKey = null;
        if(qryvo.getCurrTypeName().equals(CurrTypeConst.QUERY_LOC_CURRTYPE())){
            childKey = new String[]{"initquant","initlocamount"};
        }else{
            childKey = new String[]{"initquant","initamount","initlocamount"};
        }

        if(!qryvo.getFormatVO().isTwoWayBalance()){
            colList.add(new ColumnInfo(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000134")/*@res "方向"*/, "initorients", ColumnInfo.CENTER));
            colList.add(AccountRepUtil.getMultHeadColum(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000459")/*@res "期初余额"*/ , childStr, childKey, childAlign));
        }else{
            if(qryvo.getCurrTypeName().equals(CurrTypeConst.QUERY_LOC_CURRTYPE())){
                childKey = new String[]{"initdebitquant","initdebitlocamount"};
            }else{
                childKey = new String[]{"initdebitquant","initdebitamount","initdebitlocamount"};
            }
            colList.add(AccountRepUtil.getMultHeadColum(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000479")/*@res "期初借方"*/
                    , childStr, childKey, childAlign));
            if(qryvo.getCurrTypeName().equals(CurrTypeConst.QUERY_LOC_CURRTYPE())){
                childKey = new String[]{"initcreditquant","initcreditlocamount"};
            }else{
                childKey = new String[]{"initcreditquant","initcreditamount","initcreditlocamount"};
            }
            colList.add(AccountRepUtil.getMultHeadColum(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000480")/*@res "期初贷方"*/
                    , childStr, childKey, childAlign));
        }

        if(qryvo.getCurrTypeName().equals(CurrTypeConst.QUERY_LOC_CURRTYPE())){
            childKey = new String[]{"debitquant","debitlocamount"};
        }else{
            childKey = new String[]{"debitquant","debitamount","debitlocamount"};
        }
        colList.add(AccountRepUtil.getMultHeadColum(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000044")/*@res "本期借方"*/
                , childStr, childKey, childAlign));

        if(qryvo.getCurrTypeName().equals(CurrTypeConst.QUERY_LOC_CURRTYPE())){
            childKey = new String[]{"creditquant","creditlocamount"};
        }else{
            childKey = new String[]{"creditquant","creditamount","creditlocamount"};
        }
        colList.add(AccountRepUtil.getMultHeadColum(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000045")/*@res "本期贷方"*/
                , childStr, childKey, childAlign));

        if(qryvo.getCurrTypeName().equals(CurrTypeConst.QUERY_LOC_CURRTYPE())){
            childKey = new String[]{"debitaccumquant","debitaccumlocamount"};
        }else{
            childKey = new String[]{"debitaccumquant","debitaccumamount","debitaccumlocamount"};
        }
        colList.add(AccountRepUtil.getMultHeadColum(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000046")/*@res "借方累计"*/
                , childStr, childKey, childAlign));

        if(qryvo.getCurrTypeName().equals(CurrTypeConst.QUERY_LOC_CURRTYPE())){
            childKey = new String[]{"creditaccumquant","creditaccumlocamount"};
        }else{
            childKey = new String[]{"creditaccumquant","creditaccumamount","creditaccumlocamount"};
        }
        colList.add(AccountRepUtil.getMultHeadColum(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000047")/*@res "贷方累计"*/
                , childStr, childKey, childAlign));

        if(qryvo.getCurrTypeName().equals(CurrTypeConst.QUERY_LOC_CURRTYPE())){
            childKey = new String[]{"endquant","endlocamount"};
        }else{
            childKey = new String[]{"endquant","endamount","endlocamount"};
        }
        if(!qryvo.getFormatVO().isTwoWayBalance()){
            colList.add(new ColumnInfo(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000134")/*@res "方向"*/, "endorients", ColumnInfo.CENTER));
            colList.add(AccountRepUtil.getMultHeadColum(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000048")/*@res "期末余额"*/
                    , childStr, childKey, childAlign));
        }else {
            if(qryvo.getCurrTypeName().equals(CurrTypeConst.QUERY_LOC_CURRTYPE())){
                childKey = new String[]{"enddebitquant","enddebitlocamount"};
            }else{
                childKey = new String[]{"enddebitquant","enddebitamount","enddebitlocamount"};
            }
            colList.add(AccountRepUtil.getMultHeadColum(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000481")/*@res "期末借方"*/
                    , childStr, childKey, childAlign));

            if(qryvo.getCurrTypeName().equals(CurrTypeConst.QUERY_LOC_CURRTYPE())){
                childKey = new String[]{"endcreditquant","endcreditlocamount"};
            }else{
                childKey = new String[]{"endcreditquant","endcreditamount","endcreditlocamount"};
            }
            colList.add(AccountRepUtil.getMultHeadColum(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000482")/*@res "期末贷方"*/
                    , childStr, childKey, childAlign));
        }

        return colList;

    }

    /**
     * 校验查询条件
     * <br>nc.ui.gl.assbalance.QueryDialogPanel.checkQryObjs(GlQryFormatVO qryFormatVo)
     * @param qryVO
     * @throws BusinessException
     */
    public void checkQryObjs(GlQueryVO qryVO) throws BusinessException {
        if (qryVO.getDate() == null) {
            throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000185")/*@res "请重新输入起始日期！"*/);
        }
        GlQryFormatVO qryFormatVo = qryVO.getFormatVO();
        int iKmAmount = 0;
        for (GLQueryObj qryObj : qryFormatVo.getQryObjs()) {
            if (!StrTools.isEmptyStr(qryObj.getType())) {
                if (qryObj.getType().equals(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000031")/*@res "会计科目"*/)) {
                    iKmAmount++;
                } else if (qryObj.getValueRange()[0]!= null
                        && qryObj.getValueRange()[0].getCheckvaluename().equals("ALL")
                        && qryObj.getIncludeSub()) {
                    throw new BusinessException(
                            NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000187")/*@res "辅助项选空，不支持同时包含下级！"*/);
                }
            }
        }
        if (iKmAmount == 0) {
            throw new BusinessException(
                    NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000188")/*@res "没有选择设定会计科目查询对象信息！"*/);
        } else if (iKmAmount > 1) {
            throw new BusinessException(
                    NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000189")/*@res "会计科目查询对象信息不唯一！"*/);
        }

        GLQueryObj[] aQryObjs = qryFormatVo.getQryObjs();

        boolean blnIsChild = false;
        boolean blnAssIsChild = false;
        String sCorpTmp = AccountBookUtil.getPk_orgByAccountBookPk(qryVO.getBaseAccountingbook());
        if(qryVO.getpk_accountingbook().length==1
                &&GLParaAccessor.isSecondBUStart(qryVO.getBaseAccountingbook()).booleanValue()
                &&qryVO.getPk_unis()!=null) {
            sCorpTmp = qryVO.getPk_unis()[0];
        }
        boolean blnSubjAccIsInBody = false;
        boolean blnAssIsInBody = false;
        int iBodyItemCount = 0;
        for (int i = 0; i < aQryObjs.length; i++) {
            if (!blnIsChild || !blnAssIsChild) {
                if (!aQryObjs[i].getHeadEle()) {
                    if (aQryObjs[i].getType().equals(NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000031")/*@res "会计科目"*/)) {
                        if (!aQryObjs[i].getHeadEle()) {
                            blnSubjAccIsInBody = true;
                            iBodyItemCount++;
                        }
                        //如果是，隔开的科目
                        if(aQryObjs[i].getValueRange()!=null&&aQryObjs[i].getValueRange()[0].getCheckvaluecode().contains(",")){
                            String[] acccode =  aQryObjs[i].getValueRange()[0].getCheckvaluecode().split(",");
                            for(int j=0;j<acccode.length;j++){
                                for(int k=0;k<acccode.length;k++){
                                    if(j != k&& acccode[j].startsWith(acccode[k])){
                                        blnIsChild = true;
                                        break;
                                    }
                                }
                            }
                        }else{
                            for (int j = 0;j < aQryObjs[i].getValueRange().length; j++) {
                                for (int k = 0; k < aQryObjs[i].getValueRange().length; k++) {
                                    if (j != k
                                            && aQryObjs[i].getValueRange()[j]
                                            .getCheckvaluecode()
                                            .startsWith(aQryObjs[i].getValueRange()[k].getCheckvaluecode())) {
                                        blnIsChild = true;
                                        break;
                                    }
                                }
                            }
                        }
                    } else {
                        if (!aQryObjs[i].getHeadEle()) {
                            iBodyItemCount++;
                            blnAssIsInBody = true;
                        }
                        for (int j = 0; aQryObjs[i].getValueRange() != null
                                && j < aQryObjs[i].getValueRange().length; j++) {
                            if (aQryObjs[i].getIncludeSub()) {
                                try {
                                    AssVO[] assVos = CBalanceAssTool
                                            .getSubDocsTackle(
                                                    aQryObjs[i]
                                                            .getValueRange()[j],
                                                    sCorpTmp);
                                    for (int f = 0; f < assVos.length; f++) {
                                        for (int k = 0; k < aQryObjs[i]
                                                .getValueRange().length; k++) {
                                            if (assVos[f]
                                                    .getPk_Checkvalue()
                                                    .equals(
                                                            aQryObjs[i]
                                                                    .getValueRange()[k]
                                                                    .getPk_Checkvalue())) {
                                                blnAssIsChild = true;
                                                break;
                                            }
                                        }
                                    }
                                } catch (Exception e) {
                                    throw new BusinessException(e.getMessage(), e);
                                }
                            }
                        }
                    }
                }
            }
        }

        String tempyear = null;
        String tempendyear = null;
        if (qryVO.isQueryByPeriod()) {
            tempyear = qryVO.getYear();
            tempendyear = qryVO.getEndYear();
        } else {
            UFDate date1 = qryVO.getDate();
            UFDate date2 = qryVO.getEndDate();
            GlPeriodVO period1 = null, period2 = null;
            try {
                IGlPeriod itf = (IGlPeriod) NCLocator.getInstance().lookup(IGlPeriod.class.getName());
                period1 = itf.getPeriod(qryVO.getBaseAccountingbook(), date1);
                period2 = itf.getPeriod(qryVO.getBaseAccountingbook(), date2);
            } catch (Exception e) {
                Logger.error(e.getMessage(), e);
            }
            tempyear = period1.getYear();
            tempendyear = period2.getYear();
        }
        //同一页显示可以显示上下级。
        if(blnIsChild&&!(blnSubjAccIsInBody && iBodyItemCount == 1)){
            qryFormatVo.setAssBalIncludeChildSubj(true);
            blnIsChild = false;
        }
        if (blnIsChild) {
            if (!(blnSubjAccIsInBody && iBodyItemCount == 1)
                    || (qryFormatVo.getCorpDispLocation() == 0 && qryVO.getpk_accountingbook().length > 1)
                    || (!tempyear.equals(tempendyear))) {
                throw new BusinessException(
                        NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000190")/*@res "查询条件出现以下情况时，不支持科目之间有上下级关系：1、辅助明细帐查询；2、表体查询中有辅助核算； 3、选择多个单位，且“多单位排序方式”为“查询对象＋单位”；4、辅助余额表跨年。 请检查是否出现上述情况，修改查询条件后再试。"*/);
            } else {
                qryFormatVo.setIsSubjAccIncldFatherSon(true);
            }
        } else {
            qryFormatVo.setIsSubjAccIncldFatherSon(false);
        }
        if (blnAssIsChild) {
            if (!(blnAssIsInBody && iBodyItemCount == 1)
                    || (qryFormatVo.getCorpDispLocation() == 0 && qryVO.getpk_accountingbook().length > 1)
                    || (!qryVO.getYear().equals(qryVO.getEndYear()))) {
                throw new BusinessException(
                        NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000191")/*@res "查询条件出现以下情况时，不支持辅助核算之间有上下级关系：1、辅助明细帐查询；2、表体查询中大于一个查询对象； 3、选择多个单位，且“多单位排序方式”为“查询对象＋单位”；4、辅助余额表跨年。 请检查是否出现上述情况，修改查询条件后再试。"*/);
            } else {
                qryFormatVo.setIsAssIncldFatherSon(true);
            }
        }

        boolean blnHaveTableBodyItem = false;
        for (int i = 0; i < 10; i++) {
            for (GLQueryObj obj : aQryObjs) {
                if (!obj.getHeadEle()) {
                    blnHaveTableBodyItem = true;
                    break;
                }
            }
        }
        if (!blnHaveTableBodyItem && aQryObjs.length >= 2) {
            throw new BusinessException(
                    NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000193")/*@res "没有选择设定表体查询对象信息！（辅助余额表至少要有一个表体查询对象）"*/);
        }

        if (aQryObjs.length < 2) {
            throw new BusinessException(
                    NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000194")/*@res "没有选辅助核算类型，请重新选择！"*/);
        }
        UFDouble from = qryVO.getFormatVO().getBalanceRangeFrom();
        UFDouble to = qryVO.getFormatVO().getBalanceRangeTo();
        if (from == null){
            from = UFDouble.ZERO_DBL;}
        if (to == null){
            to = UFDouble.ZERO_DBL;}
        if (from.compareTo(to) > 0) {
            throw new BusinessException(
                    NCLangRes4VoTransl.getNCLangRes().getStrByID("20023030","UPP20023030-000195")/*@res "余额范围查询条件信息输入有误(起始值大于终止值)！"*/);
        }
    }

    /**
     * 判断查询对象里是否有物料做表体
     * @param qryVO
     * @return
     */
    private boolean isExistsMaterial(GlQueryVO qryVO) {
        for (GLQueryObj qryObj : qryVO.getFormatVO().getQryObjs()) {
            if (qryObj.getValueRange() != null
                    && qryObj.getValueRange().length > 0
                    && IBDMetaDataIDConst.MATERIAL_V.equals(qryObj.getValueRange()[0].getM_classid())) {
//					&& qryObj.getValueRange()[0].getCheckvaluecode()!=null		) {
                return true;
            }
        }
        return false;
    }

    /**
     * 获取Map<物料pk，计量单位pk>
     * @param vos
     * @return
     * @throws Exception
     */
    private Map<String, String> getMaterialMeasdoc(BalanceSubjAssBSVO[] vos) throws Exception {
        Map<String, String> map = new HashMap<String, String>();
        // 取出辅助中的pk_material
        Set<String> pk_material = new HashSet<String>();
        for (BalanceSubjAssBSVO vo : vos) {
            String materialPK = getMaterialPK(vo);
            if (!StrTools.isEmptyStr(materialPK) && !StrTools.NULL.equals(materialPK)) {
                pk_material.add(materialPK);
            }
        }
        // 查询物料计量单位，组成Map<物料pk，计量单位pk>
        if (pk_material.size() > 0) {
            MaterialVO[] materialVOs = (MaterialVO[]) BDCacheQueryUtil.queryVOsByIDs(
                    MaterialVO.class,
                    MaterialVO.PK_MATERIAL,
                    pk_material.toArray(new String[pk_material.size()]),
                    new String[] { MaterialVO.PK_MEASDOC });
            if (materialVOs != null && materialVOs.length > 0) {
                for (MaterialVO materialVO : materialVOs) {
                    if (materialVO != null) {
                        map.put(materialVO.getPk_material(), materialVO.getPk_measdoc());
                    }
                }
            }
        }
        return map;
    }

    /**
     * 取出辅助中的pk_material
     * @param vo
     * @return
     * @throws Exception
     */
    private String getMaterialPK(BalanceSubjAssBSVO vo) throws Exception {
        AssVO[] assvos = (AssVO[]) vo.getValue(BalanceSubjAssBSKey.K_ASSVOS);
        if (assvos != null) {
            for (AssVO assvo : assvos) {
                if (IBDMetaDataIDConst.MATERIAL_V.equals(assvo.getM_classid())) {
                    return assvo.getPk_Checkvalue();
                }
            }
        }
        return null;
    }

    private void setPk_localcurr(String pk_localcurr) {
        this.pk_localcurr = pk_localcurr;
    }

}
